summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--functions.php82
-rw-r--r--templates/generated_feed.txt36
2 files changed, 78 insertions, 40 deletions
diff --git a/functions.php b/functions.php
index 37f56d063..26a973679 100644
--- a/functions.php
+++ b/functions.php
@@ -3628,6 +3628,8 @@
function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat,
$limit, $search, $search_mode, $match_on, $view_mode = false) {
+ require_once "lib/MiniTemplator.class.php";
+
$note_style = "float : right; background-color : #fff7d5; border-width : 1px; ".
"padding : 5px; border-style : dashed; border-color : #e7d796;".
"margin-bottom : 1em; color : #9a8c59;";
@@ -3649,69 +3651,69 @@
$feed_site_url = $qfh_ret[2];
$last_error = $qfh_ret[3];
+ $feed_self_url = get_self_url_prefix() .
+ "/backend.php?op=rss&id=-2&key=" .
+ get_feed_access_key($link, -2, false);
+
if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
- print "<?xml version=\"1.0\" encoding=\"utf-8\"?>
- <?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\"?>
- <rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
- xmlns:atom=\"http://www.w3.org/2005/Atom\">
- <channel>";
+ $tpl = new MiniTemplator;
+
+ $tpl->readTemplateFromFile("templates/generated_feed.txt");
+
+ $tpl->setVariable('FEED_TITLE', $feed_title);
+ $tpl->setVariable('VERSION', VERSION);
+ $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url));
- if (PUBSUBHUBBUB_HUB && $feed == -2) {
- print "<atom:link rel='hub' href='".PUBSUBHUBBUB_HUB."'/>";
+ if (PUBSUBHUBBUB_HUB) {
+ $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB));
+ $tpl->addBlock('feed_hub');
}
- print "<title>$feed_title</title>
- <link>$feed_site_url</link>
- <description>Feed generated by Tiny Tiny RSS</description>";
+ $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()));
while ($line = db_fetch_assoc($result)) {
- print "<item>";
- print "<guid>" . htmlspecialchars($line["guid"]) . "</guid>";
- print "<link>" . htmlspecialchars($line["link"]) . "</link>";
+ $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']));
+ $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']));
+ $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']));
+ $tpl->setVariable('ARTICLE_EXCERPT',
+ truncate_string(strip_tags($line["content_preview"]), 100, '...'));
+ $tpl->setVariable('ARTICLE_CONTENT',
+ sanitize_rss($link, $line["content_preview"], false, $owner_uid));
+
+ $tpl->setVariable('ARTICLE_UPDATED', date('c', strtotime($line["updated"])));
+ $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']));
$tags = get_article_tags($link, $line["id"], $owner_uid);
foreach ($tags as $tag) {
- print "<category>" . htmlspecialchars($tag) . "</category>";
+ $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag));
+ $tpl->addBlock('category');
}
- $rfc822_date = date('r', strtotime($line["updated"]));
-
- print "<pubDate>$rfc822_date</pubDate>";
-
- if ($line["author"]) {
- print "<author>" . htmlspecialchars($line["author"]) . "</author>";
- }
-
- print "<title><![CDATA[" .
- htmlspecialchars($line["title"]) . "]]></title>";
-
- print "<description><![CDATA[";
-
- if ($line["note"]) {
- print "<div style='$note_style'>";
- print $line["note"];
- print "</div>";
- }
-
- print sanitize_rss($link, $line["content_preview"], false, $owner_uid);
- print "]]></description>";
-
$enclosures = get_article_enclosures($link, $line["id"]);
foreach ($enclosures as $e) {
$type = htmlspecialchars($e['content_type']);
$url = htmlspecialchars($e['content_url']);
$length = $e['duration'];
- print "<enclosure url=\"$url\" type=\"$type\" length=\"$length\"/>";
+
+ $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url);
+ $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type);
+ $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length);
+
+ $tpl->addBlock('enclosure');
}
- print "</item>";
- }
+ $tpl->addBlock('entry');
+ }
- print "</channel></rss>";
+ $tmp = "";
+
+ $tpl->addBlock('feed');
+ $tpl->generateOutputToString($tmp);
+ print $tmp;
}
function getCategoryTitle($link, $cat_id) {
diff --git a/templates/generated_feed.txt b/templates/generated_feed.txt
new file mode 100644
index 000000000..9631d4cf8
--- /dev/null
+++ b/templates/generated_feed.txt
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- $BeginBlock feed -->
+<feed xmlns="http://www.w3.org/2005/Atom">
+<title>${FEED_TITLE}</title>
+<generator uri="http://tt-rss.org/">Tiny Tiny RSS/${VERSION}</generator>
+<updated>${ARTICLE_UPDATED}</updated>
+<id>${FEED_URL}</id>
+<link href="${FEED_URL}" rel="self"/>
+<!-- $BeginBlock feed_hub -->
+<link href="${HUB_URL}" rel="hub"/>
+<!-- $EndBlock feed_hub -->
+<link href="${SELF_URL}" rel="alternate"/>
+<!-- $BeginBlock entry -->
+<entry>
+ <id>${ARTICLE_ID}</id>
+ <link href="${ARTICLE_LINK}" rel="alternate" type="text/html"/>
+ <title>${ARTICLE_TITLE}</title>
+ <summary type="html"><![CDATA[${ARTICLE_EXCERPT}]]></summary>
+ <content type="html"><![CDATA[${ARTICLE_CONTENT}]]></content>
+ <updated>${ARTICLE_UPDATED}</updated>
+ <author><name>${ARTICLE_AUTHOR}</name></author>
+<!-- $BeginBlock category -->
+ <category term="${ARTICLE_CATEGORY}"/>
+<!-- $EndBlock category -->
+<!-- $BeginBlock enclosure -->
+ <link rel="enclosure"
+ type="${ARTICLE_ENCLOSURE_TYPE}"
+ length="${ARTICLE_ENCLOSURE_LENGTH}"
+ href="${ARTICLE_ENCLOSURE_URL}"/>
+<!-- $EndBlock enclosure -->
+</entry>
+<!-- $EndBlock entry -->
+<!-- $EndBlock feed -->
+</feed>
+<!-- vim:ft=xml
+ -->