error_reporting(E_ALL);
ini_set('display_errors', TRUE);
+function abort($body, $status = NULL) {
+ if ($status) header("HTTP/1.1 $status");
+ print "$body\n";
+ exit;
+}
+
function getoutput($blocks = [])
{
- $rep = [];
- foreach ($blocks as $name => $html) {
- $rep["[[$name]]"] = sprintf('<!--BLOCK:%s-->%s<!--/-->',
- is_numeric($name) ? '' : "[[$name]]",
- preg_replace('{<!--[^-]*-->}', '', $html)
- );
- }
$doc = ob_get_clean();
+
if (!empty($blocks['warn'])) {
$warn = '<p class="warn">[[warn]]</p>';
if ($offset = strpos($doc, '</h2>')) {
$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('<!--BLOCK:%s-->%s<!--/-->',
+ is_numeric($name) ? '' : $placeholder, # edit replacement
+ preg_replace('{<!--[^-]*-->}', '', $html) # contents
+ );
+ },
+ $doc
+ );
}
# custom error handling
print '<div class="static">'."\n\n";
$found = FALSE;
-if (file_exists("$Page$Args/index.html")) {
- $found = include "./$Page$Args/index.html";
-}
-elseif (file_exists("$Page$Args.html")) {
+if (file_exists("$Page$Args.html")) {
$found = include "./$Page$Args.html";
}
+elseif (file_exists("$Page$Args/index.html")) {
+ $found = include "./$Page$Args/index.html";
+}
elseif (!empty($User['admin'])) {
$found = include (file_exists("$Page/template.html") ? "$Page/template.html" : './template.html');
}