Merge pull request #407 from ksdhans/patch-2

Add RSS feeds for categories and tags
This commit is contained in:
Michael Strong 2016-06-17 13:13:34 +12:00 committed by GitHub
commit 35c5357cc6

View File

@ -644,8 +644,8 @@ class Blog_Controller extends Page_Controller
* @var array
*/
private static $url_handlers = array(
'tag/$Tag!' => 'tag',
'category/$Category!' => 'category',
'tag/$Tag!/$Rss' => 'tag',
'category/$Category!/$Rss' => 'category',
'archive/$Year!/$Month/$Day' => 'archive',
'profile/$URLSegment!' => 'profile',
);
@ -834,7 +834,12 @@ class Blog_Controller extends Page_Controller
if ($tag) {
$this->blogPosts = $tag->BlogPosts();
return $this->render();
if($this->isRSS()) {
return $this->rssFeed($this->blogPosts, $tag->getLink());
} else {
return $this->render();
}
}
$this->httpError(404, 'Not Found');
@ -874,7 +879,11 @@ class Blog_Controller extends Page_Controller
if ($category) {
$this->blogPosts = $category->BlogPosts();
return $this->render();
if($this->isRSS()) {
return $this->rssFeed($this->blogPosts, $category->getLink());
} else {
return $this->render();
}
}
$this->httpError(404, 'Not Found');
@ -1049,11 +1058,7 @@ class Blog_Controller extends Page_Controller
$this->blogPosts = $dataRecord->getBlogPosts();
$rss = new RSSFeed($this->blogPosts, $this->Link(), $this->MetaTitle, $this->MetaDescription);
$this->extend('updateRss', $rss);
return $rss->outputToBrowser();
return $this->rssFeed($this->blogPosts, $this->Link());
}
/**
@ -1093,4 +1098,34 @@ class Blog_Controller extends Page_Controller
{
return $this->Link('rss');
}
/**
* Displays an RSS feed of the given blog posts.
*
* @param DataList $blogPosts
* @param string $link
*
* @return string
*/
protected function rssFeed($blogPosts, $link)
{
$rss = new RSSFeed($blogPosts, $link, $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(is_string($rss) && strcasecmp($rss, "rss") == 0) {
return true;
} else {
return false;
}
}
}