* [Friends] Members can now apply to be added to the contact list.
[pivip.git] / project / modules / page / Module.php
blob1600e0d812f936f9190288e99675093bdf8cd043
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 if(!file_exists(CODE_PATH . 'application/models/generated/BaseBlock.php'))
56 return false;
58 try
60 $blockTable = Doctrine::getTable('Block');
61 } catch(Exception $e) {
62 return false;
64 return true;
67 /**
68 * Communicate that Page does not need any configuration
70 * Always returns false since there is nothing to configure for the Page
71 * module.
73 * @return boolean False, since Page does not need to be configured.
75 public static function needsConfiguring()
77 return false;
80 /**
81 * Creates the table in the database
83 * @throws Pivip_Install_Exception
84 * @return boolean Whether the installation succeeded
86 public function install()
88 $nextRequest = new Zend_Controller_Request_Simple('index',
89 'install',
90 'page');
91 $this->_pushStack($nextRequest);
94 /**
95 * Remove the table from the database
97 * @throws Pivip_Install_Exception
98 * @return boolean Whether uninstallation succeeded
100 public function uninstall()
105 * Load the generic cache for use by this module
107 * @return Zend_Cache
109 public static function loadCache()
111 $frontendOptions = array('cache_id_prefix' => 'page_',
112 'automatic_serialization' => true);
113 $cacheConfig = Zend_Registry::get('cacheConfig');
114 $cache = Zend_Cache::factory('Core',
115 $cacheConfig->cache->backend,
116 $frontendOptions,
117 $cacheConfig->backendOptions->toArray());
118 return $cache;
122 * Normalize a URL so it can be used as a cache ID
124 * @param string $url URL to be cache ID-ized
125 * @return string Cache ID-ized URL
126 * @todo Remove this method
128 public static function urlToCacheId($url)
130 return Pivip_Utility_Cache::toCacheId($url);
134 * Load the module
136 * First loads the SegmentMapper Action Helper and makes sure Page's index
137 * controller is called by default. It then sets the layout which will
138 * include all blocks. Of course, all related routes and view helpers are
139 * also loaded.
140 * It also saves a "default request" to the registry. Other modules can
141 * forward to this request when they have been called directly and thus the
142 * rest of the page has not been loaded.
144 public function bootstrap()
146 // Make sure that other modules can extends Page_Abstract
147 require 'modules/page/Abstract.php';
149 * Load the SegmentMapper action helper
151 * @see modules/page/helpers/SegmentMapper.php
153 $frontController = Zend_Controller_Front::getInstance();
154 require_once 'helpers/SegmentMapper.php';
155 Zend_Controller_Action_HelperBroker::addHelper(new SegmentMapper());
156 // Make sure this module is loaded when no other module is
157 $frontController->setDefaultModule('page');
158 // Initialize the layout
159 Zend_Layout::startMvc(array('layoutPath' =>
160 'modules/page/views/scripts'));
161 // Set the website title
162 $generalConfig = Zend_Registry::get('generalConfig');
163 $viewRenderer = Zend_Controller_Action_HelperBroker
164 ::getStaticHelper('viewRenderer');
165 $viewRenderer->view->headTitle($generalConfig->website->name);
166 // Add the view helpers
167 $viewRenderer->view->addHelperPath('modules/page/views/helpers',
168 'Page_View_Helper');
169 // Define the Access Control List
170 $acl = Zend_Registry::get('acl');
171 $acl->add(new Zend_Acl_Resource('block'))
172 ->allow('admin', 'block', array('add', 'edit', 'delete'));
173 Zend_Registry::set('acl', $acl);
174 // Make sure other modules can forward to the page controller
175 $defaultRequest = new Zend_Controller_Request_Simple('index',
176 'index',
177 'page',
178 array('bundle'
179 => 'core'));
180 Zend_Registry::set('defaultRequest', $defaultRequest);
181 $auth = Pivip_Auth::getInstance();
182 if(!$this->isInstalled() && $auth->hasIdentity())
184 $properties = $auth->getIdentityProperties();
185 if($acl->isAllowed((string) $properties->aclRole, 'module', 'install'))
187 $this->install();