page: move showdate() into formatting include
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 5 Dec 2020 08:15:51 +0000 (09:15 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 19 Dec 2020 02:01:43 +0000 (03:01 +0100)
Do not enforce presentation style in articles.  Separate from class,
allowing site override if wanted.

article.inc.php
format.inc.php [new file with mode: 0644]
nieuws/index.php
page.php
widget/nieuws.php

index 47a08a7eb67ced8af7a9d30704c61414f91c1797..2104ef9d65025e0b3a0687d0d49dc0a0e9ff34ce 100644 (file)
@@ -1,19 +1,4 @@
 <?php
-global $monthname;
-$monthname = ['?',
-       'januari', 'februari', 'maart', 'april', 'mei', 'juni',
-       'juli', 'augustus', 'september', 'oktober', 'november', 'december',
-];
-
-function showdate($parts)
-{
-       global $monthname;
-       return implode(' ', array_filter([
-               intval(@$parts[2]), $parts[1] > 0 ? $monthname[intval($parts[1])] : '', $parts[0],
-               count($parts) > 5 ? "$parts[3]:$parts[4]" : '',
-       ]));
-}
-
 class ArchiveArticle
 {
        public $raw, $title, $body; # file contents
@@ -114,10 +99,6 @@ class ArchiveArticle
        {
                return implode('-', $this->dateparts()) . 'T12:00:00+02:00';
        }
-       function date()
-       {
-               return showdate($this->dateparts);
-       }
 
        function story()
        {
diff --git a/format.inc.php b/format.inc.php
new file mode 100644 (file)
index 0000000..10908f3
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+global $monthname;
+$monthname = ['?',
+       'januari', 'februari', 'maart', 'april', 'mei', 'juni',
+       'juli', 'augustus', 'september', 'oktober', 'november', 'december',
+];
+
+function showdate($parts)
+{
+       global $monthname;
+       return implode(' ', array_filter([
+               intval(@$parts[2]), $parts[1] > 0 ? $monthname[intval($parts[1])] : '', $parts[0],
+               count($parts) > 5 ? "$parts[3]:$parts[4]" : '',
+       ]));
+}
+
index 33b61fb49885f00c56f46de82f2f6d78cd37dde8..61ba993d39d4d4a571ee0b64a3216d20e4f9a76d 100644 (file)
@@ -13,7 +13,7 @@ if ($page and !is_numeric($page)) {
                $Page->title = $edit;
        }
        if ($Page->dateparts) {
-               $Page->place[1] = ' <small class="date">'.$Page->date.'</small>';
+               $Page->place[1] = ' <small class="date">'.showdate($Page->dateparts).'</small>';
        }
        else {
                $Page->place[1] = '';
index a4440cb2ff7447e9b1f49f2eb7b4e167f7a9102b..f493c7fb04f8cca4619dedd1ba66b2985da9f334 100644 (file)
--- a/page.php
+++ b/page.php
@@ -83,6 +83,8 @@ if (isset($Page->raw)) {
 
 # output dynamic and/or static html
 
+include_once 'format.inc.php';
+
 ob_start();
 if ($Page->handler and !require("./{$Page->handler}/index.php")) {
        # replace contents by code output on false return
index 9cf427cf23bfad67d8b47d92f09dd97f6e627363..c12efc8db3348b5b262f1c24dfe77357832bc4d5 100644 (file)
@@ -17,7 +17,7 @@ function shownews($input, $limit = 1000)
                print '<div>';
                printf(
                        '<h3><a href="/%s">%s <small class="date">%s</small></a></h3>',
-                       $article->link, $article->title, $article->date
+                       $article->link, $article->title, showdate($article->dateparts)
                );
                print $article->story;
                print '</div>';