X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/aa4a9fd115357f8d8781220e1f1345df774d6893..7983570288ed2798470a552ec04f64aa646b664a:/article.inc.php diff --git a/article.inc.php b/article.inc.php index dd3d5b2..b676dd0 100644 --- a/article.inc.php +++ b/article.inc.php @@ -16,8 +16,8 @@ function showdate($parts) class ArchiveArticle { - public $raw, $preface, $title, $body; - public $meta = []; + public $raw, $title, $body; # file contents + public $meta = []; # head metadata properties function __construct($path) { @@ -41,8 +41,11 @@ class ArchiveArticle $this->meta = array_combine($meta[1], $meta[2]); # [property => content] } - @list ($this->preface, $this->title, $this->body) = - preg_split('{

(.*?)

\s*}s', $this->raw, 2, PREG_SPLIT_DELIM_CAPTURE); + // find significant contents + $this->body = preg_replace('{}s', '', $this->raw); + if (preg_match('{

(.*?)

\s*(.*)}s', $this->body, $titlematch)) { + list (, $this->title, $this->body) = $titlematch; + } } function __get($col) @@ -74,6 +77,12 @@ class ArchiveArticle return; } + function restricted() + { + $this->handler; + return $this->restricted; + } + function safetitle() { return trim($this->meta['og:title'] ?? strip_tags($this->title)); @@ -128,19 +137,10 @@ class ArchiveArticle return $override; } + # paragraph contents following the page header if any if (preg_match('{ - (?: \s+ | | ]*> )*

\s* (.*?)

- }sx', $this->raw, $bodyp, PREG_OFFSET_CAPTURE)) { - # fallback paragraph contents following the page header - if ($bodyp[1][1] < 512) { - return $bodyp[1][0]; - } - } - - # starting paragraph for documents without title (assumed simple/partial) - if (strpos($this->raw, ']*> \s* )*

\s* (.*?)

- }sx', $this->raw, $bodyp)) { + \G (?> \s+ |
]*> | \[\[[^]]*\]\] )*

\s* (.*?)

+ }sx', $this->body, $bodyp, 0)) { return $bodyp[1]; } } @@ -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 ''.$name.' ontbreekt'; + } + + 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('%s', + "fout in $name: {$e->getMessage()}" + ); + } + } } class PageSearch