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