aliroComponentManager.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*******************************************************************************
00004  * Aliro - the modern, accessible content management system
00005  *
00006  * Aliro is open source software, free to use, and licensed under GPL.
00007  * You can find the full licence at http://www.gnu.org/copyleft/gpl.html GNU/GPL
00008  *
00009  * The author freely draws attention to the fact that Aliro derives from Mambo,
00010  * software that is controlled by the Mambo Foundation.  However, this section
00011  * of code is totally new.  If it should contain any fragments that are similar
00012  * to Mambo, please bear in mind (1) there are only so many ways to do things
00013  * and (2) the author of Aliro is also the author and copyright owner for large
00014  * parts of Mambo 4.6.
00015  *
00016  * Tribute should be paid to all the developers who took Mambo to the stage
00017  * it had reached at the time Aliro was created.  It is a feature rich system
00018  * that contains a good deal of innovation.
00019  *
00020  * Your attention is also drawn to the fact that Aliro relies on other items of
00021  * open source software, which is very much in the spirit of open source.  Aliro
00022  * wishes to give credit to those items of code.  Please refer to
00023  * http://aliro.org/credits for details.  The credits are not included within
00024  * the Aliro package simply to avoid providing a marker that allows hackers to
00025  * identify the system.
00026  *
00027  * Copyright in this code is strictly reserved by its author, Martin Brampton.
00028  * If it seems appropriate, the copyright will be vested in the Aliro Organisation
00029  * at a suitable time.
00030  *
00031  * Copyright (c) 2007 Martin Brampton
00032  *
00033  * http://aliro.org
00034  *
00035  * counterpoint@aliro.org
00036  *
00037  * These classes are the optional basis for component (or to some extent
00038  * other add-ons) construction.  They are used extensively by Aliro itself.
00039  *
00040  * aliroFriendlyBase simply provides for any class that uses it as a base
00041  * to have properties and methods of general utility, such as access to
00042  * configuration data.
00043  *
00044  * aliroComponentManager is the abstract base class for manager classes
00045  * for components.
00046  *
00047  * aliroComponentUserManager is the class that provides initial logic to
00048  * handle the startup of a component on the user side.  It decides what
00049  * class and method to call.
00050  *
00051  * aliroComponentControllers is the base class for component logic, to be
00052  * called under the control of the manager class.  So the manager decides
00053  * what function has been requested, and from that uses a simple scheme
00054  * to derive the name of the controller class and method to handle the
00055  * request.  The actual code of the component inherits from this class.
00056  *
00057  */
00058 
00059 abstract class aliroFriendlyBase {
00060 
00061     protected function getTableInfo ($tablename) {
00062         $database = call_user_func(array($this->DBname, 'getInstance'));
00063         return $database->getAllFieldInfo($tablename);
00064     }
00065 
00066     protected function __call ($method, $args) {
00067         return call_user_func_array(array(aliroRequest::getInstance(), $method), $args);
00068     }
00069 
00070     protected function __get ($property) {
00071         if ('option' == $property) return aliroRequest::getInstance()->getOption();
00072         $info = criticalInfo::getInstance();
00073         if (isset($info->$property)) return $info->$property;
00074         trigger_error(sprintf(T_('Invalid criticalInfo property %s requested through aliroFriendlyBase'), $property));
00075     }
00076 
00077     protected final function getCfg ($property) {
00078         return aliroCore::getInstance()->getCfg($property);
00079     }
00080 
00081     protected final function getParam ($array, $key, $default=null, $mask=0) {
00082         return aliroRequest::getInstance()->getParam ($array, $key, $default, $mask);
00083     }
00084 
00085     protected final function getStickyParam ($array, $key, $default=null, $mask=0) {
00086         return aliroRequest::getInstance()->getStickyParam ($array, $key, $default, $mask);
00087     }
00088 
00089     protected final function redirect ($url, $message='', $severity=_ALIRO_ERROR_INFORM) {
00090         aliroRequest::getInstance()->redirect($url, $message, $severity);
00091     }
00092 
00093     protected final function getUser () {
00094         $user = aliroUser::getInstance();
00095         return $user;
00096     }
00097 
00098     protected function formatDate ($time=null, $format=null) {
00099         return aliroLanguage::getInstance()->formatDate($time, $format);
00100     }
00101 
00102 }
00103 
00108 abstract class aliroComponentManager extends aliroFriendlyBase {
00109     protected $name = '';
00110     protected $formalname = '';
00111     protected $barename = '';
00112     protected $system = '';
00113     protected $system_version = '';
00114 
00115     protected function __construct ($component, $system, $version) {
00116         $this->name = $component->name;
00117         $this->formalname = $component->option;
00118         $parts = explode('_', $this->formalname);
00119         $this->barename = isset($parts[1]) ? $parts[1] : $this->formalname;
00120         $this->system = $system;
00121         $this->system_version = $version;
00122         if(file_exists($this->absolute_path."/components/$this->formalname/language/".$this->getCfg('lang').'.php')) {
00123             require_once($this->absolute_path."/components/$this->formalname/language/".$this->getCfg('lang').'.php');
00124         }
00125         else if (file_exists($this->absolute_path."/components/$this->formalname/language/english.php")) {
00126             require_once($this->absolute_path."/components/$this->formalname/language/english.php");
00127         }
00128     }
00129 
00130     protected function __clone () {
00131         // Enforce singleton
00132     }
00133 
00134     protected function noMagicQuotes () {
00135         // Is magic quotes on?
00136         if (get_magic_quotes_gpc()) {
00137             // Yes? Strip the added slashes
00138             $_REQUEST = $this->remove_magic_quotes($_REQUEST);
00139             $_GET = $this->remove_magic_quotes($_GET);
00140             $_POST = $this->remove_magic_quotes($_POST);
00141             $_FILES = $this->remove_magic_quotes($_FILES, 'tmp_name');
00142         }
00143     }
00144 
00145     private function &remove_magic_quotes ($array, $exclude='') {
00146         foreach ($array as $k => &$v) {
00147             if (is_array($v)) $v = $this->remove_magic_quotes($v, $exclude);
00148             // Did apply stripslashes twice, why?  Removed to see what happens
00149             elseif ($k != $exclude) $v = stripslashes($v);
00150         }
00151         return $array;
00152     }
00153 
00154 }
00155 
00160 abstract class aliroComponentUserManager extends aliroComponentManager {
00161     private $func;
00162     private $method;
00163     private $classname;
00164     private $controller;
00165     public $menu = null;
00166     public $limit = 10;
00167     public $limitstart = 0;
00168 
00169     public function __construct ($component, $control_name, $alternatives, $default, $title, $system, $version, $menu) {
00170         parent::__construct($component, $system, $version);
00171         $this->menu = $menu;
00172         if ($title) $this->SetPageTitle($title);
00173         $this->func = $this->getParam ($_REQUEST, $control_name, $default);
00174         if (isset($alternatives[$this->func])) $this->method = $alternatives[$this->func];
00175         else $this->method = $this->func;
00176         $this->classname = $this->barename.'_'.$this->method.'_Controller';
00177 
00178         if (class_exists($this->classname)) $this->controller = call_user_func(array($this->classname, 'getInstance'), $this);
00179         else new aliroPage404();
00180     }
00181 
00182     public function activate() {
00183         $this->noMagicQuotes();
00184         $cmethod = $this->method;
00185         if (method_exists($this->controller,$cmethod)) $this->controller->$cmethod($this->func);
00186         else new aliroPage404();
00187     }
00188 
00189 }
00190 
00191 abstract class aliroComponentControllers extends aliroFriendlyBase {
00192     protected $authoriser = null;
00193     protected $user;
00194     protected $menu;
00195     protected $params;
00196     protected $manager;
00197     protected $idparm;
00198     public $pageNav;
00199 
00200     protected function __construct ($manager) {
00201         $this->manager = $manager;
00202         $this->authoriser = aliroAuthoriser::getInstance();
00203         $this->menu = isset($manager->menu) ? $manager->menu : null;
00204         if ($this->menu) $this->params = new aliroParameters($this->menu->params, $this->menu->name);
00205         else $this->params = new aliroParameters();
00206         $this->user = aliroUser::getInstance();
00207         $this->idparm = $this->getParam($_REQUEST, 'id', 0);
00208     }
00209 
00210     protected function __clone () {
00211         // Restricted to enforce singleton
00212     }
00213 
00214     public function makePageNav ($total) {
00215         $limit = $this->getUserStateFromRequest($this->option.'_page_limit', 'limit', intval($this->getCfg('list_limit')));
00216         $limitstart = $this->getUserStateFromRequest($this->option.'_page_limitstart', 'limitstart', 0 );
00217         $this->pageNav = new aliroPageNav($total, $limitstart, $limit );
00218     }
00219 
00220 }

Generated on Wed May 14 13:01:55 2008 for ALIRO by  doxygen 1.5.5