From c1eb891eceb8be1f3621fda7f0e5a58875df4d3e Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 14 Sep 2017 17:44:57 +0200 Subject: [PATCH] page: common getoutput() to replace placeholders --- page.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/page.php b/page.php index 4944467..6d98863 100644 --- a/page.php +++ b/page.php @@ -8,7 +8,7 @@ function fail($error) include_once 'page.inc.php'; ob_start(); require_once './500.html'; - print str_replace('[[debug]]', $error, ob_get_clean()); + print getoutput(['debug' => $error]); } set_exception_handler('fail'); register_shutdown_function(function () { @@ -58,6 +58,15 @@ print "\n\n"; # execute dynamic code if ($Page) { + function getoutput($blocks = []) + { + $rep = []; + foreach ($blocks as $name => $html) { + $rep["[[$name]]"] = $html; + } + return str_replace(array_keys($rep), array_values($rep), ob_get_clean()); + } + $found |= require "./$Page.php"; } @@ -74,8 +83,7 @@ if (!$found) { http_response_code(404); ob_start(); require "./404.html"; - $url = htmlspecialchars($_SERVER['REQUEST_URI']); - print str_replace('[[url]]', $url, ob_get_clean()); + print getoutput([ 'url' => htmlspecialchars($_SERVER['REQUEST_URI']) ]); } } -- 2.30.0