* [Friends] Members can now apply to be added to the contact list.
[pivip.git] / project / modules / html / Module.php
blob42f1ff88086ae84c0063cbd8e79cec996f8ea5b5
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_Html
23 * @copyright (C) 2008 Vincent Tunru
24 * @author Vincent Tunru <email@vincentt.org>
27 /**
28 * Manage the Html module
30 * @see /library/Pivip/Module/Abstract.php
32 class Html_Module extends Pivip_Module_Abstract
34 /**
35 * Checks whether this module is already installed
37 * In the case of the Html module, "installed" means that the database table
38 * exists.
40 * @return boolean Whether Html is already installed.
42 public static function isInstalled()
44 if(!file_exists(CODE_PATH . 'application/models/generated/BaseHtml.php'))
46 return false;
48 try
50 $htmlTable = Doctrine::getTable('Html');
51 } catch(Exception $e) {
52 return false;
54 return true;
57 /**
58 * Communicate that Html does not need any configuration
60 * @return boolean False, since Html does not need to be configured.
62 public static function needsConfiguring()
64 return false;
67 /**
68 * Creates the table in the database
70 * @throws Pivip_Install_Exception
71 * @return boolean Whether the installation succeeded
73 public function install()
77 /**
78 * Remove the table from the database
80 * @throws Pivip_Install_Exception
81 * @return boolean Whether uninstallation succeeded
83 public function uninstall()
87 /**
88 * Load the generic cache for use by this module
90 * @return Zend_Cache
92 public static function loadCache()
94 $frontendOptions = array('cache_id_prefix' => 'html_');
95 $cacheConfig = Zend_Registry::get('cacheConfig');
96 $cache = Zend_Cache::factory('Core',
97 $cacheConfig->cache->backend,
98 $frontendOptions,
99 $cacheConfig->backendOptions->toArray());
100 return $cache;
104 * @return array A list of the blocks this module provides for normal pages,
105 * in the format:
106 * array('section' => array('Link to add this block'
107 => 'Block name'))
109 public static function getPageBlocks($location)
111 if(!self::isInstalled())
113 return array();
115 $translate = Zend_Registry::get('Zend_Translate');
116 $route = Zend_Controller_Front::getInstance()->getRouter()
117 ->getRoute('Html_AddHtml');
118 $blocks = array();
119 $sections = array('main');
120 foreach($sections as $section)
122 $blocks[$section] = array($route->assemble(array('section' => $section,
123 'location'
124 => $location))
125 => $translate->_('Plain HTML block'));
127 return $blocks;
131 * Load the module
133 public function bootstrap()
135 // Define the Access Control List
136 $acl = Zend_Registry::get('acl');
137 $acl->add(new Zend_Acl_Resource('html'))
138 ->allow('admin', 'html', 'write');
139 Zend_Registry::set('acl', $acl);
140 // Define the routes
141 $router = Zend_Controller_Front::getInstance()->getRouter();
142 $options = array('module' => 'html', 'controller' => 'index',
143 'action' => 'add', 'location' => '');
144 $route = new Zend_Controller_Router_Route('html/add/:section/:location',
145 $options);
146 $router->addRoute('Html_AddHtml', $route);
147 $options = array('module' => 'html', 'controller' => 'index',
148 'action' => 'edit');
149 $route = new Zend_Controller_Router_Route('html/edit/:html_id',
150 $options);
151 $router->addRoute('Html_EditHtml', $route);
152 $options = array('module' => 'html', 'controller' => 'index',
153 'action' => 'delete');
154 $route = new Zend_Controller_Router_Route('html/delete/:html_id',
155 $options);
156 $router->addRoute('Html_DeleteHtml', $route);