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/.private")) {
45 http_response_code(403);
46 include_once 'page.inc.php';
48 require_once './403.html';
53 if (file_exists("$Page.php")) {
57 $up = strrpos($Page, '/');
58 $Args = substr($Page, $up) . $Args;
59 $Page = substr($Page, 0, $up);
65 # load static contents
67 ob_start(); # page body
68 ob_start(); # inner html
69 print '<div class="static">'."\n\n";
72 if (file_exists("$Page$Args/index.html")) {
73 $found = include "./$Page$Args/index.html";
75 elseif (file_exists("$Page$Args.html")) {
76 $found = include "./$Page$Args.html";
78 elseif (isset($User) and $User['admin']) {
79 $found = require (file_exists("$Page/template.html") ? "$Page/template.html" : './template.html');
84 # execute dynamic code
87 $found |= require "./$Page.php";
92 include_once 'page.inc.php';
96 http_response_code(404);
99 print getoutput([ 'url' => htmlspecialchars($_SERVER['REQUEST_URI']) ]);