2 error_reporting(E_ALL);
3 ini_set('display_errors', TRUE);
5 function getoutput($blocks = [])
8 foreach ($blocks as $name => $html) {
9 $rep["[[$name]]"] = sprintf('<!--BLOCK:%s-->%s<!--/-->',
10 is_numeric($name) ? '' : "[[$name]]",
11 preg_replace('{<!--[^-]*-->}', '', $html)
14 return str_replace(array_keys($rep), array_values($rep), ob_get_clean());
19 http_response_code(500);
20 include_once 'page.inc.php';
22 require_once './500.html';
23 print getoutput(['debug' => $error]);
25 set_exception_handler('fail');
26 register_shutdown_function(function () {
27 # display failure page for fatal exceptions
28 $error = error_get_last();
29 if (!($error['type'] & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR))) return;
30 fail("Fatal: $error[message] in $error[file]:$error[line]");
33 include_once 'auth.inc.php';
34 $Edit = isset($_GET['edit']);
36 # distinguish subpage Args from topmost Page script
39 $Page = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
40 $Page = urldecode(trim($Page, '/')) ?: 'index';
42 if (file_exists("$Page.php")) {
46 $up = strrpos($Page, '/');
47 $Args = substr($Page, $up) . $Args;
48 $Page = substr($Page, 0, $up);
54 # load static contents
56 ob_start(); # page body
57 ob_start(); # inner html
58 print '<div class="static">'."\n\n";
61 if (file_exists("$Page$Args/index.html")) {
62 $found = include "./$Page$Args/index.html";
64 elseif (file_exists("$Page$Args.html")) {
65 $found = include "./$Page$Args.html";
67 elseif (isset($User) and $User['admin']) {
68 $found = require (file_exists("$Page/template.html") ? "$Page/template.html" : './template.html');
73 # execute dynamic code
76 $found |= require "./$Page.php";
81 include_once 'page.inc.php';
85 http_response_code(404);
88 print getoutput([ 'url' => htmlspecialchars($_SERVER['REQUEST_URI']) ]);