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 * @copyright (C) 2008 Vincent Tunru
24 * @author Vincent Tunru <email@vincentt.org>
28 * Manage the Page module
30 * The Page module handles detemining which modules need to be loaded for each
33 * @see /library/Pivip/Module/Abstract.php
35 class Page_Module
extends Pivip_Module_Abstract
38 * Defines the dependencies
40 * Page depends on Pivip
42 protected $_dependencies = array('Pivip' => array('max' => '0.0.0dev'));
45 * Checks whether this module is already installed
47 * In the case of the Page module, "installed" means that the "Blocks" table
50 * @return boolean Whether Page is already installed.
52 public static function isInstalled()
56 $htmlTable = Doctrine
::getTable('Html');
57 } catch(Exception
$e) {
64 * Communicate that Page does not need any configuration
66 * Always returns false since there is nothing to configure for the Page
69 * @return boolean False, since Page does not need to be configured.
71 public static function needsConfiguring()
77 * Creates the table in the database
79 * @throws Pivip_Install_Exception
80 * @return boolean Whether the installation succeeded
82 public function install()
84 $mextRequest = new Zend_Controller_Request_Simple('index',
87 $this->_pushStack($nextRequest);
91 * Remove the table from the database
93 * @throws Pivip_Install_Exception
94 * @return boolean Whether uninstallation succeeded
96 public function uninstall()
101 * Load the generic cache for use by this module
105 public static function loadCache()
107 $frontendOptions = array('cache_id_prefix' => 'page_',
108 'automatic_serialization' => true);
109 $cacheConfig = Zend_Registry
::get('cacheConfig');
110 $cache = Zend_Cache
::factory('Core',
111 $cacheConfig->cache
->backend
,
113 $cacheConfig->backendOptions
->toArray());
118 * Normalize a URL so it can be used as a cache ID
120 * @param string $url URL to be cache ID-ized
121 * @return string Cache ID-ized URL
122 * @todo Move this somewhere else
124 public static function urlToCacheId($url)
126 return str_replace(':', '__colon__',
127 str_replace('.', '__fullstop__',
128 str_replace(';', '__semicolon__',
129 str_replace('%', '__percent__',
130 str_replace('/', '__fwdslash__',
131 str_replace('\\', '__bwdslash__',
132 str_replace('#', '__hash__',
133 str_replace('?', '__qmark__',
134 str_replace('&', '__amp__',
135 str_replace('-', '__hyphen__',
136 str_replace('=', '__equal__',
137 Zend_Filter
::get($url, 'HtmlEntities'))))))))))));
143 * First loads the SegmentMapper Action Helper and makes sure Page's index
144 * controller is called by default. It then sets the layout which will
145 * include all blocks. Of course, all related routes and view helpers are
147 * It also saves a "default request" to the registry. Other modules can
148 * forward to this request when they have been called directly and thus the
149 * rest of the page has not been loaded.
151 public function bootstrap()
153 // Make sure that other modules can extends Page_Abstract
154 require 'modules/page/Abstract.php';
156 * Load the SegmentMapper action helper
158 * @see modules/page/helpers/SegmentMapper.php
160 $frontController = Zend_Controller_Front
::getInstance();
161 require_once 'helpers/SegmentMapper.php';
162 Zend_Controller_Action_HelperBroker
::addHelper(new SegmentMapper());
163 // Make sure this module is loaded when no other module is
164 $frontController->setDefaultModule('page');
165 // Initialize the layout
166 Zend_Layout
::startMvc(array('layoutPath' =>
167 'modules/page/views/scripts'));
168 // Set the website title
169 $generalConfig = Zend_Registry
::get('generalConfig');
170 $viewRenderer = Zend_Controller_Action_HelperBroker
171 ::getStaticHelper('viewRenderer');
172 $viewRenderer->view
->headTitle($generalConfig->website
->name
);
173 // Add the view helpers
174 $viewRenderer->view
->addHelperPath('modules/page/views/helpers',
176 // Define the Access Control List
177 $acl = Zend_Registry
::get('acl');
178 $acl->add(new Zend_Acl_Resource('block'))
179 ->allow('admin', 'block', array('add', 'edit', 'delete'));
180 Zend_Registry
::set('acl', $acl);
181 // Make sure other modules can forward to the page controller
182 $defaultRequest = new Zend_Controller_Request_Simple('index',
187 Zend_Registry
::set('defaultRequest', $defaultRequest);