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 $_blIsSsl = null;
00257
00263 protected $_aAbsDynImageDir = array();
00264
00270 protected $_oActCurrencyObject = null;
00271
00277 const OXMODULE_THEME_PREFIX = 'theme:';
00278
00286 public function getConfigParam( $sName )
00287 {
00288 if ( isset( $this->$sName ) ) {
00289 return $this->$sName;
00290 } elseif ( isset ( $this->_aConfigParams[$sName] ) ) {
00291 return $this->_aConfigParams[$sName];
00292 }
00293 }
00294
00303 public function setConfigParam( $sName, $sValue )
00304 {
00305 if ( isset( $this->$sName ) ) {
00306 $this->$sName = $sValue;
00307 } else {
00308 $this->_aConfigParams[$sName] = $sValue;
00309 }
00310 }
00311
00317 public function init()
00318 {
00319 include getShopBasePath().'config.inc.php';
00320 include getShopBasePath().'core/oxconfk.php';
00321
00322
00323 $oFileUtils = oxUtilsFile::getInstance();
00324 $this->sShopDir = $oFileUtils->normalizeDir($this->sShopDir);
00325 $this->sCompileDir = $oFileUtils->normalizeDir($this->sCompileDir);
00326 $this->sShopURL = $oFileUtils->normalizeDir($this->sShopURL);
00327 $this->sSSLShopURL = $oFileUtils->normalizeDir($this->sSSLShopURL);
00328 $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00329
00330
00331
00332 if( !$this->getConfigParam( 'sDefaultLang' ) )
00333 $this->setConfigParam( 'sDefaultLang', 0 );
00334
00335
00336 $this->setConfigParam( 'sTheme', 'basic' );
00337
00338
00339 $blLogChangesInAdmin = $this->getConfigParam( 'blLogChangesInAdmin' );
00340 if( !isset( $blLogChangesInAdmin ) )
00341 $this->setConfigParam( 'blLogChangesInAdmin', false );
00342
00343 $blCheckTemplates = $this->getConfigParam( 'blCheckTemplates' );
00344 if( !isset( $blCheckTemplates ) )
00345 $this->setConfigParam( 'blCheckTemplates', false );
00346
00347 $blAllowArticlesubclass = $this->getConfigParam( 'blAllowArticlesubclass' );
00348 if( !isset( $blAllowArticlesubclass ) )
00349 $this->setConfigParam( 'blAllowArticlesubclass', false );
00350
00351 $iAdminListSize = $this->getConfigParam( 'iAdminListSize' );
00352 if( !isset( $iAdminListSize ) )
00353 $this->setConfigParam( 'iAdminListSize', 9 );
00354
00355
00356 $iPicCount = $this->getConfigParam( 'iPicCount' );
00357 if( !isset( $iPicCount ) )
00358 $this->setConfigParam( 'iPicCount', 7 );
00359
00360 $iZoomPicCount = $this->getConfigParam( 'iZoomPicCount' );
00361 if( !isset( $iZoomPicCount ) )
00362 $this->setConfigParam( 'iZoomPicCount', 4 );
00363
00364
00365 $iMaxShopId = $this->getConfigParam( 'iMaxShopId' );
00366 if( !isset( $iMaxShopId ) )
00367 $this->setConfigParam( 'iMaxShopId', 64 );
00368
00369
00370 $this->setConfigParam( 'blTemplateCaching', false );
00371
00372
00373 global $ADODB_SESS_LIFE;
00374 $ADODB_SESS_LIFE = 1;
00375
00376
00377 $iDBCacheLifeTime = $this->getConfigParam( 'iDBCacheLifeTime' );
00378 if( !isset( $iDBCacheLifeTime ) )
00379 $this->setConfigParam( 'iDBCacheLifeTime', 3600 );
00380
00381 $sCoreDir = $this->getConfigParam( 'sShopDir' );
00382 $this->setConfigParam( 'sCoreDir', $sCoreDir.'/core/' );
00383
00384 try {
00385 $sShopID = $this->getShopId();
00386
00387
00388 $this->_loadVarsFromDb( $sShopID );
00389 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') );
00390
00391
00392
00393 $this->getSession()->start();
00394 } catch ( oxConnectionException $oEx ) {
00395 $oEx->debugOut();
00396 if ( defined( 'OXID_PHP_UNIT' ) ) {
00397 return false;
00398 } elseif ( 0 != $this->iDebug ) {
00399 oxUtils::getInstance()->showMessageAndExit( $oEx->getString() );
00400 } else {
00401 header( "HTTP/1.1 500 Internal Server Error");
00402 header( "Location: offline.html");
00403 header( "Connection: close");
00404 }
00405 } catch ( oxCookieException $oEx ) {
00406
00407
00408 $this->getSession()->start();
00409
00410
00411 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00412 oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start', true, 302 );
00413 }
00414
00415
00416
00417 $this->_oStart = new oxStart();
00418 $this->_oStart->appInit();
00419 }
00420
00426 public static function getInstance()
00427 {
00428
00429 if ( defined( 'OXID_PHP_UNIT' ) ) {
00430 if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00431 return modConfig::$unitMOD;
00432 }
00433 }
00434
00435 if ( !self::$_instance instanceof oxConfig ) {
00436
00437
00438 self::$_instance = new oxConfig();
00439 self::$_instance->init();
00440 }
00441 return self::$_instance;
00442 }
00443
00453 protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null, $sModule = '' )
00454 {
00455 $oDb = oxDb::getDb();
00456
00457 $sQ = "select oxvarname, oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '$sShopID' and oxmodule=".$oDb->quote($sModule);
00458
00459 if ( $aOnlyVars !== null ) {
00460 $blSep = false;
00461 $sIn = '';
00462 foreach ( $aOnlyVars as $sField ) {
00463 if ( $blSep ) {
00464 $sIn .= ', ';
00465 }
00466 $sIn .= '"'.$sField.'"';
00467 $blSep = true;
00468 }
00469 $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00470 }
00471
00472 $oRs = $oDb->execute( $sQ );
00473 if ( $oRs != false && $oRs->recordCount() > 0 ) {
00474 while ( !$oRs->EOF ) {
00475 $sVarName = $oRs->fields[0];
00476 $sVarType = $oRs->fields[1];
00477 $sVarVal = $oRs->fields[2];
00478
00479
00480 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00481 ( !$sVarVal || $this->isAdmin() === true ) ) {
00482 $oRs->moveNext();
00483 continue;
00484 }
00485
00486 $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
00487
00488
00489 if ( $sModule != '' ) {
00490 $this->_aThemeConfigParams[$sVarName] = $sModule;
00491 }
00492
00493 $oRs->moveNext();
00494 }
00495 }
00496 }
00497
00507 protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
00508 {
00509 switch ( $sVarType ) {
00510 case 'arr':
00511 case 'aarr':
00512 $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00513 break;
00514 case 'bool':
00515 $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00516 break;
00517 default:
00518 $this->setConfigParam( $sVarName, $sVarVal );
00519 break;
00520 }
00521 }
00522
00528 public function pageClose()
00529 {
00530 return $this->_oStart->pageClose();
00531 }
00532
00544 public static function getParameter( $sName, $blRaw = false )
00545 {
00546 if ( defined( 'OXID_PHP_UNIT' ) ) {
00547 if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00548 try{
00549 return modConfig::getParameter( $sName, $blRaw );
00550 } catch( Exception $e ) {
00551
00552 }
00553 }
00554 }
00555
00556 $sValue = null;
00557 if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_POST[$sName] ) ) {
00558 $sValue = $_POST[$sName];
00559 } elseif ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'GET' && isset( $_GET[$sName] ) ) {
00560 $sValue = $_GET[$sName];
00561 } else {
00562 $sValue = null;
00563 }
00564
00565
00566 $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00567 if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00568 self::checkSpecialChars( $sValue, $blRaw );
00569 }
00570
00571 return $sValue;
00572 }
00573
00581 public function getUploadedFile($sParamName)
00582 {
00583 return $_FILES[$sParamName];
00584 }
00585
00594 public function setGlobalParameter( $sName, $sValue )
00595 {
00596 $this->_aGlobalParams[$sName] = $sValue;
00597 }
00598
00606 public function getGlobalParameter( $sName )
00607 {
00608 if ( isset( $this->_aGlobalParams[$sName] ) ) {
00609 return $this->_aGlobalParams[$sName];
00610 } else {
00611 return null;
00612 }
00613 }
00614
00624 public static function checkSpecialChars( & $sValue, $aRaw = null )
00625 {
00626 if ( is_object( $sValue ) ) {
00627 return $sValue;
00628 }
00629
00630 if ( is_array( $sValue ) ) {
00631 $newValue = array();
00632 foreach ( $sValue as $sKey => $sVal ) {
00633 $sValidKey = $sKey;
00634 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00635 self::checkSpecialChars( $sValidKey );
00636 self::checkSpecialChars( $sVal );
00637 if ($sValidKey != $sKey) {
00638 unset ($sValue[$sKey]);
00639 }
00640 }
00641 $newValue[$sValidKey] = $sVal;
00642 }
00643 $sValue = $newValue;
00644 } else {
00645 $sValue = str_replace( array( '&', '<', '>', '"', "'", chr(0), '\\' ),
00646 array( '&', '<', '>', '"', ''', '', '\' ),
00647 $sValue );
00648 }
00649 return $sValue;
00650 }
00651
00657 public function getShopId()
00658 {
00659 if ( $this->_iShopId !== null )
00660 return $this->_iShopId;
00661
00662 $this->_iShopId = $this->getBaseShopId();
00663
00664
00665 oxSession::setVar( 'actshop', $this->_iShopId );
00666 return $this->_iShopId;
00667 }
00668
00669
00677 public function setShopId( $sShopId )
00678 {
00679 oxSession::setVar( 'actshop', $sShopId );
00680 $this->_iShopId = $sShopId;
00681 }
00682
00683
00689 public function isSsl()
00690 {
00691 if ( is_null( $this->_blIsSsl ) ) {
00692
00693 $myUtilsServer = oxUtilsServer::getInstance();
00694 $aServerVars = $myUtilsServer->getServerVar();
00695 $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00696
00697 $this->_blIsSsl = false;
00698 if (isset( $aHttpsServerVar ) && ($aHttpsServerVar === 'on' || $aHttpsServerVar == '1' )) {
00699
00700 $this->_blIsSsl = ($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
00701 if ($this->isAdmin() && !$this->_blIsSsl) {
00702 $this->_blIsSsl = $this->getConfigParam('sAdminSSLURL');
00703 }
00704 }
00705
00706
00707 if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00708 ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00709 strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00710 $this->_blIsSsl = true;
00711 }
00712 }
00713
00714 return $this->_blIsSsl;
00715 }
00716
00724 public function isCurrentUrl( $sURL )
00725 {
00726 if ( !$sURL ) {
00727 return false;
00728 }
00729
00730 $oUtilsServer = oxUtilsServer::getInstance();
00731 $sHost = $oUtilsServer->getServerVar( 'HTTP_HOST' );
00732 $sScriptName = $oUtilsServer->getServerVar( 'SCRIPT_NAME' );
00733
00734 $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $sHost . $sScriptName );
00735
00736
00737 $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00738 $sURL = str_replace( '/', '', $sURL );
00739
00740
00741 if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00742 return true;
00743 }
00744
00745 return false;
00746 }
00747
00756 public function getShopUrl( $iLang = null, $blAdmin = null )
00757 {
00758 $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00759 if ( $blAdmin ) {
00760 return $this->getConfigParam( 'sShopURL' );
00761 }
00762
00763
00764 $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00765 $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00766 if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00767 $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00768 return $aLanguageURLs[$iLang];
00769 }
00770
00771
00772 $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00773 if ( $sMallShopURL ) {
00774 $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00775 return $sMallShopURL;
00776 }
00777
00778 return $this->getConfigParam( 'sShopURL' );
00779 }
00780
00788 public function getSslShopUrl( $iLang = null )
00789 {
00790
00791 $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00792 $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00793 if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00794 $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00795 return $aLanguageSSLURLs[$iLang];
00796 }
00797
00798
00799 if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00800 $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00801 return $sMallSSLShopURL;
00802 }
00803
00804 if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00805 $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00806 return $sMallShopURL;
00807 }
00808
00809
00810 if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00811 return $sSSLShopURL;
00812 }
00813
00814 return $this->getShopUrl( $iLang );
00815 }
00816
00822 public function getCoreUtilsUrl()
00823 {
00824 return $this->getCurrentShopUrl().'core/utils/';
00825 }
00826
00835 public function getCurrentShopUrl($blAdmin = null)
00836 {
00837 if ($blAdmin===null) {
00838 $blAdmin = $this->isAdmin();
00839 }
00840 if ($blAdmin) {
00841 if ($this->isSsl()) {
00842
00843 $sUrl = $this->getConfigParam( 'sAdminSSLURL' );
00844 if ( !$sUrl ) {
00845 return $this->getSslShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00846 }
00847 return $sUrl;
00848 } else {
00849 return $this->getShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00850 }
00851 } else {
00852 return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
00853 }
00854 }
00855
00863 public function getShopCurrentUrl( $iLang = null )
00864 {
00865 if ( $this->isSsl() ) {
00866 $sURL = $this->getSSLShopURL( $iLang );
00867 } else {
00868 $sURL = $this->getShopURL( $iLang );
00869 }
00870
00871 return oxUtilsUrl::getInstance()->processUrl( $sURL.'index.php', false );
00872 }
00873
00882 public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00883 {
00884 return oxUtilsUrl::getInstance()->processUrl($this->getShopUrl( $iLang, $blAdmin).'index.php', false );
00885 }
00886
00892 public function getShopSecureHomeUrl()
00893 {
00894 return oxUtilsUrl::getInstance()->processUrl( $this->getSslShopUrl().'index.php', false );
00895 }
00896
00902 public function getShopCurrency()
00903 {
00904 $iCurr = null;
00905 if ( ( null === ( $iCurr = oxConfig::getParameter( 'cur' ) ) ) ) {
00906 if ( null === ( $iCurr = oxConfig::getParameter( 'currency' ) ) ) {
00907 $iCurr = oxSession::getVar( 'currency' );
00908 }
00909 }
00910 return (int) $iCurr;
00911 }
00912
00918 public function getActShopCurrencyObject()
00919 {
00920
00921
00922 if ( !defined( 'OXID_PHP_UNIT' ) ) {
00923 if (!is_null($this->_oActCurrencyObject)) {
00924 return $this->_oActCurrencyObject;
00925 }
00926 }
00927
00928 $iCur = $this->getShopCurrency();
00929 $aCurrencies = $this->getCurrencyArray();
00930 if ( !isset( $aCurrencies[$iCur] ) ) {
00931 return $this->_oActCurrencyObject = reset( $aCurrencies );
00932 }
00933
00934 return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00935 }
00936
00944 public function setActShopCurrency( $iCur )
00945 {
00946 $aCurrencies = $this->getCurrencyArray();
00947 if ( isset( $aCurrencies[$iCur] ) ) {
00948 oxSession::setVar( 'currency', $iCur );
00949 $this->_oActCurrencyObject = null;
00950 }
00951 }
00952
00960 public function getOutDir( $blAbsolute = true)
00961 {
00962 if ($blAbsolute) {
00963 return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
00964 } else {
00965 return $this->_sOutDir.'/';
00966 }
00967 }
00968
00978 public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
00979 {
00980 $blSSL = is_null($blSSL)?$this->isSsl():$blSSL;
00981 $blAdmin = is_null($blAdmin)?$this->isAdmin():$blAdmin;
00982
00983 if ( $blSSL ) {
00984 if ($blNativeImg && !$blAdmin) {
00985 $sUrl = $this->getSslShopUrl();
00986 } else {
00987 $sUrl = $this->getConfigParam('sSSLShopURL');
00988 if (!$sUrl && $blAdmin) {
00989 $sUrl = $this->getConfigParam('sAdminSSLURL').'../';
00990 }
00991 }
00992 } else {
00993 $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
00994 }
00995
00996 return $sUrl.$this->_sOutDir.'/';
00997 }
00998
01013 public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false )
01014 {
01015 if ( is_null($sTheme) ) {
01016 $sTheme = $this->getConfigParam( 'sTheme' );
01017 }
01018
01019 if ( $blAdmin ) {
01020 $sTheme = 'admin';
01021 }
01022
01023 $sBase = $this->getOutDir( $blAbsolute );
01024 $sAbsBase = $this->getOutDir();
01025
01026 $sLang = '-';
01027
01028 if ( $iLang !== false ) {
01029 $oLang = oxLang::getInstance();
01030
01031 if ( is_null( $iLang ) ) {
01032 $iLang = $oLang->getEditLanguage();
01033 }
01034
01035 $sLang = $oLang->getLanguageAbbr( $iLang );
01036 }
01037
01038 if ( is_null($iShop) ) {
01039 $iShop = $this->getShopId();
01040 }
01041
01042
01043 $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01044 $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01045
01046 if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01047 return $sReturn;
01048 }
01049
01050 $sReturn = false;
01051
01052
01053 $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
01054 if ( !$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01055 $sReturn = $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute );
01056 }
01057
01058
01059 if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01060 $sReturn = $sBase . $sPath;
01061 }
01062
01063
01064 $sPath = "$sTheme/$iShop/$sDir/$sFile";
01065 if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01066 $sReturn = $sBase . $sPath;
01067 }
01068
01069
01070
01071 $sPath = "$sTheme/$sLang/$sDir/$sFile";
01072 if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01073 $sReturn = $sBase . $sPath;
01074 }
01075
01076
01077 $sPath = "$sTheme/$sDir/$sFile";
01078 if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01079 $sReturn = $sBase . $sPath;
01080 }
01081
01082
01083 $sPath = "$sLang/$sDir/$sFile";
01084 if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01085 $sReturn = $sBase . $sPath;
01086 }
01087
01088
01089 $sPath = "$sDir/$sFile";
01090 if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01091 $sReturn = $sBase . $sPath;
01092 }
01093
01094 if ( !$sReturn ) {
01095
01096 }
01097
01098
01099 oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01100
01101 return $sReturn;
01102 }
01103
01118 public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01119 {
01120 $sUrl = str_replace(
01121 $this->getOutDir(),
01122 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01123 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01124 );
01125 return $sUrl;
01126 }
01127
01136 public function getImagePath( $sFile, $blAdmin = false )
01137 {
01138 return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01139 }
01140
01151 public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null )
01152 {
01153 $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01154 return $this->getUrl( $sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01155 }
01156
01164 public function getImageDir( $blAdmin = false )
01165 {
01166 return $this->getDir( null, $this->_sImageDir, $blAdmin );
01167 }
01168
01180 public function getPicturePath($sFile, $blAdmin = false, $iLang = null , $iShop = null , $sTheme = null)
01181 {
01182 return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme );
01183 }
01184
01192 public function getMasterPictureDir( $blAdmin = false )
01193 {
01194 return $this->getDir( null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01195 }
01196
01205 public function getMasterPicturePath( $sFile, $blAdmin = false )
01206 {
01207 return $this->getDir( $sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01208 }
01209
01222 public function getPictureUrl( $sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01223 {
01224 if (!isset($blSSL)) {
01225 $blSSL = $this->isSsl();
01226 }
01227 if ( $sAltUrl = $this->getConfigParam( 'sAltImageDir' ) ) {
01228
01229 if ( $this->isSsl() && $blSSL && $sSslAltUrl = $this->getConfigParam( 'sSSLAltImageDir' ) ) {
01230 $sAltUrl = $sSslAltUrl;
01231 }
01232
01233 if ( !is_null( $sFile ) ) {
01234 $sAltUrl .= $sFile;
01235 }
01236
01237 return $sAltUrl;
01238 }
01239
01240 $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01241
01242 $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01243
01244
01245
01246 if ( !$sUrl && $sDefPic ) {
01247 $sUrl = $this->getUrl( $sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01248 }
01249 return $sUrl;
01250 }
01251
01266 public function getIconUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01267 {
01268 return $this->getPictureUrl( $sFile, $blAdmin, $blSSL, $iLang, $iShopId, $sDefPic );
01269 }
01270
01278 public function getPictureDir( $blAdmin )
01279 {
01280 return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01281 }
01282
01291 public function getTemplatePath( $sFile, $blAdmin )
01292 {
01293 return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01294 }
01295
01303 public function getTemplateDir( $blAdmin = false )
01304 {
01305 return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01306 }
01307
01318 public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01319 {
01320 return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01321 }
01322
01330 public function getTemplateBase( $blAdmin = false )
01331 {
01332
01333 return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01334 }
01335
01344 public function getResourcePath($sFile = '', $blAdmin = false )
01345 {
01346 return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01347 }
01348
01359 public function getResourceUrl( $sFile = '', $blAdmin = false , $blSSL = null , $iLang = null )
01360 {
01361 $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01362 return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang );
01363 }
01364
01372 public function getResourceDir( $blAdmin )
01373 {
01374 return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01375 }
01376
01390 public function getLanguagePath( $sFile, $blAdmin, $iLang = null, $iShop = null, $sTheme = null )
01391 {
01392 return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang, $iShop, $sTheme );
01393 }
01394
01406 public function getStdLanguagePath( $sFile, $blAdmin, $iLang = null )
01407 {
01408 $sDir = null;
01409 if ( $iLang !== false ) {
01410 $sDir = oxLang::getInstance()->getLanguageAbbr( $iLang );
01411 }
01412
01413 return $this->getDir( $sFile, $sDir, $blAdmin, $iLang, null, $this->getConfigParam( "sTheme" ), true, true );
01414 }
01415
01423 public function getLanguageDir( $blAdmin )
01424 {
01425 return $this->getDir( null, null, $blAdmin );
01426 }
01427
01435 public function getCurrencyArray( $iCurrency = null )
01436 {
01437 $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01438 if ( !is_array( $aConfCurrencies ) ) {
01439 return array();
01440 }
01441
01442 if ( defined( 'OXID_PHP_UNIT' ) ) {
01443 if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01444 try{
01445 $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01446 if ( isset( $aAltCurrencies ) ) {
01447 $aConfCurrencies = $aAltCurrencies;
01448 }
01449 } catch( Exception $e ) {
01450
01451 }
01452 }
01453 }
01454
01455
01456 $aCurrencies = array();
01457 reset( $aConfCurrencies );
01458 while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01459 if ( $val ) {
01460 $oCur = new oxStdClass();
01461 $oCur->id = $key;
01462 $sCur = explode( '@', $val);
01463 $oCur->name = trim( $sCur[0] );
01464 $oCur->rate = trim( $sCur[1] );
01465 $oCur->dec = trim( $sCur[2] );
01466 $oCur->thousand = trim( $sCur[3] );
01467 $oCur->sign = trim( $sCur[4] );
01468 $oCur->decimal = trim( $sCur[5] );
01469
01470
01471 if ( isset( $sCur[6] ) ) {
01472 $oCur->side = trim($sCur[6]);
01473 }
01474
01475 if ( isset( $iCurrency) && $key == $iCurrency ) {
01476 $oCur->selected = 1;
01477 } else {
01478 $oCur->selected = 0;
01479 }
01480 $aCurrencies[$key]= $oCur;
01481 }
01482
01483
01484 if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01485 break;
01486 }
01487 }
01488 return $aCurrencies;
01489 }
01490
01498 public function getCurrencyObject( $sName )
01499 {
01500 $aSearch = $this->getCurrencyArray();
01501 foreach ( $aSearch as $oCur ) {
01502 if ( $oCur->name == $sName ) {
01503 return $oCur;
01504 }
01505 }
01506 }
01507
01513 public function isDemoShop()
01514 {
01515 return $this->getConfigParam('blDemoShop');
01516 }
01517
01523 public function getEdition()
01524 {
01525 return "CE";
01526
01527
01528 }
01529
01535 public function getFullEdition()
01536 {
01537 $sEdition = $this->getEdition();
01538
01539 if ($sEdition == "CE") {
01540 return "Community Edition";
01541 }
01542
01543
01544
01545 return $sEdition;
01546 }
01547
01553 public function getVersion()
01554 {
01555 $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01556 return $sVersion;
01557 }
01558
01564 public function getRevision()
01565 {
01566 try {
01567 $sFileName = getShopBasePath() . "/pkg.rev";
01568 $iRev = (int) trim(@file_get_contents($sFileName));
01569 } catch (Exception $e) {
01570 return false;
01571 }
01572
01573 if (!$iRev) {
01574 return false;
01575 }
01576
01577 return $iRev;
01578 }
01579
01580
01586 public function isMall()
01587 {
01588
01589 return false;
01590 }
01591
01601 public function detectVersion()
01602 {
01603 }
01604
01605
01606
01619 public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '' )
01620 {
01621 switch ( $sVarType ) {
01622 case 'arr':
01623 case 'aarr':
01624 if (is_array($sVarVal)) {
01625 $sValue = serialize( $sVarVal );
01626 } else {
01627
01628 $sValue = $sVarVal ;
01629 $sVarVal = unserialize( $sVarVal );
01630 }
01631 break;
01632 case 'bool':
01633
01634 $sVarVal = (( $sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
01635
01636 $sValue = $sVarVal?"1":"";
01637 break;
01638 default:
01639 $sValue = $sVarVal;
01640 break;
01641 }
01642
01643 if ( !$sShopId ) {
01644 $sShopId = $this->getShopId();
01645 }
01646
01647
01648 if ($sShopId == $this->getShopId()) {
01649 $this->setConfigParam( $sVarName, $sVarVal );
01650 }
01651
01652 $oDb = oxDb::getDb(true);
01653
01654 $sShopIdQuoted = $oDb->quote($sShopId);
01655 $sModuleQuoted = $oDb->quote($sModule);
01656 $sVarNameQuoted = $oDb->quote($sVarName);
01657 $sVarTypeQuoted = $oDb->quote($sVarType);
01658 $sVarValueQuoted = $oDb->quote($sValue);
01659 $sConfigKeyQuoted = $oDb->quote($this->getConfigParam('sConfigKey'));
01660 $sNewOXIDdQuoted = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
01661
01662 $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
01663 $oDb->execute( $sQ );
01664
01665 $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
01666 values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
01667
01668 $oDb->execute( $sQ );
01669 }
01670
01679 public function getShopConfVar( $sVarName, $sShopId = null )
01680 {
01681 if ( !$sShopId ) {
01682 $sShopId = $this->getShopId();
01683 }
01684
01685 $oDb = oxDb::getDb(true);
01686 $sQ = "select oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '$sShopId' and oxvarname = ".$oDb->quote($sVarName);
01687 $oRs = $oDb->Execute( $sQ );
01688
01689 $sValue = null;
01690 if ( $oRs != false && $oRs->recordCount() > 0 ) {
01691 $sValue = $this->decodeValue( $oRs->fields['oxvartype'], $oRs->fields['oxvarvalue'] );
01692 }
01693 return $sValue;
01694 }
01695
01704 public function decodeValue( $sType, $mOrigValue )
01705 {
01706 $sValue = $mOrigValue;
01707 switch ( $sType ) {
01708 case 'arr':
01709 case 'aarr':
01710 $sValue = unserialize( $mOrigValue );
01711 break;
01712 case 'bool':
01713 $sValue = ( $mOrigValue == 'true' || $mOrigValue == '1' );
01714 break;
01715 }
01716
01717 return $sValue;
01718 }
01719
01727 public function getDecodeValueQuery( $sFieldName = "oxvarvalue" )
01728 {
01729 return " DECODE( {$sFieldName}, '".$this->getConfigParam( 'sConfigKey' )."') ";
01730 }
01731
01737 public function isProductiveMode()
01738 {
01739 $blProductive = false;
01740
01741 $blProductive = $this->getConfigParam( 'blProductive' );
01742 if ( !isset( $blProductive ) ) {
01743 $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01744 $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01745 $this->setConfigParam( 'blProductive', $blProductive );
01746 }
01747
01748 return $blProductive;
01749 }
01750
01751
01752
01758 public function getBaseShopId()
01759 {
01760
01761 return 'oxbaseshop';
01762 }
01763
01769 public function getActiveShop()
01770 {
01771 if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01772 $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01773 return $this->_oActShop;
01774 }
01775
01776 $this->_oActShop = oxNew( 'oxshop' );
01777 $this->_oActShop->load( $this->getShopId() );
01778 return $this->_oActShop;
01779 }
01780
01786 public function getActiveView()
01787 {
01788 if ( $this->_oActView != null ) {
01789 return $this->_oActView;
01790 }
01791
01792 $this->_oActView = oxNew( 'oxubase' );
01793 return $this->_oActView;
01794 }
01795
01803 public function setActiveView( $oView )
01804 {
01805 $this->_oActView = $oView;
01806 }
01807
01813 public function isUtf()
01814 {
01815 return ( bool ) $this->getConfigParam( 'iUtfMode' );
01816 }
01817
01823 public function getLogsDir()
01824 {
01825 return $this->getConfigParam( 'sShopDir' ).'log/';
01826 }
01827
01835 public function isThemeOption( $sName )
01836 {
01837 return (bool) isset( $this->_aThemeConfigParams[$sName] );
01838 }
01839
01840 }