From 204dfd96a91d8dd44a7ca85e44d0bac2ffbfd2c8 Mon Sep 17 00:00:00 2001 From: Paul Dragoonis Date: Mon, 17 Sep 2012 20:51:25 +0100 Subject: [PATCH] Adding BlogModule rss work - issue: #71 --- modules/BlogModule/Classes/GenerateRSS.php | 19 +++++++++++++++---- modules/BlogModule/Controller/Blog.php | 14 ++++++++++++-- modules/BlogModule/Controller/Shared.php | 10 ++++++++++ modules/BlogModule/Entity/BlogPost.php | 4 ++++ .../BlogModule/resources/config/routes.yml | 2 +- .../resources/views/blog/rss.xml.php | 17 +++++++++++++++++ 6 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 modules/BlogModule/resources/views/blog/rss.xml.php diff --git a/modules/BlogModule/Classes/GenerateRSS.php b/modules/BlogModule/Classes/GenerateRSS.php index 1ac3c02..ae7acc4 100644 --- a/modules/BlogModule/Classes/GenerateRSS.php +++ b/modules/BlogModule/Classes/GenerateRSS.php @@ -7,12 +7,15 @@ 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; } /** @@ -20,7 +23,7 @@ public function __construct($cache, $blogPostStorage) * * @return array */ - public function getRSSContent() + public function getRSSData() { if ($this->cache->contains($this->cacheKey)) { @@ -28,9 +31,17 @@ public function getRSSContent() } 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); } diff --git a/modules/BlogModule/Controller/Blog.php b/modules/BlogModule/Controller/Blog.php index ddbe3d6..df3245e 100644 --- a/modules/BlogModule/Controller/Blog.php +++ b/modules/BlogModule/Controller/Blog.php @@ -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) diff --git a/modules/BlogModule/Controller/Shared.php b/modules/BlogModule/Controller/Shared.php index 6705b5c..04bcb8e 100644 --- a/modules/BlogModule/Controller/Shared.php +++ b/modules/BlogModule/Controller/Shared.php @@ -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'); + } } \ No newline at end of file diff --git a/modules/BlogModule/Entity/BlogPost.php b/modules/BlogModule/Entity/BlogPost.php index d7ef186..84df865 100644 --- a/modules/BlogModule/Entity/BlogPost.php +++ b/modules/BlogModule/Entity/BlogPost.php @@ -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()); diff --git a/modules/BlogModule/resources/config/routes.yml b/modules/BlogModule/resources/config/routes.yml index 1330399..2cc4ce5 100644 --- a/modules/BlogModule/resources/config/routes.yml +++ b/modules/BlogModule/resources/config/routes.yml @@ -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"} \ No newline at end of file diff --git a/modules/BlogModule/resources/views/blog/rss.xml.php b/modules/BlogModule/resources/views/blog/rss.xml.php new file mode 100644 index 0000000..907ca06 --- /dev/null +++ b/modules/BlogModule/resources/views/blog/rss.xml.php @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> + + + PPI Blog RSS Feed + + Add Content Here + + + + <?=$r['title'];?> + Add Content Here + + + + + + \ No newline at end of file