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 ( 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         //adding trailing slashes
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         // some important defaults
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         // #1173M  for EE - not all pic are deleted
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         //max shop id default value
00365         $iMaxShopId = $this->getConfigParam( 'iMaxShopId' );
00366         if( !isset( $iMaxShopId ) )
00367             $this->setConfigParam( 'iMaxShopId', 64 );
00368 
00369         // disabling caching according to DODGER #655 : disable Caching as it doesnt work good enought
00370         $this->setConfigParam( 'blTemplateCaching', false );
00371 
00372         //setting ADODB timeout
00373         global  $ADODB_SESS_LIFE;
00374         $ADODB_SESS_LIFE  = 1;
00375 
00376         // ADODB cachelifetime
00377         $iDBCacheLifeTime = $this->getConfigParam( 'iDBCacheLifeTime' );
00378         if( !isset( $iDBCacheLifeTime ) )
00379             $this->setConfigParam( 'iDBCacheLifeTime', 3600 ); // 1 hour
00380 
00381         $sCoreDir = $this->getConfigParam( 'sShopDir' );
00382         $this->setConfigParam( 'sCoreDir', $sCoreDir.'/core/' );
00383 
00384         try {
00385             $sShopID = $this->getShopId();
00386 
00387             // load now
00388             $this->_loadVarsFromDb( $sShopID );
00389             $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') );
00390 
00391 
00392             //starting up the session
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             //starting up the session
00408             $this->getSession()->start();
00409 
00410             // redirect to start page and display the error
00411             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00412             oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start', true, 302 );
00413         }
00414 
00415 
00416         //application initialization
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                 //exceptions from here go directly to global exception handler
00437                 //if no init is possible whole application has to die!
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         // dodger, allow loading from some vars only from baseshop
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                 //in sShopURL and sSSLShopURL cases we skip (for admin or when URL values are not set)
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                 //setting theme options array
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                     // if exception is thrown, use default
00552                 }
00553             }
00554         }
00555 
00556         $sValue = null;
00557 
00558         if ( isset( $_POST[$sName] ) ) {
00559             $sValue = $_POST[$sName];
00560         } elseif ( isset( $_GET[$sName] ) ) {
00561             $sValue = $_GET[$sName];
00562         }
00563 
00564         // TODO: remove this after special charts concept implementation
00565         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00566         if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00567             self::checkSpecialChars( $sValue, $blRaw );
00568         }
00569 
00570         return $sValue;
00571     }
00572 
00580     public function getUploadedFile($sParamName)
00581     {
00582         return $_FILES[$sParamName];
00583     }
00584 
00593     public function setGlobalParameter( $sName, $sValue )
00594     {
00595         $this->_aGlobalParams[$sName] = $sValue;
00596     }
00597 
00605     public function getGlobalParameter( $sName )
00606     {
00607         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00608             return $this->_aGlobalParams[$sName];
00609         } else {
00610             return null;
00611         }
00612     }
00613 
00623     public static function checkSpecialChars( & $sValue, $aRaw = null )
00624     {
00625         if ( is_object( $sValue ) ) {
00626             return $sValue;
00627         }
00628 
00629         if ( is_array( $sValue ) ) {
00630             $newValue = array();
00631             foreach ( $sValue as $sKey => $sVal ) {
00632                 $sValidKey = $sKey;
00633                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00634                     self::checkSpecialChars( $sValidKey );
00635                     self::checkSpecialChars( $sVal );
00636                     if ($sValidKey != $sKey) {
00637                         unset ($sValue[$sKey]);
00638                     }
00639                 }
00640                 $newValue[$sValidKey] = $sVal;
00641             }
00642             $sValue = $newValue;
00643         } else {
00644             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00645                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00646                                    $sValue );
00647         }
00648         return $sValue;
00649     }
00650 
00656     public function getShopId()
00657     {
00658         if ( $this->_iShopId !== null )
00659             return $this->_iShopId;
00660 
00661             $this->_iShopId = $this->getBaseShopId();
00662 
00663 
00664         oxSession::setVar( 'actshop', $this->_iShopId );
00665         return $this->_iShopId;
00666     }
00667 
00668 
00676     public function setShopId( $sShopId )
00677     {
00678         oxSession::setVar( 'actshop', $sShopId );
00679         $this->_iShopId = $sShopId;
00680     }
00681 
00682 
00688     public function isSsl()
00689     {
00690         if ( is_null( $this->_blIsSsl ) ) {
00691 
00692             $myUtilsServer   = oxUtilsServer::getInstance();
00693             $aServerVars     = $myUtilsServer->getServerVar();
00694             $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00695 
00696             $this->_blIsSsl = false;
00697             if (isset( $aHttpsServerVar ) && ($aHttpsServerVar === 'on' || $aHttpsServerVar == '1' )) {
00698                 // "1&1" hoster provides "1"
00699                 $this->_blIsSsl = ($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
00700                 if ($this->isAdmin() && !$this->_blIsSsl) {
00701                     $this->_blIsSsl = $this->getConfigParam('sAdminSSLURL');
00702                 }
00703             }
00704 
00705             //additional special handling for profihost customers
00706             if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00707                  ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00708                  strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00709                 $this->_blIsSsl = true;
00710             }
00711         }
00712 
00713         return $this->_blIsSsl;
00714     }
00715 
00723     public function isCurrentUrl( $sURL )
00724     {
00725         if ( !$sURL ) {
00726             return false;
00727         }
00728 
00729         $oUtilsServer = oxUtilsServer::getInstance();
00730         $sHost = $oUtilsServer->getServerVar( 'HTTP_HOST' );
00731         $sScriptName = $oUtilsServer->getServerVar( 'SCRIPT_NAME' );
00732 
00733         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $sHost . $sScriptName );
00734 
00735         //remove double slashes all the way
00736         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00737         $sURL = str_replace( '/', '', $sURL );
00738 
00739         //so far comparing for the host is enought for us
00740         if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00741             return true;
00742         }
00743 
00744         return false;
00745     }
00746 
00755     public function getShopUrl( $iLang = null, $blAdmin = null )
00756     {
00757         $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00758         if ( $blAdmin ) {
00759             return $this->getConfigParam( 'sShopURL' );
00760         }
00761 
00762         // #680 per language another URL
00763         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00764         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00765         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00766             $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00767             return $aLanguageURLs[$iLang];
00768         }
00769 
00770         //normal section
00771         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00772         if ( $sMallShopURL ) {
00773             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00774             return $sMallShopURL;
00775         }
00776 
00777         return $this->getConfigParam( 'sShopURL' );
00778     }
00779 
00787     public function getSslShopUrl( $iLang = null )
00788     {
00789         // #680 per language another URL
00790         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00791         $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00792         if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00793             $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00794             return $aLanguageSSLURLs[$iLang];
00795         }
00796 
00797         //mall mode
00798         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00799             $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00800             return $sMallSSLShopURL;
00801         }
00802 
00803         if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00804             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00805             return $sMallShopURL;
00806         }
00807 
00808         //normal section
00809         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00810             return $sSSLShopURL;
00811         }
00812 
00813         return $this->getShopUrl( $iLang );
00814     }
00815 
00821     public function getCoreUtilsUrl()
00822     {
00823         return $this->getCurrentShopUrl().'core/utils/';
00824     }
00825 
00834     public function getCurrentShopUrl($blAdmin = null)
00835     {
00836         if ($blAdmin===null) {
00837             $blAdmin = $this->isAdmin();
00838         }
00839         if ($blAdmin) {
00840             if ($this->isSsl()) {
00841 
00842                 $sUrl = $this->getConfigParam( 'sAdminSSLURL' );
00843                 if ( !$sUrl ) {
00844                     return $this->getSslShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00845                 }
00846                 return $sUrl;
00847             } else {
00848                 return $this->getShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00849             }
00850         } else {
00851             return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
00852         }
00853     }
00854 
00862     public function getShopCurrentUrl( $iLang = null )
00863     {
00864         if ( $this->isSsl() ) {
00865             $sURL = $this->getSSLShopURL( $iLang );
00866         } else {
00867             $sURL = $this->getShopURL( $iLang );
00868         }
00869 
00870         return oxUtilsUrl::getInstance()->processUrl( $sURL.'index.php', false );
00871     }
00872 
00881     public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00882     {
00883         return oxUtilsUrl::getInstance()->processUrl($this->getShopUrl( $iLang, $blAdmin).'index.php', false );
00884     }
00885 
00891     public function getShopSecureHomeUrl()
00892     {
00893         return  oxUtilsUrl::getInstance()->processUrl( $this->getSslShopUrl().'index.php', false );
00894     }
00895 
00901     public function getShopCurrency()
00902     {
00903         $iCurr = null;
00904         if ( ( null === ( $iCurr = oxConfig::getParameter( 'cur' ) ) ) ) {
00905             if ( null === ( $iCurr = oxConfig::getParameter( 'currency' ) ) ) {
00906                 $iCurr = oxSession::getVar( 'currency' );
00907             }
00908         }
00909         return (int) $iCurr;
00910     }
00911 
00917     public function getActShopCurrencyObject()
00918     {
00919         //caching currency as it does not change through the script
00920         //but not for unit tests as ther it changes always
00921         if ( !defined( 'OXID_PHP_UNIT' ) ) {
00922             if (!is_null($this->_oActCurrencyObject)) {
00923                 return $this->_oActCurrencyObject;
00924             }
00925         }
00926 
00927         $iCur = $this->getShopCurrency();
00928         $aCurrencies = $this->getCurrencyArray();
00929         if ( !isset( $aCurrencies[$iCur] ) ) {
00930             return $this->_oActCurrencyObject = reset( $aCurrencies ); // reset() returns the first element
00931         }
00932 
00933         return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00934     }
00935 
00943     public function setActShopCurrency( $iCur )
00944     {
00945         $aCurrencies = $this->getCurrencyArray();
00946         if ( isset( $aCurrencies[$iCur] ) ) {
00947             oxSession::setVar( 'currency', $iCur );
00948             $this->_oActCurrencyObject = null;
00949         }
00950     }
00951 
00959     public function getOutDir( $blAbsolute = true)
00960     {
00961         if ($blAbsolute) {
00962             return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
00963         } else {
00964             return $this->_sOutDir.'/';
00965         }
00966     }
00967 
00977     public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
00978     {
00979         $blSSL    = is_null($blSSL)?$this->isSsl():$blSSL;
00980         $blAdmin  = is_null($blAdmin)?$this->isAdmin():$blAdmin;
00981 
00982         if ( $blSSL ) {
00983             if ($blNativeImg && !$blAdmin) {
00984                 $sUrl = $this->getSslShopUrl();
00985             } else {
00986                 $sUrl = $this->getConfigParam('sSSLShopURL');
00987                 if (!$sUrl && $blAdmin) {
00988                     $sUrl = $this->getConfigParam('sAdminSSLURL').'../';
00989                 }
00990             }
00991         } else {
00992             $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
00993         }
00994 
00995         return $sUrl.$this->_sOutDir.'/';
00996     }
00997 
01012     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false )
01013     {
01014         if ( is_null($sTheme) ) {
01015             $sTheme = $this->getConfigParam( 'sTheme' );
01016         }
01017 
01018         if ( $blAdmin ) {
01019             $sTheme = 'admin';
01020         }
01021 
01022         $sBase    = $this->getOutDir( $blAbsolute );
01023         $sAbsBase = $this->getOutDir();
01024 
01025         $sLang = '-';
01026         // FALSE means skip language folder check
01027         if ( $iLang !== false ) {
01028             $oLang = oxLang::getInstance();
01029 
01030             if ( is_null( $iLang ) ) {
01031                 $iLang = $oLang->getEditLanguage();
01032             }
01033 
01034             $sLang = $oLang->getLanguageAbbr( $iLang );
01035         }
01036 
01037         if ( is_null($iShop) ) {
01038             $iShop = $this->getShopId();
01039         }
01040 
01041         //Load from
01042         $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01043         $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01044 
01045         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01046             return $sReturn;
01047         }
01048 
01049         $sReturn = false;
01050 
01051         // Check for custom template
01052         $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
01053         if ( !$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01054             $sReturn = $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute );
01055         }
01056 
01057         //test lang level ..
01058         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01059             $sReturn = $sBase . $sPath;
01060         }
01061 
01062         //test shop level ..
01063         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01064         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01065             $sReturn = $sBase . $sPath;
01066         }
01067 
01068 
01069         //test theme language level ..
01070         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01071         if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01072             $sReturn = $sBase . $sPath;
01073         }
01074 
01075         //test theme level ..
01076         $sPath = "$sTheme/$sDir/$sFile";
01077         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01078             $sReturn = $sBase . $sPath;
01079         }
01080 
01081         //test out language level ..
01082         $sPath = "$sLang/$sDir/$sFile";
01083         if ( !$sReturn &&  $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01084             $sReturn = $sBase . $sPath;
01085         }
01086 
01087         //test out level ..
01088         $sPath = "$sDir/$sFile";
01089         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01090             $sReturn = $sBase . $sPath;
01091         }
01092 
01093         if ( !$sReturn ) {
01094             // TODO: implement logic to log missing paths
01095         }
01096 
01097         // to cache
01098         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01099 
01100         return $sReturn;
01101     }
01102 
01117     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01118     {
01119         $sUrl = str_replace(
01120                                 $this->getOutDir(),
01121                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01122                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01123                             );
01124         return $sUrl;
01125     }
01126 
01135     public function getImagePath( $sFile, $blAdmin = false )
01136     {
01137         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01138     }
01139 
01150     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null )
01151     {
01152         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01153         return $this->getUrl( $sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01154     }
01155 
01163     public function getImageDir( $blAdmin = false )
01164     {
01165         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01166     }
01167 
01179     public function getPicturePath($sFile, $blAdmin = false, $iLang = null , $iShop = null , $sTheme = null)
01180     {
01181         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme );
01182     }
01183 
01191     public function getMasterPictureDir( $blAdmin = false )
01192     {
01193         return $this->getDir( null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01194     }
01195 
01204     public function getMasterPicturePath( $sFile, $blAdmin = false )
01205     {
01206         return $this->getDir( $sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01207     }
01208 
01221     public function getPictureUrl( $sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01222     {
01223         if (!isset($blSSL)) {
01224             $blSSL = $this->isSsl();
01225         }
01226         if ( $sAltUrl = $this->getConfigParam( 'sAltImageDir' ) ) {
01227 
01228             if ( $this->isSsl() && $blSSL && $sSslAltUrl = $this->getConfigParam( 'sSSLAltImageDir' ) ) {
01229                 $sAltUrl = $sSslAltUrl;
01230             }
01231 
01232             if ( !is_null( $sFile ) ) {
01233                 $sAltUrl .= $sFile;
01234             }
01235 
01236             return $sAltUrl;
01237         }
01238 
01239         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01240 
01241         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01242 
01243 
01244         //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01245         if ( !$sUrl && $sDefPic ) {
01246             $sUrl = $this->getUrl( $sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01247         }
01248         return $sUrl;
01249     }
01250 
01265     public function getIconUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01266     {
01267         return $this->getPictureUrl( $sFile, $blAdmin, $blSSL, $iLang, $iShopId, $sDefPic );
01268     }
01269 
01277     public function getPictureDir( $blAdmin )
01278     {
01279         return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01280     }
01281 
01290     public function getTemplatePath( $sFile, $blAdmin )
01291     {
01292         return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01293     }
01294 
01302     public function getTemplateDir( $blAdmin = false )
01303     {
01304         return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01305     }
01306 
01317     public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01318     {
01319         return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01320     }
01321 
01329     public function getTemplateBase( $blAdmin = false )
01330     {
01331         // Base template dir is the parent dir of template dir
01332         return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01333     }
01334 
01343     public function getResourcePath($sFile = '', $blAdmin = false )
01344     {
01345         return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01346     }
01347 
01358     public function getResourceUrl( $sFile = '', $blAdmin = false , $blSSL = null , $iLang = null )
01359     {
01360         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01361         return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang );
01362     }
01363 
01371     public function getResourceDir( $blAdmin )
01372     {
01373         return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01374     }
01375 
01389     public function getLanguagePath( $sFile, $blAdmin, $iLang = null, $iShop = null, $sTheme = null )
01390     {
01391         return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang, $iShop, $sTheme );
01392     }
01393 
01405     public function getStdLanguagePath( $sFile, $blAdmin, $iLang = null )
01406     {
01407         $sDir = null;
01408         if ( $iLang !== false ) {
01409             $sDir = oxLang::getInstance()->getLanguageAbbr( $iLang );
01410         }
01411 
01412         return $this->getDir( $sFile, $sDir, $blAdmin, $iLang, null, $this->getConfigParam( "sTheme" ), true, true );
01413     }
01414 
01422     public function getLanguageDir( $blAdmin )
01423     {
01424         return $this->getDir( null, null, $blAdmin );
01425     }
01426 
01434     public function getCurrencyArray( $iCurrency = null )
01435     {
01436         $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01437         if ( !is_array( $aConfCurrencies ) ) {
01438             return array();
01439         }
01440 
01441         if ( defined( 'OXID_PHP_UNIT' ) ) {
01442             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01443                 try{
01444                     $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01445                     if ( isset( $aAltCurrencies ) ) {
01446                         $aConfCurrencies = $aAltCurrencies;
01447                     }
01448                 } catch( Exception $e ) {
01449                     // if exception is thrown, use default
01450                 }
01451             }
01452         }
01453 
01454         // processing currency configuration data
01455         $aCurrencies = array();
01456         reset( $aConfCurrencies );
01457         while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01458             if ( $val ) {
01459                 $oCur = new oxStdClass();
01460                 $oCur->id      = $key;
01461                 $sCur = explode( '@', $val);
01462                 $oCur->name     = trim( $sCur[0] );
01463                 $oCur->rate     = trim( $sCur[1] );
01464                 $oCur->dec      = trim( $sCur[2] );
01465                 $oCur->thousand = trim( $sCur[3] );
01466                 $oCur->sign     = trim( $sCur[4] );
01467                 $oCur->decimal  = trim( $sCur[5] );
01468 
01469                 // change for US version
01470                 if ( isset( $sCur[6] ) ) {
01471                     $oCur->side = trim($sCur[6]);
01472                 }
01473 
01474                 if ( isset( $iCurrency) && $key == $iCurrency ) {
01475                     $oCur->selected = 1;
01476                 } else {
01477                     $oCur->selected = 0;
01478                 }
01479                 $aCurrencies[$key]= $oCur;
01480             }
01481 
01482             // #861C -  performance, do not load other currencies
01483             if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01484                 break;
01485             }
01486         }
01487         return $aCurrencies;
01488     }
01489 
01497     public function getCurrencyObject( $sName )
01498     {
01499         $aSearch = $this->getCurrencyArray();
01500         foreach ( $aSearch as $oCur ) {
01501             if ( $oCur->name == $sName ) {
01502                 return $oCur;
01503             }
01504         }
01505     }
01506 
01512     public function isDemoShop()
01513     {
01514         return $this->getConfigParam('blDemoShop');
01515     }
01516 
01522     public function getEdition()
01523     {
01524             return "CE";
01525 
01526 
01527     }
01528 
01534     public function getFullEdition()
01535     {
01536         $sEdition = $this->getEdition();
01537 
01538             if ($sEdition == "CE") {
01539                 return "Community Edition";
01540             }
01541 
01542 
01543 
01544         return $sEdition;
01545     }
01546 
01552     public function getVersion()
01553     {
01554         $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01555         return $sVersion;
01556     }
01557 
01563     public function getRevision()
01564     {
01565         try {
01566             $sFileName = getShopBasePath() . "/pkg.rev";
01567             $iRev = (int) trim(@file_get_contents($sFileName));
01568         } catch (Exception $e) {
01569             return false;
01570         }
01571 
01572         if (!$iRev) {
01573             return false;
01574         }
01575 
01576         return $iRev;
01577     }
01578 
01579 
01585     public function isMall()
01586     {
01587 
01588             return false;
01589     }
01590 
01600     public function detectVersion()
01601     {
01602     }
01603 
01604 
01605 
01618     public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '' )
01619     {
01620         switch ( $sVarType ) {
01621             case 'arr':
01622             case 'aarr':
01623                 if (is_array($sVarVal)) {
01624                     $sValue = serialize( $sVarVal );
01625                 } else {
01626                     // Deprecated functionality
01627                     $sValue  = $sVarVal ;
01628                     $sVarVal = unserialize( $sVarVal );
01629                 }
01630                 break;
01631             case 'bool':
01632                 //config param
01633                 $sVarVal = (( $sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
01634                 //db value
01635                 $sValue  = $sVarVal?"1":"";
01636                 break;
01637             default:
01638                 $sValue  = $sVarVal;
01639                 break;
01640         }
01641 
01642         if ( !$sShopId ) {
01643             $sShopId = $this->getShopId();
01644         }
01645 
01646         // Update value only for current shop
01647         if ($sShopId == $this->getShopId()) {
01648             $this->setConfigParam( $sVarName, $sVarVal );
01649         }
01650 
01651         $oDb = oxDb::getDb(true);
01652 
01653         $sShopIdQuoted     = $oDb->quote($sShopId);
01654         $sModuleQuoted     = $oDb->quote($sModule);
01655         $sVarNameQuoted    = $oDb->quote($sVarName);
01656         $sVarTypeQuoted    = $oDb->quote($sVarType);
01657         $sVarValueQuoted   = $oDb->quote($sValue);
01658         $sConfigKeyQuoted  = $oDb->quote($this->getConfigParam('sConfigKey'));
01659         $sNewOXIDdQuoted   = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
01660 
01661         $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
01662         $oDb->execute( $sQ );
01663 
01664         $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
01665                values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
01666 
01667         $oDb->execute( $sQ );
01668     }
01669 
01678     public function getShopConfVar( $sVarName, $sShopId = null )
01679     {
01680         if ( !$sShopId ) {
01681             $sShopId = $this->getShopId();
01682         }
01683 
01684         $oDb = oxDb::getDb(true);
01685         $sQ  = "select oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '$sShopId' and oxvarname = ".$oDb->quote($sVarName);
01686         $oRs = $oDb->Execute( $sQ );
01687 
01688         $sValue = null;
01689         if ( $oRs != false && $oRs->recordCount() > 0 ) {
01690             $sValue = $this->decodeValue( $oRs->fields['oxvartype'], $oRs->fields['oxvarvalue'] );
01691         }
01692         return $sValue;
01693     }
01694 
01703     public function decodeValue( $sType, $mOrigValue )
01704     {
01705         $sValue = $mOrigValue;
01706         switch ( $sType ) {
01707             case 'arr':
01708             case 'aarr':
01709                 $sValue = unserialize( $mOrigValue );
01710                 break;
01711             case 'bool':
01712                 $sValue = ( $mOrigValue == 'true' || $mOrigValue == '1' );
01713                 break;
01714         }
01715 
01716         return $sValue;
01717     }
01718 
01726     public function getDecodeValueQuery( $sFieldName = "oxvarvalue" )
01727     {
01728         return " DECODE( {$sFieldName}, '".$this->getConfigParam( 'sConfigKey' )."') ";
01729     }
01730 
01736     public function isProductiveMode()
01737     {
01738         $blProductive = false;
01739 
01740         $blProductive = $this->getConfigParam( 'blProductive' );
01741         if ( !isset( $blProductive ) ) {
01742             $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01743             $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01744             $this->setConfigParam( 'blProductive', $blProductive );
01745         }
01746 
01747         return $blProductive;
01748     }
01749 
01750 
01751 
01757     public function getBaseShopId()
01758     {
01759 
01760             return 'oxbaseshop';
01761     }
01762 
01768     public function getActiveShop()
01769     {
01770         if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01771              $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01772             return $this->_oActShop;
01773         }
01774 
01775         $this->_oActShop = oxNew( 'oxshop' );
01776         $this->_oActShop->load( $this->getShopId() );
01777         return $this->_oActShop;
01778     }
01779 
01785     public function getActiveView()
01786     {
01787         if ( $this->_oActView != null ) {
01788             return $this->_oActView;
01789         }
01790 
01791         $this->_oActView = oxNew( 'oxubase' );
01792         return $this->_oActView;
01793     }
01794 
01802     public function setActiveView( $oView )
01803     {
01804         $this->_oActView = $oView;
01805     }
01806 
01812     public function isUtf()
01813     {
01814         return ( bool ) $this->getConfigParam( 'iUtfMode' );
01815     }
01816 
01822     public function getLogsDir()
01823     {
01824         return $this->getConfigParam( 'sShopDir' ).'log/';
01825     }
01826 
01834     public function isThemeOption( $sName )
01835     {
01836         return (bool) isset( $this->_aThemeConfigParams[$sName] );
01837     }
01838 
01839 }