4 'januari', 'februari', 'maart', 'april', 'mei', 'juni',
5 'juli', 'augustus', 'september', 'oktober', 'november', 'december',
8 function showdate($parts)
11 return implode(' ', array_filter([
12 intval(@$parts[2]), $parts[1] > 0 ? $monthname[intval($parts[1])] : '', $parts[0],
13 count($parts) > 5 ? "$parts[3]:$parts[4]" : '',
19 public $raw, $title, $body; # file contents
20 public $meta = []; # head metadata properties
22 function __construct($path)
24 $this->page = preg_replace('{^\.(?:/|$)}', '', $path);
25 $this->link = preg_replace('{(?:(?:/|^)index)?\.html$}', '', $this->page);
26 $this->raw($this->page);
31 if (!file_exists($page)) {
34 $this->raw = file_get_contents($page);
37 \G <meta \s+ property="( [^"]+ )" \s+ content="( [^"]* )" > \s*
38 }x', $this->raw, $meta)) {
39 $matchlen = array_sum(array_map('strlen', $meta[0]));
40 $this->raw = substr($this->raw, $matchlen); # delete matched contents
41 $this->meta = array_combine($meta[1], $meta[2]); # [property => content]
44 // find significant contents
45 $this->body = preg_replace('{<aside\b.*?</aside>}s', '', $this->raw);
46 if (preg_match('{<h2>(.*?)</h2>\s*(.*)}s', $this->body, $titlematch)) {
47 list (, $this->title, $this->body) = $titlematch;
55 return $this->$col = $this->$col(); # run method and cache
62 $this->restricted = FALSE;
64 if (file_exists("$path/.private")) {
65 $this->restricted = $path;
68 if (file_exists("$path/index.php")) {
72 $up = strrpos($path, '/');
73 $this->path = substr($path, $up) . $this->path;
74 $path = substr($path, 0, $up);
85 return $this->restricted;
90 return trim($this->meta['og:title'] ?? strip_tags($this->title));
94 return $this->safetitle ?: $this->link;
99 return filemtime($this->page);
103 return date(DATE_ATOM, $this->last);
108 preg_match('< / (\d{4}) [/-] (\d{2}) (?:- (\d{2}) )? - >x', $this->page, $ymd);
114 return implode('-', $this->dateparts()) . 'T12:00:00+02:00';
118 return showdate($this->dateparts);
124 (?: < (?: p | figure [^>]* ) >\s* )+ (<img\ [^>]*>) | \n <hr\ />
125 }x', $this->body, $img, PREG_OFFSET_CAPTURE) ) {
126 # strip part after matching divider (image)
127 if (isset($img[1])) {
128 $this->img = $img[1][0];
130 return substr($this->body, 0, $img[0][1]);
137 if ($override = @$this->meta['og:description']) {
138 # prefer specific page description if found in metadata
142 # paragraph contents following the page header if any
144 \G (?> \s+ | <div [^>]*> | \[\[[^]]*\]\] )* <p> \s* (.*?) </p>
145 }sx', $this->body, $bodyp, 0)) {
158 if ($override = @$this->meta['og:image']) {
159 # prefer specific page image if found in metadata
163 if ( preg_match('/\bsrc="([^"]*)"/', $this->img, $src) ) {
167 function thumb($size = '300x')
169 if (!$this->image or $this->image[0] !== '/') return;
171 ['{^(?:/thumb/[^/]*)?}', '/\.groot(?=\.\w+$)/'], ["thumb/$size", ''],
176 function widget($name, $params = [])
178 $path = stream_resolve_include_path("widget/$name.php");
179 if (!file_exists($path)) {
180 return '<strong class="warn"><em>'.$name.'</em> ontbreekt</strong>';
185 $Page->handler = $Page->handler . $Page->path; // .= with explicit getter
187 $Place = $GLOBALS['Place'];
188 foreach ($params as $param) {
189 if ($set = strpos($param, '=')) {
190 $Place[ substr($param, 0, $set) ] = substr($param, $set + 1);
192 elseif (!empty($param)) {
193 $Page->path .= '/'.$param;
196 $Page->link .= $Page->path;
198 include "widget/$name.php";
199 return ob_get_clean();
201 catch (Exception $e) {
202 return sprintf('<strong class="warn">%s</strong>',
203 "fout in <em>$name</em>: {$e->getMessage()}"
208 function render($blocks = [])
210 $doc = ob_get_clean();
212 if (!empty($blocks['warn'])) {
213 $warn = '<p class="warn">[[warn]]</p>';
214 if ($offset = strpos($doc, '</h2>')) {
215 $doc = substr_replace($doc, "\n\n".$warn, $offset + 5, 0);
218 $doc = $warn . "\n\n" . $doc;
222 # keep either login or logout parts depending on user level
224 $hideclass = $User && property_exists($User, 'login') && $User->login ? 'logout' : 'login';
225 $doc = preg_replace('{\s*<([a-z]+) class="'.$hideclass.'">.*?</\1>}s', '', $doc);
227 return preg_replace_callback(
228 '{ \[\[ ([^] ]+) ([^]]*) \]\] }x',
229 function ($sub) use ($blocks) {
230 list ($placeholder, $name, $params) = $sub;
231 $html = $blocks[$name] ??
232 $this->widget($name, explode(' ', $params));
233 if (empty($html) or $html[0] != '<') {
234 $html = "<span>$html</span>";
236 $attr = sprintf(' data-dyn="%s"', is_numeric($name) ? '' : $name.$params);
237 # contents with identifier in first tag
238 return preg_replace( '/(?=>)/', $attr, $html, 1);
247 function __construct($path = '.')
249 $this->iterator = new RecursiveCallbackFilterIterator(
250 new RecursiveDirectoryIterator($path),
251 function ($current) {
252 if ($current->getFilename()[0] === '.') {
253 # skip hidden files and directories
256 if ($current->isLink()) {
257 # ignore symlinks, original contents only
260 if ($current->isDir()) {
261 # traverse subdirectories unless untracked in any amount
262 return !file_exists("$current/.gitignore");
265 return preg_match('/(?<!\.inc)\.html$/', $current->getFilename());
272 # order alphabetically by link
273 $dir = iterator_to_array(new RecursiveIteratorIterator($this->iterator));
274 array_walk($dir, function (&$row, $name) {
275 # prepare values for sorting (directory index first)
276 $row = preg_replace('{/index\.html$}', '', $name);