page: placeholder options
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 2 May 2018 15:23:19 +0000 (17:23 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 8 Jun 2018 22:37:09 +0000 (00:37 +0200)
Target name can be followed by whitespace for additional configuration.
Syntax "name=value" will be applied to global GET (overriding user input).
Otherwise a /subpath will be appended to local page Args.

page.php

index c2dfd9f0ed6089d0f9171c16e8eb02c16fa62341..7c4f8b1363101fa091eb40e8ac0ccaaaff21e76a 100644 (file)
--- a/page.php
+++ b/page.php
@@ -23,7 +23,7 @@ function getoutput($blocks = [])
        }
 
        return preg_replace_callback(
-               '< \[\[ ([^]/]+) ([^]]*) \]\] >x',
+               '< \[\[ ([^] ]+) ([^]]*) \]\] >x',
                function ($sub) use ($blocks) {
                        list ($placeholder, $name, $params) = $sub;
                        if (isset($blocks[$name])) {
@@ -32,7 +32,15 @@ function getoutput($blocks = [])
                        elseif (file_exists("$name.php")) {
                                ob_start();
                                $Page = $GLOBALS['Page'];
-                               $Args = $GLOBALS['Args'] . $params;
+                               $Args = $GLOBALS['Args'];
+                               foreach (explode(' ', $params) as $param) {
+                                       if ($set = strpos($param, '=')) {
+                                               $_GET[ substr($param, 0, $set) ] = substr($param, $set + 1);
+                                       }
+                                       elseif (!empty($param)) {
+                                               $Args .= '/'.$param;
+                                       }
+                               }
                                include "$name.php";
                                $html = ob_get_clean();
                        }