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