page: move placeholder_include() to widget method
[minimedit.git] / article.inc.php
index acd219d164aab81397d9da33ef104148f3e23574..b676dd0c5e34537bb17732e13dd5a6b5f35628ff 100644 (file)
@@ -170,6 +170,38 @@ class ArchiveArticle
                        $this->image
                );
        }
+
+       function widget($name, $params = [])
+       {
+               $path = stream_resolve_include_path("widget/$name.php");
+               if (!file_exists($path)) {
+                       return '<strong class="warn"><em>'.$name.'</em> ontbreekt</strong>';
+               }
+
+               ob_start();
+               $Page = clone $this;
+               $Page->handler = $Page->handler . $Page->path; // .= with explicit getter
+               $Page->path = '';
+               $Place = $GLOBALS['Place'];
+               foreach ($params as $param) {
+                       if ($set = strpos($param, '=')) {
+                               $Place[ substr($param, 0, $set) ] = substr($param, $set + 1);
+                       }
+                       elseif (!empty($param)) {
+                               $Page->path .= '/'.$param;
+                       }
+               }
+               $Page->link .= $Page->path;
+               try {
+                       include "widget/$name.php";
+                       return ob_get_clean();
+               }
+               catch (Exception $e) {
+                       return sprintf('<strong class="warn">%s</strong>',
+                               "fout in <em>$name</em>: {$e->getMessage()}"
+                       );
+               }
+       }
 }
 
 class PageSearch