nieuws/feed: atom export of articles
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 25 Aug 2018 21:51:17 +0000 (23:51 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 25 Aug 2018 22:14:58 +0000 (00:14 +0200)
nieuws.inc.php
nieuws/feed/index.php [new file with mode: 0644]

index a925a9139d331c2b24c65e7d022c384d6969fd1c..c5dfa2331344503746cca81fbeebcd9128dacfb4 100644 (file)
@@ -42,10 +42,30 @@ class ArchiveArticle
                return strip_tags($this->title);
        }
 
+       function last()
+       {
+               return filemtime($this->page);
+       }
+
+       function lastiso()
+       {
+               return date(DATE_ATOM, $this->last);
+       }
+
+       function dateparts()
+       {
+               preg_match('</(\d{4})/(\d{2})-(\d{2})->', $this->page, $ymd);
+               return $ymd;
+       }
+
+       function dateiso()
+       {
+               return implode('-', $this->dateparts());
+       }
+
        function date()
        {
-               if (!preg_match('</(\d{4})/(\d{2})-(\d{2})->', $this->page, $parts)) return;
-               return showdate($parts);
+               return showdate($this->dateparts);
        }
 
        function body()
diff --git a/nieuws/feed/index.php b/nieuws/feed/index.php
new file mode 100644 (file)
index 0000000..eff9203
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+ob_clean();
+print '<?xml version="1.0" encoding="utf-8"?>';
+$siteref = 'http://'.$_SERVER['HTTP_HOST'];
+?>
+
+<feed xmlns="http://www.w3.org/2005/Atom">
+       <title>Lijtweg.nl</title>
+       <subtitle>Nieuwsberichten</subtitle>
+       <id><?= $siteref ?></id>
+       <link href="<?= $siteref ?>" />
+       <link href="<?= $siteref . $_SERVER['REQUEST_URI'] ?>" rel="self" />
+       <author><name>Lijtweg</name></author>
+<?php
+include 'nieuws.inc.php';
+$root = preg_replace('{/feed$}', '', $Page) . "/2???";
+$pages = array_reverse(glob("$root/*.html"));
+
+foreach ($pages as $i => $page) {
+       $article = new ArchiveArticle($page);
+       if (!$i) {
+               // feed metadata from top (most recent) article
+               print "\t<updated>{$article->lastiso}</updated>\n";
+       }
+?>
+
+       <entry>
+               <id><?= $siteref . '/' . $article->link ?></id>
+               <link href="/<?= $article->link ?>" />
+               <title><?= $article->title ?></title>
+               <published><?= $article->dateiso ?></published>
+               <updated><?= $article->lastiso ?></updated>
+               <content type="html"><?= htmlspecialchars($article->body) ?></content>
+<?php
+       if ($article->thumb) {
+               printf("\t\t".'<link rel="enclosure" type="%s" length="%d" href="%s" />'."\n",
+                       'image/jpeg', filesize($article->thumb), "$siteref/{$article->thumb}"
+               );
+       }
+?>
+       </entry>
+<?php
+}
+?>
+</feed>
+<?php
+exit;