Add RSS feeds for categories and tags

This patch adds RSS feeds for tags and categories. The RSS feeds are at the following URLs:
- */category/<category-name>/rss
- */tag/<tag-name>/rss
This commit is contained in:
ksdhans 2016-06-13 23:20:07 +12:00 committed by GitHub
parent 09bdf60aa4
commit 073fca5f0d

View File

@ -644,8 +644,8 @@ class Blog_Controller extends Page_Controller
* @var array * @var array
*/ */
private static $url_handlers = array( private static $url_handlers = array(
'tag/$Tag!' => 'tag', 'tag/$Tag!/$Rss' => 'tag',
'category/$Category!' => 'category', 'category/$Category!/$Rss' => 'category',
'archive/$Year!/$Month/$Day' => 'archive', 'archive/$Year!/$Month/$Day' => 'archive',
'profile/$URLSegment!' => 'profile', 'profile/$URLSegment!' => 'profile',
); );
@ -834,8 +834,13 @@ class Blog_Controller extends Page_Controller
if ($tag) { if ($tag) {
$this->blogPosts = $tag->BlogPosts(); $this->blogPosts = $tag->BlogPosts();
if($this->isRSS()) {
return $this->rssFeed($this->blogPosts);
} else {
return $this->render(); return $this->render();
} }
}
$this->httpError(404, 'Not Found'); $this->httpError(404, 'Not Found');
@ -874,8 +879,12 @@ class Blog_Controller extends Page_Controller
if ($category) { if ($category) {
$this->blogPosts = $category->BlogPosts(); $this->blogPosts = $category->BlogPosts();
if($this->isRSS()) {
return $this->rssFeed($this->blogPosts);
} else {
return $this->render(); return $this->render();
} }
}
$this->httpError(404, 'Not Found'); $this->httpError(404, 'Not Found');
@ -1049,11 +1058,7 @@ class Blog_Controller extends Page_Controller
$this->blogPosts = $dataRecord->getBlogPosts(); $this->blogPosts = $dataRecord->getBlogPosts();
$rss = new RSSFeed($this->blogPosts, $this->Link(), $this->MetaTitle, $this->MetaDescription); return $this->rssFeed($this->blogPosts);
$this->extend('updateRss', $rss);
return $rss->outputToBrowser();
} }
/** /**
@ -1093,4 +1098,30 @@ class Blog_Controller extends Page_Controller
{ {
return $this->Link('rss'); return $this->Link('rss');
} }
/**
* Displays an RSS feed of the given blog posts.
*
* @return string
*/
public function rssFeed($blogPosts)
{
$rss = new RSSFeed($blogPosts, $this->Link() . 'category/general/', $this->MetaTitle, $this->MetaDescription);
$this->extend('updateRss', $rss);
return $rss->outputToBrowser();
}
/**
* Returns true if the $Rss sub-action for categories/tags has been set to "rss"
*/
private function isRSS() {
$rss = $this->request->param('Rss');
if($rss && strcasecmp($rss, "rss") == 0) {
return true;
} else {
return false;
}
}
} }