X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/7983570288ed2798470a552ec04f64aa646b664a..467fdea52c27dcf01e79cb96068134403afff660:/page.php?ds=inline diff --git a/page.php b/page.php index d5c78cd..5eefadb 100644 --- a/page.php +++ b/page.php @@ -8,42 +8,6 @@ function abort($body, $status = NULL) { exit; } -function getoutput($blocks = []) -{ - $doc = ob_get_clean(); - - if (!empty($blocks['warn'])) { - $warn = '

[[warn]]

'; - if ($offset = strpos($doc, '')) { - $doc = substr_replace($doc, "\n\n".$warn, $offset + 5, 0); - } - else { - $doc = $warn . "\n\n" . $doc; - } - } - - # keep either login or logout parts depending on user level - global $User; - $hideclass = $User && property_exists($User, 'login') && $User->login ? 'logout' : 'login'; - $doc = preg_replace('{\s*<([a-z]+) class="'.$hideclass.'">.*?}s', '', $doc); - - return preg_replace_callback( - '{ \[\[ ([^] ]+) ([^]]*) \]\] }x', - function ($sub) use ($blocks) { - list ($placeholder, $name, $params) = $sub; - $html = $blocks[$name] ?? - placeholder_include($name, explode(' ', $params)); - if (empty($html) or $html[0] != '<') { - $html = "$html"; - } - $attr = sprintf(' data-dyn="%s"', is_numeric($name) ? '' : $name.$params); - # contents with identifier in first tag - return preg_replace( '/(?=>)/', $attr, $html, 1); - }, - $doc - ); -} - # custom error handling define('DOCROOT', getcwd()); @@ -61,7 +25,8 @@ function fail($error) include_once 'page.inc.php'; ob_start(); require '500.inc.html'; - print getoutput(['debug' => htmlspecialchars($error)]); + $Page->place['debug'] = htmlspecialchars($error); + print $Page->render(); } set_exception_handler('fail'); @@ -131,7 +96,7 @@ header(sprintf('Content-Security-Policy: %s', implode('; ', [ ]))); ob_start(); # page body -$Place = [ +$Page->place += [ 'user' => $User->login ?: '', 'url' => htmlspecialchars($_SERVER['REQUEST_URI']), ];