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 
00217 
00223     protected $_sImageDir = 'img';
00224 
00230     protected $_sPictureDir = 'pictures';
00231 
00237     protected $_sTemplateDir = 'tpl';
00238 
00244     protected $_sResourceDir = 'src';
00245 
00251     protected $_blIsSsl = null;
00252 
00258     protected $_aAbsDynImageDir = array();
00259 
00265     protected $_oActCurrencyObject = null;
00266 
00274     public function getConfigParam( $sName )
00275     {
00276         if ( isset( $this->$sName ) ) {
00277             return $this->$sName;
00278         } elseif ( isset ( $this->_aConfigParams[$sName] ) ) {
00279             return $this->_aConfigParams[$sName];
00280         }
00281     }
00282 
00291     public function setConfigParam( $sName, $sValue )
00292     {
00293         if ( isset( $this->$sName ) ) {
00294             $this->$sName = $sValue;
00295         } else {
00296             $this->_aConfigParams[$sName] = $sValue;
00297         }
00298     }
00299 
00305     public function init()
00306     {
00307         include getShopBasePath().'config.inc.php';
00308         include getShopBasePath().'core/oxconfk.php';
00309 
00310         //adding trailing slashes
00311         $oFileUtils = oxUtilsFile::getInstance();
00312         $this->sShopDir     = $oFileUtils->normalizeDir($this->sShopDir);
00313         $this->sCompileDir  = $oFileUtils->normalizeDir($this->sCompileDir);
00314         $this->sShopURL     = $oFileUtils->normalizeDir($this->sShopURL);
00315         $this->sShopDir     = $oFileUtils->normalizeDir($this->sShopDir);
00316         $this->sSSLShopURL  = $oFileUtils->normalizeDir($this->sSSLShopURL);
00317         $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00318 
00319 
00320         // some important defaults
00321         if( !$this->getConfigParam( 'sDefaultLang' ) )
00322             $this->setConfigParam( 'sDefaultLang', 0 );
00323 
00324         $blLogChangesInAdmin = $this->getConfigParam( 'blLogChangesInAdmin' );
00325         if( !isset( $blLogChangesInAdmin ) )
00326             $this->setConfigParam( 'blLogChangesInAdmin', false );
00327 
00328         $blCheckTemplates = $this->getConfigParam( 'blCheckTemplates' );
00329         if( !isset( $blCheckTemplates ) )
00330             $this->setConfigParam( 'blCheckTemplates', false );
00331 
00332         $blAllowArticlesubclass = $this->getConfigParam( 'blAllowArticlesubclass' );
00333         if( !isset( $blAllowArticlesubclass ) )
00334             $this->setConfigParam( 'blAllowArticlesubclass', false );
00335 
00336         $iAdminListSize = $this->getConfigParam( 'iAdminListSize' );
00337         if( !isset( $iAdminListSize ) )
00338             $this->setConfigParam( 'iAdminListSize', 9 );
00339 
00340         // #1173M  for EE - not all pic are deleted
00341         $iPicCount = $this->getConfigParam( 'iPicCount' );
00342         if( !isset( $iPicCount ) )
00343             $this->setConfigParam( 'iPicCount', 12 );
00344 
00345         $iZoomPicCount = $this->getConfigParam( 'iZoomPicCount' );
00346         if( !isset( $iZoomPicCount ) )
00347             $this->setConfigParam( 'iZoomPicCount', 4 );
00348 
00349         //max shop id default value
00350         $iMaxShopId = $this->getConfigParam( 'iMaxShopId' );
00351         if( !isset( $iMaxShopId ) )
00352             $this->setConfigParam( 'iMaxShopId', 64 );
00353 
00354         // disabling caching according to DODGER #655 : disable Caching as it doesnt work good enought
00355         $this->setConfigParam( 'blTemplateCaching', false );
00356 
00357         //setting ADODB timeout
00358         global  $ADODB_SESS_LIFE;
00359         $ADODB_SESS_LIFE  = 1;
00360 
00361 
00362             /*
00363         $iSessionTimeout = null;
00364         if ( $this->isAdmin())
00365             $iSessionTimeout = $this->getConfigParam( 'iSessionTimeoutAdmin' );
00366         if ( !$this->isAdmin() || !$iSessionTimeout )
00367             $iSessionTimeout = $this->getConfigParam( 'iSessionTimeout' );
00368         if (!$iSessionTimeout)
00369             $iSessionTimeout = 60;*/
00370 
00371         // ADODB cachelifetime
00372         $iDBCacheLifeTime = $this->getConfigParam( 'iDBCacheLifeTime' );
00373         if( !isset( $iDBCacheLifeTime ) )
00374             $this->setConfigParam( 'iDBCacheLifeTime', 3600 ); // 1 hour
00375 
00376         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) )
00377             $this->setConfigParam( 'sSSLShopURL', $sSSLShopURL.'/' );
00378 
00379         $sCoreDir = $this->getConfigParam( 'sShopDir' );
00380         $this->setConfigParam( 'sCoreDir', $sCoreDir.'/core/' );
00381 
00382         //starting up the session
00383         $this->getSession()->start();
00384 
00385         try {
00386             $sShopID = $this->getShopId();
00387 
00388             // load now
00389             $this->_loadVarsFromDb( $sShopID );
00390 
00391         } catch ( oxConnectionException $oEx ) {
00392             $oEx->debugOut( $this->iDebug);
00393             if ( defined( 'OXID_PHP_UNIT' ) ) {
00394                 return false;
00395             } elseif ( 0 != $this->iDebug ) {
00396                 exit( $oEx->getString() );
00397             } else {
00398                 header( "HTTP/1.1 500 Internal Server Error");
00399                 header( "Location: offline.html");
00400                 header( "Connection: close");
00401             }
00402         }
00403 
00404         //application initialization
00405         $this->_oStart = new oxStart();
00406         $this->_oStart->appInit();
00407     }
00408 
00414     public static function getInstance()
00415     {
00416 
00417         if ( defined( 'OXID_PHP_UNIT' ) ) {
00418             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00419                 return modConfig::$unitMOD;
00420             }
00421         }
00422 
00423         if ( !self::$_instance instanceof oxConfig ) {
00424                 //exceptions from here go directly to global exception handler
00425                 //if no init is possible whole application has to die!
00426                 self::$_instance = new oxConfig();
00427                 self::$_instance->init();
00428         }
00429         return self::$_instance;
00430     }
00431 
00440     protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null )
00441     {
00442 
00443         $sQ = "select oxvarname, oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopID'";
00444         // dodger, allow loading from some vars only from baseshop
00445         if ( $aOnlyVars !== null ) {
00446             $blSep = false;
00447             $sIn  = '';
00448             foreach ( $aOnlyVars as $sField ) {
00449                 if ( $blSep ) {
00450                     $sIn .= ', ';
00451                 }
00452                 $sIn .= '"'.$sField.'"';
00453                 $blSep = true;
00454             }
00455             $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00456         }
00457 
00458         $oRs = oxDb::getDb()->execute( $sQ );
00459         if ( $oRs != false && $oRs->recordCount() > 0 ) {
00460             while ( !$oRs->EOF ) {
00461                 $sVarName = $oRs->fields[0];
00462                 $sVarType = $oRs->fields[1];
00463                 $sVarVal  = $oRs->fields[2];
00464 
00465                 //in sShopURL and sSSLShopURL cases we skip (for admin or when URL values are not set)
00466                 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00467                     ( !$sVarVal || $this->isAdmin() === true ) ) {
00468                     $oRs->moveNext();
00469                     continue;
00470                 }
00471 
00472                 switch ( $sVarType ) {
00473                     case 'arr':
00474                     case 'aarr':
00475                         $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00476                         break;
00477                     case 'bool':
00478                         $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00479                         break;
00480                     default:
00481                         $this->setConfigParam( $sVarName, $sVarVal );
00482                     }
00483 
00484 
00485                 if ( $sVarType == 'arr' || $sVarType == 'aarr' ) {
00486                 } elseif ( $sVarType == 'bool' ) {
00487                 } else {
00488 
00489                 }
00490 
00491                 $oRs->moveNext();
00492             }
00493         }
00494 
00495     }
00496 
00502     public function pageClose()
00503     {
00504         return $this->_oStart->pageClose();
00505     }
00506 
00520     public static function getParameter(  $sName, $blRaw = false )
00521     {
00522         if ( defined( 'OXID_PHP_UNIT' ) ) {
00523             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00524                 try{
00525                     return modConfig::getParameter(  $sName, $blRaw );
00526                 } catch( Exception $e ) {
00527                     // if exception is thrown, use default
00528                 }
00529             }
00530         }
00531 
00532         $sValue = null;
00533         if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_POST[$sName] ) ) {
00534             $sValue = $_POST[$sName];
00535         } elseif ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'GET' && isset( $_GET[$sName] ) ) {
00536             $sValue = $_GET[$sName];
00537         //<deprecated>
00538         } elseif ( oxSession::hasVar( $sName ) ) {
00539             $sValue = oxSession::getVar( $sName );
00540         //</deprecated>
00541         } else {
00542             $sValue = null;
00543         }
00544 
00545         // TODO: remove this after special charts concept implementation
00546         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00547         if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00548             self::checkSpecialChars( $sValue, $blRaw );
00549         }
00550 
00551         return $sValue;
00552     }
00553 
00561     public function getUploadedFile($sParamName)
00562     {
00563         return $_FILES[$sParamName];
00564     }
00565 
00574     public function setGlobalParameter( $sName, $sValue )
00575     {
00576         $this->_aGlobalParams[$sName] = $sValue;
00577     }
00578 
00586     public function getGlobalParameter( $sName )
00587     {
00588         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00589             return $this->_aGlobalParams[$sName];
00590         } else {
00591             return null;
00592         }
00593     }
00594 
00604     public static function checkSpecialChars( & $sValue, $aRaw = null )
00605     {
00606         if ( is_object( $sValue ) ) {
00607             return $sValue;
00608         }
00609 
00610         if ( is_array( $sValue ) ) {
00611             foreach ( $sValue as $sKey => $sVal ) {
00612                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00613                     $sValidKey = $sKey;
00614                     self::checkSpecialChars( $sValidKey );
00615                     self::checkSpecialChars( $sVal );
00616                     if ($sValidKey != $sKey) {
00617                         unset ($sValue[$sKey]);
00618                     }
00619                     $sValue[$sValidKey] = $sVal;
00620                 }
00621             }
00622         } else {
00623             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00624                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00625                                    $sValue );
00626         }
00627         return $sValue;
00628     }
00629 
00635     public function getShopId()
00636     {
00637         if ( $this->_iShopId !== null )
00638             return $this->_iShopId;
00639 
00640             $this->_iShopId = $this->getBaseShopId();
00641 
00642 
00643         oxSession::setVar( 'actshop', $this->_iShopId );
00644         return $this->_iShopId;
00645     }
00646 
00654     public function setShopId( $sShopId )
00655     {
00656         oxSession::setVar( 'actshop', $sShopId );
00657         $this->_iShopId = $sShopId;
00658     }
00659 
00660 
00666     public function isSsl()
00667     {
00668         if (!is_null($this->_blIsSsl)) {
00669             return $this->_blIsSsl;
00670         }
00671 
00672         $aServerVars     = oxUtilsServer::getInstance()->getServerVar();
00673         $aHttpsServerVar = oxUtilsServer::getInstance()->getServerVar( 'HTTPS' );
00674 
00675         $blIsSsl = ( isset( $aHttpsServerVar ) && $this->getConfigParam( 'sSSLShopURL' ) &&
00676                      ( $aHttpsServerVar == 'on' || $aHttpsServerVar == '1' ) ); // 1&1 provides "1"
00677 
00678         //additional special handling for profihost customers
00679         if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00680              ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false || 
00681              strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00682             $blIsssl = true;
00683         }
00684 
00685         //oxUtils::getInstance()->toStaticCache($sCacheName, $blIsSsl);
00686         $this->_blIsSsl = $blIsSsl;
00687 
00688         return $blIsSsl;
00689     }
00690 
00698     public function isCurrentUrl( $sURL )
00699     {
00700         if ( !$sURL ) {
00701             return false;
00702         }
00703 
00704         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'] );
00705 
00706         //remove double slashes all the way
00707         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00708         $sURL = str_replace( '/', '', $sURL );
00709 
00710         //so far comparing for the host is enought for us
00711         if ( strpos( $sURL, $sCurrentHost ) !== false ) {
00712             return true;
00713         }
00714 
00715         return false;
00716     }
00717 
00725     public function getShopUrl( $iLang = null )
00726     {
00727         if ( $this->isAdmin() ) {
00728             return $this->getConfigParam( 'sShopURL' );
00729         }
00730 
00731         // #680 per language another URL
00732         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00733         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00734         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) ) {
00735             return $aLanguageURLs[$iLang];
00736         }
00737 
00738         //normal section
00739         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00740         if ( $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] ) ) {
00760             return $aLanguageSSLURLs[$iLang];
00761         }
00762 
00763         //mall mode
00764         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00765             return $sMallSSLShopURL;
00766         }
00767 
00768         if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00769             return $sMallShopURL;
00770         }
00771 
00772         //normal section
00773         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00774             return $sSSLShopURL;
00775         }
00776 
00777         return $this->getShopUrl( $iLang );
00778     }
00779 
00785     public function getCoreUtilsUrl()
00786     {
00787         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00788             return $sSSLShopURL.'core/utils/';
00789         }
00790         return $this->getConfigParam( 'sShopURL' ).'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 $this->getSession()->url( $sURL.'index.php' );
00822     }
00823 
00829     public function getShopHomeUrl()
00830     {
00831         return $this->getSession()->url( $this->getShopUrl().'index.php' );
00832     }
00833 
00839     public function getShopSecureHomeUrl()
00840     {
00841         return $this->getSession()->url( $this->getSslShopUrl().'index.php' );
00842     }
00843 
00849     public function getShopCurrency()
00850     {
00851         return (int) oxConfig::getParameter( 'currency' );
00852     }
00853 
00859     public function getActShopCurrencyObject()
00860     {
00861         //caching currency as it does not change through the script
00862         //but not for unit tests as ther it changes always
00863         if ( !defined( 'OXID_PHP_UNIT' ) ) {
00864             if (!is_null($this->_oActCurrencyObject)) {
00865                 return $this->_oActCurrencyObject;
00866             }
00867         }
00868 
00869         $iCur = oxConfig::getParameter( 'cur' );
00870         if ( !isset( $iCur ) ) {
00871             $iCur = $this->getShopCurrency();
00872         }
00873 
00874         $aCurrencies = $this->getCurrencyArray();
00875         if ( !isset( $aCurrencies[$iCur] ) ) {
00876             return $this->_oActCurrencyObject = reset( $aCurrencies ); // reset() returns the first element
00877         }
00878 
00879         return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00880     }
00881 
00889     public function setActShopCurrency( $iCur )
00890     {
00891         $aCurrencies = $this->getCurrencyArray();
00892         if ( isset( $aCurrencies[$iCur] ) ) {
00893             oxSession::setVar( 'currency', $iCur );
00894             $this->_oActCurrencyObject = null;
00895         }
00896     }
00897 
00898 
00908     public function getNoSslImageDir( $blAdmin = false )
00909     {
00910         return $this->getImageUrl( $blAdmin, false );
00911     }
00912 
00920     public function getAbsAdminImageDir()
00921     {
00922         return $this->getImageDir( true );
00923 
00924     }
00925 
00940     /* is not used
00941     public function formatOutDir($sFile, $iLang = null, $blAdmin = false, $blNoThemes = false, $iShop = null)
00942     {
00943         //resolving theme and shop dir
00944         $sThemeDir  = ($blNoThemes || $blAdmin) ? "" : $this->getConfigParam( 'sTheme' );
00945 
00946         if (is_null($iShop))
00947             $iShop = $this->getShopId();
00948 
00949         $aShopDirs = array();
00950 
00951 
00952         if ($sThemeDir)
00953             $aShopDirs[] = "$sThemeDir/1/";
00954         else
00955             $aShopDirs[] = $this->getBaseShopId() . "/";
00956 
00957         //admin dir
00958         if ( $blAdmin ) {
00959             $aShopDirs = array('admin/');
00960         }
00961 
00962         if ($sFile) {
00963             //language dir
00964             if (is_null($iLang))
00965                 $iLang = oxLang::getInstance()->getBaseLanguage();
00966 
00967             $aLangs    = oxLang::getInstance()->getLanguageArray();
00968             //specific language dir and top dir
00969             $aLangDirs = array();
00970             if (isset($aLangs[$iLang]))
00971                 $aLangDirs[] = strtolower($aLangs[$iLang]->abbr . "/");
00972             $aLangDirs[] = "";
00973 
00974 
00975             //finally checking dir
00976             foreach ($aShopDirs as $sShopDir) {
00977                 foreach ($aLangDirs as $sLangDir) {
00978                     $sOut = "out/" . $sShopDir . $sLangDir . $sFile;
00979                     if (file_exists($this->getConfigParam('sShopDir'). $sOut))
00980                         return $sOut;
00981                 }
00982             }
00983         }
00984 
00985         //not language specific default dir
00986         foreach ($aShopDirs as $sShopDir) {
00987             $sOut = "out/" . $sShopDir;
00988             if (file_exists($this->getConfigParam('sShopDir'). $sOut))
00989                 return $sOut;
00990         }
00991     }*/
00992 
01000     public function getOutDir( $blAbsolute = true)
01001     {
01002         if ($blAbsolute) {
01003             return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
01004         } else {
01005             return $this->_sOutDir.'/';
01006         }
01007     }
01008 
01018     public function getOutUrl( $blSSL = null , $blNativeImg = false, $blAdmin = null )
01019     {
01020         $blSSL    = is_null($blSSL)?$this->isSsl():$blSSL;
01021         $blAdmin  = is_null($blAdmin)?$this->isAdmin():$blAdmin;
01022 
01023         if ( $blSSL ) {
01024             $sUrl = ($blNativeImg && !$blAdmin )?$this->getSslShopUrl():$this->getConfigParam( 'sSSLShopURL');
01025         } else {
01026             $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
01027         }
01028 
01029         return $sUrl.$this->_sOutDir.'/';
01030     }
01031 
01045     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true )
01046     {
01047         $sBase    = $this->getOutDir( $blAbsolute );
01048         $sAbsBase = $this->getOutDir();
01049 
01050         $oLang = oxLang::getInstance(); //getTplLanguage
01051 
01052         if ( is_null($iLang) ) {
01053             $iLang = $oLang->getEditLanguage();
01054         }
01055 
01056         $sLang = $oLang->getLanguageAbbr( $iLang );
01057 
01058         if ( is_null($iShop) ) {
01059             $iShop = $this->getShopId();
01060         }
01061 
01062         if ( is_null($sTheme) ) {
01063             $sTheme = $this->getConfigParam( 'sTheme' );
01064         }
01065 
01066         if ( $blAdmin ) {
01067             $sTheme = 'admin';
01068         }
01069 
01070         //Load from
01071         $sPath = "$sTheme/$iShop/$sLang/$sDir/$sFile";
01072         $sCacheKey = $sPath . "_$blAbsolute";
01073 
01074         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01075             return $sReturn;
01076         }
01077 
01078         $sReturn = false;
01079 
01080         //test lang level ..
01081         if ( !$sReturn && !$blAdmin && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath ) ) ) ) {
01082             $sReturn = $sBase . $sPath;
01083         }
01084 
01085         //test shop level ..
01086         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01087         if ( !$sReturn && !$blAdmin && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath ) ) ) ) {
01088             $sReturn = $sBase . $sPath;
01089         }
01090 
01091 
01092         //test theme language level ..
01093         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01094         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01095             $sReturn = $sBase . $sPath;
01096         }
01097 
01098         //test theme level ..
01099         $sPath = "$sTheme/$sDir/$sFile";
01100         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01101             $sReturn = $sBase . $sPath;
01102         }
01103 
01104         //test out language level ..
01105         $sPath = "$sLang/$sDir/$sFile";
01106         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01107             $sReturn = $sBase . $sPath;
01108         }
01109 
01110         //test out level ..
01111         $sPath = "$sDir/$sFile";
01112         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01113             $sReturn = $sBase . $sPath;
01114         }
01115 
01116         if ( !$sReturn ) {
01117             // TODO: log missing paths...
01118         }
01119 
01120         // to cache
01121         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01122 
01123         return $sReturn;
01124     }
01125 
01140     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01141     {
01142         $sUrl = str_replace(
01143                                 $this->getOutDir(),
01144                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01145                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01146                             );
01147         return $sUrl;
01148     }
01149 
01158     public function getImagePath( $sFile, $blAdmin = false )
01159     {
01160         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01161     }
01162 
01172     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null )
01173     {
01174         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01175         return $this->getUrl( null , $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01176     }
01177 
01185     public function getImageDir( $blAdmin = false )
01186     {
01187         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01188     }
01189 
01198     public function getPicturePath($sFile, $blAdmin = false )
01199     {
01200         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin );
01201     }
01202 
01214     public function getPictureUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null )
01215     {
01216         if ( $sAltUrl = $this->getConfigParam( 'sAltImageDir' ) ) {
01217 
01218             if ( $this->isSsl() ) {
01219                 $sAltUrl = str_replace( 'http://', 'https://', $sAltUrl );
01220             }
01221 
01222             if ( !is_null( $sFile ) ) {
01223                 $sAltUrl .= $sFile;
01224             }
01225 
01226             return $sAltUrl;
01227         }
01228         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, null, $iLang, $iShopId );
01229         if ( $sFile && $this->getConfigParam('blFormerTplSupport') ) {
01230             $sUrl = str_replace( $this->getPictureUrl( null, $blAdmin, $blSSL, $iLang, $iShopId ), '', $sUrl );
01231         }
01232         return $sUrl;
01233     }
01234 
01242     public function getPictureDir( $blAdmin )
01243     {
01244         return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01245     }
01246 
01255     public function getTemplatePath( $sFile, $blAdmin )
01256     {
01257         return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01258     }
01259 
01267     public function getTemplateDir( $blAdmin = false )
01268     {
01269         return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01270     }
01271 
01282     public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01283     {
01284         return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01285     }
01286 
01294     public function getTemplateBase( $blAdmin = false )
01295     {
01296         // Base template dir is the parent dir of template dir
01297         return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01298     }
01299 
01308     public function getResourcePath($sFile, $blAdmin = false )
01309     {
01310         return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01311     }
01312 
01323     public function getResourceUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null )
01324     {
01325         return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, false, $iLang );
01326     }
01327 
01335     public function getResourceDir( $blAdmin )
01336     {
01337         return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01338     }
01339 
01349     public function getLanguagePath( $sFile, $blAdmin, $iLang = null )
01350     {
01351         return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang );
01352     }
01353 
01361     public function getLanguageDir( $blAdmin )
01362     {
01363         return $this->getDir( null, null, $blAdmin );
01364     }
01365 
01373     public function getAbsImageDir()
01374     {
01375         return $this->getImageDir();
01376     }
01377 
01388     public function getDynImageDir( $sOverrideShopId = null, $blNoSsl = null )
01389     {
01390         return $this->getPictureUrl(null, false, $this->isSsl() && !$blNoSsl, null, $sOverrideShopId);
01391 
01392         /*
01393 
01394         $sCacheKey = "getDynImageDir_" . $this->isSsl() . "_" . $this->getShopId() . "_" .oxLang::getInstance()->getTplLanguage() . "_" . $sOverrideShopId . "_" . $blNoSsl;
01395         $sImageDir = oxUtils::getInstance()->fromStaticCache($sCacheKey);
01396 
01397         if ($sImageDir)
01398             return $sImageDir;
01399 
01400         if ( $sAltImageDir = $this->getConfigParam( 'sAltImageDir' ) ) {
01401             if ( $this->isSsl() ) {
01402                 $sAltImageDir = str_replace( 'http://', 'https://', $sAltImageDir );
01403             }
01404             oxUtils::getInstance()->toStaticCache($sCacheKey, $sAltImageDir);
01405             return $sAltImageDir;
01406         }
01407 
01408         //Tomas 2005-01-19
01409         //now it loads images only from either active shop either from oxbaseshop
01410         //later to be fixed to load images from any shop according $sOverrideShopId by implementing
01411         //function oxConfig::getShopURL($sOverrideShopId);
01412 
01413         $blNativeImg = $this->getConfigParam( 'blNativeImages' ) && $sOverrideShopId == $this->getShopId();
01414 
01415         if ( $this->isSsl() && !$blNoSsl ) {
01416             $sUrl = $blNativeImg ? $this->getSSLShopURL():$this->getConfigParam( 'sSSLShopURL');
01417         }
01418 
01419         if(!$sUrl) {
01420             $sUrl = $blNativeImg ? $this->getShopURL():$this->getConfigParam( 'sShopURL' );
01421         }
01422 
01423         $sLang = $this->getConfigParam( 'blUseDifferentDynDirs' )?oxLang::getInstance()->getTplLanguage():0;
01424         $sDir  = $this->_sPictureDir;
01425 
01426         $sImageDir = $sUrl . $this->formatOutDir($sDir, $iLang, false, true, $sOverrideShopId);
01427 
01428         oxUtils::getInstance()->toStaticCache($sCacheKey, $sImageDir);
01429 
01430 
01431         return $sImageDir;
01432         */
01433     }
01434 
01444     public function getAbsDynImageDir( $sOverrideShopId = null )
01445     {
01446         return $this->getPictureDir(false);
01447 
01448         /*
01449         //$sShop = is_null($sOverrideShopId)?$this->getShopId():$sOverrideShopId;
01450 
01451         if (isset($this->_aAbsDynImageDir[$sShop]))
01452             return $this->_aAbsDynImageDir[$sShop];
01453 
01454         $sRoot = $this->getConfigParam('sShopDir');
01455         $iLang = $this->getConfigParam( 'blUseDifferentDynDirs' )?oxLang::getInstance()->getTplLanguage():0;
01456         $sDir  = $this->_sPictureDir;
01457 
01458         $this->_aAbsDynImageDir[$sShop] = $sRoot . $this->formatOutDir($sDir, $iLang, false, true, $sOverrideShopId);
01459         return $this->_aAbsDynImageDir[$sShop];
01460         */
01461     }
01462 
01473     public function getTemplateFile( $sTemplate, $blAdmin = false )
01474     {
01475         return $this->getTemplatePath( $sTemplate, $blAdmin );
01476     }
01477 
01487     public function getBaseTemplateDir( $blAdmin = false )
01488     {
01489         return $this->getResourceUrl( null, $blAdmin );
01490         /*
01491         $blNativeImg = $this->getConfigParam( 'blNativeImages' ) && !$blAdmin;
01492 
01493         if ( $this->isSsl() ) {
01494             $sTemplateUrl = $blNativeImg?$this->getSSLShopURL():$this->getConfigParam( 'sSSLShopURL' );
01495         } else {
01496             $sTemplateUrl = $blNativeImg?$this->getShopURL():$this->getConfigParam( 'sShopURL' );
01497         }
01498 
01499         return $this->getResourceUrl( null, $blAdmin, $this->isSsl() );
01500         */
01501     }
01502 
01512     public function getBaseTplDir( $blAdmin = false )
01513     {
01514         //TODO: check usage
01515         return $this->getResourceUrl( null, $blAdmin);
01516     }
01517 
01525     public function getCurrencyArray( $iCurrency = null )
01526     {
01527         $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01528         if ( !is_array( $aConfCurrencies ) ) {
01529             return array();
01530         }
01531 
01532         if ( defined( 'OXID_PHP_UNIT' ) ) {
01533             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01534                 try{
01535                     $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01536                     if ( isset( $aAltCurrencies ) ) {
01537                         $aConfCurrencies = $aAltCurrencies;
01538                     }
01539                 } catch( Exception $e ) {
01540                     // if exception is thrown, use default
01541                 }
01542             }
01543         }
01544 
01545         // processing currency configuration data
01546         $aCurrencies = array();
01547         reset( $aConfCurrencies );
01548         while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01549             if ( $val ) {
01550                 $oCur = new oxStdClass();
01551                 $oCur->id      = $key;
01552                 $sCur = explode( '@', $val);
01553                 $oCur->name     = trim( $sCur[0] );
01554                 $oCur->rate     = trim( $sCur[1] );
01555                 $oCur->dec      = trim( $sCur[2] );
01556                 $oCur->thousand = trim( $sCur[3] );
01557                 $oCur->sign     = trim( $sCur[4] );
01558                 $oCur->decimal  = trim( $sCur[5] );
01559 
01560                 // change for US version
01561                 if ( isset( $sCur[6] ) )
01562                     $oCur->side = trim($sCur[6]);
01563 
01564                 if ( isset( $iCurrency) && $key == $iCurrency ) {
01565                     $oCur->selected = 1;
01566                 } else {
01567                     $oCur->selected = 0;
01568                 }
01569                 $aCurrencies[$key]= $oCur;
01570             }
01571 
01572             // #861C -  performance, do not load other currencies
01573             if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01574                 break;
01575             }
01576         }
01577         return $aCurrencies;
01578     }
01579 
01587     public function getCurrencyObject( $sName )
01588     {
01589         $aSearch = $this->getCurrencyArray();
01590         foreach ( $aSearch as $oCur ) {
01591             if ( $oCur->name == $sName ) {
01592                 return $oCur;
01593             }
01594         }
01595     }
01596 
01602     public function isDemoShop()
01603     {
01604         return $this->getConfigParam('blDemoShop');
01605     }
01606 
01612     public function getEdition()
01613     {
01614         return $this->getActiveShop()->oxshops__oxedition->value;
01615     }
01616 
01622     public function getFullEdition()
01623     {
01624         $sEdition = $this->getEdition();
01625 
01626             if ($sEdition == "CE") {
01627                 return "Community Edition";
01628             }
01629 
01630 
01631 
01632         return $sEdition;
01633     }
01634 
01640     public function getVersion()
01641     {
01642         $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01643         return $sVersion;
01644     }
01645 
01651     public function getRevision()
01652     {
01653         try {
01654             $sFileName = getShopBasePath() . "/pkg.rev";
01655             $iRev = (int) trim(@file_get_contents($sFileName));
01656         } catch (Exception $e) {
01657             return false;
01658         }
01659 
01660         if (!$iRev) {
01661             return false;
01662         }
01663 
01664         return $iRev;
01665     }
01666 
01667 
01673     public function isMall()
01674     {
01675 
01676             return false;
01677     }
01678 
01688     public function detectVersion()
01689     {
01690     }
01691 
01692 
01693 
01704     public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null )
01705     {
01706         if ( !$sShopId ) {
01707           $sShopId = $this->getShopId();
01708         }
01709 
01710         $sQ = "delete from oxconfig where oxshopid = '$sShopId' and oxvarname = '$sVarName'";
01711         oxDb::getDb()->Execute( $sQ );
01712         $sUid = oxUtilsObject::getInstance()->generateUID();
01713 
01714         $sUid     = mysql_real_escape_string($sUid);
01715         $sShopId  = mysql_real_escape_string($sShopId);
01716         $sVarName = mysql_real_escape_string($sVarName);
01717         $sVarVal  = mysql_real_escape_string($sVarVal);
01718 
01719         $sQ = "insert into oxconfig (oxid, oxshopid, oxvarname, oxvartype, oxvarvalue)
01720                values('$sUid', '$sShopId', '$sVarName', '$sVarType', ENCODE( '$sVarVal', '".$this->getConfigParam('sConfigKey')."'))";
01721 
01722         oxDb::getDb()->Execute($sQ);
01723     }
01724 
01733     public function getShopConfVar( $sVarName, $sShopId = null )
01734     {
01735         if ( !$sShopId ) {
01736             $sShopId = $this->getShopId();
01737         }
01738 
01739         $sQ  = "select oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopId' and oxvarname = '$sVarName'";
01740         $oRs = oxDb::getDb(true)->Execute( $sQ );
01741 
01742         $sValue = null;
01743         if ( $oRs != false && $oRs->recordCount() > 0 ) {
01744             $sVarType = $oRs->fields['oxvartype'];
01745             $sVarVal  = $oRs->fields['oxvarvalue'];
01746             switch ( $sVarType ) {
01747                 case 'arr':
01748                 case 'aarr':
01749                     $sValue =  unserialize( $sVarVal );
01750                     break;
01751                 case 'bool':
01752                     $sValue =  ( $sVarVal == 'true' || $sVarVal == '1' );
01753                     break;
01754                 default:
01755                     $sValue = $sVarVal;
01756                 }
01757         }
01758         return $sValue;
01759     }
01760 
01766     public function isProductiveMode()
01767     {
01768         $blProductive = false;
01769 
01770         $blProductive = $this->getConfigParam( 'blProductive' );
01771         if ( !isset( $blProductive ) ) {
01772             $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01773             $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01774             $this->setConfigParam( 'blProductive', $blProductive );
01775         }
01776 
01777         return $blProductive;
01778     }
01779 
01780 
01781 
01787     public function getBaseShopId()
01788     {
01789 
01790             return 'oxbaseshop';
01791     }
01792 
01798     public function getActiveShop()
01799     {
01800         if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() )
01801             return $this->_oActShop;
01802 
01803         $this->_oActShop = oxNew( 'oxshop' );
01804         $this->_oActShop->load( $this->getShopId() );
01805         return $this->_oActShop;
01806     }
01807 
01813     public function getActiveView()
01814     {
01815         if ( $this->_oActView != null ) {
01816             return $this->_oActView;
01817         }
01818 
01819         $this->_oActView = oxNew( 'oxubase' );
01820         return $this->_oActView;
01821     }
01822 
01830     public function setActiveView( $oView )
01831     {
01832         $this->_oActView = $oView;
01833     }
01834 }

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5