OXID eShop CE  4.9.9
 All Classes 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  'oxnews', 'oxselectlist', 'oxwrapping',
135  'oxdeliveryset', 'oxdelivery', 'oxvendor', 'oxobject2category');
136 
142  private $_oStart = null;
143 
144 
150  protected $_oActShop = null;
151 
159  protected $_aActiveViews = array();
160 
166  protected $_aGlobalParams = array();
167 
173  protected $_aConfigParams = array();
174 
180  protected $_aThemeConfigParams = array();
181 
187  protected $_iLanguageId = null;
188 
194  protected $_iShopId = null;
195 
196 
202  protected $_sOutDir = 'out';
203 
209  protected $_sImageDir = 'img';
210 
216  protected $_sPictureDir = 'pictures';
217 
223  protected $_sMasterPictureDir = 'master';
224 
230  protected $_sTemplateDir = 'tpl';
231 
237  protected $_sResourceDir = 'src';
238 
244  protected $_sModulesDir = 'modules';
245 
251  protected $_blIsSsl = null;
252 
258  protected $_aAbsDynImageDir = array();
259 
265  protected $_oActCurrencyObject = null;
266 
274  protected $_blInit = false;
275 
281  const OXMODULE_THEME_PREFIX = 'theme:';
282 
288  const OXMODULE_MODULE_PREFIX = 'module:';
289 
297  public function getConfigParam($sName)
298  {
299  if (defined('OXID_PHP_UNIT')) {
300  if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
301  $sValue = modConfig::$unitMOD->getModConfigParam($sName);
302  if ($sValue !== null) {
303  return $sValue;
304  }
305  }
306  }
307 
308  $this->init();
309 
310  if (isset ($this->_aConfigParams[$sName])) {
311  return $this->_aConfigParams[$sName];
312  }
313 
314  if (isset($this->$sName)) {
315  return $this->$sName;
316  }
317  }
318 
325  public function setConfigParam($sName, $sValue)
326  {
327  if (isset($this->$sName)) {
328  $this->$sName = $sValue;
329  } else {
330  $this->_aConfigParams[$sName] = $sValue;
331  }
332  }
333 
337  protected function _processSeoCall()
338  {
339  // TODO: refactor shop bootstrap and parse url params as soon as possible
340  if (isSearchEngineUrl()) {
341  oxNew('oxSeoDecoder')->processSeoCall();
342  }
343  }
344 
352  public function init()
353  {
354  // Duplicated init protection
355  if ($this->_blInit) {
356  return;
357  }
358  $this->_blInit = true;
359 
360  $this->_loadVarsFromFile();
361 
362  include getShopBasePath() . 'core/oxconfk.php';
363 
364  // setting ADODB timeout
365  global $ADODB_SESS_LIFE;
366  $ADODB_SESS_LIFE = 1;
367 
368  $this->_setDefaults();
369 
370  try {
371  $sShopID = $this->getShopId();
372 
373 
374  $blConfigLoaded = $this->_loadVarsFromDb($sShopID);
375  // loading shop config
376  if (empty($sShopID) || !$blConfigLoaded) {
377  // if no config values where loaded (some problems with DB), throwing an exception
378  $oEx = new oxConnectionException();
379  $oEx->setMessage("Unable to load shop config values from database");
380  throw $oEx;
381  }
382 
383  // loading theme config options
384  $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme'));
385 
386  // checking if custom theme (which has defined parent theme) config options should be loaded over parent theme (#3362)
387  if ($this->getConfigParam('sCustomTheme')) {
388  $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme'));
389  }
390 
391  // loading modules config
392  $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_MODULE_PREFIX);
393 
394 
395  $this->_processSeoCall();
396 
397  //starting up the session
398  $this->getSession()->start();
399 
400 
401  // Admin handling
402  $this->setConfigParam('blAdmin', isAdmin());
403 
404  if (defined('OX_ADMIN_DIR')) {
405  $this->setConfigParam('sAdminDir', OX_ADMIN_DIR);
406  }
407 
408  $this->_loadVarsFromFile();
409 
410  //application initialization
411  $this->_oStart = new oxStart();
412  $this->_oStart->appInit();
413  } catch (oxConnectionException $oEx) {
414  return $this->_handleDbConnectionException($oEx);
415  } catch (oxCookieException $oEx) {
416  return $this->_handleCookieException($oEx);
417  }
418  }
419 
423  protected function _loadVarsFromFile()
424  {
425  //config variables from config.inc.php takes priority over the ones loaded from db
426  include getShopBasePath() . '/config.inc.php';
427 
428  //adding trailing slashes
429  $oFileUtils = oxRegistry::get("oxUtilsFile");
430  $this->sShopDir = $oFileUtils->normalizeDir($this->sShopDir);
431  $this->sCompileDir = $oFileUtils->normalizeDir($this->sCompileDir);
432  $this->sShopURL = $oFileUtils->normalizeDir($this->sShopURL);
433  $this->sSSLShopURL = $oFileUtils->normalizeDir($this->sSSLShopURL);
434  $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
435 
436  $this->_loadCustomConfig();
437  }
438 
442  protected function _setDefaults()
443  {
444 
445  $this->setConfigParam('sTheme', 'azure');
446 
447  if (is_null($this->getConfigParam('sDefaultLang'))) {
448  $this->setConfigParam('sDefaultLang', 0);
449  }
450 
451  if (is_null($this->getConfigParam('blLogChangesInAdmin'))) {
452  $this->setConfigParam('blLogChangesInAdmin', false);
453  }
454 
455  if (is_null($this->getConfigParam('blCheckTemplates'))) {
456  $this->setConfigParam('blCheckTemplates', false);
457  }
458 
459  if (is_null($this->getConfigParam('blAllowArticlesubclass'))) {
460  $this->setConfigParam('blAllowArticlesubclass', false);
461  }
462 
463  if (is_null($this->getConfigParam('iAdminListSize'))) {
464  $this->setConfigParam('iAdminListSize', 9);
465  }
466 
467  // #1173M for EE - not all pic are deleted
468  if (is_null($this->getConfigParam('iPicCount'))) {
469  $this->setConfigParam('iPicCount', 7);
470  }
471 
472  if (is_null($this->getConfigParam('iZoomPicCount'))) {
473  $this->setConfigParam('iZoomPicCount', 4);
474  }
475 
476  // ADODB cache life time
477  if (is_null($this->getConfigParam('iDBCacheLifeTime'))) {
478  $this->setConfigParam('iDBCacheLifeTime', 3600); // 1 hour
479  }
480 
481  if (is_null($this->getConfigParam('iDebug'))) {
482  $this->setConfigParam('iDebug', $this->isProductiveMode() ? 0 : -1);
483  }
484 
485  $sCoreDir = $this->getConfigParam('sShopDir');
486  $this->setConfigParam('sCoreDir', $sCoreDir . '/core/');
487  }
488 
492  protected function _loadCustomConfig()
493  {
494  $sCustConfig = getShopBasePath() . '/cust_config.inc.php';
495  if (is_readable($sCustConfig)) {
496  include $sCustConfig;
497  }
498  }
499 
509  protected function _loadVarsFromDb($sShopID, $aOnlyVars = null, $sModule = '')
510  {
511  $oDb = oxDb::getDb();
512 
513  $sModuleSql = $sModule ? " oxmodule LIKE " . $oDb->quote($sModule . "%") : " oxmodule='' ";
514  $sOnlyVarsSql = $this->_getConfigParamsSelectSnippet($aOnlyVars);
515 
516  $sSelect = "select
517  oxvarname, oxvartype, " . $this->getDecodeValueQuery() . " as oxvarvalue
518  from oxconfig
519  where oxshopid = '$sShopID' and " . $sModuleSql . $sOnlyVarsSql;
520 
521  $aResult = $oDb->getAll($sSelect);
522 
523  foreach ($aResult as $aValue) {
524  $sVarName = $aValue[0];
525  $sVarType = $aValue[1];
526  $sVarVal = $aValue[2];
527 
528  $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
529 
530  //setting theme options array
531  if ($sModule) {
532  $this->_aThemeConfigParams[$sVarName] = $sModule;
533  }
534  }
535 
536  return (bool) count($aResult);
537  }
538 
546  protected function _getConfigParamsSelectSnippet($aVars)
547  {
548  $sSelect = '';
549  if (is_array($aVars) && !empty($aVars)) {
550  foreach ($aVars as &$sField) {
551  $sField = '"' . $sField . '"';
552  }
553  $sSelect = ' and oxvarname in ( ' . implode(', ', $aVars) . ' ) ';
554  }
555 
556  return $sSelect;
557  }
558 
569  protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
570  {
571  if (($sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL') &&
572  (!$sVarVal || $this->isAdmin() === true)
573  ) {
574  return;
575  }
576 
577  switch ($sVarType) {
578  case 'arr':
579  case 'aarr':
580  $this->setConfigParam($sVarName, unserialize($sVarVal));
581  break;
582  case 'bool':
583  $this->setConfigParam($sVarName, ($sVarVal == 'true' || $sVarVal == '1'));
584  break;
585  default:
586  $this->setConfigParam($sVarName, $sVarVal);
587  break;
588  }
589  }
590 
596  public function pageClose()
597  {
598  if ($this->hasActiveViewsChain()) {
599  // do not commit session until active views chain exists
600  return;
601  }
602 
603  return $this->_oStart->pageClose();
604  }
605 
617  public function getRequestParameter($sName, $blRaw = false)
618  {
619  if (defined('OXID_PHP_UNIT')) {
620  if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
621  try {
622  $sValue = modConfig::getRequestParameter($sName, $blRaw);
623 
624  // TODO: remove this after special chars concept implementation
625  $blIsAdmin = modConfig::getInstance()->isAdmin() || modSession::getInstance()->getVariable("blIsAdmin");
626  if ($sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
627  $this->checkParamSpecialChars($sValue, $blRaw);
628  }
629 
630  return $sValue;
631  } catch (Exception $e) {
632  // if exception is thrown, use default
633  }
634  }
635  }
636 
637  $sValue = null;
638 
639  if (isset($_POST[$sName])) {
640  $sValue = $_POST[$sName];
641  } elseif (isset($_GET[$sName])) {
642  $sValue = $_GET[$sName];
643  }
644 
645  // TODO: remove this after special chars concept implementation
646  $blIsAdmin = $this->isAdmin() && $this->getSession()->getVariable("blIsAdmin");
647  if ($sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
648  $this->checkParamSpecialChars($sValue, $blRaw);
649  }
650 
651  return $sValue;
652  }
653 
661  public function getUploadedFile($sParamName)
662  {
663  return $_FILES[$sParamName];
664  }
665 
672  public function setGlobalParameter($sName, $sValue)
673  {
674  $this->_aGlobalParams[$sName] = $sValue;
675  }
676 
684  public function getGlobalParameter($sName)
685  {
686  if (isset($this->_aGlobalParams[$sName])) {
687  return $this->_aGlobalParams[$sName];
688  } else {
689  return null;
690  }
691  }
692 
702  public function checkParamSpecialChars(& $sValue, $aRaw = null)
703  {
704  if (is_object($sValue)) {
705  return $sValue;
706  }
707 
708  if (is_array($sValue)) {
709  $newValue = array();
710  foreach ($sValue as $sKey => $sVal) {
711  $sValidKey = $sKey;
712  if (!$aRaw || !in_array($sKey, $aRaw)) {
713  $this->checkParamSpecialChars($sValidKey);
714  $this->checkParamSpecialChars($sVal);
715  if ($sValidKey != $sKey) {
716  unset ($sValue[$sKey]);
717  }
718  }
719  $newValue[$sValidKey] = $sVal;
720  }
721  $sValue = $newValue;
722  } elseif (is_string($sValue)) {
723  $sValue = str_replace(
724  array('&', '<', '>', '"', "'", chr(0), '\\', "\n", "\r"),
725  array('&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '', '&#092;', '&#10;', '&#13;'),
726  $sValue
727  );
728  }
729 
730  return $sValue;
731  }
732 
740  public function setShopId($sShopId)
741  {
742 
743  $this->getSession()->setVariable('actshop', $sShopId);
744  $this->_iShopId = $sShopId;
745  }
746 
752  public function getShopId()
753  {
754  if ($this->_iShopId !== null) {
755  return $this->_iShopId;
756  }
757 
758  $this->setShopId($this->getBaseShopId());
759 
760 
761  $this->getSession()->setVariable('actshop', $this->_iShopId);
762 
763  return $this->_iShopId;
764  }
765 
766 
767 
768 
774  public function setIsSsl($blIsSsl = false)
775  {
776  $this->_blIsSsl = $blIsSsl;
777  }
778 
782  protected function _checkSsl()
783  {
784  $myUtilsServer = oxRegistry::get("oxUtilsServer");
785  $aServerVars = $myUtilsServer->getServerVar();
786  $aHttpsServerVar = $myUtilsServer->getServerVar('HTTPS');
787 
788  $this->setIsSsl();
789  if (isset($aHttpsServerVar) && ($aHttpsServerVar === 'on' || $aHttpsServerVar === 'ON' || $aHttpsServerVar == '1')) {
790  // "1&1" hoster provides "1"
791  $this->setIsSsl($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
792  if ($this->isAdmin() && !$this->_blIsSsl) {
793  //#4026
794  $this->setIsSsl(!is_null($this->getConfigParam('sAdminSSLURL')));
795  }
796  }
797 
798  //additional special handling for profihost customers
799  if (isset($aServerVars['HTTP_X_FORWARDED_SERVER']) &&
800  (strpos($aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl') !== false ||
801  strpos($aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de') !== false)
802  ) {
803  $this->setIsSsl(true);
804  }
805  }
806 
807 
813  public function isSsl()
814  {
815  if (is_null($this->_blIsSsl)) {
816  $this->_checkSsl();
817  }
818 
819  return $this->_blIsSsl;
820  }
821 
829  public function isCurrentUrl($sURL)
830  {
831  // Missing protocol, cannot proceed, assuming true.
832  if (!$sURL || (strpos($sURL, "http") !== 0)) {
833  return true;
834  }
835 
836  return oxRegistry::get("oxUtilsServer")->isCurrentUrl($sURL);
837  }
838 
846  public function isCurrentProtocol($sURL)
847  {
848  // Missing protocol, cannot proceed, assuming true.
849  if (!$sURL || (strpos($sURL, "http") !== 0)) {
850  return true;
851  }
852 
853  return (strpos($sURL, "https:") === 0) == $this->isSsl();
854  }
855 
864  public function getShopUrl($iLang = null, $blAdmin = null)
865  {
866  $sUrl = null;
867  $blAdmin = isset($blAdmin) ? $blAdmin : $this->isAdmin();
868 
869  if (!$blAdmin) {
870  $sUrl = $this->getShopUrlByLanguage($iLang);
871  if (!$sUrl) {
872  $sUrl = $this->getMallShopUrl();
873  }
874  }
875 
876  if (!$sUrl) {
877  $sUrl = $this->getConfigParam('sShopURL');
878  }
879 
880  return $sUrl;
881  }
882 
890  public function getSslShopUrl($iLang = null)
891  {
892  $sUrl = null;
893 
894  if (!$sUrl) {
895  $sUrl = $this->getShopUrlByLanguage($iLang, true);
896  }
897 
898  if (!$sUrl) {
899  $sUrl = $this->getMallShopUrl(true);
900  }
901 
902  if (!$sUrl) {
903  $sUrl = $this->getMallShopUrl();
904  }
905 
906  //normal section
907  if (!$sUrl) {
908  $sUrl = $this->getConfigParam('sSSLShopURL');
909  }
910 
911  if (!$sUrl) {
912  $sUrl = $this->getShopUrl($iLang);
913  }
914 
915  return $sUrl;
916  }
917 
923  public function getCoreUtilsUrl()
924  {
925  return $this->getCurrentShopUrl() . 'core/utils/';
926  }
927 
936  public function getCurrentShopUrl($blAdmin = null)
937  {
938  if ($blAdmin === null) {
939  $blAdmin = $this->isAdmin();
940  }
941  if ($blAdmin) {
942  if ($this->isSsl()) {
943 
944  $sUrl = $this->getConfigParam('sAdminSSLURL');
945  if (!$sUrl) {
946  return $this->getSslShopUrl() . $this->getConfigParam('sAdminDir') . '/';
947  }
948 
949  return $sUrl;
950  } else {
951  return $this->getShopUrl() . $this->getConfigParam('sAdminDir') . '/';
952  }
953  } else {
954  return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
955  }
956  }
957 
965  public function getShopCurrentUrl($iLang = null)
966  {
967  if ($this->isSsl()) {
968  $sURL = $this->getSSLShopURL($iLang);
969  } else {
970  $sURL = $this->getShopURL($iLang);
971  }
972 
973  return oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'index.php', false);
974  }
975 
984  public function getShopHomeUrl($iLang = null, $blAdmin = null)
985  {
986  return oxRegistry::get("oxUtilsUrl")->processUrl($this->getShopUrl($iLang, $blAdmin) . 'index.php', false);
987  }
988 
997  public function getWidgetUrl($iLang = null, $blAdmin = null)
998  {
999  $sUrl = $this->isSsl() ? $this->getSslShopUrl($iLang) : $this->getShopUrl($iLang, $blAdmin);
1000 
1001  return oxRegistry::get('oxUtilsUrl')->processUrl($sUrl . 'widget.php', false);
1002  }
1003 
1009  public function getShopSecureHomeUrl()
1010  {
1011  return oxRegistry::get("oxUtilsUrl")->processUrl($this->getSslShopUrl() . 'index.php', false);
1012  }
1013 
1019  public function getShopCurrency()
1020  {
1021  $iCurr = null;
1022  if ((null === ($iCurr = $this->getRequestParameter('cur')))) {
1023  if (null === ($iCurr = $this->getRequestParameter('currency'))) {
1024  $iCurr = $this->getSession()->getVariable('currency');
1025  }
1026  }
1027 
1028  return (int) $iCurr;
1029  }
1030 
1036  public function getActShopCurrencyObject()
1037  {
1038  //caching currency as it does not change through the script
1039  //but not for unit tests as ther it changes always
1040  if (!defined('OXID_PHP_UNIT')) {
1041  if (!is_null($this->_oActCurrencyObject)) {
1043  }
1044  }
1045 
1046  $iCur = $this->getShopCurrency();
1047  $aCurrencies = $this->getCurrencyArray();
1048  if (!isset($aCurrencies[$iCur])) {
1049  return $this->_oActCurrencyObject = reset($aCurrencies); // reset() returns the first element
1050  }
1051 
1052  return $this->_oActCurrencyObject = $aCurrencies[$iCur];
1053  }
1054 
1060  public function setActShopCurrency($iCur)
1061  {
1062  $aCurrencies = $this->getCurrencyArray();
1063  if (isset($aCurrencies[$iCur])) {
1064  $this->getSession()->setVariable('currency', $iCur);
1065  $this->_oActCurrencyObject = null;
1066  }
1067  }
1068 
1076  public function getOutDir($blAbsolute = true)
1077  {
1078  if ($blAbsolute) {
1079  return $this->getConfigParam('sShopDir') . $this->_sOutDir . '/';
1080  } else {
1081  return $this->_sOutDir . '/';
1082  }
1083  }
1084 
1092  public function getViewsDir($blAbsolute = true)
1093  {
1094  if ($blAbsolute) {
1095  return $this->getConfigParam('sShopDir') . 'application/views/';
1096  } else {
1097  return 'application/views/';
1098  }
1099  }
1100 
1110  public function getTranslationsDir($sFile, $sDir, $blAbsolute = true)
1111  {
1112  $sPath = $blAbsolute ? $this->getConfigParam('sShopDir') : '';
1113  $sPath .= 'application/translations/';
1114  if (is_readable($sPath . $sDir . '/' . $sFile)) {
1115  return $sPath . $sDir . '/' . $sFile;
1116  }
1117 
1118  return false;
1119  }
1120 
1128  public function getAppDir($blAbsolute = true)
1129  {
1130  if ($blAbsolute) {
1131  return $this->getConfigParam('sShopDir') . 'application/';
1132  } else {
1133  return 'application/';
1134  }
1135  }
1136 
1146  public function getOutUrl($blSSL = null, $blAdmin = null, $blNativeImg = false)
1147  {
1148  $blSSL = is_null($blSSL) ? $this->isSsl() : $blSSL;
1149  $blAdmin = is_null($blAdmin) ? $this->isAdmin() : $blAdmin;
1150 
1151  if ($blSSL) {
1152  if ($blNativeImg && !$blAdmin) {
1153  $sUrl = $this->getSslShopUrl();
1154  } else {
1155  $sUrl = $this->getConfigParam('sSSLShopURL');
1156  if (!$sUrl && $blAdmin) {
1157  $sUrl = $this->getConfigParam('sAdminSSLURL') . '../';
1158  }
1159  }
1160  } else {
1161  $sUrl = ($blNativeImg && !$blAdmin) ? $this->getShopUrl() : $this->getConfigParam('sShopURL');
1162  }
1163 
1164  return $sUrl . $this->_sOutDir . '/';
1165  }
1166 
1181  public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false)
1182  {
1183  if (is_null($sTheme)) {
1184  $sTheme = $this->getConfigParam('sTheme');
1185  }
1186 
1187  if ($blAdmin) {
1188  $sTheme = 'admin';
1189  }
1190 
1191  if ($sDir != $this->_sTemplateDir) {
1192  $sBase = $this->getOutDir($blAbsolute);
1193  $sAbsBase = $this->getOutDir();
1194  } else {
1195  $sBase = $this->getViewsDir($blAbsolute);
1196  $sAbsBase = $this->getViewsDir();
1197  }
1198 
1199  $sLang = '-';
1200  // FALSE means skip language folder check
1201  if ($iLang !== false) {
1202  $oLang = oxRegistry::getLang();
1203 
1204  if (is_null($iLang)) {
1205  $iLang = $oLang->getEditLanguage();
1206  }
1207 
1208  $sLang = $oLang->getLanguageAbbr($iLang);
1209  }
1210 
1211  if (is_null($iShop)) {
1212  $iShop = $this->getShopId();
1213  }
1214 
1215  //Load from
1216  $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
1217  $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
1218 
1219  if (($sReturn = oxRegistry::getUtils()->fromStaticCache($sCacheKey)) !== null) {
1220  return $sReturn;
1221  }
1222 
1223  $sReturn = false;
1224 
1225  // Check for custom template
1226  $sCustomTheme = $this->getConfigParam('sCustomTheme');
1227  if (!$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
1228  $sReturn = $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute);
1229  }
1230 
1231  //test lang level ..
1232  if (!$sReturn && !$blAdmin && is_readable($sAbsBase . $sPath)) {
1233  $sReturn = $sBase . $sPath;
1234  }
1235 
1236  //test shop level ..
1237  $sPath = "$sTheme/$iShop/$sDir/$sFile";
1238  if (!$sReturn && !$blAdmin && is_readable($sAbsBase . $sPath)) {
1239  $sReturn = $sBase . $sPath;
1240  }
1241 
1242 
1243  //test theme language level ..
1244  $sPath = "$sTheme/$sLang/$sDir/$sFile";
1245  if (!$sReturn && $iLang !== false && is_readable($sAbsBase . $sPath)) {
1246  $sReturn = $sBase . $sPath;
1247  }
1248 
1249  //test theme level ..
1250  $sPath = "$sTheme/$sDir/$sFile";
1251  if (!$sReturn && is_readable($sAbsBase . $sPath)) {
1252  $sReturn = $sBase . $sPath;
1253  }
1254 
1255  //test out language level ..
1256  $sPath = "$sLang/$sDir/$sFile";
1257  if (!$sReturn && $iLang !== false && is_readable($sAbsBase . $sPath)) {
1258  $sReturn = $sBase . $sPath;
1259  }
1260 
1261  //test out level ..
1262  $sPath = "$sDir/$sFile";
1263  if (!$sReturn && is_readable($sAbsBase . $sPath)) {
1264  $sReturn = $sBase . $sPath;
1265  }
1266 
1267  if (!$sReturn) {
1268  // TODO: implement logic to log missing paths
1269  }
1270 
1271  // to cache
1272  oxRegistry::getUtils()->toStaticCache($sCacheKey, $sReturn);
1273 
1274  return $sReturn;
1275  }
1276 
1291  public function getUrl($sFile, $sDir, $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null, $iShop = null, $sTheme = null)
1292  {
1293  $sUrl = str_replace(
1294  $this->getOutDir(),
1295  $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
1296  $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme)
1297  );
1298 
1299  return $sUrl;
1300  }
1301 
1310  public function getImagePath($sFile, $blAdmin = false)
1311  {
1312  return $this->getDir($sFile, $this->_sImageDir, $blAdmin);
1313  }
1314 
1325  public function getImageUrl($blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null)
1326  {
1327  $blNativeImg = is_null($blNativeImg) ? $this->getConfigParam('blNativeImages') : $blNativeImg;
1328 
1329  return $this->getUrl($sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg);
1330  }
1331 
1339  public function getImageDir($blAdmin = false)
1340  {
1341  return $this->getDir(null, $this->_sImageDir, $blAdmin);
1342  }
1343 
1355  public function getPicturePath($sFile, $blAdmin = false, $iLang = null, $iShop = null, $sTheme = null)
1356  {
1357  return $this->getDir($sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme);
1358  }
1359 
1367  public function getMasterPictureDir($blAdmin = false)
1368  {
1369  return $this->getDir(null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin);
1370  }
1371 
1380  public function getMasterPicturePath($sFile, $blAdmin = false)
1381  {
1382  return $this->getDir($sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin);
1383  }
1384 
1397  public function getPictureUrl($sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg")
1398  {
1399  if ($sAltUrl = oxRegistry::get("oxPictureHandler")->getAltImageUrl('/', $sFile, $blSSL)) {
1400  return $sAltUrl;
1401  }
1402 
1403  $blNativeImg = $this->getConfigParam('blNativeImages');
1404  $sUrl = $this->getUrl($sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId);
1405 
1406  //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
1407  if (!$sUrl && $sDefPic) {
1408  $sUrl = $this->getUrl($sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId);
1409  }
1410 
1411  return $sUrl;
1412  }
1413 
1421  public function getPictureDir($blAdmin)
1422  {
1423  return $this->getDir(null, $this->_sPictureDir, $blAdmin);
1424  }
1425 
1434  public function getTemplatePath($sFile, $blAdmin)
1435  {
1436  $sTemplatePath = $this->getDir($sFile, $this->_sTemplateDir, $blAdmin);
1437 
1438  if (!$sTemplatePath) {
1439  $sBasePath = getShopBasePath();
1440  $aModuleTemplates = $this->getConfigParam('aModuleTemplates');
1441 
1442  $oModulelist = oxNew('oxmodulelist');
1443  $aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
1444  if (is_array($aModuleTemplates) && is_array($aActiveModuleInfo)) {
1445  foreach ($aModuleTemplates as $sModuleId => $aTemplates) {
1446  if (isset($aTemplates[$sFile]) && isset($aActiveModuleInfo[$sModuleId])) {
1447  $sPath = $aTemplates[$sFile];
1448  $sPath = $sBasePath . 'modules/' . $sPath;
1449  if (is_file($sPath) && is_readable($sPath)) {
1450  $sTemplatePath = $sPath;
1451  }
1452  }
1453  }
1454  }
1455  }
1456 
1457  return $sTemplatePath;
1458  }
1459 
1467  public function getTemplateDir($blAdmin = false)
1468  {
1469  return $this->getDir(null, $this->_sTemplateDir, $blAdmin);
1470  }
1471 
1482  public function getTemplateUrl($sFile = null, $blAdmin = false, $blSSL = null, $iLang = null)
1483  {
1484  return $this->getShopMainUrl() . $this->getDir($sFile, $this->_sTemplateDir, $blAdmin, $iLang, null, null, false);
1485  }
1486 
1494  public function getTemplateBase($blAdmin = false)
1495  {
1496  // Base template dir is the parent dir of template dir
1497  return str_replace($this->_sTemplateDir . '/', '', $this->getDir(null, $this->_sTemplateDir, $blAdmin, null, null, null, false));
1498  }
1499 
1508  public function getResourcePath($sFile = '', $blAdmin = false)
1509  {
1510  return $this->getDir($sFile, $this->_sResourceDir, $blAdmin);
1511  }
1512 
1520  public function getModulesDir($blAbsolute = true)
1521  {
1522  if ($blAbsolute) {
1523  return $this->getConfigParam('sShopDir') . $this->_sModulesDir . '/';
1524  } else {
1525  return $this->_sModulesDir . '/';
1526  }
1527  }
1528 
1539  public function getResourceUrl($sFile = '', $blAdmin = false, $blSSL = null, $iLang = null)
1540  {
1541  $blNativeImg = $this->getConfigParam('blNativeImages');
1542 
1543  return $this->getUrl($sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang);
1544  }
1545 
1553  public function getResourceDir($blAdmin)
1554  {
1555  return $this->getDir(null, $this->_sResourceDir, $blAdmin);
1556  }
1557 
1565  public function getCurrencyArray($iCurrency = null)
1566  {
1567  $aConfCurrencies = $this->getConfigParam('aCurrencies');
1568  if (!is_array($aConfCurrencies)) {
1569  return array();
1570  }
1571 
1572  if (defined('OXID_PHP_UNIT')) {
1573  if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
1574  try {
1575  $aAltCurrencies = modConfig::getInstance()->getConfigParam('modaCurrencies');
1576  if (isset($aAltCurrencies)) {
1577  $aConfCurrencies = $aAltCurrencies;
1578  }
1579  } catch (Exception $e) {
1580  // if exception is thrown, use default
1581  }
1582  }
1583  }
1584 
1585  // processing currency configuration data
1586  $aCurrencies = array();
1587  reset($aConfCurrencies);
1588  while (list($key, $val) = each($aConfCurrencies)) {
1589  if ($val) {
1590  $oCur = new stdClass();
1591  $oCur->id = $key;
1592  $sCur = explode('@', $val);
1593  $oCur->name = trim($sCur[0]);
1594  $oCur->rate = trim($sCur[1]);
1595  $oCur->dec = trim($sCur[2]);
1596  $oCur->thousand = trim($sCur[3]);
1597  $oCur->sign = trim($sCur[4]);
1598  $oCur->decimal = trim($sCur[5]);
1599 
1600  // change for US version
1601  if (isset($sCur[6])) {
1602  $oCur->side = trim($sCur[6]);
1603  }
1604 
1605  if (isset($iCurrency) && $key == $iCurrency) {
1606  $oCur->selected = 1;
1607  } else {
1608  $oCur->selected = 0;
1609  }
1610  $aCurrencies[$key] = $oCur;
1611  }
1612 
1613  // #861C - performance, do not load other currencies
1614  if (!$this->getConfigParam('bl_perfLoadCurrency')) {
1615  break;
1616  }
1617  }
1618 
1619  return $aCurrencies;
1620  }
1621 
1629  public function getCurrencyObject($sName)
1630  {
1631  $aSearch = $this->getCurrencyArray();
1632  foreach ($aSearch as $oCur) {
1633  if ($oCur->name == $sName) {
1634  return $oCur;
1635  }
1636  }
1637  }
1638 
1644  public function isDemoShop()
1645  {
1646  return $this->getConfigParam('blDemoShop');
1647  }
1648 
1649 
1650 
1656  public function getEdition()
1657  {
1658  return "CE";
1659 
1660 
1661  }
1662 
1668  public function getFullEdition()
1669  {
1670  $sEdition = $this->getEdition();
1671 
1672  if ($sEdition == "CE") {
1673  return "Community Edition";
1674  }
1675 
1676 
1677 
1678  return $sEdition;
1679  }
1680 
1686  public function getVersion()
1687  {
1688  $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
1689 
1690  return $sVersion;
1691  }
1692 
1698  public function getRevision()
1699  {
1700  $sFileName = $this->getConfigParam('sShopDir') . "/pkg.rev";
1701  $sRev = trim(@file_get_contents($sFileName));
1702 
1703  if (!$sRev) {
1704  return false;
1705  }
1706 
1707  return $sRev;
1708  }
1709 
1715  public function getPackageInfo()
1716  {
1717  $sFileName = $this->getConfigParam('sShopDir') . "/pkg.info";
1718  $sRev = @file_get_contents($sFileName);
1719  $sRev = str_replace("\n", "<br>", $sRev);
1720 
1721  if (!$sRev) {
1722  return false;
1723  }
1724 
1725  return $sRev;
1726  }
1727 
1733  public function getMandateCount()
1734  {
1735  $iShopCount = 1;
1736 
1737 
1738  return $iShopCount;
1739  }
1740 
1746  public function isMall()
1747  {
1748 
1749  return false;
1750  }
1751 
1761  public function detectVersion()
1762  {
1763  }
1764 
1765 
1766 
1777  public function saveShopConfVar($sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '')
1778  {
1779  switch ($sVarType) {
1780  case 'arr':
1781  case 'aarr':
1782  $sValue = serialize($sVarVal);
1783  break;
1784  case 'bool':
1785  //config param
1786  $sVarVal = (($sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
1787  //db value
1788  $sValue = $sVarVal ? "1" : "";
1789  break;
1790  case 'num':
1791  //config param
1792  $sVarVal = $sVarVal != '' ? oxRegistry::getUtils()->string2Float($sVarVal) : '';
1793  $sValue = $sVarVal;
1794  break;
1795  default:
1796  $sValue = $sVarVal;
1797  break;
1798  }
1799 
1800  if (!$sShopId) {
1801  $sShopId = $this->getShopId();
1802  }
1803 
1804  // Update value only for current shop
1805  if ($sShopId == $this->getShopId()) {
1806  $this->setConfigParam($sVarName, $sVarVal);
1807  }
1808 
1809  $oDb = oxDb::getDb();
1810  $sShopIdQuoted = $oDb->quote($sShopId);
1811  $sModuleQuoted = $oDb->quote($sModule);
1812  $sVarNameQuoted = $oDb->quote($sVarName);
1813  $sVarTypeQuoted = $oDb->quote($sVarType);
1814  $sVarValueQuoted = $oDb->quote($sValue);
1815  $sConfigKeyQuoted = $oDb->quote($this->getConfigParam('sConfigKey'));
1816  $sNewOXIDdQuoted = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
1817 
1818  $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
1819  $oDb->execute($sQ);
1820 
1821  $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
1822  values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
1823  $oDb->execute($sQ);
1824 
1825 
1826  }
1827 
1828 
1838  public function getShopConfVar($sVarName, $sShopId = null, $sModule = '')
1839  {
1840  if (!$sShopId) {
1841  $sShopId = $this->getShopId();
1842  }
1843 
1844  if ($sShopId == $this->getShopId() && (!$sModule || $sModule == oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme'))) {
1845  $sVarValue = $this->getConfigParam($sVarName);
1846  if ($sVarValue !== null) {
1847  return $sVarValue;
1848  }
1849  }
1850 
1852 
1853  $sQ = "select oxvartype, " . $this->getDecodeValueQuery() . " as oxvarvalue from oxconfig where oxshopid = '{$sShopId}' and oxmodule = '{$sModule}' and oxvarname = " . $oDb->quote($sVarName);
1854  $oRs = $oDb->select($sQ);
1855 
1856  $sValue = null;
1857  if ($oRs != false && $oRs->recordCount() > 0) {
1858  $sValue = $this->decodeValue($oRs->fields['oxvartype'], $oRs->fields['oxvarvalue']);
1859  }
1860 
1861  return $sValue;
1862  }
1863 
1872  public function decodeValue($sType, $mOrigValue)
1873  {
1874  $sValue = $mOrigValue;
1875  switch ($sType) {
1876  case 'arr':
1877  case 'aarr':
1878  $sValue = unserialize($mOrigValue);
1879  break;
1880  case 'bool':
1881  $sValue = ($mOrigValue == 'true' || $mOrigValue == '1');
1882  break;
1883  }
1884 
1885  return $sValue;
1886  }
1887 
1895  public function getDecodeValueQuery($sFieldName = "oxvarvalue")
1896  {
1897  return " DECODE( {$sFieldName}, '" . $this->getConfigParam('sConfigKey') . "') ";
1898  }
1899 
1905  public function isProductiveMode()
1906  {
1907  $blProductive = $this->getConfigParam('blProductive');
1908  if (!isset($blProductive)) {
1909  $sQ = 'select oxproductive from oxshops where oxid = "' . $this->getShopId() . '"';
1910  $blProductive = ( bool ) oxDb::getDb()->getOne($sQ);
1911  $this->setConfigParam('blProductive', $blProductive);
1912  }
1913 
1914  return $blProductive;
1915  }
1916 
1917 
1918 
1924  public function getBaseShopId()
1925  {
1926 
1927  return 'oxbaseshop';
1928  }
1929 
1935  public function getActiveShop()
1936  {
1937  if ($this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
1938  $this->_oActShop->getLanguage() == oxRegistry::getLang()->getBaseLanguage()
1939  ) {
1940  return $this->_oActShop;
1941  }
1942 
1943  $this->_oActShop = oxNew('oxshop');
1944  $this->_oActShop->load($this->getShopId());
1945 
1946  return $this->_oActShop;
1947  }
1948 
1954  public function getActiveView()
1955  {
1956  if (count($this->_aActiveViews)) {
1957  $oActView = end($this->_aActiveViews);
1958  }
1959  if (!isset($oActView) || $oActView == null) {
1960  $oActView = oxNew('oxubase');
1961  $this->_aActiveViews[] = $oActView;
1962  }
1963 
1964  return $oActView;
1965  }
1966 
1972  public function getTopActiveView()
1973  {
1974  if (count($this->_aActiveViews)) {
1975  return reset($this->_aActiveViews);
1976  } else {
1977  return $this->getActiveView();
1978  }
1979  }
1980 
1986  public function getActiveViewsList()
1987  {
1988  return $this->_aActiveViews;
1989  }
1990 
1996  public function setActiveView($oView)
1997  {
1998  $this->_aActiveViews[] = $oView;
1999  }
2000 
2004  public function dropLastActiveView()
2005  {
2006  array_pop($this->_aActiveViews);
2007  }
2008 
2014  public function hasActiveViewsChain()
2015  {
2016  return (count($this->_aActiveViews) > 1);
2017  }
2018 
2024  public function getActiveViewsNames()
2025  {
2026  $aNames = array();
2027 
2028  if (is_array($this->getActiveViewsList())) {
2029  foreach ($this->getActiveViewsList() as $oView) {
2030  $aNames[] = $oView->getClassName();
2031  }
2032  }
2033 
2034  return $aNames;
2035  }
2036 
2042  public function isUtf()
2043  {
2044  return ( bool ) $this->getConfigParam('iUtfMode');
2045  }
2046 
2052  public function getLogsDir()
2053  {
2054  return $this->getConfigParam('sShopDir') . 'log/';
2055  }
2056 
2064  public function isThemeOption($sName)
2065  {
2066  return (bool) isset($this->_aThemeConfigParams[$sName]);
2067  }
2068 
2074  public function getShopMainUrl()
2075  {
2076  return $this->_blIsSsl ? $this->getConfigParam('sSSLShopURL') : $this->getConfigParam('sShopURL');
2077  }
2078 
2086  public function getAllModules()
2087  {
2088  return $this->getModulesWithExtendedClass();
2089  }
2090 
2097  {
2098  return $this->parseModuleChains($this->getConfigParam('aModules'));
2099  }
2100 
2108  public function parseModuleChains($aModules)
2109  {
2110  $aModuleArray = array();
2111 
2112  if (is_array($aModules)) {
2113  foreach ($aModules as $sClass => $sModuleChain) {
2114  if (strstr($sModuleChain, '&')) {
2115  $aModuleChain = explode('&', $sModuleChain);
2116  } else {
2117  $aModuleChain = array($sModuleChain);
2118  }
2119  $aModuleArray[$sClass] = $aModuleChain;
2120  }
2121  }
2122 
2123  return $aModuleArray;
2124  }
2125 
2131  public function getShopIds()
2132  {
2133  return oxDb::getDb()->getCol("SELECT `oxid` FROM `oxshops`");
2134  }
2135 
2145  public function getShopUrlByLanguage($iLang, $blSSL = false)
2146  {
2147  $sLanguageUrl = null;
2148  $sConfigParameter = $blSSL ? 'aLanguageSSLURLs' : 'aLanguageURLs';
2149  $iLang = isset($iLang) ? $iLang : oxRegistry::getLang()->getBaseLanguage();
2150  $aLanguageURLs = $this->getConfigParam($sConfigParameter);
2151  if (isset($iLang) && isset($aLanguageURLs[$iLang]) && !empty($aLanguageURLs[$iLang])) {
2152  $aLanguageURLs[$iLang] = oxRegistry::getUtils()->checkUrlEndingSlash($aLanguageURLs[$iLang]);
2153  $sLanguageUrl = $aLanguageURLs[$iLang];
2154  }
2155 
2156  return $sLanguageUrl;
2157  }
2158 
2166  public function getMallShopUrl($blSSL = false)
2167  {
2168  $sUrl = null;
2169  $sConfigParameter = $blSSL ? 'sMallSSLShopURL' : 'sMallShopURL';
2170  $sMallShopURL = $this->getConfigParam($sConfigParameter);
2171  if ($sMallShopURL) {
2172  $sMallShopURL = oxRegistry::getUtils()->checkUrlEndingSlash($sMallShopURL);
2173  $sUrl = $sMallShopURL;
2174  }
2175 
2176  return $sUrl;
2177  }
2178 
2186  protected function _handleDbConnectionException($oEx)
2187  {
2188  $oEx->debugOut();
2189  if (defined('OXID_PHP_UNIT')) {
2190  return false;
2191  } elseif (0 != $this->iDebug) {
2192  oxRegistry::getUtils()->showMessageAndExit($oEx->getString());
2193  } else {
2194  header("HTTP/1.1 500 Internal Server Error");
2195  header("Location: offline.html");
2196  header("Connection: close");
2197  exit(1);
2198  }
2199  }
2200 
2206  protected function _handleCookieException($oEx)
2207  {
2208  $this->_processSeoCall();
2209 
2210  //starting up the session
2211  $this->getSession()->start();
2212 
2213  // redirect to start page and display the error
2214  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
2215  oxRegistry::getUtils()->redirect($this->getShopHomeURL() . 'cl=start', true, 302);
2216  }
2217 
2225  public function saveSystemConfigParameter($sParameterType, $sParameterName, $sParameterValue)
2226  {
2227  $this->saveShopConfVar($sParameterType, $sParameterName, $sParameterValue, $this->getBaseShopId());
2228  }
2229 
2237  public function getSystemConfigParameter($sParameterName)
2238  {
2239  return $this->getShopConfVar($sParameterName, $this->getBaseShopId());
2240  }
2241 }