X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/b06e0695bbf6a9710ed53eefb941134812a3ff27..37dbd7898c9c0baf9aec5073b757e3205a6a0c3d:/page.php diff --git a/page.php b/page.php index 76a99b5..c6eee87 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,19 @@ 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; + $html = $blocks[$name]; + return sprintf('%s', + is_numeric($name) ? '' : $placeholder, # edit replacement + preg_replace('{}', '', $html) # contents + ); + }, + $doc + ); } # custom error handling