Go to the documentation of this file.00001 <?php
00002
00007 class oxTheme extends oxSuperCfg
00008 {
00013 protected $_aTheme = array();
00014
00019 protected $_aThemeList = array();
00020
00028 public function load($sOXID)
00029 {
00030 $sFilePath = $this->getConfig()->getOutDir().$sOXID."/theme.php";
00031 if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
00032 $aTheme = array();
00033 include $sFilePath;
00034 $this->_aTheme = $aTheme;
00035 $this->_aTheme['id'] = $sOXID;
00036 $this->_aTheme['active'] = ($this->getActiveThemeId() == $sOXID);
00037 return true;
00038 }
00039
00040 return false;
00041 }
00042
00048 public function activate()
00049 {
00050 $sError = $this->checkForActivationErrors();
00051 if ($sError) {
00052 throw new oxException($sError);
00053 }
00054 $sParent = $this->getInfo('parentTheme');
00055 if ($sParent) {
00056 $this->getConfig()->saveShopConfVar("str", 'sTheme', $sParent);
00057 $this->getConfig()->saveShopConfVar("str", 'sCustomTheme', $this->getInfo('id'));
00058 } else {
00059 $this->getConfig()->saveShopConfVar("str", 'sTheme', $this->getInfo('id'));
00060 $this->getConfig()->saveShopConfVar("str", 'sCustomTheme', '');
00061 }
00062 }
00063
00069 public function getList()
00070 {
00071 $this->_aThemeList = array();
00072 $sOutDir = $this->getConfig()->getOutDir();
00073 foreach ( glob( $sOutDir."*", GLOB_ONLYDIR ) as $sDir ) {
00074 $oTheme = oxNew('oxTheme');
00075 if ($oTheme->load(basename($sDir))) {
00076 $this->_aThemeList[$sDir] = $oTheme;
00077 }
00078 }
00079 return $this->_aThemeList;
00080 }
00081
00089 public function getInfo($sName)
00090 {
00091 if (!isset($this->_aTheme[$sName])) {
00092 return null;
00093 }
00094 return $this->_aTheme[$sName];
00095 }
00096
00102 public function getActiveThemeId()
00103 {
00104 $sCustTheme = $this->getConfig()->getConfigParam('sCustomTheme');
00105 if ($sCustTheme) {
00106 return $sCustTheme;
00107 }
00108 return $this->getConfig()->getConfigParam('sTheme');
00109 }
00110
00116 public function getParent()
00117 {
00118 $sParent = $this->getInfo('parentTheme');
00119 if (!$sParent) {
00120 return null;
00121 }
00122 $oTheme = oxNew('oxTheme');
00123 if ($oTheme->load($sParent)) {
00124 return $oTheme;
00125 }
00126 return null;
00127 }
00128
00135 public function checkForActivationErrors()
00136 {
00137 if (!$this->getInfo('id')) {
00138 return 'EXCEPTION_THEME_NOT_LOADED';
00139 }
00140 $oParent = $this->getParent();
00141 if ($oParent) {
00142 $sParentVersion = $oParent->getInfo('version');
00143 if (!$sParentVersion) {
00144 return 'EXCEPTION_PARENT_VERSION_UNSPECIFIED';
00145 }
00146 $aMyParentVersions = $this->getInfo('parentVersions');
00147 if (!$aMyParentVersions || !is_array($aMyParentVersions)) {
00148 return 'EXCEPTION_UNSPECIFIED_PARENT_VERSIONS';
00149 }
00150 if (!in_array($sParentVersion, $aMyParentVersions)) {
00151 return 'EXCEPTION_PARENT_VERSION_MISMATCH';
00152 }
00153 } elseif ($this->getInfo('parentTheme')) {
00154 return 'EXCEPTION_PARENT_THEME_NOT_FOUND';
00155 }
00156 return false;
00157 }
00158 }
00159