Go to the documentation of this file.00001 <?php
00002
00009 class oxModule extends oxSuperCfg
00010 {
00011
00017 protected $_aModule = array();
00018
00024 protected $_blMetadata = false;
00025
00031 protected $_blRegistered = false;
00032
00038 public function setModuleData($aModule)
00039 {
00040 $this->_aModule = $aModule;
00041 }
00042
00050 public function load($sModuleId)
00051 {
00052 $sModulePath = $this->getModuleFullPath($sModuleId);
00053 $sMetadataPath = $sModulePath . "/metadata.php";
00054
00055 if ($sModulePath && file_exists($sMetadataPath) && is_readable($sMetadataPath)) {
00056 $aModule = array();
00057 include $sMetadataPath;
00058 $this->_aModule = $aModule;
00059 $this->_blRegistered = true;
00060 $this->_blMetadata = true;
00061 $this->_aModule['active'] = $this->isActive();
00062
00063 return true;
00064 }
00065
00066 return false;
00067 }
00068
00076 public function loadByDir($sModuleDir)
00077 {
00078 $sModuleId = null;
00079 $aModulePaths = $this->getModulePaths();
00080
00081 if (is_array($aModulePaths)) {
00082 $sModuleId = array_search($sModuleDir, $aModulePaths);
00083 }
00084
00085
00086 if (!$sModuleId) {
00087 $sModuleId = $sModuleDir;
00088 }
00089
00090 return $this->load($sModuleId);
00091 }
00092
00098 public function getDescription()
00099 {
00100 $iLang = oxRegistry::getLang()->getTplLanguage();
00101
00102 return $this->getInfo("description", $iLang);
00103 }
00104
00110 public function getTitle()
00111 {
00112 $iLang = oxRegistry::getLang()->getTplLanguage();
00113
00114 return $this->getInfo("title", $iLang);
00115 }
00116
00122 public function getId()
00123 {
00124 return $this->_aModule['id'];
00125 }
00126
00132 public function getExtensions()
00133 {
00134 return isset($this->_aModule['extend']) ? $this->_aModule['extend'] : array();
00135 }
00136
00142 public function getFiles()
00143 {
00144 return isset($this->_aModule['files']) ? $this->_aModule['files'] : array();
00145 }
00146
00154 public function getIdByPath($sModule)
00155 {
00156 $myConfig = $this->getConfig();
00157 $aModulePaths = $myConfig->getConfigParam('aModulePaths');
00158 $sModuleId = null;
00159 if (is_array($aModulePaths)) {
00160 foreach ($aModulePaths as $sId => $sPath) {
00161 if (strpos($sModule, $sPath . "/") === 0) {
00162 $sModuleId = $sId;
00163 }
00164 }
00165 }
00166 if (!$sModuleId) {
00167 $sModuleId = substr($sModule, 0, strpos($sModule, "/"));
00168 }
00169 if (!$sModuleId) {
00170 $sModuleId = $sModule;
00171 }
00172
00173 return $sModuleId;
00174 }
00175
00185 public function getInfo($sName, $iLang = null)
00186 {
00187 if (isset($this->_aModule[$sName])) {
00188
00189 if ($iLang !== null && is_array($this->_aModule[$sName])) {
00190 $sValue = null;
00191
00192 $sLang = oxRegistry::getLang()->getLanguageAbbr($iLang);
00193
00194 if (!empty($this->_aModule[$sName])) {
00195 if (!empty($this->_aModule[$sName][$sLang])) {
00196 $sValue = $this->_aModule[$sName][$sLang];
00197 } elseif (!empty($this->_aModule['lang'])) {
00198
00199 $sValue = $this->_aModule[$sName][$this->_aModule['lang']];
00200 } else {
00201
00202 $sValue = reset($this->_aModule[$sName]);
00203 }
00204
00205 return $sValue;
00206 }
00207 } else {
00208 return $this->_aModule[$sName];
00209 }
00210 }
00211 }
00212
00218 public function isActive()
00219 {
00220 $blActive = false;
00221 $sId = $this->getId();
00222 if (!is_null($sId)) {
00223 $blActive = !$this->_isInDisabledList($sId);
00224 if ($blActive && $this->hasExtendClass()) {
00225 $blActive = $this->_isExtensionsActive();
00226 }
00227 }
00228
00229 return $blActive;
00230 }
00231
00237 public function hasExtendClass()
00238 {
00239 $aExtensions = $this->getExtensions();
00240
00241 return isset($aExtensions)
00242 && is_array($aExtensions)
00243 && !empty($aExtensions);
00244 }
00245
00251 public function isRegistered()
00252 {
00253 return $this->_blRegistered;
00254 }
00255
00261 public function hasMetadata()
00262 {
00263 return $this->_blMetadata;
00264 }
00265
00271 public function getMetadataPath()
00272 {
00273 $sModulePath = $this->getModuleFullPath();
00274 if (substr($sModulePath, -1) != DIRECTORY_SEPARATOR) {
00275 $sModulePath .= DIRECTORY_SEPARATOR;
00276 }
00277
00278 return $sModulePath . 'metadata.php';
00279 }
00280
00288 public function getModulePath($sModuleId = null)
00289 {
00290 if (!$sModuleId) {
00291 $sModuleId = $this->getId();
00292 }
00293
00294 $aModulePaths = $this->getModulePaths();
00295 $sModulePath = $aModulePaths[$sModuleId];
00296
00297
00298 if (!$sModulePath && is_dir($this->getConfig()->getModulesDir() . $sModuleId)) {
00299 $sModulePath = $sModuleId;
00300 }
00301
00302 return $sModulePath;
00303 }
00304
00312 public function getModuleFullPath($sModuleId = null)
00313 {
00314 if (!$sModuleId) {
00315 $sModuleId = $this->getId();
00316 }
00317
00318 if ($sModuleDir = $this->getModulePath($sModuleId)) {
00319 return $this->getConfig()->getModulesDir() . $sModuleDir;
00320 }
00321
00322 return false;
00323 }
00324
00330 public function getModulePaths()
00331 {
00332 return $this->getConfig()->getConfigParam('aModulePaths');
00333 }
00334
00342 public function getTemplates($sModuleId = null)
00343 {
00344 if (is_null($sModuleId)) {
00345 $sModuleId = $this->getId();
00346 }
00347
00348 if (!$sModuleId) {
00349 return array();
00350 }
00351
00352 $sShopId = $this->getConfig()->getShopId();
00353
00354 $aTemplates = oxDb::getDb()->getCol("SELECT oxtemplate FROM oxtplblocks WHERE oxmodule = '$sModuleId' AND oxshopid = '$sShopId'");
00355
00356 return $aTemplates;
00357 }
00358
00367 protected function _countActivatedExtensions($aModuleExtensions, $aInstalledExtensions)
00368 {
00369 $iActive = 0;
00370 foreach ($aModuleExtensions as $sClass => $mExtension) {
00371 if (is_array($mExtension)) {
00372 foreach ($mExtension as $sExtension) {
00373 if ((isset($aInstalledExtensions[$sClass]) && in_array($sExtension, $aInstalledExtensions[$sClass]))) {
00374 $iActive++;
00375 }
00376 }
00377 } elseif ((isset($aInstalledExtensions[$sClass]) && in_array($mExtension, $aInstalledExtensions[$sClass]))) {
00378 $iActive++;
00379 }
00380 }
00381
00382 return $iActive;
00383 }
00384
00392 protected function _countExtensions($aModuleExtensions)
00393 {
00394 $iCount = 0;
00395 foreach ($aModuleExtensions as $mExtensions) {
00396 if (is_array($mExtensions)) {
00397 $iCount += count($mExtensions);
00398 } else {
00399 $iCount++;
00400 }
00401 }
00402
00403 return $iCount;
00404 }
00405
00411 protected function _isExtensionsActive()
00412 {
00413 $aModuleExtensions = $this->getExtensions();
00414
00415 $aInstalledExtensions = $this->getConfig()->getModulesWithExtendedClass();
00416 $iModuleExtensionsCount = $this->_countExtensions($aModuleExtensions);
00417 $iActivatedModuleExtensionsCount = $this->_countActivatedExtensions($aModuleExtensions, $aInstalledExtensions);
00418 $blActive = $iModuleExtensionsCount > 0 && $iActivatedModuleExtensionsCount == $iModuleExtensionsCount;
00419
00420 return $blActive;
00421 }
00422
00430 protected function _isInDisabledList($sId)
00431 {
00432 $blInDisabledList = false;
00433
00434 $aDisabledModules = (array) $this->getConfig()->getConfigParam('aDisabledModules');
00435 if (in_array($sId, $aDisabledModules)) {
00436 $blInDisabledList = true;
00437 }
00438
00439 return $blInDisabledList;
00440 }
00441 }