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