OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxmodule.php
Go to the documentation of this file.
1 <?php
2 
7 class oxModule extends oxSuperCfg
8 {
14  protected $_aModule = array();
15 
21  protected $_blMetadata = false;
22 
28  protected $_blRegistered = false;
29 
35  protected $_blFile = false;
36 
42  protected $_blLegacy = false;
43 
51  public function setModuleData( $aModule )
52  {
53  $this->_aModule = $aModule;
54  }
55 
63  public function load( $sModuleId )
64  {
65  if ( $this->loadModule($sModuleId) ) return true;
66 
67  if ( $this->loadLegacyModule($sModuleId) ) return true;
68 
69  if ( $this->loadUnregisteredModule($sModuleId) ) return true;
70 
71  return false;
72  }
73 
81  public function loadByDir( $sModuleDir )
82  {
83  $sModuleId = null;
84  $aModulePaths = $this->getModulePaths();
85 
86  if ( is_array($aModulePaths) ) {
87  $sModuleId = array_search( $sModuleDir, $aModulePaths);
88  }
89 
90  // if no module id defined, using module dir as id
91  if ( !$sModuleId ) {
92  $sModuleId = $sModuleDir;
93  }
94 
95  return $this->load( $sModuleId );
96  }
97 
105  public function loadModule( $sModuleId )
106  {
107  $sModulePath = $this->getModuleFullPath( $sModuleId );
108  $sMetadataPath = $sModulePath . "/metadata.php";
109 
110  if ( $sModulePath && file_exists( $sMetadataPath ) && is_readable( $sMetadataPath ) ) {
111  $aModule = array();
112  include $sMetadataPath;
113  $this->_aModule = $aModule;
114  $this->_blLegacy = false;
115  $this->_blRegistered = true;
116  $this->_blMetadata = true;
117  $this->_blFile = false;
118  $this->_aModule['active'] = $this->isActive();
119  return true;
120  }
121  return false;
122  }
123 
131  public function loadLegacyModule( $sModuleId )
132  {
133  $aLegacyModules = $this->getLegacyModules();
134  $sModuleDir = $this->getModulePath( $sModuleId );
135 
136  // registered legacy module
137  if ( isset( $aLegacyModules[$sModuleId] ) ) {
138  $this->_aModule = $aLegacyModules[$sModuleId];
139  $this->_blLegacy = true;
140  $this->_blRegistered = true;
141  $this->_blMetadata = false;
142  $this->_blFile = empty( $sModuleDir );
143  $this->_aModule['active'] = $this->isActive();
144  return true;
145  }
146  return false;
147  }
148 
156  public function loadUnregisteredModule( $sModuleId )
157  {
158  $sModulePath = $this->getModuleFullPath( $sModuleId );
159 
160  if ( !$sModulePath ) {
161  $sModulePath = $this->getConfig()->getModulesDir() . $sModuleId;
162  }
163 
164  if ( file_exists( $sModulePath ) && is_readable( $sModulePath ) ) {
165  $aModules = $this->getAllModules();
166 
167  $this->_aModule = array();
168  $this->_aModule['id'] = $sModuleId;
169  $this->_aModule['title'] = $sModuleId;
170  $this->_aModule['extend'] = $this->buildModuleChains( $this->filterModuleArray( $aModules, $sModuleId ) );
171  $this->_blLegacy = true;
172  $this->_blRegistered = false;
173  $this->_blMetadata = false;
174  $this->_blFile = !is_dir($this->getConfig()->getModulesDir() . $sModuleId );
175  $this->_aModule['active'] = $this->isActive();
176  return true;
177  }
178  return false;
179  }
180 
186  public function getDescription()
187  {
188  $iLang = oxRegistry::getLang()->getTplLanguage();
189 
190  return $this->getInfo( "description", $iLang );
191  }
192 
198  public function getTitle()
199  {
200  $iLang = oxRegistry::getLang()->getTplLanguage();
201 
202  return $this->getInfo( "title", $iLang );
203  }
204 
210  public function getId()
211  {
212  return $this->_aModule['id'];
213  }
214 
220  public function getExtensions()
221  {
222  return isset( $this->_aModule['extend'] ) ? $this->_aModule['extend'] : array();
223  }
224 
232  public function getIdByPath( $sModule )
233  {
234  $myConfig = $this->getConfig();
235  $aModulePaths = $myConfig->getConfigParam( 'aModulePaths' );
236  $sModuleId = null;
237  if (is_array( $aModulePaths )) {
238  foreach ($aModulePaths as $sId => $sPath) {
239  if (strpos($sModule, $sPath."/") === 0 ) {
240  $sModuleId = $sId;
241  }
242  }
243  }
244  if (!$sModuleId) {
245  $sModuleId = substr( $sModule, 0, strpos( $sModule, "/" ) );
246  }
247  if (!$sModuleId) {
248  $sModuleId = $sModule;
249  }
250  return $sModuleId;
251  }
252 
262  public function getInfo( $sName, $iLang = null )
263  {
264  if (isset($this->_aModule[$sName])) {
265 
266  if ( $iLang !== null && is_array($this->_aModule[$sName]) ) {
267  $sValue = null;
268 
269  $sLang = oxRegistry::getLang()->getLanguageAbbr( $iLang );
270 
271  if ( !empty($this->_aModule[$sName]) ) {
272  if ( !empty( $this->_aModule[$sName][$sLang] ) ) {
273  $sValue = $this->_aModule[$sName][$sLang];
274  } elseif ( !empty( $this->_aModule['lang'] ) ) {
275  // trying to get value according default language
276  $sValue = $this->_aModule[$sName][$this->_aModule['lang']];
277  } else {
278  // returning first array value
279  $sValue = reset( $this->_aModule[$sName] );
280  }
281 
282  return $sValue;
283  }
284  } else {
285  return $this->_aModule[$sName];
286  }
287  }
288  }
289 
295  public function isActive()
296  {
297  $blActive = false;
298  $sId = $this->getId();
299  if ( !is_null( $sId ) ) {
300  if ( $this->hasExtendClass() ) {
301  $blActive = $this->_isExtensionsActive();
302  if ( $blActive && $this->_isInDisabledList( $sId ) ) {
303  $blActive = false;
304  }
305  } else {
306  $aDisabledModules = $this->getDisabledModules();
307  if ( is_array( $aDisabledModules ) && !in_array( $sId, $aDisabledModules ) ) {
308  $blActive = true;
309  }
310  }
311  }
312 
313  return $blActive;
314  }
315 
316 
325  public function isExtended()
326  {
327  if ( $this->hasMetadata() && $this->hasExtendClass() ) {
328  return true;
329  }
330 
331  return false;
332  }
333 
337  public function hasExtendClass()
338  {
339  $aExtensions = $this->getExtensions();
340  return isset( $aExtensions )
341  && is_array( $aExtensions )
342  && !empty( $aExtensions );
343  }
344 
350  public function isLegacy()
351  {
352  return $this->_blLegacy;
353  }
354 
360  public function isRegistered()
361  {
362  return $this->_blRegistered;
363  }
364 
370  public function hasMetadata()
371  {
372  return $this->_blMetadata;
373  }
374 
380  public function isFile()
381  {
382  return $this->_blFile;
383  }
384 
390  public function activate()
391  {
392  $blResult = false;
393 
394  if ( $this->hasMetadata() || $this->hasExtendClass() ) {
395 
396  $this->_addExtensions();
397 
398  $this->_removeFromDisabledList();
399 
400  $this->_addTemplateBlocks( $this->getInfo("blocks") );
401 
402  // Register new module templates
403  $this->_addModuleFiles($this->getInfo("files") );
404 
405  // Register new module templates
406  $this->_addTemplateFiles( $this->getInfo("templates") );
407 
408  // Add module settings
409  $this->_addModuleSettings($this->getInfo("settings"));
410 
411  // Add module version
412  $this->_addModuleVersion($this->getInfo("version"));
413 
414  // Add module events
415  $this->_addModuleEvents($this->getInfo("events"));
416 
417  //resets cache
418  $this->_resetCache();
419 
420 
421  $this->_callEvent('onActivate', $this->getId() );
422 
423  $blResult = true;
424  }
425  return $blResult;
426  }
427 
435  public function deactivate( $sModuleId = null )
436  {
437  $blResult = false;
438  if ( is_null( $sModuleId ) ) {
439  $sModuleId = $this->getId();
440  }
441  if ( isset( $sModuleId ) ) {
442 
443  $this->_callEvent( 'onDeactivate', $sModuleId );
444 
445  $this->_addToDisabledList( $sModuleId );
446 
447  //resets cache
448  $this->_resetCache();
449 
450  $this->_deleteBlock( $sModuleId );
451 
452 
453  $blResult = true;
454  }
455  return $blResult;
456  }
457 
466  protected function _callEvent( $sEvent, $sModuleId )
467  {
468  $aModuleEvents = $this->getModuleEvents();
469 
470  if ( isset( $aModuleEvents[$sModuleId], $aModuleEvents[$sModuleId][$sEvent] ) ) {
471  $mEvent = $aModuleEvents[$sModuleId][$sEvent];
472 
473  if ( is_callable( $mEvent ) ) {
474  call_user_func($mEvent);
475  }
476  }
477  }
478 
487  protected function _changeBlockStatus( $sModule, $iStatus = 0 )
488  {
489  $oDb = oxDb::getDb();
490  $sShopId = $this->getConfig()->getShopId();
491  $oDb->execute( "UPDATE oxtplblocks SET oxactive = '".(int) $iStatus."' WHERE oxmodule =". $oDb->quote( $sModule )."AND oxshopid = '$sShopId'" );
492  }
493 
501  protected function _deleteBlock( $sModule )
502  {
503  $oDb = oxDb::getDb();
504  $sShopId = $this->getConfig()->getShopId();
505  $oDb->execute( "DELETE FROM `oxtplblocks` WHERE `oxmodule` =" . $oDb->quote( $sModule ) . " AND `oxshopid` = " . $oDb->quote( $sShopId ) );
506  }
507 
508 
514  protected function _resetCache()
515  {
516  $aTemplates = $this->getTemplates();
517  $oUtils = oxRegistry::getUtils();
518  $oUtils->resetTemplateCache($aTemplates);
519  $oUtils->resetLanguageCache();
520  $oUtils->resetMenuCache();
521 
522  $oUtilsObject = oxUtilsObject::getInstance();
523  $oUtilsObject->resetModuleVars();
524 
525  $this->_clearApcCache();
526  }
527 
528 
536  public function buildModuleChains($aModuleArray)
537  {
538  $aModules = array();
539  if (is_array($aModuleArray)) {
540  foreach ($aModuleArray as $sClass => $aModuleChain) {
541  $aModules[$sClass] = implode('&', $aModuleChain);
542  }
543  }
544  return $aModules;
545  }
546 
556  public function mergeModuleArrays($aAllModuleArray, $aAddModuleArray)
557  {
558  if ( is_array( $aAllModuleArray ) && is_array( $aAddModuleArray ) ) {
559  foreach ( $aAddModuleArray as $sClass => $aModuleChain ) {
560  if ( !is_array( $aModuleChain ) ) {
561  $aModuleChain = array( $aModuleChain );
562  }
563  if ( isset( $aAllModuleArray[$sClass] ) ) {
564  foreach ( $aModuleChain as $sModule ) {
565  if ( !in_array( $sModule, $aAllModuleArray[$sClass] ) ) {
566  $aAllModuleArray[$sClass][] = $sModule;
567  }
568  }
569  } else {
570  $aAllModuleArray[$sClass] = $aModuleChain;
571  }
572  }
573  }
574 
575  return $aAllModuleArray;
576  }
577 
586  public function filterModuleArray( $aModules, $sModuleId )
587  {
588  $aFilteredModules = array();
589  foreach ($aModules as $sClass => $aExtend) {
590  foreach ($aExtend as $sExtendPath) {
591  if (strstr($sExtendPath, $sModuleId.'/')) {
592  $aFilteredModules[$sClass][] = $sExtendPath;
593  }
594  }
595  }
596  return $aFilteredModules;
597  }
598 
606  public function getModulePath( $sModuleId = null )
607  {
608  if ( !$sModuleId ) {
609  $sModuleId = $this->getId();
610  }
611 
612  $aModulePaths = $this->getModulePaths();
613  $sModulePath = $aModulePaths[$sModuleId];
614 
615  // if still no module dir, try using module ID as dir name
616  if ( !$sModulePath && is_dir($this->getConfig()->getModulesDir().$sModuleId) ) {
617  $sModulePath = $sModuleId;
618  }
619 
620  return $sModulePath;
621  }
622 
630  public function getModuleFullPath( $sModuleId )
631  {
632  if ( $sModuleDir = $this->getModulePath( $sModuleId ) ) {
633  return $this->getConfig()->getModulesDir() . $sModuleDir;
634  }
635  return false;
636  }
637 
643  public function getAllModules()
644  {
645  return $this->getConfig()->getAllModules();
646  }
647 
653  public function getLegacyModules()
654  {
655  return $this->getConfig()->getConfigParam('aLegacyModules');
656  }
657 
663  public function getDisabledModules()
664  {
665  return $this->getConfig()->getConfigParam('aDisabledModules');
666  }
667 
673  public function getModulePaths()
674  {
675  return $this->getConfig()->getConfigParam('aModulePaths');
676  }
677 
683  public function getModuleTemplates()
684  {
685  return (array) $this->getConfig()->getConfigParam('aModuleTemplates');
686  }
687 
693  public function getModuleFiles()
694  {
695  return (array) $this->getConfig()->getConfigParam('aModuleFiles');
696  }
697 
703  public function getModuleVersions()
704  {
705  return (array) $this->getConfig()->getConfigParam('aModuleVersions');
706  }
707 
713  public function getModuleEvents()
714  {
715  return (array) $this->getConfig()->getConfigParam('aModuleEvents');
716  }
717 
725  protected function _hasInstalledTemplateBlocks( $sModuleId )
726  {
727  $sShopId = $this->getConfig()->getShopId();
728  $oDb = oxDb::getDb();
729  $blRes = $oDb->getOne( "SELECT 1 FROM oxtplblocks WHERE oxmodule = ".$oDb->quote($sModuleId)." AND oxshopid = '$sShopId' LIMIT 1" );
730  return (bool) $blRes;
731  }
732 
741  protected function _addTemplateBlocks( $aModuleBlocks, $sModuleId = null )
742  {
743  if (is_null($sModuleId)) {
744  $sModuleId = $this->getId();
745  }
746 
747  $sShopId = $this->getConfig()->getShopId();
748  $oDb = oxDb::getDb();
749 
750  if ( is_array($aModuleBlocks) ) {
751 
752  foreach ( $aModuleBlocks as $aValue ) {
753  $sOxId = oxUtilsObject::getInstance()->generateUId();
754 
755  $sTemplate = $aValue["template"];
756  $iPosition = $aValue["position"]?$aValue["position"]:1;
757  $sBlock = $aValue["block"];
758  $sFile = $aValue["file"];
759 
760  $sSql = "INSERT INTO `oxtplblocks` (`OXID`, `OXACTIVE`, `OXSHOPID`, `OXTEMPLATE`, `OXBLOCKNAME`, `OXPOS`, `OXFILE`, `OXMODULE`)
761  VALUES ('{$sOxId}', 1, '{$sShopId}', ".$oDb->quote($sTemplate).", ".$oDb->quote($sBlock).", ".$oDb->quote($iPosition).", ".$oDb->quote($sFile).", '{$sModuleId}')";
762 
763  $oDb->execute( $sSql );
764  }
765  }
766  }
767 
776  protected function _addTemplateFiles( $aModuleTemplates , $sModuleId = null)
777  {
778  if (is_null($sModuleId)) {
779  $sModuleId = $this->getId();
780  }
781 
782  $oConfig = $this->getConfig();
783  $aTemplates = $this->getModuleTemplates();
784  if ( is_array($aModuleTemplates) ) {
785  $aTemplates[$sModuleId] = $aModuleTemplates;
786  }
787 
788  $oConfig->setConfigParam('aModuleTemplates', $aTemplates);
789  $oConfig->saveShopConfVar('aarr', 'aModuleTemplates', $aTemplates);
790  }
791 
800  protected function _addModuleVersion( $sModuleVersion, $sModuleId = null)
801  {
802  if (is_null($sModuleId)) {
803  $sModuleId = $this->getId();
804  }
805 
806  $oConfig = $this->getConfig();
807  $aVersions = $this->getModuleVersions();
808  if ( is_array($aVersions) ) {
809  $aVersions[$sModuleId] = $sModuleVersion;
810  }
811 
812  $oConfig->setConfigParam('aModuleVersions', $aVersions);
813  $oConfig->saveShopConfVar('aarr', 'aModuleVersions', $aVersions);
814  }
815 
824  protected function _addModuleEvents( $aModuleEvents, $sModuleId = null)
825  {
826  if (is_null($sModuleId)) {
827  $sModuleId = $this->getId();
828  }
829 
830  $oConfig = $this->getConfig();
831  $aEvents = $this->getModuleEvents();
832  if ( is_array($aEvents) ) {
833  $aEvents[$sModuleId] = $aModuleEvents;
834  }
835 
836  $oConfig->setConfigParam('aModuleEvents', $aEvents);
837  $oConfig->saveShopConfVar('aarr', 'aModuleEvents', $aEvents);
838  }
839 
848  protected function _addModuleFiles( $aModuleFiles, $sModuleId = null)
849  {
850  if (is_null($sModuleId)) {
851  $sModuleId = $this->getId();
852  }
853 
854  $oConfig = $this->getConfig();
855  $aFiles = $this->getModuleFiles();
856  if ( is_array($aModuleFiles) ) {
857  $aFiles[$sModuleId] = array_change_key_case($aModuleFiles, CASE_LOWER);
858  }
859 
860  $oConfig->setConfigParam('aModuleFiles', $aFiles);
861  $oConfig->saveShopConfVar('aarr', 'aModuleFiles', $aFiles);
862  }
863 
872  protected function _addModuleSettings( $aModuleSettings, $sModuleId = null )
873  {
874  if (is_null($sModuleId)) {
875  $sModuleId = $this->getId();
876  }
877  $oConfig = $this->getConfig();
878  $sShopId = $oConfig->getShopId();
879  $oDb = oxDb::getDb();
880 
881  if ( is_array($aModuleSettings) ) {
882 
883  foreach ( $aModuleSettings as $aValue ) {
884  $sOxId = oxUtilsObject::getInstance()->generateUId();
885 
886  $sModule = 'module:'.$sModuleId;
887  $sName = $aValue["name"];
888  $sType = $aValue["type"];
889  $sValue = is_null($oConfig->getConfigParam($sName))?$aValue["value"]:$oConfig->getConfigParam($sName);
890  $sGroup = $aValue["group"];
891 
892  $sConstraints = "";
893  if ( $aValue["constraints"] ) {
894  $sConstraints = $aValue["constraints"];
895  } elseif ( $aValue["constrains"] ) {
896  $sConstraints = $aValue["constrains"];
897  }
898 
899  $iPosition = $aValue["position"]?$aValue["position"]:1;
900 
901  $oConfig->setConfigParam($sName, $sValue);
902  $oConfig->saveShopConfVar($sType, $sName, $sValue, $sShopId, $sModule);
903 
904  $sDeleteSql = "DELETE FROM `oxconfigdisplay` WHERE OXCFGMODULE=".$oDb->quote($sModule)." AND OXCFGVARNAME=".$oDb->quote($sName);
905  $sInsertSql = "INSERT INTO `oxconfigdisplay` (`OXID`, `OXCFGMODULE`, `OXCFGVARNAME`, `OXGROUPING`, `OXVARCONSTRAINT`, `OXPOS`) ".
906  "VALUES ('{$sOxId}', ".$oDb->quote($sModule).", ".$oDb->quote($sName).", ".$oDb->quote($sGroup).", ".$oDb->quote($sConstraints).", ".$oDb->quote($iPosition).")";
907 
908  $oDb->execute( $sDeleteSql );
909  $oDb->execute( $sInsertSql );
910  }
911  }
912  }
913 
921  public function getTemplates( $sModuleId = null )
922  {
923  if (is_null($sModuleId)) {
924  $sModuleId = $this->getId();
925  }
926 
927  if (!$sModuleId) {
928  return array();
929  }
930 
931  $sShopId = $this->getConfig()->getShopId();
932 
933  $aTemplates = oxDb::getDb()->getCol("SELECT oxtemplate FROM oxtplblocks WHERE oxmodule = '$sModuleId' AND oxshopid = '$sShopId'" );
934 
935  return $aTemplates;
936  }
937 
949  public function saveLegacyModule($sModuleId, $sModuleName, $aModuleInfo = null)
950  {
951  $aLegacyModules = $this->getLegacyModules();
952 
953  if ( !empty( $aModuleInfo ) && is_array($aModuleInfo)) {
954  $aLegacyModules[$sModuleId]["id"] = $sModuleId;
955  $aLegacyModules[$sModuleId]["title"] = ( $sModuleName ) ? $sModuleName : $sModuleId;
956  $aLegacyModules[$sModuleId]['extend'] = array();
957 
958  foreach ( $aModuleInfo as $sKey => $sValue ) {
959  if ( strpos( $sValue, "=>" ) > 1 ) {
960  $aClassInfo = explode( "=>", $sValue );
961  $sClassName = trim( $aClassInfo[0] );
962  $sExtendString = trim( $aClassInfo[1] );
963  $aLegacyModules[$sModuleId]['extend'][$sClassName] = $sExtendString;
964  }
965  }
966  }
967 
968  if ( !empty( $aLegacyModules[$sModuleId]['extend'] ) ) {
969  $this->getConfig()->saveShopConfVar( "aarr", "aLegacyModules", $aLegacyModules );
970  }
971  return $sModuleId;
972  }
973 
982  public function updateModuleIds( $sModuleLegacyId, $sModuleId )
983  {
984  $oConfig = $this->getConfig();
985 
986  // updating module ID in aModulePaths config var
987  $aModulePaths = $oConfig->getConfigParam( 'aModulePaths' );
988  $aModulePaths[$sModuleId] = $aModulePaths[$sModuleLegacyId];
989  unset( $aModulePaths[$sModuleLegacyId] );
990 
991  $oConfig->saveShopConfVar( 'aarr', 'aModulePaths', $aModulePaths );
992 
993  if ( isset($aModulePaths[$sModuleLegacyId]) ) {
994  $aModulePaths[$sModuleId] = $aModulePaths[$sModuleLegacyId];
995  unset( $aModulePaths[$sModuleLegacyId] );
996  $oConfig->saveShopConfVar( 'aarr', 'aModulePaths', $aModulePaths );
997  }
998 
999  // updating module ID in aDisabledModules config var
1000  $aDisabledModules = $oConfig->getConfigParam( 'aDisabledModules' );
1001 
1002  if ( is_array($aDisabledModules) ) {
1003  $iOldKey = array_search( $sModuleLegacyId, $aDisabledModules );
1004  if ( $iOldKey !== false ) {
1005  unset( $aDisabledModules[$iOldKey] );
1006  $aDisabledModules[$iOldKey] = $sModuleId;
1007  $oConfig->saveShopConfVar( 'arr', 'aDisabledModules', $aDisabledModules );
1008  }
1009  }
1010  }
1011 
1015  protected function _clearApcCache()
1016  {
1017  if ( extension_loaded( 'apc' ) && ini_get( 'apc.enabled' ) ) {
1018  apc_clear_cache();
1019  }
1020  }
1021 
1025  protected function _removeFromDisabledList()
1026  {
1027  $oConfig = $this->getConfig();
1028  $aDisabledModules = $this->getDisabledModules();
1029  $sModuleId = $this->getId();
1030 
1031  if ( isset( $aDisabledModules ) && is_array( $aDisabledModules ) ) {
1032  $aDisabledModules = array_diff( $aDisabledModules, array($sModuleId) );
1033  $oConfig->setConfigParam( 'aDisabledModules', $aDisabledModules );
1034  $oConfig->saveShopConfVar( 'arr', 'aDisabledModules', $aDisabledModules );
1035  }
1036  }
1037 
1041  protected function _addExtensions()
1042  {
1043  $oConfig = $this->getConfig();
1044  $aModules = $this->_removeNotUsedExtensions( $this->getAllModules() );
1045 
1046  if ( $this->hasExtendClass() ) {
1047  $aAddModules = $this->getExtensions();
1048  $aModules = $this->mergeModuleArrays( $aModules, $aAddModules );
1049  }
1050 
1051  $aModules = $this->buildModuleChains( $aModules );
1052  $oConfig->setConfigParam( 'aModules', $aModules );
1053  $oConfig->saveShopConfVar( 'aarr', 'aModules', $aModules );
1054  }
1055 
1059  protected function _addToDisabledList( $sModuleId )
1060  {
1061  $oConfig = $this->getConfig();
1062  $aDisabledModules = $this->getDisabledModules();
1063 
1064  if ( !is_array( $aDisabledModules ) ) {
1065  $aDisabledModules = array();
1066  }
1067  $aModules = array_merge( $aDisabledModules, array( $sModuleId ) );
1068  $aModules = array_unique( $aModules );
1069 
1070  $oConfig->saveShopConfVar( 'arr', 'aDisabledModules', $aModules );
1071  $oConfig->setConfigParam( 'aDisabledModules', $aModules );
1072  }
1073 
1081  protected function _removeNotUsedExtensions( $aInstalledExtensions )
1082  {
1083  $aModuleExtensions = $this->getExtensions();
1084 
1085  $aInstalledModuleExtensions = $this->filterModuleArray( $aInstalledExtensions, $this->getId() );
1086 
1087  if ( count( $aInstalledModuleExtensions ) ) {
1088  $aGarbage = $this->_getModuleExtensionsGarbage( $aModuleExtensions, $aInstalledModuleExtensions );
1089 
1090  if ( count( $aGarbage ) ) {
1091  $aInstalledExtensions = $this->_removeGarbage( $aInstalledExtensions, $aGarbage );
1092  }
1093  }
1094 
1095  return $aInstalledExtensions;
1096  }
1097 
1106  protected function _getModuleExtensionsGarbage( $aModuleMetaDataExtensions, $aModuleInstalledExtensions )
1107  {
1108  $aGarbage = $aModuleInstalledExtensions;
1109 
1110  foreach ( $aModuleMetaDataExtensions as $sClassName => $sClassPath ) {
1111  if ( isset( $aGarbage[$sClassName] ) ) {
1112  unset( $aGarbage[$sClassName][ array_search( $sClassPath, $aGarbage[$sClassName] )] );
1113  if ( count( $aGarbage[$sClassName] ) == 0 ) {
1114  unset( $aGarbage[$sClassName] );
1115  }
1116  }
1117  }
1118 
1119  return $aGarbage;
1120  }
1121 
1130  protected function _removeGarbage( $aInstalledExtensions, $aGarbage )
1131  {
1132  foreach ( $aGarbage as $sClassName => $aClassPaths ) {
1133  foreach ( $aClassPaths as $sClassPath ) {
1134  if ( isset( $aInstalledExtensions[$sClassName] ) ) {
1135  unset( $aInstalledExtensions[$sClassName][ array_search( $sClassPath, $aInstalledExtensions[$sClassName] )] );
1136  if ( count( $aInstalledExtensions[$sClassName] ) == 0 ) {
1137  unset( $aInstalledExtensions[$sClassName] );
1138  }
1139  }
1140  }
1141  }
1142 
1143  return $aInstalledExtensions;
1144  }
1145 
1153  protected function _countActivatedExtensions( $aModuleExtensions, $aInstalledExtensions )
1154  {
1155  $iActive = 0;
1156  foreach ( $aModuleExtensions as $sClass => $mExtension ) {
1157  if ( is_array( $mExtension ) ) {
1158  foreach ( $mExtension as $sExtension ) {
1159  if ( ( isset( $aInstalledExtensions[$sClass] ) && in_array( $sExtension, $aInstalledExtensions[$sClass] ) ) ) {
1160  $iActive++;
1161  }
1162  }
1163  } elseif ( ( isset( $aInstalledExtensions[$sClass] ) && in_array( $mExtension, $aInstalledExtensions[$sClass] ) ) ) {
1164  $iActive++;
1165  }
1166  }
1167 
1168  return $iActive;
1169  }
1170 
1177  protected function _countExtensions( $aModuleExtensions )
1178  {
1179  $iCount = 0;
1180  foreach ( $aModuleExtensions as $mExtensions ) {
1181  if ( is_array( $mExtensions ) ) {
1182  $iCount += count( $mExtensions );
1183  } else {
1184  $iCount++;
1185  }
1186  }
1187 
1188  return $iCount;
1189  }
1190 
1196  protected function _isExtensionsActive()
1197  {
1198  $aModuleExtensions = $this->getExtensions();
1199  $aInstalledExtensions = $this->getAllModules();
1200  $iModuleExtensionsCount = $this->_countExtensions( $aModuleExtensions );
1201  $iActivatedModuleExtensionsCount = $this->_countActivatedExtensions( $aModuleExtensions, $aInstalledExtensions );
1202  $blActive = $iModuleExtensionsCount > 0 && $iActivatedModuleExtensionsCount == $iModuleExtensionsCount;
1203 
1204  return $blActive;
1205  }
1206 
1213  protected function _isInDisabledList( $sId )
1214  {
1215  $blInDisabledList = false;
1216 
1217  $aDisabledModules = $this->getDisabledModules();
1218  if ( is_array( $aDisabledModules ) && in_array( $sId, $aDisabledModules ) ) {
1219  $blInDisabledList = true;
1220  }
1221 
1222  return $blInDisabledList;
1223  }
1224 }