oxconfig.php

Go to the documentation of this file.
00001 <?php
00002 
00003 define( 'MAX_64BIT_INTEGER', '18446744073709551615' );
00004 
00010 class oxConfig extends oxSuperCfg
00011 {
00012     // this column of params are defined in config.inc.php file,
00013     // so for backwards compat. names starts without underscore
00014 
00020     protected $dbHost = null;
00021 
00027     protected $dbName = null;
00028 
00034     protected $dbUser = null;
00035 
00041     protected $dbPwd  = null;
00042 
00048     protected $dbType = null;
00049 
00055     protected $sShopURL = null;
00056 
00062     protected $sSSLShopURL = null;
00063 
00069     protected $sAdminSSLURL = null;
00070 
00076     protected $sShopDir = null;
00077 
00083     protected $sCompileDir = null;
00084 
00099     protected $iDebug = 0;
00100 
00106     protected $sAdminEmail = null;
00107 
00113     protected $blSessionUseCookies = null;
00114 
00120     protected $blSessionEnforceCookies = null;
00121 
00127     //protected $iMaxArticles = 6000;
00128 
00138     protected $blNativeImages = true;
00139 
00145     protected $aMultiShopTables = array( 'oxarticles', 'oxdiscount', 'oxcategories', 'oxattribute',
00146                                          'oxlinks', 'oxvoucherseries',
00147                                          'oxnews', 'oxselectlist', 'oxwrapping',
00148                                          'oxdeliveryset', 'oxdelivery', 'oxvendor', 'oxobject2category');
00149 
00155     private static $_instance = null;
00156 
00162     private $_oStart = null;
00163 
00164 
00170     protected $_oActShop       = null;
00171 
00179     protected $_oActView       = null;
00180 
00186     protected $_aGlobalParams = array();
00187 
00193     protected $_aConfigParams = array();
00194 
00200     protected $_iLanguageId = null;
00201 
00207     protected $_iShopId = null;
00208 
00209 
00215     protected $_sOutDir = 'out';
00216 
00222     protected $_sImageDir = 'img';
00223 
00229     protected $_sPictureDir = 'pictures';
00230 
00236     protected $_sTemplateDir = 'tpl';
00237 
00243     protected $_sResourceDir = 'src';
00244 
00250     protected $_blIsSsl = null;
00251 
00257     protected $_aAbsDynImageDir = array();
00258 
00264     protected $_oActCurrencyObject = null;
00265 
00273     public function getConfigParam( $sName )
00274     {
00275         if ( isset( $this->$sName ) ) {
00276             return $this->$sName;
00277         } elseif ( isset ( $this->_aConfigParams[$sName] ) ) {
00278             return $this->_aConfigParams[$sName];
00279         }
00280     }
00281 
00290     public function setConfigParam( $sName, $sValue )
00291     {
00292         if ( isset( $this->$sName ) ) {
00293             $this->$sName = $sValue;
00294         } else {
00295             $this->_aConfigParams[$sName] = $sValue;
00296         }
00297     }
00298 
00304     public function init()
00305     {
00306         include getShopBasePath().'config.inc.php';
00307         include getShopBasePath().'core/oxconfk.php';
00308 
00309         //adding trailing slashes
00310         $oFileUtils = oxUtilsFile::getInstance();
00311         $this->sShopDir     = $oFileUtils->normalizeDir($this->sShopDir);
00312         $this->sCompileDir  = $oFileUtils->normalizeDir($this->sCompileDir);
00313         $this->sShopURL     = $oFileUtils->normalizeDir($this->sShopURL);
00314         $this->sShopDir     = $oFileUtils->normalizeDir($this->sShopDir);
00315         $this->sSSLShopURL  = $oFileUtils->normalizeDir($this->sSSLShopURL);
00316         $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00317 
00318 
00319         // some important defaults
00320         if( !$this->getConfigParam( 'sDefaultLang' ) )
00321             $this->setConfigParam( 'sDefaultLang', 0 );
00322 
00323         $blLogChangesInAdmin = $this->getConfigParam( 'blLogChangesInAdmin' );
00324         if( !isset( $blLogChangesInAdmin ) )
00325             $this->setConfigParam( 'blLogChangesInAdmin', false );
00326 
00327         $blCheckTemplates = $this->getConfigParam( 'blCheckTemplates' );
00328         if( !isset( $blCheckTemplates ) )
00329             $this->setConfigParam( 'blCheckTemplates', false );
00330 
00331         $blAllowArticlesubclass = $this->getConfigParam( 'blAllowArticlesubclass' );
00332         if( !isset( $blAllowArticlesubclass ) )
00333             $this->setConfigParam( 'blAllowArticlesubclass', false );
00334 
00335         $iAdminListSize = $this->getConfigParam( 'iAdminListSize' );
00336         if( !isset( $iAdminListSize ) )
00337             $this->setConfigParam( 'iAdminListSize', 9 );
00338 
00339         // #1173M  for EE - not all pic are deleted
00340         $iPicCount = $this->getConfigParam( 'iPicCount' );
00341         if( !isset( $iPicCount ) )
00342             $this->setConfigParam( 'iPicCount', 12 );
00343 
00344         $iZoomPicCount = $this->getConfigParam( 'iZoomPicCount' );
00345         if( !isset( $iZoomPicCount ) )
00346             $this->setConfigParam( 'iZoomPicCount', 4 );
00347 
00348         //max shop id default value
00349         $iMaxShopId = $this->getConfigParam( 'iMaxShopId' );
00350         if( !isset( $iMaxShopId ) )
00351             $this->setConfigParam( 'iMaxShopId', 64 );
00352 
00353         // disabling caching according to DODGER #655 : disable Caching as it doesnt work good enought
00354         $this->setConfigParam( 'blTemplateCaching', false );
00355 
00356         //setting ADODB timeout
00357         global  $ADODB_SESS_LIFE;
00358         $ADODB_SESS_LIFE  = 1;
00359 
00360 
00361             /*
00362         $iSessionTimeout = null;
00363         if ( $this->isAdmin())
00364             $iSessionTimeout = $this->getConfigParam( 'iSessionTimeoutAdmin' );
00365         if ( !$this->isAdmin() || !$iSessionTimeout )
00366             $iSessionTimeout = $this->getConfigParam( 'iSessionTimeout' );
00367         if (!$iSessionTimeout)
00368             $iSessionTimeout = 60;*/
00369 
00370         // ADODB cachelifetime
00371         $iDBCacheLifeTime = $this->getConfigParam( 'iDBCacheLifeTime' );
00372         if( !isset( $iDBCacheLifeTime ) )
00373             $this->setConfigParam( 'iDBCacheLifeTime', 3600 ); // 1 hour
00374 
00375         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) )
00376             $this->setConfigParam( 'sSSLShopURL', $sSSLShopURL.'/' );
00377 
00378         $sCoreDir = $this->getConfigParam( 'sShopDir' );
00379         $this->setConfigParam( 'sCoreDir', $sCoreDir.'/core/' );
00380 
00381         try {
00382             //starting up the session
00383             $this->getSession()->start();
00384 
00385             $sShopID = $this->getShopId();
00386 
00387             // load now
00388             $this->_loadVarsFromDb( $sShopID );
00389 
00390         } catch ( oxConnectionException $oEx ) {
00391             $oEx->debugOut( $this->iDebug);
00392             if ( defined( 'OXID_PHP_UNIT' ) ) {
00393                 return false;
00394             } elseif ( 0 != $this->iDebug ) {
00395                 exit( $oEx->getString() );
00396             } else {
00397                 header( "HTTP/1.1 500 Internal Server Error");
00398                 header( "Location: offline.html");
00399                 header( "Connection: close");
00400             }
00401         } catch ( oxCookieException $oEx ) {
00402             // redirect to start page and display the error
00403             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00404             oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start' );
00405         }
00406 
00407         //application initialization
00408         $this->_oStart = new oxStart();
00409         $this->_oStart->appInit();
00410     }
00411 
00417     public static function getInstance()
00418     {
00419 
00420         if ( defined( 'OXID_PHP_UNIT' ) ) {
00421             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00422                 return modConfig::$unitMOD;
00423             }
00424         }
00425 
00426         if ( !self::$_instance instanceof oxConfig ) {
00427                 //exceptions from here go directly to global exception handler
00428                 //if no init is possible whole application has to die!
00429                 self::$_instance = new oxConfig();
00430                 self::$_instance->init();
00431         }
00432         return self::$_instance;
00433     }
00434 
00443     protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null )
00444     {
00445 
00446         $sQ = "select oxvarname, oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopID'";
00447         // dodger, allow loading from some vars only from baseshop
00448         if ( $aOnlyVars !== null ) {
00449             $blSep = false;
00450             $sIn  = '';
00451             foreach ( $aOnlyVars as $sField ) {
00452                 if ( $blSep ) {
00453                     $sIn .= ', ';
00454                 }
00455                 $sIn .= '"'.$sField.'"';
00456                 $blSep = true;
00457             }
00458             $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00459         }
00460 
00461         $oRs = oxDb::getDb()->execute( $sQ );
00462         if ( $oRs != false && $oRs->recordCount() > 0 ) {
00463             while ( !$oRs->EOF ) {
00464                 $sVarName = $oRs->fields[0];
00465                 $sVarType = $oRs->fields[1];
00466                 $sVarVal  = $oRs->fields[2];
00467 
00468                 //in sShopURL and sSSLShopURL cases we skip (for admin or when URL values are not set)
00469                 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00470                     ( !$sVarVal || $this->isAdmin() === true ) ) {
00471                     $oRs->moveNext();
00472                     continue;
00473                 }
00474 
00475                 switch ( $sVarType ) {
00476                     case 'arr':
00477                     case 'aarr':
00478                         $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00479                         break;
00480                     case 'bool':
00481                         $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00482                         break;
00483                     default:
00484                         $this->setConfigParam( $sVarName, $sVarVal );
00485                     }
00486 
00487 
00488                 if ( $sVarType == 'arr' || $sVarType == 'aarr' ) {
00489                 } elseif ( $sVarType == 'bool' ) {
00490                 } else {
00491 
00492                 }
00493 
00494                 $oRs->moveNext();
00495             }
00496         }
00497 
00498     }
00499 
00505     public function pageClose()
00506     {
00507         return $this->_oStart->pageClose();
00508     }
00509 
00523     public static function getParameter(  $sName, $blRaw = false )
00524     {
00525         if ( defined( 'OXID_PHP_UNIT' ) ) {
00526             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00527                 try{
00528                     return modConfig::getParameter(  $sName, $blRaw );
00529                 } catch( Exception $e ) {
00530                     // if exception is thrown, use default
00531                 }
00532             }
00533         }
00534 
00535         $sValue = null;
00536         if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_POST[$sName] ) ) {
00537             $sValue = $_POST[$sName];
00538         } elseif ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'GET' && isset( $_GET[$sName] ) ) {
00539             $sValue = $_GET[$sName];
00540         //<deprecated>
00541         } elseif ( oxSession::hasVar( $sName ) ) {
00542             $sValue = oxSession::getVar( $sName );
00543         //</deprecated>
00544         } else {
00545             $sValue = null;
00546         }
00547 
00548         // TODO: remove this after special charts concept implementation
00549         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00550         if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00551             self::checkSpecialChars( $sValue, $blRaw );
00552         }
00553 
00554         return $sValue;
00555     }
00556 
00564     public function getUploadedFile($sParamName)
00565     {
00566         return $_FILES[$sParamName];
00567     }
00568 
00577     public function setGlobalParameter( $sName, $sValue )
00578     {
00579         $this->_aGlobalParams[$sName] = $sValue;
00580     }
00581 
00589     public function getGlobalParameter( $sName )
00590     {
00591         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00592             return $this->_aGlobalParams[$sName];
00593         } else {
00594             return null;
00595         }
00596     }
00597 
00607     public static function checkSpecialChars( & $sValue, $aRaw = null )
00608     {
00609         if ( is_object( $sValue ) ) {
00610             return $sValue;
00611         }
00612 
00613         if ( is_array( $sValue ) ) {
00614             foreach ( $sValue as $sKey => $sVal ) {
00615                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00616                     $sValidKey = $sKey;
00617                     self::checkSpecialChars( $sValidKey );
00618                     self::checkSpecialChars( $sVal );
00619                     if ($sValidKey != $sKey) {
00620                         unset ($sValue[$sKey]);
00621                     }
00622                     $sValue[$sValidKey] = $sVal;
00623                 }
00624             }
00625         } else {
00626             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00627                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00628                                    $sValue );
00629         }
00630         return $sValue;
00631     }
00632 
00638     public function getShopId()
00639     {
00640         if ( $this->_iShopId !== null )
00641             return $this->_iShopId;
00642 
00643             $this->_iShopId = $this->getBaseShopId();
00644 
00645 
00646         oxSession::setVar( 'actshop', $this->_iShopId );
00647         return $this->_iShopId;
00648     }
00649 
00657     public function setShopId( $sShopId )
00658     {
00659         oxSession::setVar( 'actshop', $sShopId );
00660         $this->_iShopId = $sShopId;
00661     }
00662 
00663 
00669     public function isSsl()
00670     {
00671         if (!is_null($this->_blIsSsl)) {
00672             return $this->_blIsSsl;
00673         }
00674 
00675         $aServerVars     = oxUtilsServer::getInstance()->getServerVar();
00676         $aHttpsServerVar = oxUtilsServer::getInstance()->getServerVar( 'HTTPS' );
00677 
00678         $blIsSsl = ( isset( $aHttpsServerVar ) && $this->getConfigParam( 'sSSLShopURL' ) &&
00679                      ( $aHttpsServerVar == 'on' || $aHttpsServerVar == '1' ) ); // 1&1 provides "1"
00680 
00681         //additional special handling for profihost customers
00682         if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00683              ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00684              strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00685             $blIsssl = true;
00686         }
00687 
00688         //oxUtils::getInstance()->toStaticCache($sCacheName, $blIsSsl);
00689         $this->_blIsSsl = $blIsSsl;
00690 
00691         return $blIsSsl;
00692     }
00693 
00701     public function isCurrentUrl( $sURL )
00702     {
00703         if ( !$sURL ) {
00704             return false;
00705         }
00706 
00707         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'] );
00708 
00709         //remove double slashes all the way
00710         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00711         $sURL = str_replace( '/', '', $sURL );
00712 
00713         //so far comparing for the host is enought for us
00714         if ( strpos( $sURL, $sCurrentHost ) !== false ) {
00715             return true;
00716         }
00717 
00718         return false;
00719     }
00720 
00728     public function getShopUrl( $iLang = null )
00729     {
00730         if ( $this->isAdmin() ) {
00731             return $this->getConfigParam( 'sShopURL' );
00732         }
00733 
00734         // #680 per language another URL
00735         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00736         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00737         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) ) {
00738             return $aLanguageURLs[$iLang];
00739         }
00740 
00741         //normal section
00742         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00743         if ( $sMallShopURL ) {
00744             return $sMallShopURL;
00745         }
00746 
00747         return $this->getConfigParam( 'sShopURL' );
00748     }
00749 
00757     public function getSslShopUrl( $iLang = null )
00758     {
00759         // #680 per language another URL
00760         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00761         $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00762         if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) ) {
00763             return $aLanguageSSLURLs[$iLang];
00764         }
00765 
00766         //mall mode
00767         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00768             return $sMallSSLShopURL;
00769         }
00770 
00771         if ( ( $sMallShopURL = $this->getConfigParam( '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         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00791             return $sSSLShopURL.'core/utils/';
00792         }
00793         return $this->getConfigParam( 'sShopURL' ).'core/utils/';
00794     }
00795 
00801     public function getCurrentShopUrl()
00802     {
00803         if ( $this->isSsl() ) {
00804             return $this->getSslShopUrl();
00805         }
00806         return $this->getShopUrl();
00807     }
00808 
00816     public function getShopCurrentUrl( $iLang = null )
00817     {
00818         if ( $this->isSsl() ) {
00819             $sURL = $this->getSSLShopURL( $iLang );
00820         } else {
00821             $sURL = $this->getShopURL( $iLang );
00822         }
00823 
00824         return $this->getSession()->url( $sURL.'index.php' );
00825     }
00826 
00832     public function getShopHomeUrl()
00833     {
00834         return $this->getSession()->url( $this->getShopUrl().'index.php' );
00835     }
00836 
00842     public function getShopSecureHomeUrl()
00843     {
00844         return $this->getSession()->url( $this->getSslShopUrl().'index.php' );
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 , $blNativeImg = false, $blAdmin = null )
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 
01048     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true )
01049     {
01050         $sBase    = $this->getOutDir( $blAbsolute );
01051         $sAbsBase = $this->getOutDir();
01052 
01053         $oLang = oxLang::getInstance(); //getTplLanguage
01054 
01055         if ( is_null($iLang) ) {
01056             $iLang = $oLang->getEditLanguage();
01057         }
01058 
01059         $sLang = $oLang->getLanguageAbbr( $iLang );
01060 
01061         if ( is_null($iShop) ) {
01062             $iShop = $this->getShopId();
01063         }
01064 
01065         if ( is_null($sTheme) ) {
01066             $sTheme = $this->getConfigParam( 'sTheme' );
01067         }
01068 
01069         if ( $blAdmin ) {
01070             $sTheme = 'admin';
01071         }
01072 
01073         //Load from
01074         $sPath = "$sTheme/$iShop/$sLang/$sDir/$sFile";
01075         $sCacheKey = $sPath . "_$blAbsolute";
01076 
01077         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01078             return $sReturn;
01079         }
01080 
01081         $sReturn = false;
01082 
01083         //test lang level ..
01084         if ( !$sReturn && !$blAdmin && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath ) ) ) ) {
01085             $sReturn = $sBase . $sPath;
01086         }
01087 
01088         //test shop level ..
01089         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01090         if ( !$sReturn && !$blAdmin && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath ) ) ) ) {
01091             $sReturn = $sBase . $sPath;
01092         }
01093 
01094 
01095         //test theme language level ..
01096         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01097         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01098             $sReturn = $sBase . $sPath;
01099         }
01100 
01101         //test theme level ..
01102         $sPath = "$sTheme/$sDir/$sFile";
01103         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01104             $sReturn = $sBase . $sPath;
01105         }
01106 
01107         //test out language level ..
01108         $sPath = "$sLang/$sDir/$sFile";
01109         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01110             $sReturn = $sBase . $sPath;
01111         }
01112 
01113         //test out level ..
01114         $sPath = "$sDir/$sFile";
01115         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01116             $sReturn = $sBase . $sPath;
01117         }
01118 
01119         if ( !$sReturn ) {
01120             // TODO: log missing paths...
01121         }
01122 
01123         // to cache
01124         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01125 
01126         return $sReturn;
01127     }
01128 
01143     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01144     {
01145         $sUrl = str_replace(
01146                                 $this->getOutDir(),
01147                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01148                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01149                             );
01150         return $sUrl;
01151     }
01152 
01161     public function getImagePath( $sFile, $blAdmin = false )
01162     {
01163         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01164     }
01165 
01175     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null )
01176     {
01177         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01178         return $this->getUrl( null , $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01179     }
01180 
01188     public function getImageDir( $blAdmin = false )
01189     {
01190         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01191     }
01192 
01201     public function getPicturePath($sFile, $blAdmin = false )
01202     {
01203         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin );
01204     }
01205 
01217     public function getPictureUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null )
01218     {
01219         if ( $sAltUrl = $this->getConfigParam( 'sAltImageDir' ) ) {
01220 
01221             if ( $this->isSsl() ) {
01222                 $sAltUrl = str_replace( 'http://', 'https://', $sAltUrl );
01223             }
01224 
01225             if ( !is_null( $sFile ) ) {
01226                 $sAltUrl .= $sFile;
01227             }
01228 
01229             return $sAltUrl;
01230         }
01231         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, null, $iLang, $iShopId );
01232         if ( $sFile && $this->getConfigParam('blFormerTplSupport') ) {
01233             $sUrl = str_replace( $this->getPictureUrl( null, $blAdmin, $blSSL, $iLang, $iShopId ), '', $sUrl );
01234         }
01235         return $sUrl;
01236     }
01237 
01245     public function getPictureDir( $blAdmin )
01246     {
01247         return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01248     }
01249 
01258     public function getTemplatePath( $sFile, $blAdmin )
01259     {
01260         return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01261     }
01262 
01270     public function getTemplateDir( $blAdmin = false )
01271     {
01272         return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01273     }
01274 
01285     public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01286     {
01287         return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01288     }
01289 
01297     public function getTemplateBase( $blAdmin = false )
01298     {
01299         // Base template dir is the parent dir of template dir
01300         return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01301     }
01302 
01311     public function getResourcePath($sFile, $blAdmin = false )
01312     {
01313         return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01314     }
01315 
01326     public function getResourceUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null )
01327     {
01328         return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, false, $iLang );
01329     }
01330 
01338     public function getResourceDir( $blAdmin )
01339     {
01340         return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01341     }
01342 
01352     public function getLanguagePath( $sFile, $blAdmin, $iLang = null )
01353     {
01354         return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang );
01355     }
01356 
01364     public function getLanguageDir( $blAdmin )
01365     {
01366         return $this->getDir( null, null, $blAdmin );
01367     }
01368 
01376     public function getAbsImageDir()
01377     {
01378         return $this->getImageDir();
01379     }
01380 
01391     public function getDynImageDir( $sOverrideShopId = null, $blNoSsl = null )
01392     {
01393         return $this->getPictureUrl(null, false, $this->isSsl() && !$blNoSsl, null, $sOverrideShopId);
01394 
01395         /*
01396 
01397         $sCacheKey = "getDynImageDir_" . $this->isSsl() . "_" . $this->getShopId() . "_" .oxLang::getInstance()->getTplLanguage() . "_" . $sOverrideShopId . "_" . $blNoSsl;
01398         $sImageDir = oxUtils::getInstance()->fromStaticCache($sCacheKey);
01399 
01400         if ($sImageDir)
01401             return $sImageDir;
01402 
01403         if ( $sAltImageDir = $this->getConfigParam( 'sAltImageDir' ) ) {
01404             if ( $this->isSsl() ) {
01405                 $sAltImageDir = str_replace( 'http://', 'https://', $sAltImageDir );
01406             }
01407             oxUtils::getInstance()->toStaticCache($sCacheKey, $sAltImageDir);
01408             return $sAltImageDir;
01409         }
01410 
01411         //Tomas 2005-01-19
01412         //now it loads images only from either active shop either from oxbaseshop
01413         //later to be fixed to load images from any shop according $sOverrideShopId by implementing
01414         //function oxConfig::getShopURL($sOverrideShopId);
01415 
01416         $blNativeImg = $this->getConfigParam( 'blNativeImages' ) && $sOverrideShopId == $this->getShopId();
01417 
01418         if ( $this->isSsl() && !$blNoSsl ) {
01419             $sUrl = $blNativeImg ? $this->getSSLShopURL():$this->getConfigParam( 'sSSLShopURL');
01420         }
01421 
01422         if(!$sUrl) {
01423             $sUrl = $blNativeImg ? $this->getShopURL():$this->getConfigParam( 'sShopURL' );
01424         }
01425 
01426         $sLang = $this->getConfigParam( 'blUseDifferentDynDirs' )?oxLang::getInstance()->getTplLanguage():0;
01427         $sDir  = $this->_sPictureDir;
01428 
01429         $sImageDir = $sUrl . $this->formatOutDir($sDir, $iLang, false, true, $sOverrideShopId);
01430 
01431         oxUtils::getInstance()->toStaticCache($sCacheKey, $sImageDir);
01432 
01433 
01434         return $sImageDir;
01435         */
01436     }
01437 
01447     public function getAbsDynImageDir( $sOverrideShopId = null )
01448     {
01449         return $this->getPictureDir(false);
01450 
01451         /*
01452         //$sShop = is_null($sOverrideShopId)?$this->getShopId():$sOverrideShopId;
01453 
01454         if (isset($this->_aAbsDynImageDir[$sShop]))
01455             return $this->_aAbsDynImageDir[$sShop];
01456 
01457         $sRoot = $this->getConfigParam('sShopDir');
01458         $iLang = $this->getConfigParam( 'blUseDifferentDynDirs' )?oxLang::getInstance()->getTplLanguage():0;
01459         $sDir  = $this->_sPictureDir;
01460 
01461         $this->_aAbsDynImageDir[$sShop] = $sRoot . $this->formatOutDir($sDir, $iLang, false, true, $sOverrideShopId);
01462         return $this->_aAbsDynImageDir[$sShop];
01463         */
01464     }
01465 
01476     public function getTemplateFile( $sTemplate, $blAdmin = false )
01477     {
01478         return $this->getTemplatePath( $sTemplate, $blAdmin );
01479     }
01480 
01490     public function getBaseTemplateDir( $blAdmin = false )
01491     {
01492         return $this->getResourceUrl( null, $blAdmin );
01493         /*
01494         $blNativeImg = $this->getConfigParam( 'blNativeImages' ) && !$blAdmin;
01495 
01496         if ( $this->isSsl() ) {
01497             $sTemplateUrl = $blNativeImg?$this->getSSLShopURL():$this->getConfigParam( 'sSSLShopURL' );
01498         } else {
01499             $sTemplateUrl = $blNativeImg?$this->getShopURL():$this->getConfigParam( 'sShopURL' );
01500         }
01501 
01502         return $this->getResourceUrl( null, $blAdmin, $this->isSsl() );
01503         */
01504     }
01505 
01515     public function getBaseTplDir( $blAdmin = false )
01516     {
01517         //TODO: check usage
01518         return $this->getResourceUrl( null, $blAdmin);
01519     }
01520 
01528     public function getCurrencyArray( $iCurrency = null )
01529     {
01530         $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01531         if ( !is_array( $aConfCurrencies ) ) {
01532             return array();
01533         }
01534 
01535         if ( defined( 'OXID_PHP_UNIT' ) ) {
01536             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01537                 try{
01538                     $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01539                     if ( isset( $aAltCurrencies ) ) {
01540                         $aConfCurrencies = $aAltCurrencies;
01541                     }
01542                 } catch( Exception $e ) {
01543                     // if exception is thrown, use default
01544                 }
01545             }
01546         }
01547 
01548         // processing currency configuration data
01549         $aCurrencies = array();
01550         reset( $aConfCurrencies );
01551         while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01552             if ( $val ) {
01553                 $oCur = new oxStdClass();
01554                 $oCur->id      = $key;
01555                 $sCur = explode( '@', $val);
01556                 $oCur->name     = trim( $sCur[0] );
01557                 $oCur->rate     = trim( $sCur[1] );
01558                 $oCur->dec      = trim( $sCur[2] );
01559                 $oCur->thousand = trim( $sCur[3] );
01560                 $oCur->sign     = trim( $sCur[4] );
01561                 $oCur->decimal  = trim( $sCur[5] );
01562 
01563                 // change for US version
01564                 if ( isset( $sCur[6] ) )
01565                     $oCur->side = trim($sCur[6]);
01566 
01567                 if ( isset( $iCurrency) && $key == $iCurrency ) {
01568                     $oCur->selected = 1;
01569                 } else {
01570                     $oCur->selected = 0;
01571                 }
01572                 $aCurrencies[$key]= $oCur;
01573             }
01574 
01575             // #861C -  performance, do not load other currencies
01576             if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01577                 break;
01578             }
01579         }
01580         return $aCurrencies;
01581     }
01582 
01590     public function getCurrencyObject( $sName )
01591     {
01592         $aSearch = $this->getCurrencyArray();
01593         foreach ( $aSearch as $oCur ) {
01594             if ( $oCur->name == $sName ) {
01595                 return $oCur;
01596             }
01597         }
01598     }
01599 
01605     public function isDemoShop()
01606     {
01607         return $this->getConfigParam('blDemoShop');
01608     }
01609 
01615     public function getEdition()
01616     {
01617         return $this->getActiveShop()->oxshops__oxedition->value;
01618     }
01619 
01625     public function getFullEdition()
01626     {
01627         $sEdition = $this->getEdition();
01628 
01629             if ($sEdition == "CE") {
01630                 return "Community Edition";
01631             }
01632 
01633 
01634 
01635         return $sEdition;
01636     }
01637 
01643     public function getVersion()
01644     {
01645         $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01646         return $sVersion;
01647     }
01648 
01654     public function getRevision()
01655     {
01656         try {
01657             $sFileName = getShopBasePath() . "/pkg.rev";
01658             $iRev = (int) trim(@file_get_contents($sFileName));
01659         } catch (Exception $e) {
01660             return false;
01661         }
01662 
01663         if (!$iRev) {
01664             return false;
01665         }
01666 
01667         return $iRev;
01668     }
01669 
01670 
01676     public function isMall()
01677     {
01678 
01679             return false;
01680     }
01681 
01691     public function detectVersion()
01692     {
01693     }
01694 
01695 
01696 
01707     public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null )
01708     {
01709         if ( !$sShopId ) {
01710           $sShopId = $this->getShopId();
01711         }
01712 
01713         $sQ = "delete from oxconfig where oxshopid = '$sShopId' and oxvarname = '$sVarName'";
01714         oxDb::getDb()->Execute( $sQ );
01715         $sUid = oxUtilsObject::getInstance()->generateUID();
01716 
01717         $sUid     = mysql_real_escape_string($sUid);
01718         $sShopId  = mysql_real_escape_string($sShopId);
01719         $sVarName = mysql_real_escape_string($sVarName);
01720         $sVarVal  = mysql_real_escape_string($sVarVal);
01721 
01722         $sQ = "insert into oxconfig (oxid, oxshopid, oxvarname, oxvartype, oxvarvalue)
01723                values('$sUid', '$sShopId', '$sVarName', '$sVarType', ENCODE( '$sVarVal', '".$this->getConfigParam('sConfigKey')."'))";
01724 
01725         oxDb::getDb()->Execute($sQ);
01726     }
01727 
01736     public function getShopConfVar( $sVarName, $sShopId = null )
01737     {
01738         if ( !$sShopId ) {
01739             $sShopId = $this->getShopId();
01740         }
01741 
01742         $sQ  = "select oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopId' and oxvarname = '$sVarName'";
01743         $oRs = oxDb::getDb(true)->Execute( $sQ );
01744 
01745         $sValue = null;
01746         if ( $oRs != false && $oRs->recordCount() > 0 ) {
01747             $sVarType = $oRs->fields['oxvartype'];
01748             $sVarVal  = $oRs->fields['oxvarvalue'];
01749             switch ( $sVarType ) {
01750                 case 'arr':
01751                 case 'aarr':
01752                     $sValue =  unserialize( $sVarVal );
01753                     break;
01754                 case 'bool':
01755                     $sValue =  ( $sVarVal == 'true' || $sVarVal == '1' );
01756                     break;
01757                 default:
01758                     $sValue = $sVarVal;
01759                 }
01760         }
01761         return $sValue;
01762     }
01763 
01769     public function isProductiveMode()
01770     {
01771         $blProductive = false;
01772 
01773         $blProductive = $this->getConfigParam( 'blProductive' );
01774         if ( !isset( $blProductive ) ) {
01775             $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01776             $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01777             $this->setConfigParam( 'blProductive', $blProductive );
01778         }
01779 
01780         return $blProductive;
01781     }
01782 
01783 
01784 
01790     public function getBaseShopId()
01791     {
01792 
01793             return 'oxbaseshop';
01794     }
01795 
01801     public function getActiveShop()
01802     {
01803         if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() )
01804             return $this->_oActShop;
01805 
01806         $this->_oActShop = oxNew( 'oxshop' );
01807         $this->_oActShop->load( $this->getShopId() );
01808         return $this->_oActShop;
01809     }
01810 
01816     public function getActiveView()
01817     {
01818         if ( $this->_oActView != null ) {
01819             return $this->_oActView;
01820         }
01821 
01822         $this->_oActView = oxNew( 'oxubase' );
01823         return $this->_oActView;
01824     }
01825 
01833     public function setActiveView( $oView )
01834     {
01835         $this->_oActView = $oView;
01836     }
01837 }

Generated on Thu Feb 19 15:02:22 2009 for OXID eShop CE by  doxygen 1.5.5