mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #407 from ksdhans/patch-2
Add RSS feeds for categories and tags
This commit is contained in:
commit
35c5357cc6
@ -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, $tag->getLink());
|
||||||
|
} 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, $category->getLink());
|
||||||
|
} 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->Link());
|
||||||
|
|
||||||
$this->extend('updateRss', $rss);
|
|
||||||
|
|
||||||
return $rss->outputToBrowser();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1093,4 +1098,34 @@ class Blog_Controller extends Page_Controller
|
|||||||
{
|
{
|
||||||
return $this->Link('rss');
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user