part of #6: atom feed for recently updated pastes
authorChristian Weiske <cweiske@cweiske.de>
Thu, 25 Oct 2012 05:48:26 +0000 (07:48 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 25 Oct 2012 05:48:26 +0000 (07:48 +0200)
README.rst
data/templates/feed-updated.htm [new file with mode: 0644]
data/templates/list.htm
www/.htaccess
www/feed-updated.php [new file with mode: 0644]

index 255de2a..ede03d0 100644 (file)
@@ -284,6 +284,7 @@ If you use nginx, place the following lines into your ``server`` block:
 
     rewrite ^/new$ /new.php;
     rewrite ^/feed/new$ /feed-new.php;
+    rewrite ^/feed/updated$ /feed-updated.php;
     rewrite ^/list$ /list.php;
     rewrite ^/list/([0-9]+)$ /list.php?page=$1;
 
diff --git a/data/templates/feed-updated.htm b/data/templates/feed-updated.htm
new file mode 100644 (file)
index 0000000..699dabd
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title>{{title}}: Updated pastes</title>
+ <link href="{{url}}"/>
+ <link rel="self" href="{{feedurl}}"/>
+ <id>{{url}}</id>
+{% set repo = pastes.repos.0 %}
+ <updated>{{repo.modate|date('c')}}</updated>
+
+{% for repo in pastes.repos %}
+ <entry>
+  <id>{{repo.getLink('display', null, true)}}</id>
+  <title>{{repo.getTitle}}</title>
+  <published>{{repo.crdate|date('c')}}</published>
+  <updated>{{repo.modate|date('c')}}</updated>
+  <link rel="alternate" type="text/html" href="{{repo.getLink('display', null, true)}}" />
+  <author>
+   {% set owner=repo.getOwner() %}
+   <name>{{owner.name}}</name>
+   <email>{{owner.email}}</email>
+  </author>
+ </entry>
+{% endfor %}
+</feed>
\ No newline at end of file
index ac3d664..c9768ff 100644 (file)
@@ -3,6 +3,7 @@
 
 {% block meta %}
  <link rel="alternate" type="application/atom+xml" title="New pastes" href="feed/new" />
+ <link rel="alternate" type="application/atom+xml" title="Updated pastes" href="feed/updated" />
 {% endblock %}
 
 {% block content %}
index d18aa34..f3dc267 100644 (file)
@@ -17,6 +17,7 @@ RewriteRule ^fork-remote$ /fork-remote.php
 RewriteRule ^new$ /new.php
 
 RewriteRule ^feed/new$ /feed-new.php
+RewriteRule ^feed/updated$ /feed-updated.php
 
 RewriteRule ^list$ /list.php
 RewriteRule ^list/([0-9]+)$ /list.php?page=$1
diff --git a/www/feed-updated.php b/www/feed-updated.php
new file mode 100644 (file)
index 0000000..679a5d7
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Generate an atom feed with the 10 most recently updated pastes
+ */
+namespace phorkie;
+$reqWritePermissions = false;
+require_once 'www-header.php';
+
+$db = new Database();
+header('Content-Type: application/atom+xml');
+render(
+    'feed-updated',
+    array(
+        'pastes'  => $db->getSearch()->listAll(0, 10, 'modate', 'desc'),
+        'url'     => Tools::fullUrl('/'),
+        'feedurl' => Tools::fullUrl('/feed/updated'),
+    )
+);
+?>