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_Page
23 * @subpackage Controllers
24 * @copyright (C) 2008 Vincent Tunru
25 * @author Vincent Tunru <email@vincentt.org>
29 * Load a page's blocks
31 class IndexController
extends Pivip_Controller_Module_Abstract
34 * Load the blocks common to all pages
36 * Note: setting the 'bundle' request parameter will load a certain bundle,
37 * default bundle is 'default'.
39 public function commonAction()
41 $this->_helper
->viewRenderer
->setNoRender();
42 $bundle = $this->_request
->getParam('bundle');
47 $cache = Page_Module
::loadCache();
48 if(!$rows = $cache->load($bundle))
50 $query = new Doctrine_Query();
51 $query->from('Block b')
52 ->where('b.location=?', $bundle)
53 ->orderby('b.priority ASC');
54 $rows = $query->execute();
55 $cache->save($rows, $bundle, array('page', 'bundle', 'block'));
57 foreach($rows as $row)
59 $params = array('block_id' => $row->block_id
);
60 $nextRequest = new Zend_Controller_Request_Simple($row->action
,
64 $this->_helper
->actionStack($nextRequest);
69 * Adds stylesheets and loads the blocks of a certain page
71 * @throws Page_Exception
73 public function indexAction()
75 $this->_helper
->viewRenderer
->setNoRender();
77 $contentType = 'text/html; charset=UTF-8';
78 $translate = Zend_Registry
::get('Zend_Translate');
79 $this->view
->headMeta()->prependHttpEquiv('Content-Type',
81 $this->view
->headMeta()->appendHttpEquiv('Content-Language',
82 $translate->getLocale());
83 header('Content-Type: ' . $contentType);
85 $pageConfig = new Zend_Config_Ini('./modules/page/config.ini');
88 $directories = new DirectoryIterator('public/styles');
89 } catch(Exception
$e) {
90 // Fail silently, no stylesheets found
92 foreach($directories as $directory)
94 if(!$directory->isDir() ||
$directory->isDot())
98 $files = new DirectoryIterator($directory->getPathname());
99 foreach($files as $file)
101 if($file->isDir() ||
$file->isDot())
105 if($pageConfig->styles
->default == $directory->getFilename())
107 $stylesheet = array('href' => $file->getPathname(),
108 'type' => 'text/css',
109 'title' => $directory->getFilename(),
110 'rel' => 'stylesheet',
111 'media' => str_replace('.css', '',
112 $file->getFilename())
115 $stylesheet = array('href' => $file->getPathname(),
116 'type' => 'text/css',
117 'title' => $directory->getFilename(),
118 'rel' => 'alternate stylesheet');
120 $stylesheet['href'] = $this->_request
->getBaseUrl() . '/' .
122 $this->view
->headLink($stylesheet);
125 $location = $this->_getLocation();
126 $cache = Page_Module
::loadCache();
127 $cacheId = Page_Module
::urlToCacheId($location);
128 if(!$rows = $cache->load($cacheId))
130 // Check if Page is installed, if not, we have nothing more to do
131 if(!Page_Module
::isInstalled())
137 $query = new Doctrine_Query();
138 $query->from('Block b')
139 ->where('b.location=?', $location)
140 ->orderby('b.priority ASC');
141 $rows = $query->execute();
142 $cache->save($rows, $cacheId, array('page', 'location', 'block'));
143 } catch(Exception
$e) {
144 $logger = Zend_Registry
::get('logger');
145 $translate = Zend_Registry
::get('Zend_Translate');
146 $error = $translate->_('Could not fetch blocks from the database.');
147 $logger->err($error);
148 // Could not fetch the blocks, don't do anything
152 foreach($rows as $row)
154 $params = array('block_id' => $row->block_id
);
155 $nextRequest = new Zend_Controller_Request_Simple($row->action
,
159 $this->_helper
->actionStack($nextRequest);
161 $this->commonAction();
165 * Display a list of blocks to add
167 public function mainAction()
169 $this->_forward('add');
173 * Add a block to a page
175 public function addAction()
177 $location = $this->_request
->getParam('location');
179 $auth = Pivip_Auth
::getInstance();
180 $acl = Zend_Registry
::get('acl');
181 if(!$acl->isAllowed('guest', 'block', 'add') && !$auth->hasIdentity())
183 $this->_helper
->viewRenderer
->setNoRender();
186 $identity = $auth->getIdentityProperties();
187 if(!$acl->isAllowed($identity->aclRole
, 'block', 'add'))
189 $this->_helper
->viewRenderer
->setNoRender();
193 $modules = new Pivip_Modules();
195 foreach($modules as $module)
197 if(!method_exists($module, 'getPageBlocks'))
201 $links = array_merge($links, $module->getPageBlocks($location));
203 $this->view
->links
= $links;
204 $this->view
->addScriptPath('modules/page/views/scripts/');
208 * Retrieve the path to the current page
210 * @return string The current location
212 protected function _getLocation()
214 $location = substr($this->_request
->getRequestUri(),
215 strlen($this->_request
->getBaseUrl()));