X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/1d0e94b9030f08157198b6e4911491698e9d2f5f..4486f69521f03fe56549394f13f7c529f57fa962:/article.inc.php diff --git a/article.inc.php b/article.inc.php index a9c6ce4..f56b2be 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) @@ -89,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() { @@ -103,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; } @@ -220,8 +220,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', @@ -276,12 +281,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; } }