/source/core/oxconfig.php
PHP | 2265 lines | 1034 code | 309 blank | 922 comment | 219 complexity | d510dfbc07a19ae0e4d87437d2f3b3a5 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * This file is part of OXID eShop Community Edition.
- *
- * OXID eShop Community Edition is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * OXID eShop Community Edition is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with OXID eShop Community Edition. If not, see <http://www.gnu.org/licenses/>.
- *
- * @link http://www.oxid-esales.com
- * @copyright (C) OXID eSales AG 2003-2014
- * @version OXID eShop CE
- */
- //max integer
- define('MAX_64BIT_INTEGER', '18446744073709551615');
- /**
- * Main shop configuration class.
- *
- */
- class oxConfig extends oxSuperCfg
- {
- // this column of params are defined in config.inc.php file,
- // so for backwards compatibility. names starts without underscore
- /**
- * Database host name
- *
- * @var string
- */
- protected $dbHost = null;
- /**
- * Database name
- *
- * @var string
- */
- protected $dbName = null;
- /**
- * Database user name
- *
- * @var string
- */
- protected $dbUser = null;
- /**
- * Database user password
- *
- * @var string
- */
- protected $dbPwd = null;
- /**
- * Database driver type
- *
- * @var string
- */
- protected $dbType = null;
- /**
- * Shop Url
- *
- * @var string
- */
- protected $sShopURL = null;
- /**
- * Shop SSL mode Url
- *
- * @var string
- */
- protected $sSSLShopURL = null;
- /**
- * Shops admin SSL mode Url
- *
- * @var string
- */
- protected $sAdminSSLURL = null;
- /**
- * Shops install directory
- *
- * @var string
- */
- protected $sShopDir = null;
- /**
- * Shops compile directory
- *
- * @var string
- */
- protected $sCompileDir = null;
- /**
- * Debug mode (default is set depending on if it is productive mode or not):
- * -1 = Logger Messages internal use only
- * 0 = off
- * 1 = smarty
- * 2 = SQL
- * 3 = SQL + smarty
- * 4 = SQL + smarty + shop template data
- * 5 = Delivery Cost calculation info
- * 6 = SMTP Debug Messages
- * 7 = Slow SQL query indication
- *
- * @var int
- */
- protected $iDebug = null;
- /**
- * Administrator email address, used to send critical notices
- *
- * @var string
- */
- protected $sAdminEmail = null;
- /**
- * Use cookies
- *
- * @var bool
- */
- protected $blSessionUseCookies = null;
- /**
- * Default image loading location.
- * If $blNativeImages is set to true the shop loads images from current domain,
- * otherwise images are loaded from the domain specified in config.inc.php.
- * This is applicable for different domains depending on language or mall
- * if mall mode is available.
- *
- * @var bool
- */
- protected $blNativeImages = true;
- /**
- * Names of tables which are multi-shop
- *
- * @var array
- */
- protected $aMultiShopTables = array('oxarticles', 'oxdiscount', 'oxcategories', 'oxattribute',
- 'oxlinks', 'oxvoucherseries', 'oxmanufacturers',
- 'oxnews', 'oxselectlist', 'oxwrapping',
- 'oxdeliveryset', 'oxdelivery', 'oxvendor', 'oxobject2category');
- /**
- * Application starter instance
- *
- * @var oxStart
- */
- private $_oStart = null;
- /**
- * Active shop object.
- *
- * @var object
- */
- protected $_oActShop = null;
- /**
- * Active Views object array. Object has setters/getters for these properties:
- * _sClass - name of current view class
- * _sFnc - name of current action function
- *
- * @var array
- */
- protected $_aActiveViews = array();
- /**
- * Array of global parameters.
- *
- * @var array
- */
- protected $_aGlobalParams = array();
- /**
- * Shop config parameters storage array
- *
- * @var array
- */
- protected $_aConfigParams = array();
- /**
- * Theme config parameters storage array
- *
- * @var array
- */
- protected $_aThemeConfigParams = array();
- /**
- * Current language Id
- *
- * @var int
- */
- protected $_iLanguageId = null;
- /**
- * Current shop Id
- *
- * @var int
- */
- protected $_iShopId = null;
- /**
- * Out dir name
- *
- * @var string
- */
- protected $_sOutDir = 'out';
- /**
- * Image dir name
- *
- * @var string
- */
- protected $_sImageDir = 'img';
- /**
- * Dyn Image dir name
- *
- * @var string
- */
- protected $_sPictureDir = 'pictures';
- /**
- * Master pictures dir name
- *
- * @var string
- */
- protected $_sMasterPictureDir = 'master';
- /**
- * Template dir name
- *
- * @var string
- */
- protected $_sTemplateDir = 'tpl';
- /**
- * Resource dir name
- *
- * @var string
- */
- protected $_sResourceDir = 'src';
- /**
- * Modules dir name
- *
- * @var string
- */
- protected $_sModulesDir = 'modules';
- /**
- * Whether shop is in SSL mode
- *
- * @var bool
- */
- protected $_blIsSsl = null;
- /**
- * Absolute image dirs for each shops
- *
- * @var array
- */
- protected $_aAbsDynImageDir = array();
- /**
- * Active currency object
- *
- * @var array
- */
- protected $_oActCurrencyObject = null;
- /**
- * Indicates if OxConfig::init() method has been already run.
- * Is checked for loading config variables on demand.
- * Used in OxConfig::getConfigParam() method
- *
- * @var bool
- */
- protected $_blInit = false;
- /**
- * prefix for oxModule field for themes in oxConfig and oxConfigDisplay tables
- *
- * @var string
- */
- const OXMODULE_THEME_PREFIX = 'theme:';
- /**
- * prefix for oxModule field for modules in oxConfig and oxConfigDisplay tables
- *
- * @var string
- */
- const OXMODULE_MODULE_PREFIX = 'module:';
- /**
- * Returns config parameter value if such parameter exists
- *
- * @param string $sName config parameter name
- *
- * @return mixed
- */
- public function getConfigParam($sName)
- {
- if (defined('OXID_PHP_UNIT')) {
- if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
- $sValue = modConfig::$unitMOD->getModConfigParam($sName);
- if ($sValue !== null) {
- return $sValue;
- }
- }
- }
- $this->init();
- if (isset ($this->_aConfigParams[$sName])) {
- return $this->_aConfigParams[$sName];
- }
- if (isset($this->$sName)) {
- return $this->$sName;
- }
- }
- /**
- * Stores config parameter value in config
- *
- * @param string $sName config parameter name
- * @param string $sValue config parameter value
- */
- public function setConfigParam($sName, $sValue)
- {
- if (isset($this->$sName)) {
- $this->$sName = $sValue;
- } else {
- $this->_aConfigParams[$sName] = $sValue;
- }
- }
- /**
- * Parse SEO url parameters.
- */
- protected function _processSeoCall()
- {
- // TODO: refactor shop bootstrap and parse url params as soon as possible
- if (isSearchEngineUrl()) {
- oxNew('oxSeoDecoder')->processSeoCall();
- }
- }
- /**
- * Starts session manager
- *
- * @throws oxConnectionException
- *
- * @return null
- */
- public function init()
- {
- // Duplicated init protection
- if ($this->_blInit) {
- return;
- }
- $this->_blInit = true;
- $this->_loadVarsFromFile();
- include getShopBasePath() . 'core/oxconfk.php';
- // setting ADODB timeout
- global $ADODB_SESS_LIFE;
- $ADODB_SESS_LIFE = 1;
- $this->_setDefaults();
- try {
- $sShopID = $this->getShopId();
- $blConfigLoaded = $this->_loadVarsFromDb($sShopID);
- // loading shop config
- if (empty($sShopID) || !$blConfigLoaded) {
- // if no config values where loaded (some problems with DB), throwing an exception
- $oEx = new oxConnectionException();
- $oEx->setMessage("Unable to load shop config values from database");
- throw $oEx;
- }
- // loading theme config options
- $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme'));
- // checking if custom theme (which has defined parent theme) config options should be loaded over parent theme (#3362)
- if ($this->getConfigParam('sCustomTheme')) {
- $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme'));
- }
- // loading modules config
- $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_MODULE_PREFIX);
- $this->_processSeoCall();
- //starting up the session
- $this->getSession()->start();
- // Admin handling
- $this->setConfigParam('blAdmin', isAdmin());
- if (defined('OX_ADMIN_DIR')) {
- $this->setConfigParam('sAdminDir', OX_ADMIN_DIR);
- }
- $this->_loadVarsFromFile();
- //application initialization
- $this->_oStart = new oxStart();
- $this->_oStart->appInit();
- } catch (oxConnectionException $oEx) {
- return $this->_handleDbConnectionException($oEx);
- } catch (oxCookieException $oEx) {
- return $this->_handleCookieException($oEx);
- }
- }
- /**
- * Loads vars from default config file
- */
- protected function _loadVarsFromFile()
- {
- //config variables from config.inc.php takes priority over the ones loaded from db
- include getShopBasePath() . '/config.inc.php';
- //adding trailing slashes
- $oFileUtils = oxRegistry::get("oxUtilsFile");
- $this->sShopDir = $oFileUtils->normalizeDir($this->sShopDir);
- $this->sCompileDir = $oFileUtils->normalizeDir($this->sCompileDir);
- $this->sShopURL = $oFileUtils->normalizeDir($this->sShopURL);
- $this->sSSLShopURL = $oFileUtils->normalizeDir($this->sSSLShopURL);
- $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
- $this->_loadCustomConfig();
- }
- /**
- * Set important defaults.
- */
- protected function _setDefaults()
- {
- $this->setConfigParam('sTheme', 'azure');
- if (is_null($this->getConfigParam('sDefaultLang'))) {
- $this->setConfigParam('sDefaultLang', 0);
- }
- if (is_null($this->getConfigParam('blLogChangesInAdmin'))) {
- $this->setConfigParam('blLogChangesInAdmin', false);
- }
- if (is_null($this->getConfigParam('blCheckTemplates'))) {
- $this->setConfigParam('blCheckTemplates', false);
- }
- if (is_null($this->getConfigParam('blAllowArticlesubclass'))) {
- $this->setConfigParam('blAllowArticlesubclass', false);
- }
- if (is_null($this->getConfigParam('iAdminListSize'))) {
- $this->setConfigParam('iAdminListSize', 9);
- }
- // #1173M for EE - not all pic are deleted
- if (is_null($this->getConfigParam('iPicCount'))) {
- $this->setConfigParam('iPicCount', 7);
- }
- if (is_null($this->getConfigParam('iZoomPicCount'))) {
- $this->setConfigParam('iZoomPicCount', 4);
- }
- // ADODB cache life time
- if (is_null($this->getConfigParam('iDBCacheLifeTime'))) {
- $this->setConfigParam('iDBCacheLifeTime', 3600); // 1 hour
- }
- if (is_null($this->getConfigParam('iDebug'))) {
- $this->setConfigParam('iDebug', $this->isProductiveMode() ? 0 : -1);
- }
- $sCoreDir = $this->getConfigParam('sShopDir');
- $this->setConfigParam('sCoreDir', $sCoreDir . '/core/');
- }
- /**
- * Loads vars from custom config file
- */
- protected function _loadCustomConfig()
- {
- $sCustConfig = getShopBasePath() . '/cust_config.inc.php';
- if (is_readable($sCustConfig)) {
- include $sCustConfig;
- }
- }
- /**
- * Load config values from DB
- *
- * @param string $sShopID shop ID to load parameters
- * @param array $aOnlyVars array of params to load (optional)
- * @param string $sModule module vars to load, empty for base options
- *
- * @return bool
- */
- protected function _loadVarsFromDb($sShopID, $aOnlyVars = null, $sModule = '')
- {
- $oDb = oxDb::getDb();
- $sModuleSql = $sModule ? " oxmodule LIKE " . $oDb->quote($sModule . "%") : " oxmodule='' ";
- $sOnlyVarsSql = $this->_getConfigParamsSelectSnippet($aOnlyVars);
- $sSelect = "select
- oxvarname, oxvartype, " . $this->getDecodeValueQuery() . " as oxvarvalue
- from oxconfig
- where oxshopid = '$sShopID' and " . $sModuleSql . $sOnlyVarsSql;
- $aResult = $oDb->getAll($sSelect);
- foreach ($aResult as $aValue) {
- $sVarName = $aValue[0];
- $sVarType = $aValue[1];
- $sVarVal = $aValue[2];
- $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
- //setting theme options array
- if ($sModule) {
- $this->_aThemeConfigParams[$sVarName] = $sModule;
- }
- }
- return (bool) count($aResult);
- }
- /**
- * Allow loading from some vars only from baseshop
- *
- * @param array $aVars
- *
- * @return string
- */
- protected function _getConfigParamsSelectSnippet($aVars)
- {
- $sSelect = '';
- if (is_array($aVars) && !empty($aVars)) {
- foreach ($aVars as &$sField) {
- $sField = '"' . $sField . '"';
- }
- $sSelect = ' and oxvarname in ( ' . implode(', ', $aVars) . ' ) ';
- }
- return $sSelect;
- }
- /**
- * Sets config variable to config object, first unserializing it by given type.
- * sShopURL and sSSLShopURL are skipped for admin or when URL values are not set
- *
- * @param string $sVarName variable name
- * @param string $sVarType variable type - arr, aarr, bool or str
- * @param string $sVarVal serialized by type value
- *
- * @return null
- */
- protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
- {
- if (($sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL') &&
- (!$sVarVal || $this->isAdmin() === true)
- ) {
- return;
- }
- switch ($sVarType) {
- case 'arr':
- case 'aarr':
- $this->setConfigParam($sVarName, unserialize($sVarVal));
- break;
- case 'bool':
- $this->setConfigParam($sVarName, ($sVarVal == 'true' || $sVarVal == '1'));
- break;
- default:
- $this->setConfigParam($sVarName, $sVarVal);
- break;
- }
- }
- /**
- * Unsets all session data.
- *
- * @return null
- */
- public function pageClose()
- {
- if ($this->hasActiveViewsChain()) {
- // do not commit session until active views chain exists
- return;
- }
- return $this->_oStart->pageClose();
- }
- /**
- * Returns value of parameter stored in POST,GET.
- * For security reasons performed oxconfig->checkParamSpecialChars().
- * use $blRaw very carefully if you want to get unescaped
- * parameter.
- *
- * @param string $sName Name of parameter
- * @param bool $blRaw Get unescaped parameter
- *
- * @return mixed
- */
- public function getRequestParameter($sName, $blRaw = false)
- {
- if (defined('OXID_PHP_UNIT')) {
- if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
- try {
- $sValue = modConfig::getRequestParameter($sName, $blRaw);
- // TODO: remove this after special chars concept implementation
- $blIsAdmin = modConfig::getInstance()->isAdmin() || modSession::getInstance()->getVariable("blIsAdmin");
- if ($sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
- $this->checkParamSpecialChars($sValue, $blRaw);
- }
- return $sValue;
- } catch (Exception $e) {
- // if exception is thrown, use default
- }
- }
- }
- $sValue = null;
- if (isset($_POST[$sName])) {
- $sValue = $_POST[$sName];
- } elseif (isset($_GET[$sName])) {
- $sValue = $_GET[$sName];
- }
- // TODO: remove this after special chars concept implementation
- $blIsAdmin = $this->isAdmin() && $this->getSession()->getVariable("blIsAdmin");
- if ($sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
- $this->checkParamSpecialChars($sValue, $blRaw);
- }
- return $sValue;
- }
- /**
- * Returns uploaded file parameter
- *
- * @param array $sParamName param name
- *
- * @return null
- */
- public function getUploadedFile($sParamName)
- {
- return $_FILES[$sParamName];
- }
- /**
- * Sets global parameter value
- *
- * @param string $sName name of parameter
- * @param mixed $sValue value to store
- */
- public function setGlobalParameter($sName, $sValue)
- {
- $this->_aGlobalParams[$sName] = $sValue;
- }
- /**
- * Returns global parameter value
- *
- * @param string $sName name of cached parameter
- *
- * @return mixed
- */
- public function getGlobalParameter($sName)
- {
- if (isset($this->_aGlobalParams[$sName])) {
- return $this->_aGlobalParams[$sName];
- } else {
- return null;
- }
- }
- /**
- * Checks if passed parameter has special chars and replaces them.
- * Returns checked value.
- *
- * @param mixed &$sValue value to process escaping
- * @param array $aRaw keys of unescaped values
- *
- * @return mixed
- */
- public function checkParamSpecialChars(& $sValue, $aRaw = null)
- {
- if (is_object($sValue)) {
- return $sValue;
- }
- if (is_array($sValue)) {
- $newValue = array();
- foreach ($sValue as $sKey => $sVal) {
- $sValidKey = $sKey;
- if (!$aRaw || !in_array($sKey, $aRaw)) {
- $this->checkParamSpecialChars($sValidKey);
- $this->checkParamSpecialChars($sVal);
- if ($sValidKey != $sKey) {
- unset ($sValue[$sKey]);
- }
- }
- $newValue[$sValidKey] = $sVal;
- }
- $sValue = $newValue;
- } elseif (is_string($sValue)) {
- $sValue = str_replace(
- array('&', '<', '>', '"', "'", chr(0), '\\', "\n", "\r"),
- array('&', '<', '>', '"', ''', '', '\', ' ', ' '),
- $sValue
- );
- }
- return $sValue;
- }
- /**
- * Active Shop id setter
- *
- * @param string $sShopId shop id
- *
- * @return null
- */
- public function setShopId($sShopId)
- {
- $this->getSession()->setVariable('actshop', $sShopId);
- $this->_iShopId = $sShopId;
- }
- /**
- * Returns active shop ID.
- *
- * @return int
- */
- public function getShopId()
- {
- if ($this->_iShopId !== null) {
- return $this->_iShopId;
- }
- $this->setShopId($this->getBaseShopId());
- $this->getSession()->setVariable('actshop', $this->_iShopId);
- return $this->_iShopId;
- }
- /**
- * Set is shop url
- *
- * @param bool $blIsSsl - state bool value
- */
- public function setIsSsl($blIsSsl = false)
- {
- $this->_blIsSsl = $blIsSsl;
- }
- /**
- * Checks if WEB session is SSL.
- */
- protected function _checkSsl()
- {
- $myUtilsServer = oxRegistry::get("oxUtilsServer");
- $aServerVars = $myUtilsServer->getServerVar();
- $aHttpsServerVar = $myUtilsServer->getServerVar('HTTPS');
- $this->setIsSsl();
- if (isset($aHttpsServerVar) && ($aHttpsServerVar === 'on' || $aHttpsServerVar === 'ON' || $aHttpsServerVar == '1')) {
- // "1&1" hoster provides "1"
- $this->setIsSsl($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
- if ($this->isAdmin() && !$this->_blIsSsl) {
- //#4026
- $this->setIsSsl(!is_null($this->getConfigParam('sAdminSSLURL')));
- }
- }
- //additional special handling for profihost customers
- if (isset($aServerVars['HTTP_X_FORWARDED_SERVER']) &&
- (strpos($aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl') !== false ||
- strpos($aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de') !== false)
- ) {
- $this->setIsSsl(true);
- }
- }
- /**
- * Checks if WEB session is SSL. Returns true if yes.
- *
- * @return bool
- */
- public function isSsl()
- {
- if (is_null($this->_blIsSsl)) {
- $this->_checkSsl();
- }
- return $this->_blIsSsl;
- }
- /**
- * Compares current URL to supplied string
- *
- * @param string $sURL URL
- *
- * @return bool true if $sURL is equal to current page URL
- */
- public function isCurrentUrl($sURL)
- {
- // Missing protocol, cannot proceed, assuming true.
- if (!$sURL || (strpos($sURL, "http") !== 0)) {
- return true;
- }
- return oxRegistry::get("oxUtilsServer")->isCurrentUrl($sURL);
- }
- /**
- * Compares current protocol to supplied url string
- *
- * @param string $sURL URL
- *
- * @return bool true if $sURL is equal to current page URL
- */
- public function isCurrentProtocol($sURL)
- {
- // Missing protocol, cannot proceed, assuming true.
- if (!$sURL || (strpos($sURL, "http") !== 0)) {
- return true;
- }
- return (strpos($sURL, "https:") === 0) == $this->isSsl();
- }
- /**
- * Returns config sShopURL or sMallShopURL if secondary shop
- *
- * @param int $iLang language
- * @param bool $blAdmin if set true, function returns shop url without checking language/subshops for different url.
- *
- * @return string
- */
- public function getShopUrl($iLang = null, $blAdmin = null)
- {
- $sUrl = null;
- $blAdmin = isset($blAdmin) ? $blAdmin : $this->isAdmin();
- if (!$blAdmin) {
- $sUrl = $this->getShopUrlByLanguage($iLang);
- if (!$sUrl) {
- $sUrl = $this->getMallShopUrl();
- }
- }
- if (!$sUrl) {
- $sUrl = $this->getConfigParam('sShopURL');
- }
- return $sUrl;
- }
- /**
- * Returns config sSSLShopURL or sMallSSLShopURL if secondary shop
- *
- * @param int $iLang language (default is null)
- *
- * @return string
- */
- public function getSslShopUrl($iLang = null)
- {
- $sUrl = null;
- if (!$sUrl) {
- $sUrl = $this->getShopUrlByLanguage($iLang, true);
- }
- if (!$sUrl) {
- $sUrl = $this->getMallShopUrl(true);
- }
- if (!$sUrl) {
- $sUrl = $this->getMallShopUrl();
- }
- //normal section
- if (!$sUrl) {
- $sUrl = $this->getConfigParam('sSSLShopURL');
- }
- if (!$sUrl) {
- $sUrl = $this->getShopUrl($iLang);
- }
- return $sUrl;
- }
- /**
- * Returns utils dir URL
- *
- * @return string
- */
- public function getCoreUtilsUrl()
- {
- return $this->getCurrentShopUrl() . 'core/utils/';
- }
- /**
- * Returns SSL or non SSL shop URL without index.php depending on Mall
- * affecting environment is admin mode and current ssl usage status
- *
- * @param bool $blAdmin if admin
- *
- * @return string
- */
- public function getCurrentShopUrl($blAdmin = null)
- {
- if ($blAdmin === null) {
- $blAdmin = $this->isAdmin();
- }
- if ($blAdmin) {
- if ($this->isSsl()) {
- $sUrl = $this->getConfigParam('sAdminSSLURL');
- if (!$sUrl) {
- return $this->getSslShopUrl() . $this->getConfigParam('sAdminDir') . '/';
- }
- return $sUrl;
- } else {
- return $this->getShopUrl() . $this->getConfigParam('sAdminDir') . '/';
- }
- } else {
- return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
- }
- }
- /**
- * Returns SSL or not SSL shop URL with index.php and sid
- *
- * @param int $iLang language (optional)
- *
- * @return string
- */
- public function getShopCurrentUrl($iLang = null)
- {
- if ($this->isSsl()) {
- $sURL = $this->getSSLShopURL($iLang);
- } else {
- $sURL = $this->getShopURL($iLang);
- }
- return oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'index.php', false);
- }
- /**
- * Returns shop non SSL URL including index.php and sid.
- *
- * @param int $iLang language
- * @param bool $blAdmin if admin
- *
- * @return string
- */
- public function getShopHomeUrl($iLang = null, $blAdmin = null)
- {
- return oxRegistry::get("oxUtilsUrl")->processUrl($this->getShopUrl($iLang, $blAdmin) . 'index.php', false);
- }
- /**
- * Returns widget start non SSL URL including widget.php and sid.
- *
- * @param int $iLang language
- * @param bool $blAdmin if admin
- *
- * @return string
- */
- public function getWidgetUrl($iLang = null, $blAdmin = null)
- {
- $sUrl = $this->isSsl() ? $this->getSslShopUrl($iLang) : $this->getShopUrl($iLang, $blAdmin);
- return oxRegistry::get('oxUtilsUrl')->processUrl($sUrl . 'widget.php', false);
- }
- /**
- * Returns shop SSL URL with index.php and sid.
- *
- * @return string
- */
- public function getShopSecureHomeUrl()
- {
- return oxRegistry::get("oxUtilsUrl")->processUrl($this->getSslShopUrl() . 'index.php', false);
- }
- /**
- * Returns active shop currency.
- *
- * @return string
- */
- public function getShopCurrency()
- {
- $iCurr = null;
- if ((null === ($iCurr = $this->getRequestParameter('cur')))) {
- if (null === ($iCurr = $this->getRequestParameter('currency'))) {
- $iCurr = $this->getSession()->getVariable('currency');
- }
- }
- return (int) $iCurr;
- }
- /**
- * Returns active shop currency object.
- *
- * @return object
- */
- public function getActShopCurrencyObject()
- {
- //caching currency as it does not change through the script
- //but not for unit tests as ther it changes always
- if (!defined('OXID_PHP_UNIT')) {
- if (!is_null($this->_oActCurrencyObject)) {
- return $this->_oActCurrencyObject;
- }
- }
- $iCur = $this->getShopCurrency();
- $aCurrencies = $this->getCurrencyArray();
- if (!isset($aCurrencies[$iCur])) {
- return $this->_oActCurrencyObject = reset($aCurrencies); // reset() returns the first element
- }
- return $this->_oActCurrencyObject = $aCurrencies[$iCur];
- }
- /**
- * Sets the actual currency
- *
- * @param int $iCur 0 = EUR, 1 = GBP, 2 = CHF
- */
- public function setActShopCurrency($iCur)
- {
- $aCurrencies = $this->getCurrencyArray();
- if (isset($aCurrencies[$iCur])) {
- $this->getSession()->setVariable('currency', $iCur);
- $this->_oActCurrencyObject = null;
- }
- }
- /**
- * Returns path to out dir
- *
- * @param bool $blAbsolute mode - absolute/relative path
- *
- * @return string
- */
- public function getOutDir($blAbsolute = true)
- {
- if ($blAbsolute) {
- return $this->getConfigParam('sShopDir') . $this->_sOutDir . '/';
- } else {
- return $this->_sOutDir . '/';
- }
- }
- /**
- * Returns path to out dir
- *
- * @param bool $blAbsolute mode - absolute/relative path
- *
- * @return string
- */
- public function getViewsDir($blAbsolute = true)
- {
- if ($blAbsolute) {
- return $this->getConfigParam('sShopDir') . 'application/views/';
- } else {
- return 'application/views/';
- }
- }
- /**
- * Returns path to translations dir
- *
- * @param string $sFile File name
- * @param string $sDir Directory name
- * @param bool $blAbsolute mode - absolute/relative path
- *
- * @return string
- */
- public function getTranslationsDir($sFile, $sDir, $blAbsolute = true)
- {
- $sPath = $blAbsolute ? $this->getConfigParam('sShopDir') : '';
- $sPath .= 'application/translations/';
- if (is_readable($sPath . $sDir . '/' . $sFile)) {
- return $sPath . $sDir . '/' . $sFile;
- }
- return false;
- }
- /**
- * Returns path to out dir
- *
- * @param bool $blAbsolute mode - absolute/relative path
- *
- * @return string
- */
- public function getAppDir($blAbsolute = true)
- {
- if ($blAbsolute) {
- return $this->getConfigParam('sShopDir') . 'application/';
- } else {
- return 'application/';
- }
- }
- /**
- * Returns url to out dir
- *
- * @param bool $blSSL Whether to force ssl
- * @param bool $blAdmin Whether to force admin
- * @param bool $blNativeImg Whether to force native image dirs
- *
- * @return string
- */
- public function getOutUrl($blSSL = null, $blAdmin = null, $blNativeImg = false)
- {
- $blSSL = is_null($blSSL) ? $this->isSsl() : $blSSL;
- $blAdmin = is_null($blAdmin) ? $this->isAdmin() : $blAdmin;
- if ($blSSL) {
- if ($blNativeImg && !$blAdmin) {
- $sUrl = $this->getSslShopUrl();
- } else {
- $sUrl = $this->getConfigParam('sSSLShopURL');
- if (!$sUrl && $blAdmin) {
- $sUrl = $this->getConfigParam('sAdminSSLURL') . '../';
- }
- }
- } else {
- $sUrl = ($blNativeImg && !$blAdmin) ? $this->getShopUrl() : $this->getConfigParam('sShopURL');
- }
- return $sUrl . $this->_sOutDir . '/';
- }
- /**
- * Finds and returns files or folders path in out dir
- *
- * @param string $sFile File name
- * @param string $sDir Directory name
- * @param bool $blAdmin Whether to force admin
- * @param int $iLang Language id
- * @param int $iShop Shop id
- * @param string $sTheme Theme name
- * @param bool $blAbsolute mode - absolute/relative path
- * @param bool $blIgnoreCust Ignore custom theme
- *
- * @return string
- */
- public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false)
- {
- if (is_null($sTheme)) {
- $sTheme = $this->getConfigParam('sTheme');
- }
- if ($blAdmin) {
- $sTheme = 'admin';
- }
- if ($sDir != $this->_sTemplateDir) {
- $sBase = $this->getOutDir($blAbsolute);
- $sAbsBase = $this->getOutDir();
- } else {
- $sBase = $this->getViewsDir($blAbsolute);
- $sAbsBase = $this->getViewsDir();
- }
- $sLang = '-';
- // FALSE means skip language folder check
- if ($iLang !== false) {
- $oLang = oxRegistry::getLang();
- if (is_null($iLang)) {
- $iLang = $oLang->getEditLanguage();
- }
- $sLang = $oLang->getLanguageAbbr($iLang);
- }
- if (is_null($iShop)) {
- $iShop = $this->getShopId();
- }
- //Load from
- $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
- $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
- if (($sReturn = oxRegistry::getUtils()->fromStaticCache($sCacheKey)) !== null) {
- return $sReturn;
- }
- $sReturn = false;
- // Check for custom template
- $sCustomTheme = $this->getConfigParam('sCustomTheme');
- if (!$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
- $sReturn = $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute);
- }
- //test lang level ..
- if (!$sReturn && !$blAdmin && is_readable($sAbsBase . $sPath)) {
- $sReturn = $sBase . $sPath;
- }
- //test shop level ..
- $sPath = "$sTheme/$iShop/$sDir/$sFile";
- if (!$sReturn && !$blAdmin && is_readable($sAbsBase . $sPath)) {
- $sReturn = $sBase . $sPath;
- }
- //test theme language level ..
- $sPath = "$sTheme/$sLang/$sDir/$sFile";
- if (!$sReturn && $iLang !== false && is_readable($sAbsBase . $sPath)) {
- $sReturn = $sBase . $sPath;
- }
- //test theme level ..
- $sPath = "$sTheme/$sDir/$sFile";
- if (!$sReturn && is_readable($sAbsBase . $sPath)) {
- $sReturn = $sBase . $sPath;
- }
- //test out language level ..
- $sPath = "$sLang/$sDir/$sFile";
- if (!$sReturn && $iLang !== false && is_readable($sAbsBase . $sPath)) {
- $sReturn = $sBase . $sPath;
- }
- //test out level ..
- $sPath = "$sDir/$sFile";
- if (!$sReturn && is_readable($sAbsBase . $sPath)) {
- $sReturn = $sBase . $sPath;
- }
- if (!$sReturn) {
- // TODO: implement logic to log missing paths
- }
- // to cache
- oxRegistry::getUtils()->toStaticCache($sCacheKey, $sReturn);
- return $sReturn;
- }
- /**
- * Finds and returns file or folder url in out dir
- *
- * @param string $sFile File name
- * @param string $sDir Directory name
- * @param bool $blAdmin Whether to force admin
- * @param bool $blSSL Whether to force ssl
- * @param bool $blNativeImg Whether to force native image dirs
- * @param int $iLang Language id
- * @param int $iShop Shop id
- * @param string $sTheme Theme name
- *
- * @return string
- */
- public function getUrl($sFile, $sDir, $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null, $iShop = null, $sTheme = null)
- {
- $sUrl = str_replace(
- $this->getOutDir(),
- $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
- $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme)
- );
- return $sUrl;
- }
- /**
- * Finds and returns image files or folders path
- *
- * @param string $sFile File name
- * @param bool $blAdmin Whether to force admin
- *
- * @return string
- */
- public function getImagePath($sFile, $blAdmin = false)
- {
- return $this->getDir($sFile, $this->_sImageDir, $blAdmin);
- }
- /**
- * Finds and returns image folder url
- *
- * @param bool $blAdmin Whether to force admin
- * @param bool $blSSL Whether to force ssl
- * @param bool $blNativeImg Whether to force native image dirs
- * @param string $sFile Image file name
- *
- * @return string
- */
- public function getImageUrl($blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null)
- {
- $blNativeImg = is_null($blNativeImg) ? $this->getConfigParam('blNativeImages') : $blNativeImg;
- return $this->getUrl($sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg);
- }
- /**
- * Finds and returns image folders path
- *
- * @param bool $blAdmin Whether to force admin
- *
- * @return string
- */
- public function getImageDir($blAdmin = false)
- {
- return $this->getDir(null, $this->_sImageDir, $blAdmin);
- }
- /**
- * Finds and returns product pictures files or folders path
- *
- * @param string $sFile File name
- * @param bool $blAdmin Whether to force admin
- * @param int $iLang Language
- * @param int $iShop Shop id
- * @param string $sTheme theme name
- *
- * @return string
- */
- public function getPicturePath($sFile, $blAdmin = false, $iLang = null, $iShop = null, $sTheme = null)
- {
- return $this->getDir($sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme);
- }
- /**
- * Finds and returns master pictures folder path
- *
- * @param bool $blAdmin Whether to force admin
- *
- * @return string
- */
- public function getMasterPictureDir($blAdmin = false)
- {
- return $this->getDir(null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin);
- }
- /**
- * Finds and returns master picture path
- *
- * @param string $sFile File name
- * @param bool $blAdmin Whether to force admin
- *
- * @return string
- */
- public function getMasterPicturePath($sFile, $blAdmin = false)
- {
- return $this->getDir($sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin);
- }
- /**
- * Finds and returns product picture file or folder url
- *
- * @param string $sFile File name
- * @param bool $blAdmin Whether to force admin
- * @param bool $blSSL Whether to force ssl
- * @param int $iLang Language
- * @param int $iShopId Shop id
- * @param string $sDefPic Default (nopic) image path ["0/nopic.jpg"]
- *
- * @return string
- */
- public function getPictureUrl($sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg")
- {
- if ($sAltUrl = oxRegistry::get("oxPictureHandler")->getAltImageUrl('/', $sFile, $blSSL)) {
- return $sAltUrl;
- }
- $blNativeImg = $this->getConfigParam('blNativeImages');
- $sUrl = $this->getUrl($sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId);
- //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
- if (!$sUrl && $sDefPic) {
- $sUrl = $this->getUrl($sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId);
- }
- return $sUrl;
- }
- /**
- * Finds and returns product pictures folders path
- *
- * @param bool $blAdmin Whether to force admin
- *
- * @return string
- */
- public function getPictureDir($blAdmin)
- {
- return $this->getDir(null, $this->_sPictureDir, $blAdmin);
- }
- /**
- * Finds and returns templates files or folders path
- *
- * @param string $sFile File name
- * @param bool $blAdmin Whether to force admin
- *
- * @return string
- */
- public function getTemplatePath($sFile, $blAdmin)
- {
- $sTemplatePath = $this->getDir($sFile, $this->_sTemplateDir, $blAdmin);
- if (!$sTemplatePath) {
- $sBasePath = getShopBasePath();
- $aModuleTemplates = $this->getConfigParam('aModuleTemplates');
- $oModulelist = oxNew('oxmodulelist');
- $aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
- if (is_array($aModuleTemplates) && is_array($aActiveModuleInfo)) {
- foreach ($aModuleTemplates as $sModuleId => $aTemplates) {
- if (isset($aTemplates[$sFile]) && isset($aActiveModuleInfo[$sModuleId])) {
- $sPath = $aTemplates[$sFile];
- $sPath = $sBasePath . 'modules/' . $sPath;
- if (is_file($sPath) && is_readable($sPath)) {
- $sTemplatePath = $sPath;
- }
- }
- }
- }
- }
- return $sTemplatePath;
- }
- /**
- * Finds and returns templates folders path
- *
- * @param bool $blAdmin Whether to force admin
- *
- * @return string
- */
- public function getTemplateDir($blAdmin = false)
- {
- return $this->getDir(null, $this->_sTemplateDir, $blAdmin);
- }
- /**
- * Finds and returns template file or folder url
- *
- * @param string $sFile File name
- * @param bool $blAdmin Whether to force admin
- * @param bool $blSSL Whether to force ssl
- * @param int $iLang Language id
- *
- * @return string
- */
- public function getTemplateUrl($sFile = null, $blAdmin = false, $blSSL = null, $iLang = null)
- {
- return $this->getShopMainUrl() . $this->getDir($sFile, $this->_sTemplateDir, $blAdmin, $iLang, null, null, false);
- }
- /**
- * Finds and returns base template folder url
- *
- * @param bool $blAdmin Whether to force admin
- *
- * @return string
- */
- public function getTemplateBase($blAdmin = false)
- {
- // Base template dir is the parent dir of template dir
- return str_replace($this->_sTemplateDir . '/', '', $this->getDir(null, $this->_sTemplateDir, $blAdmin, null, null, null, false));
- }
- /**
- * Finds and returns resource (css, js, etc..) files or folders path
- *
- * @param string $sFile File name
- * @param bool $blAdmin Whether to force admin
- *
- * @return string
- */
- public function getResourcePath($sFile = '', $blAdmin = false)
- {
- return $this->getDir($sFile, $this->_sResourceDir, $blAdmin);
- }
- /**
- * Returns path to modules dir
- *
- * @param bool $blAbsolute mode - absolute/relative path
- *
- * @return string
- */
- public function getModulesDir($blAbsolute = true)
- {
- if ($blAbsolute) {
- return $this->getConfigParam('sShopDir') . $this->_sModulesDir . '/';
- } else {
- return $this->_sModulesDir . '/';
- }
- }
- /**
- * Finds and returns resource (css, js, etc..) file or folder url
- *
- * @param string $sFile File name
- * @param bool $blAdmin Whether to force admin
- * @param bool $blSSL Whether to force ssl
- * @param int $iLang Language id
- *
- * @return string
- */
- public function getResourceUrl($sFile = '', $blAdmin = false, $blSSL = null, $iLang = null)
- {
- $blNativeImg = $this->getConfigParam('blNativeImages');
- return $this->getUrl($sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang);
- }
- /**
- * Finds and returns resource (css, js, etc..) folders path
- *
- * @param bool $blAdmin Whether to force admin
- *
- * @return string
- */
- public function getResourceDir($blAdmin)
- {
- return $this->getDir(null, $this->_sResourceDir, $blAdmin);
- }
- /**
- * Returns array of available currencies
- *
- * @param integer $iCurrency Active currency number (default null)
- *
- * @return array
- */
- public function getCurrencyArray($iCurrency = null)
- {
- $aConfCurrencies = $this->getConfigParam('aCurrencies');
- if (!is_array($aConfCurrencies)) {
- return array();
- }
- if (defined('OXID_PHP_UNIT')) {
- if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
- try {
- $aAltCurrencies = modConfig::getInstance()->getConfigParam('modaCurrencies');
- if (isset($aAltCurrencies)) {
- $aConfCurrencies = $aAltCurrencies;
- }
- } catch (Exception $e) {
- // if exception is thrown, use default
- }
- }
- }
- // processing currency configuration data
- $aCurrencies = array();
- reset($aConfCurrencies);
- while (list($key, $val) = each($aConfCurrencies)) {
- if ($val) {
- $oCur = new stdClass();
- $oCur->id = $key;
- $sCur = explode('@', $val);
- $oCur->name = trim($sCur[0]);
- $oCur->rate = trim($sCur[1]);
- $oCur->dec = trim($sCur[2]);
- $oCur->thousand = trim($sCur[3]);
- $oCur->sign = trim($sCur[4]);
- $oCur->decimal = trim($sCur[5]);
- // change for US version
- if (isset($sCur[6])) {
- $oCur->side = trim($sCur[6]);
- }
- if (isset($iCurrency) && $key == $iCurrency) {
- $oCur->selected = 1;
- } else {
- $oCur->selected = 0;
- }
- $aCurrencies[$key] = $oCur;
- }
- // #861C - performance, do not load other currencies
- if (!$this->getConfigParam('bl_perfLoadCurrency')) {
- break;
- }
- }
- return $aCurrencies;
- }
- /**
- * Returns currency object.
- *
- * @param string $sName Name of active currency
- *
- * @return object
- */
- public function getCurrencyObject($sName)
- {
- $aSearch = $this->getCurrencyArray();
- foreach ($aSearch as $oCur) {
- if ($oCur->name == $sName) {
- return $oCur;
- }
- }
- }
- /**
- * Checks if the shop is in demo mode.
- *
- * @return bool
- */
- public function isDemoShop()
- {
- return $this->getConfigParam('blDemoShop');
- }
- /**
- * Returns OXID eShop edition
- *
- * @return string
- */
- public function getEdition()
- {
- return "CE";
- }
- /**
- * Returns full eShop edition name
- *
- * @return string
- */
- public function getFullEdition()
- {
- $sEdition = $this->getEdition();
- if ($sEdition == "CE") {
- return "Community Edition";
- }
- return $sEdition;
- }
- /**
- * Returns shops version number (eg. '4.4.2')
- *
- * @return string
- */
- public function getVersion()
- {
- $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
- return $sVersion;
- }
- /**
- * Returns build revision number or false on read error.
- *
- * @return int
- */
- public function getRevision()
- {
- $sFileName = $this->getConfigParam('sShopDir') . "/pkg.rev";
- $sRev = trim(@file_get_contents($sFileName));
- if (!$sRev) {
- return false;
- }
- return $sRev;
- }
- /**
- * Returns build package info file content.
- *
- * @return bool|string
- */
- public function getPackageInfo()
- {
- $sFileName = $this->getConfigParam('sShopDir') . "/pkg.info";
- $sRev = @file_get_contents($sFileName);
- $sRev = str_replace("\n", "<br>", $sRev);
- if (!$sRev) {
- return false;
- }
- return $sRev;
- }
- /**
- * Counts OXID mandates
- *
- * @return int
- */
- public function getMandateCount()
- {
- $iShopCount = 1;
- return $iShopCount;
- }
- /**
- * Checks if shop is MALL. Returns true on success.
- *
- * @return bool
- */
- public function isMall()
- {
- return false;
- }
- /**
- * Checks version of shop, returns:
- * 0 - version is bellow 2.2
- * 1 - Demo or unlicensed
- * 2 - Pro
- * 3 - Enterprise
- *
- * @return int
- */
- public function detectVersion()
- {
- }
- /**
- * Updates or adds new shop configuration parameters to DB.
- * Arrays must be passed not serialized, serialized values are supported just for backward compatibility.
- *
- * @param string $sVarType Variable Type
- * @param string $sVarName Variable name
- * @param mixed $sVarVal Variable value (can be string, integer or array)
- * @param string $sShopId Shop ID, default is current shop
- * @param string $sModule Module name (empty for base options)
- */
- public function saveShopConfVar($sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '')
- {
- switch ($sVarType) {
- case 'arr':
- case 'aarr':
- $sValue = serialize($sVarVal);
- break;
- case 'bool':
- //config param
- $sVarVal = (($sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
- //db value
- $sValue = $sVarVal ? "1" : "";
- break;
- case 'num':
- //config param
- $sVarVal = $sVarVal != '' ? oxRegistry::getUtils()->string2Float($sVarVal) : '';
- $sValue = $sVarVal;
- break;
- default:
- $sValue = $sVarVal;
- break;
- }
- if (!$sShopId) {
- $sShopId = $this->getShopId();
- }
- // Update value only for current shop
- if ($sShopId…
Large files files are truncated, but you can click here to view the full file