X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/d1d031e348974975891a7ad232ef387e95abdd61..7333dc046075c7873b15643ecd73f6e3b32c7a79:/page.php diff --git a/page.php b/page.php index 38f54ec..cb201f2 100644 --- a/page.php +++ b/page.php @@ -2,38 +2,65 @@ error_reporting(E_ALL); ini_set('display_errors', TRUE); +set_exception_handler(function ($error) { + include_once 'page.inc.php'; + include_once '500.php'; +}); + 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'; +# load static contents + +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"; +} + +print "
\n\n"; + +# execute dynamic code + +if ($Page) { + $found |= require "./$Page.php"; +} + +# global html + +include_once 'page.inc.php'; + +if (!$found) { + # no resulting output + if (isset($User) and $User['admin']) { + require './template.html'; + } + else { + require "./404.php"; + } +} +