X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/d1d031e348974975891a7ad232ef387e95abdd61..2b56d0fa69a4608fb1b582fca5f08d343f5b90eb:/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; +