oxmodule.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxModule extends oxSuperCfg
00008 {
00014     protected $_aModule = array();
00015 
00021     protected $_blMetadata   = false;
00022 
00028     protected $_blRegistered = false;
00029 
00035     protected $_blFile       = false;
00036 
00042     protected $_blLegacy     = false;
00043 
00051     public function setModuleData( $aModule )
00052     {
00053         $this->_aModule = $aModule;
00054     }
00055 
00063     public function load( $sModuleId )
00064     {
00065         if ( $this->loadModule($sModuleId) ) return true;
00066 
00067         if ( $this->loadLegacyModule($sModuleId) ) return true;
00068 
00069         if ( $this->loadUnregisteredModule($sModuleId) ) return true;
00070 
00071         return false;
00072     }
00073 
00081     public function loadByDir( $sModuleDir )
00082     {
00083         $sModuleId    = null;
00084         $aModulePaths = $this->getModulePaths();
00085 
00086         if ( is_array($aModulePaths) ) {
00087             $sModuleId = array_search( $sModuleDir, $aModulePaths);
00088         }
00089 
00090         // if no module id defined, using module dir as id
00091         if ( !$sModuleId ) {
00092             $sModuleId = $sModuleDir;
00093         }
00094 
00095         return $this->load( $sModuleId );
00096     }
00097 
00105     public function loadModule( $sModuleId )
00106     {
00107         $sModulePath = $this->getModuleFullPath( $sModuleId );
00108         $sMetadataPath = $sModulePath . "/metadata.php";
00109 
00110         if ( $sModulePath && file_exists( $sMetadataPath ) && is_readable( $sMetadataPath ) ) {
00111             $aModule = array();
00112             include $sMetadataPath;
00113             $this->_aModule = $aModule;
00114             $this->_blLegacy      = false;
00115             $this->_blRegistered  = true;
00116             $this->_blMetadata    = true;
00117             $this->_blFile        = false;
00118             $this->_aModule['active'] = $this->isActive();
00119             return true;
00120         }
00121         return false;
00122     }
00123 
00131     public function loadLegacyModule( $sModuleId )
00132     {
00133         $aLegacyModules = $this->getLegacyModules();
00134         $sModuleDir = $this->getModulePath( $sModuleId );
00135 
00136         // registered legacy module
00137         if ( isset( $aLegacyModules[$sModuleId] ) ) {
00138             $this->_aModule = $aLegacyModules[$sModuleId];
00139             $this->_blLegacy      = true;
00140             $this->_blRegistered  = true;
00141             $this->_blMetadata    = false;
00142             $this->_blFile        = empty( $sModuleDir );
00143             $this->_aModule['active'] = $this->isActive();
00144             return true;
00145         }
00146         return false;
00147     }
00148 
00156     public function loadUnregisteredModule( $sModuleId )
00157     {
00158         $sModulePath = $this->getModuleFullPath( $sModuleId );
00159 
00160         if ( !$sModulePath ) {
00161             $sModulePath = $this->getConfig()->getModulesDir() . $sModuleId;
00162         }
00163 
00164         if ( file_exists( $sModulePath ) && is_readable( $sModulePath ) ) {
00165             $aModules = $this->getAllModules();
00166 
00167             $this->_aModule = array();
00168             $this->_aModule['id'] = $sModuleId;
00169             $this->_aModule['title'] = $sModuleId;
00170             $this->_aModule['extend'] = $this->buildModuleChains( $this->filterModuleArray( $aModules, $sModuleId ) );
00171             $this->_blLegacy      = true;
00172             $this->_blRegistered  = false;
00173             $this->_blMetadata    = false;
00174             $this->_blFile        = !is_dir($this->getConfig()->getModulesDir() . $sModuleId );
00175             $this->_aModule['active'] = $this->isActive();
00176             return true;
00177         }
00178         return false;
00179     }
00180 
00186     public function getDescription()
00187     {
00188         $iLang = oxRegistry::getLang()->getTplLanguage();
00189 
00190         return $this->getInfo( "description", $iLang );
00191     }
00192 
00198     public function getTitle()
00199     {
00200         $iLang = oxRegistry::getLang()->getTplLanguage();
00201 
00202         return $this->getInfo( "title", $iLang );
00203     }
00204 
00210     public function getId()
00211     {
00212         return $this->_aModule['id'];
00213     }
00214 
00220     public function getExtensions()
00221     {
00222         return isset( $this->_aModule['extend'] ) ? $this->_aModule['extend'] : array();
00223     }
00224 
00232     public function getIdByPath( $sModule )
00233     {
00234         $myConfig     = $this->getConfig();
00235         $aModulePaths = $myConfig->getConfigParam( 'aModulePaths' );
00236         $sModuleId    = null;
00237         if (is_array( $aModulePaths )) {
00238             foreach ($aModulePaths as $sId => $sPath) {
00239                 if (strpos($sModule, $sPath."/") === 0 ) {
00240                     $sModuleId = $sId;
00241                 }
00242             }
00243         }
00244         if (!$sModuleId) {
00245             $sModuleId = substr( $sModule, 0, strpos( $sModule, "/" ) );
00246         }
00247         if (!$sModuleId) {
00248             $sModuleId = $sModule;
00249         }
00250         return $sModuleId;
00251     }
00252 
00262     public function getInfo( $sName, $iLang = null )
00263     {
00264         if (isset($this->_aModule[$sName])) {
00265 
00266             if ( $iLang !== null && is_array($this->_aModule[$sName]) ) {
00267                 $sValue = null;
00268 
00269                 $sLang = oxRegistry::getLang()->getLanguageAbbr( $iLang );
00270 
00271                 if ( !empty($this->_aModule[$sName]) ) {
00272                     if ( !empty( $this->_aModule[$sName][$sLang] ) ) {
00273                         $sValue = $this->_aModule[$sName][$sLang];
00274                     } elseif ( !empty( $this->_aModule['lang'] ) ) {
00275                         // trying to get value according default language
00276                         $sValue = $this->_aModule[$sName][$this->_aModule['lang']];
00277                     } else {
00278                         // returning first array value
00279                         $sValue = reset( $this->_aModule[$sName] );
00280                     }
00281 
00282                     return $sValue;
00283                 }
00284             } else {
00285                 return $this->_aModule[$sName];
00286             }
00287         }
00288     }
00289 
00295     public function isActive()
00296     {
00297         $blActive = false;
00298         $sId = $this->getId();
00299         if ( !is_null( $sId ) ) {
00300             if ( $this->hasExtendClass() ) {
00301                 $blActive = $this->_isExtensionsActive();
00302                 if ( $blActive && $this->_isInDisabledList( $sId ) ) {
00303                     $blActive = false;
00304                 }
00305             } else {
00306                 $aDisabledModules = $this->getDisabledModules();
00307                 if ( is_array( $aDisabledModules ) && !in_array( $sId, $aDisabledModules ) ) {
00308                     $blActive = true;
00309                 }
00310             }
00311         }
00312 
00313         return $blActive;
00314     }
00315 
00316 
00325     public function isExtended()
00326     {
00327         if ( $this->hasMetadata() && $this->hasExtendClass() ) {
00328             return true;
00329         }
00330 
00331         return false;
00332     }
00333 
00337     public function hasExtendClass()
00338     {
00339         $aExtensions = $this->getExtensions();
00340         return isset( $aExtensions )
00341         && is_array( $aExtensions )
00342         && !empty( $aExtensions );
00343     }
00344 
00350     public function isLegacy()
00351     {
00352         return $this->_blLegacy;
00353     }
00354 
00360     public function isRegistered()
00361     {
00362         return $this->_blRegistered;
00363     }
00364 
00370     public function hasMetadata()
00371     {
00372         return $this->_blMetadata;
00373     }
00374 
00380     public function isFile()
00381     {
00382         return $this->_blFile;
00383     }
00384 
00390     public function activate()
00391     {
00392         $blResult = false;
00393 
00394         if ( $this->hasMetadata() || $this->hasExtendClass() ) {
00395 
00396             $this->_addExtensions();
00397 
00398             $this->_removeFromDisabledList();
00399 
00400             $this->_addTemplateBlocks( $this->getInfo("blocks") );
00401 
00402             // Register new module templates
00403             $this->_addModuleFiles($this->getInfo("files") );
00404 
00405             // Register new module templates
00406             $this->_addTemplateFiles( $this->getInfo("templates") );
00407 
00408             // Add module settings
00409             $this->_addModuleSettings($this->getInfo("settings"));
00410 
00411             // Add module version
00412             $this->_addModuleVersion($this->getInfo("version"));
00413 
00414             // Add module events
00415             $this->_addModuleEvents($this->getInfo("events"));
00416 
00417             //resets cache
00418             $this->_resetCache();
00419 
00420 
00421             $this->_callEvent('onActivate',  $this->getId() );
00422 
00423             $blResult = true;
00424         }
00425         return $blResult;
00426     }
00427 
00435     public function deactivate( $sModuleId = null )
00436     {
00437         $blResult = false;
00438         if ( is_null( $sModuleId ) ) {
00439             $sModuleId = $this->getId();
00440         }
00441         if ( isset( $sModuleId ) ) {
00442 
00443             $this->_addToDisabledList( $sModuleId );
00444 
00445             $this->_callEvent( 'onDeactivate', $sModuleId );
00446 
00447             //resets cache
00448             $this->_resetCache();
00449 
00450             $this->_deleteBlock( $sModuleId );
00451 
00452 
00453             $blResult = true;
00454         }
00455         return $blResult;
00456     }
00457 
00466     protected function _callEvent( $sEvent, $sModuleId )
00467     {
00468         $aModuleEvents = $this->getModuleEvents();
00469 
00470         if ( isset( $aModuleEvents[$sModuleId], $aModuleEvents[$sModuleId][$sEvent] ) ) {
00471             $mEvent = $aModuleEvents[$sModuleId][$sEvent];
00472 
00473             if ( is_callable( $mEvent ) ) {
00474                 call_user_func($mEvent);
00475             }
00476         }
00477     }
00478 
00487     protected function _changeBlockStatus( $sModule, $iStatus = 0 )
00488     {
00489         $oDb = oxDb::getDb();
00490         $sShopId   = $this->getConfig()->getShopId();
00491         $oDb->execute( "UPDATE oxtplblocks SET oxactive = '".(int) $iStatus."' WHERE oxmodule =". $oDb->quote( $sModule )."AND oxshopid = '$sShopId'" );
00492     }
00493 
00501     protected function _deleteBlock( $sModule )
00502     {
00503         $oDb = oxDb::getDb();
00504         $sShopId = $this->getConfig()->getShopId();
00505         $oDb->execute( "DELETE FROM `oxtplblocks` WHERE `oxmodule` =" . $oDb->quote( $sModule ) . " AND `oxshopid` = " . $oDb->quote( $sShopId ) );
00506     }
00507 
00508 
00514     protected function _resetCache()
00515     {
00516         $aTemplates = $this->getTemplates();
00517         $oUtils = oxRegistry::getUtils();
00518         $oUtils->resetTemplateCache($aTemplates);
00519         $oUtils->resetLanguageCache();
00520         $oUtils->resetMenuCache();
00521 
00522         $oUtilsObject = oxUtilsObject::getInstance();
00523         $oUtilsObject->resetModuleVars();
00524 
00525         $this->_clearApcCache();
00526     }
00527 
00528 
00536     public function buildModuleChains($aModuleArray)
00537     {
00538         $aModules = array();
00539         if (is_array($aModuleArray)) {
00540             foreach ($aModuleArray as $sClass => $aModuleChain) {
00541                 $aModules[$sClass] = implode('&', $aModuleChain);
00542             }
00543         }
00544         return $aModules;
00545     }
00546 
00556     public function mergeModuleArrays($aAllModuleArray, $aAddModuleArray)
00557     {
00558         if ( is_array( $aAllModuleArray ) && is_array( $aAddModuleArray ) ) {
00559             foreach ( $aAddModuleArray as $sClass => $aModuleChain ) {
00560                 if ( !is_array( $aModuleChain ) ) {
00561                     $aModuleChain = array( $aModuleChain );
00562                 }
00563                 if ( isset( $aAllModuleArray[$sClass] ) ) {
00564                     foreach ( $aModuleChain as $sModule ) {
00565                         if ( !in_array( $sModule, $aAllModuleArray[$sClass] ) ) {
00566                             $aAllModuleArray[$sClass][] = $sModule;
00567                         }
00568                     }
00569                 } else {
00570                     $aAllModuleArray[$sClass] = $aModuleChain;
00571                 }
00572             }
00573         }
00574 
00575         return $aAllModuleArray;
00576     }
00577 
00586     public function filterModuleArray( $aModules, $sModuleId )
00587     {
00588         $aFilteredModules = array();
00589         foreach ($aModules as $sClass => $aExtend) {
00590             foreach ($aExtend as $sExtendPath) {
00591                 if (strstr($sExtendPath, $sModuleId.'/')) {
00592                     $aFilteredModules[$sClass][] = $sExtendPath;
00593                 }
00594             }
00595         }
00596         return $aFilteredModules;
00597     }
00598 
00606     public function getModulePath( $sModuleId = null )
00607     {
00608         if ( !$sModuleId ) {
00609             $sModuleId = $this->getId();
00610         }
00611 
00612         $aModulePaths = $this->getModulePaths();
00613         $sModulePath = $aModulePaths[$sModuleId];
00614 
00615         // if still no module dir, try using module ID as dir name
00616         if ( !$sModulePath && is_dir($this->getConfig()->getModulesDir().$sModuleId) ) {
00617             $sModulePath = $sModuleId;
00618         }
00619 
00620         return $sModulePath;
00621     }
00622 
00630     public function getModuleFullPath( $sModuleId )
00631     {
00632         if ( $sModuleDir = $this->getModulePath( $sModuleId ) ) {
00633             return $this->getConfig()->getModulesDir() . $sModuleDir;
00634         }
00635         return false;
00636     }
00637 
00643     public function getAllModules()
00644     {
00645         return $this->getConfig()->getAllModules();
00646     }
00647 
00653     public function getLegacyModules()
00654     {
00655         return $this->getConfig()->getConfigParam('aLegacyModules');
00656     }
00657 
00663     public function getDisabledModules()
00664     {
00665         return $this->getConfig()->getConfigParam('aDisabledModules');
00666     }
00667 
00673     public function getModulePaths()
00674     {
00675         return $this->getConfig()->getConfigParam('aModulePaths');
00676     }
00677 
00683     public function getModuleTemplates()
00684     {
00685         return (array) $this->getConfig()->getConfigParam('aModuleTemplates');
00686     }
00687 
00693     public function getModuleFiles()
00694     {
00695         return (array) $this->getConfig()->getConfigParam('aModuleFiles');
00696     }
00697 
00703     public function getModuleVersions()
00704     {
00705         return (array) $this->getConfig()->getConfigParam('aModuleVersions');
00706     }
00707 
00713     public function getModuleEvents()
00714     {
00715         return (array) $this->getConfig()->getConfigParam('aModuleEvents');
00716     }
00717 
00725     protected function _hasInstalledTemplateBlocks( $sModuleId )
00726     {
00727         $sShopId   = $this->getConfig()->getShopId();
00728         $oDb = oxDb::getDb();
00729         $blRes = $oDb->getOne( "SELECT 1 FROM oxtplblocks WHERE oxmodule = ".$oDb->quote($sModuleId)." AND oxshopid = '$sShopId' LIMIT 1" );
00730         return (bool) $blRes;
00731     }
00732 
00741     protected function _addTemplateBlocks( $aModuleBlocks, $sModuleId = null )
00742     {
00743         if (is_null($sModuleId)) {
00744             $sModuleId = $this->getId();
00745         }
00746 
00747         $sShopId = $this->getConfig()->getShopId();
00748         $oDb     = oxDb::getDb();
00749 
00750         if ( is_array($aModuleBlocks) ) {
00751 
00752             foreach ( $aModuleBlocks as $aValue ) {
00753                 $sOxId = oxUtilsObject::getInstance()->generateUId();
00754 
00755                 $sTemplate = $aValue["template"];
00756                 $iPosition = $aValue["position"]?$aValue["position"]:1;
00757                 $sBlock    = $aValue["block"];
00758                 $sFile     = $aValue["file"];
00759 
00760                 $sSql = "INSERT INTO `oxtplblocks` (`OXID`, `OXACTIVE`, `OXSHOPID`, `OXTEMPLATE`, `OXBLOCKNAME`, `OXPOS`, `OXFILE`, `OXMODULE`)
00761                          VALUES ('{$sOxId}', 1, '{$sShopId}', ".$oDb->quote($sTemplate).", ".$oDb->quote($sBlock).", ".$oDb->quote($iPosition).", ".$oDb->quote($sFile).", '{$sModuleId}')";
00762 
00763                 $oDb->execute( $sSql );
00764             }
00765         }
00766     }
00767 
00776     protected function _addTemplateFiles( $aModuleTemplates , $sModuleId = null)
00777     {
00778         if (is_null($sModuleId)) {
00779             $sModuleId = $this->getId();
00780         }
00781 
00782         $oConfig    = $this->getConfig();
00783         $aTemplates = $this->getModuleTemplates();
00784         if ( is_array($aModuleTemplates) ) {
00785             $aTemplates[$sModuleId] = $aModuleTemplates;
00786         }
00787 
00788         $oConfig->setConfigParam('aModuleTemplates', $aTemplates);
00789         $oConfig->saveShopConfVar('aarr', 'aModuleTemplates', $aTemplates);
00790     }
00791 
00800     protected function _addModuleVersion( $sModuleVersion, $sModuleId = null)
00801     {
00802         if (is_null($sModuleId)) {
00803             $sModuleId = $this->getId();
00804         }
00805 
00806         $oConfig = $this->getConfig();
00807         $aVersions  = $this->getModuleVersions();
00808         if ( is_array($aVersions) ) {
00809             $aVersions[$sModuleId] = $sModuleVersion;
00810         }
00811 
00812         $oConfig->setConfigParam('aModuleVersions', $aVersions);
00813         $oConfig->saveShopConfVar('aarr', 'aModuleVersions', $aVersions);
00814     }
00815 
00824     protected function _addModuleEvents( $aModuleEvents, $sModuleId = null)
00825     {
00826         if (is_null($sModuleId)) {
00827             $sModuleId = $this->getId();
00828         }
00829 
00830         $oConfig = $this->getConfig();
00831         $aEvents  = $this->getModuleEvents();
00832         if ( is_array($aEvents) ) {
00833             $aEvents[$sModuleId] = $aModuleEvents;
00834         }
00835 
00836         $oConfig->setConfigParam('aModuleEvents', $aEvents);
00837         $oConfig->saveShopConfVar('aarr', 'aModuleEvents', $aEvents);
00838     }
00839 
00848     protected function _addModuleFiles( $aModuleFiles, $sModuleId = null)
00849     {
00850         if (is_null($sModuleId)) {
00851             $sModuleId = $this->getId();
00852         }
00853 
00854         $oConfig = $this->getConfig();
00855         $aFiles  = $this->getModuleFiles();
00856         if ( is_array($aModuleFiles) ) {
00857             $aFiles[$sModuleId] = array_change_key_case($aModuleFiles, CASE_LOWER);
00858         }
00859 
00860         $oConfig->setConfigParam('aModuleFiles', $aFiles);
00861         $oConfig->saveShopConfVar('aarr', 'aModuleFiles', $aFiles);
00862     }
00863 
00872     protected function _addModuleSettings( $aModuleSettings, $sModuleId = null )
00873     {
00874         if (is_null($sModuleId)) {
00875             $sModuleId = $this->getId();
00876         }
00877         $oConfig = $this->getConfig();
00878         $sShopId = $oConfig->getShopId();
00879         $oDb     = oxDb::getDb();
00880 
00881         if ( is_array($aModuleSettings) ) {
00882 
00883             foreach ( $aModuleSettings as $aValue ) {
00884                 $sOxId = oxUtilsObject::getInstance()->generateUId();
00885 
00886                 $sModule     = 'module:'.$sModuleId;
00887                 $sName       = $aValue["name"];
00888                 $sType       = $aValue["type"];
00889                 $sValue      = is_null($oConfig->getConfigParam($sName))?$aValue["value"]:$oConfig->getConfigParam($sName);
00890                 $sGroup      = $aValue["group"];
00891 
00892                 $sConstraints = "";
00893                 if ( $aValue["constraints"] ) {
00894                     $sConstraints = $aValue["constraints"];
00895                 } elseif ( $aValue["constrains"] ) {
00896                     $sConstraints = $aValue["constrains"];
00897                 }
00898 
00899                 $iPosition   = $aValue["position"]?$aValue["position"]:1;
00900 
00901                 $oConfig->setConfigParam($sName, $sValue);
00902                 $oConfig->saveShopConfVar($sType, $sName, $sValue, $sShopId, $sModule);
00903 
00904                 $sDeleteSql = "DELETE FROM `oxconfigdisplay` WHERE OXCFGMODULE=".$oDb->quote($sModule)." AND OXCFGVARNAME=".$oDb->quote($sName);
00905                 $sInsertSql = "INSERT INTO `oxconfigdisplay` (`OXID`, `OXCFGMODULE`, `OXCFGVARNAME`, `OXGROUPING`, `OXVARCONSTRAINT`, `OXPOS`) ".
00906                               "VALUES ('{$sOxId}', ".$oDb->quote($sModule).", ".$oDb->quote($sName).", ".$oDb->quote($sGroup).", ".$oDb->quote($sConstraints).", ".$oDb->quote($iPosition).")";
00907 
00908                 $oDb->execute( $sDeleteSql );
00909                 $oDb->execute( $sInsertSql );
00910             }
00911         }
00912     }
00913 
00921     public function getTemplates( $sModuleId = null )
00922     {
00923         if (is_null($sModuleId)) {
00924             $sModuleId = $this->getId();
00925         }
00926 
00927         if (!$sModuleId) {
00928             return array();
00929         }
00930 
00931         $sShopId   = $this->getConfig()->getShopId();
00932 
00933         $aTemplates = oxDb::getDb()->getCol("SELECT oxtemplate FROM oxtplblocks WHERE oxmodule = '$sModuleId' AND oxshopid = '$sShopId'" );
00934 
00935         return $aTemplates;
00936     }
00937 
00949     public function saveLegacyModule($sModuleId, $sModuleName, $aModuleInfo = null)
00950     {
00951         $aLegacyModules = $this->getLegacyModules();
00952 
00953         if ( !empty( $aModuleInfo ) && is_array($aModuleInfo)) {
00954             $aLegacyModules[$sModuleId]["id"] = $sModuleId;
00955             $aLegacyModules[$sModuleId]["title"] = ( $sModuleName ) ? $sModuleName : $sModuleId;
00956             $aLegacyModules[$sModuleId]['extend'] = array();
00957 
00958             foreach ( $aModuleInfo as $sKey => $sValue ) {
00959                 if ( strpos( $sValue, "=>" ) > 1 ) {
00960                     $aClassInfo    = explode( "=>", $sValue );
00961                     $sClassName    = trim( $aClassInfo[0] );
00962                     $sExtendString = trim( $aClassInfo[1] );
00963                     $aLegacyModules[$sModuleId]['extend'][$sClassName] = $sExtendString;
00964                 }
00965             }
00966         }
00967 
00968         if ( !empty( $aLegacyModules[$sModuleId]['extend'] ) ) {
00969             $this->getConfig()->saveShopConfVar( "aarr", "aLegacyModules", $aLegacyModules );
00970         }
00971         return $sModuleId;
00972     }
00973 
00982     public function updateModuleIds( $sModuleLegacyId, $sModuleId )
00983     {
00984         $oConfig = $this->getConfig();
00985 
00986         // updating module ID in aModulePaths config var
00987         $aModulePaths = $oConfig->getConfigParam( 'aModulePaths' );
00988         $aModulePaths[$sModuleId] = $aModulePaths[$sModuleLegacyId];
00989         unset( $aModulePaths[$sModuleLegacyId] );
00990 
00991         $oConfig->saveShopConfVar( 'aarr', 'aModulePaths', $aModulePaths );
00992 
00993         if ( isset($aModulePaths[$sModuleLegacyId]) ) {
00994             $aModulePaths[$sModuleId] = $aModulePaths[$sModuleLegacyId];
00995             unset( $aModulePaths[$sModuleLegacyId] );
00996             $oConfig->saveShopConfVar( 'aarr', 'aModulePaths', $aModulePaths );
00997         }
00998 
00999         // updating module ID in aDisabledModules config var
01000         $aDisabledModules = $oConfig->getConfigParam( 'aDisabledModules' );
01001 
01002         if ( is_array($aDisabledModules) ) {
01003             $iOldKey = array_search( $sModuleLegacyId, $aDisabledModules );
01004             if ( $iOldKey !== false ) {
01005                 unset( $aDisabledModules[$iOldKey] );
01006                 $aDisabledModules[$iOldKey] = $sModuleId;
01007                 $oConfig->saveShopConfVar( 'arr', 'aDisabledModules', $aDisabledModules );
01008             }
01009         }
01010     }
01011 
01015     protected function _clearApcCache()
01016     {
01017         if ( extension_loaded( 'apc' ) && ini_get( 'apc.enabled' ) ) {
01018             apc_clear_cache();
01019         }
01020     }
01021 
01025     protected function _removeFromDisabledList()
01026     {
01027         $oConfig = $this->getConfig();
01028         $aDisabledModules = $this->getDisabledModules();
01029         $sModuleId = $this->getId();
01030 
01031         if ( isset( $aDisabledModules ) && is_array( $aDisabledModules ) ) {
01032             $aDisabledModules = array_diff( $aDisabledModules, array($sModuleId) );
01033             $oConfig->setConfigParam( 'aDisabledModules', $aDisabledModules );
01034             $oConfig->saveShopConfVar( 'arr', 'aDisabledModules', $aDisabledModules );
01035         }
01036     }
01037 
01041     protected function _addExtensions()
01042     {
01043         $oConfig = $this->getConfig();
01044         $aModules = $this->_removeNotUsedExtensions( $this->getAllModules() );
01045 
01046         if ( $this->hasExtendClass() ) {
01047             $aAddModules  = $this->getExtensions();
01048             $aModules = $this->mergeModuleArrays( $aModules, $aAddModules );
01049         }
01050 
01051         $aModules = $this->buildModuleChains( $aModules );
01052         $oConfig->setConfigParam( 'aModules', $aModules );
01053         $oConfig->saveShopConfVar( 'aarr', 'aModules', $aModules );
01054     }
01055 
01059     protected function _addToDisabledList( $sModuleId )
01060     {
01061         $oConfig = $this->getConfig();
01062         $aDisabledModules = $this->getDisabledModules();
01063 
01064         if ( !is_array( $aDisabledModules ) ) {
01065             $aDisabledModules = array();
01066         }
01067         $aModules = array_merge( $aDisabledModules, array( $sModuleId ) );
01068         $aModules = array_unique( $aModules );
01069 
01070         $oConfig->saveShopConfVar( 'arr', 'aDisabledModules', $aModules );
01071         $oConfig->setConfigParam( 'aDisabledModules', $aModules );
01072     }
01073 
01081     protected function _removeNotUsedExtensions( $aInstalledExtensions )
01082     {
01083         $aModuleExtensions = $this->getExtensions();
01084 
01085         $aInstalledModuleExtensions = $this->filterModuleArray( $aInstalledExtensions, $this->getId() );
01086 
01087         if ( count( $aInstalledModuleExtensions ) ) {
01088             $aGarbage = $this->_getModuleExtensionsGarbage( $aModuleExtensions, $aInstalledModuleExtensions );
01089 
01090             if ( count( $aGarbage ) ) {
01091                 $aInstalledExtensions = $this->_removeGarbage( $aInstalledExtensions, $aGarbage );
01092             }
01093         }
01094 
01095         return $aInstalledExtensions;
01096     }
01097 
01106     protected function _getModuleExtensionsGarbage( $aModuleMetaDataExtensions, $aModuleInstalledExtensions )
01107     {
01108         $aGarbage = $aModuleInstalledExtensions;
01109 
01110         foreach ( $aModuleMetaDataExtensions as $sClassName => $sClassPath ) {
01111             if ( isset( $aGarbage[$sClassName] ) ) {
01112                 unset( $aGarbage[$sClassName][ array_search( $sClassPath, $aGarbage[$sClassName] )] );
01113                 if ( count( $aGarbage[$sClassName] ) == 0 ) {
01114                     unset( $aGarbage[$sClassName] );
01115                 }
01116             }
01117         }
01118 
01119         return $aGarbage;
01120     }
01121 
01130     protected function _removeGarbage( $aInstalledExtensions, $aGarbage )
01131     {
01132         foreach ( $aGarbage as $sClassName => $aClassPaths ) {
01133             foreach ( $aClassPaths as $sClassPath ) {
01134                 if ( isset( $aInstalledExtensions[$sClassName] ) ) {
01135                     unset( $aInstalledExtensions[$sClassName][ array_search( $sClassPath, $aInstalledExtensions[$sClassName] )] );
01136                     if ( count( $aInstalledExtensions[$sClassName] ) == 0 ) {
01137                         unset( $aInstalledExtensions[$sClassName] );
01138                     }
01139                 }
01140             }
01141         }
01142 
01143         return $aInstalledExtensions;
01144     }
01145 
01153     protected function _countActivatedExtensions( $aModuleExtensions, $aInstalledExtensions )
01154     {
01155         $iActive = 0;
01156         foreach ( $aModuleExtensions as $sClass => $mExtension ) {
01157             if ( is_array( $mExtension ) ) {
01158                 foreach ( $mExtension as $sExtension ) {
01159                     if ( ( isset( $aInstalledExtensions[$sClass] ) && in_array( $sExtension, $aInstalledExtensions[$sClass] ) ) ) {
01160                         $iActive++;
01161                     }
01162                 }
01163             } elseif ( ( isset( $aInstalledExtensions[$sClass] ) && in_array( $mExtension, $aInstalledExtensions[$sClass] ) ) ) {
01164                 $iActive++;
01165             }
01166         }
01167 
01168         return $iActive;
01169     }
01170 
01177     protected function _countExtensions( $aModuleExtensions )
01178     {
01179         $iCount = 0;
01180         foreach ( $aModuleExtensions as $mExtensions ) {
01181             if ( is_array( $mExtensions ) ) {
01182                 $iCount += count( $mExtensions );
01183             } else {
01184                 $iCount++;
01185             }
01186         }
01187 
01188         return $iCount;
01189     }
01190 
01196     protected function _isExtensionsActive()
01197     {
01198         $aModuleExtensions = $this->getExtensions();
01199         $aInstalledExtensions = $this->getAllModules();
01200         $iModuleExtensionsCount = $this->_countExtensions( $aModuleExtensions );
01201         $iActivatedModuleExtensionsCount = $this->_countActivatedExtensions( $aModuleExtensions, $aInstalledExtensions );
01202         $blActive = $iModuleExtensionsCount > 0 && $iActivatedModuleExtensionsCount == $iModuleExtensionsCount;
01203 
01204         return $blActive;
01205     }
01206 
01213     protected function _isInDisabledList( $sId )
01214     {
01215         $blInDisabledList = false;
01216 
01217         $aDisabledModules = $this->getDisabledModules();
01218         if ( is_array( $aDisabledModules ) && in_array( $sId, $aDisabledModules ) ) {
01219             $blInDisabledList = true;
01220         }
01221 
01222         return $blInDisabledList;
01223     }
01224 }