Part of #6: atom feed for new pastes
authorChristian Weiske <cweiske@cweiske.de>
Wed, 24 Oct 2012 21:16:11 +0000 (23:16 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 24 Oct 2012 21:16:11 +0000 (23:16 +0200)
README.rst
data/templates/feed-new.htm [new file with mode: 0644]
data/templates/list.htm
www/.htaccess
www/feed-new.php [new file with mode: 0644]

index f805e77..255de2a 100644 (file)
@@ -283,6 +283,7 @@ If you use nginx, place the following lines into your ``server`` block:
     rewrite ^/([0-9]+)/tool/([^/]+)/(.+)$ /tool.php?id=$1&tool=$2&file=$3;
 
     rewrite ^/new$ /new.php;
+    rewrite ^/feed/new$ /feed-new.php;
     rewrite ^/list$ /list.php;
     rewrite ^/list/([0-9]+)$ /list.php?page=$1;
 
diff --git a/data/templates/feed-new.htm b/data/templates/feed-new.htm
new file mode 100644 (file)
index 0000000..c0d5fa5
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title>{{title}}: New pastes</title>
+ <link href="{{url}}"/>
+ <link rel="self" href="{{feedurl}}"/>
+ <id>{{url}}</id>
+{% set repo = pastes.repos.0 %}
+ <updated>{{repo.crdate|date('c')}}</updated>
+
+{% for repo in pastes.repos %}
+ <entry>
+  <id>{{repo.getLink('display', null, true)}}</id>
+  <title>{{repo.getTitle}}</title>
+  <updated>{{repo.crdate|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 0315119..ac3d664 100644 (file)
@@ -1,6 +1,10 @@
 {% extends "base.htm" %}
 {% block title %}List of all pastes{% endblock %}
 
+{% block meta %}
+ <link rel="alternate" type="application/atom+xml" title="New pastes" href="feed/new" />
+{% endblock %}
+
 {% block content %}
 <div style="height: 1em"></div>
 <ul class="nav nav-pills nav-stacked">
index 03bbf60..d18aa34 100644 (file)
@@ -16,6 +16,8 @@ RewriteRule ^([0-9]+)/tool/([^/]+)/(.+)$ /tool.php?id=$1&tool=$2&file=$3
 RewriteRule ^fork-remote$ /fork-remote.php
 RewriteRule ^new$ /new.php
 
+RewriteRule ^feed/new$ /feed-new.php
+
 RewriteRule ^list$ /list.php
 RewriteRule ^list/([0-9]+)$ /list.php?page=$1
 
diff --git a/www/feed-new.php b/www/feed-new.php
new file mode 100644 (file)
index 0000000..a462808
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Generate an atom feed with the 10 most recently created pastes
+ */
+namespace phorkie;
+$reqWritePermissions = false;
+require_once 'www-header.php';
+
+$db = new Database();
+header('Content-Type: application/atom+xml');
+render(
+    'feed-new',
+    array(
+        'pastes'  => $db->getSearch()->listAll(0, 10, 'crdate', 'desc'),
+        'url'     => Tools::fullUrl('/'),
+        'feedurl' => Tools::fullUrl('/feed/new'),
+    )
+);
+?>