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', true, 302 );
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                         break;
00474                 }
00475 
00476                 $oRs->moveNext();
00477             }
00478         }
00479 
00480     }
00481 
00487     public function pageClose()
00488     {
00489         return $this->_oStart->pageClose();
00490     }
00491 
00505     public static function getParameter(  $sName, $blRaw = false )
00506     {
00507         if ( defined( 'OXID_PHP_UNIT' ) ) {
00508             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
00509                 try{
00510                     return modConfig::getParameter(  $sName, $blRaw );
00511                 } catch( Exception $e ) {
00512                     // if exception is thrown, use default
00513                 }
00514             }
00515         }
00516 
00517         $sValue = null;
00518         if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_POST[$sName] ) ) {
00519             $sValue = $_POST[$sName];
00520         } elseif ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'GET' && isset( $_GET[$sName] ) ) {
00521             $sValue = $_GET[$sName];
00522             //<deprecated>
00523         } elseif ( oxSession::hasVar( $sName ) ) {
00524             $sValue = oxSession::getVar( $sName );
00525             //</deprecated>
00526         } else {
00527             $sValue = null;
00528         }
00529 
00530         // TODO: remove this after special charts concept implementation
00531         $blIsAdmin = oxConfig::getInstance()->isAdmin() && oxSession::getVar("blIsAdmin");
00532         if ( $sValue != null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
00533             self::checkSpecialChars( $sValue, $blRaw );
00534         }
00535 
00536         return $sValue;
00537     }
00538 
00546     public function getUploadedFile($sParamName)
00547     {
00548         return $_FILES[$sParamName];
00549     }
00550 
00559     public function setGlobalParameter( $sName, $sValue )
00560     {
00561         $this->_aGlobalParams[$sName] = $sValue;
00562     }
00563 
00571     public function getGlobalParameter( $sName )
00572     {
00573         if ( isset( $this->_aGlobalParams[$sName] ) ) {
00574             return $this->_aGlobalParams[$sName];
00575         } else {
00576             return null;
00577         }
00578     }
00579 
00589     public static function checkSpecialChars( & $sValue, $aRaw = null )
00590     {
00591         if ( is_object( $sValue ) ) {
00592             return $sValue;
00593         }
00594 
00595         if ( is_array( $sValue ) ) {
00596             $newValue = array();
00597             foreach ( $sValue as $sKey => $sVal ) {
00598                 $sValidKey = $sKey;
00599                 if ( !$aRaw || !in_array($sKey, $aRaw) ) {
00600                     self::checkSpecialChars( $sValidKey );
00601                     self::checkSpecialChars( $sVal );
00602                     if ($sValidKey != $sKey) {
00603                         unset ($sValue[$sKey]);
00604                     }
00605                 }
00606                 $newValue[$sValidKey] = $sVal;
00607             }
00608             $sValue = $newValue;
00609         } else {
00610             $sValue = str_replace( array( '&',     '<',    '>',    '"',      "'",      chr(0), '\\' ),
00611                                    array( '&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '',     '&#092;' ),
00612                                    $sValue );
00613         }
00614         return $sValue;
00615     }
00616 
00622     public function getShopId()
00623     {
00624         if ( $this->_iShopId !== null )
00625             return $this->_iShopId;
00626 
00627             $this->_iShopId = $this->getBaseShopId();
00628 
00629 
00630         oxSession::setVar( 'actshop', $this->_iShopId );
00631         return $this->_iShopId;
00632     }
00633 
00634 
00642     public function setShopId( $sShopId )
00643     {
00644         oxSession::setVar( 'actshop', $sShopId );
00645         $this->_iShopId = $sShopId;
00646     }
00647 
00648 
00654     public function isSsl()
00655     {
00656         if ( is_null( $this->_blIsSsl ) ) {
00657 
00658             $myUtilsServer   = oxUtilsServer::getInstance();
00659             $aServerVars     = $myUtilsServer->getServerVar();
00660             $aHttpsServerVar = $myUtilsServer->getServerVar( 'HTTPS' );
00661 
00662             $this->_blIsSsl = ( isset( $aHttpsServerVar ) && ( $this->getConfigParam( 'sSSLShopURL' ) || $this->getConfigParam( 'sMallSSLShopURL' ) ) &&
00663                          ( $aHttpsServerVar === 'on' || $aHttpsServerVar == '1' ) ); // 1&1 provides "1"
00664 
00665             //additional special handling for profihost customers
00666             if ( isset( $aServerVars['HTTP_X_FORWARDED_SERVER'] ) &&
00667                  ( strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl' ) !== false ||
00668                  strpos( $aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de' ) !== false ) ) {
00669                 $this->_blIsSsl = true;
00670             }
00671         }
00672 
00673         return $this->_blIsSsl;
00674     }
00675 
00683     public function isCurrentUrl( $sURL )
00684     {
00685         if ( !$sURL ) {
00686             return false;
00687         }
00688 
00689         $oUtilsServer = oxUtilsServer::getInstance();
00690         $sHost = $oUtilsServer->getServerVar( 'HTTP_HOST' );
00691         $sScriptName = $oUtilsServer->getServerVar( 'SCRIPT_NAME' );
00692 
00693         $sCurrentHost = preg_replace( '/\/\w*\.php.*/', '', $sHost . $sScriptName );
00694 
00695         //remove double slashes all the way
00696         $sCurrentHost = str_replace( '/', '', $sCurrentHost );
00697         $sURL = str_replace( '/', '', $sURL );
00698 
00699         //so far comparing for the host is enought for us
00700         if ( getStr()->strpos( $sURL, $sCurrentHost ) !== false ) {
00701             return true;
00702         }
00703 
00704         return false;
00705     }
00706 
00715     public function getShopUrl( $iLang = null, $blAdmin = null )
00716     {
00717         $blAdmin = isset( $blAdmin ) ? $blAdmin : $this->isAdmin();
00718         if ( $blAdmin ) {
00719             return $this->getConfigParam( 'sShopURL' );
00720         }
00721 
00722         // #680 per language another URL
00723         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00724         $aLanguageURLs = $this->getConfigParam( 'aLanguageURLs' );
00725         if ( isset( $iLang ) && isset( $aLanguageURLs[$iLang] ) && !empty( $aLanguageURLs[$iLang] ) ) {
00726             $aLanguageURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageURLs[$iLang] );
00727             return $aLanguageURLs[$iLang];
00728         }
00729 
00730         //normal section
00731         $sMallShopURL = $this->getConfigParam( 'sMallShopURL' );
00732         if ( $sMallShopURL ) {
00733             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00734             return $sMallShopURL;
00735         }
00736 
00737         return $this->getConfigParam( 'sShopURL' );
00738     }
00739 
00747     public function getSslShopUrl( $iLang = null )
00748     {
00749         // #680 per language another URL
00750         $iLang = isset( $iLang ) ? $iLang : oxLang::getInstance()->getBaseLanguage();
00751         $aLanguageSSLURLs = $this->getConfigParam( 'aLanguageSSLURLs' );
00752         if ( isset( $iLang ) && isset( $aLanguageSSLURLs[$iLang] ) && !empty( $aLanguageSSLURLs[$iLang] ) ) {
00753             $aLanguageSSLURLs[$iLang] = oxUtils::getInstance()->checkUrlEndingSlash( $aLanguageSSLURLs[$iLang] );
00754             return $aLanguageSSLURLs[$iLang];
00755         }
00756 
00757         //mall mode
00758         if ( ( $sMallSSLShopURL = $this->getConfigParam( 'sMallSSLShopURL' ) ) ) {
00759             $sMallSSLShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallSSLShopURL );
00760             return $sMallSSLShopURL;
00761         }
00762 
00763         if ( ( $sMallShopURL = $this->getConfigParam( 'sMallShopURL' ) ) ) {
00764             $sMallShopURL = oxUtils::getInstance()->checkUrlEndingSlash( $sMallShopURL );
00765             return $sMallShopURL;
00766         }
00767 
00768         //normal section
00769         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00770             return $sSSLShopURL;
00771         }
00772 
00773         return $this->getShopUrl( $iLang );
00774     }
00775 
00781     public function getCoreUtilsUrl()
00782     {
00783         if ( ( $sSSLShopURL = $this->getConfigParam( 'sSSLShopURL' ) ) ) {
00784             return $sSSLShopURL.'core/utils/';
00785         }
00786         return $this->getConfigParam( 'sShopURL' ).'core/utils/';
00787     }
00788 
00794     public function getCurrentShopUrl()
00795     {
00796         if ( $this->isSsl() ) {
00797             return $this->getSslShopUrl();
00798         }
00799         return $this->getShopUrl();
00800     }
00801 
00809     public function getShopCurrentUrl( $iLang = null )
00810     {
00811         if ( $this->isSsl() ) {
00812             $sURL = $this->getSSLShopURL( $iLang );
00813         } else {
00814             $sURL = $this->getShopURL( $iLang );
00815         }
00816 
00817         return $this->getSession()->url( $sURL.'index.php' );
00818     }
00819 
00828     public function getShopHomeUrl( $iLang = null, $blAdmin = null )
00829     {
00830         return $this->getSession()->url( $this->getShopUrl( $iLang, $blAdmin).'index.php' );
00831     }
00832 
00838     public function getShopSecureHomeUrl()
00839     {
00840         return $this->getSession()->url( $this->getSslShopUrl().'index.php' );
00841     }
00842 
00848     public function getShopCurrency()
00849     {
00850         return (int) oxConfig::getParameter( 'currency' );
00851     }
00852 
00858     public function getActShopCurrencyObject()
00859     {
00860         //caching currency as it does not change through the script
00861         //but not for unit tests as ther it changes always
00862         if ( !defined( 'OXID_PHP_UNIT' ) ) {
00863             if (!is_null($this->_oActCurrencyObject)) {
00864                 return $this->_oActCurrencyObject;
00865             }
00866         }
00867 
00868         $iCur = oxConfig::getParameter( 'cur' );
00869         if ( !isset( $iCur ) ) {
00870             $iCur = $this->getShopCurrency();
00871         }
00872 
00873         $aCurrencies = $this->getCurrencyArray();
00874         if ( !isset( $aCurrencies[$iCur] ) ) {
00875             return $this->_oActCurrencyObject = reset( $aCurrencies ); // reset() returns the first element
00876         }
00877 
00878         return $this->_oActCurrencyObject = $aCurrencies[$iCur];
00879     }
00880 
00888     public function setActShopCurrency( $iCur )
00889     {
00890         $aCurrencies = $this->getCurrencyArray();
00891         if ( isset( $aCurrencies[$iCur] ) ) {
00892             oxSession::setVar( 'currency', $iCur );
00893             $this->_oActCurrencyObject = null;
00894         }
00895     }
00896 
00897 
00907     public function getNoSslImageDir( $blAdmin = false )
00908     {
00909         return $this->getImageUrl( $blAdmin, false );
00910     }
00911 
00919     public function getAbsAdminImageDir()
00920     {
00921         return $this->getImageDir( true );
00922 
00923     }
00924 
00939     /* is not used
00940     public function formatOutDir($sFile, $iLang = null, $blAdmin = false, $blNoThemes = false, $iShop = null)
00941     {
00942         //resolving theme and shop dir
00943         $sThemeDir  = ($blNoThemes || $blAdmin) ? "" : $this->getConfigParam( 'sTheme' );
00944 
00945         if (is_null($iShop))
00946             $iShop = $this->getShopId();
00947 
00948         $aShopDirs = array();
00949 
00950 
00951         if ($sThemeDir)
00952             $aShopDirs[] = "$sThemeDir/1/";
00953         else
00954             $aShopDirs[] = $this->getBaseShopId() . "/";
00955 
00956         //admin dir
00957         if ( $blAdmin ) {
00958             $aShopDirs = array('admin/');
00959         }
00960 
00961         if ($sFile) {
00962             //language dir
00963             if (is_null($iLang))
00964                 $iLang = oxLang::getInstance()->getBaseLanguage();
00965 
00966             $aLangs    = oxLang::getInstance()->getLanguageArray();
00967             //specific language dir and top dir
00968             $aLangDirs = array();
00969             if (isset($aLangs[$iLang]))
00970                 $aLangDirs[] = strtolower($aLangs[$iLang]->abbr . "/");
00971             $aLangDirs[] = "";
00972 
00973 
00974             //finally checking dir
00975             foreach ($aShopDirs as $sShopDir) {
00976                 foreach ($aLangDirs as $sLangDir) {
00977                     $sOut = "out/" . $sShopDir . $sLangDir . $sFile;
00978                     if (file_exists($this->getConfigParam('sShopDir'). $sOut))
00979                         return $sOut;
00980                 }
00981             }
00982         }
00983 
00984         //not language specific default dir
00985         foreach ($aShopDirs as $sShopDir) {
00986             $sOut = "out/" . $sShopDir;
00987             if (file_exists($this->getConfigParam('sShopDir'). $sOut))
00988                 return $sOut;
00989         }
00990     }*/
00991 
00999     public function getOutDir( $blAbsolute = true)
01000     {
01001         if ($blAbsolute) {
01002             return $this->getConfigParam('sShopDir').$this->_sOutDir.'/';
01003         } else {
01004             return $this->_sOutDir.'/';
01005         }
01006     }
01007 
01017     public function getOutUrl( $blSSL = null , $blAdmin = null, $blNativeImg = false )
01018     {
01019         $blSSL    = is_null($blSSL)?$this->isSsl():$blSSL;
01020         $blAdmin  = is_null($blAdmin)?$this->isAdmin():$blAdmin;
01021 
01022         if ( $blSSL ) {
01023             $sUrl = ($blNativeImg && !$blAdmin )?$this->getSslShopUrl():$this->getConfigParam( 'sSSLShopURL');
01024         } else {
01025             $sUrl = ($blNativeImg && !$blAdmin )?$this->getShopUrl():$this->getConfigParam( 'sShopURL' );
01026         }
01027 
01028         return $sUrl.$this->_sOutDir.'/';
01029     }
01030 
01044     public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true )
01045     {
01046         $sBase    = $this->getOutDir( $blAbsolute );
01047         $sAbsBase = $this->getOutDir();
01048 
01049         $oLang = oxLang::getInstance(); //getTplLanguage
01050 
01051         if ( is_null($iLang) ) {
01052             $iLang = $oLang->getEditLanguage();
01053         }
01054 
01055         $sLang = $oLang->getLanguageAbbr( $iLang );
01056 
01057         if ( is_null($iShop) ) {
01058             $iShop = $this->getShopId();
01059         }
01060 
01061         if ( is_null($sTheme) ) {
01062             $sTheme = $this->getConfigParam( 'sTheme' );
01063         }
01064 
01065         if ( $blAdmin ) {
01066             $sTheme = 'admin';
01067         }
01068 
01069         //Load from
01070         $sPath = "$sTheme/$iShop/$sLang/$sDir/$sFile";
01071         $sCacheKey = $sPath . "_$blAbsolute";
01072 
01073         if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) {
01074             return $sReturn;
01075         }
01076 
01077         $sReturn = false;
01078 
01079         //test lang level ..
01080         if ( !$sReturn && !$blAdmin && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath ) ) ) ) {
01081             $sReturn = $sBase . $sPath;
01082         }
01083 
01084         //test shop level ..
01085         $sPath = "$sTheme/$iShop/$sDir/$sFile";
01086         if ( !$sReturn && !$blAdmin && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath ) ) ) ) {
01087             $sReturn = $sBase . $sPath;
01088         }
01089 
01090 
01091         //test theme language level ..
01092         $sPath = "$sTheme/$sLang/$sDir/$sFile";
01093         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01094             $sReturn = $sBase . $sPath;
01095         }
01096 
01097         //test theme level ..
01098         $sPath = "$sTheme/$sDir/$sFile";
01099         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01100             $sReturn = $sBase . $sPath;
01101         }
01102 
01103         //test out language level ..
01104         $sPath = "$sLang/$sDir/$sFile";
01105         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01106             $sReturn = $sBase . $sPath;
01107         }
01108 
01109         //test out level ..
01110         $sPath = "$sDir/$sFile";
01111         if ( !$sReturn && ( is_readable( $sAbsBase.$sPath ) || is_dir( realpath( $sAbsBase.$sPath )) ) ) {
01112             $sReturn = $sBase . $sPath;
01113         }
01114 
01115         if ( !$sReturn ) {
01116             // TODO: log missing paths...
01117         }
01118 
01119         // to cache
01120         oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );
01121 
01122         return $sReturn;
01123     }
01124 
01139     public function getUrl($sFile, $sDir , $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null , $iShop = null , $sTheme = null )
01140     {
01141         $sUrl = str_replace(
01142                                 $this->getOutDir(),
01143                                 $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
01144                                 $this->getDir( $sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme )
01145                             );
01146         return $sUrl;
01147     }
01148 
01157     public function getImagePath( $sFile, $blAdmin = false )
01158     {
01159         return $this->getDir( $sFile, $this->_sImageDir, $blAdmin );
01160     }
01161 
01171     public function getImageUrl( $blAdmin = false, $blSSL = null, $blNativeImg = null )
01172     {
01173         $blNativeImg = is_null($blNativeImg)?$this->getConfigParam( 'blNativeImages' ):$blNativeImg;
01174         return $this->getUrl( null, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg );
01175     }
01176 
01184     public function getImageDir( $blAdmin = false )
01185     {
01186         return $this->getDir( null, $this->_sImageDir, $blAdmin );
01187     }
01188 
01197     public function getPicturePath($sFile, $blAdmin = false )
01198     {
01199         return $this->getDir( $sFile, $this->_sPictureDir, $blAdmin );
01200     }
01201 
01213     public function getPictureUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null, $iShopId = null )
01214     {
01215         if ( $sAltUrl = $this->getConfigParam( 'sAltImageDir' ) ) {
01216 
01217             if ( $this->isSsl() ) {
01218                 $sAltUrl = str_replace( 'http://', 'https://', $sAltUrl );
01219             }
01220 
01221             if ( !is_null( $sFile ) ) {
01222                 $sAltUrl .= $sFile;
01223             }
01224 
01225             return $sAltUrl;
01226         }
01227 
01228         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01229 
01230         $sUrl = $this->getUrl( $sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId );
01231         if ( $sFile && $this->getConfigParam('blFormerTplSupport') ) {
01232             $sUrl = str_replace( $this->getPictureUrl( null, $blAdmin, $blSSL, $iLang, $iShopId ), '', $sUrl );
01233         }
01234         //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
01235         if (!$sUrl) {
01236             return $this->getTemplateUrl()."../".$this->_sPictureDir."/0/nopic.jpg";
01237         }
01238         return $sUrl;
01239     }
01240 
01248     public function getPictureDir( $blAdmin )
01249     {
01250         return $this->getDir( null, $this->_sPictureDir, $blAdmin );
01251     }
01252 
01261     public function getTemplatePath( $sFile, $blAdmin )
01262     {
01263         return $this->getDir( $sFile, $this->_sTemplateDir, $blAdmin );
01264     }
01265 
01273     public function getTemplateDir( $blAdmin = false )
01274     {
01275         return $this->getDir( null, $this->_sTemplateDir, $blAdmin );
01276     }
01277 
01288     public function getTemplateUrl( $sFile = null, $blAdmin = false, $blSSL = null , $iLang = null )
01289     {
01290         return $this->getUrl( $sFile, $this->_sTemplateDir, $blAdmin, $blSSL, false, $iLang );
01291     }
01292 
01300     public function getTemplateBase( $blAdmin = false )
01301     {
01302         // Base template dir is the parent dir of template dir
01303         return str_replace( $this->_sTemplateDir.'/', '', $this->getDir( null, $this->_sTemplateDir, $blAdmin, null, null, null, false ));
01304     }
01305 
01314     public function getResourcePath($sFile, $blAdmin = false )
01315     {
01316         return $this->getDir( $sFile, $this->_sResourceDir, $blAdmin );
01317     }
01318 
01329     public function getResourceUrl( $sFile, $blAdmin = false , $blSSL = null , $iLang = null )
01330     {
01331         $blNativeImg = $this->getConfigParam( 'blNativeImages' );
01332         return $this->getUrl( $sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang );
01333     }
01334 
01342     public function getResourceDir( $blAdmin )
01343     {
01344         return $this->getDir( null, $this->_sResourceDir, $blAdmin );
01345     }
01346 
01356     public function getLanguagePath( $sFile, $blAdmin, $iLang = null )
01357     {
01358         return $this->getDir( $sFile, oxLang::getInstance()->getLanguageAbbr( $iLang ), $blAdmin, $iLang );
01359     }
01360 
01368     public function getLanguageDir( $blAdmin )
01369     {
01370         return $this->getDir( null, null, $blAdmin );
01371     }
01372 
01380     public function getAbsImageDir()
01381     {
01382         return $this->getImageDir();
01383     }
01384 
01395     public function getDynImageDir( $sOverrideShopId = null, $blNoSsl = null )
01396     {
01397         return $this->getPictureUrl(null, false, $this->isSsl() && !$blNoSsl, null, $sOverrideShopId);
01398 
01399         /*
01400 
01401         $sCacheKey = "getDynImageDir_" . $this->isSsl() . "_" . $this->getShopId() . "_" .oxLang::getInstance()->getTplLanguage() . "_" . $sOverrideShopId . "_" . $blNoSsl;
01402         $sImageDir = oxUtils::getInstance()->fromStaticCache($sCacheKey);
01403 
01404         if ($sImageDir)
01405             return $sImageDir;
01406 
01407         if ( $sAltImageDir = $this->getConfigParam( 'sAltImageDir' ) ) {
01408             if ( $this->isSsl() ) {
01409                 $sAltImageDir = str_replace( 'http://', 'https://', $sAltImageDir );
01410             }
01411             oxUtils::getInstance()->toStaticCache($sCacheKey, $sAltImageDir);
01412             return $sAltImageDir;
01413         }
01414 
01415         //Tomas 2005-01-19
01416         //now it loads images only from either active shop either from oxbaseshop
01417         //later to be fixed to load images from any shop according $sOverrideShopId by implementing
01418         //function oxConfig::getShopURL($sOverrideShopId);
01419 
01420         $blNativeImg = $this->getConfigParam( 'blNativeImages' ) && $sOverrideShopId == $this->getShopId();
01421 
01422         if ( $this->isSsl() && !$blNoSsl ) {
01423             $sUrl = $blNativeImg ? $this->getSSLShopURL():$this->getConfigParam( 'sSSLShopURL');
01424         }
01425 
01426         if(!$sUrl) {
01427             $sUrl = $blNativeImg ? $this->getShopURL():$this->getConfigParam( 'sShopURL' );
01428         }
01429 
01430         $sLang = $this->getConfigParam( 'blUseDifferentDynDirs' )?oxLang::getInstance()->getTplLanguage():0;
01431         $sDir  = $this->_sPictureDir;
01432 
01433         $sImageDir = $sUrl . $this->formatOutDir($sDir, $iLang, false, true, $sOverrideShopId);
01434 
01435         oxUtils::getInstance()->toStaticCache($sCacheKey, $sImageDir);
01436 
01437 
01438         return $sImageDir;
01439         */
01440     }
01441 
01451     public function getAbsDynImageDir( $sOverrideShopId = null )
01452     {
01453         return $this->getPictureDir(false);
01454 
01455         /*
01456         //$sShop = is_null($sOverrideShopId)?$this->getShopId():$sOverrideShopId;
01457 
01458         if (isset($this->_aAbsDynImageDir[$sShop]))
01459             return $this->_aAbsDynImageDir[$sShop];
01460 
01461         $sRoot = $this->getConfigParam('sShopDir');
01462         $iLang = $this->getConfigParam( 'blUseDifferentDynDirs' )?oxLang::getInstance()->getTplLanguage():0;
01463         $sDir  = $this->_sPictureDir;
01464 
01465         $this->_aAbsDynImageDir[$sShop] = $sRoot . $this->formatOutDir($sDir, $iLang, false, true, $sOverrideShopId);
01466         return $this->_aAbsDynImageDir[$sShop];
01467         */
01468     }
01469 
01480     public function getTemplateFile( $sTemplate, $blAdmin = false )
01481     {
01482         return $this->getTemplatePath( $sTemplate, $blAdmin );
01483     }
01484 
01494     public function getBaseTemplateDir( $blAdmin = false )
01495     {
01496         return $this->getResourceUrl( null, $blAdmin );
01497         /*
01498         $blNativeImg = $this->getConfigParam( 'blNativeImages' ) && !$blAdmin;
01499 
01500         if ( $this->isSsl() ) {
01501             $sTemplateUrl = $blNativeImg?$this->getSSLShopURL():$this->getConfigParam( 'sSSLShopURL' );
01502         } else {
01503             $sTemplateUrl = $blNativeImg?$this->getShopURL():$this->getConfigParam( 'sShopURL' );
01504         }
01505 
01506         return $this->getResourceUrl( null, $blAdmin, $this->isSsl() );
01507         */
01508     }
01509 
01519     public function getBaseTplDir( $blAdmin = false )
01520     {
01521         //TODO: check usage
01522         return $this->getResourceUrl( null, $blAdmin);
01523     }
01524 
01532     public function getCurrencyArray( $iCurrency = null )
01533     {
01534         $aConfCurrencies = $this->getConfigParam( 'aCurrencies' );
01535         if ( !is_array( $aConfCurrencies ) ) {
01536             return array();
01537         }
01538 
01539         if ( defined( 'OXID_PHP_UNIT' ) ) {
01540             if ( isset( modConfig::$unitMOD ) && is_object( modConfig::$unitMOD ) ) {
01541                 try{
01542                     $aAltCurrencies = modConfig::getInstance()->getConfigParam( 'modaCurrencies' );
01543                     if ( isset( $aAltCurrencies ) ) {
01544                         $aConfCurrencies = $aAltCurrencies;
01545                     }
01546                 } catch( Exception $e ) {
01547                     // if exception is thrown, use default
01548                 }
01549             }
01550         }
01551 
01552         // processing currency configuration data
01553         $aCurrencies = array();
01554         reset( $aConfCurrencies );
01555         while ( list( $key, $val ) = each( $aConfCurrencies ) ) {
01556             if ( $val ) {
01557                 $oCur = new oxStdClass();
01558                 $oCur->id      = $key;
01559                 $sCur = explode( '@', $val);
01560                 $oCur->name     = trim( $sCur[0] );
01561                 $oCur->rate     = trim( $sCur[1] );
01562                 $oCur->dec      = trim( $sCur[2] );
01563                 $oCur->thousand = trim( $sCur[3] );
01564                 $oCur->sign     = trim( $sCur[4] );
01565                 $oCur->decimal  = trim( $sCur[5] );
01566 
01567                 // change for US version
01568                 if ( isset( $sCur[6] ) ) {
01569                     $oCur->side = trim($sCur[6]);
01570                 }
01571 
01572                 if ( isset( $iCurrency) && $key == $iCurrency ) {
01573                     $oCur->selected = 1;
01574                 } else {
01575                     $oCur->selected = 0;
01576                 }
01577                 $aCurrencies[$key]= $oCur;
01578             }
01579 
01580             // #861C -  performance, do not load other currencies
01581             if ( !$this->getConfigParam( 'bl_perfLoadCurrency' ) ) {
01582                 break;
01583             }
01584         }
01585         return $aCurrencies;
01586     }
01587 
01595     public function getCurrencyObject( $sName )
01596     {
01597         $aSearch = $this->getCurrencyArray();
01598         foreach ( $aSearch as $oCur ) {
01599             if ( $oCur->name == $sName ) {
01600                 return $oCur;
01601             }
01602         }
01603     }
01604 
01610     public function isDemoShop()
01611     {
01612         return $this->getConfigParam('blDemoShop');
01613     }
01614 
01620     public function getEdition()
01621     {
01622             return "CE";
01623 
01624 
01625     }
01626 
01632     public function getFullEdition()
01633     {
01634         $sEdition = $this->getEdition();
01635 
01636             if ($sEdition == "CE") {
01637                 return "Community Edition";
01638             }
01639 
01640 
01641 
01642         return $sEdition;
01643     }
01644 
01650     public function getVersion()
01651     {
01652         $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
01653         return $sVersion;
01654     }
01655 
01661     public function getRevision()
01662     {
01663         try {
01664             $sFileName = getShopBasePath() . "/pkg.rev";
01665             $iRev = (int) trim(@file_get_contents($sFileName));
01666         } catch (Exception $e) {
01667             return false;
01668         }
01669 
01670         if (!$iRev) {
01671             return false;
01672         }
01673 
01674         return $iRev;
01675     }
01676 
01677 
01683     public function isMall()
01684     {
01685 
01686             return false;
01687     }
01688 
01698     public function detectVersion()
01699     {
01700     }
01701 
01702 
01703 
01714     public function saveShopConfVar( $sVarType, $sVarName, $sVarVal, $sShopId = null )
01715     {
01716         if ( !$sShopId ) {
01717             $sShopId = $this->getShopId();
01718         }
01719 
01720         $oDb = oxDb::getDb();
01721         $sQ = "delete from oxconfig where oxshopid = '$sShopId' and oxvarname = '$sVarName'";
01722         $oDb->execute( $sQ );
01723         $sUid = oxUtilsObject::getInstance()->generateUID();
01724 
01725         $sUid     = mysql_real_escape_string($sUid);
01726         $sShopId  = mysql_real_escape_string($sShopId);
01727         $sVarName = mysql_real_escape_string($sVarName);
01728         $sVarVal  = mysql_real_escape_string($sVarVal);
01729 
01730         $sQ = "insert into oxconfig (oxid, oxshopid, oxvarname, oxvartype, oxvarvalue)
01731                values('$sUid', '$sShopId', '$sVarName', '$sVarType', ENCODE( '$sVarVal', '".$this->getConfigParam('sConfigKey')."'))";
01732 
01733         $oDb->execute( $sQ );
01734     }
01735 
01744     public function getShopConfVar( $sVarName, $sShopId = null )
01745     {
01746         if ( !$sShopId ) {
01747             $sShopId = $this->getShopId();
01748         }
01749 
01750         $oDb = oxDb::getDb(true);
01751         $sQ  = "select oxvartype, DECODE( oxvarvalue, '".$this->getConfigParam( 'sConfigKey' )."') as oxvarvalue from oxconfig where oxshopid = '$sShopId' and oxvarname = ".$oDb->quote($sVarName);
01752         $oRs = $oDb->Execute( $sQ );
01753 
01754         $sValue = null;
01755         if ( $oRs != false && $oRs->recordCount() > 0 ) {
01756             $sVarType = $oRs->fields['oxvartype'];
01757             $sVarVal  = $oRs->fields['oxvarvalue'];
01758             switch ( $sVarType ) {
01759                 case 'arr':
01760                 case 'aarr':
01761                     $sValue =  unserialize( $sVarVal );
01762                     break;
01763                 case 'bool':
01764                     $sValue =  ( $sVarVal == 'true' || $sVarVal == '1' );
01765                     break;
01766                 default:
01767                     $sValue = $sVarVal;
01768                     break;
01769             }
01770         }
01771         return $sValue;
01772     }
01773 
01779     public function isProductiveMode()
01780     {
01781         $blProductive = false;
01782 
01783         $blProductive = $this->getConfigParam( 'blProductive' );
01784         if ( !isset( $blProductive ) ) {
01785             $sQ = 'select oxproductive from oxshops where oxid = "'.$this->getShopId().'"';
01786             $blProductive = ( bool ) oxDb::getDb()->getOne( $sQ );
01787             $this->setConfigParam( 'blProductive', $blProductive );
01788         }
01789 
01790         return $blProductive;
01791     }
01792 
01793 
01794 
01800     public function getBaseShopId()
01801     {
01802 
01803             return 'oxbaseshop';
01804     }
01805 
01811     public function getActiveShop()
01812     {
01813         if ( $this->_oActShop && $this->_iShopId == $this->_oActShop->getId() &&
01814              $this->_oActShop->getLanguage() == oxLang::getInstance()->getBaseLanguage() ) {
01815             return $this->_oActShop;
01816         }
01817 
01818         $this->_oActShop = oxNew( 'oxshop' );
01819         $this->_oActShop->load( $this->getShopId() );
01820         return $this->_oActShop;
01821     }
01822 
01828     public function getActiveView()
01829     {
01830         if ( $this->_oActView != null ) {
01831             return $this->_oActView;
01832         }
01833 
01834         $this->_oActView = oxNew( 'oxubase' );
01835         return $this->_oActView;
01836     }
01837 
01845     public function setActiveView( $oView )
01846     {
01847         $this->_oActView = $oView;
01848     }
01849 
01855     public function isUtf()
01856     {
01857         return ( bool ) $this->getConfigParam( 'iUtfMode' );
01858     }
01859 }

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5