oxconfig.php

Go to the documentation of this file.
00001 <?php
00002 
00003 define( 'MAX_64BIT_INTEGER', '18446744073709551615' );
00004 
00009 class oxConfig extends oxSuperCfg
00010 {
00011     // this column of params are defined in config.inc.php file,
00012     // so for backwards compat. names starts without underscore
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     //protected $iMaxArticles = 6000;
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 ( defined( 'OXID_PHP_UNIT' ) ) {
00289             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00290                 $sValue = modConfig::$unitMOD->getModConfigParam( $sName );
00291                 if ( $sValue !== null ) {
00292                     return $sValue;
00293                 }
00294             }
00295         }
00296 
00297         if ( isset( $this->$sName ) ) {
00298             return $this->$sName;
00299         } elseif ( isset ( $this->_aConfigParams[$sName] ) ) {
00300             return $this->_aConfigParams[$sName];
00301         }
00302     }
00303 
00312     public function setConfigParam( $sName, $sValue )
00313     {
00314         if ( isset( $this->$sName ) ) {
00315             $this->$sName = $sValue;
00316         } else {
00317             $this->_aConfigParams[$sName] = $sValue;
00318         }
00319     }
00320 
00326     public function init()
00327     {
00328         include getShopBasePath().'config.inc.php';
00329         include getShopBasePath().'core/oxconfk.php';
00330 
00331         //adding trailing slashes
00332         $oFileUtils = oxUtilsFile::getInstance();
00333         $this->sShopDir     = $oFileUtils->normalizeDir($this->sShopDir);
00334         $this->sCompileDir  = $oFileUtils->normalizeDir($this->sCompileDir);
00335         $this->sShopURL     = $oFileUtils->normalizeDir($this->sShopURL);
00336         $this->sSSLShopURL  = $oFileUtils->normalizeDir($this->sSSLShopURL);
00337         $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00338 
00339 
00340         // some important defaults
00341         if( !$this->getConfigParam( 'sDefaultLang' ) )
00342             $this->setConfigParam( 'sDefaultLang', 0 );
00343 
00344 
00345         $this->setConfigParam( 'sTheme', 'basic' );
00346 
00347 
00348         $blLogChangesInAdmin = $this->getConfigParam( 'blLogChangesInAdmin' );
00349         if( !isset( $blLogChangesInAdmin ) )
00350             $this->setConfigParam( 'blLogChangesInAdmin', false );
00351 
00352         $blCheckTemplates = $this->getConfigParam( 'blCheckTemplates' );
00353         if( !isset( $blCheckTemplates ) )
00354             $this->setConfigParam( 'blCheckTemplates', false );
00355 
00356         $blAllowArticlesubclass = $this->getConfigParam( 'blAllowArticlesubclass' );
00357         if( !isset( $blAllowArticlesubclass ) )
00358             $this->setConfigParam( 'blAllowArticlesubclass', false );
00359 
00360         $iAdminListSize = $this->getConfigParam( 'iAdminListSize' );
00361         if( !isset( $iAdminListSize ) )
00362             $this->setConfigParam( 'iAdminListSize', 9 );
00363 
00364         // #1173M  for EE - not all pic are deleted
00365         $iPicCount = $this->getConfigParam( 'iPicCount' );
00366         if( !isset( $iPicCount ) )
00367             $this->setConfigParam( 'iPicCount', 7 );
00368 
00369         $iZoomPicCount = $this->getConfigParam( 'iZoomPicCount' );
00370         if( !isset( $iZoomPicCount ) )
00371             $this->setConfigParam( 'iZoomPicCount', 4 );
00372 
00373         //max shop id default value
00374         $iMaxShopId = $this->getConfigParam( 'iMaxShopId' );
00375         if( !isset( $iMaxShopId ) )
00376             $this->setConfigParam( 'iMaxShopId', 64 );
00377 
00378         // disabling caching according to DODGER #655 : disable Caching as it doesnt work good enought
00379         $this->setConfigParam( 'blTemplateCaching', false );
00380 
00381         //setting ADODB timeout
00382         global  $ADODB_SESS_LIFE;
00383         $ADODB_SESS_LIFE  = 1;
00384 
00385         // ADODB cachelifetime
00386         $iDBCacheLifeTime = $this->getConfigParam( 'iDBCacheLifeTime' );
00387         if( !isset( $iDBCacheLifeTime ) )
00388             $this->setConfigParam( 'iDBCacheLifeTime', 3600 ); // 1 hour
00389 
00390         $sCoreDir = $this->getConfigParam( 'sShopDir' );
00391         $this->setConfigParam( 'sCoreDir', $sCoreDir.'/core/' );
00392 
00393         try {
00394             $sShopID = $this->getShopId();
00395 
00396             // load now
00397             $this->_loadVarsFromDb( $sShopID );
00398             
00399             // loading theme config options
00400             $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') );
00401 
00402             // checking if custom theme (which has defined parent theme) config options should be loaded over parent theme (#3362)
00403             if ( $this->getConfigParam('sCustomTheme') ) {
00404                 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme') );
00405             }
00406 
00407 
00408             //starting up the session
00409             $this->getSession()->start();
00410         } catch ( oxConnectionException $oEx ) {
00411             $oEx->debugOut();
00412             if ( defined( 'OXID_PHP_UNIT' ) ) {
00413                 return false;
00414             } elseif ( 0 != $this->iDebug ) {
00415                 oxUtils::getInstance()->showMessageAndExit( $oEx->getString() );
00416             } else {
00417                 header( "HTTP/1.1 500 Internal Server Error");
00418                 header( "Location: offline.html");
00419                 header( "Connection: close");
00420             }
00421         } catch ( oxCookieException $oEx ) {
00422 
00423             //starting up the session
00424             $this->getSession()->start();
00425 
00426             // redirect to start page and display the error
00427             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00428             oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start', true, 302 );
00429         }
00430 
00431 
00432         //application initialization
00433         $this->_oStart = new oxStart();
00434         $this->_oStart->appInit();
00435     }
00436 
00442     public static function getInstance()
00443     {
00444 
00445         if ( defined( 'OXID_PHP_UNIT' ) ) {
00446             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00447                 return modConfig::$unitMOD;
00448             }
00449         }
00450 
00451         if ( !self::$_instance instanceof oxConfig ) {
00452                 //exceptions from here go directly to global exception handler
00453                 //if no init is possible whole application has to die!
00454                 self::$_instance = new oxConfig();
00455                 self::$_instance->init();
00456         }
00457         return self::$_instance;
00458     }
00459 
00469     protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null, $sModule = '' )
00470     {
00471         $oDb = oxDb::getDb();
00472 
00473         $sQ = "select oxvarname, oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '$sShopID' and oxmodule=".$oDb->quote($sModule);
00474         // dodger, allow loading from some vars only from baseshop
00475         if ( $aOnlyVars !== null ) {
00476             $blSep = false;
00477             $sIn  = '';
00478             foreach ( $aOnlyVars as $sField ) {
00479                 if ( $blSep ) {
00480                     $sIn .= ', ';
00481                 }
00482                 $sIn .= '"'.$sField.'"';
00483                 $blSep = true;
00484             }
00485             $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00486         }
00487 
00488         $oRs = $oDb->execute( $sQ );
00489         if ( $oRs != false && $oRs->recordCount() > 0 ) {
00490             while ( !$oRs->EOF ) {
00491                 $sVarName = $oRs->fields[0];
00492                 $sVarType = $oRs->fields[1];
00493                 $sVarVal  = $oRs->fields[2];
00494 
00495                 //in sShopURL and sSSLShopURL cases we skip (for admin or when URL values are not set)
00496                 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00497                     ( !$sVarVal || $this->isAdmin() === true ) ) {
00498                     $oRs->moveNext();
00499                     continue;
00500                 }
00501 
00502                 $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
00503 
00504                 //setting theme options array
00505                 if ( $sModule != '' ) {
00506                     $this->_aThemeConfigParams[$sVarName] = $sModule;
00507                 }
00508 
00509                 $oRs->moveNext();
00510             }
00511         }
00512     }
00513 
00523     protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
00524     {
00525         switch ( $sVarType ) {
00526             case 'arr':
00527             case 'aarr':
00528                 $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00529                 break;
00530             case 'bool':
00531                 $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00532                 break;
00533             default:
00534                 $this->setConfigParam( $sVarName, $sVarVal );
00535                 break;
00536         }
00537     }
00538 
00544     public function pageClose()
00545     {
00546         return $this->_oStart->pageClose();
00547     }
00548 
00560     public static function getParameter(  $sName, $blRaw = false )
00561     {
00562         if ( defined( 'OXID_PHP_UNIT' ) ) {
00563             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00564                 try{
00565                     return modConfig::getParameter(  $sName, $blRaw );
00566                 } catch( Exception $e ) {
00567                     // if exception is thrown, use default
00568                 }
00569             }
00570         }
00571 
00572         $sValue = null;
00573 
00574         if ( isset( $_POST[$sName] ) ) {
00575             $sValue = $_POST[$sName];
00576         } elseif ( isset( $_GET[$sName] ) ) {
00577             $sValue = $_GET[$sName];
00578         }
00579 
00580         // TODO: remove this after special charts concept implementation
00581         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00582         if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00583             self::checkSpecialChars( $sValue, $blRaw );
00584         }
00585 
00586         return $sValue;
00587     }
00588 
00596     public function getUploadedFile($sParamName)
00597     {
00598         return $_FILES[$sParamName];
00599     }
00600 
00609     public function setGlobalParameter( $sName, $sValue )
00610     {
00611         $this->_aGlobalParams[$sName] = $sValue;
00612     }
00613 
00621     public function getGlobalParameter( $sName )
00622     {
00623         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00624             return $this->_aGlobalParams[$sName];
00625         } else {
00626             return null;
00627         }
00628     }
00629 
00639     public static function checkSpecialChars( & $sValue, $aRaw = null )
00640     {
00641         if ( is_object( $sValue ) ) {
00642             return $sValue;
00643         }
00644 
00645         if ( is_array( $sValue ) ) {
00646             $newValue = array();
00647             foreach ( $sValue as $sKey => $sVal ) {
00648                 $sValidKey = $sKey;
00649                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00650                     self::checkSpecialChars( $sValidKey );
00651                     self::checkSpecialChars( $sVal );
00652                     if ($sValidKey != $sKey) {
00653                         unset ($sValue[$sKey]);
00654                     }
00655                 }
00656                 $newValue[$sValidKey] = $sVal;
00657             }
00658             $sValue = $newValue;
00659         } else {
00660             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00661                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00662                                    $sValue );
00663         }
00664         return $sValue;
00665     }
00666 
00672     public function getShopId()
00673     {
00674         if ( $this->_iShopId !== null )
00675             return $this->_iShopId;
00676 
00677             $this->_iShopId = $this->getBaseShopId();
00678 
00679 
00680         oxSession::setVar( 'actshop', $this->_iShopId );
00681         return $this->_iShopId;
00682     }
00683 
00684 
00692     public function setShopId( $sShopId )
00693     {
00694         oxSession::setVar( 'actshop', $sShopId );
00695         $this->_iShopId = $sShopId;
00696     }
00697 
00698 
00704     public function isSsl()
00705     {
00706         if ( is_null( $this->_blIsSsl ) ) {
00707 
00708             $myUtilsServer   = oxUtilsServer::getInstance();
00709             $aServerVars     = $myUtilsServer->getServerVar();
00710             $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00711 
00712             $this->_blIsSsl = false;
00713             if (isset( $aHttpsServerVar ) && ($aHttpsServerVar === 'on' || $aHttpsServerVar == '1' )) {
00714                 // "1&1" hoster provides "1"
00715                 $this->_blIsSsl = ($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
00716                 if ($this->isAdmin() && !$this->_blIsSsl) {
00717                     $this->_blIsSsl = $this->getConfigParam('sAdminSSLURL');
00718                 }
00719             }
00720 
00721             //additional special handling for profihost customers
00722             if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00723                  ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00724                  strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00725                 $this->_blIsSsl = true;
00726             }
00727         }
00728 
00729         return $this->_blIsSsl;
00730     }
00731 
00739     public function isCurrentUrl( $sURL )
00740     {
00741         if ( !$sURL ) {
00742             return false;
00743         }
00744 
00745         $oUtilsServer = oxUtilsServer::getInstance();
00746 
00747         preg_match("/^(http:\/\/)?([^\/]+)/i", $sURL, $matches);
00748         $sUrlHost = $matches[2];
00749 
00750         preg_match("/^(http:\/\/)?([^\/]+)/i", $oUtilsServer->getServerVar( 'HTTP_HOST' ), $matches);
00751         $sRealHost = $matches[2];
00752 
00753         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $oUtilsServer->getServerVar( 'HTTP_HOST' ) . $oUtilsServer->getServerVar( 'SCRIPT_NAME' ) );
00754 
00755         //remove double slashes all the way
00756         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00757         $sURL = str_replace( '/', '', $sURL );
00758 
00759         if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00760 
00761             //bug fix #0002991
00762             if ( $sUrlHost == $sRealHost ) {
00763                 return true;
00764             }
00765         }
00766 
00767         return false;
00768     }
00769 
00778     public function getShopUrl( $iLang = null, $blAdmin = null )
00779     {
00780         $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00781         if ( $blAdmin ) {
00782             return $this->getConfigParam( 'sShopURL' );
00783         }
00784 
00785         // #680 per language another URL
00786         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00787         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00788         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00789             $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00790             return $aLanguageURLs[$iLang];
00791         }
00792 
00793         //normal section
00794         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00795         if ( $sMallShopURL ) {
00796             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00797             return $sMallShopURL;
00798         }
00799 
00800         return $this->getConfigParam( 'sShopURL' );
00801     }
00802 
00810     public function getSslShopUrl( $iLang = null )
00811     {
00812         // #680 per language another URL
00813         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00814         $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00815         if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00816             $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00817             return $aLanguageSSLURLs[$iLang];
00818         }
00819 
00820         //mall mode
00821         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00822             $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00823             return $sMallSSLShopURL;
00824         }
00825 
00826         if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00827             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00828             return $sMallShopURL;
00829         }
00830 
00831         //normal section
00832         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00833             return $sSSLShopURL;
00834         }
00835 
00836         return $this->getShopUrl( $iLang );
00837     }
00838 
00844     public function getCoreUtilsUrl()
00845     {
00846         return $this->getCurrentShopUrl().'core/utils/';
00847     }
00848 
00857     public function getCurrentShopUrl($blAdmin = null)
00858     {
00859         if ($blAdmin===null) {
00860             $blAdmin = $this->isAdmin();
00861         }
00862         if ($blAdmin) {
00863             if ($this->isSsl()) {
00864 
00865                 $sUrl = $this->getConfigParam( 'sAdminSSLURL' );
00866                 if ( !$sUrl ) {
00867                     return $this->getSslShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00868                 }
00869                 return $sUrl;
00870             } else {
00871                 return $this->getShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00872             }
00873         } else {
00874             return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
00875         }
00876     }
00877 
00885     public function getShopCurrentUrl( $iLang = null )
00886     {
00887         if ( $this->isSsl() ) {
00888             $sURL = $this->getSSLShopURL( $iLang );
00889         } else {
00890             $sURL = $this->getShopURL( $iLang );
00891         }
00892 
00893         return oxUtilsUrl::getInstance()->processUrl( $sURL.'index.php', false );
00894     }
00895 
00904     public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00905     {
00906         return oxUtilsUrl::getInstance()->processUrl($this->getShopUrl( $iLang, $blAdmin).'index.php', false );
00907     }
00908 
00914     public function getShopSecureHomeUrl()
00915     {
00916         return  oxUtilsUrl::getInstance()->processUrl( $this->getSslShopUrl().'index.php', false );
00917     }
00918 
00924     public function getShopCurrency()
00925     {
00926         $iCurr = null;
00927         if ( ( null === ( $iCurr = oxConfig::getParameter( 'cur' ) ) ) ) {
00928             if ( null === ( $iCurr = oxConfig::getParameter( 'currency' ) ) ) {
00929                 $iCurr = oxSession::getVar( 'currency' );
00930             }
00931         }
00932         return (int) $iCurr;
00933     }
00934 
00940     public function getActShopCurrencyObject()
00941     {
00942         //caching currency as it does not change through the script
00943         //but not for unit tests as ther it changes always
00944         if ( !defined( 'OXID_PHP_UNIT' ) ) {
00945             if (!is_null($this->_oActCurrencyObject)) {
00946                 return $this->_oActCurrencyObject;
00947             }
00948         }
00949 
00950         $iCur = $this->getShopCurrency();
00951         $aCurrencies = $this->getCurrencyArray();
00952         if ( !isset( $aCurrencies[$iCur] ) ) {
00953             return $this->_oActCurrencyObject = reset( $aCurrencies ); // reset() returns the first element
00954         }
00955 
00956         return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00957     }
00958 
00966     public function setActShopCurrency( $iCur )
00967     {
00968         $aCurrencies = $this->getCurrencyArray();
00969         if ( isset( $aCurrencies[$iCur] ) ) {
00970             oxSession::setVar( 'currency', $iCur );
00971             $this->_oActCurrencyObject = null;
00972         }
00973     }
00974 
00982     public function getOutDir( $blAbsolute = true)
00983     {
00984         if ($blAbsolute) {
00985             return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
00986         } else {
00987             return $this->_sOutDir.'/';
00988         }
00989     }
00990 
01000     public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
01001     {
01002         $blSSL    = is_null($blSSL)?$this->isSsl():$blSSL;
01003         $blAdmin  = is_null($blAdmin)?$this->isAdmin():$blAdmin;
01004 
01005         if ( $blSSL ) {
01006             if ($blNativeImg && !$blAdmin) {
01007                 $sUrl = $this->getSslShopUrl();
01008             } else {
01009                 $sUrl = $this->getConfigParam('sSSLShopURL');
01010                 if (!$sUrl && $blAdmin) {
01011                     $sUrl = $this->getConfigParam('sAdminSSLURL').'../';
01012                 }
01013             }
01014         } else {
01015             $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
01016         }
01017 
01018         return $sUrl.$this->_sOutDir.'/';
01019     }
01020 
01035     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false )
01036     {
01037         if ( is_null($sTheme) ) {
01038             $sTheme = $this->getConfigParam( 'sTheme' );
01039         }
01040 
01041         if ( $blAdmin ) {
01042             $sTheme = 'admin';
01043         }
01044 
01045         $sBase    = $this->getOutDir( $blAbsolute );
01046         $sAbsBase = $this->getOutDir();
01047 
01048         $sLang = '-';
01049         // FALSE means skip language folder check
01050         if ( $iLang !== false ) {
01051             $oLang = oxLang::getInstance();
01052 
01053             if ( is_null( $iLang ) ) {
01054                 $iLang = $oLang->getEditLanguage();
01055             }
01056 
01057             $sLang = $oLang->getLanguageAbbr( $iLang );
01058         }
01059 
01060         if ( is_null($iShop) ) {
01061             $iShop = $this->getShopId();
01062         }
01063 
01064         //Load from
01065         $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01066         $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01067 
01068         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01069             return $sReturn;
01070         }
01071 
01072         $sReturn = false;
01073 
01074         // Check for custom template
01075         $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
01076         if ( !$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01077             $sReturn = $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute );
01078         }
01079 
01080         //test lang level ..
01081         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01082             $sReturn = $sBase . $sPath;
01083         }
01084 
01085         //test shop level ..
01086         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01087         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01088             $sReturn = $sBase . $sPath;
01089         }
01090 
01091 
01092         //test theme language level ..
01093         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01094         if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01095             $sReturn = $sBase . $sPath;
01096         }
01097 
01098         //test theme level ..
01099         $sPath = "$sTheme/$sDir/$sFile";
01100         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01101             $sReturn = $sBase . $sPath;
01102         }
01103 
01104         //test out language level ..
01105         $sPath = "$sLang/$sDir/$sFile";
01106         if ( !$sReturn &&  $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01107             $sReturn = $sBase . $sPath;
01108         }
01109 
01110         //test out level ..
01111         $sPath = "$sDir/$sFile";
01112         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01113             $sReturn = $sBase . $sPath;
01114         }
01115 
01116         if ( !$sReturn ) {
01117             // TODO: implement logic to log missing paths
01118         }
01119 
01120         // to cache
01121         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01122 
01123         return $sReturn;
01124     }
01125 
01140     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01141     {
01142         $sUrl = str_replace(
01143                                 $this->getOutDir(),
01144                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01145                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01146                             );
01147         return $sUrl;
01148     }
01149 
01158     public function getImagePath( $sFile, $blAdmin = false )
01159     {
01160         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01161     }
01162 
01173     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null )
01174     {
01175         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01176         return $this->getUrl( $sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01177     }
01178 
01186     public function getImageDir( $blAdmin = false )
01187     {
01188         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01189     }
01190 
01202     public function getPicturePath($sFile, $blAdmin = false, $iLang = null , $iShop = null , $sTheme = null)
01203     {
01204         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme );
01205     }
01206 
01214     public function getMasterPictureDir( $blAdmin = false )
01215     {
01216         return $this->getDir( null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01217     }
01218 
01227     public function getMasterPicturePath( $sFile, $blAdmin = false )
01228     {
01229         return $this->getDir( $sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01230     }
01231 
01244     public function getPictureUrl( $sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01245     {
01246         if ( $sAltUrl = oxPictureHandler::getInstance()->getAltImageUrl('/', $sFile, $blSSL) ) {
01247             return $sAltUrl;
01248         }
01249 
01250         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01251         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01252 
01253         //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01254         if ( !$sUrl && $sDefPic ) {
01255             $sUrl = $this->getUrl( $sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01256         }
01257         return $sUrl;
01258     }
01259 
01274     public function getIconUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01275     {
01276         return $this->getPictureUrl( $sFile, $blAdmin, $blSSL, $iLang, $iShopId, $sDefPic );
01277     }
01278 
01286     public function getPictureDir( $blAdmin )
01287     {
01288         return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01289     }
01290 
01299     public function getTemplatePath( $sFile, $blAdmin )
01300     {
01301         return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01302     }
01303 
01311     public function getTemplateDir( $blAdmin = false )
01312     {
01313         return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01314     }
01315 
01326     public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01327     {
01328         return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01329     }
01330 
01338     public function getTemplateBase( $blAdmin = false )
01339     {
01340         // Base template dir is the parent dir of template dir
01341         return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01342     }
01343 
01352     public function getResourcePath($sFile = '', $blAdmin = false )
01353     {
01354         return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01355     }
01356 
01367     public function getResourceUrl( $sFile = '', $blAdmin = false , $blSSL = null , $iLang = null )
01368     {
01369         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01370         return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang );
01371     }
01372 
01380     public function getResourceDir( $blAdmin )
01381     {
01382         return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01383     }
01384 
01398     public function getLanguagePath( $sFile, $blAdmin, $iLang = null, $iShop = null, $sTheme = null )
01399     {
01400         return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang, $iShop, $sTheme );
01401     }
01402 
01414     public function getStdLanguagePath( $sFile, $blAdmin, $iLang = null )
01415     {
01416         $sDir = null;
01417         if ( $iLang !== false ) {
01418             $sDir = oxLang::getInstance()->getLanguageAbbr( $iLang );
01419         }
01420 
01421         return $this->getDir( $sFile, $sDir, $blAdmin, $iLang, null, $this->getConfigParam( "sTheme" ), true, true );
01422     }
01423 
01431     public function getLanguageDir( $blAdmin )
01432     {
01433         return $this->getDir( null, null, $blAdmin );
01434     }
01435 
01443     public function getCurrencyArray( $iCurrency = null )
01444     {
01445         $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01446         if ( !is_array( $aConfCurrencies ) ) {
01447             return array();
01448         }
01449 
01450         if ( defined( 'OXID_PHP_UNIT' ) ) {
01451             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01452                 try{
01453                     $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01454                     if ( isset( $aAltCurrencies ) ) {
01455                         $aConfCurrencies = $aAltCurrencies;
01456                     }
01457                 } catch( Exception $e ) {
01458                     // if exception is thrown, use default
01459                 }
01460             }
01461         }
01462 
01463         // processing currency configuration data
01464         $aCurrencies = array();
01465         reset( $aConfCurrencies );
01466         while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01467             if ( $val ) {
01468                 $oCur = new oxStdClass();
01469                 $oCur->id      = $key;
01470                 $sCur = explode( '@', $val);
01471                 $oCur->name     = trim( $sCur[0] );
01472                 $oCur->rate     = trim( $sCur[1] );
01473                 $oCur->dec      = trim( $sCur[2] );
01474                 $oCur->thousand = trim( $sCur[3] );
01475                 $oCur->sign     = trim( $sCur[4] );
01476                 $oCur->decimal  = trim( $sCur[5] );
01477 
01478                 // change for US version
01479                 if ( isset( $sCur[6] ) ) {
01480                     $oCur->side = trim($sCur[6]);
01481                 }
01482 
01483                 if ( isset( $iCurrency) && $key == $iCurrency ) {
01484                     $oCur->selected = 1;
01485                 } else {
01486                     $oCur->selected = 0;
01487                 }
01488                 $aCurrencies[$key]= $oCur;
01489             }
01490 
01491             // #861C -  performance, do not load other currencies
01492             if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01493                 break;
01494             }
01495         }
01496         return $aCurrencies;
01497     }
01498 
01506     public function getCurrencyObject( $sName )
01507     {
01508         $aSearch = $this->getCurrencyArray();
01509         foreach ( $aSearch as $oCur ) {
01510             if ( $oCur->name == $sName ) {
01511                 return $oCur;
01512             }
01513         }
01514     }
01515 
01521     public function isDemoShop()
01522     {
01523         return $this->getConfigParam('blDemoShop');
01524     }
01525 
01531     public function getEdition()
01532     {
01533             return "CE";
01534 
01535 
01536     }
01537 
01543     public function getFullEdition()
01544     {
01545         $sEdition = $this->getEdition();
01546 
01547             if ($sEdition == "CE") {
01548                 return "Community Edition";
01549             }
01550 
01551 
01552 
01553         return $sEdition;
01554     }
01555 
01561     public function getVersion()
01562     {
01563         $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01564         return $sVersion;
01565     }
01566 
01572     public function getRevision()
01573     {
01574         try {
01575             $sFileName = getShopBasePath() . "/pkg.rev";
01576             $iRev = (int) trim(@file_get_contents($sFileName));
01577         } catch (Exception $e) {
01578             return false;
01579         }
01580 
01581         if (!$iRev) {
01582             return false;
01583         }
01584 
01585         return $iRev;
01586     }
01587 
01588 
01594     public function isMall()
01595     {
01596 
01597             return false;
01598     }
01599 
01609     public function detectVersion()
01610     {
01611     }
01612 
01613 
01614 
01627     public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '' )
01628     {
01629         switch ( $sVarType ) {
01630             case 'arr':
01631             case 'aarr':
01632                 if (is_array($sVarVal)) {
01633                     $sValue = serialize( $sVarVal );
01634                 } else {
01635                     // Deprecated functionality
01636                     $sValue  = $sVarVal ;
01637                     $sVarVal = unserialize( $sVarVal );
01638                 }
01639                 break;
01640             case 'bool':
01641                 //config param
01642                 $sVarVal = (( $sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
01643                 //db value
01644                 $sValue  = $sVarVal?"1":"";
01645                 break;
01646             default:
01647                 $sValue  = $sVarVal;
01648                 break;
01649         }
01650 
01651         if ( !$sShopId ) {
01652             $sShopId = $this->getShopId();
01653         }
01654 
01655         // Update value only for current shop
01656         if ($sShopId == $this->getShopId()) {
01657             $this->setConfigParam( $sVarName, $sVarVal );
01658         }
01659 
01660         $oDb = oxDb::getDb(true);
01661 
01662         $sShopIdQuoted     = $oDb->quote($sShopId);
01663         $sModuleQuoted     = $oDb->quote($sModule);
01664         $sVarNameQuoted    = $oDb->quote($sVarName);
01665         $sVarTypeQuoted    = $oDb->quote($sVarType);
01666         $sVarValueQuoted   = $oDb->quote($sValue);
01667         $sConfigKeyQuoted  = $oDb->quote($this->getConfigParam('sConfigKey'));
01668         $sNewOXIDdQuoted   = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
01669 
01670         $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
01671         $oDb->execute( $sQ );
01672 
01673         $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
01674                values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
01675 
01676         $oDb->execute( $sQ );
01677     }
01678 
01688     public function getShopConfVar( $sVarName, $sShopId = null, $sModule = '' )
01689     {
01690         if ( !$sShopId ) {
01691             $sShopId = $this->getShopId();
01692         }
01693 
01694         if ( $sShopId === $this->getShopId() && ( !$sModule || $sModule == oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') ) ) {
01695             $sVarValue = $this->getConfigParam( $sVarName );
01696             if ( $sVarValue !== null ) {
01697                 return $sVarValue;
01698             }
01699         }
01700 
01701         $oDb = oxDb::getDb(true);
01702         $sQ  = "select oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '{$sShopId}' and oxmodule = '{$sModule}' and oxvarname = ".$oDb->quote($sVarName);
01703         $oRs = $oDb->execute( $sQ );
01704 
01705         $sValue = null;
01706         if ( $oRs != false && $oRs->recordCount() > 0 ) {
01707             $sValue = $this->decodeValue( $oRs->fields['oxvartype'], $oRs->fields['oxvarvalue'] );
01708         }
01709         return $sValue;
01710     }
01711 
01720     public function decodeValue( $sType, $mOrigValue )
01721     {
01722         $sValue = $mOrigValue;
01723         switch ( $sType ) {
01724             case 'arr':
01725             case 'aarr':
01726                 $sValue = unserialize( $mOrigValue );
01727                 break;
01728             case 'bool':
01729                 $sValue = ( $mOrigValue == 'true' || $mOrigValue == '1' );
01730                 break;
01731         }
01732 
01733         return $sValue;
01734     }
01735 
01743     public function getDecodeValueQuery( $sFieldName = "oxvarvalue" )
01744     {
01745         return " DECODE( {$sFieldName}, '".$this->getConfigParam( 'sConfigKey' )."') ";
01746     }
01747 
01753     public function isProductiveMode()
01754     {
01755         $blProductive = false;
01756 
01757         $blProductive = $this->getConfigParam( 'blProductive' );
01758         if ( !isset( $blProductive ) ) {
01759             $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01760             $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01761             $this->setConfigParam( 'blProductive', $blProductive );
01762         }
01763 
01764         return $blProductive;
01765     }
01766 
01767 
01768 
01774     public function getBaseShopId()
01775     {
01776 
01777             return 'oxbaseshop';
01778     }
01779 
01785     public function getActiveShop()
01786     {
01787         if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01788              $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01789             return $this->_oActShop;
01790         }
01791 
01792         $this->_oActShop = oxNew( 'oxshop' );
01793         $this->_oActShop->load( $this->getShopId() );
01794         return $this->_oActShop;
01795     }
01796 
01802     public function getActiveView()
01803     {
01804         if ( $this->_oActView != null ) {
01805             return $this->_oActView;
01806         }
01807 
01808         $this->_oActView = oxNew( 'oxubase' );
01809         return $this->_oActView;
01810     }
01811 
01819     public function setActiveView( $oView )
01820     {
01821         $this->_oActView = $oView;
01822     }
01823 
01829     public function isUtf()
01830     {
01831         return ( bool ) $this->getConfigParam( 'iUtfMode' );
01832     }
01833 
01839     public function getLogsDir()
01840     {
01841         return $this->getConfigParam( 'sShopDir' ).'log/';
01842     }
01843 
01851     public function isThemeOption( $sName )
01852     {
01853         return (bool) isset( $this->_aThemeConfigParams[$sName] );
01854     }
01855 
01861     public function getShopMainUrl()
01862     {
01863         return $this->isSsl() ? $this->getConfigParam( 'sSSLShopURL' ) : $this->getConfigParam( 'sShopURL' );
01864     }
01865 }