nieuws: drop prompt for article (back)date
[minimedit.git] / page.php
index edb074e158348da910b1c6b7d80ae1a3fb4ae7d2..290a59670ba98955d69362f1b643105a2a72cd11 100644 (file)
--- a/page.php
+++ b/page.php
@@ -2,16 +2,16 @@
 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>')) {
@@ -21,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 = '<strong class="warn"><em>'.$name.'</em> ontbreekt</strong>';
+                       }
+                       return sprintf('<!--BLOCK:%s-->%s<!--/-->',
+                               is_numeric($name) ? '' : $placeholder, # edit replacement
+                               preg_replace('{<!--[^-]*-->}', '', $html) # contents
+                       );
+               },
+               $doc
+       );
 }
 
 # custom error handling
@@ -99,12 +116,12 @@ ob_start(); # inner html
 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');
 }