page: ignore output buffer in article render
[minimedit.git] / page.php
index 5eefadb5c8870e13ad8eeb045dce849f1ff258c3..8d2d01c1f3b7852d58db9a3ed283fb9dcd055a7c 100644 (file)
--- a/page.php
+++ b/page.php
@@ -23,9 +23,11 @@ function fail($error)
                $Page->title = 'Fout';
        }
        include_once 'page.inc.php';
+
        ob_start();
        require '500.inc.html';
        $Page->place['debug'] = htmlspecialchars($error);
+       $Page->raw = ob_get_clean();
        print $Page->render();
 }
 
@@ -95,7 +97,6 @@ header(sprintf('Content-Security-Policy: %s', implode('; ', [
        "frame-ancestors 'none'", # prevent malicious embedding
 ])));
 
-ob_start(); # page body
 $Page->place += [
        'user'  => $User->login ?: '',
        'url'   => htmlspecialchars($_SERVER['REQUEST_URI']),
@@ -127,15 +128,18 @@ if (isset($Page->raw)) {
 
 # output dynamic and/or static html
 
-if (!$Page->handler or require("./{$Page->handler}/index.php")) {
-       # static contents
-       if (isset($Page->raw)) {
-               print $Page->raw;
-       }
-       else {
+ob_start();
+if ($Page->handler and !require("./{$Page->handler}/index.php")) {
+       # replace contents by code output on false return
+       $Page->raw = ob_get_clean();
+}
+else {
+       # keep article contents
+       if (!isset($Page->raw)) {
                # no resulting output
                http_response_code(404);
                @require '404.inc.html';
+               $Page->raw = ob_get_clean();
        }
 }