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 $_iLanguageId = null;
00193 
00199     protected $_iShopId = null;
00200 
00201 
00207     protected $_sOutDir = 'out';
00208 
00214     protected $_sImageDir = 'img';
00215 
00221     protected $_sPictureDir = 'pictures';
00222 
00228     protected $_sMasterPictureDir = 'master';
00229 
00235     protected $_sTemplateDir = 'tpl';
00236 
00242     protected $_sResourceDir = 'src';
00243 
00249     protected $_blIsSsl = null;
00250 
00256     protected $_aAbsDynImageDir = array();
00257 
00263     protected $_oActCurrencyObject = null;
00264 
00272     public function getConfigParam( $sName )
00273     {
00274         if ( isset( $this->$sName ) ) {
00275             return $this->$sName;
00276         } elseif ( isset ( $this->_aConfigParams[$sName] ) ) {
00277             return $this->_aConfigParams[$sName];
00278         }
00279     }
00280 
00289     public function setConfigParam( $sName, $sValue )
00290     {
00291         if ( isset( $this->$sName ) ) {
00292             $this->$sName = $sValue;
00293         } else {
00294             $this->_aConfigParams[$sName] = $sValue;
00295         }
00296     }
00297 
00303     public function init()
00304     {
00305         include getShopBasePath().'config.inc.php';
00306         include getShopBasePath().'core/oxconfk.php';
00307 
00308         //adding trailing slashes
00309         $oFileUtils = oxUtilsFile::getInstance();
00310         $this->sShopDir     = $oFileUtils->normalizeDir($this->sShopDir);
00311         $this->sCompileDir  = $oFileUtils->normalizeDir($this->sCompileDir);
00312         $this->sShopURL     = $oFileUtils->normalizeDir($this->sShopURL);
00313         $this->sSSLShopURL  = $oFileUtils->normalizeDir($this->sSSLShopURL);
00314         $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00315 
00316 
00317         // some important defaults
00318         if( !$this->getConfigParam( 'sDefaultLang' ) )
00319             $this->setConfigParam( 'sDefaultLang', 0 );
00320 
00321         $blLogChangesInAdmin = $this->getConfigParam( 'blLogChangesInAdmin' );
00322         if( !isset( $blLogChangesInAdmin ) )
00323             $this->setConfigParam( 'blLogChangesInAdmin', false );
00324 
00325         $blCheckTemplates = $this->getConfigParam( 'blCheckTemplates' );
00326         if( !isset( $blCheckTemplates ) )
00327             $this->setConfigParam( 'blCheckTemplates', false );
00328 
00329         $blAllowArticlesubclass = $this->getConfigParam( 'blAllowArticlesubclass' );
00330         if( !isset( $blAllowArticlesubclass ) )
00331             $this->setConfigParam( 'blAllowArticlesubclass', false );
00332 
00333         $iAdminListSize = $this->getConfigParam( 'iAdminListSize' );
00334         if( !isset( $iAdminListSize ) )
00335             $this->setConfigParam( 'iAdminListSize', 9 );
00336 
00337         // #1173M  for EE - not all pic are deleted
00338         $iPicCount = $this->getConfigParam( 'iPicCount' );
00339         if( !isset( $iPicCount ) )
00340             $this->setConfigParam( 'iPicCount', 7 );
00341 
00342         $iZoomPicCount = $this->getConfigParam( 'iZoomPicCount' );
00343         if( !isset( $iZoomPicCount ) )
00344             $this->setConfigParam( 'iZoomPicCount', 4 );
00345 
00346         //max shop id default value
00347         $iMaxShopId = $this->getConfigParam( 'iMaxShopId' );
00348         if( !isset( $iMaxShopId ) )
00349             $this->setConfigParam( 'iMaxShopId', 64 );
00350 
00351         // disabling caching according to DODGER #655 : disable Caching as it doesnt work good enought
00352         $this->setConfigParam( 'blTemplateCaching', false );
00353 
00354         //setting ADODB timeout
00355         global  $ADODB_SESS_LIFE;
00356         $ADODB_SESS_LIFE  = 1;
00357 
00358 
00359             /*
00360         $iSessionTimeout = null;
00361         if ( $this->isAdmin())
00362             $iSessionTimeout = $this->getConfigParam( 'iSessionTimeoutAdmin' );
00363         if ( !$this->isAdmin() || !$iSessionTimeout )
00364             $iSessionTimeout = $this->getConfigParam( 'iSessionTimeout' );
00365         if (!$iSessionTimeout)
00366             $iSessionTimeout = 60;*/
00367 
00368         // ADODB cachelifetime
00369         $iDBCacheLifeTime = $this->getConfigParam( 'iDBCacheLifeTime' );
00370         if( !isset( $iDBCacheLifeTime ) )
00371             $this->setConfigParam( 'iDBCacheLifeTime', 3600 ); // 1 hour
00372 
00373         $sCoreDir = $this->getConfigParam( 'sShopDir' );
00374         $this->setConfigParam( 'sCoreDir', $sCoreDir.'/core/' );
00375 
00376         try {
00377             //starting up the session
00378             $this->getSession()->start();
00379 
00380             $sShopID = $this->getShopId();
00381 
00382             // load now
00383             $this->_loadVarsFromDb( $sShopID );
00384 
00385         } catch ( oxConnectionException $oEx ) {
00386             $oEx->debugOut();
00387             if ( defined( 'OXID_PHP_UNIT' ) ) {
00388                 return false;
00389             } elseif ( 0 != $this->iDebug ) {
00390                 oxUtils::getInstance()->showMessageAndExit( $oEx->getString() );
00391             } else {
00392                 header( "HTTP/1.1 500 Internal Server Error");
00393                 header( "Location: offline.html");
00394                 header( "Connection: close");
00395             }
00396         } catch ( oxCookieException $oEx ) {
00397             // redirect to start page and display the error
00398             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00399             oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start', true, 302 );
00400         }
00401 
00402         //application initialization
00403         $this->_oStart = new oxStart();
00404         $this->_oStart->appInit();
00405     }
00406 
00412     public static function getInstance()
00413     {
00414 
00415         if ( defined( 'OXID_PHP_UNIT' ) ) {
00416             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00417                 return modConfig::$unitMOD;
00418             }
00419         }
00420 
00421         if ( !self::$_instance instanceof oxConfig ) {
00422                 //exceptions from here go directly to global exception handler
00423                 //if no init is possible whole application has to die!
00424                 self::$_instance = new oxConfig();
00425                 self::$_instance->init();
00426         }
00427         return self::$_instance;
00428     }
00429 
00438     protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null )
00439     {
00440 
00441         $sQ = "select oxvarname, oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopID'";
00442         // dodger, allow loading from some vars only from baseshop
00443         if ( $aOnlyVars !== null ) {
00444             $blSep = false;
00445             $sIn  = '';
00446             foreach ( $aOnlyVars as $sField ) {
00447                 if ( $blSep ) {
00448                     $sIn .= ', ';
00449                 }
00450                 $sIn .= '"'.$sField.'"';
00451                 $blSep = true;
00452             }
00453             $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00454         }
00455 
00456         $oRs = oxDb::getDb()->execute( $sQ );
00457         if ( $oRs != false && $oRs->recordCount() > 0 ) {
00458             while ( !$oRs->EOF ) {
00459                 $sVarName = $oRs->fields[0];
00460                 $sVarType = $oRs->fields[1];
00461                 $sVarVal  = $oRs->fields[2];
00462 
00463                 //in sShopURL and sSSLShopURL cases we skip (for admin or when URL values are not set)
00464                 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00465                     ( !$sVarVal || $this->isAdmin() === true ) ) {
00466                     $oRs->moveNext();
00467                     continue;
00468                 }
00469 
00470                 switch ( $sVarType ) {
00471                     case 'arr':
00472                     case 'aarr':
00473                         $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00474                         break;
00475                     case 'bool':
00476                         $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00477                         break;
00478                     default:
00479                         $this->setConfigParam( $sVarName, $sVarVal );
00480                         break;
00481                 }
00482 
00483                 $oRs->moveNext();
00484             }
00485         }
00486 
00487     }
00488 
00494     public function pageClose()
00495     {
00496         return $this->_oStart->pageClose();
00497     }
00498 
00512     public static function getParameter(  $sName, $blRaw = false )
00513     {
00514         if ( defined( 'OXID_PHP_UNIT' ) ) {
00515             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00516                 try{
00517                     return modConfig::getParameter(  $sName, $blRaw );
00518                 } catch( Exception $e ) {
00519                     // if exception is thrown, use default
00520                 }
00521             }
00522         }
00523 
00524         $sValue = null;
00525         if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_POST[$sName] ) ) {
00526             $sValue = $_POST[$sName];
00527         } elseif ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'GET' && isset( $_GET[$sName] ) ) {
00528             $sValue = $_GET[$sName];
00529             //<deprecated>
00530         } elseif ( oxSession::hasVar( $sName ) ) {
00531             $sValue = oxSession::getVar( $sName );
00532             //</deprecated>
00533         } else {
00534             $sValue = null;
00535         }
00536 
00537         // TODO: remove this after special charts concept implementation
00538         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00539         if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00540             self::checkSpecialChars( $sValue, $blRaw );
00541         }
00542 
00543         return $sValue;
00544     }
00545 
00553     public function getUploadedFile($sParamName)
00554     {
00555         return $_FILES[$sParamName];
00556     }
00557 
00566     public function setGlobalParameter( $sName, $sValue )
00567     {
00568         $this->_aGlobalParams[$sName] = $sValue;
00569     }
00570 
00578     public function getGlobalParameter( $sName )
00579     {
00580         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00581             return $this->_aGlobalParams[$sName];
00582         } else {
00583             return null;
00584         }
00585     }
00586 
00596     public static function checkSpecialChars( & $sValue, $aRaw = null )
00597     {
00598         if ( is_object( $sValue ) ) {
00599             return $sValue;
00600         }
00601 
00602         if ( is_array( $sValue ) ) {
00603             $newValue = array();
00604             foreach ( $sValue as $sKey => $sVal ) {
00605                 $sValidKey = $sKey;
00606                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00607                     self::checkSpecialChars( $sValidKey );
00608                     self::checkSpecialChars( $sVal );
00609                     if ($sValidKey != $sKey) {
00610                         unset ($sValue[$sKey]);
00611                     }
00612                 }
00613                 $newValue[$sValidKey] = $sVal;
00614             }
00615             $sValue = $newValue;
00616         } else {
00617             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00618                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00619                                    $sValue );
00620         }
00621         return $sValue;
00622     }
00623 
00629     public function getShopId()
00630     {
00631         if ( $this->_iShopId !== null )
00632             return $this->_iShopId;
00633 
00634             $this->_iShopId = $this->getBaseShopId();
00635 
00636 
00637         oxSession::setVar( 'actshop', $this->_iShopId );
00638         return $this->_iShopId;
00639     }
00640 
00641 
00649     public function setShopId( $sShopId )
00650     {
00651         oxSession::setVar( 'actshop', $sShopId );
00652         $this->_iShopId = $sShopId;
00653     }
00654 
00655 
00661     public function isSsl()
00662     {
00663         if ( is_null( $this->_blIsSsl ) ) {
00664 
00665             $myUtilsServer   = oxUtilsServer::getInstance();
00666             $aServerVars     = $myUtilsServer->getServerVar();
00667             $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00668 
00669             $this->_blIsSsl = ( isset( $aHttpsServerVar ) && ( $this->getConfigParam( 'sSSLShopURL' ) || $this->getConfigParam( 'sMallSSLShopURL' ) ) &&
00670                          ( $aHttpsServerVar === 'on' || $aHttpsServerVar == '1' ) ); // "1&1" hoster provides "1"
00671 
00672             //additional special handling for profihost customers
00673             if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00674                  ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00675                  strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00676                 $this->_blIsSsl = true;
00677             }
00678         }
00679 
00680         return $this->_blIsSsl;
00681     }
00682 
00690     public function isCurrentUrl( $sURL )
00691     {
00692         if ( !$sURL ) {
00693             return false;
00694         }
00695 
00696         $oUtilsServer = oxUtilsServer::getInstance();
00697         $sHost = $oUtilsServer->getServerVar( 'HTTP_HOST' );
00698         $sScriptName = $oUtilsServer->getServerVar( 'SCRIPT_NAME' );
00699 
00700         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $sHost . $sScriptName );
00701 
00702         //remove double slashes all the way
00703         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00704         $sURL = str_replace( '/', '', $sURL );
00705 
00706         //so far comparing for the host is enought for us
00707         if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00708             return true;
00709         }
00710 
00711         return false;
00712     }
00713 
00722     public function getShopUrl( $iLang = null, $blAdmin = null )
00723     {
00724         $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00725         if ( $blAdmin ) {
00726             return $this->getConfigParam( 'sShopURL' );
00727         }
00728 
00729         // #680 per language another URL
00730         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00731         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00732         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00733             $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00734             return $aLanguageURLs[$iLang];
00735         }
00736 
00737         //normal section
00738         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00739         if ( $sMallShopURL ) {
00740             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00741             return $sMallShopURL;
00742         }
00743 
00744         return $this->getConfigParam( 'sShopURL' );
00745     }
00746 
00754     public function getSslShopUrl( $iLang = null )
00755     {
00756         // #680 per language another URL
00757         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00758         $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00759         if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00760             $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00761             return $aLanguageSSLURLs[$iLang];
00762         }
00763 
00764         //mall mode
00765         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00766             $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00767             return $sMallSSLShopURL;
00768         }
00769 
00770         if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00771             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00772             return $sMallShopURL;
00773         }
00774 
00775         //normal section
00776         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00777             return $sSSLShopURL;
00778         }
00779 
00780         return $this->getShopUrl( $iLang );
00781     }
00782 
00788     public function getCoreUtilsUrl()
00789     {
00790         return $this->getCurrentShopUrl().'core/utils/';
00791     }
00792 
00798     public function getCurrentShopUrl()
00799     {
00800         if ( $this->isSsl() ) {
00801             return $this->getSslShopUrl();
00802         }
00803         return $this->getShopUrl();
00804     }
00805 
00813     public function getShopCurrentUrl( $iLang = null )
00814     {
00815         if ( $this->isSsl() ) {
00816             $sURL = $this->getSSLShopURL( $iLang );
00817         } else {
00818             $sURL = $this->getShopURL( $iLang );
00819         }
00820 
00821         return oxUtilsUrl::getInstance()->processUrl( $sURL.'index.php', false );
00822     }
00823 
00832     public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00833     {
00834         return oxUtilsUrl::getInstance()->processUrl($this->getShopUrl( $iLang, $blAdmin).'index.php', false );
00835     }
00836 
00842     public function getShopSecureHomeUrl()
00843     {
00844         return  oxUtilsUrl::getInstance()->processUrl( $this->getSslShopUrl().'index.php', false );
00845     }
00846 
00852     public function getShopCurrency()
00853     {
00854         return (int) oxConfig::getParameter( 'currency' );
00855     }
00856 
00862     public function getActShopCurrencyObject()
00863     {
00864         //caching currency as it does not change through the script
00865         //but not for unit tests as ther it changes always
00866         if ( !defined( 'OXID_PHP_UNIT' ) ) {
00867             if (!is_null($this->_oActCurrencyObject)) {
00868                 return $this->_oActCurrencyObject;
00869             }
00870         }
00871 
00872         $iCur = oxConfig::getParameter( 'cur' );
00873         if ( !isset( $iCur ) ) {
00874             $iCur = $this->getShopCurrency();
00875         }
00876 
00877         $aCurrencies = $this->getCurrencyArray();
00878         if ( !isset( $aCurrencies[$iCur] ) ) {
00879             return $this->_oActCurrencyObject = reset( $aCurrencies ); // reset() returns the first element
00880         }
00881 
00882         return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00883     }
00884 
00892     public function setActShopCurrency( $iCur )
00893     {
00894         $aCurrencies = $this->getCurrencyArray();
00895         if ( isset( $aCurrencies[$iCur] ) ) {
00896             oxSession::setVar( 'currency', $iCur );
00897             $this->_oActCurrencyObject = null;
00898         }
00899     }
00900 
00901 
00911     public function getNoSslImageDir( $blAdmin = false )
00912     {
00913         return $this->getImageUrl( $blAdmin, false );
00914     }
00915 
00923     public function getAbsAdminImageDir()
00924     {
00925         return $this->getImageDir( true );
00926 
00927     }
00928 
00943     /* is not used
00944     public function formatOutDir($sFile, $iLang = null, $blAdmin = false, $blNoThemes = false, $iShop = null)
00945     {
00946         //resolving theme and shop dir
00947         $sThemeDir  = ($blNoThemes || $blAdmin) ? "" : $this->getConfigParam( 'sTheme' );
00948 
00949         if (is_null($iShop))
00950             $iShop = $this->getShopId();
00951 
00952         $aShopDirs = array();
00953 
00954 
00955         if ($sThemeDir)
00956             $aShopDirs[] = "$sThemeDir/1/";
00957         else
00958             $aShopDirs[] = $this->getBaseShopId() . "/";
00959 
00960         //admin dir
00961         if ( $blAdmin ) {
00962             $aShopDirs = array('admin/');
00963         }
00964 
00965         if ($sFile) {
00966             //language dir
00967             if (is_null($iLang))
00968                 $iLang = oxLang::getInstance()->getBaseLanguage();
00969 
00970             $aLangs    = oxLang::getInstance()->getLanguageArray();
00971             //specific language dir and top dir
00972             $aLangDirs = array();
00973             if (isset($aLangs[$iLang]))
00974                 $aLangDirs[] = strtolower($aLangs[$iLang]->abbr . "/");
00975             $aLangDirs[] = "";
00976 
00977 
00978             //finally checking dir
00979             foreach ($aShopDirs as $sShopDir) {
00980                 foreach ($aLangDirs as $sLangDir) {
00981                     $sOut = "out/" . $sShopDir . $sLangDir . $sFile;
00982                     if (file_exists($this->getConfigParam('sShopDir'). $sOut))
00983                         return $sOut;
00984                 }
00985             }
00986         }
00987 
00988         //not language specific default dir
00989         foreach ($aShopDirs as $sShopDir) {
00990             $sOut = "out/" . $sShopDir;
00991             if (file_exists($this->getConfigParam('sShopDir'). $sOut))
00992                 return $sOut;
00993         }
00994     }*/
00995 
01003     public function getOutDir( $blAbsolute = true)
01004     {
01005         if ($blAbsolute) {
01006             return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
01007         } else {
01008             return $this->_sOutDir.'/';
01009         }
01010     }
01011 
01021     public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
01022     {
01023         $blSSL    = is_null($blSSL)?$this->isSsl():$blSSL;
01024         $blAdmin  = is_null($blAdmin)?$this->isAdmin():$blAdmin;
01025 
01026         if ( $blSSL ) {
01027             $sUrl = ($blNativeImg && !$blAdmin )?$this->getSslShopUrl():$this->getConfigParam( 'sSSLShopURL');
01028         } else {
01029             $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
01030         }
01031 
01032         return $sUrl.$this->_sOutDir.'/';
01033     }
01034 
01049     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false )
01050     {
01051         if ( is_null($sTheme) ) {
01052             $sTheme = $this->getConfigParam( 'sTheme' );
01053         }
01054 
01055         if ( $blAdmin ) {
01056             $sTheme = 'admin';
01057         }
01058 
01059         $sBase    = $this->getOutDir( $blAbsolute );
01060         $sAbsBase = $this->getOutDir();
01061 
01062         $sLang = '-';
01063         // FALSE means skip language folder check
01064         if ( $iLang !== false ) {
01065             $oLang = oxLang::getInstance();
01066 
01067             if ( is_null( $iLang ) ) {
01068                 $iLang = $oLang->getEditLanguage();
01069             }
01070 
01071             $sLang = $oLang->getLanguageAbbr( $iLang );
01072         }
01073 
01074         if ( is_null($iShop) ) {
01075             $iShop = $this->getShopId();
01076         }
01077 
01078         //Load from
01079         $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01080         $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01081 
01082         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01083             return $sReturn;
01084         }
01085 
01086         $sReturn = false;
01087 
01088         // Check for custom template
01089         $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
01090         if ( !$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01091             $sReturn = $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute );
01092         }
01093 
01094         //test lang level ..
01095         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01096             $sReturn = $sBase . $sPath;
01097         }
01098 
01099         //test shop level ..
01100         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01101         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01102             $sReturn = $sBase . $sPath;
01103         }
01104 
01105 
01106         //test theme language level ..
01107         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01108         if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01109             $sReturn = $sBase . $sPath;
01110         }
01111 
01112         //test theme level ..
01113         $sPath = "$sTheme/$sDir/$sFile";
01114         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01115             $sReturn = $sBase . $sPath;
01116         }
01117 
01118         //test out language level ..
01119         $sPath = "$sLang/$sDir/$sFile";
01120         if ( !$sReturn &&  $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01121             $sReturn = $sBase . $sPath;
01122         }
01123 
01124         //test out level ..
01125         $sPath = "$sDir/$sFile";
01126         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01127             $sReturn = $sBase . $sPath;
01128         }
01129 
01130         if ( !$sReturn ) {
01131             // TODO: implement logic to log missing paths
01132         }
01133 
01134         // to cache
01135         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01136 
01137         return $sReturn;
01138     }
01139 
01154     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01155     {
01156         $sUrl = str_replace(
01157                                 $this->getOutDir(),
01158                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01159                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01160                             );
01161         return $sUrl;
01162     }
01163 
01172     public function getImagePath( $sFile, $blAdmin = false )
01173     {
01174         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01175     }
01176 
01186     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null )
01187     {
01188         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01189         return $this->getUrl( null, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01190     }
01191 
01199     public function getImageDir( $blAdmin = false )
01200     {
01201         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01202     }
01203 
01212     public function getPicturePath($sFile, $blAdmin = false )
01213     {
01214         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin );
01215     }
01216 
01224     public function getMasterPictureDir( $blAdmin = false )
01225     {
01226         return $this->getDir( null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01227     }
01228 
01237     public function getMasterPicturePath( $sFile, $blAdmin = false )
01238     {
01239         return $this->getDir( $sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01240     }
01241 
01254     public function getPictureUrl( $sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "0/nopic.jpg" )
01255     {
01256         if ( $sAltUrl = $this->getConfigParam( 'sAltImageDir' ) ) {
01257 
01258             if ( $this->isSsl() ) {
01259                 $sAltUrl = str_replace( 'http://', 'https://', $sAltUrl );
01260             }
01261 
01262             if ( !is_null( $sFile ) ) {
01263                 $sAltUrl .= $sFile;
01264             }
01265 
01266             return $sAltUrl;
01267         }
01268 
01269         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01270 
01271         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01272         if ( $sFile && $this->getConfigParam( 'blFormerTplSupport' ) && !$blAdmin ) {
01273             $sUrl = str_replace( $this->getPictureUrl( null, $blAdmin, $blSSL, $iLang, $iShopId ), '', $sUrl );
01274         }
01275 
01276         //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01277         if ( !$sUrl ) {
01278             $sUrl = $this->getUrl( $sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01279         }
01280         return $sUrl;
01281     }
01282 
01295     public function getIconUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null, $sDefPic = "icon/nopic_ico.jpg" )
01296     {
01297         return $this->getPictureUrl( $sFile, $blAdmin, $blSSL, $iLang, $iShopId, $sDefPic );
01298     }
01299 
01307     public function getPictureDir( $blAdmin )
01308     {
01309         return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01310     }
01311 
01320     public function getTemplatePath( $sFile, $blAdmin )
01321     {
01322         return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01323     }
01324 
01332     public function getTemplateDir( $blAdmin = false )
01333     {
01334         return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01335     }
01336 
01347     public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01348     {
01349         return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01350     }
01351 
01359     public function getTemplateBase( $blAdmin = false )
01360     {
01361         // Base template dir is the parent dir of template dir
01362         return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01363     }
01364 
01373     public function getResourcePath($sFile, $blAdmin = false )
01374     {
01375         return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01376     }
01377 
01388     public function getResourceUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null )
01389     {
01390         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01391         return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang );
01392     }
01393 
01401     public function getResourceDir( $blAdmin )
01402     {
01403         return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01404     }
01405 
01415     public function getLanguagePath( $sFile, $blAdmin, $iLang = null )
01416     {
01417         return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang );
01418     }
01419 
01429     public function getStdLanguagePath( $sFile, $blAdmin, $iLang = null )
01430     {
01431         $sDir = null;
01432         if ( $iLang !== false ) {
01433             $sDir = oxLang::getInstance()->getLanguageAbbr( $iLang );
01434         }
01435 
01436         return $this->getDir( $sFile, $sDir, $blAdmin, $iLang, null, $this->getConfigParam( "sTheme" ), true, true );
01437     }
01438 
01446     public function getLanguageDir( $blAdmin )
01447     {
01448         return $this->getDir( null, null, $blAdmin );
01449     }
01450 
01458     public function getAbsImageDir()
01459     {
01460         return $this->getImageDir();
01461     }
01462 
01473     public function getDynImageDir( $sOverrideShopId = null, $blNoSsl = null )
01474     {
01475         return $this->getPictureUrl(null, false, $this->isSsl() && !$blNoSsl, null, $sOverrideShopId);
01476 
01477         /*
01478 
01479         $sCacheKey = "getDynImageDir_" . $this->isSsl() . "_" . $this->getShopId() . "_" .oxLang::getInstance()->getTplLanguage() . "_" . $sOverrideShopId . "_" . $blNoSsl;
01480         $sImageDir = oxUtils::getInstance()->fromStaticCache($sCacheKey);
01481 
01482         if ($sImageDir)
01483             return $sImageDir;
01484 
01485         if ( $sAltImageDir = $this->getConfigParam( 'sAltImageDir' ) ) {
01486             if ( $this->isSsl() ) {
01487                 $sAltImageDir = str_replace( 'http://', 'https://', $sAltImageDir );
01488             }
01489             oxUtils::getInstance()->toStaticCache($sCacheKey, $sAltImageDir);
01490             return $sAltImageDir;
01491         }
01492 
01493         //Tomas 2005-01-19
01494         //now it loads images only from either active shop either from oxbaseshop
01495         //later to be fixed to load images from any shop according $sOverrideShopId by implementing
01496         //function oxConfig::getShopURL($sOverrideShopId);
01497 
01498         $blNativeImg = $this->getConfigParam( 'blNativeImages' ) && $sOverrideShopId == $this->getShopId();
01499 
01500         if ( $this->isSsl() && !$blNoSsl ) {
01501             $sUrl = $blNativeImg ? $this->getSSLShopURL():$this->getConfigParam( 'sSSLShopURL');
01502         }
01503 
01504         if(!$sUrl) {
01505             $sUrl = $blNativeImg ? $this->getShopURL():$this->getConfigParam( 'sShopURL' );
01506         }
01507 
01508         $sLang = $this->getConfigParam( 'blUseDifferentDynDirs' )?oxLang::getInstance()->getTplLanguage():0;
01509         $sDir  = $this->_sPictureDir;
01510 
01511         $sImageDir = $sUrl . $this->formatOutDir($sDir, $iLang, false, true, $sOverrideShopId);
01512 
01513         oxUtils::getInstance()->toStaticCache($sCacheKey, $sImageDir);
01514 
01515 
01516         return $sImageDir;
01517         */
01518     }
01519 
01529     public function getAbsDynImageDir( $sOverrideShopId = null )
01530     {
01531         return $this->getPictureDir(false);
01532 
01533         /*
01534         //$sShop = is_null($sOverrideShopId)?$this->getShopId():$sOverrideShopId;
01535 
01536         if (isset($this->_aAbsDynImageDir[$sShop]))
01537             return $this->_aAbsDynImageDir[$sShop];
01538 
01539         $sRoot = $this->getConfigParam('sShopDir');
01540         $iLang = $this->getConfigParam( 'blUseDifferentDynDirs' )?oxLang::getInstance()->getTplLanguage():0;
01541         $sDir  = $this->_sPictureDir;
01542 
01543         $this->_aAbsDynImageDir[$sShop] = $sRoot . $this->formatOutDir($sDir, $iLang, false, true, $sOverrideShopId);
01544         return $this->_aAbsDynImageDir[$sShop];
01545         */
01546     }
01547 
01558     public function getTemplateFile( $sTemplate, $blAdmin = false )
01559     {
01560         return $this->getTemplatePath( $sTemplate, $blAdmin );
01561     }
01562 
01572     public function getBaseTemplateDir( $blAdmin = false )
01573     {
01574         return $this->getResourceUrl( null, $blAdmin );
01575         /*
01576         $blNativeImg = $this->getConfigParam( 'blNativeImages' ) && !$blAdmin;
01577 
01578         if ( $this->isSsl() ) {
01579             $sTemplateUrl = $blNativeImg?$this->getSSLShopURL():$this->getConfigParam( 'sSSLShopURL' );
01580         } else {
01581             $sTemplateUrl = $blNativeImg?$this->getShopURL():$this->getConfigParam( 'sShopURL' );
01582         }
01583 
01584         return $this->getResourceUrl( null, $blAdmin, $this->isSsl() );
01585         */
01586     }
01587 
01597     public function getBaseTplDir( $blAdmin = false )
01598     {
01599         //TODO: check usage
01600         return $this->getResourceUrl( null, $blAdmin);
01601     }
01602 
01610     public function getCurrencyArray( $iCurrency = null )
01611     {
01612         $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01613         if ( !is_array( $aConfCurrencies ) ) {
01614             return array();
01615         }
01616 
01617         if ( defined( 'OXID_PHP_UNIT' ) ) {
01618             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01619                 try{
01620                     $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01621                     if ( isset( $aAltCurrencies ) ) {
01622                         $aConfCurrencies = $aAltCurrencies;
01623                     }
01624                 } catch( Exception $e ) {
01625                     // if exception is thrown, use default
01626                 }
01627             }
01628         }
01629 
01630         // processing currency configuration data
01631         $aCurrencies = array();
01632         reset( $aConfCurrencies );
01633         while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01634             if ( $val ) {
01635                 $oCur = new oxStdClass();
01636                 $oCur->id      = $key;
01637                 $sCur = explode( '@', $val);
01638                 $oCur->name     = trim( $sCur[0] );
01639                 $oCur->rate     = trim( $sCur[1] );
01640                 $oCur->dec      = trim( $sCur[2] );
01641                 $oCur->thousand = trim( $sCur[3] );
01642                 $oCur->sign     = trim( $sCur[4] );
01643                 $oCur->decimal  = trim( $sCur[5] );
01644 
01645                 // change for US version
01646                 if ( isset( $sCur[6] ) ) {
01647                     $oCur->side = trim($sCur[6]);
01648                 }
01649 
01650                 if ( isset( $iCurrency) && $key == $iCurrency ) {
01651                     $oCur->selected = 1;
01652                 } else {
01653                     $oCur->selected = 0;
01654                 }
01655                 $aCurrencies[$key]= $oCur;
01656             }
01657 
01658             // #861C -  performance, do not load other currencies
01659             if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01660                 break;
01661             }
01662         }
01663         return $aCurrencies;
01664     }
01665 
01673     public function getCurrencyObject( $sName )
01674     {
01675         $aSearch = $this->getCurrencyArray();
01676         foreach ( $aSearch as $oCur ) {
01677             if ( $oCur->name == $sName ) {
01678                 return $oCur;
01679             }
01680         }
01681     }
01682 
01688     public function isDemoShop()
01689     {
01690         return $this->getConfigParam('blDemoShop');
01691     }
01692 
01698     public function getEdition()
01699     {
01700             return "CE";
01701 
01702 
01703     }
01704 
01710     public function getFullEdition()
01711     {
01712         $sEdition = $this->getEdition();
01713 
01714             if ($sEdition == "CE") {
01715                 return "Community Edition";
01716             }
01717 
01718 
01719 
01720         return $sEdition;
01721     }
01722 
01728     public function getVersion()
01729     {
01730         $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01731         return $sVersion;
01732     }
01733 
01739     public function getRevision()
01740     {
01741         try {
01742             $sFileName = getShopBasePath() . "/pkg.rev";
01743             $iRev = (int) trim(@file_get_contents($sFileName));
01744         } catch (Exception $e) {
01745             return false;
01746         }
01747 
01748         if (!$iRev) {
01749             return false;
01750         }
01751 
01752         return $iRev;
01753     }
01754 
01755 
01761     public function isMall()
01762     {
01763 
01764             return false;
01765     }
01766 
01776     public function detectVersion()
01777     {
01778     }
01779 
01780 
01781 
01793     public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null )
01794     {
01795         switch ( $sVarType ) {
01796             case 'arr':
01797             case 'aarr':
01798                 if (is_array($sVarVal)) {
01799                     $sValue = serialize( $sVarVal );
01800                 } else {
01801                     // Deprecated functionality
01802                     $sValue  = $sVarVal ;
01803                     $sVarVal = unserialize( $sVarVal );
01804                 }
01805                 break;
01806             case 'bool':
01807                 //config param
01808                 $sVarVal = (( $sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
01809                 //db value
01810                 $sValue  = $sVarVal?"1":"";
01811                 break;
01812             default:
01813                 $sValue  = $sVarVal;
01814                 break;
01815         }
01816 
01817         if ( !$sShopId ) {
01818             $sShopId = $this->getShopId();
01819         }
01820 
01821         // Update value only for current shop
01822         if ($sShopId == $this->getShopId()) {
01823             $this->setConfigParam( $sVarName, $sVarVal );
01824         }
01825 
01826         $oDb = oxDb::getDb();
01827         $sQ = "delete from oxconfig where oxshopid = '$sShopId' and oxvarname = '$sVarName'";
01828         $oDb->execute( $sQ );
01829 
01830         $sNewOXIDdQuoted  = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
01831         $sShopIdQuoted    = $oDb->quote($sShopId);
01832         $sVarNameQuoted   = $oDb->quote($sVarName);
01833         $sVarTypeQuoted   = $oDb->quote($sVarType);
01834         $sVarValueQuoted  = $oDb->quote($sValue);
01835         $sConfigKeyQuoted = $oDb->quote($this->getConfigParam('sConfigKey'));
01836 
01837         $sQ = "insert into oxconfig (oxid, oxshopid, oxvarname, oxvartype, oxvarvalue)
01838                values($sNewOXIDdQuoted, $sShopIdQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted))";
01839 
01840         $oDb->execute( $sQ );
01841     }
01842 
01851     public function getShopConfVar( $sVarName, $sShopId = null )
01852     {
01853         if ( !$sShopId ) {
01854             $sShopId = $this->getShopId();
01855         }
01856 
01857         $oDb = oxDb::getDb(true);
01858         $sQ  = "select oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopId' and oxvarname = ".$oDb->quote($sVarName);
01859         $oRs = $oDb->Execute( $sQ );
01860 
01861         $sValue = null;
01862         if ( $oRs != false && $oRs->recordCount() > 0 ) {
01863             $sVarType = $oRs->fields['oxvartype'];
01864             $sVarVal  = $oRs->fields['oxvarvalue'];
01865             switch ( $sVarType ) {
01866                 case 'arr':
01867                 case 'aarr':
01868                     $sValue =  unserialize( $sVarVal );
01869                     break;
01870                 case 'bool':
01871                     $sValue =  ( $sVarVal == 'true' || $sVarVal == '1' );
01872                     break;
01873                 default:
01874                     $sValue = $sVarVal;
01875                     break;
01876             }
01877         }
01878         return $sValue;
01879     }
01880 
01886     public function isProductiveMode()
01887     {
01888         $blProductive = false;
01889 
01890         $blProductive = $this->getConfigParam( 'blProductive' );
01891         if ( !isset( $blProductive ) ) {
01892             $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01893             $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01894             $this->setConfigParam( 'blProductive', $blProductive );
01895         }
01896 
01897         return $blProductive;
01898     }
01899 
01900 
01901 
01907     public function getBaseShopId()
01908     {
01909 
01910             return 'oxbaseshop';
01911     }
01912 
01918     public function getActiveShop()
01919     {
01920         if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01921              $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01922             return $this->_oActShop;
01923         }
01924 
01925         $this->_oActShop = oxNew( 'oxshop' );
01926         $this->_oActShop->load( $this->getShopId() );
01927         return $this->_oActShop;
01928     }
01929 
01935     public function getActiveView()
01936     {
01937         if ( $this->_oActView != null ) {
01938             return $this->_oActView;
01939         }
01940 
01941         $this->_oActView = oxNew( 'oxubase' );
01942         return $this->_oActView;
01943     }
01944 
01952     public function setActiveView( $oView )
01953     {
01954         $this->_oActView = $oView;
01955     }
01956 
01962     public function isUtf()
01963     {
01964         return ( bool ) $this->getConfigParam( 'iUtfMode' );
01965     }
01966 
01972     public function getLogsDir()
01973     {
01974         return $this->getConfigParam( 'sShopDir' ).'log/';
01975     }
01976 }