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             $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') );
00399 
00400 
00401             //starting up the session
00402             $this->getSession()->start();
00403         } catch ( oxConnectionException $oEx ) {
00404             $oEx->debugOut();
00405             if ( defined( 'OXID_PHP_UNIT' ) ) {
00406                 return false;
00407             } elseif ( 0 != $this->iDebug ) {
00408                 oxUtils::getInstance()->showMessageAndExit( $oEx->getString() );
00409             } else {
00410                 header( "HTTP/1.1 500 Internal Server Error");
00411                 header( "Location: offline.html");
00412                 header( "Connection: close");
00413             }
00414         } catch ( oxCookieException $oEx ) {
00415 
00416             //starting up the session
00417             $this->getSession()->start();
00418 
00419             // redirect to start page and display the error
00420             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00421             oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start', true, 302 );
00422         }
00423 
00424 
00425         //application initialization
00426         $this->_oStart = new oxStart();
00427         $this->_oStart->appInit();
00428     }
00429 
00435     public static function getInstance()
00436     {
00437 
00438         if ( defined( 'OXID_PHP_UNIT' ) ) {
00439             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00440                 return modConfig::$unitMOD;
00441             }
00442         }
00443 
00444         if ( !self::$_instance instanceof oxConfig ) {
00445                 //exceptions from here go directly to global exception handler
00446                 //if no init is possible whole application has to die!
00447                 self::$_instance = new oxConfig();
00448                 self::$_instance->init();
00449         }
00450         return self::$_instance;
00451     }
00452 
00462     protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null, $sModule = '' )
00463     {
00464         $oDb = oxDb::getDb();
00465 
00466         $sQ = "select oxvarname, oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '$sShopID' and oxmodule=".$oDb->quote($sModule);
00467         // dodger, allow loading from some vars only from baseshop
00468         if ( $aOnlyVars !== null ) {
00469             $blSep = false;
00470             $sIn  = '';
00471             foreach ( $aOnlyVars as $sField ) {
00472                 if ( $blSep ) {
00473                     $sIn .= ', ';
00474                 }
00475                 $sIn .= '"'.$sField.'"';
00476                 $blSep = true;
00477             }
00478             $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00479         }
00480 
00481         $oRs = $oDb->execute( $sQ );
00482         if ( $oRs != false && $oRs->recordCount() > 0 ) {
00483             while ( !$oRs->EOF ) {
00484                 $sVarName = $oRs->fields[0];
00485                 $sVarType = $oRs->fields[1];
00486                 $sVarVal  = $oRs->fields[2];
00487 
00488                 //in sShopURL and sSSLShopURL cases we skip (for admin or when URL values are not set)
00489                 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00490                     ( !$sVarVal || $this->isAdmin() === true ) ) {
00491                     $oRs->moveNext();
00492                     continue;
00493                 }
00494 
00495                 $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
00496 
00497                 //setting theme options array
00498                 if ( $sModule != '' ) {
00499                     $this->_aThemeConfigParams[$sVarName] = $sModule;
00500                 }
00501 
00502                 $oRs->moveNext();
00503             }
00504         }
00505     }
00506 
00516     protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
00517     {
00518         switch ( $sVarType ) {
00519             case 'arr':
00520             case 'aarr':
00521                 $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00522                 break;
00523             case 'bool':
00524                 $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00525                 break;
00526             default:
00527                 $this->setConfigParam( $sVarName, $sVarVal );
00528                 break;
00529         }
00530     }
00531 
00537     public function pageClose()
00538     {
00539         return $this->_oStart->pageClose();
00540     }
00541 
00553     public static function getParameter(  $sName, $blRaw = false )
00554     {
00555         if ( defined( 'OXID_PHP_UNIT' ) ) {
00556             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00557                 try{
00558                     return modConfig::getParameter(  $sName, $blRaw );
00559                 } catch( Exception $e ) {
00560                     // if exception is thrown, use default
00561                 }
00562             }
00563         }
00564 
00565         $sValue = null;
00566 
00567         if ( isset( $_POST[$sName] ) ) {
00568             $sValue = $_POST[$sName];
00569         } elseif ( isset( $_GET[$sName] ) ) {
00570             $sValue = $_GET[$sName];
00571         }
00572 
00573         // TODO: remove this after special charts concept implementation
00574         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00575         if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00576             self::checkSpecialChars( $sValue, $blRaw );
00577         }
00578 
00579         return $sValue;
00580     }
00581 
00589     public function getUploadedFile($sParamName)
00590     {
00591         return $_FILES[$sParamName];
00592     }
00593 
00602     public function setGlobalParameter( $sName, $sValue )
00603     {
00604         $this->_aGlobalParams[$sName] = $sValue;
00605     }
00606 
00614     public function getGlobalParameter( $sName )
00615     {
00616         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00617             return $this->_aGlobalParams[$sName];
00618         } else {
00619             return null;
00620         }
00621     }
00622 
00632     public static function checkSpecialChars( & $sValue, $aRaw = null )
00633     {
00634         if ( is_object( $sValue ) ) {
00635             return $sValue;
00636         }
00637 
00638         if ( is_array( $sValue ) ) {
00639             $newValue = array();
00640             foreach ( $sValue as $sKey => $sVal ) {
00641                 $sValidKey = $sKey;
00642                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00643                     self::checkSpecialChars( $sValidKey );
00644                     self::checkSpecialChars( $sVal );
00645                     if ($sValidKey != $sKey) {
00646                         unset ($sValue[$sKey]);
00647                     }
00648                 }
00649                 $newValue[$sValidKey] = $sVal;
00650             }
00651             $sValue = $newValue;
00652         } else {
00653             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00654                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00655                                    $sValue );
00656         }
00657         return $sValue;
00658     }
00659 
00665     public function getShopId()
00666     {
00667         if ( $this->_iShopId !== null )
00668             return $this->_iShopId;
00669 
00670             $this->_iShopId = $this->getBaseShopId();
00671 
00672 
00673         oxSession::setVar( 'actshop', $this->_iShopId );
00674         return $this->_iShopId;
00675     }
00676 
00677 
00685     public function setShopId( $sShopId )
00686     {
00687         oxSession::setVar( 'actshop', $sShopId );
00688         $this->_iShopId = $sShopId;
00689     }
00690 
00691 
00697     public function isSsl()
00698     {
00699         if ( is_null( $this->_blIsSsl ) ) {
00700 
00701             $myUtilsServer   = oxUtilsServer::getInstance();
00702             $aServerVars     = $myUtilsServer->getServerVar();
00703             $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00704 
00705             $this->_blIsSsl = false;
00706             if (isset( $aHttpsServerVar ) && ($aHttpsServerVar === 'on' || $aHttpsServerVar == '1' )) {
00707                 // "1&1" hoster provides "1"
00708                 $this->_blIsSsl = ($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
00709                 if ($this->isAdmin() && !$this->_blIsSsl) {
00710                     $this->_blIsSsl = $this->getConfigParam('sAdminSSLURL');
00711                 }
00712             }
00713 
00714             //additional special handling for profihost customers
00715             if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00716                  ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00717                  strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00718                 $this->_blIsSsl = true;
00719             }
00720         }
00721 
00722         return $this->_blIsSsl;
00723     }
00724 
00732     public function isCurrentUrl( $sURL )
00733     {
00734         if ( !$sURL ) {
00735             return false;
00736         }
00737 
00738         $oUtilsServer = oxUtilsServer::getInstance();
00739         $sHost = $oUtilsServer->getServerVar( 'HTTP_HOST' );
00740         $sScriptName = $oUtilsServer->getServerVar( 'SCRIPT_NAME' );
00741 
00742         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $sHost . $sScriptName );
00743 
00744         //remove double slashes all the way
00745         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00746         $sURL = str_replace( '/', '', $sURL );
00747 
00748         //so far comparing for the host is enought for us
00749         if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00750             return true;
00751         }
00752 
00753         return false;
00754     }
00755 
00764     public function getShopUrl( $iLang = null, $blAdmin = null )
00765     {
00766         $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00767         if ( $blAdmin ) {
00768             return $this->getConfigParam( 'sShopURL' );
00769         }
00770 
00771         // #680 per language another URL
00772         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00773         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00774         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00775             $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00776             return $aLanguageURLs[$iLang];
00777         }
00778 
00779         //normal section
00780         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00781         if ( $sMallShopURL ) {
00782             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00783             return $sMallShopURL;
00784         }
00785 
00786         return $this->getConfigParam( 'sShopURL' );
00787     }
00788 
00796     public function getSslShopUrl( $iLang = null )
00797     {
00798         // #680 per language another URL
00799         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00800         $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00801         if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00802             $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00803             return $aLanguageSSLURLs[$iLang];
00804         }
00805 
00806         //mall mode
00807         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00808             $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00809             return $sMallSSLShopURL;
00810         }
00811 
00812         if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00813             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00814             return $sMallShopURL;
00815         }
00816 
00817         //normal section
00818         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00819             return $sSSLShopURL;
00820         }
00821 
00822         return $this->getShopUrl( $iLang );
00823     }
00824 
00830     public function getCoreUtilsUrl()
00831     {
00832         return $this->getCurrentShopUrl().'core/utils/';
00833     }
00834 
00843     public function getCurrentShopUrl($blAdmin = null)
00844     {
00845         if ($blAdmin===null) {
00846             $blAdmin = $this->isAdmin();
00847         }
00848         if ($blAdmin) {
00849             if ($this->isSsl()) {
00850 
00851                 $sUrl = $this->getConfigParam( 'sAdminSSLURL' );
00852                 if ( !$sUrl ) {
00853                     return $this->getSslShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00854                 }
00855                 return $sUrl;
00856             } else {
00857                 return $this->getShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00858             }
00859         } else {
00860             return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
00861         }
00862     }
00863 
00871     public function getShopCurrentUrl( $iLang = null )
00872     {
00873         if ( $this->isSsl() ) {
00874             $sURL = $this->getSSLShopURL( $iLang );
00875         } else {
00876             $sURL = $this->getShopURL( $iLang );
00877         }
00878 
00879         return oxUtilsUrl::getInstance()->processUrl( $sURL.'index.php', false );
00880     }
00881 
00890     public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00891     {
00892         return oxUtilsUrl::getInstance()->processUrl($this->getShopUrl( $iLang, $blAdmin).'index.php', false );
00893     }
00894 
00900     public function getShopSecureHomeUrl()
00901     {
00902         return  oxUtilsUrl::getInstance()->processUrl( $this->getSslShopUrl().'index.php', false );
00903     }
00904 
00910     public function getShopCurrency()
00911     {
00912         $iCurr = null;
00913         if ( ( null === ( $iCurr = oxConfig::getParameter( 'cur' ) ) ) ) {
00914             if ( null === ( $iCurr = oxConfig::getParameter( 'currency' ) ) ) {
00915                 $iCurr = oxSession::getVar( 'currency' );
00916             }
00917         }
00918         return (int) $iCurr;
00919     }
00920 
00926     public function getActShopCurrencyObject()
00927     {
00928         //caching currency as it does not change through the script
00929         //but not for unit tests as ther it changes always
00930         if ( !defined( 'OXID_PHP_UNIT' ) ) {
00931             if (!is_null($this->_oActCurrencyObject)) {
00932                 return $this->_oActCurrencyObject;
00933             }
00934         }
00935 
00936         $iCur = $this->getShopCurrency();
00937         $aCurrencies = $this->getCurrencyArray();
00938         if ( !isset( $aCurrencies[$iCur] ) ) {
00939             return $this->_oActCurrencyObject = reset( $aCurrencies ); // reset() returns the first element
00940         }
00941 
00942         return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00943     }
00944 
00952     public function setActShopCurrency( $iCur )
00953     {
00954         $aCurrencies = $this->getCurrencyArray();
00955         if ( isset( $aCurrencies[$iCur] ) ) {
00956             oxSession::setVar( 'currency', $iCur );
00957             $this->_oActCurrencyObject = null;
00958         }
00959     }
00960 
00968     public function getOutDir( $blAbsolute = true)
00969     {
00970         if ($blAbsolute) {
00971             return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
00972         } else {
00973             return $this->_sOutDir.'/';
00974         }
00975     }
00976 
00986     public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
00987     {
00988         $blSSL    = is_null($blSSL)?$this->isSsl():$blSSL;
00989         $blAdmin  = is_null($blAdmin)?$this->isAdmin():$blAdmin;
00990 
00991         if ( $blSSL ) {
00992             if ($blNativeImg && !$blAdmin) {
00993                 $sUrl = $this->getSslShopUrl();
00994             } else {
00995                 $sUrl = $this->getConfigParam('sSSLShopURL');
00996                 if (!$sUrl && $blAdmin) {
00997                     $sUrl = $this->getConfigParam('sAdminSSLURL').'../';
00998                 }
00999             }
01000         } else {
01001             $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
01002         }
01003 
01004         return $sUrl.$this->_sOutDir.'/';
01005     }
01006 
01021     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false )
01022     {
01023         if ( is_null($sTheme) ) {
01024             $sTheme = $this->getConfigParam( 'sTheme' );
01025         }
01026 
01027         if ( $blAdmin ) {
01028             $sTheme = 'admin';
01029         }
01030 
01031         $sBase    = $this->getOutDir( $blAbsolute );
01032         $sAbsBase = $this->getOutDir();
01033 
01034         $sLang = '-';
01035         // FALSE means skip language folder check
01036         if ( $iLang !== false ) {
01037             $oLang = oxLang::getInstance();
01038 
01039             if ( is_null( $iLang ) ) {
01040                 $iLang = $oLang->getEditLanguage();
01041             }
01042 
01043             $sLang = $oLang->getLanguageAbbr( $iLang );
01044         }
01045 
01046         if ( is_null($iShop) ) {
01047             $iShop = $this->getShopId();
01048         }
01049 
01050         //Load from
01051         $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01052         $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01053 
01054         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01055             return $sReturn;
01056         }
01057 
01058         $sReturn = false;
01059 
01060         // Check for custom template
01061         $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
01062         if ( !$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01063             $sReturn = $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute );
01064         }
01065 
01066         //test lang level ..
01067         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01068             $sReturn = $sBase . $sPath;
01069         }
01070 
01071         //test shop level ..
01072         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01073         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01074             $sReturn = $sBase . $sPath;
01075         }
01076 
01077 
01078         //test theme language level ..
01079         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01080         if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01081             $sReturn = $sBase . $sPath;
01082         }
01083 
01084         //test theme level ..
01085         $sPath = "$sTheme/$sDir/$sFile";
01086         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01087             $sReturn = $sBase . $sPath;
01088         }
01089 
01090         //test out language level ..
01091         $sPath = "$sLang/$sDir/$sFile";
01092         if ( !$sReturn &&  $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01093             $sReturn = $sBase . $sPath;
01094         }
01095 
01096         //test out level ..
01097         $sPath = "$sDir/$sFile";
01098         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01099             $sReturn = $sBase . $sPath;
01100         }
01101 
01102         if ( !$sReturn ) {
01103             // TODO: implement logic to log missing paths
01104         }
01105 
01106         // to cache
01107         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01108 
01109         return $sReturn;
01110     }
01111 
01126     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01127     {
01128         $sUrl = str_replace(
01129                                 $this->getOutDir(),
01130                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01131                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01132                             );
01133         return $sUrl;
01134     }
01135 
01144     public function getImagePath( $sFile, $blAdmin = false )
01145     {
01146         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01147     }
01148 
01159     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null )
01160     {
01161         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01162         return $this->getUrl( $sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01163     }
01164 
01172     public function getImageDir( $blAdmin = false )
01173     {
01174         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01175     }
01176 
01188     public function getPicturePath($sFile, $blAdmin = false, $iLang = null , $iShop = null , $sTheme = null)
01189     {
01190         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme );
01191     }
01192 
01200     public function getMasterPictureDir( $blAdmin = false )
01201     {
01202         return $this->getDir( null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01203     }
01204 
01213     public function getMasterPicturePath( $sFile, $blAdmin = false )
01214     {
01215         return $this->getDir( $sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01216     }
01217 
01230     public function getPictureUrl( $sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01231     {
01232         if (!isset($blSSL)) {
01233             $blSSL = $this->isSsl();
01234         }
01235         if ( $sAltUrl = $this->getConfigParam( 'sAltImageDir' ) ) {
01236 
01237             if ( $this->isSsl() && $blSSL && $sSslAltUrl = $this->getConfigParam( 'sSSLAltImageDir' ) ) {
01238                 $sAltUrl = $sSslAltUrl;
01239             }
01240 
01241             if ( !is_null( $sFile ) ) {
01242                 $sAltUrl .= $sFile;
01243             }
01244 
01245             return $sAltUrl;
01246         }
01247 
01248         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01249 
01250         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01251 
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 }