Skip to content

Commit

Permalink
Adding BlogModule rss work - issue: #71
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoonis committed Sep 17, 2012
1 parent e58d60d commit 204dfd9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
19 changes: 15 additions & 4 deletions modules/BlogModule/Classes/GenerateRSS.php
Expand Up @@ -7,30 +7,41 @@ class GenerateRSS {
protected $cache = null;
protected $defaultTTL = 43200; // (86400 / 2)
protected $cacheKey = 'blog_rss_generate';
protected $routeKey = 'BlogView';
protected $blogPostStorage = null;
protected $router = null;

public function __construct($cache, $blogPostStorage)
public function __construct($cache, $blogPostStorage, $router)
{
$this->cache = $cache;
$this->blogPostStorage = $blogPostStorage;
$this->router = $router;
}

/**
* Generate the RSS data
*
* @return array
*/
public function getRSSContent()
public function getRSSData()
{

if ($this->cache->contains($this->cacheKey)) {
$rssData = $this->cache->fetch($this->cacheKey);
} else {

$rssData = array();
foreach($this->blogPostStorage->getAllPublished() as $post) {
$rssData[] = array(
'title' => $post->getTitle(),
'date' => $post->getCreatedDate()->format('D, d M Y H:i:s O'),
'link' => $this->router->generate($this->routeKey, array(
'postID' => $post->getID(),
'title' => $post->getTitleForLink()
))
);
}

/* @todo - Generate RSS content */

$this->cache->save($this->cacheKey, $rssData, $this->defaultTTL);
}

Expand Down
14 changes: 12 additions & 2 deletions modules/BlogModule/Controller/Blog.php
Expand Up @@ -122,9 +122,19 @@ public function tagviewAction()
}


public function getRSS()
public function getRSSAction()
{

$rssHelper = new \BlogModule\Classes\GenerateRSS(
$this->getCache(),
$this->getBlogStorage(),
$this->getService('router')
);
$rssData = $rssHelper->getRSSData();
$rssBaseLink = $this->generateUrl('BlogGetRSS');
$content = $this->render('BlogModule:blog:rss.xml.php', compact('rssData', 'rssBaseLink'));
// die($content);
$this->getService('response')->headers->set('Content-Type', 'text/xml');
return $content;
}

protected function normalizePostTitleLink($title)
Expand Down
10 changes: 10 additions & 0 deletions modules/BlogModule/Controller/Shared.php
Expand Up @@ -102,5 +102,15 @@ protected function addTemplateGlobal($param, $value)
{
$this->getService('templating')->addGlobal($param, $value);
}

/**
* Get the blog cache
*
* @return object
*/
protected function getCache()
{
return $this->getService('blog.cache');
}

}
4 changes: 4 additions & 0 deletions modules/BlogModule/Entity/BlogPost.php
Expand Up @@ -30,6 +30,10 @@ public function getCategoryID() {
public function getTitle() {
return $this->_title;
}

public function getTitleForLink() {
return strtolower(str_replace(' ', '-', $this->getTitle()));
}

public function getShortContent() {
$content = explode('[split]', $this->getContent());
Expand Down
2 changes: 1 addition & 1 deletion modules/BlogModule/resources/config/routes.yml
Expand Up @@ -22,6 +22,6 @@ BlogGetRecentComments:
pattern: /blog/get_recent_comments
defaults: { _controller: "BlogModule:Blog:getRecentComments"}

BlogGetPopular:
BlogGetRSS:
pattern: /blog/get_rss
defaults: { _controller: "BlogModule:Blog:getRSS"}
17 changes: 17 additions & 0 deletions modules/BlogModule/resources/views/blog/rss.xml.php
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>PPI Blog RSS Feed</title>
<link><?=$rssBaseLink;?></link>
<description>Add Content Here</description>

<?php foreach($rssData as $r): ?>
<item>
<title><?=$r['title'];?></title>
<description>Add Content Here</description>
<link><?=$r['link'];?></link>
<pubDate><?=$r['date'];?></pubDate>
</item>
<?php endforeach; ?>
</channel>
</rss>

0 comments on commit 204dfd9

Please sign in to comment.