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 $blConfigLoaded = $this->_loadVarsFromDb( $sShopID );
00426
00427
00428 if ( empty($sShopID) || !$blConfigLoaded ) {
00429
00430 $oEx = oxNew( "oxConnectionException" );
00431 $oEx->setMessage( "Unable to load shop config values from database" );
00432 throw $oEx;
00433 }
00434
00435
00436 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') );
00437
00438
00439 if ( $this->getConfigParam('sCustomTheme') ) {
00440 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme') );
00441 }
00442
00443
00444 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_MODULE_PREFIX );
00445
00446
00447 $this->_processSeoCall();
00448
00449
00450 $this->getSession()->start();
00451
00452 } catch ( oxConnectionException $oEx ) {
00453
00454 $oEx->debugOut();
00455 if ( defined( 'OXID_PHP_UNIT' ) ) {
00456 return false;
00457 } elseif ( 0 != $this->iDebug ) {
00458 oxUtils::getInstance()->showMessageAndExit( $oEx->getString() );
00459 } else {
00460 header( "HTTP/1.1 500 Internal Server Error");
00461 header( "Location: offline.html");
00462 header( "Connection: close");
00463 }
00464 } catch ( oxCookieException $oEx ) {
00465
00466 $this->_processSeoCall();
00467
00468
00469 $this->getSession()->start();
00470
00471
00472 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00473 oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start', true, 302 );
00474 }
00475
00476
00477 $this->_loadVarsFromFile();
00478
00479
00480 $this->_oStart = new oxStart();
00481 $this->_oStart->appInit();
00482 }
00483
00489 public static function getInstance()
00490 {
00491
00492 if ( defined( 'OXID_PHP_UNIT' ) ) {
00493 if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00494 return modConfig::$unitMOD;
00495 }
00496 }
00497
00498 if ( !self::$_instance instanceof oxConfig ) {
00499
00500
00501 self::$_instance = new oxConfig();
00502 self::$_instance->init();
00503 }
00504 return self::$_instance;
00505 }
00506
00512 protected function _loadVarsFromFile()
00513 {
00514
00515 include getShopBasePath().'/config.inc.php';
00516
00517
00518 $oFileUtils = oxUtilsFile::getInstance();
00519 $this->sShopDir = $oFileUtils->normalizeDir($this->sShopDir);
00520 $this->sCompileDir = $oFileUtils->normalizeDir($this->sCompileDir);
00521 $this->sShopURL = $oFileUtils->normalizeDir($this->sShopURL);
00522 $this->sSSLShopURL = $oFileUtils->normalizeDir($this->sSSLShopURL);
00523 $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00524 }
00525
00535 protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null, $sModule = '' )
00536 {
00537 $oDb = oxDb::getDb();
00538
00539 if ( !empty($sModule) ) {
00540 $sModuleSql = " oxmodule LIKE " . $oDb->quote($sModule."%");
00541 } else {
00542 $sModuleSql = " oxmodule='' ";
00543 }
00544
00545 $sQ = "select oxvarname, oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '$sShopID' and " . $sModuleSql;
00546
00547 if ( $aOnlyVars !== null ) {
00548 $blSep = false;
00549 $sIn = '';
00550 foreach ( $aOnlyVars as $sField ) {
00551 if ( $blSep ) {
00552 $sIn .= ', ';
00553 }
00554 $sIn .= '"'.$sField.'"';
00555 $blSep = true;
00556 }
00557 $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00558 }
00559 $oRs = $oDb->select( $sQ );
00560
00561 if ( $oRs != false && $oRs->recordCount() > 0 ) {
00562 while ( !$oRs->EOF ) {
00563 $sVarName = $oRs->fields[0];
00564 $sVarType = $oRs->fields[1];
00565 $sVarVal = $oRs->fields[2];
00566
00567
00568 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00569 ( !$sVarVal || $this->isAdmin() === true ) ) {
00570 $oRs->moveNext();
00571 continue;
00572 }
00573
00574 $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
00575
00576
00577 if ( $sModule != '' ) {
00578 $this->_aThemeConfigParams[$sVarName] = $sModule;
00579 }
00580
00581 $oRs->moveNext();
00582 }
00583
00584 return true;
00585 } else {
00586 return false;
00587 }
00588 }
00589
00599 protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
00600 {
00601 switch ( $sVarType ) {
00602 case 'arr':
00603 case 'aarr':
00604 $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00605 break;
00606 case 'bool':
00607 $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00608 break;
00609 default:
00610 $this->setConfigParam( $sVarName, $sVarVal );
00611 break;
00612 }
00613 }
00614
00620 public function pageClose()
00621 {
00622 return $this->_oStart->pageClose();
00623 }
00624
00636 public static function getParameter( $sName, $blRaw = false )
00637 {
00638 if ( defined( 'OXID_PHP_UNIT' ) ) {
00639 if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00640 try{
00641 $sValue = modConfig::getParameter( $sName, $blRaw );
00642
00643
00644 $blIsAdmin = modConfig::getInstance()->isAdmin() || isAdmin();
00645 if ( $sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00646 self::checkSpecialChars( $sValue, $blRaw );
00647 }
00648
00649 return $sValue;
00650 } catch( Exception $e ) {
00651
00652 }
00653 }
00654 }
00655
00656 $sValue = null;
00657
00658 if ( isset( $_POST[$sName] ) ) {
00659 $sValue = $_POST[$sName];
00660 } elseif ( isset( $_GET[$sName] ) ) {
00661 $sValue = $_GET[$sName];
00662 }
00663
00664
00665 $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00666 if ( $sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00667 self::checkSpecialChars( $sValue, $blRaw );
00668 }
00669
00670 return $sValue;
00671 }
00672
00680 public function getUploadedFile($sParamName)
00681 {
00682 return $_FILES[$sParamName];
00683 }
00684
00693 public function setGlobalParameter( $sName, $sValue )
00694 {
00695 $this->_aGlobalParams[$sName] = $sValue;
00696 }
00697
00705 public function getGlobalParameter( $sName )
00706 {
00707 if ( isset( $this->_aGlobalParams[$sName] ) ) {
00708 return $this->_aGlobalParams[$sName];
00709 } else {
00710 return null;
00711 }
00712 }
00713
00723 public static function checkSpecialChars( & $sValue, $aRaw = null )
00724 {
00725 if ( is_object( $sValue ) ) {
00726 return $sValue;
00727 }
00728
00729 if ( is_array( $sValue ) ) {
00730 $newValue = array();
00731 foreach ( $sValue as $sKey => $sVal ) {
00732 $sValidKey = $sKey;
00733 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00734 self::checkSpecialChars( $sValidKey );
00735 self::checkSpecialChars( $sVal );
00736 if ($sValidKey != $sKey) {
00737 unset ($sValue[$sKey]);
00738 }
00739 }
00740 $newValue[$sValidKey] = $sVal;
00741 }
00742 $sValue = $newValue;
00743 } elseif ( is_string( $sValue ) ) {
00744 $sValue = str_replace( array( '&', '<', '>', '"', "'", chr(0), '\\' ),
00745 array( '&', '<', '>', '"', ''', '', '\' ),
00746 $sValue );
00747 }
00748 return $sValue;
00749 }
00750
00756 public function getShopId()
00757 {
00758 if ( $this->_iShopId !== null )
00759 return $this->_iShopId;
00760
00761 $this->_iShopId = $this->getBaseShopId();
00762
00763
00764 oxSession::setVar( 'actshop', $this->_iShopId );
00765 return $this->_iShopId;
00766 }
00767
00768
00776 public function setShopId( $sShopId )
00777 {
00778 oxSession::setVar( 'actshop', $sShopId );
00779 $this->_iShopId = $sShopId;
00780 }
00781
00782
00788 public function isSsl()
00789 {
00790 if ( is_null( $this->_blIsSsl ) ) {
00791
00792 $myUtilsServer = oxUtilsServer::getInstance();
00793 $aServerVars = $myUtilsServer->getServerVar();
00794 $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00795
00796 $this->_blIsSsl = false;
00797 if (isset( $aHttpsServerVar ) && ($aHttpsServerVar === 'on' || $aHttpsServerVar === 'ON' || $aHttpsServerVar == '1' )) {
00798
00799 $this->_blIsSsl = ($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
00800 if ($this->isAdmin() && !$this->_blIsSsl) {
00801
00802 $this->_blIsSsl = !is_null($this->getConfigParam('sAdminSSLURL')) ? true : false;
00803 }
00804 }
00805
00806
00807 if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00808 ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00809 strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00810 $this->_blIsSsl = true;
00811 }
00812 }
00813
00814 return $this->_blIsSsl;
00815 }
00816
00824 public function isCurrentUrl( $sURL )
00825 {
00826 if ( !$sURL ) {
00827 return false;
00828 }
00829
00830 $oUtilsServer = oxUtilsServer::getInstance();
00831
00832
00833 preg_match("/^(https?:\/\/)?([^\/]+)/i", $sURL, $matches);
00834 $sUrlHost = $matches[2];
00835
00836
00837 preg_match("/^(https?:\/\/)?([^\/]+)/i", $oUtilsServer->getServerVar( 'HTTP_HOST' ), $matches);
00838 $sRealHost = $matches[2];
00839
00840 $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $oUtilsServer->getServerVar( 'HTTP_HOST' ) . $oUtilsServer->getServerVar( 'SCRIPT_NAME' ) );
00841
00842
00843 $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00844 $sURL = str_replace( '/', '', $sURL );
00845
00846 if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00847
00848
00849 if ( $sUrlHost == $sRealHost ) {
00850 return true;
00851 }
00852 }
00853
00854 return false;
00855 }
00856
00865 public function getShopUrl( $iLang = null, $blAdmin = null )
00866 {
00867 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00868 if ( $blAdmin ) {
00869 return $this->getConfigParam( 'sShopURL' );
00870 }
00871
00872
00873 $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00874 $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00875 if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00876 $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00877 return $aLanguageURLs[$iLang];
00878 }
00879
00880
00881 $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00882 if ( $sMallShopURL ) {
00883 $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00884 return $sMallShopURL;
00885 }
00886
00887 return $this->getConfigParam( 'sShopURL' );
00888 }
00889
00897 public function getSslShopUrl( $iLang = null )
00898 {
00899
00900 $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00901 $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00902 if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00903 $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00904 return $aLanguageSSLURLs[$iLang];
00905 }
00906
00907
00908 if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00909 $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00910 return $sMallSSLShopURL;
00911 }
00912
00913 if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00914 $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00915 return $sMallShopURL;
00916 }
00917
00918
00919 if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00920 return $sSSLShopURL;
00921 }
00922
00923 return $this->getShopUrl( $iLang );
00924 }
00925
00931 public function getCoreUtilsUrl()
00932 {
00933 return $this->getCurrentShopUrl().'core/utils/';
00934 }
00935
00944 public function getCurrentShopUrl($blAdmin = null)
00945 {
00946 if ($blAdmin===null) {
00947 $blAdmin = $this->isAdmin();
00948 }
00949 if ($blAdmin) {
00950 if ($this->isSsl()) {
00951
00952 $sUrl = $this->getConfigParam( 'sAdminSSLURL' );
00953 if ( !$sUrl ) {
00954 return $this->getSslShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00955 }
00956 return $sUrl;
00957 } else {
00958 return $this->getShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00959 }
00960 } else {
00961 return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
00962 }
00963 }
00964
00972 public function getShopCurrentUrl( $iLang = null )
00973 {
00974 if ( $this->isSsl() ) {
00975 $sURL = $this->getSSLShopURL( $iLang );
00976 } else {
00977 $sURL = $this->getShopURL( $iLang );
00978 }
00979
00980 return oxUtilsUrl::getInstance()->processUrl( $sURL.'index.php', false );
00981 }
00982
00991 public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00992 {
00993 return oxUtilsUrl::getInstance()->processUrl($this->getShopUrl( $iLang, $blAdmin).'index.php', false );
00994 }
00995
01001 public function getShopSecureHomeUrl()
01002 {
01003 return oxUtilsUrl::getInstance()->processUrl( $this->getSslShopUrl().'index.php', false );
01004 }
01005
01011 public function getShopCurrency()
01012 {
01013 $iCurr = null;
01014 if ( ( null === ( $iCurr = oxConfig::getParameter( 'cur' ) ) ) ) {
01015 if ( null === ( $iCurr = oxConfig::getParameter( 'currency' ) ) ) {
01016 $iCurr = oxSession::getVar( 'currency' );
01017 }
01018 }
01019 return (int) $iCurr;
01020 }
01021
01027 public function getActShopCurrencyObject()
01028 {
01029
01030
01031 if ( !defined( 'OXID_PHP_UNIT' ) ) {
01032 if (!is_null($this->_oActCurrencyObject)) {
01033 return $this->_oActCurrencyObject;
01034 }
01035 }
01036
01037 $iCur = $this->getShopCurrency();
01038 $aCurrencies = $this->getCurrencyArray();
01039 if ( !isset( $aCurrencies[$iCur] ) ) {
01040 return $this->_oActCurrencyObject = reset( $aCurrencies );
01041 }
01042
01043 return $this->_oActCurrencyObject = $aCurrencies[$iCur];
01044 }
01045
01053 public function setActShopCurrency( $iCur )
01054 {
01055 $aCurrencies = $this->getCurrencyArray();
01056 if ( isset( $aCurrencies[$iCur] ) ) {
01057 oxSession::setVar( 'currency', $iCur );
01058 $this->_oActCurrencyObject = null;
01059 }
01060 }
01061
01069 public function getOutDir( $blAbsolute = true)
01070 {
01071 if ($blAbsolute) {
01072 return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
01073 } else {
01074 return $this->_sOutDir.'/';
01075 }
01076 }
01077
01087 public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
01088 {
01089 $blSSL = is_null($blSSL)?$this->isSsl():$blSSL;
01090 $blAdmin = is_null($blAdmin)?$this->isAdmin():$blAdmin;
01091
01092 if ( $blSSL ) {
01093 if ($blNativeImg && !$blAdmin) {
01094 $sUrl = $this->getSslShopUrl();
01095 } else {
01096 $sUrl = $this->getConfigParam('sSSLShopURL');
01097 if (!$sUrl && $blAdmin) {
01098 $sUrl = $this->getConfigParam('sAdminSSLURL').'../';
01099 }
01100 }
01101 } else {
01102 $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
01103 }
01104
01105 return $sUrl.$this->_sOutDir.'/';
01106 }
01107
01122 public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false )
01123 {
01124 if ( is_null($sTheme) ) {
01125 $sTheme = $this->getConfigParam( 'sTheme' );
01126 }
01127
01128 if ( $blAdmin ) {
01129 $sTheme = 'admin';
01130 }
01131
01132 $sBase = $this->getOutDir( $blAbsolute );
01133 $sAbsBase = $this->getOutDir();
01134
01135 $sLang = '-';
01136
01137 if ( $iLang !== false ) {
01138 $oLang = oxLang::getInstance();
01139
01140 if ( is_null( $iLang ) ) {
01141 $iLang = $oLang->getEditLanguage();
01142 }
01143
01144 $sLang = $oLang->getLanguageAbbr( $iLang );
01145 }
01146
01147 if ( is_null($iShop) ) {
01148 $iShop = $this->getShopId();
01149 }
01150
01151
01152 $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01153 $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01154
01155 if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01156 return $sReturn;
01157 }
01158
01159 $sReturn = false;
01160
01161
01162 $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
01163 if ( !$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01164 $sReturn = $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute );
01165 }
01166
01167
01168 if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01169 $sReturn = $sBase . $sPath;
01170 }
01171
01172
01173 $sPath = "$sTheme/$iShop/$sDir/$sFile";
01174 if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01175 $sReturn = $sBase . $sPath;
01176 }
01177
01178
01179
01180 $sPath = "$sTheme/$sLang/$sDir/$sFile";
01181 if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01182 $sReturn = $sBase . $sPath;
01183 }
01184
01185
01186 $sPath = "$sTheme/$sDir/$sFile";
01187 if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01188 $sReturn = $sBase . $sPath;
01189 }
01190
01191
01192 $sPath = "$sLang/$sDir/$sFile";
01193 if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01194 $sReturn = $sBase . $sPath;
01195 }
01196
01197
01198 $sPath = "$sDir/$sFile";
01199 if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01200 $sReturn = $sBase . $sPath;
01201 }
01202
01203 if ( !$sReturn ) {
01204
01205 }
01206
01207
01208 oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01209
01210 return $sReturn;
01211 }
01212
01227 public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01228 {
01229 $sUrl = str_replace(
01230 $this->getOutDir(),
01231 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01232 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01233 );
01234 return $sUrl;
01235 }
01236
01245 public function getImagePath( $sFile, $blAdmin = false )
01246 {
01247 return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01248 }
01249
01260 public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null )
01261 {
01262 $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01263 return $this->getUrl( $sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01264 }
01265
01273 public function getImageDir( $blAdmin = false )
01274 {
01275 return $this->getDir( null, $this->_sImageDir, $blAdmin );
01276 }
01277
01289 public function getPicturePath($sFile, $blAdmin = false, $iLang = null , $iShop = null , $sTheme = null)
01290 {
01291 return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme );
01292 }
01293
01301 public function getMasterPictureDir( $blAdmin = false )
01302 {
01303 return $this->getDir( null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01304 }
01305
01314 public function getMasterPicturePath( $sFile, $blAdmin = false )
01315 {
01316 return $this->getDir( $sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01317 }
01318
01331 public function getPictureUrl( $sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01332 {
01333 if ( $sAltUrl = oxPictureHandler::getInstance()->getAltImageUrl('/', $sFile, $blSSL) ) {
01334 return $sAltUrl;
01335 }
01336
01337 $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01338 $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01339
01340
01341 if ( !$sUrl && $sDefPic ) {
01342 $sUrl = $this->getUrl( $sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01343 }
01344 return $sUrl;
01345 }
01346
01361 public function getIconUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01362 {
01363 return $this->getPictureUrl( $sFile, $blAdmin, $blSSL, $iLang, $iShopId, $sDefPic );
01364 }
01365
01373 public function getPictureDir( $blAdmin )
01374 {
01375 return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01376 }
01377
01386 public function getTemplatePath( $sFile, $blAdmin )
01387 {
01388 $sTemplatePath = $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01389
01390 if (!$sTemplatePath) {
01391 $sBasePath = getShopBasePath();
01392 $aModuleTemplates = $this->getConfigParam('aModuleTemplates');
01393
01394 $oModulelist = oxNew('oxmodulelist');
01395 $aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
01396 if (is_array($aModuleTemplates) && is_array($aActiveModuleInfo)) {
01397 foreach ($aModuleTemplates as $sModuleId => $aTemplates) {
01398 if (isset($aTemplates[$sFile]) && isset($aActiveModuleInfo[$sModuleId])) {
01399 $sPath = $aTemplates[$sFile];
01400 $sPath = $sBasePath. 'modules/'. $sPath;
01401 if (is_file($sPath) && is_readable($sPath)) {
01402 $sTemplatePath = $sPath;
01403 }
01404 }
01405 }
01406 }
01407 }
01408
01409 return $sTemplatePath;
01410 }
01411
01419 public function getTemplateDir( $blAdmin = false )
01420 {
01421 return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01422 }
01423
01434 public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01435 {
01436 return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01437 }
01438
01446 public function getTemplateBase( $blAdmin = false )
01447 {
01448
01449 return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01450 }
01451
01460 public function getResourcePath($sFile = '', $blAdmin = false )
01461 {
01462 return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01463 }
01464
01472 public function getModulesDir( $blAbsolute = true )
01473 {
01474 if ($blAbsolute) {
01475 return $this->getConfigParam('sShopDir') . $this->_sModulesDir . '/';
01476 } else {
01477 return $this->_sModulesDir . '/';
01478 }
01479 }
01480
01491 public function getResourceUrl( $sFile = '', $blAdmin = false , $blSSL = null , $iLang = null )
01492 {
01493 $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01494 return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang );
01495 }
01496
01504 public function getResourceDir( $blAdmin )
01505 {
01506 return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01507 }
01508
01522 public function getLanguagePath( $sFile, $blAdmin, $iLang = null, $iShop = null, $sTheme = null )
01523 {
01524 return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang, $iShop, $sTheme );
01525 }
01526
01538 public function getStdLanguagePath( $sFile, $blAdmin, $iLang = null )
01539 {
01540 $sDir = null;
01541 if ( $iLang !== false ) {
01542 $sDir = oxLang::getInstance()->getLanguageAbbr( $iLang );
01543 }
01544
01545 return $this->getDir( $sFile, $sDir, $blAdmin, $iLang, null, $this->getConfigParam( "sTheme" ), true, true );
01546 }
01547
01555 public function getLanguageDir( $blAdmin )
01556 {
01557 return $this->getDir( null, null, $blAdmin );
01558 }
01559
01567 public function getCurrencyArray( $iCurrency = null )
01568 {
01569 $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01570 if ( !is_array( $aConfCurrencies ) ) {
01571 return array();
01572 }
01573
01574 if ( defined( 'OXID_PHP_UNIT' ) ) {
01575 if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01576 try{
01577 $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01578 if ( isset( $aAltCurrencies ) ) {
01579 $aConfCurrencies = $aAltCurrencies;
01580 }
01581 } catch( Exception $e ) {
01582
01583 }
01584 }
01585 }
01586
01587
01588 $aCurrencies = array();
01589 reset( $aConfCurrencies );
01590 while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01591 if ( $val ) {
01592 $oCur = new oxStdClass();
01593 $oCur->id = $key;
01594 $sCur = explode( '@', $val);
01595 $oCur->name = trim( $sCur[0] );
01596 $oCur->rate = trim( $sCur[1] );
01597 $oCur->dec = trim( $sCur[2] );
01598 $oCur->thousand = trim( $sCur[3] );
01599 $oCur->sign = trim( $sCur[4] );
01600 $oCur->decimal = trim( $sCur[5] );
01601
01602
01603 if ( isset( $sCur[6] ) ) {
01604 $oCur->side = trim($sCur[6]);
01605 }
01606
01607 if ( isset( $iCurrency) && $key == $iCurrency ) {
01608 $oCur->selected = 1;
01609 } else {
01610 $oCur->selected = 0;
01611 }
01612 $aCurrencies[$key]= $oCur;
01613 }
01614
01615
01616 if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01617 break;
01618 }
01619 }
01620 return $aCurrencies;
01621 }
01622
01630 public function getCurrencyObject( $sName )
01631 {
01632 $aSearch = $this->getCurrencyArray();
01633 foreach ( $aSearch as $oCur ) {
01634 if ( $oCur->name == $sName ) {
01635 return $oCur;
01636 }
01637 }
01638 }
01639
01645 public function isDemoShop()
01646 {
01647 return $this->getConfigParam('blDemoShop');
01648 }
01649
01650
01651
01657 public function getEdition()
01658 {
01659 return "CE";
01660
01661
01662 }
01663
01669 public function getFullEdition()
01670 {
01671 $sEdition = $this->getEdition();
01672
01673 if ($sEdition == "CE") {
01674 return "Community Edition";
01675 }
01676
01677
01678
01679 return $sEdition;
01680 }
01681
01687 public function getVersion()
01688 {
01689 $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01690 return $sVersion;
01691 }
01692
01698 public function getRevision()
01699 {
01700 try {
01701 $sFileName = getShopBasePath() . "/pkg.rev";
01702 $iRev = (int) trim(@file_get_contents($sFileName));
01703 } catch (Exception $e) {
01704 return false;
01705 }
01706
01707 if (!$iRev) {
01708 return false;
01709 }
01710
01711 return $iRev;
01712 }
01713
01714
01720 public function isMall()
01721 {
01722
01723 return false;
01724 }
01725
01735 public function detectVersion()
01736 {
01737 }
01738
01739
01740
01753 public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '' )
01754 {
01755 switch ( $sVarType ) {
01756 case 'arr':
01757 case 'aarr':
01758 if (is_array($sVarVal)) {
01759 $sValue = serialize( $sVarVal );
01760 } else {
01761
01762 $sValue = $sVarVal ;
01763 $sVarVal = unserialize( $sVarVal );
01764 }
01765 break;
01766 case 'bool':
01767
01768 $sVarVal = (( $sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
01769
01770 $sValue = $sVarVal?"1":"";
01771 break;
01772 default:
01773 $sValue = $sVarVal;
01774 break;
01775 }
01776
01777 if ( !$sShopId ) {
01778 $sShopId = $this->getShopId();
01779 }
01780
01781
01782 if ($sShopId == $this->getShopId()) {
01783 $this->setConfigParam( $sVarName, $sVarVal );
01784 }
01785
01786 $oDb = oxDb::getDb();
01787
01788 $sShopIdQuoted = $oDb->quote($sShopId);
01789 $sModuleQuoted = $oDb->quote($sModule);
01790 $sVarNameQuoted = $oDb->quote($sVarName);
01791 $sVarTypeQuoted = $oDb->quote($sVarType);
01792 $sVarValueQuoted = $oDb->quote($sValue);
01793 $sConfigKeyQuoted = $oDb->quote($this->getConfigParam('sConfigKey'));
01794 $sNewOXIDdQuoted = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
01795
01796 $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
01797 $oDb->execute( $sQ );
01798
01799 $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
01800 values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
01801
01802 $oDb->execute( $sQ );
01803 }
01804
01814 public function getShopConfVar( $sVarName, $sShopId = null, $sModule = '' )
01815 {
01816 if ( !$sShopId ) {
01817 $sShopId = $this->getShopId();
01818 }
01819
01820 if ( $sShopId === $this->getShopId() && ( !$sModule || $sModule == oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') ) ) {
01821 $sVarValue = $this->getConfigParam( $sVarName );
01822 if ( $sVarValue !== null ) {
01823 return $sVarValue;
01824 }
01825 }
01826
01827 $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
01828
01829 $sQ = "select oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '{$sShopId}' and oxmodule = '{$sModule}' and oxvarname = ".$oDb->quote($sVarName);
01830 $oRs = $oDb->select( $sQ );
01831
01832 $sValue = null;
01833 if ( $oRs != false && $oRs->recordCount() > 0 ) {
01834 $sValue = $this->decodeValue( $oRs->fields['oxvartype'], $oRs->fields['oxvarvalue'] );
01835 }
01836 return $sValue;
01837 }
01838
01847 public function decodeValue( $sType, $mOrigValue )
01848 {
01849 $sValue = $mOrigValue;
01850 switch ( $sType ) {
01851 case 'arr':
01852 case 'aarr':
01853 $sValue = unserialize( $mOrigValue );
01854 break;
01855 case 'bool':
01856 $sValue = ( $mOrigValue == 'true' || $mOrigValue == '1' );
01857 break;
01858 }
01859
01860 return $sValue;
01861 }
01862
01870 public function getDecodeValueQuery( $sFieldName = "oxvarvalue" )
01871 {
01872 return " DECODE( {$sFieldName}, '".$this->getConfigParam( 'sConfigKey' )."') ";
01873 }
01874
01880 public function isProductiveMode()
01881 {
01882 $blProductive = false;
01883
01884 $blProductive = $this->getConfigParam( 'blProductive' );
01885 if ( !isset( $blProductive ) ) {
01886 $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01887 $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01888 $this->setConfigParam( 'blProductive', $blProductive );
01889 }
01890
01891 return $blProductive;
01892 }
01893
01894
01895
01901 public function getBaseShopId()
01902 {
01903
01904 return 'oxbaseshop';
01905 }
01906
01912 public function getActiveShop()
01913 {
01914 if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01915 $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01916 return $this->_oActShop;
01917 }
01918
01919 $this->_oActShop = oxNew( 'oxshop' );
01920 $this->_oActShop->load( $this->getShopId() );
01921 return $this->_oActShop;
01922 }
01923
01929 public function getActiveView()
01930 {
01931 if ( $this->_oActView != null ) {
01932 return $this->_oActView;
01933 }
01934
01935 $this->_oActView = oxNew( 'oxubase' );
01936 return $this->_oActView;
01937 }
01938
01946 public function setActiveView( $oView )
01947 {
01948 $this->_oActView = $oView;
01949 }
01950
01956 public function isUtf()
01957 {
01958 return ( bool ) $this->getConfigParam( 'iUtfMode' );
01959 }
01960
01966 public function getLogsDir()
01967 {
01968 return $this->getConfigParam( 'sShopDir' ).'log/';
01969 }
01970
01978 public function isThemeOption( $sName )
01979 {
01980 return (bool) isset( $this->_aThemeConfigParams[$sName] );
01981 }
01982
01988 public function getShopMainUrl()
01989 {
01990 return $this->isSsl() ? $this->getConfigParam( 'sSSLShopURL' ) : $this->getConfigParam( 'sShopURL' );
01991 }
01992
01998 public function getAllModules()
01999 {
02000 return $this->parseModuleChains($this->getConfigParam('aModules'));
02001 }
02002
02010 public function parseModuleChains($aModules)
02011 {
02012 $aModuleArray = array();
02013
02014 if (is_array($aModules)) {
02015 foreach ($aModules as $sClass => $sModuleChain) {
02016 if (strstr($sModuleChain, '&')) {
02017 $aModuleChain = explode('&', $sModuleChain);
02018 } else {
02019 $aModuleChain = array($sModuleChain);
02020 }
02021 $aModuleArray[$sClass] = $aModuleChain;
02022 }
02023 }
02024
02025 return $aModuleArray;
02026 }
02027
02028 }