oxconfig.php

Go to the documentation of this file.
00001 <?php
00002 
00003 define( 'MAX_64BIT_INTEGER', '18446744073709551615' );
00004 
00009 class oxConfig extends oxSuperCfg
00010 {
00011     // this column of params are defined in config.inc.php file,
00012     // so for backwards compat. names starts without underscore
00013 
00019     protected $dbHost = null;
00020 
00026     protected $dbName = null;
00027 
00033     protected $dbUser = null;
00034 
00040     protected $dbPwd  = null;
00041 
00047     protected $dbType = null;
00048 
00054     protected $sShopURL = null;
00055 
00061     protected $sSSLShopURL = null;
00062 
00068     protected $sAdminSSLURL = null;
00069 
00075     protected $sShopDir = null;
00076 
00082     protected $sCompileDir = null;
00083 
00098     protected $iDebug = 0;
00099 
00105     protected $sAdminEmail = null;
00106 
00112     protected $blSessionUseCookies = null;
00113 
00119     //protected $iMaxArticles = 6000;
00120 
00130     protected $blNativeImages = true;
00131 
00137     protected $aMultiShopTables = array( 'oxarticles', 'oxdiscount', 'oxcategories', 'oxattribute',
00138                                          'oxlinks', 'oxvoucherseries', 'oxmanufacturers',
00139                                          'oxnews', 'oxselectlist', 'oxwrapping',
00140                                          'oxdeliveryset', 'oxdelivery', 'oxvendor', 'oxobject2category');
00141 
00147     private static $_instance = null;
00148 
00154     private $_oStart = null;
00155 
00156 
00162     protected $_oActShop       = null;
00163 
00171     protected $_oActView       = null;
00172 
00178     protected $_aGlobalParams = array();
00179 
00185     protected $_aConfigParams = array();
00186 
00192     protected $_iLanguageId = null;
00193 
00199     protected $_iShopId = null;
00200 
00201 
00207     protected $_sOutDir = 'out';
00208 
00214     protected $_sImageDir = 'img';
00215 
00221     protected $_sPictureDir = 'pictures';
00222 
00228     protected $_sTemplateDir = 'tpl';
00229 
00235     protected $_sResourceDir = 'src';
00236 
00242     protected $_blIsSsl = null;
00243 
00249     protected $_aAbsDynImageDir = array();
00250 
00256     protected $_oActCurrencyObject = null;
00257 
00265     public function getConfigParam( $sName )
00266     {
00267         if ( isset( $this->$sName ) ) {
00268             return $this->$sName;
00269         } elseif ( isset ( $this->_aConfigParams[$sName] ) ) {
00270             return $this->_aConfigParams[$sName];
00271         }
00272     }
00273 
00282     public function setConfigParam( $sName, $sValue )
00283     {
00284         if ( isset( $this->$sName ) ) {
00285             $this->$sName = $sValue;
00286         } else {
00287             $this->_aConfigParams[$sName] = $sValue;
00288         }
00289     }
00290 
00296     public function init()
00297     {
00298         include getShopBasePath().'config.inc.php';
00299         include getShopBasePath().'core/oxconfk.php';
00300 
00301         //adding trailing slashes
00302         $oFileUtils = oxUtilsFile::getInstance();
00303         $this->sShopDir     = $oFileUtils->normalizeDir($this->sShopDir);
00304         $this->sCompileDir  = $oFileUtils->normalizeDir($this->sCompileDir);
00305         $this->sShopURL     = $oFileUtils->normalizeDir($this->sShopURL);
00306         $this->sSSLShopURL  = $oFileUtils->normalizeDir($this->sSSLShopURL);
00307         $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
00308 
00309 
00310         // some important defaults
00311         if( !$this->getConfigParam( 'sDefaultLang' ) )
00312             $this->setConfigParam( 'sDefaultLang', 0 );
00313 
00314         $blLogChangesInAdmin = $this->getConfigParam( 'blLogChangesInAdmin' );
00315         if( !isset( $blLogChangesInAdmin ) )
00316             $this->setConfigParam( 'blLogChangesInAdmin', false );
00317 
00318         $blCheckTemplates = $this->getConfigParam( 'blCheckTemplates' );
00319         if( !isset( $blCheckTemplates ) )
00320             $this->setConfigParam( 'blCheckTemplates', false );
00321 
00322         $blAllowArticlesubclass = $this->getConfigParam( 'blAllowArticlesubclass' );
00323         if( !isset( $blAllowArticlesubclass ) )
00324             $this->setConfigParam( 'blAllowArticlesubclass', false );
00325 
00326         $iAdminListSize = $this->getConfigParam( 'iAdminListSize' );
00327         if( !isset( $iAdminListSize ) )
00328             $this->setConfigParam( 'iAdminListSize', 9 );
00329 
00330         // #1173M  for EE - not all pic are deleted
00331         $iPicCount = $this->getConfigParam( 'iPicCount' );
00332         if( !isset( $iPicCount ) )
00333             $this->setConfigParam( 'iPicCount', 12 );
00334 
00335         $iZoomPicCount = $this->getConfigParam( 'iZoomPicCount' );
00336         if( !isset( $iZoomPicCount ) )
00337             $this->setConfigParam( 'iZoomPicCount', 4 );
00338 
00339         //max shop id default value
00340         $iMaxShopId = $this->getConfigParam( 'iMaxShopId' );
00341         if( !isset( $iMaxShopId ) )
00342             $this->setConfigParam( 'iMaxShopId', 64 );
00343 
00344         // disabling caching according to DODGER #655 : disable Caching as it doesnt work good enought
00345         $this->setConfigParam( 'blTemplateCaching', false );
00346 
00347         //setting ADODB timeout
00348         global  $ADODB_SESS_LIFE;
00349         $ADODB_SESS_LIFE  = 1;
00350 
00351 
00352             /*
00353         $iSessionTimeout = null;
00354         if ( $this->isAdmin())
00355             $iSessionTimeout = $this->getConfigParam( 'iSessionTimeoutAdmin' );
00356         if ( !$this->isAdmin() || !$iSessionTimeout )
00357             $iSessionTimeout = $this->getConfigParam( 'iSessionTimeout' );
00358         if (!$iSessionTimeout)
00359             $iSessionTimeout = 60;*/
00360 
00361         // ADODB cachelifetime
00362         $iDBCacheLifeTime = $this->getConfigParam( 'iDBCacheLifeTime' );
00363         if( !isset( $iDBCacheLifeTime ) )
00364             $this->setConfigParam( 'iDBCacheLifeTime', 3600 ); // 1 hour
00365 
00366         $sCoreDir = $this->getConfigParam( 'sShopDir' );
00367         $this->setConfigParam( 'sCoreDir', $sCoreDir.'/core/' );
00368 
00369         try {
00370             //starting up the session
00371             $this->getSession()->start();
00372 
00373             $sShopID = $this->getShopId();
00374 
00375             // load now
00376             $this->_loadVarsFromDb( $sShopID );
00377 
00378         } catch ( oxConnectionException $oEx ) {
00379             $oEx->debugOut( $this->iDebug);
00380             if ( defined( 'OXID_PHP_UNIT' ) ) {
00381                 return false;
00382             } elseif ( 0 != $this->iDebug ) {
00383                 exit( $oEx->getString() );
00384             } else {
00385                 header( "HTTP/1.1 500 Internal Server Error");
00386                 header( "Location: offline.html");
00387                 header( "Connection: close");
00388             }
00389         } catch ( oxCookieException $oEx ) {
00390             // redirect to start page and display the error
00391             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00392             oxUtils::getInstance()->redirect( $this->getShopHomeURL() .'cl=start' );
00393         }
00394 
00395         //application initialization
00396         $this->_oStart = new oxStart();
00397         $this->_oStart->appInit();
00398     }
00399 
00405     public static function getInstance()
00406     {
00407 
00408         if ( defined( 'OXID_PHP_UNIT' ) ) {
00409             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00410                 return modConfig::$unitMOD;
00411             }
00412         }
00413 
00414         if ( !self::$_instance instanceof oxConfig ) {
00415                 //exceptions from here go directly to global exception handler
00416                 //if no init is possible whole application has to die!
00417                 self::$_instance = new oxConfig();
00418                 self::$_instance->init();
00419         }
00420         return self::$_instance;
00421     }
00422 
00431     protected function _loadVarsFromDb( $sShopID, $aOnlyVars = null )
00432     {
00433 
00434         $sQ = "select oxvarname, oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopID'";
00435         // dodger, allow loading from some vars only from baseshop
00436         if ( $aOnlyVars !== null ) {
00437             $blSep = false;
00438             $sIn  = '';
00439             foreach ( $aOnlyVars as $sField ) {
00440                 if ( $blSep ) {
00441                     $sIn .= ', ';
00442                 }
00443                 $sIn .= '"'.$sField.'"';
00444                 $blSep = true;
00445             }
00446             $sQ .= ' and oxvarname in ( '.$sIn.' ) ';
00447         }
00448 
00449         $oRs = oxDb::getDb()->execute( $sQ );
00450         if ( $oRs != false && $oRs->recordCount() > 0 ) {
00451             while ( !$oRs->EOF ) {
00452                 $sVarName = $oRs->fields[0];
00453                 $sVarType = $oRs->fields[1];
00454                 $sVarVal  = $oRs->fields[2];
00455 
00456                 //in sShopURL and sSSLShopURL cases we skip (for admin or when URL values are not set)
00457                 if ( ( $sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL' ) &&
00458                     ( !$sVarVal || $this->isAdmin() === true ) ) {
00459                     $oRs->moveNext();
00460                     continue;
00461                 }
00462 
00463                 switch ( $sVarType ) {
00464                     case 'arr':
00465                     case 'aarr':
00466                         $this->setConfigParam( $sVarName, unserialize( $sVarVal ) );
00467                         break;
00468                     case 'bool':
00469                         $this->setConfigParam( $sVarName, ( $sVarVal == 'true' || $sVarVal == '1' ) );
00470                         break;
00471                     default:
00472                         $this->setConfigParam( $sVarName, $sVarVal );
00473                 }
00474 
00475                 $oRs->moveNext();
00476             }
00477         }
00478 
00479     }
00480 
00486     public function pageClose()
00487     {
00488         return $this->_oStart->pageClose();
00489     }
00490 
00504     public static function getParameter(  $sName, $blRaw = false )
00505     {
00506         if ( defined( 'OXID_PHP_UNIT' ) ) {
00507             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00508                 try{
00509                     return modConfig::getParameter(  $sName, $blRaw );
00510                 } catch( Exception $e ) {
00511                     // if exception is thrown, use default
00512                 }
00513             }
00514         }
00515 
00516         $sValue = null;
00517         if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_POST[$sName] ) ) {
00518             $sValue = $_POST[$sName];
00519         } elseif ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'GET' && isset( $_GET[$sName] ) ) {
00520             $sValue = $_GET[$sName];
00521             //<deprecated>
00522         } elseif ( oxSession::hasVar( $sName ) ) {
00523             $sValue = oxSession::getVar( $sName );
00524             //</deprecated>
00525         } else {
00526             $sValue = null;
00527         }
00528 
00529         // TODO: remove this after special charts concept implementation
00530         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00531         if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00532             self::checkSpecialChars( $sValue, $blRaw );
00533         }
00534 
00535         return $sValue;
00536     }
00537 
00545     public function getUploadedFile($sParamName)
00546     {
00547         return $_FILES[$sParamName];
00548     }
00549 
00558     public function setGlobalParameter( $sName, $sValue )
00559     {
00560         $this->_aGlobalParams[$sName] = $sValue;
00561     }
00562 
00570     public function getGlobalParameter( $sName )
00571     {
00572         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00573             return $this->_aGlobalParams[$sName];
00574         } else {
00575             return null;
00576         }
00577     }
00578 
00588     public static function checkSpecialChars( & $sValue, $aRaw = null )
00589     {
00590         if ( is_object( $sValue ) ) {
00591             return $sValue;
00592         }
00593 
00594         if ( is_array( $sValue ) ) {
00595             $newValue = array();
00596             foreach ( $sValue as $sKey => $sVal ) {
00597                 $sValidKey = $sKey;
00598                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00599                     self::checkSpecialChars( $sValidKey );
00600                     self::checkSpecialChars( $sVal );
00601                     if ($sValidKey != $sKey) {
00602                         unset ($sValue[$sKey]);
00603                     }
00604                 }
00605                 $newValue[$sValidKey] = $sVal;
00606             }
00607             $sValue = $newValue;
00608         } else {
00609             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00610                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00611                                    $sValue );
00612         }
00613         return $sValue;
00614     }
00615 
00621     public function getShopId()
00622     {
00623         if ( $this->_iShopId !== null )
00624             return $this->_iShopId;
00625 
00626             $this->_iShopId = $this->getBaseShopId();
00627 
00628 
00629         oxSession::setVar( 'actshop', $this->_iShopId );
00630         return $this->_iShopId;
00631     }
00632 
00640     public function setShopId( $sShopId )
00641     {
00642         oxSession::setVar( 'actshop', $sShopId );
00643         $this->_iShopId = $sShopId;
00644     }
00645 
00646 
00652     public function isSsl()
00653     {
00654         if ( is_null( $this->_blIsSsl ) ) {
00655 
00656             $myUtilsServer   = oxUtilsServer::getInstance();
00657             $aServerVars     = $myUtilsServer->getServerVar();
00658             $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00659 
00660             $this->_blIsSsl = ( isset( $aHttpsServerVar ) && $this->getConfigParam( 'sSSLShopURL' ) &&
00661                          ( $aHttpsServerVar == 'on' || $aHttpsServerVar == '1' ) ); // 1&1 provides "1"
00662 
00663             //additional special handling for profihost customers
00664             if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00665                  ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00666                  strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00667                 $this->_blIsSsl = true;
00668             }
00669         }
00670 
00671         return $this->_blIsSsl;
00672     }
00673 
00681     public function isCurrentUrl( $sURL )
00682     {
00683         if ( !$sURL ) {
00684             return false;
00685         }
00686 
00687         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'] );
00688 
00689         //remove double slashes all the way
00690         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00691         $sURL = str_replace( '/', '', $sURL );
00692 
00693         //so far comparing for the host is enought for us
00694         if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00695             return true;
00696         }
00697 
00698         return false;
00699     }
00700 
00709     public function getShopUrl( $iLang = null, $blAdmin = null )
00710     {
00711         $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00712         if ( $blAdmin ) {
00713             return $this->getConfigParam( 'sShopURL' );
00714         }
00715 
00716         // #680 per language another URL
00717         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00718         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00719         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00720             $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00721             return $aLanguageURLs[$iLang];
00722         }
00723 
00724         //normal section
00725         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00726         if ( $sMallShopURL ) {
00727             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00728             return $sMallShopURL;
00729         }
00730 
00731         return $this->getConfigParam( 'sShopURL' );
00732     }
00733 
00741     public function getSslShopUrl( $iLang = null )
00742     {
00743         // #680 per language another URL
00744         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00745         $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00746         if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00747             $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00748             return $aLanguageSSLURLs[$iLang];
00749         }
00750 
00751         //mall mode
00752         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00753             $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00754             return $sMallSSLShopURL;
00755         }
00756 
00757         if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00758             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00759             return $sMallShopURL;
00760         }
00761 
00762         //normal section
00763         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00764             return $sSSLShopURL;
00765         }
00766 
00767         return $this->getShopUrl( $iLang );
00768     }
00769 
00775     public function getCoreUtilsUrl()
00776     {
00777         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00778             return $sSSLShopURL.'core/utils/';
00779         }
00780         return $this->getConfigParam( 'sShopURL' ).'core/utils/';
00781     }
00782 
00788     public function getCurrentShopUrl()
00789     {
00790         if ( $this->isSsl() ) {
00791             return $this->getSslShopUrl();
00792         }
00793         return $this->getShopUrl();
00794     }
00795 
00803     public function getShopCurrentUrl( $iLang = null )
00804     {
00805         if ( $this->isSsl() ) {
00806             $sURL = $this->getSSLShopURL( $iLang );
00807         } else {
00808             $sURL = $this->getShopURL( $iLang );
00809         }
00810 
00811         return $this->getSession()->url( $sURL.'index.php' );
00812     }
00813 
00822     public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00823     {
00824         return $this->getSession()->url( $this->getShopUrl( $iLang, $blAdmin).'index.php' );
00825     }
00826 
00832     public function getShopSecureHomeUrl()
00833     {
00834         return $this->getSession()->url( $this->getSslShopUrl().'index.php' );
00835     }
00836 
00842     public function getShopCurrency()
00843     {
00844         return (int) oxConfig::getParameter( 'currency' );
00845     }
00846 
00852     public function getActShopCurrencyObject()
00853     {
00854         //caching currency as it does not change through the script
00855         //but not for unit tests as ther it changes always
00856         if ( !defined( 'OXID_PHP_UNIT' ) ) {
00857             if (!is_null($this->_oActCurrencyObject)) {
00858                 return $this->_oActCurrencyObject;
00859             }
00860         }
00861 
00862         $iCur = oxConfig::getParameter( 'cur' );
00863         if ( !isset( $iCur ) ) {
00864             $iCur = $this->getShopCurrency();
00865         }
00866 
00867         $aCurrencies = $this->getCurrencyArray();
00868         if ( !isset( $aCurrencies[$iCur] ) ) {
00869             return $this->_oActCurrencyObject = reset( $aCurrencies ); // reset() returns the first element
00870         }
00871 
00872         return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00873     }
00874 
00882     public function setActShopCurrency( $iCur )
00883     {
00884         $aCurrencies = $this->getCurrencyArray();
00885         if ( isset( $aCurrencies[$iCur] ) ) {
00886             oxSession::setVar( 'currency', $iCur );
00887             $this->_oActCurrencyObject = null;
00888         }
00889     }
00890 
00891 
00901     public function getNoSslImageDir( $blAdmin = false )
00902     {
00903         return $this->getImageUrl( $blAdmin, false );
00904     }
00905 
00913     public function getAbsAdminImageDir()
00914     {
00915         return $this->getImageDir( true );
00916 
00917     }
00918 
00933     /* is not used
00934     public function formatOutDir($sFile, $iLang = null, $blAdmin = false, $blNoThemes = false, $iShop = null)
00935     {
00936         //resolving theme and shop dir
00937         $sThemeDir  = ($blNoThemes || $blAdmin) ? "" : $this->getConfigParam( 'sTheme' );
00938 
00939         if (is_null($iShop))
00940             $iShop = $this->getShopId();
00941 
00942         $aShopDirs = array();
00943 
00944 
00945         if ($sThemeDir)
00946             $aShopDirs[] = "$sThemeDir/1/";
00947         else
00948             $aShopDirs[] = $this->getBaseShopId() . "/";
00949 
00950         //admin dir
00951         if ( $blAdmin ) {
00952             $aShopDirs = array('admin/');
00953         }
00954 
00955         if ($sFile) {
00956             //language dir
00957             if (is_null($iLang))
00958                 $iLang = oxLang::getInstance()->getBaseLanguage();
00959 
00960             $aLangs    = oxLang::getInstance()->getLanguageArray();
00961             //specific language dir and top dir
00962             $aLangDirs = array();
00963             if (isset($aLangs[$iLang]))
00964                 $aLangDirs[] = strtolower($aLangs[$iLang]->abbr . "/");
00965             $aLangDirs[] = "";
00966 
00967 
00968             //finally checking dir
00969             foreach ($aShopDirs as $sShopDir) {
00970                 foreach ($aLangDirs as $sLangDir) {
00971                     $sOut = "out/" . $sShopDir . $sLangDir . $sFile;
00972                     if (file_exists($this->getConfigParam('sShopDir'). $sOut))
00973                         return $sOut;
00974                 }
00975             }
00976         }
00977 
00978         //not language specific default dir
00979         foreach ($aShopDirs as $sShopDir) {
00980             $sOut = "out/" . $sShopDir;
00981             if (file_exists($this->getConfigParam('sShopDir'). $sOut))
00982                 return $sOut;
00983         }
00984     }*/
00985 
00993     public function getOutDir( $blAbsolute = true)
00994     {
00995         if ($blAbsolute) {
00996             return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
00997         } else {
00998             return $this->_sOutDir.'/';
00999         }
01000     }
01001 
01011     public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
01012     {
01013         $blSSL    = is_null($blSSL)?$this->isSsl():$blSSL;
01014         $blAdmin  = is_null($blAdmin)?$this->isAdmin():$blAdmin;
01015 
01016         if ( $blSSL ) {
01017             $sUrl = ($blNativeImg && !$blAdmin )?$this->getSslShopUrl():$this->getConfigParam( 'sSSLShopURL');
01018         } else {
01019             $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
01020         }
01021 
01022         return $sUrl.$this->_sOutDir.'/';
01023     }
01024 
01038     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true )
01039     {
01040         $sBase    = $this->getOutDir( $blAbsolute );
01041         $sAbsBase = $this->getOutDir();
01042 
01043         $oLang = oxLang::getInstance(); //getTplLanguage
01044 
01045         if ( is_null($iLang) ) {
01046             $iLang = $oLang->getEditLanguage();
01047         }
01048 
01049         $sLang = $oLang->getLanguageAbbr( $iLang );
01050 
01051         if ( is_null($iShop) ) {
01052             $iShop = $this->getShopId();
01053         }
01054 
01055         if ( is_null($sTheme) ) {
01056             $sTheme = $this->getConfigParam( 'sTheme' );
01057         }
01058 
01059         if ( $blAdmin ) {
01060             $sTheme = 'admin';
01061         }
01062 
01063         //Load from
01064         $sPath = "$sTheme/$iShop/$sLang/$sDir/$sFile";
01065         $sCacheKey = $sPath . "_$blAbsolute";
01066 
01067         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01068             return $sReturn;
01069         }
01070 
01071         $sReturn = false;
01072 
01073         //test lang level ..
01074         if ( !$sReturn && !$blAdmin && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath ) ) ) ) {
01075             $sReturn = $sBase . $sPath;
01076         }
01077 
01078         //test shop level ..
01079         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01080         if ( !$sReturn && !$blAdmin && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath ) ) ) ) {
01081             $sReturn = $sBase . $sPath;
01082         }
01083 
01084 
01085         //test theme language level ..
01086         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01087         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01088             $sReturn = $sBase . $sPath;
01089         }
01090 
01091         //test theme level ..
01092         $sPath = "$sTheme/$sDir/$sFile";
01093         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01094             $sReturn = $sBase . $sPath;
01095         }
01096 
01097         //test out language level ..
01098         $sPath = "$sLang/$sDir/$sFile";
01099         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01100             $sReturn = $sBase . $sPath;
01101         }
01102 
01103         //test out level ..
01104         $sPath = "$sDir/$sFile";
01105         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01106             $sReturn = $sBase . $sPath;
01107         }
01108 
01109         if ( !$sReturn ) {
01110             // TODO: log missing paths...
01111         }
01112 
01113         // to cache
01114         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01115 
01116         return $sReturn;
01117     }
01118 
01133     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01134     {
01135         $sUrl = str_replace(
01136                                 $this->getOutDir(),
01137                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01138                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01139                             );
01140         return $sUrl;
01141     }
01142 
01151     public function getImagePath( $sFile, $blAdmin = false )
01152     {
01153         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01154     }
01155 
01165     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null )
01166     {
01167         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01168         return $this->getUrl( null, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01169     }
01170 
01178     public function getImageDir( $blAdmin = false )
01179     {
01180         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01181     }
01182 
01191     public function getPicturePath($sFile, $blAdmin = false )
01192     {
01193         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin );
01194     }
01195 
01207     public function getPictureUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null )
01208     {
01209         if ( $sAltUrl = $this->getConfigParam( 'sAltImageDir' ) ) {
01210 
01211             if ( $this->isSsl() ) {
01212                 $sAltUrl = str_replace( 'http://', 'https://', $sAltUrl );
01213             }
01214 
01215             if ( !is_null( $sFile ) ) {
01216                 $sAltUrl .= $sFile;
01217             }
01218 
01219             return $sAltUrl;
01220         }
01221         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, null, $iLang, $iShopId );
01222         if ( $sFile && $this->getConfigParam('blFormerTplSupport') ) {
01223             $sUrl = str_replace( $this->getPictureUrl( null, $blAdmin, $blSSL, $iLang, $iShopId ), '', $sUrl );
01224         }
01225         //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01226         if (!$sUrl) {
01227             return $this->getTemplateUrl()."../".$this->_sPictureDir."/0/nopic.jpg";
01228         }
01229         return $sUrl;
01230     }
01231 
01239     public function getPictureDir( $blAdmin )
01240     {
01241         return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01242     }
01243 
01252     public function getTemplatePath( $sFile, $blAdmin )
01253     {
01254         return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01255     }
01256 
01264     public function getTemplateDir( $blAdmin = false )
01265     {
01266         return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01267     }
01268 
01279     public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01280     {
01281         return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01282     }
01283 
01291     public function getTemplateBase( $blAdmin = false )
01292     {
01293         // Base template dir is the parent dir of template dir
01294         return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01295     }
01296 
01305     public function getResourcePath($sFile, $blAdmin = false )
01306     {
01307         return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01308     }
01309 
01320     public function getResourceUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null )
01321     {
01322         return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, false, $iLang );
01323     }
01324 
01332     public function getResourceDir( $blAdmin )
01333     {
01334         return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01335     }
01336 
01346     public function getLanguagePath( $sFile, $blAdmin, $iLang = null )
01347     {
01348         return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang );
01349     }
01350 
01358     public function getLanguageDir( $blAdmin )
01359     {
01360         return $this->getDir( null, null, $blAdmin );
01361     }
01362 
01370     public function getAbsImageDir()
01371     {
01372         return $this->getImageDir();
01373     }
01374 
01385     public function getDynImageDir( $sOverrideShopId = null, $blNoSsl = null )
01386     {
01387         return $this->getPictureUrl(null, false, $this->isSsl() && !$blNoSsl, null, $sOverrideShopId);
01388 
01389         /*
01390 
01391         $sCacheKey = "getDynImageDir_" . $this->isSsl() . "_" . $this->getShopId() . "_" .oxLang::getInstance()->getTplLanguage() . "_" . $sOverrideShopId . "_" . $blNoSsl;
01392         $sImageDir = oxUtils::getInstance()->fromStaticCache($sCacheKey);
01393 
01394         if ($sImageDir)
01395             return $sImageDir;
01396 
01397         if ( $sAltImageDir = $this->getConfigParam( 'sAltImageDir' ) ) {
01398             if ( $this->isSsl() ) {
01399                 $sAltImageDir = str_replace( 'http://', 'https://', $sAltImageDir );
01400             }
01401             oxUtils::getInstance()->toStaticCache($sCacheKey, $sAltImageDir);
01402             return $sAltImageDir;
01403         }
01404 
01405         //Tomas 2005-01-19
01406         //now it loads images only from either active shop either from oxbaseshop
01407         //later to be fixed to load images from any shop according $sOverrideShopId by implementing
01408         //function oxConfig::getShopURL($sOverrideShopId);
01409 
01410         $blNativeImg = $this->getConfigParam( 'blNativeImages' ) && $sOverrideShopId == $this->getShopId();
01411 
01412         if ( $this->isSsl() && !$blNoSsl ) {
01413             $sUrl = $blNativeImg ? $this->getSSLShopURL():$this->getConfigParam( 'sSSLShopURL');
01414         }
01415 
01416         if(!$sUrl) {
01417             $sUrl = $blNativeImg ? $this->getShopURL():$this->getConfigParam( 'sShopURL' );
01418         }
01419 
01420         $sLang = $this->getConfigParam( 'blUseDifferentDynDirs' )?oxLang::getInstance()->getTplLanguage():0;
01421         $sDir  = $this->_sPictureDir;
01422 
01423         $sImageDir = $sUrl . $this->formatOutDir($sDir, $iLang, false, true, $sOverrideShopId);
01424 
01425         oxUtils::getInstance()->toStaticCache($sCacheKey, $sImageDir);
01426 
01427 
01428         return $sImageDir;
01429         */
01430     }
01431 
01441     public function getAbsDynImageDir( $sOverrideShopId = null )
01442     {
01443         return $this->getPictureDir(false);
01444 
01445         /*
01446         //$sShop = is_null($sOverrideShopId)?$this->getShopId():$sOverrideShopId;
01447 
01448         if (isset($this->_aAbsDynImageDir[$sShop]))
01449             return $this->_aAbsDynImageDir[$sShop];
01450 
01451         $sRoot = $this->getConfigParam('sShopDir');
01452         $iLang = $this->getConfigParam( 'blUseDifferentDynDirs' )?oxLang::getInstance()->getTplLanguage():0;
01453         $sDir  = $this->_sPictureDir;
01454 
01455         $this->_aAbsDynImageDir[$sShop] = $sRoot . $this->formatOutDir($sDir, $iLang, false, true, $sOverrideShopId);
01456         return $this->_aAbsDynImageDir[$sShop];
01457         */
01458     }
01459 
01470     public function getTemplateFile( $sTemplate, $blAdmin = false )
01471     {
01472         return $this->getTemplatePath( $sTemplate, $blAdmin );
01473     }
01474 
01484     public function getBaseTemplateDir( $blAdmin = false )
01485     {
01486         return $this->getResourceUrl( null, $blAdmin );
01487         /*
01488         $blNativeImg = $this->getConfigParam( 'blNativeImages' ) && !$blAdmin;
01489 
01490         if ( $this->isSsl() ) {
01491             $sTemplateUrl = $blNativeImg?$this->getSSLShopURL():$this->getConfigParam( 'sSSLShopURL' );
01492         } else {
01493             $sTemplateUrl = $blNativeImg?$this->getShopURL():$this->getConfigParam( 'sShopURL' );
01494         }
01495 
01496         return $this->getResourceUrl( null, $blAdmin, $this->isSsl() );
01497         */
01498     }
01499 
01509     public function getBaseTplDir( $blAdmin = false )
01510     {
01511         //TODO: check usage
01512         return $this->getResourceUrl( null, $blAdmin);
01513     }
01514 
01522     public function getCurrencyArray( $iCurrency = null )
01523     {
01524         $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01525         if ( !is_array( $aConfCurrencies ) ) {
01526             return array();
01527         }
01528 
01529         if ( defined( 'OXID_PHP_UNIT' ) ) {
01530             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01531                 try{
01532                     $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01533                     if ( isset( $aAltCurrencies ) ) {
01534                         $aConfCurrencies = $aAltCurrencies;
01535                     }
01536                 } catch( Exception $e ) {
01537                     // if exception is thrown, use default
01538                 }
01539             }
01540         }
01541 
01542         // processing currency configuration data
01543         $aCurrencies = array();
01544         reset( $aConfCurrencies );
01545         while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01546             if ( $val ) {
01547                 $oCur = new oxStdClass();
01548                 $oCur->id      = $key;
01549                 $sCur = explode( '@', $val);
01550                 $oCur->name     = trim( $sCur[0] );
01551                 $oCur->rate     = trim( $sCur[1] );
01552                 $oCur->dec      = trim( $sCur[2] );
01553                 $oCur->thousand = trim( $sCur[3] );
01554                 $oCur->sign     = trim( $sCur[4] );
01555                 $oCur->decimal  = trim( $sCur[5] );
01556 
01557                 // change for US version
01558                 if ( isset( $sCur[6] ) ) {
01559                     $oCur->side = trim($sCur[6]);
01560                 }
01561 
01562                 if ( isset( $iCurrency) && $key == $iCurrency ) {
01563                     $oCur->selected = 1;
01564                 } else {
01565                     $oCur->selected = 0;
01566                 }
01567                 $aCurrencies[$key]= $oCur;
01568             }
01569 
01570             // #861C -  performance, do not load other currencies
01571             if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01572                 break;
01573             }
01574         }
01575         return $aCurrencies;
01576     }
01577 
01585     public function getCurrencyObject( $sName )
01586     {
01587         $aSearch = $this->getCurrencyArray();
01588         foreach ( $aSearch as $oCur ) {
01589             if ( $oCur->name == $sName ) {
01590                 return $oCur;
01591             }
01592         }
01593     }
01594 
01600     public function isDemoShop()
01601     {
01602         return $this->getConfigParam('blDemoShop');
01603     }
01604 
01610     public function getEdition()
01611     {
01612             return "CE";
01613 
01614 
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         $oDb = oxDb::getDb();
01711         $sQ = "delete from oxconfig where oxshopid = '$sShopId' and oxvarname = '$sVarName'";
01712         $oDb->execute( $sQ );
01713         $sUid = oxUtilsObject::getInstance()->generateUID();
01714 
01715         $sUid     = mysql_real_escape_string($sUid);
01716         $sShopId  = mysql_real_escape_string($sShopId);
01717         $sVarName = mysql_real_escape_string($sVarName);
01718         $sVarVal  = mysql_real_escape_string($sVarVal);
01719 
01720         $sQ = "insert into oxconfig (oxid, oxshopid, oxvarname, oxvartype, oxvarvalue)
01721                values('$sUid', '$sShopId', '$sVarName', '$sVarType', ENCODE( '$sVarVal', '".$this->getConfigParam('sConfigKey')."'))";
01722 
01723         $oDb->execute( $sQ );
01724     }
01725 
01734     public function getShopConfVar( $sVarName, $sShopId = null )
01735     {
01736         if ( !$sShopId ) {
01737             $sShopId = $this->getShopId();
01738         }
01739 
01740         $sQ  = "select oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopId' and oxvarname = '$sVarName'";
01741         $oRs = oxDb::getDb(true)->Execute( $sQ );
01742 
01743         $sValue = null;
01744         if ( $oRs != false && $oRs->recordCount() > 0 ) {
01745             $sVarType = $oRs->fields['oxvartype'];
01746             $sVarVal  = $oRs->fields['oxvarvalue'];
01747             switch ( $sVarType ) {
01748                 case 'arr':
01749                 case 'aarr':
01750                     $sValue =  unserialize( $sVarVal );
01751                     break;
01752                 case 'bool':
01753                     $sValue =  ( $sVarVal == 'true' || $sVarVal == '1' );
01754                     break;
01755                 default:
01756                     $sValue = $sVarVal;
01757                 }
01758         }
01759         return $sValue;
01760     }
01761 
01767     public function isProductiveMode()
01768     {
01769         $blProductive = false;
01770 
01771         $blProductive = $this->getConfigParam( 'blProductive' );
01772         if ( !isset( $blProductive ) ) {
01773             $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01774             $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01775             $this->setConfigParam( 'blProductive', $blProductive );
01776         }
01777 
01778         return $blProductive;
01779     }
01780 
01781 
01782 
01788     public function getBaseShopId()
01789     {
01790 
01791             return 'oxbaseshop';
01792     }
01793 
01799     public function getActiveShop()
01800     {
01801         if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01802              $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01803             return $this->_oActShop;
01804         }
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 
01843     public function isUtf()
01844     {
01845         return ( bool ) $this->getConfigParam( 'iUtfMode' );
01846     }
01847 }

Generated on Wed Jun 17 12:09:01 2009 for OXID eShop CE by  doxygen 1.5.5