mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
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:
parent
09bdf60aa4
commit
073fca5f0d
@ -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,7 +834,12 @@ class Blog_Controller extends Page_Controller
|
|||||||
|
|
||||||
if ($tag) {
|
if ($tag) {
|
||||||
$this->blogPosts = $tag->BlogPosts();
|
$this->blogPosts = $tag->BlogPosts();
|
||||||
return $this->render();
|
|
||||||
|
if($this->isRSS()) {
|
||||||
|
return $this->rssFeed($this->blogPosts);
|
||||||
|
} else {
|
||||||
|
return $this->render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->httpError(404, 'Not Found');
|
$this->httpError(404, 'Not Found');
|
||||||
@ -874,7 +879,11 @@ class Blog_Controller extends Page_Controller
|
|||||||
if ($category) {
|
if ($category) {
|
||||||
$this->blogPosts = $category->BlogPosts();
|
$this->blogPosts = $category->BlogPosts();
|
||||||
|
|
||||||
return $this->render();
|
if($this->isRSS()) {
|
||||||
|
return $this->rssFeed($this->blogPosts);
|
||||||
|
} else {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user