X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/b06e0695bbf6a9710ed53eefb941134812a3ff27..7b2536e0bef980a9d153522320c14dc5261b4ba4:/page.php diff --git a/page.php b/page.php index 76a99b5..290a596 100644 --- a/page.php +++ b/page.php @@ -10,14 +10,8 @@ function abort($body, $status = NULL) { function getoutput($blocks = []) { - $rep = []; - foreach ($blocks as $name => $html) { - $rep["[[$name]]"] = sprintf('%s', - is_numeric($name) ? '' : "[[$name]]", - preg_replace('{}', '', $html) - ); - } $doc = ob_get_clean(); + if (!empty($blocks['warn'])) { $warn = '

[[warn]]

'; if ($offset = strpos($doc, '')) { @@ -27,7 +21,24 @@ function getoutput($blocks = []) $doc = $warn . "\n\n" . $doc; } } - return str_replace(array_keys($rep), array_values($rep), $doc); + + return preg_replace_callback( + '< \[\[ ([^]]*) \]\] >x', + function ($sub) use ($blocks) { + list ($placeholder, $name) = $sub; + if (isset($blocks[$name])) { + $html = $blocks[$name]; + } + else { + $html = ''.$name.' ontbreekt'; + } + return sprintf('%s', + is_numeric($name) ? '' : $placeholder, # edit replacement + preg_replace('{}', '', $html) # contents + ); + }, + $doc + ); } # custom error handling