login/edit: generic multi-values declaration
[minimedit.git] / page.php
index 2c3a68ae4e172c86524bbe91004c551bec0794b3..33a1f4440ed5469e3aee9e7be5c27913606053f2 100644 (file)
--- a/page.php
+++ b/page.php
@@ -23,12 +23,35 @@ function getoutput($blocks = [])
        }
 
        return preg_replace_callback(
-               '< \[\[ ([^]]*) \]\] >x',
+               '< \[\[ ([^] ]+) ([^]]*) \]\] >x',
                function ($sub) use ($blocks) {
-                       list ($placeholder, $name) = $sub;
+                       list ($placeholder, $name, $params) = $sub;
                        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>';
                        }
@@ -130,15 +153,17 @@ print "</div>\n\n";
 
 # execute dynamic code
 
-$Place = [
-       'user'  => $User['name'],
-       'url'   => htmlspecialchars($_SERVER['REQUEST_URI']),
-];
+$Place = [];
 
 if ($Page) {
        $found |= require "./$Page/index.php";
 }
 
+$Place += [
+       'user'  => empty($User) ? '' : $User['name'],
+       'url'   => htmlspecialchars($_SERVER['REQUEST_URI']),
+];
+
 # global html
 
 if (!$found) {