5 * Copyright (C) 2008 Vincent Tunru
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 * @license http://www.fsf.org/licensing/licenses/info/GPLv2.html GPL v.2
21 * @category PivipModulesDefault
22 * @package Module_Planet
23 * @copyright (C) 2008 Vincent Tunru
24 * @author Vincent Tunru <email@vincentt.org>
28 * Create a "Planet" of RSS feeds
30 * A "Planet" is an aggregation of RSS feeds from many different sources.
32 class Planet_PlanetController
extends Page_Abstract
35 * Display the Planet in the main section of the website
37 public function mainAction()
39 $streamId = $this->_request->getParam('block_id');
40 if(null === $streamId)
42 $this->_helper->viewRenderer->setNoRender();
45 $cache = Imagestream_Module::loadCache();
46 if(!$row = $cache->load($streamId))
48 $row = Doctrine::getTable('Imagestream')->find($streamId);
49 $cache->save($row, $streamId, array('stream', 'block'));
54 $service = new Zend_Service_Flickr(self::API_KEY);
58 $service = new Vogel_Service_23(self::API_KEY);
61 $options = array('per_page' => 5);
62 if(isset($row->amount))
64 $options['per_page'] = intval($row->amount);
69 $this->view->images = $service->userSearch($row->keywords,
74 $this->view->images = $service->tagSearch($row->keywords, $options);
80 // Break intentionally omitted
82 // Break intentionally omitted
84 // Break intentionally omitted
86 // Break intentionally omitted
88 // Break intentionally omitted
90 $this->view->imageSize = $row->size;
93 $this->view->imageSize = 'Small';
95 $this->view->urlParams = array('stream_id' => $streamId);
96 if($this->_isAllowed('edit'))
98 $this->view->allowEdit = true;
100 if($this->_isAllowed('delete'))
102 $this->view->allowDelete = true;
109 public function addAction()
111 $translate = Zend_Registry
::get('Zend_Translate');
112 $location = '/' . $this->_request
->getParam('location');
113 if(!$this->_isAllowed('add'))
115 $this->_flashMessenger
->addMessage($translate->_(
116 'You are not allowed to add a planet.'));
117 $this->_redirect($location);
119 $section = $this->_request
->getParam('section');
122 $this->_flashMessenger
->addMessage($translate->_(
123 'You need to specify a section to add a planet to.'));
124 $this->_redirect($location);
128 $block = new Block();
129 $block->location
= $location;
130 $block->action
= $section;
131 $block->controller
= 'planet';
132 $block->module
= 'planet';
134 $cacheId = Page_Module
::urlToCacheId($location);
135 $cache = Page_Module
::loadCache();
136 $cache->remove($cacheId);
137 $this->_flashMessenger
->addMessage($translate->_(
138 'Planet created, please add a feed.'));
139 } catch(Exception
$e) {
140 $this->_flashMessenger
->setNamespace('error')->addMessage($translate
141 ->_('Failed to add the planet.'));
143 $route = Zend_Controller_Front
::getInstance()->getRouter()
144 ->getRoute('Planet_AddFeed');
145 $options = array('planet_id' => $block->block_id
);
146 $this->_redirect($route->assemble($options));
152 * @todo Adapt this function to the Planet module
154 public function editAction()
156 $translate = Zend_Registry
::get('Zend_Translate');
158 $streamId = $this->_request
->getParam('stream_id');
160 if(null === $streamId)
162 $this->_flashMessenger
->addMessage($translate->_(
163 'No image stream specified.'));
167 $streamTable = Doctrine
::getTable('Imagestream');
168 $stream = $streamTable->find($streamId);
170 if(!$this->_isAllowed('edit'))
172 $this->_flashMessenger
->addMessage($translate->_(
173 'You are not allowed to edit image stream.'));
174 $this->_redirect($html->Block
->location
);
177 $this->_helper
->viewRenderer
->setScriptAction('add');
178 $defaultRequest = Zend_Registry
::get('defaultRequest');
179 $this->_helper
->actionStack($defaultRequest);
181 $form = $this->_getForm();
182 $form->submit
->setLabel('Edit');
183 $form->populate($stream->toArray());
184 $this->view
->form
= $form->render();
185 if(!$this->_request
->isPost() ||
186 !$form->isValid($this->_request
->getPost()))
192 $stream->service
= $form->getValue('service');
193 $stream->keywords
= $form->getValue('keywords');
194 $stream->amount
= intval($form->getValue('amount'));
195 $stream->type
= $form->getValue('type');
196 $stream->size
= $form->getValue('size');
198 $this->_flashMessenger
->addMessage($translate->_('Block updated.'));
199 } catch(Exception
$e) {
200 $this->_flashMessenger
->setNamespace('error')->addMessage($translate->_(
201 'An error occured while updating the block, please try again.'));
202 $this->_redirect($this->_request
->getRequestUri());
204 $cache = Imagestream_Module
::loadCache();
205 $cache->remove($streamId);
206 $this->_redirect($html->Block
->location
);
212 * @todo Allow the user to undo this
213 * @todo Finish this function (i.e. delete all feeds and entries)
215 public function deleteAction()
217 $planetId = $this->_request
->getParam('planet_id');
218 $translate = Zend_Registry
::get('Zend_Translate');
220 if(null === $planetId)
222 $this->_flashMessenger
->addMessage($translate->_(
223 'No Planet specified.'));
232 * @param $privileges What the user needs to be allowed to do to blocks
233 * @return bool Whether the user has sufficient rights
235 protected function _isAllowed($privileges = null)
237 $auth = Pivip_Auth
::getInstance();
238 $acl = Zend_Registry
::get('acl');
239 $identity = $auth->getIdentityProperties();
240 if('edit' == $privileges ||
'add' == $privileges)
242 if(!$acl->isAllowed('guest', 'planet', 'write')
243 && !$auth->hasIdentity())
247 if(!$acl->isAllowed($identity->aclRole
, 'planet', 'write'))
252 if(!$acl->isAllowed('guest', 'block', $privileges) &&
253 !$auth->hasIdentity())
257 return $acl->isAllowed($identity->aclRole
, 'block', $privileges);