X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/37dbd7898c9c0baf9aec5073b757e3205a6a0c3d..297195ea7cb59ede5d39d7f3c56fdfd2ead376f7:/page.php diff --git a/page.php b/page.php index c6eee87..554735c 100644 --- a/page.php +++ b/page.php @@ -23,10 +23,30 @@ function getoutput($blocks = []) } return preg_replace_callback( - '< \[\[ ([^]]*) \]\] >x', + '< \[\[ ([^] ]+) ([^]]*) \]\] >x', function ($sub) use ($blocks) { - list ($placeholder, $name) = $sub; - $html = $blocks[$name]; + list ($placeholder, $name, $params) = $sub; + if (isset($blocks[$name])) { + $html = $blocks[$name]; + } + elseif (file_exists("$name.php")) { + ob_start(); + $Page = $GLOBALS['Page']; + $Args = $GLOBALS['Args']; + foreach (explode(' ', $params) as $param) { + if ($set = strpos($param, '=')) { + $_GET[ substr($param, 0, $set) ] = substr($param, $set + 1); + } + elseif (!empty($param)) { + $Args .= '/'.$param; + } + } + include "$name.php"; + $html = ob_get_clean(); + } + else { + $html = ''.$name.' ontbreekt'; + } return sprintf('%s', is_numeric($name) ? '' : $placeholder, # edit replacement preg_replace('{}', '', $html) # contents @@ -92,7 +112,7 @@ while (TRUE) { $PageAccess = $Page; } - if (file_exists("$Page.php")) { + if (file_exists("$Page/index.php")) { break; } @@ -125,19 +145,24 @@ print "\n\n"; # execute dynamic code +$Place = []; + if ($Page) { - $found |= require "./$Page.php"; + $found |= require "./$Page/index.php"; } -# global html +$Place += [ + 'user' => $User ? $User['name'] : '', + 'url' => htmlspecialchars($_SERVER['REQUEST_URI']), +]; -include_once 'page.inc.php'; +# global html if (!$found) { # no resulting output http_response_code(404); - ob_start(); @require "./404.html"; - print getoutput([ 'url' => htmlspecialchars($_SERVER['REQUEST_URI']) ]); } +include_once 'page.inc.php'; +