oxconfig.php

Go to the documentation of this file.
00001 <?php
00002 
00003 define( 'MAX_64BIT_INTEGER', '18446744073709551615' );
00004 
00009 class oxConfig extends oxSuperCfg
00010 {
00011     // this column of params are defined in config.inc.php file,
00012     // so for backwards compat. names starts without underscore
00013 
00019     protected $dbHost = null;
00020 
00026     protected $dbName = null;
00027 
00033     protected $dbUser = null;
00034 
00040     protected $dbPwd  = null;
00041 
00047     protected $dbType = null;
00048 
00054     protected $sShopURL = null;
00055 
00061     protected $sSSLShopURL = null;
00062 
00068     protected $sAdminSSLURL = null;
00069 
00075     protected $sShopDir = null;
00076 
00082     protected $sCompileDir = null;
00083 
00098     protected $iDebug = 0;
00099 
00105     protected $sAdminEmail = null;
00106 
00112     protected $blSessionUseCookies = null;
00113 
00119     //protected $iMaxArticles = 6000;
00120 
00130     protected $blNativeImages = true;
00131 
00137     protected $aMultiShopTables = array( 'oxarticles', 'oxdiscount', 'oxcategories', 'oxattribute',
00138                                          'oxlinks', 'oxvoucherseries', 'oxmanufacturers',
00139                                          'oxnews', 'oxselectlist', 'oxwrapping',
00140                                          'oxdeliveryset', 'oxdelivery', 'oxvendor', 'oxobject2category');
00141 
00147     private static $_instance = null;
00148 
00154     private $_oStart = null;
00155 
00156 
00162     protected $_oActShop       = null;
00163 
00171     protected $_oActView       = null;
00172 
00178     protected $_aGlobalParams = array();
00179 
00185     protected $_aConfigParams = array();
00186 
00192     protected $_aThemeConfigParams = array();
00193 
00199     protected $_iLanguageId = null;
00200 
00206     protected $_iShopId = null;
00207 
00208 
00214     protected $_sOutDir = 'out';
00215 
00221     protected $_sImageDir = 'img';
00222 
00228     protected $_sPictureDir = 'pictures';
00229 
00235     protected $_sMasterPictureDir = 'master';
00236 
00242     protected $_sTemplateDir = 'tpl';
00243 
00249     protected $_sResourceDir = 'src';
00250 
00256     protected $_blIsSsl = null;
00257 
00263     protected $_aAbsDynImageDir = array();
00264 
00270     protected $_oActCurrencyObject = null;
00271 
00277     const OXMODULE_THEME_PREFIX = 'theme:';
00278 
00286     public function getConfigParam( $sName )
00287     {
00288         if ( defined( 'OXID_PHP_UNIT' ) ) {
00289             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00290                 $sValue = modConfig::$unitMOD->getModConfigParam( $sName );
00291                 if ( $sValue !== null ) {
00292                     return $sValue;
00293                 }
00294             }
00295         }
00296 
00297         if ( isset( $this->$sName ) ) {
00298             return $this->$sName;
00299         } elseif ( isset ( $this->_aConfigParams[$sName] ) ) {
00300             return $this->_aConfigParams[$sName];
00301         }
00302     }
00303 
00312     public function setConfigParam( $sName, $sValue )
00313     {
00314         if ( isset( $this->$sName ) ) {
00315             $this->$sName = $sValue;
00316         } else {
00317             $this->_aConfigParams[$sName] = $sValue;
00318         }
00319     }
00320 
00326     protected function _processSeoCall()
00327     {
00328         // TODO: refactor shop bootstrap and parse url params as soon as possible
00329         if (isSearchEngineUrl()) {
00330             oxNew('oxSeoDecoder')->processSeoCall();
00331         }
00332     }
00333 
00339     public function init()
00340     {
00341         include getShopBasePath().'config.inc.php';
00342         include getShopBasePath().'core/oxconfk.php';
00343 
00344         //adding trailing slashes
00345         $oFileUtils = oxUtilsFile::getInstance();
00346         $this->sShopDir     = $oFileUtils->normalizeDir($this->sShopDir);
00347         $this->sCompileDir  = $oFileUtils->normalizeDir($this->sCompileDir);
00348         $this->sShopURL     = $oFileUtils->normalizeDir($this->sShopURL);
00349         $this->sSSLShopURL  = $oFileUtils->normalizeDir($this->sSSLShopURL);
00350         $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00351 
00352 
00353         // some important defaults
00354         if( !$this->getConfigParam( 'sDefaultLang' ) )
00355             $this->setConfigParam( 'sDefaultLang', 0 );
00356 
00357 
00358         $this->setConfigParam( 'sTheme', 'basic' );
00359 
00360 
00361         $blLogChangesInAdmin = $this->getConfigParam( 'blLogChangesInAdmin' );
00362         if( !isset( $blLogChangesInAdmin ) )
00363             $this->setConfigParam( 'blLogChangesInAdmin', false );
00364 
00365         $blCheckTemplates = $this->getConfigParam( 'blCheckTemplates' );
00366         if( !isset( $blCheckTemplates ) )
00367             $this->setConfigParam( 'blCheckTemplates', false );
00368 
00369         $blAllowArticlesubclass = $this->getConfigParam( 'blAllowArticlesubclass' );
00370         if( !isset( $blAllowArticlesubclass ) )
00371             $this->setConfigParam( 'blAllowArticlesubclass', false );
00372 
00373         $iAdminListSize = $this->getConfigParam( 'iAdminListSize' );
00374         if( !isset( $iAdminListSize ) )
00375             $this->setConfigParam( 'iAdminListSize', 9 );
00376 
00377         // #1173M  for EE - not all pic are deleted
00378         $iPicCount = $this->getConfigParam( 'iPicCount' );
00379         if( !isset( $iPicCount ) )
00380             $this->setConfigParam( 'iPicCount', 7 );
00381 
00382         $iZoomPicCount = $this->getConfigParam( 'iZoomPicCount' );
00383         if( !isset( $iZoomPicCount ) )
00384             $this->setConfigParam( 'iZoomPicCount', 4 );
00385 
00386         //max shop id default value
00387         $iMaxShopId = $this->getConfigParam( 'iMaxShopId' );
00388         if( !isset( $iMaxShopId ) )
00389             $this->setConfigParam( 'iMaxShopId', 64 );
00390 
00391         // disabling caching according to DODGER #655 : disable Caching as it doesnt work good enought
00392         $this->setConfigParam( 'blTemplateCaching', false );
00393 
00394         //setting ADODB timeout
00395         global  $ADODB_SESS_LIFE;
00396         $ADODB_SESS_LIFE  = 1;
00397 
00398         // ADODB cachelifetime
00399         $iDBCacheLifeTime = $this->getConfigParam( 'iDBCacheLifeTime' );
00400         if( !isset( $iDBCacheLifeTime ) )
00401             $this->setConfigParam( 'iDBCacheLifeTime', 3600 ); // 1 hour
00402 
00403         $sCoreDir = $this->getConfigParam( 'sShopDir' );
00404         $this->setConfigParam( 'sCoreDir', $sCoreDir.'/core/' );
00405 
00406         try {
00407             $sShopID = $this->getShopId();
00408             $blConfigLoaded = $this->_loadVarsFromDb( $sShopID );
00409 
00410             // load now
00411             if ( empty($sShopID) || !$blConfigLoaded ) {
00412                 // if no config values where loaded (some problmems with DB), throwing an exception
00413                 $oEx = oxNew( "oxConnectionException" );
00414                 $oEx->setMessage( "Unable to load shop config values from database" );
00415                 throw $oEx;
00416             }
00417 
00418             // loading theme config options
00419             $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') );
00420 
00421             // checking if custom theme (which has defined parent theme) config options should be loaded over parent theme (#3362)
00422             if ( $this->getConfigParam('sCustomTheme') ) {
00423                 $this->_loadVarsFromDb( $sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme') );
00424             }
00425 
00426 
00427             $this->_processSeoCall();
00428 
00429             //starting up the session
00430             $this->getSession()->start();
00431 
00432         } catch ( oxConnectionException $oEx ) {
00433 
00434             $oEx->debugOut();
00435             if ( defined( 'OXID_PHP_UNIT' ) ) {
00436                 return false;
00437             } elseif ( 0 != $this->iDebug ) {
00438                 oxUtils::getInstance()->showMessageAndExit( $oEx->getString() );
00439             } else {
00440                 header( "HTTP/1.1 500 Internal Server Error");
00441                 header( "Location: offline.html");
00442                 header( "Connection: close");
00443             }
00444         } catch ( oxCookieException $oEx ) {
00445 
00446             $this->_processSeoCall();
00447 
00448             //starting up the session
00449             $this->getSession()->start();
00450 
00451             // redirect to start page and display the error
00452             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00453             oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start', true, 302 );
00454         }
00455 
00456 
00457         //application initialization
00458         $this->_oStart = new oxStart();
00459         $this->_oStart->appInit();
00460     }
00461 
00467     public static function getInstance()
00468     {
00469 
00470         if ( defined( 'OXID_PHP_UNIT' ) ) {
00471             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00472                 return modConfig::$unitMOD;
00473             }
00474         }
00475 
00476         if ( !self::$_instance instanceof oxConfig ) {
00477                 //exceptions from here go directly to global exception handler
00478                 //if no init is possible whole application has to die!
00479                 self::$_instance = new oxConfig();
00480                 self::$_instance->init();
00481         }
00482         return self::$_instance;
00483     }
00484 
00494     protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null, $sModule = '' )
00495     {
00496         $oDb = oxDb::getDb();
00497 
00498         $sQ = "select oxvarname, oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '$sShopID' and oxmodule=".$oDb->quote($sModule);
00499         // dodger, allow loading from some vars only from baseshop
00500         if ( $aOnlyVars !== null ) {
00501             $blSep = false;
00502             $sIn  = '';
00503             foreach ( $aOnlyVars as $sField ) {
00504                 if ( $blSep ) {
00505                     $sIn .= ', ';
00506                 }
00507                 $sIn .= '"'.$sField.'"';
00508                 $blSep = true;
00509             }
00510             $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00511         }
00512 
00513         $oRs = $oDb->execute( $sQ );
00514 
00515         if ( $oRs != false && $oRs->recordCount() > 0 ) {
00516             while ( !$oRs->EOF ) {
00517                 $sVarName = $oRs->fields[0];
00518                 $sVarType = $oRs->fields[1];
00519                 $sVarVal  = $oRs->fields[2];
00520 
00521                 //in sShopURL and sSSLShopURL cases we skip (for admin or when URL values are not set)
00522                 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00523                     ( !$sVarVal || $this->isAdmin() === true ) ) {
00524                     $oRs->moveNext();
00525                     continue;
00526                 }
00527 
00528                 $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
00529 
00530                 //setting theme options array
00531                 if ( $sModule != '' ) {
00532                     $this->_aThemeConfigParams[$sVarName] = $sModule;
00533                 }
00534 
00535                 $oRs->moveNext();
00536             }
00537 
00538             return true;
00539         } else {
00540             return false;
00541         }
00542     }
00543 
00553     protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
00554     {
00555         switch ( $sVarType ) {
00556             case 'arr':
00557             case 'aarr':
00558                 $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00559                 break;
00560             case 'bool':
00561                 $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00562                 break;
00563             default:
00564                 $this->setConfigParam( $sVarName, $sVarVal );
00565                 break;
00566         }
00567     }
00568 
00574     public function pageClose()
00575     {
00576         return $this->_oStart->pageClose();
00577     }
00578 
00590     public static function getParameter(  $sName, $blRaw = false )
00591     {
00592         if ( defined( 'OXID_PHP_UNIT' ) ) {
00593             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00594                 try{
00595                     $sValue = modConfig::getParameter(  $sName, $blRaw );
00596 
00597                     // TODO: remove this after special chars concept implementation
00598                     $blIsAdmin = modConfig::getInstance()->isAdmin();
00599                     if ( $sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00600                         self::checkSpecialChars( $sValue, $blRaw );
00601                     }
00602 
00603                     return $sValue;
00604                 } catch( Exception $e ) {
00605                     // if exception is thrown, use default
00606                 }
00607             }
00608         }
00609 
00610         $sValue = null;
00611 
00612         if ( isset( $_POST[$sName] ) ) {
00613             $sValue = $_POST[$sName];
00614         } elseif ( isset( $_GET[$sName] ) ) {
00615             $sValue = $_GET[$sName];
00616         }
00617 
00618         // TODO: remove this after special chars concept implementation
00619         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00620         if ( $sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00621             self::checkSpecialChars( $sValue, $blRaw );
00622         }
00623 
00624         return $sValue;
00625     }
00626 
00634     public function getUploadedFile($sParamName)
00635     {
00636         return $_FILES[$sParamName];
00637     }
00638 
00647     public function setGlobalParameter( $sName, $sValue )
00648     {
00649         $this->_aGlobalParams[$sName] = $sValue;
00650     }
00651 
00659     public function getGlobalParameter( $sName )
00660     {
00661         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00662             return $this->_aGlobalParams[$sName];
00663         } else {
00664             return null;
00665         }
00666     }
00667 
00677     public static function checkSpecialChars( & $sValue, $aRaw = null )
00678     {
00679         if ( is_object( $sValue ) ) {
00680             return $sValue;
00681         }
00682 
00683         if ( is_array( $sValue ) ) {
00684             $newValue = array();
00685             foreach ( $sValue as $sKey => $sVal ) {
00686                 $sValidKey = $sKey;
00687                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00688                     self::checkSpecialChars( $sValidKey );
00689                     self::checkSpecialChars( $sVal );
00690                     if ($sValidKey != $sKey) {
00691                         unset ($sValue[$sKey]);
00692                     }
00693                 }
00694                 $newValue[$sValidKey] = $sVal;
00695             }
00696             $sValue = $newValue;
00697         } elseif ( is_string( $sValue ) ) {
00698             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00699                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00700                                    $sValue );
00701         }
00702         return $sValue;
00703     }
00704 
00710     public function getShopId()
00711     {
00712         if ( $this->_iShopId !== null )
00713             return $this->_iShopId;
00714 
00715             $this->_iShopId = $this->getBaseShopId();
00716 
00717 
00718         oxSession::setVar( 'actshop', $this->_iShopId );
00719         return $this->_iShopId;
00720     }
00721 
00722 
00730     public function setShopId( $sShopId )
00731     {
00732         oxSession::setVar( 'actshop', $sShopId );
00733         $this->_iShopId = $sShopId;
00734     }
00735 
00736 
00742     public function isSsl()
00743     {
00744         if ( is_null( $this->_blIsSsl ) ) {
00745 
00746             $myUtilsServer   = oxUtilsServer::getInstance();
00747             $aServerVars     = $myUtilsServer->getServerVar();
00748             $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00749 
00750             $this->_blIsSsl = false;
00751             if (isset( $aHttpsServerVar ) && ($aHttpsServerVar === 'on' || $aHttpsServerVar === 'ON' || $aHttpsServerVar == '1' )) {
00752                 // "1&1" hoster provides "1"
00753                 $this->_blIsSsl = ($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
00754                 if ($this->isAdmin() && !$this->_blIsSsl) {
00755                     $this->_blIsSsl = $this->getConfigParam('sAdminSSLURL');
00756                 }
00757             }
00758 
00759             //additional special handling for profihost customers
00760             if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00761                  ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00762                  strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00763                 $this->_blIsSsl = true;
00764             }
00765         }
00766 
00767         return $this->_blIsSsl;
00768     }
00769 
00777     public function isCurrentUrl( $sURL )
00778     {
00779         if ( !$sURL ) {
00780             return false;
00781         }
00782 
00783         $oUtilsServer = oxUtilsServer::getInstance();
00784 
00785         // #4010: force_sid added in https to every link
00786         preg_match("/^(https?:\/\/)?([^\/]+)/i", $sURL, $matches);
00787         $sUrlHost = $matches[2];
00788 
00789         // #4010: force_sid added in https to every link
00790         preg_match("/^(https?:\/\/)?([^\/]+)/i", $oUtilsServer->getServerVar( 'HTTP_HOST' ), $matches);
00791         $sRealHost = $matches[2];
00792 
00793         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $oUtilsServer->getServerVar( 'HTTP_HOST' ) . $oUtilsServer->getServerVar( 'SCRIPT_NAME' ) );
00794 
00795         //remove double slashes all the way
00796         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00797         $sURL = str_replace( '/', '', $sURL );
00798 
00799         if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00800 
00801             //bug fix #0002991
00802             if ( $sUrlHost == $sRealHost ) {
00803                 return true;
00804             }
00805         }
00806 
00807         return false;
00808     }
00809 
00818     public function getShopUrl( $iLang = null, $blAdmin = null )
00819     {
00820         $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00821         if ( $blAdmin ) {
00822             return $this->getConfigParam( 'sShopURL' );
00823         }
00824 
00825         // #680 per language another URL
00826         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00827         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00828         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00829             $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00830             return $aLanguageURLs[$iLang];
00831         }
00832 
00833         //normal section
00834         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00835         if ( $sMallShopURL ) {
00836             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00837             return $sMallShopURL;
00838         }
00839 
00840         return $this->getConfigParam( 'sShopURL' );
00841     }
00842 
00850     public function getSslShopUrl( $iLang = null )
00851     {
00852         // #680 per language another URL
00853         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00854         $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00855         if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00856             $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00857             return $aLanguageSSLURLs[$iLang];
00858         }
00859 
00860         //mall mode
00861         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00862             $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00863             return $sMallSSLShopURL;
00864         }
00865 
00866         if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00867             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00868             return $sMallShopURL;
00869         }
00870 
00871         //normal section
00872         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00873             return $sSSLShopURL;
00874         }
00875 
00876         return $this->getShopUrl( $iLang );
00877     }
00878 
00884     public function getCoreUtilsUrl()
00885     {
00886         return $this->getCurrentShopUrl().'core/utils/';
00887     }
00888 
00897     public function getCurrentShopUrl($blAdmin = null)
00898     {
00899         if ($blAdmin===null) {
00900             $blAdmin = $this->isAdmin();
00901         }
00902         if ($blAdmin) {
00903             if ($this->isSsl()) {
00904 
00905                 $sUrl = $this->getConfigParam( 'sAdminSSLURL' );
00906                 if ( !$sUrl ) {
00907                     return $this->getSslShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00908                 }
00909                 return $sUrl;
00910             } else {
00911                 return $this->getShopUrl() . $this->getConfigParam( 'sAdminDir' ) . '/';
00912             }
00913         } else {
00914             return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
00915         }
00916     }
00917 
00925     public function getShopCurrentUrl( $iLang = null )
00926     {
00927         if ( $this->isSsl() ) {
00928             $sURL = $this->getSSLShopURL( $iLang );
00929         } else {
00930             $sURL = $this->getShopURL( $iLang );
00931         }
00932 
00933         return oxUtilsUrl::getInstance()->processUrl( $sURL.'index.php', false );
00934     }
00935 
00944     public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00945     {
00946         return oxUtilsUrl::getInstance()->processUrl($this->getShopUrl( $iLang, $blAdmin).'index.php', false );
00947     }
00948 
00954     public function getShopSecureHomeUrl()
00955     {
00956         return  oxUtilsUrl::getInstance()->processUrl( $this->getSslShopUrl().'index.php', false );
00957     }
00958 
00964     public function getShopCurrency()
00965     {
00966         $iCurr = null;
00967         if ( ( null === ( $iCurr = oxConfig::getParameter( 'cur' ) ) ) ) {
00968             if ( null === ( $iCurr = oxConfig::getParameter( 'currency' ) ) ) {
00969                 $iCurr = oxSession::getVar( 'currency' );
00970             }
00971         }
00972         return (int) $iCurr;
00973     }
00974 
00980     public function getActShopCurrencyObject()
00981     {
00982         //caching currency as it does not change through the script
00983         //but not for unit tests as ther it changes always
00984         if ( !defined( 'OXID_PHP_UNIT' ) ) {
00985             if (!is_null($this->_oActCurrencyObject)) {
00986                 return $this->_oActCurrencyObject;
00987             }
00988         }
00989 
00990         $iCur = $this->getShopCurrency();
00991         $aCurrencies = $this->getCurrencyArray();
00992         if ( !isset( $aCurrencies[$iCur] ) ) {
00993             return $this->_oActCurrencyObject = reset( $aCurrencies ); // reset() returns the first element
00994         }
00995 
00996         return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00997     }
00998 
01006     public function setActShopCurrency( $iCur )
01007     {
01008         $aCurrencies = $this->getCurrencyArray();
01009         if ( isset( $aCurrencies[$iCur] ) ) {
01010             oxSession::setVar( 'currency', $iCur );
01011             $this->_oActCurrencyObject = null;
01012         }
01013     }
01014 
01022     public function getOutDir( $blAbsolute = true)
01023     {
01024         if ($blAbsolute) {
01025             return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
01026         } else {
01027             return $this->_sOutDir.'/';
01028         }
01029     }
01030 
01040     public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
01041     {
01042         $blSSL    = is_null($blSSL)?$this->isSsl():$blSSL;
01043         $blAdmin  = is_null($blAdmin)?$this->isAdmin():$blAdmin;
01044 
01045         if ( $blSSL ) {
01046             if ($blNativeImg && !$blAdmin) {
01047                 $sUrl = $this->getSslShopUrl();
01048             } else {
01049                 $sUrl = $this->getConfigParam('sSSLShopURL');
01050                 if (!$sUrl && $blAdmin) {
01051                     $sUrl = $this->getConfigParam('sAdminSSLURL').'../';
01052                 }
01053             }
01054         } else {
01055             $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
01056         }
01057 
01058         return $sUrl.$this->_sOutDir.'/';
01059     }
01060 
01075     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false )
01076     {
01077         if ( is_null($sTheme) ) {
01078             $sTheme = $this->getConfigParam( 'sTheme' );
01079         }
01080 
01081         if ( $blAdmin ) {
01082             $sTheme = 'admin';
01083         }
01084 
01085         $sBase    = $this->getOutDir( $blAbsolute );
01086         $sAbsBase = $this->getOutDir();
01087 
01088         $sLang = '-';
01089         // FALSE means skip language folder check
01090         if ( $iLang !== false ) {
01091             $oLang = oxLang::getInstance();
01092 
01093             if ( is_null( $iLang ) ) {
01094                 $iLang = $oLang->getEditLanguage();
01095             }
01096 
01097             $sLang = $oLang->getLanguageAbbr( $iLang );
01098         }
01099 
01100         if ( is_null($iShop) ) {
01101             $iShop = $this->getShopId();
01102         }
01103 
01104         //Load from
01105         $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
01106         $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
01107 
01108         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01109             return $sReturn;
01110         }
01111 
01112         $sReturn = false;
01113 
01114         // Check for custom template
01115         $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
01116         if ( !$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
01117             $sReturn = $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute );
01118         }
01119 
01120         //test lang level ..
01121         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01122             $sReturn = $sBase . $sPath;
01123         }
01124 
01125         //test shop level ..
01126         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01127         if ( !$sReturn && !$blAdmin && is_readable( $sAbsBase.$sPath ) ) {
01128             $sReturn = $sBase . $sPath;
01129         }
01130 
01131 
01132         //test theme language level ..
01133         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01134         if ( !$sReturn && $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01135             $sReturn = $sBase . $sPath;
01136         }
01137 
01138         //test theme level ..
01139         $sPath = "$sTheme/$sDir/$sFile";
01140         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01141             $sReturn = $sBase . $sPath;
01142         }
01143 
01144         //test out language level ..
01145         $sPath = "$sLang/$sDir/$sFile";
01146         if ( !$sReturn &&  $iLang !== false && is_readable( $sAbsBase.$sPath ) ) {
01147             $sReturn = $sBase . $sPath;
01148         }
01149 
01150         //test out level ..
01151         $sPath = "$sDir/$sFile";
01152         if ( !$sReturn && is_readable( $sAbsBase.$sPath ) ) {
01153             $sReturn = $sBase . $sPath;
01154         }
01155 
01156         if ( !$sReturn ) {
01157             // TODO: implement logic to log missing paths
01158         }
01159 
01160         // to cache
01161         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01162 
01163         return $sReturn;
01164     }
01165 
01180     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01181     {
01182         $sUrl = str_replace(
01183                                 $this->getOutDir(),
01184                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01185                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01186                             );
01187         return $sUrl;
01188     }
01189 
01198     public function getImagePath( $sFile, $blAdmin = false )
01199     {
01200         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01201     }
01202 
01213     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null )
01214     {
01215         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01216         return $this->getUrl( $sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01217     }
01218 
01226     public function getImageDir( $blAdmin = false )
01227     {
01228         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01229     }
01230 
01242     public function getPicturePath($sFile, $blAdmin = false, $iLang = null , $iShop = null , $sTheme = null)
01243     {
01244         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme );
01245     }
01246 
01254     public function getMasterPictureDir( $blAdmin = false )
01255     {
01256         return $this->getDir( null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01257     }
01258 
01267     public function getMasterPicturePath( $sFile, $blAdmin = false )
01268     {
01269         return $this->getDir( $sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin );
01270     }
01271 
01284     public function getPictureUrl( $sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01285     {
01286         if ( $sAltUrl = oxPictureHandler::getInstance()->getAltImageUrl('/', $sFile, $blSSL) ) {
01287             return $sAltUrl;
01288         }
01289 
01290         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01291         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01292 
01293         //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01294         if ( !$sUrl && $sDefPic ) {
01295             $sUrl = $this->getUrl( $sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01296         }
01297         return $sUrl;
01298     }
01299 
01314     public function getIconUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg" )
01315     {
01316         return $this->getPictureUrl( $sFile, $blAdmin, $blSSL, $iLang, $iShopId, $sDefPic );
01317     }
01318 
01326     public function getPictureDir( $blAdmin )
01327     {
01328         return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01329     }
01330 
01339     public function getTemplatePath( $sFile, $blAdmin )
01340     {
01341         return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01342     }
01343 
01351     public function getTemplateDir( $blAdmin = false )
01352     {
01353         return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01354     }
01355 
01366     public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01367     {
01368         return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01369     }
01370 
01378     public function getTemplateBase( $blAdmin = false )
01379     {
01380         // Base template dir is the parent dir of template dir
01381         return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01382     }
01383 
01392     public function getResourcePath($sFile = '', $blAdmin = false )
01393     {
01394         return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01395     }
01396 
01407     public function getResourceUrl( $sFile = '', $blAdmin = false , $blSSL = null , $iLang = null )
01408     {
01409         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01410         return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang );
01411     }
01412 
01420     public function getResourceDir( $blAdmin )
01421     {
01422         return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01423     }
01424 
01438     public function getLanguagePath( $sFile, $blAdmin, $iLang = null, $iShop = null, $sTheme = null )
01439     {
01440         return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang, $iShop, $sTheme );
01441     }
01442 
01454     public function getStdLanguagePath( $sFile, $blAdmin, $iLang = null )
01455     {
01456         $sDir = null;
01457         if ( $iLang !== false ) {
01458             $sDir = oxLang::getInstance()->getLanguageAbbr( $iLang );
01459         }
01460 
01461         return $this->getDir( $sFile, $sDir, $blAdmin, $iLang, null, $this->getConfigParam( "sTheme" ), true, true );
01462     }
01463 
01471     public function getLanguageDir( $blAdmin )
01472     {
01473         return $this->getDir( null, null, $blAdmin );
01474     }
01475 
01483     public function getCurrencyArray( $iCurrency = null )
01484     {
01485         $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01486         if ( !is_array( $aConfCurrencies ) ) {
01487             return array();
01488         }
01489 
01490         if ( defined( 'OXID_PHP_UNIT' ) ) {
01491             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01492                 try{
01493                     $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01494                     if ( isset( $aAltCurrencies ) ) {
01495                         $aConfCurrencies = $aAltCurrencies;
01496                     }
01497                 } catch( Exception $e ) {
01498                     // if exception is thrown, use default
01499                 }
01500             }
01501         }
01502 
01503         // processing currency configuration data
01504         $aCurrencies = array();
01505         reset( $aConfCurrencies );
01506         while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01507             if ( $val ) {
01508                 $oCur = new oxStdClass();
01509                 $oCur->id      = $key;
01510                 $sCur = explode( '@', $val);
01511                 $oCur->name     = trim( $sCur[0] );
01512                 $oCur->rate     = trim( $sCur[1] );
01513                 $oCur->dec      = trim( $sCur[2] );
01514                 $oCur->thousand = trim( $sCur[3] );
01515                 $oCur->sign     = trim( $sCur[4] );
01516                 $oCur->decimal  = trim( $sCur[5] );
01517 
01518                 // change for US version
01519                 if ( isset( $sCur[6] ) ) {
01520                     $oCur->side = trim($sCur[6]);
01521                 }
01522 
01523                 if ( isset( $iCurrency) && $key == $iCurrency ) {
01524                     $oCur->selected = 1;
01525                 } else {
01526                     $oCur->selected = 0;
01527                 }
01528                 $aCurrencies[$key]= $oCur;
01529             }
01530 
01531             // #861C -  performance, do not load other currencies
01532             if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01533                 break;
01534             }
01535         }
01536         return $aCurrencies;
01537     }
01538 
01546     public function getCurrencyObject( $sName )
01547     {
01548         $aSearch = $this->getCurrencyArray();
01549         foreach ( $aSearch as $oCur ) {
01550             if ( $oCur->name == $sName ) {
01551                 return $oCur;
01552             }
01553         }
01554     }
01555 
01561     public function isDemoShop()
01562     {
01563         return $this->getConfigParam('blDemoShop');
01564     }
01565 
01571     public function getEdition()
01572     {
01573             return "CE";
01574 
01575 
01576     }
01577 
01583     public function getFullEdition()
01584     {
01585         $sEdition = $this->getEdition();
01586 
01587             if ($sEdition == "CE") {
01588                 return "Community Edition";
01589             }
01590 
01591 
01592 
01593         return $sEdition;
01594     }
01595 
01601     public function getVersion()
01602     {
01603         $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01604         return $sVersion;
01605     }
01606 
01612     public function getRevision()
01613     {
01614         try {
01615             $sFileName = getShopBasePath() . "/pkg.rev";
01616             $iRev = (int) trim(@file_get_contents($sFileName));
01617         } catch (Exception $e) {
01618             return false;
01619         }
01620 
01621         if (!$iRev) {
01622             return false;
01623         }
01624 
01625         return $iRev;
01626     }
01627 
01628 
01634     public function isMall()
01635     {
01636 
01637             return false;
01638     }
01639 
01649     public function detectVersion()
01650     {
01651     }
01652 
01653 
01654 
01667     public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '' )
01668     {
01669         switch ( $sVarType ) {
01670             case 'arr':
01671             case 'aarr':
01672                 if (is_array($sVarVal)) {
01673                     $sValue = serialize( $sVarVal );
01674                 } else {
01675                     // Deprecated functionality
01676                     $sValue  = $sVarVal ;
01677                     $sVarVal = unserialize( $sVarVal );
01678                 }
01679                 break;
01680             case 'bool':
01681                 //config param
01682                 $sVarVal = (( $sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
01683                 //db value
01684                 $sValue  = $sVarVal?"1":"";
01685                 break;
01686             default:
01687                 $sValue  = $sVarVal;
01688                 break;
01689         }
01690 
01691         if ( !$sShopId ) {
01692             $sShopId = $this->getShopId();
01693         }
01694 
01695         // Update value only for current shop
01696         if ($sShopId == $this->getShopId()) {
01697             $this->setConfigParam( $sVarName, $sVarVal );
01698         }
01699 
01700         $oDb = oxDb::getDb(true);
01701 
01702         $sShopIdQuoted     = $oDb->quote($sShopId);
01703         $sModuleQuoted     = $oDb->quote($sModule);
01704         $sVarNameQuoted    = $oDb->quote($sVarName);
01705         $sVarTypeQuoted    = $oDb->quote($sVarType);
01706         $sVarValueQuoted   = $oDb->quote($sValue);
01707         $sConfigKeyQuoted  = $oDb->quote($this->getConfigParam('sConfigKey'));
01708         $sNewOXIDdQuoted   = $oDb->quote(oxUtilsObject::getInstance()->generateUID());
01709 
01710         $sQ = "delete from oxconfig where oxshopid = $sShopIdQuoted and oxvarname = $sVarNameQuoted and oxmodule = $sModuleQuoted";
01711         $oDb->execute( $sQ );
01712 
01713         $sQ = "insert into oxconfig (oxid, oxshopid, oxmodule, oxvarname, oxvartype, oxvarvalue)
01714                values($sNewOXIDdQuoted, $sShopIdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarTypeQuoted, ENCODE( $sVarValueQuoted, $sConfigKeyQuoted) )";
01715 
01716         $oDb->execute( $sQ );
01717     }
01718 
01728     public function getShopConfVar( $sVarName, $sShopId = null, $sModule = '' )
01729     {
01730         if ( !$sShopId ) {
01731             $sShopId = $this->getShopId();
01732         }
01733 
01734         if ( $sShopId === $this->getShopId() && ( !$sModule || $sModule == oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme') ) ) {
01735             $sVarValue = $this->getConfigParam( $sVarName );
01736             if ( $sVarValue !== null ) {
01737                 return $sVarValue;
01738             }
01739         }
01740 
01741         $oDb = oxDb::getDb(true);
01742         $sQ  = "select oxvartype, ".$this->getDecodeValueQuery()." as oxvarvalue from oxconfig where oxshopid = '{$sShopId}' and oxmodule = '{$sModule}' and oxvarname = ".$oDb->quote($sVarName);
01743         $oRs = $oDb->execute( $sQ );
01744 
01745         $sValue = null;
01746         if ( $oRs != false && $oRs->recordCount() > 0 ) {
01747             $sValue = $this->decodeValue( $oRs->fields['oxvartype'], $oRs->fields['oxvarvalue'] );
01748         }
01749         return $sValue;
01750     }
01751 
01760     public function decodeValue( $sType, $mOrigValue )
01761     {
01762         $sValue = $mOrigValue;
01763         switch ( $sType ) {
01764             case 'arr':
01765             case 'aarr':
01766                 $sValue = unserialize( $mOrigValue );
01767                 break;
01768             case 'bool':
01769                 $sValue = ( $mOrigValue == 'true' || $mOrigValue == '1' );
01770                 break;
01771         }
01772 
01773         return $sValue;
01774     }
01775 
01783     public function getDecodeValueQuery( $sFieldName = "oxvarvalue" )
01784     {
01785         return " DECODE( {$sFieldName}, '".$this->getConfigParam( 'sConfigKey' )."') ";
01786     }
01787 
01793     public function isProductiveMode()
01794     {
01795         $blProductive = false;
01796 
01797         $blProductive = $this->getConfigParam( 'blProductive' );
01798         if ( !isset( $blProductive ) ) {
01799             $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01800             $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01801             $this->setConfigParam( 'blProductive', $blProductive );
01802         }
01803 
01804         return $blProductive;
01805     }
01806 
01807 
01808 
01814     public function getBaseShopId()
01815     {
01816 
01817             return 'oxbaseshop';
01818     }
01819 
01825     public function getActiveShop()
01826     {
01827         if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01828              $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01829             return $this->_oActShop;
01830         }
01831 
01832         $this->_oActShop = oxNew( 'oxshop' );
01833         $this->_oActShop->load( $this->getShopId() );
01834         return $this->_oActShop;
01835     }
01836 
01842     public function getActiveView()
01843     {
01844         if ( $this->_oActView != null ) {
01845             return $this->_oActView;
01846         }
01847 
01848         $this->_oActView = oxNew( 'oxubase' );
01849         return $this->_oActView;
01850     }
01851 
01859     public function setActiveView( $oView )
01860     {
01861         $this->_oActView = $oView;
01862     }
01863 
01869     public function isUtf()
01870     {
01871         return ( bool ) $this->getConfigParam( 'iUtfMode' );
01872     }
01873 
01879     public function getLogsDir()
01880     {
01881         return $this->getConfigParam( 'sShopDir' ).'log/';
01882     }
01883 
01891     public function isThemeOption( $sName )
01892     {
01893         return (bool) isset( $this->_aThemeConfigParams[$sName] );
01894     }
01895 
01901     public function getShopMainUrl()
01902     {
01903         return $this->isSsl() ? $this->getConfigParam( 'sSSLShopURL' ) : $this->getConfigParam( 'sShopURL' );
01904     }
01905 }