00001 <?php
00002
00003
00004 define('MAX_64BIT_INTEGER', '18446744073709551615');
00005
00010 class oxConfig extends oxSuperCfg
00011 {
00012
00013
00014
00015
00021 protected $dbHost = null;
00022
00028 protected $dbName = null;
00029
00035 protected $dbUser = null;
00036
00042 protected $dbPwd = null;
00043
00049 protected $dbType = null;
00050
00056 protected $sShopURL = null;
00057
00063 protected $sSSLShopURL = null;
00064
00070 protected $sAdminSSLURL = null;
00071
00077 protected $sShopDir = null;
00078
00084 protected $sCompileDir = null;
00085
00100 protected $iDebug = null;
00101
00107 protected $sAdminEmail = null;
00108
00114 protected $blSessionUseCookies = null;
00115
00125 protected $blNativeImages = true;
00126
00132 protected $aMultiShopTables = array('oxarticles', 'oxdiscount', 'oxcategories', 'oxattribute',
00133 'oxlinks', 'oxvoucherseries', 'oxmanufacturers',
00134 'oxnews', 'oxselectlist', 'oxwrapping',
00135 'oxdeliveryset', 'oxdelivery', 'oxvendor', 'oxobject2category');
00136
00142 private $_oStart = null;
00143
00144
00150 protected $_oActShop = null;
00151
00159 protected $_aActiveViews = array();
00160
00166 protected $_aGlobalParams = array();
00167
00173 protected $_aConfigParams = array();
00174
00180 protected $_aThemeConfigParams = array();
00181
00187 protected $_iLanguageId = null;
00188
00194 protected $_iShopId = null;
00195
00196
00202 protected $_sOutDir = 'out';
00203
00209 protected $_sImageDir = 'img';
00210
00216 protected $_sPictureDir = 'pictures';
00217
00223 protected $_sMasterPictureDir = 'master';
00224
00230 protected $_sTemplateDir = 'tpl';
00231
00237 protected $_sResourceDir = 'src';
00238
00244 protected $_sModulesDir = 'modules';
00245
00251 protected $_blIsSsl = null;
00252
00258 protected $_aAbsDynImageDir = array();
00259
00265 protected $_oActCurrencyObject = null;
00266
00274 protected $_blInit = false;
00275
00281 const OXMODULE_THEME_PREFIX = 'theme:';
00282
00288 const OXMODULE_MODULE_PREFIX = 'module:';
00289
00297 public function getConfigParam($sName)
00298 {
00299 if (defined('OXID_PHP_UNIT')) {
00300 if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
00301 $sValue = modConfig::$unitMOD->getModConfigParam($sName);
00302 if ($sValue !== null) {
00303 return $sValue;
00304 }
00305 }
00306 }
00307
00308 $this->init();
00309
00310 if (isset ($this->_aConfigParams[$sName])) {
00311 return $this->_aConfigParams[$sName];
00312 }
00313
00314 if (isset($this->$sName)) {
00315 return $this->$sName;
00316 }
00317 }
00318
00325 public function setConfigParam($sName, $sValue)
00326 {
00327 if (isset($this->$sName)) {
00328 $this->$sName = $sValue;
00329 } else {
00330 $this->_aConfigParams[$sName] = $sValue;
00331 }
00332 }
00333
00337 protected function _processSeoCall()
00338 {
00339
00340 if (isSearchEngineUrl()) {
00341 oxNew('oxSeoDecoder')->processSeoCall();
00342 }
00343 }
00344
00352 public function init()
00353 {
00354
00355 if ($this->_blInit) {
00356 return;
00357 }
00358 $this->_blInit = true;
00359
00360 $this->_loadVarsFromFile();
00361
00362 include getShopBasePath() . 'core/oxconfk.php';
00363
00364
00365 global $ADODB_SESS_LIFE;
00366 $ADODB_SESS_LIFE = 1;
00367
00368 $this->_setDefaults();
00369
00370 try {
00371 $sShopID = $this->getShopId();
00372
00373
00374 $blConfigLoaded = $this->_loadVarsFromDb($sShopID);
00375
00376 if (empty($sShopID) || !$blConfigLoaded) {
00377
00378 $oEx = new oxConnectionException();
00379 $oEx->setMessage("Unable to load shop config values from database");
00380 throw $oEx;
00381 }
00382
00383
00384 $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme'));
00385
00386
00387 if ($this->getConfigParam('sCustomTheme')) {
00388 $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme'));
00389 }
00390
00391
00392 $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_MODULE_PREFIX);
00393
00394
00395 $this->_processSeoCall();
00396
00397
00398 $this->getSession()->start();
00399
00400
00401
00402 $this->setConfigParam('blAdmin', isAdmin());
00403
00404 if (defined('OX_ADMIN_DIR')) {
00405 $this->setConfigParam('sAdminDir', OX_ADMIN_DIR);
00406 }
00407
00408 $this->_loadVarsFromFile();
00409
00410
00411 $this->_oStart = new oxStart();
00412 $this->_oStart->appInit();
00413 } catch (oxConnectionException $oEx) {
00414 return $this->_handleDbConnectionException($oEx);
00415 } catch (oxCookieException $oEx) {
00416 return $this->_handleCookieException($oEx);
00417 }
00418 }
00419
00423 protected function _loadVarsFromFile()
00424 {
00425
00426 include getShopBasePath() . '/config.inc.php';
00427
00428
00429 $oFileUtils = oxRegistry::get("oxUtilsFile");
00430 $this->sShopDir = $oFileUtils->normalizeDir($this->sShopDir);
00431 $this->sCompileDir = $oFileUtils->normalizeDir($this->sCompileDir);
00432 $this->sShopURL = $oFileUtils->normalizeDir($this->sShopURL);
00433 $this->sSSLShopURL = $oFileUtils->normalizeDir($this->sSSLShopURL);
00434 $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00435
00436 $this->_loadCustomConfig();
00437 }
00438
00442 protected function _setDefaults()
00443 {
00444
00445 $this->setConfigParam('sTheme', 'azure');
00446
00447 if (is_null($this->getConfigParam('sDefaultLang'))) {
00448 $this->setConfigParam('sDefaultLang', 0);
00449 }
00450
00451 if (is_null($this->getConfigParam('blLogChangesInAdmin'))) {
00452 $this->setConfigParam('blLogChangesInAdmin', false);
00453 }
00454
00455 if (is_null($this->getConfigParam('blCheckTemplates'))) {
00456 $this->setConfigParam('blCheckTemplates', false);
00457 }
00458
00459 if (is_null($this->getConfigParam('blAllowArticlesubclass'))) {
00460 $this->setConfigParam('blAllowArticlesubclass', false);
00461 }
00462
00463 if (is_null($this->getConfigParam('iAdminListSize'))) {
00464 $this->setConfigParam('iAdminListSize', 9);
00465 }
00466
00467
00468 if (is_null($this->getConfigParam('iPicCount'))) {
00469 $this->setConfigParam('iPicCount', 7);
00470 }
00471
00472 if (is_null($this->getConfigParam('iZoomPicCount'))) {
00473 $this->setConfigParam('iZoomPicCount', 4);
00474 }
00475
00476
00477 if (is_null($this->getConfigParam('iDBCacheLifeTime'))) {
00478 $this->setConfigParam('iDBCacheLifeTime', 3600);
00479 }
00480
00481 if (is_null($this->getConfigParam('iDebug'))) {
00482 $this->setConfigParam('iDebug', $this->isProductiveMode() ? 0 : -1);
00483 }
00484
00485 $sCoreDir = $this->getConfigParam('sShopDir');
00486 $this->setConfigParam('sCoreDir', $sCoreDir . '/core/');
00487 }
00488
00492 protected function _loadCustomConfig()
00493 {
00494 $sCustConfig = getShopBasePath() . '/cust_config.inc.php';
00495 if (is_readable($sCustConfig)) {
00496 include $sCustConfig;
00497 }
00498 }
00499
00509 protected function _loadVarsFromDb($sShopID, $aOnlyVars = null, $sModule = '')
00510 {
00511 $oDb = oxDb::getDb();
00512
00513 $sModuleSql = $sModule ? " oxmodule LIKE " . $oDb->quote($sModule . "%") : " oxmodule='' ";
00514 $sOnlyVarsSql = $this->_getConfigParamsSelectSnippet($aOnlyVars);
00515
00516 $sSelect = "select
00517 oxvarname, oxvartype, " . $this->getDecodeValueQuery() . " as oxvarvalue
00518 from oxconfig
00519 where oxshopid = '$sShopID' and " . $sModuleSql . $sOnlyVarsSql;
00520
00521 $aResult = $oDb->getAll($sSelect);
00522
00523 foreach ($aResult as $aValue) {
00524 $sVarName = $aValue[0];
00525 $sVarType = $aValue[1];
00526 $sVarVal = $aValue[2];
00527
00528 $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
00529
00530
00531 if ($sModule) {
00532 $this->_aThemeConfigParams[$sVarName] = $sModule;
00533 }
00534 }
00535
00536 return (bool) count($aResult);
00537 }
00538
00546 protected function _getConfigParamsSelectSnippet($aVars)
00547 {
00548 $sSelect = '';
00549 if (is_array($aVars) && !empty($aVars)) {
00550 foreach ($aVars as &$sField) {
00551 $sField = '"' . $sField . '"';
00552 }
00553 $sSelect = ' and oxvarname in ( ' . implode(', ', $aVars) . ' ) ';
00554 }
00555
00556 return $sSelect;
00557 }
00558
00569 protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
00570 {
00571 if (($sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL') &&
00572 (!$sVarVal || $this->isAdmin() === true)
00573 ) {
00574 return;
00575 }
00576
00577 switch ($sVarType) {
00578 case 'arr':
00579 case 'aarr':
00580 $this->setConfigParam($sVarName, unserialize($sVarVal));
00581 break;
00582 case 'bool':
00583 $this->setConfigParam($sVarName, ($sVarVal == 'true' || $sVarVal == '1'));
00584 break;
00585 default:
00586 $this->setConfigParam($sVarName, $sVarVal);
00587 break;
00588 }
00589 }
00590
00596 public function pageClose()
00597 {
00598 if ($this->hasActiveViewsChain()) {
00599
00600 return;
00601 }
00602
00603 return $this->_oStart->pageClose();
00604 }
00605
00617 public function getRequestParameter($sName, $blRaw = false)
00618 {
00619 if (defined('OXID_PHP_UNIT')) {
00620 if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
00621 try {
00622 $sValue = modConfig::getRequestParameter($sName, $blRaw);
00623
00624
00625 $blIsAdmin = modConfig::getInstance()->isAdmin() || modSession::getInstance()->getVariable("blIsAdmin");
00626 if ($sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00627 $this->checkParamSpecialChars($sValue, $blRaw);
00628 }
00629
00630 return $sValue;
00631 } catch (Exception $e) {
00632
00633 }
00634 }
00635 }
00636
00637 $sValue = null;
00638
00639 if (isset($_POST[$sName])) {
00640 $sValue = $_POST[$sName];
00641 } elseif (isset($_GET[$sName])) {
00642 $sValue = $_GET[$sName];
00643 }
00644
00645
00646 $blIsAdmin = $this->isAdmin() && $this->getSession()->getVariable("blIsAdmin");
00647 if ($sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00648 $this->checkParamSpecialChars($sValue, $blRaw);
00649 }
00650
00651 return $sValue;
00652 }
00653
00661 public function getUploadedFile($sParamName)
00662 {
00663 return $_FILES[$sParamName];
00664 }
00665
00672 public function setGlobalParameter($sName, $sValue)
00673 {
00674 $this->_aGlobalParams[$sName] = $sValue;
00675 }
00676
00684 public function getGlobalParameter($sName)
00685 {
00686 if (isset($this->_aGlobalParams[$sName])) {
00687 return $this->_aGlobalParams[$sName];
00688 } else {
00689 return null;
00690 }
00691 }
00692
00702 public function checkParamSpecialChars(& $sValue, $aRaw = null)
00703 {
00704 if (is_object($sValue)) {
00705 return $sValue;
00706 }
00707
00708 if (is_array($sValue)) {
00709 $newValue = array();
00710 foreach ($sValue as $sKey => $sVal) {
00711 $sValidKey = $sKey;
00712 if (!$aRaw || !in_array($sKey, $aRaw)) {
00713 $this->checkParamSpecialChars($sValidKey);
00714 $this->checkParamSpecialChars($sVal);
00715 if ($sValidKey != $sKey) {
00716 unset ($sValue[$sKey]);
00717 }
00718 }
00719 $newValue[$sValidKey] = $sVal;
00720 }
00721 $sValue = $newValue;
00722 } elseif (is_string($sValue)) {
00723 $sValue = str_replace(
00724 array('&', '<', '>', '"', "'", chr(0), '\\', "\n", "\r"),
00725 array('&', '<', '>', '"', ''', '', '\', ' ', ' '),
00726 $sValue
00727 );
00728 }
00729
00730 return $sValue;
00731 }
00732
00740 public function setShopId($sShopId)
00741 {
00742
00743 $this->getSession()->setVariable('actshop', $sShopId);
00744 $this->_iShopId = $sShopId;
00745 }
00746
00752 public function getShopId()
00753 {
00754 if ($this->_iShopId !== null) {
00755 return $this->_iShopId;
00756 }
00757
00758 $this->setShopId($this->getBaseShopId());
00759
00760
00761 $this->getSession()->setVariable('actshop', $this->_iShopId);
00762
00763 return $this->_iShopId;
00764 }
00765
00766
00767
00768
00774 public function setIsSsl($blIsSsl = false)
00775 {
00776 $this->_blIsSsl = $blIsSsl;
00777 }
00778
00782 protected function _checkSsl()
00783 {
00784 $myUtilsServer = oxRegistry::get("oxUtilsServer");
00785 $aServerVars = $myUtilsServer->getServerVar();
00786 $aHttpsServerVar = $myUtilsServer->getServerVar('HTTPS');
00787
00788 $this->setIsSsl();
00789 if (isset($aHttpsServerVar) && ($aHttpsServerVar === 'on' || $aHttpsServerVar === 'ON' || $aHttpsServerVar == '1')) {
00790
00791 $this->setIsSsl($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
00792 if ($this->isAdmin() && !$this->_blIsSsl) {
00793
00794 $this->setIsSsl(!is_null($this->getConfigParam('sAdminSSLURL')));
00795 }
00796 }
00797
00798
00799 if (isset($aServerVars['HTTP_X_FORWARDED_SERVER']) &&
00800 (strpos($aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl') !== false ||
00801 strpos($aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de') !== false)
00802 ) {
00803 $this->setIsSsl(true);
00804 }
00805 }
00806
00807
00813 public function isSsl()
00814 {
00815 if (is_null($this->_blIsSsl)) {
00816 $this->_checkSsl();
00817 }
00818
00819 return $this->_blIsSsl;
00820 }
00821
00829 public function isCurrentUrl($sURL)
00830 {
00831
00832 if (!$sURL || (strpos($sURL, "http") !== 0)) {
00833 return true;
00834 }
00835
00836 return oxRegistry::get("oxUtilsServer")->isCurrentUrl($sURL);
00837 }
00838
00846 public function isCurrentProtocol($sURL)
00847 {
00848
00849 if (!$sURL || (strpos($sURL, "http") !== 0)) {
00850 return true;
00851 }
00852
00853 return (strpos($sURL, "https:") === 0) == $this->isSsl();
00854 }
00855
00864 public function getShopUrl($iLang = null, $blAdmin = null)
00865 {
00866 $sUrl = null;
00867 $blAdmin = isset($blAdmin) ? $blAdmin : $this->isAdmin();
00868
00869 if (!$blAdmin) {
00870 $sUrl = $this->getShopUrlByLanguage($iLang);
00871 if (!$sUrl) {
00872 $sUrl = $this->getMallShopUrl();
00873 }
00874 }
00875
00876 if (!$sUrl) {
00877 $sUrl = $this->getConfigParam('sShopURL');
00878 }
00879
00880 return $sUrl;
00881 }
00882
00890 public function getSslShopUrl($iLang = null)
00891 {
00892 $sUrl = null;
00893
00894 if (!$sUrl) {
00895 $sUrl = $this->getShopUrlByLanguage($iLang, true);
00896 }
00897
00898 if (!$sUrl) {
00899 $sUrl = $this->getMallShopUrl(true);
00900 }
00901
00902 if (!$sUrl) {
00903 $sUrl = $this->getMallShopUrl();
00904 }
00905
00906
00907 if (!$sUrl) {
00908 $sUrl = $this->getConfigParam('sSSLShopURL');
00909 }
00910
00911 if (!$sUrl) {
00912 $sUrl = $this->getShopUrl($iLang);
00913 }
00914
00915 return $sUrl;
00916 }
00917
00923 public function getCoreUtilsUrl()
00924 {
00925 return $this->getCurrentShopUrl() . 'core/utils/';
00926 }
00927
00936 public function getCurrentShopUrl($blAdmin = null)
00937 {
00938 if ($blAdmin === null) {
00939 $blAdmin = $this->isAdmin();
00940 }
00941 if ($blAdmin) {
00942 if ($this->isSsl()) {
00943
00944 $sUrl = $this->getConfigParam('sAdminSSLURL');
00945 if (!$sUrl) {
00946 return $this->getSslShopUrl() . $this->getConfigParam('sAdminDir') . '/';
00947 }
00948
00949 return $sUrl;
00950 } else {
00951 return $this->getShopUrl() . $this->getConfigParam('sAdminDir') . '/';
00952 }
00953 } else {
00954 return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
00955 }
00956 }
00957
00965 public function getShopCurrentUrl($iLang = null)
00966 {
00967 if ($this->isSsl()) {
00968 $sURL = $this->getSSLShopURL($iLang);
00969 } else {
00970 $sURL = $this->getShopURL($iLang);
00971 }
00972
00973 return oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'index.php', false);
00974 }
00975
00984 public function getShopHomeUrl($iLang = null, $blAdmin = null)
00985 {
00986 return oxRegistry::get("oxUtilsUrl")->processUrl($this->getShopUrl($iLang, $blAdmin) . 'index.php', false);
00987 }
00988
00997 public function getWidgetUrl($iLang = null, $blAdmin = null)
00998 {
00999 $sUrl = $this->isSsl() ? $this->getSslShopUrl($iLang) : $this->getShopUrl($iLang, $blAdmin);
01000
01001 return oxRegistry::get('oxUtilsUrl')->processUrl($sUrl . 'widget.php', false);
01002 }
01003
01009 public function getShopSecureHomeUrl()
01010 {
01011 return oxRegistry::get("oxUtilsUrl")->processUrl($this->getSslShopUrl() . 'index.php', false);
01012 }
01013
01019 public function getShopCurrency()
01020 {
01021 $iCurr = null;
01022 if ((null === ($iCurr = $this->getRequestParameter('cur')))) {
01023 if (null === ($iCurr = $this->getRequestParameter('currency'))) {
01024 $iCurr = $this->getSession()->getVariable('currency');
01025 }
01026 }
01027
01028 return (int) $iCurr;
01029 }
01030
01036 public function getActShopCurrencyObject()
01037 {
01038
01039
01040 if (!defined('OXID_PHP_UNIT')) {
01041 if (!is_null($this->_oActCurrencyObject)) {
01042 return $this->_oActCurrencyObject;
01043 }
01044 }
01045
01046 $iCur = $this->getShopCurrency();
01047 $aCurrencies = $this->getCurrencyArray();
01048 if (!isset($aCurrencies[$iCur])) {
01049 return $this->_oActCurrencyObject = reset($aCurrencies);
01050 }
01051
01052 return $this->_oActCurrencyObject = $aCurrencies[$iCur];
01053 }
01054
01060 public function setActShopCurrency($iCur)
01061 {
01062 $aCurrencies = $this->getCurrencyArray();
01063 if (isset($aCurrencies[$iCur])) {
01064 $this->getSession()->setVariable('currency', $iCur);
01065 $this->_oActCurrencyObject = null;
01066 }
01067 }
01068
01076 public function getOutDir($blAbsolute = true)
01077 {
01078 if ($blAbsolute) {
01079 return $this->getConfigParam('sShopDir') . $this->_sOutDir . '/';
01080 } else {
01081 return $this->_sOutDir . '/';
01082 }
01083 }
01084
01092 public function getViewsDir($blAbsolute = true)
01093 {
01094 if ($blAbsolute) {
01095 return $this->getConfigParam('sShopDir') . 'application/views/';
01096 } else {
01097 return 'application/views/';
01098 }
01099 }
01100
01110 public function getTranslationsDir($sFile, $sDir, $blAbsolute = true)
01111 {
01112 $sPath = $blAbsolute ? $this->getConfigParam('sShopDir') : '';
01113 $sPath .= 'application/translations/';
01114 if (is_readable($sPath . $sDir . '/' . $sFile)) {
01115 return $sPath . $sDir . '/' . $sFile;
01116 }
01117
01118 return false;
01119 }
01120
01128 public function getAppDir($blAbsolute = true)
01129 {
01130 if ($blAbsolute) {
01131 return $this->getConfigParam('sShopDir') . 'application/';
01132 } else {
01133 return 'application/';
01134 }
01135 }
01136
01146 public function getOutUrl($blSSL = null, $blAdmin = null, $blNativeImg = false)
01147 {
01148 $blSSL = is_null($blSSL) ? $this->isSsl() : $blSSL;
01149 $blAdmin = is_null($blAdmin) ? $this->isAdmin() : $blAdmin;
01150
01151 if ($blSSL) {
01152 if ($blNativeImg && !$blAdmin) {
01153 $sUrl = $this->getSslShopUrl();
01154 } else {
01155 $sUrl = $this->getConfigParam('sSSLShopURL');
01156 if (!$sUrl && $blAdmin) {
01157 $sUrl = $this->getConfigParam('sAdminSSLURL') . '../';
01158 }
01159 }
01160 } else {
01161 $sUrl = ($blNativeImg && !$blAdmin) ? $this->getShopUrl() : $this->getConfigParam('sShopURL');
01162 }
01163
01164 return $sUrl . $this->_sOutDir . '/';
01165 }
01166
01181 public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false)
01182 {
01183 if (is_null($sTheme)) {
01184 $sTheme = $this->getConfigParam('sTheme');
01185 }
01186
01187 if ($blAdmin) {
01188 $sTheme = 'admin';
01189 }
01190
01191 if ($sDir != $this->_sTemplateDir) {
01192 $sBase = $this->getOutDir($blAbsolute);
01193 $sAbsBase = $this->getOutDir();
01194 } else {
01195 $sBase = $this->getViewsDir($blAbsolute);
01196 $sAbsBase = $this->getViewsDir();
01197 }
01198
01199 $sLang = '-';
01200
01201 if ($iLang !== false) {
01202 $oLang = oxRegistry::getLang();
01203
01204 if (is_null($iLang)) {
01205 $iLang = $oLang->getEditLanguage();
01206 }
01207
01208 $sLang = $oLang->getLanguageAbbr($iLang);
01209 }
01210
01211 if (is_null($iShop)) {
01212 $iShop = $this->getShopId();
01213 }
01214
01215
01216 $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01217 $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01218
01219 if (($sReturn = oxRegistry::getUtils()->fromStaticCache($sCacheKey)) !== null) {
01220 return $sReturn;
01221 }
01222
01223 $sReturn = false;
01224
01225
01226 $sCustomTheme = $this->getConfigParam('sCustomTheme');
01227 if (!$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01228 $sReturn = $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute);
01229 }
01230
01231
01232 if (!$sReturn && !$blAdmin && is_readable($sAbsBase . $sPath)) {
01233 $sReturn = $sBase . $sPath;
01234 }
01235
01236
01237 $sPath = "$sTheme/$iShop/$sDir/$sFile";
01238 if (!$sReturn && !$blAdmin && is_readable($sAbsBase . $sPath)) {
01239 $sReturn = $sBase . $sPath;
01240 }
01241
01242
01243
01244 $sPath = "$sTheme/$sLang/$sDir/$sFile";
01245 if (!$sReturn && $iLang !== false && is_readable($sAbsBase . $sPath)) {
01246 $sReturn = $sBase . $sPath;
01247 }
01248
01249
01250 $sPath = "$sTheme/$sDir/$sFile";
01251 if (!$sReturn && is_readable($sAbsBase . $sPath)) {
01252 $sReturn = $sBase . $sPath;
01253 }
01254
01255
01256 $sPath = "$sLang/$sDir/$sFile";
01257 if (!$sReturn && $iLang !== false && is_readable($sAbsBase . $sPath)) {
01258 $sReturn = $sBase . $sPath;
01259 }
01260
01261
01262 $sPath = "$sDir/$sFile";
01263 if (!$sReturn && is_readable($sAbsBase . $sPath)) {
01264 $sReturn = $sBase . $sPath;
01265 }
01266
01267 if (!$sReturn) {
01268
01269 }
01270
01271
01272 oxRegistry::getUtils()->toStaticCache($sCacheKey, $sReturn);
01273
01274 return $sReturn;
01275 }
01276
01291 public function getUrl($sFile, $sDir, $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null, $iShop = null, $sTheme = null)
01292 {
01293 $sUrl = str_replace(
01294 $this->getOutDir(),
01295 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01296 $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme)
01297 );
01298
01299 return $sUrl;
01300 }
01301
01310 public function getImagePath($sFile, $blAdmin = false)
01311 {
01312 return $this->getDir($sFile, $this->_sImageDir, $blAdmin);
01313 }
01314
01325 public function getImageUrl($blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null)
01326 {
01327 $blNativeImg = is_null($blNativeImg) ? $this->getConfigParam('blNativeImages') : $blNativeImg;
01328
01329 return $this->getUrl($sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg);
01330 }
01331
01339 public function getImageDir($blAdmin = false)
01340 {
01341 return $this->getDir(null, $this->_sImageDir, $blAdmin);
01342 }
01343
01355 public function getPicturePath($sFile, $blAdmin = false, $iLang = null, $iShop = null, $sTheme = null)
01356 {
01357 return $this->getDir($sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme);
01358 }
01359
01367 public function getMasterPictureDir($blAdmin = false)
01368 {
01369 return $this->getDir(null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin);
01370 }
01371
01380 public function getMasterPicturePath($sFile, $blAdmin = false)
01381 {
01382 return $this->getDir($sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin);
01383 }
01384
01397 public function getPictureUrl($sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg")
01398 {
01399 if ($sAltUrl = oxRegistry::get("oxPictureHandler")->getAltImageUrl('/', $sFile, $blSSL)) {
01400 return $sAltUrl;
01401 }
01402
01403 $blNativeImg = $this->getConfigParam('blNativeImages');
01404 $sUrl = $this->getUrl($sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId);
01405
01406
01407 if (!$sUrl && $sDefPic) {
01408 $sUrl = $this->getUrl($sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId);
01409 }
01410
01411 return $sUrl;
01412 }
01413
01421 public function getPictureDir($blAdmin)
01422 {
01423 return $this->getDir(null, $this->_sPictureDir, $blAdmin);
01424 }
01425
01434 public function getTemplatePath($sFile, $blAdmin)
01435 {
01436 $sTemplatePath = $this->getDir($sFile, $this->_sTemplateDir, $blAdmin);
01437
01438 if (!$sTemplatePath) {
01439 $sBasePath = getShopBasePath();
01440 $aModuleTemplates = $this->getConfigParam('aModuleTemplates');
01441
01442 $oModulelist = oxNew('oxmodulelist');
01443 $aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
01444 if (is_array($aModuleTemplates) && is_array($aActiveModuleInfo)) {
01445 foreach ($aModuleTemplates as $sModuleId => $aTemplates) {
01446 if (isset($aTemplates[$sFile]) && isset($aActiveModuleInfo[$sModuleId])) {
01447 $sPath = $aTemplates[$sFile];
01448 $sPath = $sBasePath . 'modules/' . $sPath;
01449 if (is_file($sPath) && is_readable($sPath)) {
01450 $sTemplatePath = $sPath;
01451 }
01452 }
01453 }
01454 }
01455 }
01456
01457 return $sTemplatePath;
01458 }
01459
01467 public function getTemplateDir($blAdmin = false)
01468 {
01469 return $this->getDir(null, $this->_sTemplateDir, $blAdmin);
01470 }
01471
01482 public function getTemplateUrl($sFile = null, $blAdmin = false, $blSSL = null, $iLang = null)
01483 {
01484 return $this->getShopMainUrl() . $this->getDir($sFile, $this->_sTemplateDir, $blAdmin, $iLang, null, null, false);
01485 }
01486
01494 public function getTemplateBase($blAdmin = false)
01495 {
01496
01497 return str_replace($this->_sTemplateDir . '/', '', $this->getDir(null, $this->_sTemplateDir, $blAdmin, null, null, null, false));
01498 }
01499
01508 public function getResourcePath($sFile = '', $blAdmin = false)
01509 {
01510 return $this->getDir($sFile, $this->_sResourceDir, $blAdmin);
01511 }
01512
01520 public function getModulesDir($blAbsolute = true)
01521 {
01522 if ($blAbsolute) {
01523 return $this->getConfigParam('sShopDir') . $this->_sModulesDir . '/';
01524 } else {
01525 return $this->_sModulesDir . '/';
01526 }
01527 }
01528
01539 public function getResourceUrl($sFile = '', $blAdmin = false, $blSSL = null, $iLang = null)
01540 {
01541 $blNativeImg = $this->getConfigParam('blNativeImages');
01542
01543 return $this->getUrl($sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang);
01544 }
01545
01553 public function getResourceDir($blAdmin)
01554 {
01555 return $this->getDir(null, $this->_sResourceDir, $blAdmin);
01556 }
01557
01565 public function getCurrencyArray($iCurrency = null)
01566 {
01567 $aConfCurrencies = $this->getConfigParam('aCurrencies');
01568 if (!is_array($aConfCurrencies)) {
01569 return array();
01570 }
01571
01572 if (defined('OXID_PHP_UNIT')) {
01573 if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
01574 try {
01575 $aAltCurrencies = modConfig::getInstance()->getConfigParam('modaCurrencies');
01576 if (isset($aAltCurrencies)) {
01577 $aConfCurrencies = $aAltCurrencies;
01578 }
01579 } catch (Exception $e) {
01580
01581 }
01582 }
01583 }
01584
01585
01586 $aCurrencies = array();
01587 reset($aConfCurrencies);
01588 while (list($key, $val) = each($aConfCurrencies)) {
01589 if ($val) {
01590 $oCur = new stdClass();
01591 $oCur->id = $key;
01592 $sCur = explode('@', $val);
01593 $oCur->name = trim($sCur[0]);
01594 $oCur->rate = trim($sCur[1]);
01595 $oCur->dec = trim($sCur[2]);
01596 $oCur->thousand = trim($sCur[3]);
01597 $oCur->sign = trim($sCur[4]);
01598 $oCur->decimal = trim($sCur[5]);
01599
01600
01601 if (isset($sCur[6])) {
01602 $oCur->side = trim($sCur[6]);
01603 }
01604
01605 if (isset($iCurrency) && $key == $iCurrency) {
01606 $oCur->selected = 1;
01607 } else {
01608 $oCur->selected = 0;
01609 }
01610 $aCurrencies[$key] = $oCur;
01611 }
01612
01613
01614 if (!$this->getConfigParam('bl_perfLoadCurrency')) {
01615 break;
01616 }
01617 }
01618
01619 return $aCurrencies;
01620 }
01621
01629 public function getCurrencyObject($sName)
01630 {
01631 $aSearch = $this->getCurrencyArray();
01632 foreach ($aSearch as $oCur) {
01633 if ($oCur->name == $sName) {
01634 return $oCur;
01635 }
01636 }
01637 }
01638
01644 public function isDemoShop()
01645 {
01646 return $this->getConfigParam('blDemoShop');
01647 }
01648
01649
01650
01656 public function getEdition()
01657 {
01658 return "CE";
01659
01660
01661 }
01662
01668 public function getFullEdition()
01669 {
01670 $sEdition = $this->getEdition();
01671
01672 if ($sEdition == "CE") {
01673 return "Community Edition";
01674 }
01675
01676
01677
01678 return $sEdition;
01679 }
01680
01686 public function getVersion()
01687 {
01688 $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01689
01690 return $sVersion;
01691 }
01692
01698 public function getRevision()
01699 {
01700 $sFileName = $this->getConfigParam('sShopDir') . "/pkg.rev";
01701 $sRev = trim(@file_get_contents($sFileName));
01702
01703 if (!$sRev) {
01704 return false;
01705 }
01706
01707 return $sRev;
01708 }
01709
01715 public function getPackageInfo()
01716 {
01717 $sFileName = $this->getConfigParam('sShopDir') . "/pkg.info";
01718 $sRev = @file_get_contents($sFileName);
01719 $sRev = str_replace("\n", "<br>", $sRev);
01720
01721 if (!$sRev) {
01722 return false;
01723 }
01724
01725 return $sRev;
01726 }
01727
01733 public function getMandateCount()
01734 {
01735 $iShopCount = 1;
01736
01737
01738 return $iShopCount;
01739 }
01740
01746 public function isMall()
01747 {
01748
01749 return false;
01750 }
01751
01761 public function detectVersion()
01762 {
01763 }
01764
01765
01766
01777 public function saveShopConfVar($sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '')
01778 {
01779 switch ($sVarType) {
01780 case 'arr':
01781 case 'aarr':
01782 $sValue = serialize($sVarVal);
01783 break;
01784 case 'bool':
01785
01786 $sVarVal = (($sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
01787
01788 $sValue = $sVarVal ? "1" : "";
01789 break;
01790 case 'num':
01791
01792 $sVarVal = $sVarVal != '' ? oxRegistry::getUtils()->string2Float($sVarVal) : '';
01793 $sValue = $sVarVal;
01794 break;
01795 default:
01796 $sValue = $sVarVal;
01797 break;
01798 }
01799
01800 if (!$sShopId) {
01801 $sShopId = $this->getShopId();
01802 }
01803
01804
01805 if ($sShopId == $this->getShopId()) {
01806 $this->setConfigParam($sVarName, $sVarVal);
01807 }
01808
01809 $oDb = oxDb::getDb();
01810
01811 $sShopIdQuoted = $oDb->quote($sShopId);
01812 $sModuleQuoted = $oDb->quote($sModule);
01813 $sVarNameQuoted = $oDb->quote($sVarName);
01814 $sVarTypeQuoted = $oDb->quote($sVarType);
01815 $sVarValueQuoted = $oDb->quote($sValue);
01816 $sConfigKeyQuoted = $oDb->quote($this->getConfigParam('sConfigKey'));
01817 $sNewOXIDdQuoted = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
01818
01819 $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
01820 $oDb->execute($sQ);
01821
01822 $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
01823 values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
01824 $oDb->execute($sQ);
01825
01826
01827 }
01828
01829
01839 public function getShopConfVar($sVarName, $sShopId = null, $sModule = '')
01840 {
01841 if (!$sShopId) {
01842 $sShopId = $this->getShopId();
01843 }
01844
01845 if ($sShopId == $this->getShopId() && (!$sModule || $sModule == oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme'))) {
01846 $sVarValue = $this->getConfigParam($sVarName);
01847 if ($sVarValue !== null) {
01848 return $sVarValue;
01849 }
01850 }
01851
01852 $oDb = oxDb::getDb(oxDb::FETCH_MODE_ASSOC);
01853
01854 $sQ = "select oxvartype, " . $this->getDecodeValueQuery() . " as oxvarvalue from oxconfig where oxshopid = '{$sShopId}' and oxmodule = '{$sModule}' and oxvarname = " . $oDb->quote($sVarName);
01855 $oRs = $oDb->select($sQ);
01856
01857 $sValue = null;
01858 if ($oRs != false && $oRs->recordCount() > 0) {
01859 $sValue = $this->decodeValue($oRs->fields['oxvartype'], $oRs->fields['oxvarvalue']);
01860 }
01861
01862 return $sValue;
01863 }
01864
01873 public function decodeValue($sType, $mOrigValue)
01874 {
01875 $sValue = $mOrigValue;
01876 switch ($sType) {
01877 case 'arr':
01878 case 'aarr':
01879 $sValue = unserialize($mOrigValue);
01880 break;
01881 case 'bool':
01882 $sValue = ($mOrigValue == 'true' || $mOrigValue == '1');
01883 break;
01884 }
01885
01886 return $sValue;
01887 }
01888
01896 public function getDecodeValueQuery($sFieldName = "oxvarvalue")
01897 {
01898 return " DECODE( {$sFieldName}, '" . $this->getConfigParam('sConfigKey') . "') ";
01899 }
01900
01906 public function isProductiveMode()
01907 {
01908 $blProductive = $this->getConfigParam('blProductive');
01909 if (!isset($blProductive)) {
01910 $sQ = 'select oxproductive from oxshops where oxid = "' . $this->getShopId() . '"';
01911 $blProductive = ( bool ) oxDb::getDb()->getOne($sQ);
01912 $this->setConfigParam('blProductive', $blProductive);
01913 }
01914
01915 return $blProductive;
01916 }
01917
01918
01919
01925 public function getBaseShopId()
01926 {
01927
01928 return 'oxbaseshop';
01929 }
01930
01936 public function getActiveShop()
01937 {
01938 if ($this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01939 $this->_oActShop->getLanguage() == oxRegistry::getLang()->getBaseLanguage()
01940 ) {
01941 return $this->_oActShop;
01942 }
01943
01944 $this->_oActShop = oxNew('oxshop');
01945 $this->_oActShop->load($this->getShopId());
01946
01947 return $this->_oActShop;
01948 }
01949
01955 public function getActiveView()
01956 {
01957 if (count($this->_aActiveViews)) {
01958 $oActView = end($this->_aActiveViews);
01959 }
01960 if (!isset($oActView) || $oActView == null) {
01961 $oActView = oxNew('oxubase');
01962 $this->_aActiveViews[] = $oActView;
01963 }
01964
01965 return $oActView;
01966 }
01967
01973 public function getTopActiveView()
01974 {
01975 if (count($this->_aActiveViews)) {
01976 return reset($this->_aActiveViews);
01977 } else {
01978 return $this->getActiveView();
01979 }
01980 }
01981
01987 public function getActiveViewsList()
01988 {
01989 return $this->_aActiveViews;
01990 }
01991
01997 public function setActiveView($oView)
01998 {
01999 $this->_aActiveViews[] = $oView;
02000 }
02001
02005 public function dropLastActiveView()
02006 {
02007 array_pop($this->_aActiveViews);
02008 }
02009
02015 public function hasActiveViewsChain()
02016 {
02017 return (count($this->_aActiveViews) > 1);
02018 }
02019
02025 public function getActiveViewsNames()
02026 {
02027 $aNames = array();
02028
02029 if (is_array($this->getActiveViewsList())) {
02030 foreach ($this->getActiveViewsList() as $oView) {
02031 $aNames[] = $oView->getClassName();
02032 }
02033 }
02034
02035 return $aNames;
02036 }
02037
02043 public function isUtf()
02044 {
02045 return ( bool ) $this->getConfigParam('iUtfMode');
02046 }
02047
02053 public function getLogsDir()
02054 {
02055 return $this->getConfigParam('sShopDir') . 'log/';
02056 }
02057
02065 public function isThemeOption($sName)
02066 {
02067 return (bool) isset($this->_aThemeConfigParams[$sName]);
02068 }
02069
02075 public function getShopMainUrl()
02076 {
02077 return $this->_blIsSsl ? $this->getConfigParam('sSSLShopURL') : $this->getConfigParam('sShopURL');
02078 }
02079
02087 public function getAllModules()
02088 {
02089 return $this->getModulesWithExtendedClass();
02090 }
02091
02097 public function getModulesWithExtendedClass()
02098 {
02099 return $this->parseModuleChains($this->getConfigParam('aModules'));
02100 }
02101
02109 public function parseModuleChains($aModules)
02110 {
02111 $aModuleArray = array();
02112
02113 if (is_array($aModules)) {
02114 foreach ($aModules as $sClass => $sModuleChain) {
02115 if (strstr($sModuleChain, '&')) {
02116 $aModuleChain = explode('&', $sModuleChain);
02117 } else {
02118 $aModuleChain = array($sModuleChain);
02119 }
02120 $aModuleArray[$sClass] = $aModuleChain;
02121 }
02122 }
02123
02124 return $aModuleArray;
02125 }
02126
02132 public function getShopIds()
02133 {
02134 return oxDb::getDb()->getCol("SELECT `oxid` FROM `oxshops`");
02135 }
02136
02146 public function getShopUrlByLanguage($iLang, $blSSL = false)
02147 {
02148 $sLanguageUrl = null;
02149 $sConfigParameter = $blSSL ? 'aLanguageSSLURLs' : 'aLanguageURLs';
02150 $iLang = isset($iLang) ? $iLang : oxRegistry::getLang()->getBaseLanguage();
02151 $aLanguageURLs = $this->getConfigParam($sConfigParameter);
02152 if (isset($iLang) && isset($aLanguageURLs[$iLang]) && !empty($aLanguageURLs[$iLang])) {
02153 $aLanguageURLs[$iLang] = oxRegistry::getUtils()->checkUrlEndingSlash($aLanguageURLs[$iLang]);
02154 $sLanguageUrl = $aLanguageURLs[$iLang];
02155 }
02156
02157 return $sLanguageUrl;
02158 }
02159
02167 public function getMallShopUrl($blSSL = false)
02168 {
02169 $sUrl = null;
02170 $sConfigParameter = $blSSL ? 'sMallSSLShopURL' : 'sMallShopURL';
02171 $sMallShopURL = $this->getConfigParam($sConfigParameter);
02172 if ($sMallShopURL) {
02173 $sMallShopURL = oxRegistry::getUtils()->checkUrlEndingSlash($sMallShopURL);
02174 $sUrl = $sMallShopURL;
02175 }
02176
02177 return $sUrl;
02178 }
02179
02187 protected function _handleDbConnectionException($oEx)
02188 {
02189 $oEx->debugOut();
02190 if (defined('OXID_PHP_UNIT')) {
02191 return false;
02192 } elseif (0 != $this->iDebug) {
02193 oxRegistry::getUtils()->showMessageAndExit($oEx->getString());
02194 } else {
02195 header("HTTP/1.1 500 Internal Server Error");
02196 header("Location: offline.html");
02197 header("Connection: close");
02198 exit(1);
02199 }
02200 }
02201
02207 protected function _handleCookieException($oEx)
02208 {
02209 $this->_processSeoCall();
02210
02211
02212 $this->getSession()->start();
02213
02214
02215 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
02216 oxRegistry::getUtils()->redirect($this->getShopHomeURL() . 'cl=start', true, 302);
02217 }
02218
02226 public function saveSystemConfigParameter($sParameterType, $sParameterName, $sParameterValue)
02227 {
02228 $this->saveShopConfVar($sParameterType, $sParameterName, $sParameterValue, $this->getBaseShopId());
02229 }
02230
02238 public function getSystemConfigParameter($sParameterName)
02239 {
02240 return $this->getShopConfVar($sParameterName, $this->getBaseShopId());
02241 }
02242 }