Go to the documentation of this file.00001 <?php
00002
00009 class oxTheme extends oxSuperCfg
00010 {
00011
00017 protected $_aTheme = array();
00018
00024 protected $_aThemeList = array();
00025
00033 public function load($sOXID)
00034 {
00035 $sFilePath = $this->getConfig()->getViewsDir() . $sOXID . "/theme.php";
00036 if (file_exists($sFilePath) && is_readable($sFilePath)) {
00037 $aTheme = array();
00038 include $sFilePath;
00039 $this->_aTheme = $aTheme;
00040 $this->_aTheme['id'] = $sOXID;
00041 $this->_aTheme['active'] = ($this->getActiveThemeId() == $sOXID);
00042
00043 return true;
00044 }
00045
00046 return false;
00047 }
00048
00052 public function activate()
00053 {
00054 $sError = $this->checkForActivationErrors();
00055 if ($sError) {
00057 $oException = oxNew("oxException", $sError);
00058 throw $oException;
00059 }
00060 $sParent = $this->getInfo('parentTheme');
00061 if ($sParent) {
00062 $this->getConfig()->saveShopConfVar("str", 'sTheme', $sParent);
00063 $this->getConfig()->saveShopConfVar("str", 'sCustomTheme', $this->getId());
00064 } else {
00065 $this->getConfig()->saveShopConfVar("str", 'sTheme', $this->getId());
00066 $this->getConfig()->saveShopConfVar("str", 'sCustomTheme', '');
00067 }
00068 }
00069
00075 public function getList()
00076 {
00077 $this->_aThemeList = array();
00078 $sOutDir = $this->getConfig()->getViewsDir();
00079 foreach (glob($sOutDir . "*", GLOB_ONLYDIR) as $sDir) {
00080 $oTheme = oxNew('oxTheme');
00081 if ($oTheme->load(basename($sDir))) {
00082 $this->_aThemeList[$sDir] = $oTheme;
00083 }
00084 }
00085
00086 return $this->_aThemeList;
00087 }
00088
00096 public function getInfo($sName)
00097 {
00098 if (!isset($this->_aTheme[$sName])) {
00099 return null;
00100 }
00101
00102 return $this->_aTheme[$sName];
00103 }
00104
00110 public function getActiveThemeId()
00111 {
00112 $sCustTheme = $this->getConfig()->getConfigParam('sCustomTheme');
00113 if ($sCustTheme) {
00114 return $sCustTheme;
00115 }
00116
00117 return $this->getConfig()->getConfigParam('sTheme');
00118 }
00119
00125 public function getParent()
00126 {
00127 $sParent = $this->getInfo('parentTheme');
00128 if (!$sParent) {
00129 return null;
00130 }
00131 $oTheme = oxNew('oxTheme');
00132 if ($oTheme->load($sParent)) {
00133 return $oTheme;
00134 }
00135
00136 return null;
00137 }
00138
00145 public function checkForActivationErrors()
00146 {
00147 if (!$this->getId()) {
00148 return 'EXCEPTION_THEME_NOT_LOADED';
00149 }
00150 $oParent = $this->getParent();
00151 if ($oParent) {
00152 $sParentVersion = $oParent->getInfo('version');
00153 if (!$sParentVersion) {
00154 return 'EXCEPTION_PARENT_VERSION_UNSPECIFIED';
00155 }
00156 $aMyParentVersions = $this->getInfo('parentVersions');
00157 if (!$aMyParentVersions || !is_array($aMyParentVersions)) {
00158 return 'EXCEPTION_UNSPECIFIED_PARENT_VERSIONS';
00159 }
00160 if (!in_array($sParentVersion, $aMyParentVersions)) {
00161 return 'EXCEPTION_PARENT_VERSION_MISMATCH';
00162 }
00163 } elseif ($this->getInfo('parentTheme')) {
00164 return 'EXCEPTION_PARENT_THEME_NOT_FOUND';
00165 }
00166
00167 return false;
00168 }
00169
00175 public function getId()
00176 {
00177 return $this->getInfo("id");
00178 }
00179 }