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 function __autoload ($classname) {
00052 aliro::getInstance()->requireClass($classname);
00053 }
00054
00055
00056 class aliroDebug {
00057 private static $instance = __CLASS__;
00058
00059 private $debug_log = array();
00060
00061 private function __construct () { }
00062
00063 private function __clone () { }
00064
00065 public static function getInstance () {
00066 return is_object(self::$instance) ? self::$instance : (self::$instance = new self::$instance);
00067 }
00068
00069 public function setDebugData ($info) {
00070 $this->debug_log[] = $info;
00071 }
00072
00073 public function getLogged () {
00074 $text = '<h4>'.count($this->debug_log).' classes loaded</h4>';
00075 foreach ($this->debug_log as $k=>$class) $text .= "\n".($k+1)."<br />".$class.'<hr />';
00076 return $text;
00077 }
00078
00079 }
00080
00081 class smartClassMapper extends cachedSingleton {
00082
00083 private static $instance = __CLASS__;
00084
00085 protected $dynamap = array();
00086 protected $debug_log = array();
00087 protected $timer = null;
00088 protected $populating = false;
00089
00090 protected $classmap = array (
00091 'mamboCore' => 'aliroCore',
00092 'aliroAbstractDatabase' => 'aliroDatabase',
00093 'aliroDatabaseHandler' => 'aliroDatabase',
00094 'aliroCoreDatabase' => 'aliroDatabase',
00095 'database' => 'aliroDatabase',
00096 'mamboDatabase' => 'aliroDatabase',
00097 'joomlaDatabase' => 'aliroDatabase',
00098 'mosDBTable' => 'aliroDatabaseRow',
00099 'aliroDBRowFactory' => 'aliroDatabaseRow',
00100 'aliroUserTemplateBase' => 'aliroTemplateBase',
00101 'aliroMainTemplateBase' => 'aliroTemplateBase',
00102 'mosAdminMenus' => 'compatibilityClasses',
00103 'mosToolBar' => 'compatibilityClasses',
00104 'mosPathway' => 'aliroPathway',
00105 'mosUser' => 'aliroUser',
00106 'mosMailer' => 'aliroMailer',
00107 'aliroSimpleCache' => 'aliroCache',
00108 'mosCache' => 'aliroCache',
00109 'aliroFolderHandler' => 'aliroFolder',
00110 'aliroSessionFactory' => 'aliroSession',
00111 'aliroSessionData' => 'aliroSession',
00112 'aliroExtension' => 'aliroExtensionHandler',
00113 'aliroCommonExtHandler' => 'aliroExtensionHandler',
00114 'aliroUserPageNav' => 'aliroPageNav',
00115 'aliroAbstractPageNav' => 'aliroPageNav',
00116 'mosPageNav' => 'aliroPageNav',
00117 'aliroDirectory' => 'aliroFileManager',
00118 'mosController' => 'mosRenderer',
00119 'mosCommand' => 'mosRenderer',
00120 'mosView' => 'mosRenderer',
00121 'aliroMenuItem' => 'aliroMenuHandler',
00122 'mosTabs' => 'aliroTabs',
00123 'aliroComponentHandler' => 'aliroComponent',
00124 'aliroFriendlyBase' => 'aliroComponentManager',
00125 'aliroComponentUserManager' => 'aliroComponentManager',
00126 'aliroUserScreenArea' => 'aliroScreenArea',
00127 'aliroAdminScreenArea' => 'aliroScreenArea',
00128 'aliroMambotHandler' => 'aliroMambot',
00129 'mosMambotHandler' => 'aliroMambot',
00130 'aliroModuleHandler' => 'aliroModule',
00131 'aliroXMLParamsDefault' => 'aliroXMLParams',
00132
00133
00134
00135 'aliroAdminParameters' => 'aliroParameters',
00136 'mosAdminParameters' => 'aliroParameters',
00137 'aliroSpecialAdminParameters' => 'aliroParameters',
00138 'mosParameters' => 'aliroParameters',
00139 'aliroLoginDetails' => 'aliroAuthenticator',
00140 'aliroUserAuthenticator' => 'aliroAuthenticator',
00141 'aliroAdminAuthenticator' => 'aliroAuthenticator',
00142 'JApplicationHelper' => 'aliroJoomla',
00143 'JFactory' => 'aliroJoomla',
00144 'JRequest' => 'aliroJoomla',
00145 'JError' => 'aliroJoomla'
00146 );
00147
00148 protected $extmap = array(
00149 'ArchieHTTP' => 'ArchieHTTP',
00150 'UniversalFeedCreator' => 'feedcreator.class',
00151 'htmlMimeMail5' => 'htmlMimeMail5',
00152 'Mail_MIMEPart' => 'mimePart',
00153 'Mail_RFC822' => 'RFC822',
00154 'smpt' => 'smtp',
00155 'HTMLPurifier' => 'HTMLPurifier',
00156 'HTMLPurifier_Config' => 'HTMLPurifier',
00157 'vCard' => 'vCard',
00158 'PclZip' => 'pclzip.lib',
00159 'Archive_Tar' => 'Tar',
00160 'PEAR' => 'PEAR',
00161 'HTMLPurifier_AttrTransform_ScriptRequired' => 'HTMLPurifier/HTMLPurifier_Script_Extension',
00162 'HTMLPurifier_HTMLModule_Scripting' => 'HTMLPurifier/HTMLPurifier_Script_Extension',
00163 'charsetmapping' => 'ConvertTables/charsetmapping',
00164 'PHPGettextFile' => 'phpgettext/phpgettext.file',
00165 'PHPGettextFilePOT' => 'phpgettext/phpgettext.file.pot',
00166 'PHPGettextFilePO' => 'phpgettext/phpgettext.file.po',
00167 'PHPGettextFileGLO' => 'phpgettext/phpgettext.file.glo',
00168 'PHPGettextFileMO' => 'phpgettext/phpgettext.file.mo',
00169 'PHPGettext' => 'phpgettext/phpgettext.class',
00170 'PHPGettextAdmin' => 'phpgettext/phpgettext.admin',
00171 'PHPGettext_Message' => 'phpgettext/phpgettext.message',
00172 'aliroUnaccent' => 'aliroUnaccent',
00173 'ConvertCharset' => 'ConvertCharset',
00174 'zipfile' => 'zipfile'
00175 );
00176
00177 protected function __construct () {
00178 $this->timer = new aliroProfiler('Time so far');
00179 }
00180
00181 public static function getInstance () {
00182 if (!is_object(self::$instance)) {
00183 self::$instance = parent::getCachedSingleton(self::$instance);
00184 self::$instance->reset();
00185 }
00186 self::$instance->checkDynamic();
00187 return self::$instance;
00188 }
00189
00190 protected function checkDynamic () {
00191 if (aliro::getInstance()->installed AND 0 == count($this->dynamap) AND !$this->populating) {
00192 $this->populating = true;
00193 $this->populateMap();
00194 $this->populating = false;
00195 $this->cacheNow();
00196 }
00197 }
00198
00199 public function reset () {
00200 $this->timer->reset();
00201 }
00202
00203 public function clearCache () {
00204 $this->dynamap = array();
00205 $this->populateMap();
00206 parent::clearCache();
00207 }
00208
00209 public function __print () {
00210 return sprintf(T_('SmartClassMapper, %s dynamic items, % logs'), count($this->dynamap), count($this->debug_log));
00211 }
00212
00213 protected function populateMap () {
00214 $database = aliroCoreDatabase::getInstance();
00215 $database->setQuery('SELECT * FROM #__classmap WHERE side != "admin"');
00216 $maps = $database->loadObjectList();
00217 if ($maps) foreach ($maps as $map) {
00218 switch ($map->type) {
00219 case 'component':
00220 $path = 'components/'.$map->formalname.'/';
00221 break;
00222 case 'module':
00223 $path = 'modules/'.$map->formalname.'/';
00224 break;
00225 case 'mambot':
00226 $path = 'mambots/'.$map->formalname.'/';
00227 break;
00228 case 'template':
00229 $path = 'templates/'.$map->formalname.'/';
00230 break;
00231 default: continue;
00232 }
00233 $this->saveMap($path, $map);
00234 }
00235 }
00236
00237 public function timeSoFar () {
00238 return $this->timer->mark('seconds');
00239 }
00240
00241 protected function getClassPath ($classname) {
00242 aliroDebug::getInstance()->setDebugData (sprintf('About to load %s, current used memory %s', $classname, (is_callable('memory_get_usage') ? memory_get_usage() : T_('not known')).$this->timeSoFar()));
00243 $base = criticalInfo::getInstance()->class_base.'/';
00244 if (isset($this->dynamap[$classname])) return $base.$this->dynamap[$classname].'.php';
00245 if (isset($this->classmap[$classname])) return $base.'classes/'.$this->classmap[$classname].'.php';
00246 if (isset($this->extmap[$classname])) return $base.'extclasses/'.$this->extmap[$classname].'.php';
00247 if (file_exists($base.'classes/'.$classname.'.php')) return $base.'classes/'.$classname.'.php';
00248 return '';
00249 }
00250
00251 public function requireClass ($classname) {
00252 $path = $this->getClassPath($classname);
00253 if ($path AND file_exists($path)) require_once($path);
00254 else {
00255 $message = sprintf('Class %s not found, trying with path = %s', $classname, $path);
00256 trigger_error($message);
00257 }
00258 }
00259
00260 public function classExists ($classname) {
00261 return $this->getClassPath($classname) ? true : false;
00262 }
00263
00264 protected function saveMap ($path, $map) {
00265 $path .= $map->filename;
00266 $map->classname = trim($map->classname);
00267 if (false !== strpos($map->classname, '..')) {
00268 var_dump($map);
00269 die(T_('Class mapping includes illegal "..".'));
00270 }
00271 if (!isset($this->dynamap[$map->classname])) $this->dynamap[$map->classname] = $path;
00272 else trigger_error (sprintf('Class %s defined in %s but already defined in %s',$map->classname, $path, $this->dynamap[$map->classname]));
00273 }
00274
00275 }