2 error_reporting(E_ALL);
3 ini_set('display_errors', TRUE);
7 http_response_code(500);
8 include_once 'page.inc.php';
10 require_once './500.html';
11 print getoutput(['debug' => $error]);
13 set_exception_handler('fail');
14 register_shutdown_function(function () {
15 # display failure page for fatal exceptions
16 $error = error_get_last();
17 if (!($error['type'] & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR))) return;
18 fail("Fatal: $error[message] in $error[file]:$error[line]");
21 include_once 'auth.inc.php';
22 $Edit = isset($_GET['edit']);
24 # distinguish subpage Args from topmost Page script
27 $Page = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
28 $Page = urldecode(trim($Page, '/')) ?: 'index';
30 if (file_exists("$Page.php")) {
34 $up = strrpos($Page, '/');
35 $Args = substr($Page, $up) . $Args;
36 $Page = substr($Page, 0, $up);
42 # load static contents
44 ob_start(); # page body
45 ob_start(); # inner html
46 print '<div class="static">'."\n\n";
49 if (file_exists("$Page$Args/index.html")) {
50 $found = include "./$Page$Args/index.html";
52 elseif (file_exists("$Page$Args.html")) {
53 $found = include "./$Page$Args.html";
58 # execute dynamic code
61 function getoutput($blocks = [])
64 foreach ($blocks as $name => $html) {
65 $rep["[[$name]]"] = "<!--BLOCK $name-->$html<!--/-->";
67 return str_replace(array_keys($rep), array_values($rep), ob_get_clean());
70 $found |= require "./$Page.php";
75 include_once 'page.inc.php';
79 if (isset($User) and $User['admin']) {
80 require './template.html';
83 http_response_code(404);
86 print getoutput([ 'url' => htmlspecialchars($_SERVER['REQUEST_URI']) ]);