page: save document root for includes during shutdown
[minimedit.git] / page.inc.php
1 <?php
2 $body = ob_get_clean();
3
4 include_once DOCROOT.'head.inc.php';
5
6 print "<header>\n";
7 ob_start();
8 include DOCROOT.'menu.html';
9 $nav = ob_get_clean();
10 $nav = preg_replace_callback('{<a href="([^"]+)">(.*?)</a>}', function ($m) {
11         $request = $_SERVER['REQUEST_URI'];
12         $html = $request == $m[1] ? $m[2] : $m[0]; # text or full link
13         return $m[1] == substr($request, 0, strlen($m[1])) ? "<b>$html</b>" : $html;
14 }, $nav);
15 if (isset($User)) {
16         $nav = preg_replace('{\s*<li class="logout">.*?</li>}', '', $nav);
17         $nav = str_replace('[[login]]', $User['name'], $nav);
18 }
19 else {
20         $nav = preg_replace('{\s*<li class="login">.*?</li>}', '', $nav);
21 }
22 print $nav;
23 print "</header>\n\n";
24
25 print $body;
26
27 register_shutdown_function(function () {
28         print '<footer>';
29         @include DOCROOT.'footer.html';
30         print "</footer>\n";
31
32         global $User;
33         if (isset($User) and $User['admin']) {
34                 print '<script src="//cdn.ckeditor.com/4.7.3/full-all/ckeditor.js"></script>'."\n";
35                 print '<script src="/edit.js"></script>'."\n";
36         }
37
38         print "</body></html>\n";
39 });
40