From: Mischa POSLAWSKY Date: Wed, 13 Sep 2017 19:51:47 +0000 (+0200) Subject: page: prepare static output before dynamic code X-Git-Tag: v2.1~10 X-Git-Url: http://git.shiar.net/minimedit.git/commitdiff_plain/7333dc046075c7873b15643ecd73f6e3b32c7a79 page: prepare static output before dynamic code Give script includes full access to prepared html, greatly simplifying buffer logic and allowing potential substitutions. Assumes small pages since all data flushes are delayed (can be worked around if ever needed). --- diff --git a/404.php b/404.php index a6c11bf..f6e1489 100644 --- a/404.php +++ b/404.php @@ -1,5 +1,7 @@ Pagina niet gevonden\n\n"; echo "

De gevraagde pagina $request bestaat niet.

\n\n"; +echo $extra; diff --git a/500.php b/500.php index a3e261c..c2ae655 100644 --- a/500.php +++ b/500.php @@ -1,4 +1,5 @@

Scriptfout

@@ -6,3 +7,5 @@ http_response_code(500);

Er ging iets mis:

Waarschijnlijk wordt hier aan gewerkt, maar als het probleem aanhoudt geef het dan aan ons door. +\n"; @@ -13,6 +15,8 @@ $nav = preg_replace_callback('{(.*?)}', function ($m) { print $nav; print "\n\n"; +print $body; + register_shutdown_function(function () { include 'foot.inc.php'; print "\n"; diff --git a/page.php b/page.php index 9acacc2..cb201f2 100644 --- a/page.php +++ b/page.php @@ -28,44 +28,39 @@ while (TRUE) { } } -# execute dynamic code +# load static contents -$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(); +ob_start(); # page body +ob_start(); # inner html +print '
'."\n\n"; + +$found = FALSE; +if (file_exists("$Page$Args/index.html")) { + $found = include "./$Page$Args/index.html"; +} +elseif (file_exists("$Page$Args.html")) { + $found = include "./$Page$Args.html"; } -# prepare static contents +print "
\n\n"; -include_once 'page.inc.php'; # global html +# execute dynamic code -if (file_exists("$Page$Args/index.html")) { - $Args .= '/index'; +if ($Page) { + $found |= require "./$Page.php"; } -if (!$Page and !file_exists("$Page$Args.html")) { - # include not found - $Args = ''; +# global html + +include_once 'page.inc.php'; + +if (!$found) { + # no resulting output if (isset($User) and $User['admin']) { - $Page = 'template'; + require './template.html'; } else { - $Page = '404'; - require "./$Page.php"; + require "./404.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; -