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 class aliroExtension extends aliroDatabaseRow {
00052 private static $legalTypes = array('component', 'module', 'mambot', 'plugin', 'template', 'language', 'patch');
00053 protected $DBclass = 'aliroCoreDatabase';
00054 protected $tableName = '#__extensions';
00055 protected $rowKey = 'id';
00056
00057 public function populateFromXML ($xmlobject) {
00058 $purifier = new HTMLPurifier();
00059 $this->name = $purifier->purify((string) $xmlobject->getXML('name'));
00060 $this->type = $xmlobject->baseAttribute('type');
00061 if (!in_array($this->type, self::$legalTypes)) return T_('has no valid type');
00062 if ('plugin' == $this->type) $extension->type = 'mambot';
00063 $this->formalname = $purifier->purify((string) $xmlobject->getXML('formalname'));
00064 if (!$this->formalname AND 'component' == strtolower($this->type)) $this->formalname = 'com_'.str_replace(' ', '', strtolower($this->name));
00065 if (!$this->formalname) return T_('has no formal name');
00066 $this->admin = ('administrator' == $xmlobject->baseAttribute('client')) ? 2 : 1;
00067 $this->inner = ('yes' == $xmlobject->baseAttribute('inner')) ? 1 : 0;
00068 if ('template' == $this->type) {
00069 $currentDefault = aliroTemplateHandler::getInstance()->getDefaultTemplateProperty('formalname', (2 == $this->admin));
00070 if (!$currentDefault OR $currentDefault == $this->formalname) $this->default_template = '1';
00071 }
00072 foreach (array('author', 'version', 'authoremail', 'authorurl', 'description', 'creationdate') as $field) {
00073 $this->$field = $purifier->purify((string) $xmlobject->getXML($field));
00074 }
00075 $this->date = $this->creationdate;
00076 unset($this->creationdate);
00077 foreach (array('adminclass', 'menuclass', 'exportclass') as $field) {
00078 $this->$field = $xmlobject->baseAttribute($field);
00079 }
00080 $this->class = $xmlobject->baseAttribute('userclass');
00081 $this->timestamp = date('Y-m-d');
00082 return false;
00083 }
00084 }
00085
00086 class aliroExtensionHandler extends cachedSingleton {
00087 protected static $instance = __CLASS__;
00088 private $extensions = array();
00089 private $extensionsByType = array();
00090 private $templates = array();
00091
00092 protected function __construct () {
00093 $results = aliroCoreDatabase::getInstance()->doSQLget("SELECT * FROM #__extensions", 'aliroExtension');
00094 if ($results) {
00095 foreach ($results as $extension) {
00096 $this->extensions[$extension->formalname] = $extension;
00097 if ($extension->type == 'template') $this->templates[] = $extension->formalname;
00098 }
00099
00100 ksort($this->extensions);
00101 foreach ($this->extensions as $extension) $this->extensionsByType[$extension->type][$extension->formalname] = $extension;
00102 }
00103 }
00104
00105 public static function getInstance () {
00106 return is_object(self::$instance) ? self::$instance : (self::$instance = parent::getCachedSingleton(self::$instance));
00107 }
00108
00109 public function checkStarterPack () {
00110 if (0 == count($this->extensions)) {
00111 $starterpack = criticalInfo::getInstance()->admin_absolute_path.'/starterpack/';
00112 $dir = new aliroDirectory($starterpack);
00113 foreach ($dir->listAll() as $package) if ('index.html' != $package) {
00114 $installer = new aliroInstaller();
00115 $installer->installfromfile($starterpack.$package);
00116 }
00117 }
00118 }
00119
00120 public function getTemplateExtensions () {
00121 $result = array();
00122 foreach ($this->templates as $templatename) $result[$templatename] = $this->extensions[$templatename];
00123 return $result;
00124 }
00125
00126 public function removeExtensions ($formalnames, $isUpgrade=false) {
00127 $extlist = implode("', '", (array) $formalnames);
00128 foreach ((array) $formalnames as $formalname) {
00129 if ($extension = $this->getExtensionByName ($formalname)) {
00130 $handler = aliroExtensionHandler::getExtensionTypeHandler($extension->type);
00131 if (!$isUpgrade) $this->uninstallExtension($handler, $extension);
00132 $this->removeExtensionFiles($handler, $extension);
00133 }
00134 }
00135 $database = aliroCoreDatabase::getInstance();
00136 $this->deleteFromTable($extlist, 'extensions', 'formalname', $database);
00137 $this->deleteFromTable($extlist, 'components', 'option', $database);
00138 if (!$isUpgrade) $this->deleteFromTable($extlist, 'modules', 'module', $database);
00139 $this->deleteFromTable($extlist, 'mambots', 'element', $database);
00140 $this->deleteFromTable($extlist, 'classmap', 'formalname', $database);
00141 if (!$isUpgrade) $database->doSQL("DELETE FROM `#__menu` WHERE `component` != '' AND `component` IN ('$extlist')");
00142 $database->doSQL("DELETE FROM `#__admin_menu` WHERE `component` != '' AND `component` IN ('$extlist')");
00143 $database->doSQL("DELETE `#__modules_menu` FROM `#__modules_menu` LEFT JOIN `#__modules` ON `moduleid`=`id` WHERE `id` IS NULL");
00144 aliroMenuHandler::getInstance()->clearCache();
00145 $this->clearCache();
00146 }
00147
00148 private function deleteFromTable ($extlist, $table, $fieldname, $database) {
00149 $database->doSQL("DELETE FROM `#__$table` WHERE `$fieldname` IN ('$extlist')");
00150 }
00151
00152 private function removeExtensionFiles ($handler, $extension) {
00153 if ($handler) {
00154 $handler->remove($extension->formalname, $extension->admin);
00155 $handler->clearCache();
00156 }
00157 }
00158
00159 private function uninstallExtension ($handler, $extension) {
00160 if ('component' == $extension->type AND file_exists(_ALIRO_ABSOLUTE_PATH.$extension->xmlfile)) {
00161 $installer = new aliroExtensionInstaller(_ALIRO_ABSOLUTE_PATH.$extension->xmlfile);
00162 $installer->removeComponent($handler, $extension);
00163 }
00164 }
00165
00166 public function getExtensions ($type='') {
00167 if ($type) return isset($this->extensionsByType[$type]) ? $this->extensionsByType[$type] : array();
00168 return $this->extensions;
00169 }
00170
00171 public function getExtensionByName ($formalname) {
00172 return isset($this->extensions[$formalname]) ? $this->extensions[$formalname] : null;
00173 }
00174
00175 public function getXMLFileName ($formalname) {
00176 if ($ext = $this->getExtensionByName ($formalname)) return $ext->xmlfile;
00177 return '';
00178 }
00179
00180 public static function getExtensionTypeHandler ($type) {
00181 $prettytype = strtoupper(substr($type,0,1)).strtolower(substr($type,1));
00182 $handlername = 'aliro'.$prettytype.'Handler';
00183 if (aliro::getInstance()->classExists($handlername)) return call_user_func(array($handlername, 'getInstance'));
00184 else return null;
00185 }
00186
00187 }
00188
00189 abstract class aliroCommonExtHandler extends cachedSingleton {
00190
00191
00192 public function getPath ($formalname, $admin) {
00193 return criticalInfo::getInstance()->absolute_path.$this->getRelativePath($formalname, $admin);
00194 }
00195
00196
00197 public function getRelativePath ($formalname, $admin) {
00198 $extradir = (_ALIRO_ADMIN_SIDE == $admin) ? criticalInfo::getInstance()->admin_dir : '';
00199 return $extradir.$this->extensiondir.$formalname;
00200 }
00201
00202
00203 public function getClassPath ($formalname, $admin) {
00204 return criticalInfo::getInstance()->class_base.$this->getRelativePath($formalname, $admin);
00205 }
00206
00207
00208 public function getXMLRelativePath ($formalname, $admin) {
00209 return $this->getRelativePath ($formalname, $admin);
00210 }
00211
00212
00213 public function getXMLPath ($formalname, $admin) {
00214 return criticalInfo::getInstance()->absolute_path.$this->getXMLRelativePath ($formalname, $admin);
00215 }
00216
00217
00218 public function createDirectory ($formalname, $admin) {
00219 $dir = new aliroDirectory ($this->getPath($formalname, $admin));
00220 return $dir->createFresh();
00221 }
00222
00223
00224 public function remove ($formalname) {
00225 $info = criticalInfo::getInstance();
00226 $this->deleteDirectory ($this->getPath($formalname, _ALIRO_USER_SIDE));
00227 $this->deleteDirectory ($this->getPath($formalname, _ALIRO_ADMIN_SIDE));
00228 $this->clearCache();
00229 }
00230
00231 private function deleteDirectory ($path) {
00232 $dir = new aliroDirectory($path);
00233 $dir->deleteAll();
00234 }
00235
00236 public function clearCache ($immediate=false) {
00237 aliroExtensionHandler::getInstance()->clearCache(true);
00238 parent::clearCache($immediate);
00239 }
00240
00241 }
00242
00243 abstract class aliroCommonExtBase extends aliroDatabaseRow {
00244 protected $xmlobject = null;
00245
00246 public function getXMLObject () {
00247 if (is_null($this->xmlobject)) {
00248 $field = $this->formalfield;
00249 $formalname = $this->$field;
00250 $extension = aliroExtensionHandler::getInstance()->getExtensionByName ($formalname);
00251 $this->xmlobject = simplexml_load_file(aliroCore::getInstance()->getCfg('absolute_path').$extension->xmlfile);
00252 }
00253 return $this->xmlobject;
00254 }
00255
00256 }