OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
oxconfig.php
Go to the documentation of this file.
1 <?php
2 
3 //max integer
4 define('MAX_64BIT_INTEGER', '18446744073709551615');
5 
10 class oxConfig extends oxSuperCfg
11 {
12 
13  // this column of params are defined in config.inc.php file,
14  // so for backwards compatibility. names starts without underscore
15 
21  protected $dbHost = null;
22 
28  protected $dbName = null;
29 
35  protected $dbUser = null;
36 
42  protected $dbPwd = null;
43 
49  protected $dbType = null;
50 
56  protected $sShopURL = null;
57 
63  protected $sSSLShopURL = null;
64 
70  protected $sAdminSSLURL = null;
71 
77  protected $sShopDir = null;
78 
84  protected $sCompileDir = null;
85 
100  protected $iDebug = null;
101 
107  protected $sAdminEmail = null;
108 
114  protected $blSessionUseCookies = null;
115 
125  protected $blNativeImages = true;
126 
132  protected $aMultiShopTables = array('oxarticles', 'oxdiscount', 'oxcategories', 'oxattribute',
133  'oxlinks', 'oxvoucherseries', 'oxmanufacturers',
134  // @deprecated since v.5.3.0 (2016-06-17); The Admin Menu: Customer Info -> News feature will be moved to a module in v6.0.0
135  'oxnews',
136  // END deprecated
137  'oxselectlist', 'oxwrapping',
138  'oxdeliveryset', 'oxdelivery', 'oxvendor', 'oxobject2category');
139 
145  private $_oStart = null;
146 
147 
153  protected $_oActShop = null;
154 
162  protected $_aActiveViews = array();
163 
169  protected $_aGlobalParams = array();
170 
176  protected $_aConfigParams = array();
177 
183  protected $_aThemeConfigParams = array();
184 
190  protected $_iLanguageId = null;
191 
197  protected $_iShopId = null;
198 
199 
205  protected $_sOutDir = 'out';
206 
212  protected $_sImageDir = 'img';
213 
219  protected $_sPictureDir = 'pictures';
220 
226  protected $_sMasterPictureDir = 'master';
227 
233  protected $_sTemplateDir = 'tpl';
234 
240  protected $_sResourceDir = 'src';
241 
247  protected $_sModulesDir = 'modules';
248 
254  protected $_blIsSsl = null;
255 
261  protected $_aAbsDynImageDir = array();
262 
268  protected $_oActCurrencyObject = null;
269 
277  protected $_blInit = false;
278 
284  const OXMODULE_THEME_PREFIX = 'theme:';
285 
291  const OXMODULE_MODULE_PREFIX = 'module:';
292 
300  public function getConfigParam($sName)
301  {
302  if (defined('OXID_PHP_UNIT')) {
303  if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
304  $sValue = modConfig::$unitMOD->getModConfigParam($sName);
305  if ($sValue !== null) {
306  return $sValue;
307  }
308  }
309  }
310 
311  $this->init();
312 
313  if (isset ($this->_aConfigParams[$sName])) {
314  return $this->_aConfigParams[$sName];
315  }
316 
317  if (isset($this->$sName)) {
318  return $this->$sName;
319  }
320  }
321 
328  public function setConfigParam($sName, $sValue)
329  {
330  if (isset($this->$sName)) {
331  $this->$sName = $sValue;
332  } else {
333  $this->_aConfigParams[$sName] = $sValue;
334  }
335  }
336 
340  protected function _processSeoCall()
341  {
342  // TODO: refactor shop bootstrap and parse url params as soon as possible
343  if (isSearchEngineUrl()) {
344  oxNew('oxSeoDecoder')->processSeoCall();
345  }
346  }
347 
355  public function init()
356  {
357  // Duplicated init protection
358  if ($this->_blInit) {
359  return;
360  }
361  $this->_blInit = true;
362 
363  $this->_loadVarsFromFile();
364 
365  include getShopBasePath() . 'core/oxconfk.php';
366 
367  // @deprecated since v5.3 (2016-05-24); Adodblite will be removed.
368  // setting ADODB timeout
369  global $ADODB_SESS_LIFE;
370  $ADODB_SESS_LIFE = 1;
371  // END deprecated
372 
373  $this->_setDefaults();
374 
375  try {
376  $sShopID = $this->getShopId();
377 
378 
379  $blConfigLoaded = $this->_loadVarsFromDb($sShopID);
380  // loading shop config
381  if (empty($sShopID) || !$blConfigLoaded) {
382  // if no config values where loaded (some problems with DB), throwing an exception
383  $oEx = new oxConnectionException();
384  $oEx->setMessage("Unable to load shop config values from database");
385  throw $oEx;
386  }
387 
388  // loading theme config options
389  $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme'));
390 
391  // checking if custom theme (which has defined parent theme) config options should be loaded over parent theme (#3362)
392  if ($this->getConfigParam('sCustomTheme')) {
393  $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme'));
394  }
395 
396  // loading modules config
397  $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_MODULE_PREFIX);
398 
399 
400  $this->_processSeoCall();
401 
402  //starting up the session
403  $this->getSession()->start();
404 
405 
406  // Admin handling
407  $this->setConfigParam('blAdmin', isAdmin());
408 
409  if (defined('OX_ADMIN_DIR')) {
410  $this->setConfigParam('sAdminDir', OX_ADMIN_DIR);
411  }
412 
413  $this->_loadVarsFromFile();
414 
415  //application initialization
416  $this->_oStart = new oxStart();
417  $this->_oStart->appInit();
418  } catch (oxConnectionException $oEx) {
419  return $this->_handleDbConnectionException($oEx);
420  } catch (oxCookieException $oEx) {
421  return $this->_handleCookieException($oEx);
422  }
423  }
424 
428  protected function _loadVarsFromFile()
429  {
430  //config variables from config.inc.php takes priority over the ones loaded from db
431  include getShopBasePath() . '/config.inc.php';
432 
433  //adding trailing slashes
434  $oFileUtils = oxRegistry::get("oxUtilsFile");
435  $this->sShopDir = $oFileUtils->normalizeDir($this->sShopDir);
436  $this->sCompileDir = $oFileUtils->normalizeDir($this->sCompileDir);
437  $this->sShopURL = $oFileUtils->normalizeDir($this->sShopURL);
438  $this->sSSLShopURL = $oFileUtils->normalizeDir($this->sSSLShopURL);
439  $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
440 
441  $this->_loadCustomConfig();
442  }
443 
447  protected function _setDefaults()
448  {
449 
450  $this->setConfigParam('sTheme', 'azure');
451 
452  if (is_null($this->getConfigParam('sDefaultLang'))) {
453  $this->setConfigParam('sDefaultLang', 0);
454  }
455 
456  if (is_null($this->getConfigParam('blLogChangesInAdmin'))) {
457  $this->setConfigParam('blLogChangesInAdmin', false);
458  }
459 
460  if (is_null($this->getConfigParam('blCheckTemplates'))) {
461  $this->setConfigParam('blCheckTemplates', false);
462  }
463 
464  if (is_null($this->getConfigParam('blAllowArticlesubclass'))) {
465  $this->setConfigParam('blAllowArticlesubclass', false);
466  }
467 
468  if (is_null($this->getConfigParam('iAdminListSize'))) {
469  $this->setConfigParam('iAdminListSize', 9);
470  }
471 
472  // #1173M for EE - not all pic are deleted
473  if (is_null($this->getConfigParam('iPicCount'))) {
474  $this->setConfigParam('iPicCount', 7);
475  }
476 
477  if (is_null($this->getConfigParam('iZoomPicCount'))) {
478  $this->setConfigParam('iZoomPicCount', 4);
479  }
480 
481  // @deprecated since v5.3 (2016-05-24); Adodblite will be removed.
482  // ADODB cache life time
483  if (is_null($this->getConfigParam('iDBCacheLifeTime'))) {
484  $this->setConfigParam('iDBCacheLifeTime', 3600); // 1 hour
485  }
486  // END deprecated
487 
488  if (is_null($this->getConfigParam('iDebug'))) {
489  $this->setConfigParam('iDebug', $this->isProductiveMode() ? 0 : -1);
490  }
491 
492  $sCoreDir = $this->getConfigParam('sShopDir');
493  $this->setConfigParam('sCoreDir', $sCoreDir . '/core/');
494  }
495 
499  protected function _loadCustomConfig()
500  {
501  $sCustConfig = getShopBasePath() . '/cust_config.inc.php';
502  if (is_readable($sCustConfig)) {
503  include $sCustConfig;
504  }
505  }
506 
516  protected function _loadVarsFromDb($sShopID, $aOnlyVars = null, $sModule = '')
517  {
518  $oDb = oxDb::getDb();
519 
520  $sModuleSql = $sModule ? " oxmodule LIKE " . $oDb->quote($sModule . "%") : " oxmodule='' ";
521  $sOnlyVarsSql = $this->_getConfigParamsSelectSnippet($aOnlyVars);
522 
523  $sSelect = "select
524  oxvarname, oxvartype, " . $this->getDecodeValueQuery() . " as oxvarvalue
525  from oxconfig
526  where oxshopid = '$sShopID' and " . $sModuleSql . $sOnlyVarsSql;
527 
528  $aResult = $oDb->getAll($sSelect);
529 
530  foreach ($aResult as $aValue) {
531  $sVarName = $aValue[0];
532  $sVarType = $aValue[1];
533  $sVarVal = $aValue[2];
534 
535  $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
536 
537  //setting theme options array
538  if ($sModule) {
539  $this->_aThemeConfigParams[$sVarName] = $sModule;
540  }
541  }
542 
543  return (bool) count($aResult);
544  }
545 
553  protected function _getConfigParamsSelectSnippet($aVars)
554  {
555  $sSelect = '';
556  if (is_array($aVars) && !empty($aVars)) {
557  foreach ($aVars as &$sField) {
558  $sField = '"' . $sField . '"';
559  }
560  $sSelect = ' and oxvarname in ( ' . implode(', ', $aVars) . ' ) ';
561  }
562 
563  return $sSelect;
564  }
565 
576  protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
577  {
578  if (($sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL') &&
579  (!$sVarVal || $this->isAdmin() === true)
580  ) {
581  return;
582  }
583 
584  switch ($sVarType) {
585  case 'arr':
586  case 'aarr':
587  $this->setConfigParam($sVarName, unserialize($sVarVal));
588  break;
589  case 'bool':
590  $this->setConfigParam($sVarName, ($sVarVal == 'true' || $sVarVal == '1'));
591  break;
592  default:
593  $this->setConfigParam($sVarName, $sVarVal);
594  break;
595  }
596  }
597 
603  public function pageClose()
604  {
605  if ($this->hasActiveViewsChain()) {
606  // do not commit session until active views chain exists
607  return;
608  }
609 
610  return $this->_oStart->pageClose();
611  }
612 
624  public function getRequestParameter($sName, $blRaw = false)
625  {
626  if (defined('OXID_PHP_UNIT')) {
627  if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
628  try {
629  $sValue = modConfig::getRequestParameter($sName, $blRaw);
630 
631  // TODO: remove this after special chars concept implementation
632  $blIsAdmin = modConfig::getInstance()->isAdmin() || modSession::getInstance()->getVariable("blIsAdmin");
633  if ($sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
634  $this->checkParamSpecialChars($sValue, $blRaw);
635  }
636 
637  return $sValue;
638  } catch (Exception $e) {
639  // if exception is thrown, use default
640  }
641  }
642  }
643 
644  $sValue = null;
645 
646  if (isset($_POST[$sName])) {
647  $sValue = $_POST[$sName];
648  } elseif (isset($_GET[$sName])) {
649  $sValue = $_GET[$sName];
650  }
651 
652  // TODO: remove this after special chars concept implementation
653  $blIsAdmin = $this->isAdmin() && $this->getSession()->getVariable("blIsAdmin");
654  if ($sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
655  $this->checkParamSpecialChars($sValue, $blRaw);
656  }
657 
658  return $sValue;
659  }
660 
668  public function getUploadedFile($sParamName)
669  {
670  return $_FILES[$sParamName];
671  }
672 
679  public function setGlobalParameter($sName, $sValue)
680  {
681  $this->_aGlobalParams[$sName] = $sValue;
682  }
683 
691  public function getGlobalParameter($sName)
692  {
693  if (isset($this->_aGlobalParams[$sName])) {
694  return $this->_aGlobalParams[$sName];
695  } else {
696  return null;
697  }
698  }
699 
709  public function checkParamSpecialChars(& $sValue, $aRaw = null)
710  {
711  if (is_object($sValue)) {
712  return $sValue;
713  }
714 
715  if (is_array($sValue)) {
716  $newValue = array();
717  foreach ($sValue as $sKey => $sVal) {
718  $sValidKey = $sKey;
719  if (!$aRaw || !in_array($sKey, $aRaw)) {
720  $this->checkParamSpecialChars($sValidKey);
721  $this->checkParamSpecialChars($sVal);
722  if ($sValidKey != $sKey) {
723  unset ($sValue[$sKey]);
724  }
725  }
726  $newValue[$sValidKey] = $sVal;
727  }
728  $sValue = $newValue;
729  } elseif (is_string($sValue)) {
730  $sValue = str_replace(
731  array('&', '<', '>', '"', "'", chr(0), '\\', "\n", "\r"),
732  array('&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '', '&#092;', '&#10;', '&#13;'),
733  $sValue
734  );
735  }
736 
737  return $sValue;
738  }
739 
747  public function setShopId($sShopId)
748  {
749 
750  $this->getSession()->setVariable('actshop', $sShopId);
751  $this->_iShopId = $sShopId;
752  }
753 
759  public function getShopId()
760  {
761  if ($this->_iShopId !== null) {
762  return $this->_iShopId;
763  }
764 
765  $this->setShopId($this->getBaseShopId());
766 
767 
768  $this->getSession()->setVariable('actshop', $this->_iShopId);
769 
770  return $this->_iShopId;
771  }
772 
773 
774 
775 
781  public function setIsSsl($blIsSsl = false)
782  {
783  $this->_blIsSsl = $blIsSsl;
784  }
785 
789  protected function _checkSsl()
790  {
791  $myUtilsServer = oxRegistry::get("oxUtilsServer");
792  $aServerVars = $myUtilsServer->getServerVar();
793  $aHttpsServerVar = $myUtilsServer->getServerVar('HTTPS');
794 
795  $this->setIsSsl();
796  if (isset($aHttpsServerVar) && ($aHttpsServerVar === 'on' || $aHttpsServerVar === 'ON' || $aHttpsServerVar == '1')) {
797  // "1&1" hoster provides "1"
798  $this->setIsSsl($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
799  if ($this->isAdmin() && !$this->_blIsSsl) {
800  //#4026
801  $this->setIsSsl(!is_null($this->getConfigParam('sAdminSSLURL')));
802  }
803  }
804 
805  //additional special handling for profihost customers
806  if (isset($aServerVars['HTTP_X_FORWARDED_SERVER']) &&
807  (strpos($aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl') !== false ||
808  strpos($aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de') !== false)
809  ) {
810  $this->setIsSsl(true);
811  }
812  }
813 
814 
820  public function isSsl()
821  {
822  if (is_null($this->_blIsSsl)) {
823  $this->_checkSsl();
824  }
825 
826  return $this->_blIsSsl;
827  }
828 
836  public function isCurrentUrl($sURL)
837  {
838  // Missing protocol, cannot proceed, assuming true.
839  if (!$sURL || (strpos($sURL, "http") !== 0)) {
840  return true;
841  }
842 
843  return oxRegistry::get("oxUtilsServer")->isCurrentUrl($sURL);
844  }
845 
853  public function isCurrentProtocol($sURL)
854  {
855  // Missing protocol, cannot proceed, assuming true.
856  if (!$sURL || (strpos($sURL, "http") !== 0)) {
857  return true;
858  }
859 
860  return (strpos($sURL, "https:") === 0) == $this->isSsl();
861  }
862 
871  public function getShopUrl($iLang = null, $blAdmin = null)
872  {
873  $sUrl = null;
874  $blAdmin = isset($blAdmin) ? $blAdmin : $this->isAdmin();
875 
876  if (!$blAdmin) {
877  $sUrl = $this->getShopUrlByLanguage($iLang);
878  if (!$sUrl) {
879  $sUrl = $this->getMallShopUrl();
880  }
881  }
882 
883  if (!$sUrl) {
884  $sUrl = $this->getConfigParam('sShopURL');
885  }
886 
887  return $sUrl;
888  }
889 
897  public function getSslShopUrl($iLang = null)
898  {
899  $sUrl = null;
900 
901  if (!$sUrl) {
902  $sUrl = $this->getShopUrlByLanguage($iLang, true);
903  }
904 
905  if (!$sUrl) {
906  $sUrl = $this->getMallShopUrl(true);
907  }
908 
909  if (!$sUrl) {
910  $sUrl = $this->getMallShopUrl();
911  }
912 
913  //normal section
914  if (!$sUrl) {
915  $sUrl = $this->getConfigParam('sSSLShopURL');
916  }
917 
918  if (!$sUrl) {
919  $sUrl = $this->getShopUrl($iLang);
920  }
921 
922  return $sUrl;
923  }
924 
930  public function getCoreUtilsUrl()
931  {
932  return $this->getCurrentShopUrl() . 'core/utils/';
933  }
934 
943  public function getCurrentShopUrl($blAdmin = null)
944  {
945  if ($blAdmin === null) {
946  $blAdmin = $this->isAdmin();
947  }
948  if ($blAdmin) {
949  if ($this->isSsl()) {
950 
951  $sUrl = $this->getConfigParam('sAdminSSLURL');
952  if (!$sUrl) {
953  return $this->getSslShopUrl() . $this->getConfigParam('sAdminDir') . '/';
954  }
955 
956  return $sUrl;
957  } else {
958  return $this->getShopUrl() . $this->getConfigParam('sAdminDir') . '/';
959  }
960  } else {
961  return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
962  }
963  }
964 
972  public function getShopCurrentUrl($iLang = null)
973  {
974  if ($this->isSsl()) {
975  $sURL = $this->getSSLShopURL($iLang);
976  } else {
977  $sURL = $this->getShopURL($iLang);
978  }
979 
980  return oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'index.php', false);
981  }
982 
991  public function getShopHomeUrl($iLang = null, $blAdmin = null)
992  {
993  return oxRegistry::get("oxUtilsUrl")->processUrl($this->getShopUrl($iLang, $blAdmin) . 'index.php', false);
994  }
995 
1004  public function getWidgetUrl($iLang = null, $blAdmin = null)
1005  {
1006  $sUrl = $this->isSsl() ? $this->getSslShopUrl($iLang) : $this->getShopUrl($iLang, $blAdmin);
1007 
1008  return oxRegistry::get('oxUtilsUrl')->processUrl($sUrl . 'widget.php', false);
1009  }
1010 
1016  public function getShopSecureHomeUrl()
1017  {
1018  return oxRegistry::get("oxUtilsUrl")->processUrl($this->getSslShopUrl() . 'index.php', false);
1019  }
1020 
1026  public function getShopCurrency()
1027  {
1028  $iCurr = null;
1029  if ((null === ($iCurr = $this->getRequestParameter('cur')))) {
1030  if (null === ($iCurr = $this->getRequestParameter('currency'))) {
1031  $iCurr = $this->getSession()->getVariable('currency');
1032  }
1033  }
1034 
1035  return (int) $iCurr;
1036  }
1037 
1043  public function getActShopCurrencyObject()
1044  {
1045  //caching currency as it does not change through the script
1046  //but not for unit tests as ther it changes always
1047  if (!defined('OXID_PHP_UNIT')) {
1048  if (!is_null($this->_oActCurrencyObject)) {
1050  }
1051  }
1052 
1053  $iCur = $this->getShopCurrency();
1054  $aCurrencies = $this->getCurrencyArray();
1055  if (!isset($aCurrencies[$iCur])) {
1056  return $this->_oActCurrencyObject = reset($aCurrencies); // reset() returns the first element
1057  }
1058 
1059  return $this->_oActCurrencyObject = $aCurrencies[$iCur];
1060  }
1061 
1067  public function setActShopCurrency($iCur)
1068  {
1069  $aCurrencies = $this->getCurrencyArray();
1070  if (isset($aCurrencies[$iCur])) {
1071  $this->getSession()->setVariable('currency', $iCur);
1072  $this->_oActCurrencyObject = null;
1073  }
1074  }
1075 
1083  public function getOutDir($blAbsolute = true)
1084  {
1085  if ($blAbsolute) {
1086  return $this->getConfigParam('sShopDir') . $this->_sOutDir . '/';
1087  } else {
1088  return $this->_sOutDir . '/';
1089  }
1090  }
1091 
1099  public function getViewsDir($blAbsolute = true)
1100  {
1101  if ($blAbsolute) {
1102  return $this->getConfigParam('sShopDir') . 'application/views/';
1103  } else {
1104  return 'application/views/';
1105  }
1106  }
1107 
1117  public function getTranslationsDir($sFile, $sDir, $blAbsolute = true)
1118  {
1119  $sPath = $blAbsolute ? $this->getConfigParam('sShopDir') : '';
1120  $sPath .= 'application/translations/';
1121  if (is_readable($sPath . $sDir . '/' . $sFile)) {
1122  return $sPath . $sDir . '/' . $sFile;
1123  }
1124 
1125  return false;
1126  }
1127 
1135  public function getAppDir($blAbsolute = true)
1136  {
1137  if ($blAbsolute) {
1138  return $this->getConfigParam('sShopDir') . 'application/';
1139  } else {
1140  return 'application/';
1141  }
1142  }
1143 
1153  public function getOutUrl($blSSL = null, $blAdmin = null, $blNativeImg = false)
1154  {
1155  $blSSL = is_null($blSSL) ? $this->isSsl() : $blSSL;
1156  $blAdmin = is_null($blAdmin) ? $this->isAdmin() : $blAdmin;
1157 
1158  if ($blSSL) {
1159  if ($blNativeImg && !$blAdmin) {
1160  $sUrl = $this->getSslShopUrl();
1161  } else {
1162  $sUrl = $this->getConfigParam('sSSLShopURL');
1163  if (!$sUrl && $blAdmin) {
1164  $sUrl = $this->getConfigParam('sAdminSSLURL') . '../';
1165  }
1166  }
1167  } else {
1168  $sUrl = ($blNativeImg && !$blAdmin) ? $this->getShopUrl() : $this->getConfigParam('sShopURL');
1169  }
1170 
1171  return $sUrl . $this->_sOutDir . '/';
1172  }
1173 
1188  public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false)
1189  {
1190  if (is_null($sTheme)) {
1191  $sTheme = $this->getConfigParam('sTheme');
1192  }
1193 
1194  if ($blAdmin) {
1195  $sTheme = 'admin';
1196  }
1197 
1198  if ($sDir != $this->_sTemplateDir) {
1199  $sBase = $this->getOutDir($blAbsolute);
1200  $sAbsBase = $this->getOutDir();
1201  } else {
1202  $sBase = $this->getViewsDir($blAbsolute);
1203  $sAbsBase = $this->getViewsDir();
1204  }
1205 
1206  $sLang = '-';
1207  // FALSE means skip language folder check
1208  if ($iLang !== false) {
1209  $oLang = oxRegistry::getLang();
1210 
1211  if (is_null($iLang)) {
1212  $iLang = $oLang->getEditLanguage();
1213  }
1214 
1215  $sLang = $oLang->getLanguageAbbr($iLang);
1216  }
1217 
1218  if (is_null($iShop)) {
1219  $iShop = $this->getShopId();
1220  }
1221 
1222  //Load from
1223  $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
1224  $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
1225 
1226  if (($sReturn = oxRegistry::getUtils()->fromStaticCache($sCacheKey)) !== null) {
1227  return $sReturn;
1228  }
1229 
1230  $sReturn = false;
1231 
1232  // Check for custom template
1233  $sCustomTheme = $this->getConfigParam('sCustomTheme');
1234  if (!$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
1235  $sReturn = $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute);
1236  }
1237 
1238  //test lang level ..
1239  if (!$sReturn && !$blAdmin && is_readable($sAbsBase . $sPath)) {
1240  $sReturn = $sBase . $sPath;
1241  }
1242 
1243  //test shop level ..
1244  $sPath = "$sTheme/$iShop/$sDir/$sFile";
1245  if (!$sReturn && !$blAdmin && is_readable($sAbsBase . $sPath)) {
1246  $sReturn = $sBase . $sPath;
1247  }
1248 
1249 
1250  //test theme language level ..
1251  $sPath = "$sTheme/$sLang/$sDir/$sFile";
1252  if (!$sReturn && $iLang !== false && is_readable($sAbsBase . $sPath)) {
1253  $sReturn = $sBase . $sPath;
1254  }
1255 
1256  //test theme level ..
1257  $sPath = "$sTheme/$sDir/$sFile";
1258  if (!$sReturn && is_readable($sAbsBase . $sPath)) {
1259  $sReturn = $sBase . $sPath;
1260  }
1261 
1262  //test out language level ..
1263  $sPath = "$sLang/$sDir/$sFile";
1264  if (!$sReturn && $iLang !== false && is_readable($sAbsBase . $sPath)) {
1265  $sReturn = $sBase . $sPath;
1266  }
1267 
1268  //test out level ..
1269  $sPath = "$sDir/$sFile";
1270  if (!$sReturn && is_readable($sAbsBase . $sPath)) {
1271  $sReturn = $sBase . $sPath;
1272  }
1273 
1274  if (!$sReturn) {
1275  // TODO: implement logic to log missing paths
1276  }
1277 
1278  // to cache
1279  oxRegistry::getUtils()->toStaticCache($sCacheKey, $sReturn);
1280 
1281  return $sReturn;
1282  }
1283 
1298  public function getUrl($sFile, $sDir, $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null, $iShop = null, $sTheme = null)
1299  {
1300  $sUrl = str_replace(
1301  $this->getOutDir(),
1302  $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
1303  $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme)
1304  );
1305 
1306  return $sUrl;
1307  }
1308 
1317  public function getImagePath($sFile, $blAdmin = false)
1318  {
1319  return $this->getDir($sFile, $this->_sImageDir, $blAdmin);
1320  }
1321 
1332  public function getImageUrl($blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null)
1333  {
1334  $blNativeImg = is_null($blNativeImg) ? $this->getConfigParam('blNativeImages') : $blNativeImg;
1335 
1336  return $this->getUrl($sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg);
1337  }
1338 
1346  public function getImageDir($blAdmin = false)
1347  {
1348  return $this->getDir(null, $this->_sImageDir, $blAdmin);
1349  }
1350 
1362  public function getPicturePath($sFile, $blAdmin = false, $iLang = null, $iShop = null, $sTheme = null)
1363  {
1364  return $this->getDir($sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme);
1365  }
1366 
1374  public function getMasterPictureDir($blAdmin = false)
1375  {
1376  return $this->getDir(null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin);
1377  }
1378 
1387  public function getMasterPicturePath($sFile, $blAdmin = false)
1388  {
1389  return $this->getDir($sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin);
1390  }
1391 
1404  public function getPictureUrl($sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg")
1405  {
1406  if ($sAltUrl = oxRegistry::get("oxPictureHandler")->getAltImageUrl('/', $sFile, $blSSL)) {
1407  return $sAltUrl;
1408  }
1409 
1410  $blNativeImg = $this->getConfigParam('blNativeImages');
1411  $sUrl = $this->getUrl($sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId);
1412 
1413  //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
1414  if (!$sUrl && $sDefPic) {
1415  $sUrl = $this->getUrl($sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId);
1416  }
1417 
1418  return $sUrl;
1419  }
1420 
1428  public function getPictureDir($blAdmin)
1429  {
1430  return $this->getDir(null, $this->_sPictureDir, $blAdmin);
1431  }
1432 
1441  public function getTemplatePath($sFile, $blAdmin)
1442  {
1443  $sTemplatePath = $this->getDir($sFile, $this->_sTemplateDir, $blAdmin);
1444 
1445  if (!$sTemplatePath) {
1446  $sBasePath = getShopBasePath();
1447  $aModuleTemplates = $this->getConfigParam('aModuleTemplates');
1448 
1449  $oModulelist = oxNew('oxmodulelist');
1450  $aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
1451  if (is_array($aModuleTemplates) && is_array($aActiveModuleInfo)) {
1452  foreach ($aModuleTemplates as $sModuleId => $aTemplates) {
1453  if (isset($aTemplates[$sFile]) && isset($aActiveModuleInfo[$sModuleId])) {
1454  $sPath = $aTemplates[$sFile];
1455  $sPath = $sBasePath . 'modules/' . $sPath;
1456  if (is_file($sPath) && is_readable($sPath)) {
1457  $sTemplatePath = $sPath;
1458  }
1459  }
1460  }
1461  }
1462  }
1463 
1464  return $sTemplatePath;
1465  }
1466 
1474  public function getTemplateDir($blAdmin = false)
1475  {
1476  return $this->getDir(null, $this->_sTemplateDir, $blAdmin);
1477  }
1478 
1489  public function getTemplateUrl($sFile = null, $blAdmin = false, $blSSL = null, $iLang = null)
1490  {
1491  return $this->getShopMainUrl() . $this->getDir($sFile, $this->_sTemplateDir, $blAdmin, $iLang, null, null, false);
1492  }
1493 
1501  public function getTemplateBase($blAdmin = false)
1502  {
1503  // Base template dir is the parent dir of template dir
1504  return str_replace($this->_sTemplateDir . '/', '', $this->getDir(null, $this->_sTemplateDir, $blAdmin, null, null, null, false));
1505  }
1506 
1515  public function getResourcePath($sFile = '', $blAdmin = false)
1516  {
1517  return $this->getDir($sFile, $this->_sResourceDir, $blAdmin);
1518  }
1519 
1527  public function getModulesDir($blAbsolute = true)
1528  {
1529  if ($blAbsolute) {
1530  return $this->getConfigParam('sShopDir') . $this->_sModulesDir . '/';
1531  } else {
1532  return $this->_sModulesDir . '/';
1533  }
1534  }
1535 
1546  public function getResourceUrl($sFile = '', $blAdmin = false, $blSSL = null, $iLang = null)
1547  {
1548  $blNativeImg = $this->getConfigParam('blNativeImages');
1549 
1550  return $this->getUrl($sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang);
1551  }
1552 
1560  public function getResourceDir($blAdmin)
1561  {
1562  return $this->getDir(null, $this->_sResourceDir, $blAdmin);
1563  }
1564 
1572  public function getCurrencyArray($iCurrency = null)
1573  {
1574  $aConfCurrencies = $this->getConfigParam('aCurrencies');
1575  if (!is_array($aConfCurrencies)) {
1576  return array();
1577  }
1578 
1579  if (defined('OXID_PHP_UNIT')) {
1580  if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
1581  try {
1582  $aAltCurrencies = modConfig::getInstance()->getConfigParam('modaCurrencies');
1583  if (isset($aAltCurrencies)) {
1584  $aConfCurrencies = $aAltCurrencies;
1585  }
1586  } catch (Exception $e) {
1587  // if exception is thrown, use default
1588  }
1589  }
1590  }
1591 
1592  // processing currency configuration data
1593  $aCurrencies = array();
1594  reset($aConfCurrencies);
1595  while (list($key, $val) = each($aConfCurrencies)) {
1596  if ($val) {
1597  $oCur = new stdClass();
1598  $oCur->id = $key;
1599  $sCur = explode('@', $val);
1600  $oCur->name = trim($sCur[0]);
1601  $oCur->rate = trim($sCur[1]);
1602  $oCur->dec = trim($sCur[2]);
1603  $oCur->thousand = trim($sCur[3]);
1604  $oCur->sign = trim($sCur[4]);
1605  $oCur->decimal = trim($sCur[5]);
1606 
1607  // change for US version
1608  if (isset($sCur[6])) {
1609  $oCur->side = trim($sCur[6]);
1610  }
1611 
1612  if (isset($iCurrency) && $key == $iCurrency) {
1613  $oCur->selected = 1;
1614  } else {
1615  $oCur->selected = 0;
1616  }
1617  $aCurrencies[$key] = $oCur;
1618  }
1619 
1620  // #861C - performance, do not load other currencies
1621  if (!$this->getConfigParam('bl_perfLoadCurrency')) {
1622  break;
1623  }
1624  }
1625 
1626  return $aCurrencies;
1627  }
1628 
1636  public function getCurrencyObject($sName)
1637  {
1638  $aSearch = $this->getCurrencyArray();
1639  foreach ($aSearch as $oCur) {
1640  if ($oCur->name == $sName) {
1641  return $oCur;
1642  }
1643  }
1644  }
1645 
1651  public function isDemoShop()
1652  {
1653  return $this->getConfigParam('blDemoShop');
1654  }
1655 
1656 
1657 
1663  public function getEdition()
1664  {
1665  return "CE";
1666 
1667 
1668  }
1669 
1675  public function getFullEdition()
1676  {
1677  $sEdition = $this->getEdition();
1678 
1679  if ($sEdition == "CE") {
1680  return "Community Edition";
1681  }
1682 
1683 
1684 
1685  return $sEdition;
1686  }
1687 
1693  public function getVersion()
1694  {
1695  $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
1696 
1697  return $sVersion;
1698  }
1699 
1705  public function getRevision()
1706  {
1707  $sFileName = $this->getConfigParam('sShopDir') . "/pkg.rev";
1708  $sRev = trim(@file_get_contents($sFileName));
1709 
1710  if (!$sRev) {
1711  return false;
1712  }
1713 
1714  return $sRev;
1715  }
1716 
1722  public function getPackageInfo()
1723  {
1724  $sFileName = $this->getConfigParam('sShopDir') . "/pkg.info";
1725  $sRev = @file_get_contents($sFileName);
1726  $sRev = str_replace("\n", "<br>", $sRev);
1727 
1728  if (!$sRev) {
1729  return false;
1730  }
1731 
1732  return $sRev;
1733  }
1734 
1740  public function getMandateCount()
1741  {
1742  $iShopCount = 1;
1743 
1744 
1745  return $iShopCount;
1746  }
1747 
1753  public function isMall()
1754  {
1755 
1756  return false;
1757  }
1758 
1768  public function detectVersion()
1769  {
1770  }
1771 
1772 
1773 
1784  public function saveShopConfVar($sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '')
1785  {
1786  switch ($sVarType) {
1787  case 'arr':
1788  case 'aarr':
1789  $sValue = serialize($sVarVal);
1790  break;
1791  case 'bool':
1792  //config param
1793  $sVarVal = (($sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
1794  //db value
1795  $sValue = $sVarVal ? "1" : "";
1796  break;
1797  case 'num':
1798  //config param
1799  $sVarVal = $sVarVal != '' ? oxRegistry::getUtils()->string2Float($sVarVal) : '';
1800  $sValue = $sVarVal;
1801  break;
1802  default:
1803  $sValue = $sVarVal;
1804  break;
1805  }
1806 
1807  if (!$sShopId) {
1808  $sShopId = $this->getShopId();
1809  }
1810 
1811  // Update value only for current shop
1812  if ($sShopId == $this->getShopId()) {
1813  $this->setConfigParam($sVarName, $sVarVal);
1814  }
1815 
1816  $oDb = oxDb::getDb();
1817  $sShopIdQuoted = $oDb->quote($sShopId);
1818  $sModuleQuoted = $oDb->quote($sModule);
1819  $sVarNameQuoted = $oDb->quote($sVarName);
1820  $sVarTypeQuoted = $oDb->quote($sVarType);
1821  $sVarValueQuoted = $oDb->quote($sValue);
1822  $sConfigKeyQuoted = $oDb->quote($this->getConfigParam('sConfigKey'));
1823  $sNewOXIDdQuoted = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
1824 
1825  $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
1826  $oDb->execute($sQ);
1827 
1828  $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
1829  values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
1830  $oDb->execute($sQ);
1831 
1832 
1833  }
1834 
1835 
1845  public function getShopConfVar($sVarName, $sShopId = null, $sModule = '')
1846  {
1847  if (!$sShopId) {
1848  $sShopId = $this->getShopId();
1849  }
1850 
1851  if ($sShopId == $this->getShopId() && (!$sModule || $sModule == oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme'))) {
1852  $sVarValue = $this->getConfigParam($sVarName);
1853  if ($sVarValue !== null) {
1854  return $sVarValue;
1855  }
1856  }
1857 
1859 
1860  $sQ = "select oxvartype, " . $this->getDecodeValueQuery() . " as oxvarvalue from oxconfig where oxshopid = '{$sShopId}' and oxmodule = '{$sModule}' and oxvarname = " . $oDb->quote($sVarName);
1861  $oRs = $oDb->select($sQ);
1862 
1863  $sValue = null;
1864  if ($oRs != false && $oRs->recordCount() > 0) {
1865  $sValue = $this->decodeValue($oRs->fields['oxvartype'], $oRs->fields['oxvarvalue']);
1866  }
1867 
1868  return $sValue;
1869  }
1870 
1879  public function decodeValue($sType, $mOrigValue)
1880  {
1881  $sValue = $mOrigValue;
1882  switch ($sType) {
1883  case 'arr':
1884  case 'aarr':
1885  $sValue = unserialize($mOrigValue);
1886  break;
1887  case 'bool':
1888  $sValue = ($mOrigValue == 'true' || $mOrigValue == '1');
1889  break;
1890  }
1891 
1892  return $sValue;
1893  }
1894 
1902  public function getDecodeValueQuery($sFieldName = "oxvarvalue")
1903  {
1904  return " DECODE( {$sFieldName}, '" . $this->getConfigParam('sConfigKey') . "') ";
1905  }
1906 
1912  public function isProductiveMode()
1913  {
1914  $blProductive = $this->getConfigParam('blProductive');
1915  if (!isset($blProductive)) {
1916  $sQ = 'select oxproductive from oxshops where oxid = "' . $this->getShopId() . '"';
1917  $blProductive = ( bool ) oxDb::getDb()->getOne($sQ);
1918  $this->setConfigParam('blProductive', $blProductive);
1919  }
1920 
1921  return $blProductive;
1922  }
1923 
1924 
1925 
1931  public function getBaseShopId()
1932  {
1933 
1934  return 'oxbaseshop';
1935  }
1936 
1942  public function getActiveShop()
1943  {
1944  if ($this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
1945  $this->_oActShop->getLanguage() == oxRegistry::getLang()->getBaseLanguage()
1946  ) {
1947  return $this->_oActShop;
1948  }
1949 
1950  $this->_oActShop = oxNew('oxshop');
1951  $this->_oActShop->load($this->getShopId());
1952 
1953  return $this->_oActShop;
1954  }
1955 
1961  public function getActiveView()
1962  {
1963  if (count($this->_aActiveViews)) {
1964  $oActView = end($this->_aActiveViews);
1965  }
1966  if (!isset($oActView) || $oActView == null) {
1967  $oActView = oxNew('oxubase');
1968  $this->_aActiveViews[] = $oActView;
1969  }
1970 
1971  return $oActView;
1972  }
1973 
1979  public function getTopActiveView()
1980  {
1981  if (count($this->_aActiveViews)) {
1982  return reset($this->_aActiveViews);
1983  } else {
1984  return $this->getActiveView();
1985  }
1986  }
1987 
1993  public function getActiveViewsList()
1994  {
1995  return $this->_aActiveViews;
1996  }
1997 
2003  public function setActiveView($oView)
2004  {
2005  $this->_aActiveViews[] = $oView;
2006  }
2007 
2011  public function dropLastActiveView()
2012  {
2013  array_pop($this->_aActiveViews);
2014  }
2015 
2021  public function hasActiveViewsChain()
2022  {
2023  return (count($this->_aActiveViews) > 1);
2024  }
2025 
2031  public function getActiveViewsNames()
2032  {
2033  $aNames = array();
2034 
2035  if (is_array($this->getActiveViewsList())) {
2036  foreach ($this->getActiveViewsList() as $oView) {
2037  $aNames[] = $oView->getClassName();
2038  }
2039  }
2040 
2041  return $aNames;
2042  }
2043 
2049  public function isUtf()
2050  {
2051  return ( bool ) $this->getConfigParam('iUtfMode');
2052  }
2053 
2059  public function getLogsDir()
2060  {
2061  return $this->getConfigParam('sShopDir') . 'log/';
2062  }
2063 
2071  public function isThemeOption($sName)
2072  {
2073  return (bool) isset($this->_aThemeConfigParams[$sName]);
2074  }
2075 
2081  public function getShopMainUrl()
2082  {
2083  return $this->_blIsSsl ? $this->getConfigParam('sSSLShopURL') : $this->getConfigParam('sShopURL');
2084  }
2085 
2093  public function getAllModules()
2094  {
2095  return $this->getModulesWithExtendedClass();
2096  }
2097 
2104  {
2105  return $this->parseModuleChains($this->getConfigParam('aModules'));
2106  }
2107 
2115  public function parseModuleChains($aModules)
2116  {
2117  $aModuleArray = array();
2118 
2119  if (is_array($aModules)) {
2120  foreach ($aModules as $sClass => $sModuleChain) {
2121  if (strstr($sModuleChain, '&')) {
2122  $aModuleChain = explode('&', $sModuleChain);
2123  } else {
2124  $aModuleChain = array($sModuleChain);
2125  }
2126  $aModuleArray[$sClass] = $aModuleChain;
2127  }
2128  }
2129 
2130  return $aModuleArray;
2131  }
2132 
2138  public function getShopIds()
2139  {
2140  return oxDb::getDb()->getCol("SELECT `oxid` FROM `oxshops`");
2141  }
2142 
2152  public function getShopUrlByLanguage($iLang, $blSSL = false)
2153  {
2154  $sLanguageUrl = null;
2155  $sConfigParameter = $blSSL ? 'aLanguageSSLURLs' : 'aLanguageURLs';
2156  $iLang = isset($iLang) ? $iLang : oxRegistry::getLang()->getBaseLanguage();
2157  $aLanguageURLs = $this->getConfigParam($sConfigParameter);
2158  if (isset($iLang) && isset($aLanguageURLs[$iLang]) && !empty($aLanguageURLs[$iLang])) {
2159  $aLanguageURLs[$iLang] = oxRegistry::getUtils()->checkUrlEndingSlash($aLanguageURLs[$iLang]);
2160  $sLanguageUrl = $aLanguageURLs[$iLang];
2161  }
2162 
2163  return $sLanguageUrl;
2164  }
2165 
2173  public function getMallShopUrl($blSSL = false)
2174  {
2175  $sUrl = null;
2176  $sConfigParameter = $blSSL ? 'sMallSSLShopURL' : 'sMallShopURL';
2177  $sMallShopURL = $this->getConfigParam($sConfigParameter);
2178  if ($sMallShopURL) {
2179  $sMallShopURL = oxRegistry::getUtils()->checkUrlEndingSlash($sMallShopURL);
2180  $sUrl = $sMallShopURL;
2181  }
2182 
2183  return $sUrl;
2184  }
2185 
2193  protected function _handleDbConnectionException($oEx)
2194  {
2195  $oEx->debugOut();
2196  if (defined('OXID_PHP_UNIT')) {
2197  return false;
2198  } elseif (0 != $this->iDebug) {
2199  oxRegistry::getUtils()->showMessageAndExit($oEx->getString());
2200  } else {
2201  header("HTTP/1.1 500 Internal Server Error");
2202  header("Location: offline.html");
2203  header("Connection: close");
2204  exit(1);
2205  }
2206  }
2207 
2213  protected function _handleCookieException($oEx)
2214  {
2215  $this->_processSeoCall();
2216 
2217  //starting up the session
2218  $this->getSession()->start();
2219 
2220  // redirect to start page and display the error
2221  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
2222  oxRegistry::getUtils()->redirect($this->getShopHomeURL() . 'cl=start', true, 302);
2223  }
2224 
2232  public function saveSystemConfigParameter($sParameterType, $sParameterName, $sParameterValue)
2233  {
2234  $this->saveShopConfVar($sParameterType, $sParameterName, $sParameterValue, $this->getBaseShopId());
2235  }
2236 
2244  public function getSystemConfigParameter($sParameterName)
2245  {
2246  return $this->getShopConfVar($sParameterName, $this->getBaseShopId());
2247  }
2248 }