page: convert error messages to html strings
[minimedit.git] / page.php
index f02544bd0b06dbd7add643d19a17e02bbdca69c2..fb0c4ddcba96d7edd2b3cd28bbbd3f1ea75017fc 100644 (file)
--- a/page.php
+++ b/page.php
@@ -55,7 +55,7 @@ function getoutput($blocks = [])
        # keep either login or logout parts depending on user level
        global $User;
        $hideclass = empty($User) ? 'login' : 'logout';
-       $doc = preg_replace('{\s*<(p|li|span) class="'.$hideclass.'">.*?</\1>}s', '', $doc);
+       $doc = preg_replace('{\s*<([a-z]+) class="'.$hideclass.'">.*?</\1>}s', '', $doc);
 
        return preg_replace_callback(
                '{ (?<! <!--BLOCK: ) \[\[ ([^] ]+) ([^]]*) \]\] }x',
@@ -84,10 +84,14 @@ set_include_path(implode(PATH_SEPARATOR, [ DOCROOT, __DIR__ ]));
 function fail($error)
 {
        http_response_code(500);
+       if (!isset($Article)) {
+               $Article = new ArchiveArticle(NULL);
+               $Article->title = 'Fout';
+       }
        include_once 'page.inc.php';
        ob_start();
-       require_once '500.inc.html';
-       print getoutput(['debug' => $error]);
+       require '500.inc.html';
+       print getoutput(['debug' => htmlspecialchars($error)]);
 }
 
 set_exception_handler('fail');
@@ -175,6 +179,15 @@ $Place = [
 ];
 
 if (isset($Article->raw)) {
+       if ($User and $User->admin("edit $Page$Args")) {
+               # restore meta tags in static contents for editing
+               foreach (array_reverse($Article->meta) as $metaprop => $val) {
+                       $Article->raw = sprintf(
+                               '<meta property="%s" content="%s" />'."\n",
+                               $metaprop, $val
+                       ) . $Article->raw;
+               }
+       }
        $Article->raw = '<div class="static">'."\n\n".$Article->raw."</div>\n\n";
 }