From 2b56d0fa69a4608fb1b582fca5f08d343f5b90eb Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 13 Sep 2017 13:44:27 +0200 Subject: [PATCH] page: rework script control Do not match *.html contents to subrequests, only traverse parents for *.php scripts which now support an additional output layer for appended output. This allows parent code to prepare how its subpages will be displayed (for example, a news directory can surround static articles with metadata). --- 404.php | 13 ++++------- edit.js | 2 +- login.php | 3 +++ page.inc.php | 6 ----- page.php | 65 +++++++++++++++++++++++++++++++++++++--------------- 5 files changed, 55 insertions(+), 34 deletions(-) mode change 100755 => 100644 404.php diff --git a/404.php b/404.php old mode 100755 new mode 100644 index 0410799..a6c11bf --- a/404.php +++ b/404.php @@ -1,8 +1,5 @@ - - -

Niet gevonden

- -

-De gevraagde pagina bestaat niet. -

- +Pagina niet gevonden\n\n"; +echo "

De gevraagde pagina $request bestaat niet.

\n\n"; diff --git a/edit.js b/edit.js index 0db4374..c5d6ce3 100644 --- a/edit.js +++ b/edit.js @@ -75,7 +75,7 @@ CKEDITOR.on('instanceCreated', function (event) { CKEDITOR.disableAutoInline = true; // add edit link to menu -var pagebody = document.getElementsByClassName('article')[0]; +var pagebody = document.getElementsByClassName('static')[0]; if (pagebody) { var editlink = document.createElement('a'); editlink.style.cursor = 'pointer'; diff --git a/login.php b/login.php index 369a013..490422f 100644 --- a/login.php +++ b/login.php @@ -1,3 +1,6 @@ +

Inloggen

\n"; }); -print '
'."\n\n"; -include "./$Page.html"; -print "
\n\n"; - -if (file_exists("$Page.php")) include_once("./$Page.php"); - diff --git a/page.php b/page.php index 38f54ec..f6c2346 100644 --- a/page.php +++ b/page.php @@ -5,35 +5,62 @@ ini_set('display_errors', TRUE); include_once 'auth.inc.php'; $Edit = isset($_GET['edit']); +# distinguish subpage Args from topmost Page script + $Args = ''; $Page = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']); $Page = urldecode(trim($Page, '/')) ?: 'index'; while (TRUE) { - if (file_exists("$Page/index.html")) { - $Page .= '/index'; - break; - } - if (file_exists("$Page.html")) { - break; - } if (file_exists("$Page.php")) { - # unformatted script override - require "$Page.php"; - exit; + break; } $up = strrpos($Page, '/'); + $Args = substr($Page, $up) . $Args; + $Page = substr($Page, 0, $up); if ($up === FALSE) { - if ($User['admin']) { - $Page = 'template'; - break; - } - http_response_code(404); - $Page = '404'; break; } - $Args = substr($Page, $up) . $Args; - $Page = substr($Page, 0, $up); } -include 'page.inc.php'; +# execute dynamic code + +$prepend = $append = ''; +if ($Page) { + require "./$Page.php"; + if (ob_get_level() > 1) $append = ob_get_clean(); + if (ob_get_level() > 0) $prepend = ob_get_clean(); +} + +# prepare static contents + +include_once 'page.inc.php'; # global html + +if (file_exists("$Page$Args/index.html")) { + $Args .= '/index'; +} + +if (!$Page and !file_exists("$Page$Args.html")) { + # include not found + $Args = ''; + if (isset($User) and $User['admin']) { + $Page = 'template'; + } + else { + $Page = '404'; + require "./$Page.php"; + } +} + +# output prepared html + +print $prepend; + +print '
'."\n\n"; +if (file_exists("$Page$Args.html")) { +include "./$Page$Args.html"; # static contents +} +print "
\n\n"; + +print $append; + -- 2.30.0