From 20e43935fca9d1fa8838782cf714c40cc286acbc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 4 Apr 2011 13:30:33 +0400 Subject: [PATCH] generate template-enabled Atom feeds instead of makeshift rss --- functions.php | 82 ++++++++++++++++++------------------ templates/generated_feed.txt | 36 ++++++++++++++++ 2 files changed, 78 insertions(+), 40 deletions(-) create mode 100644 templates/generated_feed.txt 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 " - - - "; + $tpl = new MiniTemplator; - if (PUBSUBHUBBUB_HUB && $feed == -2) { - print ""; + $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 "$feed_title - $feed_site_url - Feed generated by Tiny Tiny RSS"; + $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix())); while ($line = db_fetch_assoc($result)) { - print ""; - print "" . htmlspecialchars($line["guid"]) . ""; - print "" . htmlspecialchars($line["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 "" . htmlspecialchars($tag) . ""; + $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag)); + $tpl->addBlock('category'); } - $rfc822_date = date('r', strtotime($line["updated"])); - - print "$rfc822_date"; - - if ($line["author"]) { - print "" . htmlspecialchars($line["author"]) . ""; - } - - print "<![CDATA[" . - htmlspecialchars($line["title"]) . "]]>"; - - print ""; - print $line["note"]; - print ""; - } - - print sanitize_rss($link, $line["content_preview"], false, $owner_uid); - print "]]>"; - $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 ""; + + $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url); + $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type); + $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length); + + $tpl->addBlock('enclosure'); } - print ""; - } + $tpl->addBlock('entry'); + } - print ""; + $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 @@ + + + +${FEED_TITLE} +Tiny Tiny RSS/${VERSION} +${ARTICLE_UPDATED} +${FEED_URL} + + + + + + + + ${ARTICLE_ID} + + ${ARTICLE_TITLE} + + + ${ARTICLE_UPDATED} + ${ARTICLE_AUTHOR} + + + + + + + + + + +