page: save document root for includes during shutdown
[minimedit.git] / page.inc.php
index dcb0573223a06f4f9e6601a857ef2e1314b384a7..c0282eea341fcec090015953950f7c601c504c8f 100644 (file)
@@ -1,26 +1,40 @@
 <?php
-include_once './head.inc.php';
+$body = ob_get_clean();
+
+include_once DOCROOT.'head.inc.php';
 
 print "<header>\n";
 ob_start();
-include './menu.html';
+include DOCROOT.'menu.html';
 $nav = ob_get_clean();
 $nav = preg_replace_callback('{<a href="([^"]+)">(.*?)</a>}', function ($m) {
        $request = $_SERVER['REQUEST_URI'];
        $html = $request == $m[1] ? $m[2] : $m[0]; # text or full link
        return $m[1] == substr($request, 0, strlen($m[1])) ? "<b>$html</b>" : $html;
 }, $nav);
+if (isset($User)) {
+       $nav = preg_replace('{\s*<li class="logout">.*?</li>}', '', $nav);
+       $nav = str_replace('[[login]]', $User['name'], $nav);
+}
+else {
+       $nav = preg_replace('{\s*<li class="login">.*?</li>}', '', $nav);
+}
 print $nav;
 print "</header>\n\n";
 
-print '<div class="article">'."\n\n";
+print $body;
 
 register_shutdown_function(function () {
-       print "</div>\n\n";
-       include 'foot.inc.php';
+       print '<footer>';
+       @include DOCROOT.'footer.html';
+       print "</footer>\n";
+
+       global $User;
+       if (isset($User) and $User['admin']) {
+               print '<script src="//cdn.ckeditor.com/4.7.3/full-all/ckeditor.js"></script>'."\n";
+               print '<script src="/edit.js"></script>'."\n";
+       }
+
        print "</body></html>\n";
 });
 
-include "./$Page.html";
-if (file_exists("$Page.php")) include_once("./$Page.php");
-