generate template-enabled Atom feeds instead of makeshift rss

This commit is contained in:
Andrew Dolgov 2011-04-04 13:30:33 +04:00
parent 5de271146b
commit 20e43935fc
2 changed files with 78 additions and 40 deletions

View File

@ -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;
if (PUBSUBHUBBUB_HUB && $feed == -2) {
print "<atom:link rel='hub' href='".PUBSUBHUBBUB_HUB."'/>";
$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) {
$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) {

View File

@ -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
-->