X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/b06e0695bbf6a9710ed53eefb941134812a3ff27..7aa95dc7de12b20d7a2ae76eb6589947313b08ed:/page.php?ds=inline diff --git a/page.php b/page.php index 76a99b5..4bea9c6 100644 --- a/page.php +++ b/page.php @@ -8,16 +8,40 @@ function abort($body, $status = NULL) { exit; } -function getoutput($blocks = []) +function placeholder_include($name, $params = []) { - $rep = []; - foreach ($blocks as $name => $html) { - $rep["[[$name]]"] = sprintf('%s', - is_numeric($name) ? '' : "[[$name]]", - preg_replace('{}', '', $html) + $path = stream_resolve_include_path("widget/$name.php"); + if (!file_exists($path)) { + return ''.$name.' ontbreekt'; + } + + ob_start(); + $Page = $GLOBALS['Page'] . $GLOBALS['Args']; + $Args = ''; + $Place = $GLOBALS['Place']; + foreach ($params as $param) { + if ($set = strpos($param, '=')) { + $Place[ substr($param, 0, $set) ] = substr($param, $set + 1); + } + elseif (!empty($param)) { + $Args .= '/'.$param; + } + } + try { + include "widget/$name.php"; + return ob_get_clean(); + } + catch (Exception $e) { + return sprintf('%s', + "fout in $name: {$e->getMessage()}" ); } +} + +function getoutput($blocks = []) +{ $doc = ob_get_clean(); + if (!empty($blocks['warn'])) { $warn = '
[[warn]]
'; if ($offset = strpos($doc, '')) { @@ -27,19 +51,46 @@ function getoutput($blocks = []) $doc = $warn . "\n\n" . $doc; } } - return str_replace(array_keys($rep), array_values($rep), $doc); + + # keep either login or logout parts depending on user level + global $User; + $hideclass = empty($User) ? 'login' : 'logout'; + $doc = preg_replace('{\s*<([a-z]+) class="'.$hideclass.'">.*?\1>}s', '', $doc); + + return preg_replace_callback( + '{ (?%s', + is_numeric($name) ? '' : $placeholder, # edit replacement + preg_replace('{}', '', $html) # contents + ); + }, + $doc + ); } # custom error handling -define('DOCROOT', getcwd().'/'); +define('DOCROOT', getcwd()); +set_include_path(implode(PATH_SEPARATOR, [ DOCROOT, __DIR__ ])); function fail($error) { http_response_code(500); + if (!isset($Article)) { + $Article = new ArchiveArticle(NULL); + $Article->title = 'Fout'; + } include_once 'page.inc.php'; ob_start(); - require_once DOCROOT.'500.html'; + require_once '500.inc.html'; print getoutput(['debug' => $error]); } @@ -66,6 +117,7 @@ error_reporting(error_reporting() & ~E_FATAL); # user login and control +$User = NULL; include_once 'auth.inc.php'; $Edit = isset($_GET['edit']); @@ -86,7 +138,7 @@ while (TRUE) { $PageAccess = $Page; } - if (file_exists("$Page.php")) { + if (file_exists("$Page/index.php")) { break; } @@ -98,40 +150,60 @@ while (TRUE) { } } -# load static contents - -ob_start(); # page body -ob_start(); # inner html -print '