00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
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
00132 }
00133
00134 protected function noMagicQuotes () {
00135
00136 if (get_magic_quotes_gpc()) {
00137
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
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
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 }