00001 <?php
00002
00003 define( 'MAX_64BIT_INTEGER', '18446744073709551615' );
00004
00009 class oxConfig extends oxSuperCfg
00010 {
00011
00012
00013
00019 protected $dbHost = null;
00020
00026 protected $dbName = null;
00027
00033 protected $dbUser = null;
00034
00040 protected $dbPwd = null;
00041
00047 protected $dbType = null;
00048
00054 protected $sShopURL = null;
00055
00061 protected $sSSLShopURL = null;
00062
00068 protected $sAdminSSLURL = null;
00069
00075 protected $sShopDir = null;
00076
00082 protected $sCompileDir = null;
00083
00098 protected $iDebug = 0;
00099
00105 protected $sAdminEmail = null;
00106
00112 protected $blSessionUseCookies = null;
00113
00119
00120
00130 protected $blNativeImages = true;
00131
00137 protected $aMultiShopTables = array( 'oxarticles', 'oxdiscount', 'oxcategories', 'oxattribute',
00138 'oxlinks', 'oxvoucherseries', 'oxmanufacturers',
00139 'oxnews', 'oxselectlist', 'oxwrapping',
00140 'oxdeliveryset', 'oxdelivery', 'oxvendor', 'oxobject2category');
00141
00147 private static $_instance = null;
00148
00154 private $_oStart = null;
00155
00156
00162 protected $_oActShop = null;
00163
00171 protected $_oActView = null;
00172
00178 protected $_aGlobalParams = array();
00179
00185 protected $_aConfigParams = array();
00186
00192 protected $_aThemeConfigParams = array();
00193
00199 protected $_iLanguageId = null;
00200
00206 protected $_iShopId = null;
00207
00208
00214 protected $_sOutDir = 'out';
00215
00221 protected $_sImageDir = 'img';
00222
00228 protected $_sPictureDir = 'pictures';
00229
00235 protected $_sMasterPictureDir = 'master';
00236
00242 protected $_sTemplateDir = 'tpl';
00243
00249 protected $_sResourceDir = 'src';
00250
00256 protected $_sModulesDir = 'modules';
00257
00263 protected $_blIsSsl = null;
00264
00270 protected $_aAbsDynImageDir = array();
00271
00277 protected $_oActCurrencyObject = null;
00278
00284 const OXMODULE_THEME_PREFIX = 'theme:';
00285
00291 const OXMODULE_MODULE_PREFIX = 'module:';
00292
00298 const OXMAX_SHOP_COUNT = 256;
00299
00307 public function getConfigParam( $sName )
00308 {
00309 if ( defined( 'OXID_PHP_UNIT' ) ) {
00310 if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00311 $sValue = modConfig::$unitMOD->getModConfigParam( $sName );
00312 if ( $sValue !== null ) {
00313 return $sValue;
00314 }
00315 }
00316 }
00317
00318 if ( isset( $this->$sName ) ) {
00319 return $this->$sName;
00320 } elseif ( isset ( $this->_aConfigParams[$sName] ) ) {
00321 return $this->_aConfigParams[$sName];
00322 }
00323 }
00324
00333 public function setConfigParam( $sName, $sValue )
00334 {
00335 if ( isset( $this->$sName ) ) {
00336 $this->$sName = $sValue;
00337 } else {
00338 $this->_aConfigParams[$sName] = $sValue;
00339 }
00340 }
00341
00347 protected function _processSeoCall()
00348 {
00349
00350 if (isSearchEngineUrl()) {
00351 oxNew('oxSeoDecoder')->processSeoCall();
00352 }
00353 }
00354
00360 public function init()
00361 {
00362 $this->_loadVarsFromFile();
00363
00364 include getShopBasePath().'core/oxconfk.php';
00365
00366
00367
00368 if( !$this->getConfigParam( 'sDefaultLang' ) )
00369 $this->setConfigParam( 'sDefaultLang', 0 );
00370
00371
00372 $this->setConfigParam( 'sTheme', 'basic' );
00373
00374
00375 $blLogChangesInAdmin = $this->getConfigParam( 'blLogChangesInAdmin' );
00376 if( !isset( $blLogChangesInAdmin ) )
00377 $this->setConfigParam( 'blLogChangesInAdmin', false );
00378
00379 $blCheckTemplates = $this->getConfigParam( 'blCheckTemplates' );
00380 if( !isset( $blCheckTemplates ) )
00381 $this->setConfigParam( 'blCheckTemplates', false );
00382
00383 $blAllowArticlesubclass = $this->getConfigParam( 'blAllowArticlesubclass' );
00384 if( !isset( $blAllowArticlesubclass ) )
00385 $this->setConfigParam( 'blAllowArticlesubclass', false );
00386
00387 $iAdminListSize = $this->getConfigParam( 'iAdminListSize' );
00388 if( !isset( $iAdminListSize ) )
00389 $this->setConfigParam( 'iAdminListSize', 9 );
00390
00391
00392 $iPicCount = $this->getConfigParam( 'iPicCount' );
00393 if ( !isset( $iPicCount ) )
00394 $this->setConfigParam( 'iPicCount', 7 );
00395
00396 $iZoomPicCount = $this->getConfigParam( 'iZoomPicCount' );
00397 if ( !isset( $iZoomPicCount ) )
00398 $this->setConfigParam( 'iZoomPicCount', 4 );
00399
00400
00401 $iMaxShopId = $this->getConfigParam( 'iMaxShopId' );
00402 if ( !isset( $iMaxShopId ) ) {
00403 $this->setConfigParam( 'iMaxShopId', 128 );
00404 } elseif ( $iMaxShopId > self::OXMAX_SHOP_COUNT ) {
00405 $this->setConfigParam( 'iMaxShopId', self::OXMAX_SHOP_COUNT );
00406 }
00407
00408
00409 $this->setConfigParam( 'blTemplateCaching', false );
00410
00411
00412 global $ADODB_SESS_LIFE;
00413 $ADODB_SESS_LIFE = 1;
00414
00415
00416 $iDBCacheLifeTime = $this->getConfigParam( 'iDBCacheLifeTime' );
00417 if ( !isset( $iDBCacheLifeTime ) )
00418 $this->setConfigParam( 'iDBCacheLifeTime', 3600 );
00419
00420 $sCoreDir = $this->getConfigParam( 'sShopDir' );
00421 $this->setConfigParam( 'sCoreDir', $sCoreDir.'/core/' );
00422
00423 try {
00424 $sShopID = $this->getShopId();
00425
00426
00427 $this->_loadVarsFromDb( $sShopID );
00428
00429
00430 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') );
00431
00432
00433 if ( $this->getConfigParam('sCustomTheme') ) {
00434 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme') );
00435 }
00436
00437
00438 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_MODULE_PREFIX );
00439
00440
00441 $this->_processSeoCall();
00442
00443
00444 $this->getSession()->start();
00445 } catch ( oxConnectionException $oEx ) {
00446 $oEx->debugOut();
00447 if ( defined( 'OXID_PHP_UNIT' ) ) {
00448 return false;
00449 } elseif ( 0 != $this->iDebug ) {
00450 oxUtils::getInstance()->showMessageAndExit( $oEx->getString() );
00451 } else {
00452 header( "HTTP/1.1 500 Internal Server Error");
00453 header( "Location: offline.html");
00454 header( "Connection: close");
00455 }
00456 } catch ( oxCookieException $oEx ) {
00457
00458 $this->_processSeoCall();
00459
00460
00461 $this->getSession()->start();
00462
00463
00464 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00465 oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start', true, 302 );
00466 }
00467
00468
00469 $this->_loadVarsFromFile();
00470
00471
00472 $this->_oStart = new oxStart();
00473 $this->_oStart->appInit();
00474 }
00475
00481 public static function getInstance()
00482 {
00483
00484 if ( defined( 'OXID_PHP_UNIT' ) ) {
00485 if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00486 return modConfig::$unitMOD;
00487 }
00488 }
00489
00490 if ( !self::$_instance instanceof oxConfig ) {
00491
00492
00493 self::$_instance = new oxConfig();
00494 self::$_instance->init();
00495 }
00496 return self::$_instance;
00497 }
00498
00504 protected function _loadVarsFromFile()
00505 {
00506
00507 include getShopBasePath().'/config.inc.php';
00508
00509
00510 $oFileUtils = oxUtilsFile::getInstance();
00511 $this->sShopDir = $oFileUtils->normalizeDir($this->sShopDir);
00512 $this->sCompileDir = $oFileUtils->normalizeDir($this->sCompileDir);
00513 $this->sShopURL = $oFileUtils->normalizeDir($this->sShopURL);
00514 $this->sSSLShopURL = $oFileUtils->normalizeDir($this->sSSLShopURL);
00515 $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00516 }
00517
00527 protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null, $sModule = '' )
00528 {
00529 $oDb = oxDb::getDb();
00530
00531 if ( !empty($sModule) ) {
00532 $sModuleSql = " oxmodule LIKE " . $oDb->quote($sModule."%");
00533 } else {
00534 $sModuleSql = " oxmodule='' ";
00535 }
00536
00537 $sQ = "select oxvarname, oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '$sShopID' and " . $sModuleSql;
00538
00539 if ( $aOnlyVars !== null ) {
00540 $blSep = false;
00541 $sIn = '';
00542 foreach ( $aOnlyVars as $sField ) {
00543 if ( $blSep ) {
00544 $sIn .= ', ';
00545 }
00546 $sIn .= '"'.$sField.'"';
00547 $blSep = true;
00548 }
00549 $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00550 }
00551 $oRs = $oDb->select( $sQ );
00552 if ( $oRs != false && $oRs->recordCount() > 0 ) {
00553 while ( !$oRs->EOF ) {
00554 $sVarName = $oRs->fields[0];
00555 $sVarType = $oRs->fields[1];
00556 $sVarVal = $oRs->fields[2];
00557
00558
00559 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00560 ( !$sVarVal || $this->isAdmin() === true ) ) {
00561 $oRs->moveNext();
00562 continue;
00563 }
00564
00565 $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
00566
00567
00568 if ( $sModule != '' ) {
00569 $this->_aThemeConfigParams[$sVarName] = $sModule;
00570 }
00571
00572 $oRs->moveNext();
00573 }
00574 }
00575 }
00576
00586 protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
00587 {
00588 switch ( $sVarType ) {
00589 case 'arr':
00590 case 'aarr':
00591 $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00592 break;
00593 case 'bool':
00594 $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00595 break;
00596 default:
00597 $this->setConfigParam( $sVarName, $sVarVal );
00598 break;
00599 }
00600 }
00601
00607 public function pageClose()
00608 {
00609 return $this->_oStart->pageClose();
00610 }
00611
00623 public static function getParameter( $sName, $blRaw = false )
00624 {
00625 if ( defined( 'OXID_PHP_UNIT' ) ) {
00626 if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00627 try{
00628 return modConfig::getParameter( $sName, $blRaw );
00629 } catch( Exception $e ) {
00630
00631 }
00632 }
00633 }
00634
00635 $sValue = null;
00636
00637 if ( isset( $_POST[$sName] ) ) {
00638 $sValue = $_POST[$sName];
00639 } elseif ( isset( $_GET[$sName] ) ) {
00640 $sValue = $_GET[$sName];
00641 }
00642
00643
00644 $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00645 if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00646 self::checkSpecialChars( $sValue, $blRaw );
00647 }
00648
00649 return $sValue;
00650 }
00651
00659 public function getUploadedFile($sParamName)
00660 {
00661 return $_FILES[$sParamName];
00662 }
00663
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 static function checkSpecialChars( & $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 self::checkSpecialChars( $sValidKey );
00714 self::checkSpecialChars( $sVal );
00715 if ($sValidKey != $sKey) {
00716 unset ($sValue[$sKey]);
00717 }
00718 }
00719 $newValue[$sValidKey] = $sVal;
00720 }
00721 $sValue = $newValue;
00722 } else {
00723 $sValue = str_replace( array( '&', '<', '>', '"', "'", chr(0), '\\' ),
00724 array( '&', '<', '>', '"', ''', '', '\' ),
00725 $sValue );
00726 }
00727 return $sValue;
00728 }
00729
00735 public function getShopId()
00736 {
00737 if ( $this->_iShopId !== null )
00738 return $this->_iShopId;
00739
00740 $this->_iShopId = $this->getBaseShopId();
00741
00742
00743 oxSession::setVar( 'actshop', $this->_iShopId );
00744 return $this->_iShopId;
00745 }
00746
00747
00755 public function setShopId( $sShopId )
00756 {
00757 oxSession::setVar( 'actshop', $sShopId );
00758 $this->_iShopId = $sShopId;
00759 }
00760
00761
00767 public function isSsl()
00768 {
00769 if ( is_null( $this->_blIsSsl ) ) {
00770
00771 $myUtilsServer = oxUtilsServer::getInstance();
00772 $aServerVars = $myUtilsServer->getServerVar();
00773 $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00774
00775 $this->_blIsSsl = false;
00776 if (isset( $aHttpsServerVar ) && ($aHttpsServerVar === 'on' || $aHttpsServerVar === 'ON' || $aHttpsServerVar == '1' )) {
00777
00778 $this->_blIsSsl = ($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
00779 if ($this->isAdmin() && !$this->_blIsSsl) {
00780 $this->_blIsSsl = $this->getConfigParam('sAdminSSLURL');
00781 }
00782 }
00783
00784
00785 if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00786 ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00787 strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00788 $this->_blIsSsl = true;
00789 }
00790 }
00791
00792 return $this->_blIsSsl;
00793 }
00794
00802 public function isCurrentUrl( $sURL )
00803 {
00804 if ( !$sURL ) {
00805 return false;
00806 }
00807
00808 $oUtilsServer = oxUtilsServer::getInstance();
00809
00810 preg_match("/^(http:\/\/)?([^\/]+)/i", $sURL, $matches);
00811 $sUrlHost = $matches[2];
00812
00813 preg_match("/^(http:\/\/)?([^\/]+)/i", $oUtilsServer->getServerVar( 'HTTP_HOST' ), $matches);
00814 $sRealHost = $matches[2];
00815
00816 $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $oUtilsServer->getServerVar( 'HTTP_HOST' ) . $oUtilsServer->getServerVar( 'SCRIPT_NAME' ) );
00817
00818
00819 $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00820 $sURL = str_replace( '/', '', $sURL );
00821
00822 if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00823
00824
00825 if ( $sUrlHost == $sRealHost ) {
00826 return true;
00827 }
00828 }
00829
00830 return false;
00831 }
00832
00841 public function getShopUrl( $iLang = null, $blAdmin = null )
00842 {
00843 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00844 if ( $blAdmin ) {
00845 return $this->getConfigParam( 'sShopURL' );
00846 }
00847
00848
00849 $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00850 $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00851 if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00852 $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00853 return $aLanguageURLs[$iLang];
00854 }
00855
00856
00857 $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00858 if ( $sMallShopURL ) {
00859 $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00860 return $sMallShopURL;
00861 }
00862
00863 return $this->getConfigParam( 'sShopURL' );
00864 }
00865
00873 public function getSslShopUrl( $iLang = null )
00874 {
00875
00876 $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00877 $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00878 if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00879 $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00880 return $aLanguageSSLURLs[$iLang];
00881 }
00882
00883
00884 if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00885 $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00886 return $sMallSSLShopURL;
00887 }
00888
00889 if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00890 $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00891 return $sMallShopURL;
00892 }
00893
00894
00895 if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00896 return $sSSLShopURL;
00897 }
00898
00899 return $this->getShopUrl( $iLang );
00900 }
00901
00907 public function getCoreUtilsUrl()
00908 {
00909 return $this->getCurrentShopUrl().'core/utils/';
00910 }
00911
00920 public function getCurrentShopUrl($blAdmin = null)
00921 {
00922 if ($blAdmin===null) {
00923 $blAdmin = $this->isAdmin();
00924 }
00925 if ($blAdmin) {
00926 if ($this->isSsl()) {
00927
00928 $sUrl = $this->getConfigParam( 'sAdminSSLURL' );
00929 if ( !$sUrl ) {
00930 return $this->getSslShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00931 }
00932 return $sUrl;
00933 } else {
00934 return $this->getShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00935 }
00936 } else {
00937 return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
00938 }
00939 }
00940
00948 public function getShopCurrentUrl( $iLang = null )
00949 {
00950 if ( $this->isSsl() ) {
00951 $sURL = $this->getSSLShopURL( $iLang );
00952 } else {
00953 $sURL = $this->getShopURL( $iLang );
00954 }
00955
00956 return oxUtilsUrl::getInstance()->processUrl( $sURL.'index.php', false );
00957 }
00958
00967 public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00968 {
00969 return oxUtilsUrl::getInstance()->processUrl($this->getShopUrl( $iLang, $blAdmin).'index.php', false );
00970 }
00971
00977 public function getShopSecureHomeUrl()
00978 {
00979 return oxUtilsUrl::getInstance()->processUrl( $this->getSslShopUrl().'index.php', false );
00980 }
00981
00987 public function getShopCurrency()
00988 {
00989 $iCurr = null;
00990 if ( ( null === ( $iCurr = oxConfig::getParameter( 'cur' ) ) ) ) {
00991 if ( null === ( $iCurr = oxConfig::getParameter( 'currency' ) ) ) {
00992 $iCurr = oxSession::getVar( 'currency' );
00993 }
00994 }
00995 return (int) $iCurr;
00996 }
00997
01003 public function getActShopCurrencyObject()
01004 {
01005
01006
01007 if ( !defined( 'OXID_PHP_UNIT' ) ) {
01008 if (!is_null($this->_oActCurrencyObject)) {
01009 return $this->_oActCurrencyObject;
01010 }
01011 }
01012
01013 $iCur = $this->getShopCurrency();
01014 $aCurrencies = $this->getCurrencyArray();
01015 if ( !isset( $aCurrencies[$iCur] ) ) {
01016 return $this->_oActCurrencyObject = reset( $aCurrencies );
01017 }
01018
01019 return $this->_oActCurrencyObject = $aCurrencies[$iCur];
01020 }
01021
01029 public function setActShopCurrency( $iCur )
01030 {
01031 $aCurrencies = $this->getCurrencyArray();
01032 if ( isset( $aCurrencies[$iCur] ) ) {
01033 oxSession::setVar( 'currency', $iCur );
01034 $this->_oActCurrencyObject = null;
01035 }
01036 }
01037
01045 public function getOutDir( $blAbsolute = true)
01046 {
01047 if ($blAbsolute) {
01048 return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
01049 } else {
01050 return $this->_sOutDir.'/';
01051 }
01052 }
01053
01063 public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
01064 {
01065 $blSSL = is_null($blSSL)?$this->isSsl():$blSSL;
01066 $blAdmin = is_null($blAdmin)?$this->isAdmin():$blAdmin;
01067
01068 if ( $blSSL ) {
01069 if ($blNativeImg && !$blAdmin) {
01070 $sUrl = $this->getSslShopUrl();
01071 } else {
01072 $sUrl = $this->getConfigParam('sSSLShopURL');
01073 if (!$sUrl && $blAdmin) {
01074 $sUrl = $this->getConfigParam('sAdminSSLURL').'../';
01075 }
01076 }
01077 } else {
01078 $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
01079 }
01080
01081 return $sUrl.$this->_sOutDir.'/';
01082 }
01083
01098 public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false )
01099 {
01100 if ( is_null($sTheme) ) {
01101 $sTheme = $this->getConfigParam( 'sTheme' );
01102 }
01103
01104 if ( $blAdmin ) {
01105 $sTheme = 'admin';
01106 }
01107
01108 $sBase = $this->getOutDir( $blAbsolute );
01109 $sAbsBase = $this->getOutDir();
01110
01111 $sLang = '-';
01112
01113 if ( $iLang !== false ) {
01114 $oLang = oxLang::getInstance();
01115
01116 if ( is_null( $iLang ) ) {
01117 $iLang = $oLang->getEditLanguage();
01118 }
01119
01120 $sLang = $oLang->getLanguageAbbr( $iLang );
01121 }
01122
01123 if ( is_null($iShop) ) {
01124 $iShop = $this->getShopId();
01125 }
01126
01127
01128 $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01129 $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01130
01131 if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01132 return $sReturn;
01133 }
01134
01135 $sReturn = false;
01136
01137
01138 $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
01139 if ( !$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01140 $sReturn = $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute );
01141 }
01142
01143
01144 if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01145 $sReturn = $sBase . $sPath;
01146 }
01147
01148
01149 $sPath = "$sTheme/$iShop/$sDir/$sFile";
01150 if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01151 $sReturn = $sBase . $sPath;
01152 }
01153
01154
01155
01156 $sPath = "$sTheme/$sLang/$sDir/$sFile";
01157 if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01158 $sReturn = $sBase . $sPath;
01159 }
01160
01161
01162 $sPath = "$sTheme/$sDir/$sFile";
01163 if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01164 $sReturn = $sBase . $sPath;
01165 }
01166
01167
01168 $sPath = "$sLang/$sDir/$sFile";
01169 if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01170 $sReturn = $sBase . $sPath;
01171 }
01172
01173
01174 $sPath = "$sDir/$sFile";
01175 if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01176 $sReturn = $sBase . $sPath;
01177 }
01178
01179 if ( !$sReturn ) {
01180
01181 }
01182
01183
01184 oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01185
01186 return $sReturn;
01187 }
01188
01203 public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01204 {
01205 $sUrl = str_replace(
01206 $this->getOutDir(),
01207 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01208 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01209 );
01210 return $sUrl;
01211 }
01212
01221 public function getImagePath( $sFile, $blAdmin = false )
01222 {
01223 return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01224 }
01225
01236 public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null )
01237 {
01238 $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01239 return $this->getUrl( $sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01240 }
01241
01249 public function getImageDir( $blAdmin = false )
01250 {
01251 return $this->getDir( null, $this->_sImageDir, $blAdmin );
01252 }
01253
01265 public function getPicturePath($sFile, $blAdmin = false, $iLang = null , $iShop = null , $sTheme = null)
01266 {
01267 return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme );
01268 }
01269
01277 public function getMasterPictureDir( $blAdmin = false )
01278 {
01279 return $this->getDir( null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01280 }
01281
01290 public function getMasterPicturePath( $sFile, $blAdmin = false )
01291 {
01292 return $this->getDir( $sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01293 }
01294
01307 public function getPictureUrl( $sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01308 {
01309 if ( $sAltUrl = oxPictureHandler::getInstance()->getAltImageUrl('/', $sFile, $blSSL) ) {
01310 return $sAltUrl;
01311 }
01312
01313 $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01314 $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01315
01316
01317 if ( !$sUrl && $sDefPic ) {
01318 $sUrl = $this->getUrl( $sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01319 }
01320 return $sUrl;
01321 }
01322
01337 public function getIconUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01338 {
01339 return $this->getPictureUrl( $sFile, $blAdmin, $blSSL, $iLang, $iShopId, $sDefPic );
01340 }
01341
01349 public function getPictureDir( $blAdmin )
01350 {
01351 return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01352 }
01353
01362 public function getTemplatePath( $sFile, $blAdmin )
01363 {
01364 $sTemplatePath = $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01365
01366 if (!$sTemplatePath) {
01367 $sBasePath = getShopBasePath();
01368 $aModuleTemplates = $this->getConfigParam('aModuleTemplates');
01369
01370 $oModulelist = oxNew('oxmodulelist');
01371 $aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
01372 if (is_array($aModuleTemplates) && is_array($aActiveModuleInfo)) {
01373 foreach ($aModuleTemplates as $sModuleId => $aTemplates) {
01374 if (isset($aTemplates[$sFile]) && isset($aActiveModuleInfo[$sModuleId])) {
01375 $sPath = $aTemplates[$sFile];
01376 $sPath = $sBasePath. 'modules/'. $sPath;
01377 if (is_file($sPath) && is_readable($sPath)) {
01378 $sTemplatePath = $sPath;
01379 }
01380 }
01381 }
01382 }
01383 }
01384
01385 return $sTemplatePath;
01386 }
01387
01395 public function getTemplateDir( $blAdmin = false )
01396 {
01397 return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01398 }
01399
01410 public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01411 {
01412 return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01413 }
01414
01422 public function getTemplateBase( $blAdmin = false )
01423 {
01424
01425 return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01426 }
01427
01436 public function getResourcePath($sFile = '', $blAdmin = false )
01437 {
01438 return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01439 }
01440
01448 public function getModulesDir( $blAbsolute = true )
01449 {
01450 if ($blAbsolute) {
01451 return $this->getConfigParam('sShopDir') . $this->_sModulesDir . '/';
01452 } else {
01453 return $this->_sModulesDir . '/';
01454 }
01455 }
01456
01467 public function getResourceUrl( $sFile = '', $blAdmin = false , $blSSL = null , $iLang = null )
01468 {
01469 $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01470 return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang );
01471 }
01472
01480 public function getResourceDir( $blAdmin )
01481 {
01482 return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01483 }
01484
01498 public function getLanguagePath( $sFile, $blAdmin, $iLang = null, $iShop = null, $sTheme = null )
01499 {
01500 return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang, $iShop, $sTheme );
01501 }
01502
01514 public function getStdLanguagePath( $sFile, $blAdmin, $iLang = null )
01515 {
01516 $sDir = null;
01517 if ( $iLang !== false ) {
01518 $sDir = oxLang::getInstance()->getLanguageAbbr( $iLang );
01519 }
01520
01521 return $this->getDir( $sFile, $sDir, $blAdmin, $iLang, null, $this->getConfigParam( "sTheme" ), true, true );
01522 }
01523
01531 public function getLanguageDir( $blAdmin )
01532 {
01533 return $this->getDir( null, null, $blAdmin );
01534 }
01535
01543 public function getCurrencyArray( $iCurrency = null )
01544 {
01545 $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01546 if ( !is_array( $aConfCurrencies ) ) {
01547 return array();
01548 }
01549
01550 if ( defined( 'OXID_PHP_UNIT' ) ) {
01551 if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01552 try{
01553 $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01554 if ( isset( $aAltCurrencies ) ) {
01555 $aConfCurrencies = $aAltCurrencies;
01556 }
01557 } catch( Exception $e ) {
01558
01559 }
01560 }
01561 }
01562
01563
01564 $aCurrencies = array();
01565 reset( $aConfCurrencies );
01566 while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01567 if ( $val ) {
01568 $oCur = new oxStdClass();
01569 $oCur->id = $key;
01570 $sCur = explode( '@', $val);
01571 $oCur->name = trim( $sCur[0] );
01572 $oCur->rate = trim( $sCur[1] );
01573 $oCur->dec = trim( $sCur[2] );
01574 $oCur->thousand = trim( $sCur[3] );
01575 $oCur->sign = trim( $sCur[4] );
01576 $oCur->decimal = trim( $sCur[5] );
01577
01578
01579 if ( isset( $sCur[6] ) ) {
01580 $oCur->side = trim($sCur[6]);
01581 }
01582
01583 if ( isset( $iCurrency) && $key == $iCurrency ) {
01584 $oCur->selected = 1;
01585 } else {
01586 $oCur->selected = 0;
01587 }
01588 $aCurrencies[$key]= $oCur;
01589 }
01590
01591
01592 if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01593 break;
01594 }
01595 }
01596 return $aCurrencies;
01597 }
01598
01606 public function getCurrencyObject( $sName )
01607 {
01608 $aSearch = $this->getCurrencyArray();
01609 foreach ( $aSearch as $oCur ) {
01610 if ( $oCur->name == $sName ) {
01611 return $oCur;
01612 }
01613 }
01614 }
01615
01621 public function isDemoShop()
01622 {
01623 return $this->getConfigParam('blDemoShop');
01624 }
01625
01626
01627
01633 public function getEdition()
01634 {
01635 return "CE";
01636
01637
01638 }
01639
01645 public function getFullEdition()
01646 {
01647 $sEdition = $this->getEdition();
01648
01649 if ($sEdition == "CE") {
01650 return "Community Edition";
01651 }
01652
01653
01654
01655 return $sEdition;
01656 }
01657
01663 public function getVersion()
01664 {
01665 $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01666 return $sVersion;
01667 }
01668
01674 public function getRevision()
01675 {
01676 try {
01677 $sFileName = getShopBasePath() . "/pkg.rev";
01678 $iRev = (int) trim(@file_get_contents($sFileName));
01679 } catch (Exception $e) {
01680 return false;
01681 }
01682
01683 if (!$iRev) {
01684 return false;
01685 }
01686
01687 return $iRev;
01688 }
01689
01690
01696 public function isMall()
01697 {
01698
01699 return false;
01700 }
01701
01711 public function detectVersion()
01712 {
01713 }
01714
01715
01716
01729 public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '' )
01730 {
01731 switch ( $sVarType ) {
01732 case 'arr':
01733 case 'aarr':
01734 if (is_array($sVarVal)) {
01735 $sValue = serialize( $sVarVal );
01736 } else {
01737
01738 $sValue = $sVarVal ;
01739 $sVarVal = unserialize( $sVarVal );
01740 }
01741 break;
01742 case 'bool':
01743
01744 $sVarVal = (( $sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
01745
01746 $sValue = $sVarVal?"1":"";
01747 break;
01748 default:
01749 $sValue = $sVarVal;
01750 break;
01751 }
01752
01753 if ( !$sShopId ) {
01754 $sShopId = $this->getShopId();
01755 }
01756
01757
01758 if ($sShopId == $this->getShopId()) {
01759 $this->setConfigParam( $sVarName, $sVarVal );
01760 }
01761
01762 $oDb = oxDb::getDb();
01763
01764 $sShopIdQuoted = $oDb->quote($sShopId);
01765 $sModuleQuoted = $oDb->quote($sModule);
01766 $sVarNameQuoted = $oDb->quote($sVarName);
01767 $sVarTypeQuoted = $oDb->quote($sVarType);
01768 $sVarValueQuoted = $oDb->quote($sValue);
01769 $sConfigKeyQuoted = $oDb->quote($this->getConfigParam('sConfigKey'));
01770 $sNewOXIDdQuoted = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
01771
01772 $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
01773 $oDb->execute( $sQ );
01774
01775 $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
01776 values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
01777
01778 $oDb->execute( $sQ );
01779 }
01780
01790 public function getShopConfVar( $sVarName, $sShopId = null, $sModule = '' )
01791 {
01792 if ( !$sShopId ) {
01793 $sShopId = $this->getShopId();
01794 }
01795
01796 if ( $sShopId === $this->getShopId() && ( !$sModule || $sModule == oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') ) ) {
01797 $sVarValue = $this->getConfigParam( $sVarName );
01798 if ( $sVarValue !== null ) {
01799 return $sVarValue;
01800 }
01801 }
01802
01803 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01804
01805 $sQ = "select oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '{$sShopId}' and oxmodule = '{$sModule}' and oxvarname = ".$oDb->quote($sVarName);
01806 $oRs = $oDb->select( $sQ );
01807
01808 $sValue = null;
01809 if ( $oRs != false && $oRs->recordCount() > 0 ) {
01810 $sValue = $this->decodeValue( $oRs->fields['oxvartype'], $oRs->fields['oxvarvalue'] );
01811 }
01812 return $sValue;
01813 }
01814
01823 public function decodeValue( $sType, $mOrigValue )
01824 {
01825 $sValue = $mOrigValue;
01826 switch ( $sType ) {
01827 case 'arr':
01828 case 'aarr':
01829 $sValue = unserialize( $mOrigValue );
01830 break;
01831 case 'bool':
01832 $sValue = ( $mOrigValue == 'true' || $mOrigValue == '1' );
01833 break;
01834 }
01835
01836 return $sValue;
01837 }
01838
01846 public function getDecodeValueQuery( $sFieldName = "oxvarvalue" )
01847 {
01848 return " DECODE( {$sFieldName}, '".$this->getConfigParam( 'sConfigKey' )."') ";
01849 }
01850
01856 public function isProductiveMode()
01857 {
01858 $blProductive = false;
01859
01860 $blProductive = $this->getConfigParam( 'blProductive' );
01861 if ( !isset( $blProductive ) ) {
01862 $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01863 $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01864 $this->setConfigParam( 'blProductive', $blProductive );
01865 }
01866
01867 return $blProductive;
01868 }
01869
01870
01871
01877 public function getBaseShopId()
01878 {
01879
01880 return 'oxbaseshop';
01881 }
01882
01888 public function getActiveShop()
01889 {
01890 if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01891 $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01892 return $this->_oActShop;
01893 }
01894
01895 $this->_oActShop = oxNew( 'oxshop' );
01896 $this->_oActShop->load( $this->getShopId() );
01897 return $this->_oActShop;
01898 }
01899
01905 public function getActiveView()
01906 {
01907 if ( $this->_oActView != null ) {
01908 return $this->_oActView;
01909 }
01910
01911 $this->_oActView = oxNew( 'oxubase' );
01912 return $this->_oActView;
01913 }
01914
01922 public function setActiveView( $oView )
01923 {
01924 $this->_oActView = $oView;
01925 }
01926
01932 public function isUtf()
01933 {
01934 return ( bool ) $this->getConfigParam( 'iUtfMode' );
01935 }
01936
01942 public function getLogsDir()
01943 {
01944 return $this->getConfigParam( 'sShopDir' ).'log/';
01945 }
01946
01954 public function isThemeOption( $sName )
01955 {
01956 return (bool) isset( $this->_aThemeConfigParams[$sName] );
01957 }
01958
01964 public function getShopMainUrl()
01965 {
01966 return $this->isSsl() ? $this->getConfigParam( 'sSSLShopURL' ) : $this->getConfigParam( 'sShopURL' );
01967 }
01968
01974 public function getAllModules()
01975 {
01976 return $this->parseModuleChains($this->getConfigParam('aModules'));
01977 }
01978
01986 public function parseModuleChains($aModules)
01987 {
01988 $aModuleArray = array();
01989
01990 if (is_array($aModules)) {
01991 foreach ($aModules as $sClass => $sModuleChain) {
01992 if (strstr($sModuleChain, '&')) {
01993 $aModuleChain = explode('&', $sModuleChain);
01994 } else {
01995 $aModuleChain = array($sModuleChain);
01996 }
01997 $aModuleArray[$sClass] = $aModuleChain;
01998 }
01999 }
02000
02001 return $aModuleArray;
02002 }
02003
02004 }