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     protected function _processSeoCall()
00327     {
00328         // TODO: refactor shop bootstrap and parse url params as soon as possible
00329         if (isSearchEngineUrl()) {
00330             oxNew('oxSeoDecoder')->processSeoCall();
00331         }
00332     }
00333 
00339     public function init()
00340     {
00341         include getShopBasePath().'config.inc.php';
00342         include getShopBasePath().'core/oxconfk.php';
00343 
00344         //adding trailing slashes
00345         $oFileUtils = oxUtilsFile::getInstance();
00346         $this->sShopDir     = $oFileUtils->normalizeDir($this->sShopDir);
00347         $this->sCompileDir  = $oFileUtils->normalizeDir($this->sCompileDir);
00348         $this->sShopURL     = $oFileUtils->normalizeDir($this->sShopURL);
00349         $this->sSSLShopURL  = $oFileUtils->normalizeDir($this->sSSLShopURL);
00350         $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00351 
00352 
00353         // some important defaults
00354         if( !$this->getConfigParam( 'sDefaultLang' ) )
00355             $this->setConfigParam( 'sDefaultLang', 0 );
00356 
00357 
00358         $this->setConfigParam( 'sTheme', 'basic' );
00359 
00360 
00361         $blLogChangesInAdmin = $this->getConfigParam( 'blLogChangesInAdmin' );
00362         if( !isset( $blLogChangesInAdmin ) )
00363             $this->setConfigParam( 'blLogChangesInAdmin', false );
00364 
00365         $blCheckTemplates = $this->getConfigParam( 'blCheckTemplates' );
00366         if( !isset( $blCheckTemplates ) )
00367             $this->setConfigParam( 'blCheckTemplates', false );
00368 
00369         $blAllowArticlesubclass = $this->getConfigParam( 'blAllowArticlesubclass' );
00370         if( !isset( $blAllowArticlesubclass ) )
00371             $this->setConfigParam( 'blAllowArticlesubclass', false );
00372 
00373         $iAdminListSize = $this->getConfigParam( 'iAdminListSize' );
00374         if( !isset( $iAdminListSize ) )
00375             $this->setConfigParam( 'iAdminListSize', 9 );
00376 
00377         // #1173M  for EE - not all pic are deleted
00378         $iPicCount = $this->getConfigParam( 'iPicCount' );
00379         if( !isset( $iPicCount ) )
00380             $this->setConfigParam( 'iPicCount', 7 );
00381 
00382         $iZoomPicCount = $this->getConfigParam( 'iZoomPicCount' );
00383         if( !isset( $iZoomPicCount ) )
00384             $this->setConfigParam( 'iZoomPicCount', 4 );
00385 
00386         //max shop id default value
00387         $iMaxShopId = $this->getConfigParam( 'iMaxShopId' );
00388         if( !isset( $iMaxShopId ) )
00389             $this->setConfigParam( 'iMaxShopId', 64 );
00390 
00391         // disabling caching according to DODGER #655 : disable Caching as it doesnt work good enought
00392         $this->setConfigParam( 'blTemplateCaching', false );
00393 
00394         //setting ADODB timeout
00395         global  $ADODB_SESS_LIFE;
00396         $ADODB_SESS_LIFE  = 1;
00397 
00398         // ADODB cachelifetime
00399         $iDBCacheLifeTime = $this->getConfigParam( 'iDBCacheLifeTime' );
00400         if( !isset( $iDBCacheLifeTime ) )
00401             $this->setConfigParam( 'iDBCacheLifeTime', 3600 ); // 1 hour
00402 
00403         $sCoreDir = $this->getConfigParam( 'sShopDir' );
00404         $this->setConfigParam( 'sCoreDir', $sCoreDir.'/core/' );
00405 
00406         try {
00407             $sShopID = $this->getShopId();
00408 
00409             // load now
00410             $this->_loadVarsFromDb( $sShopID );
00411 
00412             // loading theme config options
00413             $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') );
00414 
00415             // checking if custom theme (which has defined parent theme) config options should be loaded over parent theme (#3362)
00416             if ( $this->getConfigParam('sCustomTheme') ) {
00417                 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme') );
00418             }
00419 
00420 
00421             $this->_processSeoCall();
00422 
00423             //starting up the session
00424             $this->getSession()->start();
00425         } catch ( oxConnectionException $oEx ) {
00426             $oEx->debugOut();
00427             if ( defined( 'OXID_PHP_UNIT' ) ) {
00428                 return false;
00429             } elseif ( 0 != $this->iDebug ) {
00430                 oxUtils::getInstance()->showMessageAndExit( $oEx->getString() );
00431             } else {
00432                 header( "HTTP/1.1 500 Internal Server Error");
00433                 header( "Location: offline.html");
00434                 header( "Connection: close");
00435             }
00436         } catch ( oxCookieException $oEx ) {
00437 
00438             $this->_processSeoCall();
00439 
00440             //starting up the session
00441             $this->getSession()->start();
00442 
00443             // redirect to start page and display the error
00444             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00445             oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start', true, 302 );
00446         }
00447 
00448 
00449         //application initialization
00450         $this->_oStart = new oxStart();
00451         $this->_oStart->appInit();
00452     }
00453 
00459     public static function getInstance()
00460     {
00461 
00462         if ( defined( 'OXID_PHP_UNIT' ) ) {
00463             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00464                 return modConfig::$unitMOD;
00465             }
00466         }
00467 
00468         if ( !self::$_instance instanceof oxConfig ) {
00469                 //exceptions from here go directly to global exception handler
00470                 //if no init is possible whole application has to die!
00471                 self::$_instance = new oxConfig();
00472                 self::$_instance->init();
00473         }
00474         return self::$_instance;
00475     }
00476 
00486     protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null, $sModule = '' )
00487     {
00488         $oDb = oxDb::getDb();
00489 
00490         $sQ = "select oxvarname, oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '$sShopID' and oxmodule=".$oDb->quote($sModule);
00491         // dodger, allow loading from some vars only from baseshop
00492         if ( $aOnlyVars !== null ) {
00493             $blSep = false;
00494             $sIn  = '';
00495             foreach ( $aOnlyVars as $sField ) {
00496                 if ( $blSep ) {
00497                     $sIn .= ', ';
00498                 }
00499                 $sIn .= '"'.$sField.'"';
00500                 $blSep = true;
00501             }
00502             $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00503         }
00504 
00505         $oRs = $oDb->execute( $sQ );
00506         if ( $oRs != false && $oRs->recordCount() > 0 ) {
00507             while ( !$oRs->EOF ) {
00508                 $sVarName = $oRs->fields[0];
00509                 $sVarType = $oRs->fields[1];
00510                 $sVarVal  = $oRs->fields[2];
00511 
00512                 //in sShopURL and sSSLShopURL cases we skip (for admin or when URL values are not set)
00513                 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00514                     ( !$sVarVal || $this->isAdmin() === true ) ) {
00515                     $oRs->moveNext();
00516                     continue;
00517                 }
00518 
00519                 $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
00520 
00521                 //setting theme options array
00522                 if ( $sModule != '' ) {
00523                     $this->_aThemeConfigParams[$sVarName] = $sModule;
00524                 }
00525 
00526                 $oRs->moveNext();
00527             }
00528         }
00529     }
00530 
00540     protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
00541     {
00542         switch ( $sVarType ) {
00543             case 'arr':
00544             case 'aarr':
00545                 $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00546                 break;
00547             case 'bool':
00548                 $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00549                 break;
00550             default:
00551                 $this->setConfigParam( $sVarName, $sVarVal );
00552                 break;
00553         }
00554     }
00555 
00561     public function pageClose()
00562     {
00563         return $this->_oStart->pageClose();
00564     }
00565 
00577     public static function getParameter(  $sName, $blRaw = false )
00578     {
00579         if ( defined( 'OXID_PHP_UNIT' ) ) {
00580             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00581                 try{
00582                     return modConfig::getParameter(  $sName, $blRaw );
00583                 } catch( Exception $e ) {
00584                     // if exception is thrown, use default
00585                 }
00586             }
00587         }
00588 
00589         $sValue = null;
00590 
00591         if ( isset( $_POST[$sName] ) ) {
00592             $sValue = $_POST[$sName];
00593         } elseif ( isset( $_GET[$sName] ) ) {
00594             $sValue = $_GET[$sName];
00595         }
00596 
00597         // TODO: remove this after special charts concept implementation
00598         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00599         if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00600             self::checkSpecialChars( $sValue, $blRaw );
00601         }
00602 
00603         return $sValue;
00604     }
00605 
00613     public function getUploadedFile($sParamName)
00614     {
00615         return $_FILES[$sParamName];
00616     }
00617 
00626     public function setGlobalParameter( $sName, $sValue )
00627     {
00628         $this->_aGlobalParams[$sName] = $sValue;
00629     }
00630 
00638     public function getGlobalParameter( $sName )
00639     {
00640         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00641             return $this->_aGlobalParams[$sName];
00642         } else {
00643             return null;
00644         }
00645     }
00646 
00656     public static function checkSpecialChars( & $sValue, $aRaw = null )
00657     {
00658         if ( is_object( $sValue ) ) {
00659             return $sValue;
00660         }
00661 
00662         if ( is_array( $sValue ) ) {
00663             $newValue = array();
00664             foreach ( $sValue as $sKey => $sVal ) {
00665                 $sValidKey = $sKey;
00666                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00667                     self::checkSpecialChars( $sValidKey );
00668                     self::checkSpecialChars( $sVal );
00669                     if ($sValidKey != $sKey) {
00670                         unset ($sValue[$sKey]);
00671                     }
00672                 }
00673                 $newValue[$sValidKey] = $sVal;
00674             }
00675             $sValue = $newValue;
00676         } else {
00677             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00678                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00679                                    $sValue );
00680         }
00681         return $sValue;
00682     }
00683 
00689     public function getShopId()
00690     {
00691         if ( $this->_iShopId !== null )
00692             return $this->_iShopId;
00693 
00694             $this->_iShopId = $this->getBaseShopId();
00695 
00696 
00697         oxSession::setVar( 'actshop', $this->_iShopId );
00698         return $this->_iShopId;
00699     }
00700 
00701 
00709     public function setShopId( $sShopId )
00710     {
00711         oxSession::setVar( 'actshop', $sShopId );
00712         $this->_iShopId = $sShopId;
00713     }
00714 
00715 
00721     public function isSsl()
00722     {
00723         if ( is_null( $this->_blIsSsl ) ) {
00724 
00725             $myUtilsServer   = oxUtilsServer::getInstance();
00726             $aServerVars     = $myUtilsServer->getServerVar();
00727             $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00728 
00729             $this->_blIsSsl = false;
00730             if (isset( $aHttpsServerVar ) && ($aHttpsServerVar === 'on' || $aHttpsServerVar === 'ON' || $aHttpsServerVar == '1' )) {
00731                 // "1&1" hoster provides "1"
00732                 $this->_blIsSsl = ($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
00733                 if ($this->isAdmin() && !$this->_blIsSsl) {
00734                     $this->_blIsSsl = $this->getConfigParam('sAdminSSLURL');
00735                 }
00736             }
00737 
00738             //additional special handling for profihost customers
00739             if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00740                  ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00741                  strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00742                 $this->_blIsSsl = true;
00743             }
00744         }
00745 
00746         return $this->_blIsSsl;
00747     }
00748 
00756     public function isCurrentUrl( $sURL )
00757     {
00758         if ( !$sURL ) {
00759             return false;
00760         }
00761 
00762         $oUtilsServer = oxUtilsServer::getInstance();
00763 
00764         preg_match("/^(http:\/\/)?([^\/]+)/i", $sURL, $matches);
00765         $sUrlHost = $matches[2];
00766 
00767         preg_match("/^(http:\/\/)?([^\/]+)/i", $oUtilsServer->getServerVar( 'HTTP_HOST' ), $matches);
00768         $sRealHost = $matches[2];
00769 
00770         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $oUtilsServer->getServerVar( 'HTTP_HOST' ) . $oUtilsServer->getServerVar( 'SCRIPT_NAME' ) );
00771 
00772         //remove double slashes all the way
00773         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00774         $sURL = str_replace( '/', '', $sURL );
00775 
00776         if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00777 
00778             //bug fix #0002991
00779             if ( $sUrlHost == $sRealHost ) {
00780                 return true;
00781             }
00782         }
00783 
00784         return false;
00785     }
00786 
00795     public function getShopUrl( $iLang = null, $blAdmin = null )
00796     {
00797         $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00798         if ( $blAdmin ) {
00799             return $this->getConfigParam( 'sShopURL' );
00800         }
00801 
00802         // #680 per language another URL
00803         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00804         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00805         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00806             $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00807             return $aLanguageURLs[$iLang];
00808         }
00809 
00810         //normal section
00811         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00812         if ( $sMallShopURL ) {
00813             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00814             return $sMallShopURL;
00815         }
00816 
00817         return $this->getConfigParam( 'sShopURL' );
00818     }
00819 
00827     public function getSslShopUrl( $iLang = null )
00828     {
00829         // #680 per language another URL
00830         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00831         $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00832         if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00833             $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00834             return $aLanguageSSLURLs[$iLang];
00835         }
00836 
00837         //mall mode
00838         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00839             $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00840             return $sMallSSLShopURL;
00841         }
00842 
00843         if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00844             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00845             return $sMallShopURL;
00846         }
00847 
00848         //normal section
00849         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00850             return $sSSLShopURL;
00851         }
00852 
00853         return $this->getShopUrl( $iLang );
00854     }
00855 
00861     public function getCoreUtilsUrl()
00862     {
00863         return $this->getCurrentShopUrl().'core/utils/';
00864     }
00865 
00874     public function getCurrentShopUrl($blAdmin = null)
00875     {
00876         if ($blAdmin===null) {
00877             $blAdmin = $this->isAdmin();
00878         }
00879         if ($blAdmin) {
00880             if ($this->isSsl()) {
00881 
00882                 $sUrl = $this->getConfigParam( 'sAdminSSLURL' );
00883                 if ( !$sUrl ) {
00884                     return $this->getSslShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00885                 }
00886                 return $sUrl;
00887             } else {
00888                 return $this->getShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00889             }
00890         } else {
00891             return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
00892         }
00893     }
00894 
00902     public function getShopCurrentUrl( $iLang = null )
00903     {
00904         if ( $this->isSsl() ) {
00905             $sURL = $this->getSSLShopURL( $iLang );
00906         } else {
00907             $sURL = $this->getShopURL( $iLang );
00908         }
00909 
00910         return oxUtilsUrl::getInstance()->processUrl( $sURL.'index.php', false );
00911     }
00912 
00921     public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00922     {
00923         return oxUtilsUrl::getInstance()->processUrl($this->getShopUrl( $iLang, $blAdmin).'index.php', false );
00924     }
00925 
00931     public function getShopSecureHomeUrl()
00932     {
00933         return  oxUtilsUrl::getInstance()->processUrl( $this->getSslShopUrl().'index.php', false );
00934     }
00935 
00941     public function getShopCurrency()
00942     {
00943         $iCurr = null;
00944         if ( ( null === ( $iCurr = oxConfig::getParameter( 'cur' ) ) ) ) {
00945             if ( null === ( $iCurr = oxConfig::getParameter( 'currency' ) ) ) {
00946                 $iCurr = oxSession::getVar( 'currency' );
00947             }
00948         }
00949         return (int) $iCurr;
00950     }
00951 
00957     public function getActShopCurrencyObject()
00958     {
00959         //caching currency as it does not change through the script
00960         //but not for unit tests as ther it changes always
00961         if ( !defined( 'OXID_PHP_UNIT' ) ) {
00962             if (!is_null($this->_oActCurrencyObject)) {
00963                 return $this->_oActCurrencyObject;
00964             }
00965         }
00966 
00967         $iCur = $this->getShopCurrency();
00968         $aCurrencies = $this->getCurrencyArray();
00969         if ( !isset( $aCurrencies[$iCur] ) ) {
00970             return $this->_oActCurrencyObject = reset( $aCurrencies ); // reset() returns the first element
00971         }
00972 
00973         return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00974     }
00975 
00983     public function setActShopCurrency( $iCur )
00984     {
00985         $aCurrencies = $this->getCurrencyArray();
00986         if ( isset( $aCurrencies[$iCur] ) ) {
00987             oxSession::setVar( 'currency', $iCur );
00988             $this->_oActCurrencyObject = null;
00989         }
00990     }
00991 
00999     public function getOutDir( $blAbsolute = true)
01000     {
01001         if ($blAbsolute) {
01002             return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
01003         } else {
01004             return $this->_sOutDir.'/';
01005         }
01006     }
01007 
01017     public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
01018     {
01019         $blSSL    = is_null($blSSL)?$this->isSsl():$blSSL;
01020         $blAdmin  = is_null($blAdmin)?$this->isAdmin():$blAdmin;
01021 
01022         if ( $blSSL ) {
01023             if ($blNativeImg && !$blAdmin) {
01024                 $sUrl = $this->getSslShopUrl();
01025             } else {
01026                 $sUrl = $this->getConfigParam('sSSLShopURL');
01027                 if (!$sUrl && $blAdmin) {
01028                     $sUrl = $this->getConfigParam('sAdminSSLURL').'../';
01029                 }
01030             }
01031         } else {
01032             $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
01033         }
01034 
01035         return $sUrl.$this->_sOutDir.'/';
01036     }
01037 
01052     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false )
01053     {
01054         if ( is_null($sTheme) ) {
01055             $sTheme = $this->getConfigParam( 'sTheme' );
01056         }
01057 
01058         if ( $blAdmin ) {
01059             $sTheme = 'admin';
01060         }
01061 
01062         $sBase    = $this->getOutDir( $blAbsolute );
01063         $sAbsBase = $this->getOutDir();
01064 
01065         $sLang = '-';
01066         // FALSE means skip language folder check
01067         if ( $iLang !== false ) {
01068             $oLang = oxLang::getInstance();
01069 
01070             if ( is_null( $iLang ) ) {
01071                 $iLang = $oLang->getEditLanguage();
01072             }
01073 
01074             $sLang = $oLang->getLanguageAbbr( $iLang );
01075         }
01076 
01077         if ( is_null($iShop) ) {
01078             $iShop = $this->getShopId();
01079         }
01080 
01081         //Load from
01082         $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01083         $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01084 
01085         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01086             return $sReturn;
01087         }
01088 
01089         $sReturn = false;
01090 
01091         // Check for custom template
01092         $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
01093         if ( !$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01094             $sReturn = $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute );
01095         }
01096 
01097         //test lang level ..
01098         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01099             $sReturn = $sBase . $sPath;
01100         }
01101 
01102         //test shop level ..
01103         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01104         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01105             $sReturn = $sBase . $sPath;
01106         }
01107 
01108 
01109         //test theme language level ..
01110         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01111         if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01112             $sReturn = $sBase . $sPath;
01113         }
01114 
01115         //test theme level ..
01116         $sPath = "$sTheme/$sDir/$sFile";
01117         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01118             $sReturn = $sBase . $sPath;
01119         }
01120 
01121         //test out language level ..
01122         $sPath = "$sLang/$sDir/$sFile";
01123         if ( !$sReturn &&  $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01124             $sReturn = $sBase . $sPath;
01125         }
01126 
01127         //test out level ..
01128         $sPath = "$sDir/$sFile";
01129         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01130             $sReturn = $sBase . $sPath;
01131         }
01132 
01133         if ( !$sReturn ) {
01134             // TODO: implement logic to log missing paths
01135         }
01136 
01137         // to cache
01138         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01139 
01140         return $sReturn;
01141     }
01142 
01157     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01158     {
01159         $sUrl = str_replace(
01160                                 $this->getOutDir(),
01161                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01162                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01163                             );
01164         return $sUrl;
01165     }
01166 
01175     public function getImagePath( $sFile, $blAdmin = false )
01176     {
01177         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01178     }
01179 
01190     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null )
01191     {
01192         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01193         return $this->getUrl( $sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01194     }
01195 
01203     public function getImageDir( $blAdmin = false )
01204     {
01205         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01206     }
01207 
01219     public function getPicturePath($sFile, $blAdmin = false, $iLang = null , $iShop = null , $sTheme = null)
01220     {
01221         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme );
01222     }
01223 
01231     public function getMasterPictureDir( $blAdmin = false )
01232     {
01233         return $this->getDir( null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01234     }
01235 
01244     public function getMasterPicturePath( $sFile, $blAdmin = false )
01245     {
01246         return $this->getDir( $sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01247     }
01248 
01261     public function getPictureUrl( $sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01262     {
01263         if ( $sAltUrl = oxPictureHandler::getInstance()->getAltImageUrl('/', $sFile, $blSSL) ) {
01264             return $sAltUrl;
01265         }
01266 
01267         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01268         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01269 
01270         //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01271         if ( !$sUrl && $sDefPic ) {
01272             $sUrl = $this->getUrl( $sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01273         }
01274         return $sUrl;
01275     }
01276 
01291     public function getIconUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01292     {
01293         return $this->getPictureUrl( $sFile, $blAdmin, $blSSL, $iLang, $iShopId, $sDefPic );
01294     }
01295 
01303     public function getPictureDir( $blAdmin )
01304     {
01305         return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01306     }
01307 
01316     public function getTemplatePath( $sFile, $blAdmin )
01317     {
01318         return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01319     }
01320 
01328     public function getTemplateDir( $blAdmin = false )
01329     {
01330         return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01331     }
01332 
01343     public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01344     {
01345         return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01346     }
01347 
01355     public function getTemplateBase( $blAdmin = false )
01356     {
01357         // Base template dir is the parent dir of template dir
01358         return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01359     }
01360 
01369     public function getResourcePath($sFile = '', $blAdmin = false )
01370     {
01371         return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01372     }
01373 
01384     public function getResourceUrl( $sFile = '', $blAdmin = false , $blSSL = null , $iLang = null )
01385     {
01386         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01387         return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang );
01388     }
01389 
01397     public function getResourceDir( $blAdmin )
01398     {
01399         return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01400     }
01401 
01415     public function getLanguagePath( $sFile, $blAdmin, $iLang = null, $iShop = null, $sTheme = null )
01416     {
01417         return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang, $iShop, $sTheme );
01418     }
01419 
01431     public function getStdLanguagePath( $sFile, $blAdmin, $iLang = null )
01432     {
01433         $sDir = null;
01434         if ( $iLang !== false ) {
01435             $sDir = oxLang::getInstance()->getLanguageAbbr( $iLang );
01436         }
01437 
01438         return $this->getDir( $sFile, $sDir, $blAdmin, $iLang, null, $this->getConfigParam( "sTheme" ), true, true );
01439     }
01440 
01448     public function getLanguageDir( $blAdmin )
01449     {
01450         return $this->getDir( null, null, $blAdmin );
01451     }
01452 
01460     public function getCurrencyArray( $iCurrency = null )
01461     {
01462         $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01463         if ( !is_array( $aConfCurrencies ) ) {
01464             return array();
01465         }
01466 
01467         if ( defined( 'OXID_PHP_UNIT' ) ) {
01468             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01469                 try{
01470                     $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01471                     if ( isset( $aAltCurrencies ) ) {
01472                         $aConfCurrencies = $aAltCurrencies;
01473                     }
01474                 } catch( Exception $e ) {
01475                     // if exception is thrown, use default
01476                 }
01477             }
01478         }
01479 
01480         // processing currency configuration data
01481         $aCurrencies = array();
01482         reset( $aConfCurrencies );
01483         while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01484             if ( $val ) {
01485                 $oCur = new oxStdClass();
01486                 $oCur->id      = $key;
01487                 $sCur = explode( '@', $val);
01488                 $oCur->name     = trim( $sCur[0] );
01489                 $oCur->rate     = trim( $sCur[1] );
01490                 $oCur->dec      = trim( $sCur[2] );
01491                 $oCur->thousand = trim( $sCur[3] );
01492                 $oCur->sign     = trim( $sCur[4] );
01493                 $oCur->decimal  = trim( $sCur[5] );
01494 
01495                 // change for US version
01496                 if ( isset( $sCur[6] ) ) {
01497                     $oCur->side = trim($sCur[6]);
01498                 }
01499 
01500                 if ( isset( $iCurrency) && $key == $iCurrency ) {
01501                     $oCur->selected = 1;
01502                 } else {
01503                     $oCur->selected = 0;
01504                 }
01505                 $aCurrencies[$key]= $oCur;
01506             }
01507 
01508             // #861C -  performance, do not load other currencies
01509             if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01510                 break;
01511             }
01512         }
01513         return $aCurrencies;
01514     }
01515 
01523     public function getCurrencyObject( $sName )
01524     {
01525         $aSearch = $this->getCurrencyArray();
01526         foreach ( $aSearch as $oCur ) {
01527             if ( $oCur->name == $sName ) {
01528                 return $oCur;
01529             }
01530         }
01531     }
01532 
01538     public function isDemoShop()
01539     {
01540         return $this->getConfigParam('blDemoShop');
01541     }
01542 
01548     public function getEdition()
01549     {
01550             return "CE";
01551 
01552 
01553     }
01554 
01560     public function getFullEdition()
01561     {
01562         $sEdition = $this->getEdition();
01563 
01564             if ($sEdition == "CE") {
01565                 return "Community Edition";
01566             }
01567 
01568 
01569 
01570         return $sEdition;
01571     }
01572 
01578     public function getVersion()
01579     {
01580         $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01581         return $sVersion;
01582     }
01583 
01589     public function getRevision()
01590     {
01591         try {
01592             $sFileName = getShopBasePath() . "/pkg.rev";
01593             $iRev = (int) trim(@file_get_contents($sFileName));
01594         } catch (Exception $e) {
01595             return false;
01596         }
01597 
01598         if (!$iRev) {
01599             return false;
01600         }
01601 
01602         return $iRev;
01603     }
01604 
01605 
01611     public function isMall()
01612     {
01613 
01614             return false;
01615     }
01616 
01626     public function detectVersion()
01627     {
01628     }
01629 
01630 
01631 
01644     public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '' )
01645     {
01646         switch ( $sVarType ) {
01647             case 'arr':
01648             case 'aarr':
01649                 if (is_array($sVarVal)) {
01650                     $sValue = serialize( $sVarVal );
01651                 } else {
01652                     // Deprecated functionality
01653                     $sValue  = $sVarVal ;
01654                     $sVarVal = unserialize( $sVarVal );
01655                 }
01656                 break;
01657             case 'bool':
01658                 //config param
01659                 $sVarVal = (( $sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
01660                 //db value
01661                 $sValue  = $sVarVal?"1":"";
01662                 break;
01663             default:
01664                 $sValue  = $sVarVal;
01665                 break;
01666         }
01667 
01668         if ( !$sShopId ) {
01669             $sShopId = $this->getShopId();
01670         }
01671 
01672         // Update value only for current shop
01673         if ($sShopId == $this->getShopId()) {
01674             $this->setConfigParam( $sVarName, $sVarVal );
01675         }
01676 
01677         $oDb = oxDb::getDb(true);
01678 
01679         $sShopIdQuoted     = $oDb->quote($sShopId);
01680         $sModuleQuoted     = $oDb->quote($sModule);
01681         $sVarNameQuoted    = $oDb->quote($sVarName);
01682         $sVarTypeQuoted    = $oDb->quote($sVarType);
01683         $sVarValueQuoted   = $oDb->quote($sValue);
01684         $sConfigKeyQuoted  = $oDb->quote($this->getConfigParam('sConfigKey'));
01685         $sNewOXIDdQuoted   = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
01686 
01687         $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
01688         $oDb->execute( $sQ );
01689 
01690         $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
01691                values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
01692 
01693         $oDb->execute( $sQ );
01694     }
01695 
01705     public function getShopConfVar( $sVarName, $sShopId = null, $sModule = '' )
01706     {
01707         if ( !$sShopId ) {
01708             $sShopId = $this->getShopId();
01709         }
01710 
01711         if ( $sShopId === $this->getShopId() && ( !$sModule || $sModule == oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') ) ) {
01712             $sVarValue = $this->getConfigParam( $sVarName );
01713             if ( $sVarValue !== null ) {
01714                 return $sVarValue;
01715             }
01716         }
01717 
01718         $oDb = oxDb::getDb(true);
01719         $sQ  = "select oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '{$sShopId}' and oxmodule = '{$sModule}' and oxvarname = ".$oDb->quote($sVarName);
01720         $oRs = $oDb->execute( $sQ );
01721 
01722         $sValue = null;
01723         if ( $oRs != false && $oRs->recordCount() > 0 ) {
01724             $sValue = $this->decodeValue( $oRs->fields['oxvartype'], $oRs->fields['oxvarvalue'] );
01725         }
01726         return $sValue;
01727     }
01728 
01737     public function decodeValue( $sType, $mOrigValue )
01738     {
01739         $sValue = $mOrigValue;
01740         switch ( $sType ) {
01741             case 'arr':
01742             case 'aarr':
01743                 $sValue = unserialize( $mOrigValue );
01744                 break;
01745             case 'bool':
01746                 $sValue = ( $mOrigValue == 'true' || $mOrigValue == '1' );
01747                 break;
01748         }
01749 
01750         return $sValue;
01751     }
01752 
01760     public function getDecodeValueQuery( $sFieldName = "oxvarvalue" )
01761     {
01762         return " DECODE( {$sFieldName}, '".$this->getConfigParam( 'sConfigKey' )."') ";
01763     }
01764 
01770     public function isProductiveMode()
01771     {
01772         $blProductive = false;
01773 
01774         $blProductive = $this->getConfigParam( 'blProductive' );
01775         if ( !isset( $blProductive ) ) {
01776             $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01777             $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01778             $this->setConfigParam( 'blProductive', $blProductive );
01779         }
01780 
01781         return $blProductive;
01782     }
01783 
01784 
01785 
01791     public function getBaseShopId()
01792     {
01793 
01794             return 'oxbaseshop';
01795     }
01796 
01802     public function getActiveShop()
01803     {
01804         if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01805              $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01806             return $this->_oActShop;
01807         }
01808 
01809         $this->_oActShop = oxNew( 'oxshop' );
01810         $this->_oActShop->load( $this->getShopId() );
01811         return $this->_oActShop;
01812     }
01813 
01819     public function getActiveView()
01820     {
01821         if ( $this->_oActView != null ) {
01822             return $this->_oActView;
01823         }
01824 
01825         $this->_oActView = oxNew( 'oxubase' );
01826         return $this->_oActView;
01827     }
01828 
01836     public function setActiveView( $oView )
01837     {
01838         $this->_oActView = $oView;
01839     }
01840 
01846     public function isUtf()
01847     {
01848         return ( bool ) $this->getConfigParam( 'iUtfMode' );
01849     }
01850 
01856     public function getLogsDir()
01857     {
01858         return $this->getConfigParam( 'sShopDir' ).'log/';
01859     }
01860 
01868     public function isThemeOption( $sName )
01869     {
01870         return (bool) isset( $this->_aThemeConfigParams[$sName] );
01871     }
01872 
01878     public function getShopMainUrl()
01879     {
01880         return $this->isSsl() ? $this->getConfigParam( 'sSSLShopURL' ) : $this->getConfigParam( 'sShopURL' );
01881     }
01882 }