OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxtheme.php
Go to the documentation of this file.
1 <?php
2 
7 class oxTheme extends oxSuperCfg
8 {
13  protected $_aTheme = array();
14 
19  protected $_aThemeList = array();
20 
28  public function load($sOXID)
29  {
30  $sFilePath = $this->getConfig()->getViewsDir().$sOXID."/theme.php";
31  if ( file_exists( $sFilePath ) && is_readable( $sFilePath ) ) {
32  $aTheme = array();
33  include $sFilePath;
34  $this->_aTheme = $aTheme;
35  $this->_aTheme['id'] = $sOXID;
36  $this->_aTheme['active'] = ($this->getActiveThemeId() == $sOXID);
37  return true;
38  }
39 
40  return false;
41  }
42 
48  public function activate()
49  {
50  $sError = $this->checkForActivationErrors();
51  if ($sError) {
52  throw oxNew( "oxException", $sError );
53  }
54  $sParent = $this->getInfo('parentTheme');
55  if ($sParent) {
56  $this->getConfig()->saveShopConfVar("str", 'sTheme', $sParent);
57  $this->getConfig()->saveShopConfVar("str", 'sCustomTheme', $this->getId());
58  } else {
59  $this->getConfig()->saveShopConfVar("str", 'sTheme', $this->getId());
60  $this->getConfig()->saveShopConfVar("str", 'sCustomTheme', '');
61  }
62  }
63 
69  public function getList()
70  {
71  $this->_aThemeList = array();
72  $sOutDir = $this->getConfig()->getViewsDir();
73  foreach ( glob( $sOutDir."*", GLOB_ONLYDIR ) as $sDir ) {
74  $oTheme = oxNew('oxTheme');
75  if ($oTheme->load(basename($sDir))) {
76  $this->_aThemeList[$sDir] = $oTheme;
77  }
78  }
79  return $this->_aThemeList;
80  }
81 
89  public function getInfo($sName)
90  {
91  if (!isset($this->_aTheme[$sName])) {
92  return null;
93  }
94  return $this->_aTheme[$sName];
95  }
96 
102  public function getActiveThemeId()
103  {
104  $sCustTheme = $this->getConfig()->getConfigParam('sCustomTheme');
105  if ($sCustTheme) {
106  return $sCustTheme;
107  }
108  return $this->getConfig()->getConfigParam('sTheme');
109  }
110 
116  public function getParent()
117  {
118  $sParent = $this->getInfo('parentTheme');
119  if (!$sParent) {
120  return null;
121  }
122  $oTheme = oxNew('oxTheme');
123  if ($oTheme->load($sParent)) {
124  return $oTheme;
125  }
126  return null;
127  }
128 
135  public function checkForActivationErrors()
136  {
137  if (!$this->getId()) {
138  return 'EXCEPTION_THEME_NOT_LOADED';
139  }
140  $oParent = $this->getParent();
141  if ($oParent) {
142  $sParentVersion = $oParent->getInfo('version');
143  if (!$sParentVersion) {
144  return 'EXCEPTION_PARENT_VERSION_UNSPECIFIED';
145  }
146  $aMyParentVersions = $this->getInfo('parentVersions');
147  if (!$aMyParentVersions || !is_array($aMyParentVersions)) {
148  return 'EXCEPTION_UNSPECIFIED_PARENT_VERSIONS';
149  }
150  if (!in_array($sParentVersion, $aMyParentVersions)) {
151  return 'EXCEPTION_PARENT_VERSION_MISMATCH';
152  }
153  } elseif ($this->getInfo('parentTheme')) {
154  return 'EXCEPTION_PARENT_THEME_NOT_FOUND';
155  }
156  return false;
157  }
158 
164  public function getId()
165  {
166  return $this->getInfo( "id" );
167  }
168 }
169