page: separate function to run placeholder includes
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 3 Sep 2018 19:38:07 +0000 (21:38 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 3 Sep 2018 19:40:22 +0000 (21:40 +0200)
nieuws/index.php
page.php

index cdb38925e1d50dcea8450ab8244c785b336ae929..b4191cee8898d6b275f20e02ba4dd2c8719f8bd0 100644 (file)
@@ -13,7 +13,7 @@ if ($page and !is_numeric($page)) {
                $Place['image'] = "https://lijtweg.nl/".$article->thumb('600x');
        }
        if ($replyform) {
-               include 'nieuws/replies.php';
+               print placeholder_include('nieuws/replies');
        }
        return 1;
 }
index 8979e6298d0d7c7d45a961264af9ce5a84182685..dd629fd8d4f0f869af47c8bb84515a12e34546d8 100644 (file)
--- a/page.php
+++ b/page.php
@@ -8,6 +8,36 @@ function abort($body, $status = NULL) {
        exit;
 }
 
+function placeholder_include($name, $params = [])
+{
+       $path = "$name.php";
+       if (!file_exists($path)) {
+               return '<strong class="warn"><em>'.$name.'</em> ontbreekt</strong>';
+       }
+
+       ob_start();
+       $Page = $GLOBALS['Page'] . $GLOBALS['Args'];
+       $Args = '';
+       $Place = $GLOBALS['Place'];
+       foreach ($params as $param) {
+               if ($set = strpos($param, '=')) {
+                       $Place[ substr($param, 0, $set) ] = substr($param, $set + 1);
+               }
+               elseif (!empty($param)) {
+                       $Args .= '/'.$param;
+               }
+       }
+       try {
+               include "$name.php";
+               return ob_get_clean();
+       }
+       catch (Exception $e) {
+               return sprintf('<strong class="warn">%s</strong>',
+                       "fout in <em>$name</em>: {$e->getMessage()}"
+               );
+       }
+}
+
 function getoutput($blocks = [])
 {
        $doc = ob_get_clean();
@@ -29,31 +59,8 @@ function getoutput($blocks = [])
                        if (isset($blocks[$name])) {
                                $html = $blocks[$name];
                        }
-                       elseif (file_exists("$name.php")) {
-                               ob_start();
-                               $Page = $GLOBALS['Page'] . $GLOBALS['Args'];
-                               $Args = '';
-                               $Place = $GLOBALS['Place'];
-                               foreach (explode(' ', $params) as $param) {
-                                       if ($set = strpos($param, '=')) {
-                                               $Place[ substr($param, 0, $set) ] = substr($param, $set + 1);
-                                       }
-                                       elseif (!empty($param)) {
-                                               $Args .= '/'.$param;
-                                       }
-                               }
-                               try {
-                                       include "$name.php";
-                                       $html = ob_get_clean();
-                               }
-                               catch (Exception $e) {
-                                       $html = sprintf('<strong class="warn">%s</strong>',
-                                               "fout in <em>$name</em>: {$e->getMessage()}"
-                                       );
-                               }
-                       }
                        else {
-                               $html = '<strong class="warn"><em>'.$name.'</em> ontbreekt</strong>';
+                               $html = placeholder_include($name, explode(' ', $params));
                        }
                        return sprintf('<!--BLOCK:%s-->%s<!--/-->',
                                is_numeric($name) ? '' : $placeholder, # edit replacement