page: store placeholder values in $Page object
[minimedit.git] / page.inc.php
index 0ca658920d98877769933d9ab9eace195de48ed8..afaa970868493fc3f509966f11576e47a3e3c64b 100644 (file)
@@ -1,10 +1,38 @@
 <?php
+$body = $Page->render();
+
 include_once 'head.inc.php';
 
 print "<header>\n";
 ob_start();
-include 'menu.html';
-$nav = ob_get_clean();
+$menu = new ArchiveArticle('menu.inc.html');
+print $menu->raw;
+ob_start();
+if ($User and property_exists($User, 'login') and $User->login) {
+       print '<div class="login"><p>';
+       printf('<span title="ingelogd">%s <a href="%s">%s</a></span>',
+               '<span class="icon icon-user">&#x1F464;</span>',
+               '/login', $User->login
+       );
+       if ($User->admin("edit {$Page->link}")) {
+               $editpage = $Page->link;
+               if (is_dir($editpage)) {
+                       if (file_exists("$editpage/index.html")) {
+                               $editpage .= '/index.html';
+                       }
+               }
+               else {
+                       $editpage .= '.html';
+               }
+               if (!file_exists($editpage) or is_writable($editpage)) {
+                       print ' <a class="icon icon-edit" href="#edit" title="wijzig">&#x270D;</a>';
+               }
+       }
+       print "</p></div>\n";
+}
+$menu->place['login'] = ob_get_clean();
+$nav = $menu->render();
+
 $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
@@ -13,16 +41,23 @@ $nav = preg_replace_callback('{<a href="([^"]+)">(.*?)</a>}', function ($m) {
 print $nav;
 print "</header>\n\n";
 
-print '<div class="article">'."\n\n";
-
-include_once 'auth.inc.php';
+print $body;
 
 register_shutdown_function(function () {
-       print "</div>\n\n";
-       include 'foot.inc.php';
+       print '<footer>';
+       @include 'footer.inc.html';
+       print "</footer>\n";
+
+       global $User, $Page;
+       if ($User and $User->admin("edit {$Page->link}")) {
+               $ckesrc = '/lib/ckeditor'; # local install
+               if (!file_exists(DOCROOT . $ckesrc)) {
+                       $ckesrc = '//cdn.ckeditor.com/4.15.1/full-all'; # remote fallback
+               }
+               printf("<script>var ckesrc = '%s'</script>\n", "$ckesrc/ckeditor.js");
+               print '<script src="/edit/page.js"></script>'."\n";
+       }
+
        print "</body></html>\n";
 });
 
-include "$Page.html";
-if (file_exists("$Page.php")) include_once("$Page.php");
-