OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
oxtheme.php
Go to the documentation of this file.
1 <?php
2 
9 class oxTheme extends oxSuperCfg
10 {
11 
17  protected $_aTheme = array();
18 
24  protected $_aThemeList = array();
25 
33  public function load($sOXID)
34  {
35  $sFilePath = $this->getConfig()->getViewsDir() . $sOXID . "/theme.php";
36  if (file_exists($sFilePath) && is_readable($sFilePath)) {
37  $aTheme = array();
38  include $sFilePath;
39  $this->_aTheme = $aTheme;
40  $this->_aTheme['id'] = $sOXID;
41  $this->_aTheme['active'] = ($this->getActiveThemeId() == $sOXID);
42 
43  return true;
44  }
45 
46  return false;
47  }
48 
52  public function activate()
53  {
54  $sError = $this->checkForActivationErrors();
55  if ($sError) {
57  $oException = oxNew("oxException", $sError);
58  throw $oException;
59  }
60  $sParent = $this->getInfo('parentTheme');
61  if ($sParent) {
62  $this->getConfig()->saveShopConfVar("str", 'sTheme', $sParent);
63  $this->getConfig()->saveShopConfVar("str", 'sCustomTheme', $this->getId());
64  } else {
65  $this->getConfig()->saveShopConfVar("str", 'sTheme', $this->getId());
66  $this->getConfig()->saveShopConfVar("str", 'sCustomTheme', '');
67  }
68  }
69 
75  public function getList()
76  {
77  $this->_aThemeList = array();
78  $sOutDir = $this->getConfig()->getViewsDir();
79  foreach (glob($sOutDir . "*", GLOB_ONLYDIR) as $sDir) {
80  $oTheme = oxNew('oxTheme');
81  if ($oTheme->load(basename($sDir))) {
82  $this->_aThemeList[$sDir] = $oTheme;
83  }
84  }
85 
86  return $this->_aThemeList;
87  }
88 
96  public function getInfo($sName)
97  {
98  if (!isset($this->_aTheme[$sName])) {
99  return null;
100  }
101 
102  return $this->_aTheme[$sName];
103  }
104 
110  public function getActiveThemeId()
111  {
112  $sCustTheme = $this->getConfig()->getConfigParam('sCustomTheme');
113  if ($sCustTheme) {
114  return $sCustTheme;
115  }
116 
117  return $this->getConfig()->getConfigParam('sTheme');
118  }
119 
125  public function getParent()
126  {
127  $sParent = $this->getInfo('parentTheme');
128  if (!$sParent) {
129  return null;
130  }
131  $oTheme = oxNew('oxTheme');
132  if ($oTheme->load($sParent)) {
133  return $oTheme;
134  }
135 
136  return null;
137  }
138 
145  public function checkForActivationErrors()
146  {
147  if (!$this->getId()) {
148  return 'EXCEPTION_THEME_NOT_LOADED';
149  }
150  $oParent = $this->getParent();
151  if ($oParent) {
152  $sParentVersion = $oParent->getInfo('version');
153  if (!$sParentVersion) {
154  return 'EXCEPTION_PARENT_VERSION_UNSPECIFIED';
155  }
156  $aMyParentVersions = $this->getInfo('parentVersions');
157  if (!$aMyParentVersions || !is_array($aMyParentVersions)) {
158  return 'EXCEPTION_UNSPECIFIED_PARENT_VERSIONS';
159  }
160  if (!in_array($sParentVersion, $aMyParentVersions)) {
161  return 'EXCEPTION_PARENT_VERSION_MISMATCH';
162  }
163  } elseif ($this->getInfo('parentTheme')) {
164  return 'EXCEPTION_PARENT_THEME_NOT_FOUND';
165  }
166 
167  return false;
168  }
169 
175  public function getId()
176  {
177  return $this->getInfo("id");
178  }
179 }