From 3080864c4cd697bd083f9fd0315f0ffababd593d Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sun, 26 Aug 2018 00:14:56 +0200 Subject: [PATCH] nieuws: ArchiveArticle class to access news pages Similar to User in auth.inc.php. --- nieuws.inc.php | 97 +++++++++++++++++++++++++++--------------------- nieuws/index.php | 8 +++- 2 files changed, 62 insertions(+), 43 deletions(-) diff --git a/nieuws.inc.php b/nieuws.inc.php index 524109d..a925a91 100644 --- a/nieuws.inc.php +++ b/nieuws.inc.php @@ -14,46 +14,59 @@ function showdate($parts) ])); } -function shownewsdate($url) +class ArchiveArticle { - if (!preg_match('', $url, $parts)) return; - return showdate($parts); -} + function __construct($path) + { + $this->page = $path; + $this->link = preg_replace('/\.html$/', '', $path); + } -function shownewsimage($url) -{ - foreach (['jpg', 'png'] as $ext) { - if (file_exists("$url.$ext")) { - return "$url.$ext"; - } + function __get($col) + { + return $this->$col = $this->$col(); # run method and cache } -} -function shownewsarticle($url, $link = TRUE, $title = NULL) -{ - $html = ob_get_clean(); - $date = shownewsdate($url); - ob_start(); - print $title ?: '\1'; - print '[[1]]'; + function file() + { + return fopen($this->page, 'r'); + } + + function title() + { + return preg_replace('{

(.*)

\s*}', '\1', fgets($this->file)); + } + + function safetitle() + { + return strip_tags($this->title); + } + + function date() + { + if (!preg_match('', $this->page, $parts)) return; + return showdate($parts); + } - $title = sprintf( - $link ? '

%s

' : '

%s

', - getoutput([1 => ' '.$date.'']), - $url - ); + function body() + { + return fread($this->file, filesize($this->page)); + } - if (!$link and $image = shownewsimage($url)) { - global $Place; - $Place['image'] = "https://lijtweg.nl/thumb/600x/".$image; - ob_start(); - print '[[1]]'; - $html .= getoutput([ - 1 => sprintf("\n".'

', "/thumb/640x/".$image), - ]); + function image() + { + foreach (['jpg', 'png'] as $ext) { + if (file_exists("{$this->link}.$ext")) { + return "{$this->link}.$ext"; + } + } } - return preg_replace('{

(.*?)

}', $title, $html); + function thumb($size = '300x') + { + if ($this->image) + return "thumb/$size/{$this->image}"; + } } function shownews($input, $limit = 1000) @@ -61,15 +74,17 @@ function shownews($input, $limit = 1000) if (!is_array($input)) $input = glob("$input/*.html"); print '