X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/f547127c637332119b42329ca78d0e1a659d9739..714373870efc4f371ace2d324530a2354a696da7:/article.inc.php diff --git a/article.inc.php b/article.inc.php index 30de51e..9e92094 100644 --- a/article.inc.php +++ b/article.inc.php @@ -7,9 +7,9 @@ class ArchiveArticle function __construct($path) { - $this->page = preg_replace('{^\.(?:/|$)}', '', $path); - $this->link = preg_replace('{(?:(?:/|^)index)?\.html$}', '', $this->page); - $this->raw($this->page); + $this->file = preg_replace('{^\.(?:/|$)}', '', $path); + $this->link = preg_replace('{(?:(?:/|^)index)?\.html$}', '', $this->file); + $this->raw($this->file); } function raw($page) @@ -65,6 +65,18 @@ class ArchiveArticle return; } + function index() + { + $this->handler; + if (empty($this->handler)) { + return; + } + $User = NULL; + $Page = $this; + $res = include "./{$this->handler}/index.php"; + return $res; + } + function restricted() { $this->handler; @@ -77,12 +89,12 @@ class ArchiveArticle } function name() { - return $this->safetitle ?: $this->link; + return $this->safetitle ?: htmlspecialchars($this->link); } function last() { - return filemtime($this->page); + return filemtime($this->file); } function lastiso() { @@ -91,7 +103,7 @@ class ArchiveArticle function dateparts() { - preg_match('< / (\d{4}) [/-] (\d{2}) (?:- (\d{2}) )? - >x', $this->page, $ymd); + preg_match('< / (\d{4}) [/-] (\d{2}) (?:- (\d{2}) )? - >x', $this->file, $ymd); array_shift($ymd); return $ymd; } @@ -149,9 +161,13 @@ class ArchiveArticle function thumb($size = '300x') { if (!$this->image or $this->image[0] !== '/') return; + if (preg_match('{^/thumb/\D}', $this->image)) { + return ltrim($this->image, '/'); + } return preg_replace( - ['{^(?:/thumb/[^/]*)?}', '/\.groot(?=\.\w+$)/'], ["thumb/$size", ''], - $this->image + ['{^(?:/thumb/[^/]*)?}', '/\.groot(?=\.\w+$)/', '/(?:\.jpg)?$/'], + [ "thumb/$size", '', '.jpg' ], + $this->image, 1 ); } @@ -205,8 +221,13 @@ class ArchiveArticle # keep either login or logout parts depending on user level global $User; - $hideclass = $User && property_exists($User, 'login') && $User->login ? 'logout' : 'login'; - $doc = preg_replace('{\s*<([a-z]+) class="'.$hideclass.'">.*?}s', '', $doc); + $userexists = $User && property_exists($User, 'login') && $User->login; + if (! ($userexists and $User->admin("edit {$this->link}")) ) { + # remove matching elements until first corresponding closing tag + $hideclass = $userexists ? 'logout' : 'login'; + $tagmatch = '<([a-z]+) class="'.$hideclass.'"[^>]*>'; + $doc = preg_replace("{\s*{$tagmatch}.*?}s", '', $doc); + } return preg_replace_callback( '{ \[\[ ([^] ]+) ([^]]*) \]\] }x', @@ -228,6 +249,8 @@ class ArchiveArticle class PageSearch { + public $handlers = []; + function __construct($path = '.') { $this->iterator = new RecursiveCallbackFilterIterator( @@ -237,6 +260,11 @@ class PageSearch # skip hidden files and directories return FALSE; } + if (file_exists($current->getFilename() . '/index.php')) { + # contents better provided by handler code + $this->handlers[ $current->getPathname() ] = $current; + return FALSE; + } if ($current->isLink()) { # ignore symlinks, original contents only return FALSE; @@ -254,12 +282,12 @@ class PageSearch function files() { # order alphabetically by link - $dir = iterator_to_array(new RecursiveIteratorIterator($this->iterator)); - array_walk($dir, function (&$row, $name) { - # prepare values for sorting (directory index first) - $row = preg_replace('{/index\.html$}', '', $name); - }); - asort($dir); + $dir = []; + foreach (new RecursiveIteratorIterator($this->iterator) as $name) { + $article = new ArchiveArticle($name); + $dir[$article->link] = $article; + } + ksort($dir); return $dir; } }