edit: static edit link
[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 ob_start();
10 if (isset($User)) {
11         print '<div class="login"><p>';
12         printf('<span>Ingelogd: <b>%s</b></span>', $User['name']);
13         if ($User['admin']) {
14                 print ' <a href="#edit">Wijzig</a>';
15         }
16         print "</p></div>\n";
17 }
18 $nav = getoutput(['login' => ob_get_clean()]);
19
20 $nav = preg_replace_callback('{<a href="([^"]+)">(.*?)</a>}', function ($m) {
21         $request = $_SERVER['REQUEST_URI'];
22         $html = $request == $m[1] ? $m[2] : $m[0]; # text or full link
23         return $m[1] == substr($request, 0, strlen($m[1])) ? "<b>$html</b>" : $html;
24 }, $nav);
25 if (isset($User)) {
26         $nav = preg_replace('{\s*<li class="logout">.*?</li>}', '', $nav);
27 }
28 else {
29         $nav = preg_replace('{\s*<li class="login">.*?</li>}', '', $nav);
30 }
31 print $nav;
32 print "</header>\n\n";
33
34 print $body;
35
36 register_shutdown_function(function () {
37         print '<footer>';
38         @include DOCROOT.'footer.html';
39         print "</footer>\n";
40
41         global $User;
42         if (isset($User) and $User['admin']) {
43                 print '<script src="//cdn.ckeditor.com/4.7.3/full-all/ckeditor.js"></script>'."\n";
44                 print '<script src="/edit.js"></script>'."\n";
45         }
46
47         print "</body></html>\n";
48 });
49