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         $sTheme = $this->getConfigParam( 'sTheme' );
00336         if( !isset( $sTheme ) )
00337             $this->setConfigParam( 'sTheme', 'basic' );
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             $sCustomTheme = $this->getConfigParam('sCustomTheme');
00391             if ($sCustomTheme) {
00392                 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $sCustomTheme );
00393             }
00394 
00395 
00396             //starting up the session
00397             $this->getSession()->start();
00398         } catch ( oxConnectionException $oEx ) {
00399             $oEx->debugOut();
00400             if ( defined( 'OXID_PHP_UNIT' ) ) {
00401                 return false;
00402             } elseif ( 0 != $this->iDebug ) {
00403                 oxUtils::getInstance()->showMessageAndExit( $oEx->getString() );
00404             } else {
00405                 header( "HTTP/1.1 500 Internal Server Error");
00406                 header( "Location: offline.html");
00407                 header( "Connection: close");
00408             }
00409         } catch ( oxCookieException $oEx ) {
00410 
00411             //starting up the session
00412             $this->getSession()->start();
00413 
00414             // redirect to start page and display the error
00415             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00416             oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start', true, 302 );
00417         }
00418 
00419 
00420         //application initialization
00421         $this->_oStart = new oxStart();
00422         $this->_oStart->appInit();
00423     }
00424 
00430     public static function getInstance()
00431     {
00432 
00433         if ( defined( 'OXID_PHP_UNIT' ) ) {
00434             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00435                 return modConfig::$unitMOD;
00436             }
00437         }
00438 
00439         if ( !self::$_instance instanceof oxConfig ) {
00440                 //exceptions from here go directly to global exception handler
00441                 //if no init is possible whole application has to die!
00442                 self::$_instance = new oxConfig();
00443                 self::$_instance->init();
00444         }
00445         return self::$_instance;
00446     }
00447 
00457     protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null, $sModule = '' )
00458     {
00459         $oDb = oxDb::getDb();
00460 
00461         $sQ = "select oxvarname, oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopID' and oxmodule=".$oDb->quote($sModule);
00462         // dodger, allow loading from some vars only from baseshop
00463         if ( $aOnlyVars !== null ) {
00464             $blSep = false;
00465             $sIn  = '';
00466             foreach ( $aOnlyVars as $sField ) {
00467                 if ( $blSep ) {
00468                     $sIn .= ', ';
00469                 }
00470                 $sIn .= '"'.$sField.'"';
00471                 $blSep = true;
00472             }
00473             $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00474         }
00475 
00476         $oRs = $oDb->execute( $sQ );
00477         if ( $oRs != false && $oRs->recordCount() > 0 ) {
00478             while ( !$oRs->EOF ) {
00479                 $sVarName = $oRs->fields[0];
00480                 $sVarType = $oRs->fields[1];
00481                 $sVarVal  = $oRs->fields[2];
00482 
00483                 //in sShopURL and sSSLShopURL cases we skip (for admin or when URL values are not set)
00484                 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00485                     ( !$sVarVal || $this->isAdmin() === true ) ) {
00486                     $oRs->moveNext();
00487                     continue;
00488                 }
00489 
00490                 $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
00491 
00492                 //setting theme options array
00493                 if ( $sModule != '' ) {
00494                     $this->_aThemeConfigParams[$sVarName] = $sModule;
00495                 }
00496 
00497                 $oRs->moveNext();
00498             }
00499         }
00500     }
00501 
00511     protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
00512     {
00513         switch ( $sVarType ) {
00514             case 'arr':
00515             case 'aarr':
00516                 $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00517                 break;
00518             case 'bool':
00519                 $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00520                 break;
00521             default:
00522                 $this->setConfigParam( $sVarName, $sVarVal );
00523                 break;
00524         }
00525     }
00526 
00532     public function pageClose()
00533     {
00534         return $this->_oStart->pageClose();
00535     }
00536 
00548     public static function getParameter(  $sName, $blRaw = false )
00549     {
00550         if ( defined( 'OXID_PHP_UNIT' ) ) {
00551             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00552                 try{
00553                     return modConfig::getParameter(  $sName, $blRaw );
00554                 } catch( Exception $e ) {
00555                     // if exception is thrown, use default
00556                 }
00557             }
00558         }
00559 
00560         $sValue = null;
00561         if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_POST[$sName] ) ) {
00562             $sValue = $_POST[$sName];
00563         } elseif ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'GET' && isset( $_GET[$sName] ) ) {
00564             $sValue = $_GET[$sName];
00565         } else {
00566             $sValue = null;
00567         }
00568 
00569         // TODO: remove this after special charts concept implementation
00570         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00571         if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00572             self::checkSpecialChars( $sValue, $blRaw );
00573         }
00574 
00575         return $sValue;
00576     }
00577 
00585     public function getUploadedFile($sParamName)
00586     {
00587         return $_FILES[$sParamName];
00588     }
00589 
00598     public function setGlobalParameter( $sName, $sValue )
00599     {
00600         $this->_aGlobalParams[$sName] = $sValue;
00601     }
00602 
00610     public function getGlobalParameter( $sName )
00611     {
00612         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00613             return $this->_aGlobalParams[$sName];
00614         } else {
00615             return null;
00616         }
00617     }
00618 
00628     public static function checkSpecialChars( & $sValue, $aRaw = null )
00629     {
00630         if ( is_object( $sValue ) ) {
00631             return $sValue;
00632         }
00633 
00634         if ( is_array( $sValue ) ) {
00635             $newValue = array();
00636             foreach ( $sValue as $sKey => $sVal ) {
00637                 $sValidKey = $sKey;
00638                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00639                     self::checkSpecialChars( $sValidKey );
00640                     self::checkSpecialChars( $sVal );
00641                     if ($sValidKey != $sKey) {
00642                         unset ($sValue[$sKey]);
00643                     }
00644                 }
00645                 $newValue[$sValidKey] = $sVal;
00646             }
00647             $sValue = $newValue;
00648         } else {
00649             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00650                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00651                                    $sValue );
00652         }
00653         return $sValue;
00654     }
00655 
00661     public function getShopId()
00662     {
00663         if ( $this->_iShopId !== null )
00664             return $this->_iShopId;
00665 
00666             $this->_iShopId = $this->getBaseShopId();
00667 
00668 
00669         oxSession::setVar( 'actshop', $this->_iShopId );
00670         return $this->_iShopId;
00671     }
00672 
00673 
00681     public function setShopId( $sShopId )
00682     {
00683         oxSession::setVar( 'actshop', $sShopId );
00684         $this->_iShopId = $sShopId;
00685     }
00686 
00687 
00693     public function isSsl()
00694     {
00695         if ( is_null( $this->_blIsSsl ) ) {
00696 
00697             $myUtilsServer   = oxUtilsServer::getInstance();
00698             $aServerVars     = $myUtilsServer->getServerVar();
00699             $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00700 
00701             $this->_blIsSsl = false;
00702             if (isset( $aHttpsServerVar ) && ($aHttpsServerVar === 'on' || $aHttpsServerVar == '1' )) {
00703                 // "1&1" hoster provides "1"
00704                 $this->_blIsSsl = ($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
00705                 if ($this->isAdmin() && !$this->_blIsSsl) {
00706                     $this->_blIsSsl = $this->getConfigParam('sAdminSSLURL');
00707                 }
00708             }
00709 
00710             //additional special handling for profihost customers
00711             if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00712                  ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00713                  strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00714                 $this->_blIsSsl = true;
00715             }
00716         }
00717 
00718         return $this->_blIsSsl;
00719     }
00720 
00728     public function isCurrentUrl( $sURL )
00729     {
00730         if ( !$sURL ) {
00731             return false;
00732         }
00733 
00734         $oUtilsServer = oxUtilsServer::getInstance();
00735         $sHost = $oUtilsServer->getServerVar( 'HTTP_HOST' );
00736         $sScriptName = $oUtilsServer->getServerVar( 'SCRIPT_NAME' );
00737 
00738         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $sHost . $sScriptName );
00739 
00740         //remove double slashes all the way
00741         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00742         $sURL = str_replace( '/', '', $sURL );
00743 
00744         //so far comparing for the host is enought for us
00745         if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00746             return true;
00747         }
00748 
00749         return false;
00750     }
00751 
00760     public function getShopUrl( $iLang = null, $blAdmin = null )
00761     {
00762         $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00763         if ( $blAdmin ) {
00764             return $this->getConfigParam( 'sShopURL' );
00765         }
00766 
00767         // #680 per language another URL
00768         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00769         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00770         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00771             $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00772             return $aLanguageURLs[$iLang];
00773         }
00774 
00775         //normal section
00776         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00777         if ( $sMallShopURL ) {
00778             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00779             return $sMallShopURL;
00780         }
00781 
00782         return $this->getConfigParam( 'sShopURL' );
00783     }
00784 
00792     public function getSslShopUrl( $iLang = null )
00793     {
00794         // #680 per language another URL
00795         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00796         $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00797         if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00798             $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00799             return $aLanguageSSLURLs[$iLang];
00800         }
00801 
00802         //mall mode
00803         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00804             $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00805             return $sMallSSLShopURL;
00806         }
00807 
00808         if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00809             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00810             return $sMallShopURL;
00811         }
00812 
00813         //normal section
00814         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00815             return $sSSLShopURL;
00816         }
00817 
00818         return $this->getShopUrl( $iLang );
00819     }
00820 
00826     public function getCoreUtilsUrl()
00827     {
00828         return $this->getCurrentShopUrl().'core/utils/';
00829     }
00830 
00839     public function getCurrentShopUrl($blAdmin = null)
00840     {
00841         if ($blAdmin===null) {
00842             $blAdmin = $this->isAdmin();
00843         }
00844         if ($blAdmin) {
00845             if ($this->isSsl()) {
00846 
00847                 $sUrl = $this->getConfigParam( 'sAdminSSLURL' );
00848                 if ( !$sUrl ) {
00849                     return $this->getSslShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00850                 }
00851                 return $sUrl;
00852             } else {
00853                 return $this->getShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00854             }
00855         } else {
00856             return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
00857         }
00858     }
00859 
00867     public function getShopCurrentUrl( $iLang = null )
00868     {
00869         if ( $this->isSsl() ) {
00870             $sURL = $this->getSSLShopURL( $iLang );
00871         } else {
00872             $sURL = $this->getShopURL( $iLang );
00873         }
00874 
00875         return oxUtilsUrl::getInstance()->processUrl( $sURL.'index.php', false );
00876     }
00877 
00886     public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00887     {
00888         return oxUtilsUrl::getInstance()->processUrl($this->getShopUrl( $iLang, $blAdmin).'index.php', false );
00889     }
00890 
00896     public function getShopSecureHomeUrl()
00897     {
00898         return  oxUtilsUrl::getInstance()->processUrl( $this->getSslShopUrl().'index.php', false );
00899     }
00900 
00906     public function getShopCurrency()
00907     {
00908         $iCurr = null;
00909         if ( ( null === ( $iCurr = oxConfig::getParameter( 'cur' ) ) ) ) {
00910             if ( null === ( $iCurr = oxConfig::getParameter( 'currency' ) ) ) {
00911                 $iCurr = oxSession::getVar( 'currency' );
00912             }
00913         }
00914         return (int) $iCurr;
00915     }
00916 
00922     public function getActShopCurrencyObject()
00923     {
00924         //caching currency as it does not change through the script
00925         //but not for unit tests as ther it changes always
00926         if ( !defined( 'OXID_PHP_UNIT' ) ) {
00927             if (!is_null($this->_oActCurrencyObject)) {
00928                 return $this->_oActCurrencyObject;
00929             }
00930         }
00931 
00932         $iCur = $this->getShopCurrency();
00933         $aCurrencies = $this->getCurrencyArray();
00934         if ( !isset( $aCurrencies[$iCur] ) ) {
00935             return $this->_oActCurrencyObject = reset( $aCurrencies ); // reset() returns the first element
00936         }
00937 
00938         return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00939     }
00940 
00948     public function setActShopCurrency( $iCur )
00949     {
00950         $aCurrencies = $this->getCurrencyArray();
00951         if ( isset( $aCurrencies[$iCur] ) ) {
00952             oxSession::setVar( 'currency', $iCur );
00953             $this->_oActCurrencyObject = null;
00954         }
00955     }
00956 
00964     public function getOutDir( $blAbsolute = true)
00965     {
00966         if ($blAbsolute) {
00967             return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
00968         } else {
00969             return $this->_sOutDir.'/';
00970         }
00971     }
00972 
00982     public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
00983     {
00984         $blSSL    = is_null($blSSL)?$this->isSsl():$blSSL;
00985         $blAdmin  = is_null($blAdmin)?$this->isAdmin():$blAdmin;
00986 
00987         if ( $blSSL ) {
00988             if ($blNativeImg && !$blAdmin) {
00989                 $sUrl = $this->getSslShopUrl();
00990             } else {
00991                 $sUrl = $this->getConfigParam('sSSLShopURL');
00992                 if (!$sUrl && $blAdmin) {
00993                     $sUrl = $this->getConfigParam('sAdminSSLURL').'../';
00994                 }
00995             }
00996         } else {
00997             $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
00998         }
00999 
01000         return $sUrl.$this->_sOutDir.'/';
01001     }
01002 
01017     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false )
01018     {
01019         if ( is_null($sTheme) ) {
01020             $sTheme = $this->getConfigParam( 'sTheme' );
01021         }
01022 
01023         if ( $blAdmin ) {
01024             $sTheme = 'admin';
01025         }
01026 
01027         $sBase    = $this->getOutDir( $blAbsolute );
01028         $sAbsBase = $this->getOutDir();
01029 
01030         $sLang = '-';
01031         // FALSE means skip language folder check
01032         if ( $iLang !== false ) {
01033             $oLang = oxLang::getInstance();
01034 
01035             if ( is_null( $iLang ) ) {
01036                 $iLang = $oLang->getEditLanguage();
01037             }
01038 
01039             $sLang = $oLang->getLanguageAbbr( $iLang );
01040         }
01041 
01042         if ( is_null($iShop) ) {
01043             $iShop = $this->getShopId();
01044         }
01045 
01046         //Load from
01047         $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01048         $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01049 
01050         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01051             return $sReturn;
01052         }
01053 
01054         $sReturn = false;
01055 
01056         // Check for custom template
01057         $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
01058         if ( !$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01059             $sReturn = $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute );
01060         }
01061 
01062         //test lang level ..
01063         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01064             $sReturn = $sBase . $sPath;
01065         }
01066 
01067         //test shop level ..
01068         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01069         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01070             $sReturn = $sBase . $sPath;
01071         }
01072 
01073 
01074         //test theme language level ..
01075         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01076         if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01077             $sReturn = $sBase . $sPath;
01078         }
01079 
01080         //test theme level ..
01081         $sPath = "$sTheme/$sDir/$sFile";
01082         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01083             $sReturn = $sBase . $sPath;
01084         }
01085 
01086         //test out language level ..
01087         $sPath = "$sLang/$sDir/$sFile";
01088         if ( !$sReturn &&  $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01089             $sReturn = $sBase . $sPath;
01090         }
01091 
01092         //test out level ..
01093         $sPath = "$sDir/$sFile";
01094         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01095             $sReturn = $sBase . $sPath;
01096         }
01097 
01098         if ( !$sReturn ) {
01099             // TODO: implement logic to log missing paths
01100         }
01101 
01102         // to cache
01103         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01104 
01105         return $sReturn;
01106     }
01107 
01122     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01123     {
01124         $sUrl = str_replace(
01125                                 $this->getOutDir(),
01126                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01127                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01128                             );
01129         return $sUrl;
01130     }
01131 
01140     public function getImagePath( $sFile, $blAdmin = false )
01141     {
01142         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01143     }
01144 
01154     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null )
01155     {
01156         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01157         return $this->getUrl( null, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01158     }
01159 
01167     public function getImageDir( $blAdmin = false )
01168     {
01169         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01170     }
01171 
01180     public function getPicturePath($sFile, $blAdmin = false )
01181     {
01182         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin );
01183     }
01184 
01192     public function getMasterPictureDir( $blAdmin = false )
01193     {
01194         return $this->getDir( null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01195     }
01196 
01205     public function getMasterPicturePath( $sFile, $blAdmin = false )
01206     {
01207         return $this->getDir( $sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01208     }
01209 
01222     public function getPictureUrl( $sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "0/nopic.jpg" )
01223     {
01224         if (!isset($blSSL)) {
01225             $blSSL = $this->isSsl();
01226         }
01227         if ( $sAltUrl = $this->getConfigParam( 'sAltImageDir' ) ) {
01228 
01229             if ( $this->isSsl() && $blSSL && $sSslAltUrl = $this->getConfigParam( 'sSSLAltImageDir' ) ) {
01230                 $sAltUrl = $sSslAltUrl;
01231             }
01232 
01233             if ( !is_null( $sFile ) ) {
01234                 $sAltUrl .= $sFile;
01235             }
01236 
01237             return $sAltUrl;
01238         }
01239 
01240         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01241 
01242         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01243 
01244 
01245         //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01246         if ( !$sUrl ) {
01247             $sUrl = $this->getUrl( $sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01248         }
01249         return $sUrl;
01250     }
01251 
01264     public function getIconUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null, $sDefPic = "icon/nopic_ico.jpg" )
01265     {
01266         return $this->getPictureUrl( $sFile, $blAdmin, $blSSL, $iLang, $iShopId, $sDefPic );
01267     }
01268 
01276     public function getPictureDir( $blAdmin )
01277     {
01278         return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01279     }
01280 
01289     public function getTemplatePath( $sFile, $blAdmin )
01290     {
01291         return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01292     }
01293 
01301     public function getTemplateDir( $blAdmin = false )
01302     {
01303         return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01304     }
01305 
01316     public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01317     {
01318         return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01319     }
01320 
01328     public function getTemplateBase( $blAdmin = false )
01329     {
01330         // Base template dir is the parent dir of template dir
01331         return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01332     }
01333 
01342     public function getResourcePath($sFile = '', $blAdmin = false )
01343     {
01344         return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01345     }
01346 
01357     public function getResourceUrl( $sFile = '', $blAdmin = false , $blSSL = null , $iLang = null )
01358     {
01359         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01360         return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang );
01361     }
01362 
01370     public function getResourceDir( $blAdmin )
01371     {
01372         return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01373     }
01374 
01386     public function getLanguagePath( $sFile, $blAdmin, $iLang = null, $iShop = null, $sTheme = null )
01387     {
01388         return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang, $iShop, $sTheme );
01389     }
01390 
01400     public function getStdLanguagePath( $sFile, $blAdmin, $iLang = null )
01401     {
01402         $sDir = null;
01403         if ( $iLang !== false ) {
01404             $sDir = oxLang::getInstance()->getLanguageAbbr( $iLang );
01405         }
01406 
01407         return $this->getDir( $sFile, $sDir, $blAdmin, $iLang, null, $this->getConfigParam( "sTheme" ), true, true );
01408     }
01409 
01417     public function getLanguageDir( $blAdmin )
01418     {
01419         return $this->getDir( null, null, $blAdmin );
01420     }
01421 
01429     public function getCurrencyArray( $iCurrency = null )
01430     {
01431         $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01432         if ( !is_array( $aConfCurrencies ) ) {
01433             return array();
01434         }
01435 
01436         if ( defined( 'OXID_PHP_UNIT' ) ) {
01437             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01438                 try{
01439                     $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01440                     if ( isset( $aAltCurrencies ) ) {
01441                         $aConfCurrencies = $aAltCurrencies;
01442                     }
01443                 } catch( Exception $e ) {
01444                     // if exception is thrown, use default
01445                 }
01446             }
01447         }
01448 
01449         // processing currency configuration data
01450         $aCurrencies = array();
01451         reset( $aConfCurrencies );
01452         while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01453             if ( $val ) {
01454                 $oCur = new oxStdClass();
01455                 $oCur->id      = $key;
01456                 $sCur = explode( '@', $val);
01457                 $oCur->name     = trim( $sCur[0] );
01458                 $oCur->rate     = trim( $sCur[1] );
01459                 $oCur->dec      = trim( $sCur[2] );
01460                 $oCur->thousand = trim( $sCur[3] );
01461                 $oCur->sign     = trim( $sCur[4] );
01462                 $oCur->decimal  = trim( $sCur[5] );
01463 
01464                 // change for US version
01465                 if ( isset( $sCur[6] ) ) {
01466                     $oCur->side = trim($sCur[6]);
01467                 }
01468 
01469                 if ( isset( $iCurrency) && $key == $iCurrency ) {
01470                     $oCur->selected = 1;
01471                 } else {
01472                     $oCur->selected = 0;
01473                 }
01474                 $aCurrencies[$key]= $oCur;
01475             }
01476 
01477             // #861C -  performance, do not load other currencies
01478             if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01479                 break;
01480             }
01481         }
01482         return $aCurrencies;
01483     }
01484 
01492     public function getCurrencyObject( $sName )
01493     {
01494         $aSearch = $this->getCurrencyArray();
01495         foreach ( $aSearch as $oCur ) {
01496             if ( $oCur->name == $sName ) {
01497                 return $oCur;
01498             }
01499         }
01500     }
01501 
01507     public function isDemoShop()
01508     {
01509         return $this->getConfigParam('blDemoShop');
01510     }
01511 
01517     public function getEdition()
01518     {
01519             return "CE";
01520 
01521 
01522     }
01523 
01529     public function getFullEdition()
01530     {
01531         $sEdition = $this->getEdition();
01532 
01533             if ($sEdition == "CE") {
01534                 return "Community Edition";
01535             }
01536 
01537 
01538 
01539         return $sEdition;
01540     }
01541 
01547     public function getVersion()
01548     {
01549         $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01550         return $sVersion;
01551     }
01552 
01558     public function getRevision()
01559     {
01560         try {
01561             $sFileName = getShopBasePath() . "/pkg.rev";
01562             $iRev = (int) trim(@file_get_contents($sFileName));
01563         } catch (Exception $e) {
01564             return false;
01565         }
01566 
01567         if (!$iRev) {
01568             return false;
01569         }
01570 
01571         return $iRev;
01572     }
01573 
01574 
01580     public function isMall()
01581     {
01582 
01583             return false;
01584     }
01585 
01595     public function detectVersion()
01596     {
01597     }
01598 
01599 
01600 
01613     public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '' )
01614     {
01615         switch ( $sVarType ) {
01616             case 'arr':
01617             case 'aarr':
01618                 if (is_array($sVarVal)) {
01619                     $sValue = serialize( $sVarVal );
01620                 } else {
01621                     // Deprecated functionality
01622                     $sValue  = $sVarVal ;
01623                     $sVarVal = unserialize( $sVarVal );
01624                 }
01625                 break;
01626             case 'bool':
01627                 //config param
01628                 $sVarVal = (( $sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
01629                 //db value
01630                 $sValue  = $sVarVal?"1":"";
01631                 break;
01632             default:
01633                 $sValue  = $sVarVal;
01634                 break;
01635         }
01636 
01637         if ( !$sShopId ) {
01638             $sShopId = $this->getShopId();
01639         }
01640 
01641         // Update value only for current shop
01642         if ($sShopId == $this->getShopId()) {
01643             $this->setConfigParam( $sVarName, $sVarVal );
01644         }
01645 
01646         $oDb = oxDb::getDb(true);
01647 
01648         $sShopIdQuoted     = $oDb->quote($sShopId);
01649         $sModuleQuoted     = $oDb->quote($sModule);
01650         $sVarNameQuoted    = $oDb->quote($sVarName);
01651         $sVarTypeQuoted    = $oDb->quote($sVarType);
01652         $sVarValueQuoted   = $oDb->quote($sValue);
01653         $sConfigKeyQuoted  = $oDb->quote($this->getConfigParam('sConfigKey'));
01654         $sNewOXIDdQuoted   = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
01655 
01656         $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
01657         $oDb->execute( $sQ );
01658 
01659         $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
01660                values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
01661 
01662         $oDb->execute( $sQ );
01663     }
01664 
01673     public function getShopConfVar( $sVarName, $sShopId = null )
01674     {
01675         if ( !$sShopId ) {
01676             $sShopId = $this->getShopId();
01677         }
01678 
01679         $oDb = oxDb::getDb(true);
01680         $sQ  = "select oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopId' and oxvarname = ".$oDb->quote($sVarName);
01681         $oRs = $oDb->Execute( $sQ );
01682 
01683         $sValue = null;
01684         if ( $oRs != false && $oRs->recordCount() > 0 ) {
01685             $sVarType = $oRs->fields['oxvartype'];
01686             $sVarVal  = $oRs->fields['oxvarvalue'];
01687             switch ( $sVarType ) {
01688                 case 'arr':
01689                 case 'aarr':
01690                     $sValue =  unserialize( $sVarVal );
01691                     break;
01692                 case 'bool':
01693                     $sValue =  ( $sVarVal == 'true' || $sVarVal == '1' );
01694                     break;
01695                 default:
01696                     $sValue = $sVarVal;
01697                     break;
01698             }
01699         }
01700         return $sValue;
01701     }
01702 
01708     public function isProductiveMode()
01709     {
01710         $blProductive = false;
01711 
01712         $blProductive = $this->getConfigParam( 'blProductive' );
01713         if ( !isset( $blProductive ) ) {
01714             $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01715             $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01716             $this->setConfigParam( 'blProductive', $blProductive );
01717         }
01718 
01719         return $blProductive;
01720     }
01721 
01722 
01723 
01729     public function getBaseShopId()
01730     {
01731 
01732             return 'oxbaseshop';
01733     }
01734 
01740     public function getActiveShop()
01741     {
01742         if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01743              $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01744             return $this->_oActShop;
01745         }
01746 
01747         $this->_oActShop = oxNew( 'oxshop' );
01748         $this->_oActShop->load( $this->getShopId() );
01749         return $this->_oActShop;
01750     }
01751 
01757     public function getActiveView()
01758     {
01759         if ( $this->_oActView != null ) {
01760             return $this->_oActView;
01761         }
01762 
01763         $this->_oActView = oxNew( 'oxubase' );
01764         return $this->_oActView;
01765     }
01766 
01774     public function setActiveView( $oView )
01775     {
01776         $this->_oActView = $oView;
01777     }
01778 
01784     public function isUtf()
01785     {
01786         return ( bool ) $this->getConfigParam( 'iUtfMode' );
01787     }
01788 
01794     public function getLogsDir()
01795     {
01796         return $this->getConfigParam( 'sShopDir' ).'log/';
01797     }
01798 
01806     public function isThemeOption( $sName )
01807     {
01808         return (bool) isset( $this->_aThemeConfigParams[$sName] );
01809     }
01810 
01811 }