PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/source/core/oxconfig.php

https://github.com/GM-Alex/oxideshop_ce
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

  1. <?php
  2. /**
  3. * This file is part of OXID eShop Community Edition.
  4. *
  5. * OXID eShop Community Edition is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * OXID eShop Community Edition is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with OXID eShop Community Edition. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * @link http://www.oxid-esales.com
  19. * @copyright (C) OXID eSales AG 2003-2014
  20. * @version OXID eShop CE
  21. */
  22. //max integer
  23. define('MAX_64BIT_INTEGER', '18446744073709551615');
  24. /**
  25. * Main shop configuration class.
  26. *
  27. */
  28. class oxConfig extends oxSuperCfg
  29. {
  30. // this column of params are defined in config.inc.php file,
  31. // so for backwards compatibility. names starts without underscore
  32. /**
  33. * Database host name
  34. *
  35. * @var string
  36. */
  37. protected $dbHost = null;
  38. /**
  39. * Database name
  40. *
  41. * @var string
  42. */
  43. protected $dbName = null;
  44. /**
  45. * Database user name
  46. *
  47. * @var string
  48. */
  49. protected $dbUser = null;
  50. /**
  51. * Database user password
  52. *
  53. * @var string
  54. */
  55. protected $dbPwd = null;
  56. /**
  57. * Database driver type
  58. *
  59. * @var string
  60. */
  61. protected $dbType = null;
  62. /**
  63. * Shop Url
  64. *
  65. * @var string
  66. */
  67. protected $sShopURL = null;
  68. /**
  69. * Shop SSL mode Url
  70. *
  71. * @var string
  72. */
  73. protected $sSSLShopURL = null;
  74. /**
  75. * Shops admin SSL mode Url
  76. *
  77. * @var string
  78. */
  79. protected $sAdminSSLURL = null;
  80. /**
  81. * Shops install directory
  82. *
  83. * @var string
  84. */
  85. protected $sShopDir = null;
  86. /**
  87. * Shops compile directory
  88. *
  89. * @var string
  90. */
  91. protected $sCompileDir = null;
  92. /**
  93. * Debug mode (default is set depending on if it is productive mode or not):
  94. * -1 = Logger Messages internal use only
  95. * 0 = off
  96. * 1 = smarty
  97. * 2 = SQL
  98. * 3 = SQL + smarty
  99. * 4 = SQL + smarty + shop template data
  100. * 5 = Delivery Cost calculation info
  101. * 6 = SMTP Debug Messages
  102. * 7 = Slow SQL query indication
  103. *
  104. * @var int
  105. */
  106. protected $iDebug = null;
  107. /**
  108. * Administrator email address, used to send critical notices
  109. *
  110. * @var string
  111. */
  112. protected $sAdminEmail = null;
  113. /**
  114. * Use cookies
  115. *
  116. * @var bool
  117. */
  118. protected $blSessionUseCookies = null;
  119. /**
  120. * Default image loading location.
  121. * If $blNativeImages is set to true the shop loads images from current domain,
  122. * otherwise images are loaded from the domain specified in config.inc.php.
  123. * This is applicable for different domains depending on language or mall
  124. * if mall mode is available.
  125. *
  126. * @var bool
  127. */
  128. protected $blNativeImages = true;
  129. /**
  130. * Names of tables which are multi-shop
  131. *
  132. * @var array
  133. */
  134. protected $aMultiShopTables = array('oxarticles', 'oxdiscount', 'oxcategories', 'oxattribute',
  135. 'oxlinks', 'oxvoucherseries', 'oxmanufacturers',
  136. 'oxnews', 'oxselectlist', 'oxwrapping',
  137. 'oxdeliveryset', 'oxdelivery', 'oxvendor', 'oxobject2category');
  138. /**
  139. * Application starter instance
  140. *
  141. * @var oxStart
  142. */
  143. private $_oStart = null;
  144. /**
  145. * Active shop object.
  146. *
  147. * @var object
  148. */
  149. protected $_oActShop = null;
  150. /**
  151. * Active Views object array. Object has setters/getters for these properties:
  152. * _sClass - name of current view class
  153. * _sFnc - name of current action function
  154. *
  155. * @var array
  156. */
  157. protected $_aActiveViews = array();
  158. /**
  159. * Array of global parameters.
  160. *
  161. * @var array
  162. */
  163. protected $_aGlobalParams = array();
  164. /**
  165. * Shop config parameters storage array
  166. *
  167. * @var array
  168. */
  169. protected $_aConfigParams = array();
  170. /**
  171. * Theme config parameters storage array
  172. *
  173. * @var array
  174. */
  175. protected $_aThemeConfigParams = array();
  176. /**
  177. * Current language Id
  178. *
  179. * @var int
  180. */
  181. protected $_iLanguageId = null;
  182. /**
  183. * Current shop Id
  184. *
  185. * @var int
  186. */
  187. protected $_iShopId = null;
  188. /**
  189. * Out dir name
  190. *
  191. * @var string
  192. */
  193. protected $_sOutDir = 'out';
  194. /**
  195. * Image dir name
  196. *
  197. * @var string
  198. */
  199. protected $_sImageDir = 'img';
  200. /**
  201. * Dyn Image dir name
  202. *
  203. * @var string
  204. */
  205. protected $_sPictureDir = 'pictures';
  206. /**
  207. * Master pictures dir name
  208. *
  209. * @var string
  210. */
  211. protected $_sMasterPictureDir = 'master';
  212. /**
  213. * Template dir name
  214. *
  215. * @var string
  216. */
  217. protected $_sTemplateDir = 'tpl';
  218. /**
  219. * Resource dir name
  220. *
  221. * @var string
  222. */
  223. protected $_sResourceDir = 'src';
  224. /**
  225. * Modules dir name
  226. *
  227. * @var string
  228. */
  229. protected $_sModulesDir = 'modules';
  230. /**
  231. * Whether shop is in SSL mode
  232. *
  233. * @var bool
  234. */
  235. protected $_blIsSsl = null;
  236. /**
  237. * Absolute image dirs for each shops
  238. *
  239. * @var array
  240. */
  241. protected $_aAbsDynImageDir = array();
  242. /**
  243. * Active currency object
  244. *
  245. * @var array
  246. */
  247. protected $_oActCurrencyObject = null;
  248. /**
  249. * Indicates if OxConfig::init() method has been already run.
  250. * Is checked for loading config variables on demand.
  251. * Used in OxConfig::getConfigParam() method
  252. *
  253. * @var bool
  254. */
  255. protected $_blInit = false;
  256. /**
  257. * prefix for oxModule field for themes in oxConfig and oxConfigDisplay tables
  258. *
  259. * @var string
  260. */
  261. const OXMODULE_THEME_PREFIX = 'theme:';
  262. /**
  263. * prefix for oxModule field for modules in oxConfig and oxConfigDisplay tables
  264. *
  265. * @var string
  266. */
  267. const OXMODULE_MODULE_PREFIX = 'module:';
  268. /**
  269. * Returns config parameter value if such parameter exists
  270. *
  271. * @param string $sName config parameter name
  272. *
  273. * @return mixed
  274. */
  275. public function getConfigParam($sName)
  276. {
  277. if (defined('OXID_PHP_UNIT')) {
  278. if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
  279. $sValue = modConfig::$unitMOD->getModConfigParam($sName);
  280. if ($sValue !== null) {
  281. return $sValue;
  282. }
  283. }
  284. }
  285. $this->init();
  286. if (isset ($this->_aConfigParams[$sName])) {
  287. return $this->_aConfigParams[$sName];
  288. }
  289. if (isset($this->$sName)) {
  290. return $this->$sName;
  291. }
  292. }
  293. /**
  294. * Stores config parameter value in config
  295. *
  296. * @param string $sName config parameter name
  297. * @param string $sValue config parameter value
  298. */
  299. public function setConfigParam($sName, $sValue)
  300. {
  301. if (isset($this->$sName)) {
  302. $this->$sName = $sValue;
  303. } else {
  304. $this->_aConfigParams[$sName] = $sValue;
  305. }
  306. }
  307. /**
  308. * Parse SEO url parameters.
  309. */
  310. protected function _processSeoCall()
  311. {
  312. // TODO: refactor shop bootstrap and parse url params as soon as possible
  313. if (isSearchEngineUrl()) {
  314. oxNew('oxSeoDecoder')->processSeoCall();
  315. }
  316. }
  317. /**
  318. * Starts session manager
  319. *
  320. * @throws oxConnectionException
  321. *
  322. * @return null
  323. */
  324. public function init()
  325. {
  326. // Duplicated init protection
  327. if ($this->_blInit) {
  328. return;
  329. }
  330. $this->_blInit = true;
  331. $this->_loadVarsFromFile();
  332. include getShopBasePath() . 'core/oxconfk.php';
  333. // setting ADODB timeout
  334. global $ADODB_SESS_LIFE;
  335. $ADODB_SESS_LIFE = 1;
  336. $this->_setDefaults();
  337. try {
  338. $sShopID = $this->getShopId();
  339. $blConfigLoaded = $this->_loadVarsFromDb($sShopID);
  340. // loading shop config
  341. if (empty($sShopID) || !$blConfigLoaded) {
  342. // if no config values where loaded (some problems with DB), throwing an exception
  343. $oEx = new oxConnectionException();
  344. $oEx->setMessage("Unable to load shop config values from database");
  345. throw $oEx;
  346. }
  347. // loading theme config options
  348. $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme'));
  349. // checking if custom theme (which has defined parent theme) config options should be loaded over parent theme (#3362)
  350. if ($this->getConfigParam('sCustomTheme')) {
  351. $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_THEME_PREFIX . $this->getConfigParam('sCustomTheme'));
  352. }
  353. // loading modules config
  354. $this->_loadVarsFromDb($sShopID, null, oxConfig::OXMODULE_MODULE_PREFIX);
  355. $this->_processSeoCall();
  356. //starting up the session
  357. $this->getSession()->start();
  358. // Admin handling
  359. $this->setConfigParam('blAdmin', isAdmin());
  360. if (defined('OX_ADMIN_DIR')) {
  361. $this->setConfigParam('sAdminDir', OX_ADMIN_DIR);
  362. }
  363. $this->_loadVarsFromFile();
  364. //application initialization
  365. $this->_oStart = new oxStart();
  366. $this->_oStart->appInit();
  367. } catch (oxConnectionException $oEx) {
  368. return $this->_handleDbConnectionException($oEx);
  369. } catch (oxCookieException $oEx) {
  370. return $this->_handleCookieException($oEx);
  371. }
  372. }
  373. /**
  374. * Loads vars from default config file
  375. */
  376. protected function _loadVarsFromFile()
  377. {
  378. //config variables from config.inc.php takes priority over the ones loaded from db
  379. include getShopBasePath() . '/config.inc.php';
  380. //adding trailing slashes
  381. $oFileUtils = oxRegistry::get("oxUtilsFile");
  382. $this->sShopDir = $oFileUtils->normalizeDir($this->sShopDir);
  383. $this->sCompileDir = $oFileUtils->normalizeDir($this->sCompileDir);
  384. $this->sShopURL = $oFileUtils->normalizeDir($this->sShopURL);
  385. $this->sSSLShopURL = $oFileUtils->normalizeDir($this->sSSLShopURL);
  386. $this->sAdminSSLURL = $oFileUtils->normalizeDir($this->sAdminSSLURL);
  387. $this->_loadCustomConfig();
  388. }
  389. /**
  390. * Set important defaults.
  391. */
  392. protected function _setDefaults()
  393. {
  394. $this->setConfigParam('sTheme', 'azure');
  395. if (is_null($this->getConfigParam('sDefaultLang'))) {
  396. $this->setConfigParam('sDefaultLang', 0);
  397. }
  398. if (is_null($this->getConfigParam('blLogChangesInAdmin'))) {
  399. $this->setConfigParam('blLogChangesInAdmin', false);
  400. }
  401. if (is_null($this->getConfigParam('blCheckTemplates'))) {
  402. $this->setConfigParam('blCheckTemplates', false);
  403. }
  404. if (is_null($this->getConfigParam('blAllowArticlesubclass'))) {
  405. $this->setConfigParam('blAllowArticlesubclass', false);
  406. }
  407. if (is_null($this->getConfigParam('iAdminListSize'))) {
  408. $this->setConfigParam('iAdminListSize', 9);
  409. }
  410. // #1173M for EE - not all pic are deleted
  411. if (is_null($this->getConfigParam('iPicCount'))) {
  412. $this->setConfigParam('iPicCount', 7);
  413. }
  414. if (is_null($this->getConfigParam('iZoomPicCount'))) {
  415. $this->setConfigParam('iZoomPicCount', 4);
  416. }
  417. // ADODB cache life time
  418. if (is_null($this->getConfigParam('iDBCacheLifeTime'))) {
  419. $this->setConfigParam('iDBCacheLifeTime', 3600); // 1 hour
  420. }
  421. if (is_null($this->getConfigParam('iDebug'))) {
  422. $this->setConfigParam('iDebug', $this->isProductiveMode() ? 0 : -1);
  423. }
  424. $sCoreDir = $this->getConfigParam('sShopDir');
  425. $this->setConfigParam('sCoreDir', $sCoreDir . '/core/');
  426. }
  427. /**
  428. * Loads vars from custom config file
  429. */
  430. protected function _loadCustomConfig()
  431. {
  432. $sCustConfig = getShopBasePath() . '/cust_config.inc.php';
  433. if (is_readable($sCustConfig)) {
  434. include $sCustConfig;
  435. }
  436. }
  437. /**
  438. * Load config values from DB
  439. *
  440. * @param string $sShopID shop ID to load parameters
  441. * @param array $aOnlyVars array of params to load (optional)
  442. * @param string $sModule module vars to load, empty for base options
  443. *
  444. * @return bool
  445. */
  446. protected function _loadVarsFromDb($sShopID, $aOnlyVars = null, $sModule = '')
  447. {
  448. $oDb = oxDb::getDb();
  449. $sModuleSql = $sModule ? " oxmodule LIKE " . $oDb->quote($sModule . "%") : " oxmodule='' ";
  450. $sOnlyVarsSql = $this->_getConfigParamsSelectSnippet($aOnlyVars);
  451. $sSelect = "select
  452. oxvarname, oxvartype, " . $this->getDecodeValueQuery() . " as oxvarvalue
  453. from oxconfig
  454. where oxshopid = '$sShopID' and " . $sModuleSql . $sOnlyVarsSql;
  455. $aResult = $oDb->getAll($sSelect);
  456. foreach ($aResult as $aValue) {
  457. $sVarName = $aValue[0];
  458. $sVarType = $aValue[1];
  459. $sVarVal = $aValue[2];
  460. $this->_setConfVarFromDb($sVarName, $sVarType, $sVarVal);
  461. //setting theme options array
  462. if ($sModule) {
  463. $this->_aThemeConfigParams[$sVarName] = $sModule;
  464. }
  465. }
  466. return (bool) count($aResult);
  467. }
  468. /**
  469. * Allow loading from some vars only from baseshop
  470. *
  471. * @param array $aVars
  472. *
  473. * @return string
  474. */
  475. protected function _getConfigParamsSelectSnippet($aVars)
  476. {
  477. $sSelect = '';
  478. if (is_array($aVars) && !empty($aVars)) {
  479. foreach ($aVars as &$sField) {
  480. $sField = '"' . $sField . '"';
  481. }
  482. $sSelect = ' and oxvarname in ( ' . implode(', ', $aVars) . ' ) ';
  483. }
  484. return $sSelect;
  485. }
  486. /**
  487. * Sets config variable to config object, first unserializing it by given type.
  488. * sShopURL and sSSLShopURL are skipped for admin or when URL values are not set
  489. *
  490. * @param string $sVarName variable name
  491. * @param string $sVarType variable type - arr, aarr, bool or str
  492. * @param string $sVarVal serialized by type value
  493. *
  494. * @return null
  495. */
  496. protected function _setConfVarFromDb($sVarName, $sVarType, $sVarVal)
  497. {
  498. if (($sVarName == 'sShopURL' || $sVarName == 'sSSLShopURL') &&
  499. (!$sVarVal || $this->isAdmin() === true)
  500. ) {
  501. return;
  502. }
  503. switch ($sVarType) {
  504. case 'arr':
  505. case 'aarr':
  506. $this->setConfigParam($sVarName, unserialize($sVarVal));
  507. break;
  508. case 'bool':
  509. $this->setConfigParam($sVarName, ($sVarVal == 'true' || $sVarVal == '1'));
  510. break;
  511. default:
  512. $this->setConfigParam($sVarName, $sVarVal);
  513. break;
  514. }
  515. }
  516. /**
  517. * Unsets all session data.
  518. *
  519. * @return null
  520. */
  521. public function pageClose()
  522. {
  523. if ($this->hasActiveViewsChain()) {
  524. // do not commit session until active views chain exists
  525. return;
  526. }
  527. return $this->_oStart->pageClose();
  528. }
  529. /**
  530. * Returns value of parameter stored in POST,GET.
  531. * For security reasons performed oxconfig->checkParamSpecialChars().
  532. * use $blRaw very carefully if you want to get unescaped
  533. * parameter.
  534. *
  535. * @param string $sName Name of parameter
  536. * @param bool $blRaw Get unescaped parameter
  537. *
  538. * @return mixed
  539. */
  540. public function getRequestParameter($sName, $blRaw = false)
  541. {
  542. if (defined('OXID_PHP_UNIT')) {
  543. if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
  544. try {
  545. $sValue = modConfig::getRequestParameter($sName, $blRaw);
  546. // TODO: remove this after special chars concept implementation
  547. $blIsAdmin = modConfig::getInstance()->isAdmin() || modSession::getInstance()->getVariable("blIsAdmin");
  548. if ($sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
  549. $this->checkParamSpecialChars($sValue, $blRaw);
  550. }
  551. return $sValue;
  552. } catch (Exception $e) {
  553. // if exception is thrown, use default
  554. }
  555. }
  556. }
  557. $sValue = null;
  558. if (isset($_POST[$sName])) {
  559. $sValue = $_POST[$sName];
  560. } elseif (isset($_GET[$sName])) {
  561. $sValue = $_GET[$sName];
  562. }
  563. // TODO: remove this after special chars concept implementation
  564. $blIsAdmin = $this->isAdmin() && $this->getSession()->getVariable("blIsAdmin");
  565. if ($sValue !== null && !$blIsAdmin && (!$blRaw || is_array($blRaw))) {
  566. $this->checkParamSpecialChars($sValue, $blRaw);
  567. }
  568. return $sValue;
  569. }
  570. /**
  571. * Returns uploaded file parameter
  572. *
  573. * @param array $sParamName param name
  574. *
  575. * @return null
  576. */
  577. public function getUploadedFile($sParamName)
  578. {
  579. return $_FILES[$sParamName];
  580. }
  581. /**
  582. * Sets global parameter value
  583. *
  584. * @param string $sName name of parameter
  585. * @param mixed $sValue value to store
  586. */
  587. public function setGlobalParameter($sName, $sValue)
  588. {
  589. $this->_aGlobalParams[$sName] = $sValue;
  590. }
  591. /**
  592. * Returns global parameter value
  593. *
  594. * @param string $sName name of cached parameter
  595. *
  596. * @return mixed
  597. */
  598. public function getGlobalParameter($sName)
  599. {
  600. if (isset($this->_aGlobalParams[$sName])) {
  601. return $this->_aGlobalParams[$sName];
  602. } else {
  603. return null;
  604. }
  605. }
  606. /**
  607. * Checks if passed parameter has special chars and replaces them.
  608. * Returns checked value.
  609. *
  610. * @param mixed &$sValue value to process escaping
  611. * @param array $aRaw keys of unescaped values
  612. *
  613. * @return mixed
  614. */
  615. public function checkParamSpecialChars(& $sValue, $aRaw = null)
  616. {
  617. if (is_object($sValue)) {
  618. return $sValue;
  619. }
  620. if (is_array($sValue)) {
  621. $newValue = array();
  622. foreach ($sValue as $sKey => $sVal) {
  623. $sValidKey = $sKey;
  624. if (!$aRaw || !in_array($sKey, $aRaw)) {
  625. $this->checkParamSpecialChars($sValidKey);
  626. $this->checkParamSpecialChars($sVal);
  627. if ($sValidKey != $sKey) {
  628. unset ($sValue[$sKey]);
  629. }
  630. }
  631. $newValue[$sValidKey] = $sVal;
  632. }
  633. $sValue = $newValue;
  634. } elseif (is_string($sValue)) {
  635. $sValue = str_replace(
  636. array('&', '<', '>', '"', "'", chr(0), '\\', "\n", "\r"),
  637. array('&amp;', '&lt;', '&gt;', '&quot;', '&#039;', '', '&#092;', '&#10;', '&#13;'),
  638. $sValue
  639. );
  640. }
  641. return $sValue;
  642. }
  643. /**
  644. * Active Shop id setter
  645. *
  646. * @param string $sShopId shop id
  647. *
  648. * @return null
  649. */
  650. public function setShopId($sShopId)
  651. {
  652. $this->getSession()->setVariable('actshop', $sShopId);
  653. $this->_iShopId = $sShopId;
  654. }
  655. /**
  656. * Returns active shop ID.
  657. *
  658. * @return int
  659. */
  660. public function getShopId()
  661. {
  662. if ($this->_iShopId !== null) {
  663. return $this->_iShopId;
  664. }
  665. $this->setShopId($this->getBaseShopId());
  666. $this->getSession()->setVariable('actshop', $this->_iShopId);
  667. return $this->_iShopId;
  668. }
  669. /**
  670. * Set is shop url
  671. *
  672. * @param bool $blIsSsl - state bool value
  673. */
  674. public function setIsSsl($blIsSsl = false)
  675. {
  676. $this->_blIsSsl = $blIsSsl;
  677. }
  678. /**
  679. * Checks if WEB session is SSL.
  680. */
  681. protected function _checkSsl()
  682. {
  683. $myUtilsServer = oxRegistry::get("oxUtilsServer");
  684. $aServerVars = $myUtilsServer->getServerVar();
  685. $aHttpsServerVar = $myUtilsServer->getServerVar('HTTPS');
  686. $this->setIsSsl();
  687. if (isset($aHttpsServerVar) && ($aHttpsServerVar === 'on' || $aHttpsServerVar === 'ON' || $aHttpsServerVar == '1')) {
  688. // "1&1" hoster provides "1"
  689. $this->setIsSsl($this->getConfigParam('sSSLShopURL') || $this->getConfigParam('sMallSSLShopURL'));
  690. if ($this->isAdmin() && !$this->_blIsSsl) {
  691. //#4026
  692. $this->setIsSsl(!is_null($this->getConfigParam('sAdminSSLURL')));
  693. }
  694. }
  695. //additional special handling for profihost customers
  696. if (isset($aServerVars['HTTP_X_FORWARDED_SERVER']) &&
  697. (strpos($aServerVars['HTTP_X_FORWARDED_SERVER'], 'ssl') !== false ||
  698. strpos($aServerVars['HTTP_X_FORWARDED_SERVER'], 'secure-online-shopping.de') !== false)
  699. ) {
  700. $this->setIsSsl(true);
  701. }
  702. }
  703. /**
  704. * Checks if WEB session is SSL. Returns true if yes.
  705. *
  706. * @return bool
  707. */
  708. public function isSsl()
  709. {
  710. if (is_null($this->_blIsSsl)) {
  711. $this->_checkSsl();
  712. }
  713. return $this->_blIsSsl;
  714. }
  715. /**
  716. * Compares current URL to supplied string
  717. *
  718. * @param string $sURL URL
  719. *
  720. * @return bool true if $sURL is equal to current page URL
  721. */
  722. public function isCurrentUrl($sURL)
  723. {
  724. // Missing protocol, cannot proceed, assuming true.
  725. if (!$sURL || (strpos($sURL, "http") !== 0)) {
  726. return true;
  727. }
  728. return oxRegistry::get("oxUtilsServer")->isCurrentUrl($sURL);
  729. }
  730. /**
  731. * Compares current protocol to supplied url string
  732. *
  733. * @param string $sURL URL
  734. *
  735. * @return bool true if $sURL is equal to current page URL
  736. */
  737. public function isCurrentProtocol($sURL)
  738. {
  739. // Missing protocol, cannot proceed, assuming true.
  740. if (!$sURL || (strpos($sURL, "http") !== 0)) {
  741. return true;
  742. }
  743. return (strpos($sURL, "https:") === 0) == $this->isSsl();
  744. }
  745. /**
  746. * Returns config sShopURL or sMallShopURL if secondary shop
  747. *
  748. * @param int $iLang language
  749. * @param bool $blAdmin if set true, function returns shop url without checking language/subshops for different url.
  750. *
  751. * @return string
  752. */
  753. public function getShopUrl($iLang = null, $blAdmin = null)
  754. {
  755. $sUrl = null;
  756. $blAdmin = isset($blAdmin) ? $blAdmin : $this->isAdmin();
  757. if (!$blAdmin) {
  758. $sUrl = $this->getShopUrlByLanguage($iLang);
  759. if (!$sUrl) {
  760. $sUrl = $this->getMallShopUrl();
  761. }
  762. }
  763. if (!$sUrl) {
  764. $sUrl = $this->getConfigParam('sShopURL');
  765. }
  766. return $sUrl;
  767. }
  768. /**
  769. * Returns config sSSLShopURL or sMallSSLShopURL if secondary shop
  770. *
  771. * @param int $iLang language (default is null)
  772. *
  773. * @return string
  774. */
  775. public function getSslShopUrl($iLang = null)
  776. {
  777. $sUrl = null;
  778. if (!$sUrl) {
  779. $sUrl = $this->getShopUrlByLanguage($iLang, true);
  780. }
  781. if (!$sUrl) {
  782. $sUrl = $this->getMallShopUrl(true);
  783. }
  784. if (!$sUrl) {
  785. $sUrl = $this->getMallShopUrl();
  786. }
  787. //normal section
  788. if (!$sUrl) {
  789. $sUrl = $this->getConfigParam('sSSLShopURL');
  790. }
  791. if (!$sUrl) {
  792. $sUrl = $this->getShopUrl($iLang);
  793. }
  794. return $sUrl;
  795. }
  796. /**
  797. * Returns utils dir URL
  798. *
  799. * @return string
  800. */
  801. public function getCoreUtilsUrl()
  802. {
  803. return $this->getCurrentShopUrl() . 'core/utils/';
  804. }
  805. /**
  806. * Returns SSL or non SSL shop URL without index.php depending on Mall
  807. * affecting environment is admin mode and current ssl usage status
  808. *
  809. * @param bool $blAdmin if admin
  810. *
  811. * @return string
  812. */
  813. public function getCurrentShopUrl($blAdmin = null)
  814. {
  815. if ($blAdmin === null) {
  816. $blAdmin = $this->isAdmin();
  817. }
  818. if ($blAdmin) {
  819. if ($this->isSsl()) {
  820. $sUrl = $this->getConfigParam('sAdminSSLURL');
  821. if (!$sUrl) {
  822. return $this->getSslShopUrl() . $this->getConfigParam('sAdminDir') . '/';
  823. }
  824. return $sUrl;
  825. } else {
  826. return $this->getShopUrl() . $this->getConfigParam('sAdminDir') . '/';
  827. }
  828. } else {
  829. return $this->isSsl() ? $this->getSslShopUrl() : $this->getShopUrl();
  830. }
  831. }
  832. /**
  833. * Returns SSL or not SSL shop URL with index.php and sid
  834. *
  835. * @param int $iLang language (optional)
  836. *
  837. * @return string
  838. */
  839. public function getShopCurrentUrl($iLang = null)
  840. {
  841. if ($this->isSsl()) {
  842. $sURL = $this->getSSLShopURL($iLang);
  843. } else {
  844. $sURL = $this->getShopURL($iLang);
  845. }
  846. return oxRegistry::get("oxUtilsUrl")->processUrl($sURL . 'index.php', false);
  847. }
  848. /**
  849. * Returns shop non SSL URL including index.php and sid.
  850. *
  851. * @param int $iLang language
  852. * @param bool $blAdmin if admin
  853. *
  854. * @return string
  855. */
  856. public function getShopHomeUrl($iLang = null, $blAdmin = null)
  857. {
  858. return oxRegistry::get("oxUtilsUrl")->processUrl($this->getShopUrl($iLang, $blAdmin) . 'index.php', false);
  859. }
  860. /**
  861. * Returns widget start non SSL URL including widget.php and sid.
  862. *
  863. * @param int $iLang language
  864. * @param bool $blAdmin if admin
  865. *
  866. * @return string
  867. */
  868. public function getWidgetUrl($iLang = null, $blAdmin = null)
  869. {
  870. $sUrl = $this->isSsl() ? $this->getSslShopUrl($iLang) : $this->getShopUrl($iLang, $blAdmin);
  871. return oxRegistry::get('oxUtilsUrl')->processUrl($sUrl . 'widget.php', false);
  872. }
  873. /**
  874. * Returns shop SSL URL with index.php and sid.
  875. *
  876. * @return string
  877. */
  878. public function getShopSecureHomeUrl()
  879. {
  880. return oxRegistry::get("oxUtilsUrl")->processUrl($this->getSslShopUrl() . 'index.php', false);
  881. }
  882. /**
  883. * Returns active shop currency.
  884. *
  885. * @return string
  886. */
  887. public function getShopCurrency()
  888. {
  889. $iCurr = null;
  890. if ((null === ($iCurr = $this->getRequestParameter('cur')))) {
  891. if (null === ($iCurr = $this->getRequestParameter('currency'))) {
  892. $iCurr = $this->getSession()->getVariable('currency');
  893. }
  894. }
  895. return (int) $iCurr;
  896. }
  897. /**
  898. * Returns active shop currency object.
  899. *
  900. * @return object
  901. */
  902. public function getActShopCurrencyObject()
  903. {
  904. //caching currency as it does not change through the script
  905. //but not for unit tests as ther it changes always
  906. if (!defined('OXID_PHP_UNIT')) {
  907. if (!is_null($this->_oActCurrencyObject)) {
  908. return $this->_oActCurrencyObject;
  909. }
  910. }
  911. $iCur = $this->getShopCurrency();
  912. $aCurrencies = $this->getCurrencyArray();
  913. if (!isset($aCurrencies[$iCur])) {
  914. return $this->_oActCurrencyObject = reset($aCurrencies); // reset() returns the first element
  915. }
  916. return $this->_oActCurrencyObject = $aCurrencies[$iCur];
  917. }
  918. /**
  919. * Sets the actual currency
  920. *
  921. * @param int $iCur 0 = EUR, 1 = GBP, 2 = CHF
  922. */
  923. public function setActShopCurrency($iCur)
  924. {
  925. $aCurrencies = $this->getCurrencyArray();
  926. if (isset($aCurrencies[$iCur])) {
  927. $this->getSession()->setVariable('currency', $iCur);
  928. $this->_oActCurrencyObject = null;
  929. }
  930. }
  931. /**
  932. * Returns path to out dir
  933. *
  934. * @param bool $blAbsolute mode - absolute/relative path
  935. *
  936. * @return string
  937. */
  938. public function getOutDir($blAbsolute = true)
  939. {
  940. if ($blAbsolute) {
  941. return $this->getConfigParam('sShopDir') . $this->_sOutDir . '/';
  942. } else {
  943. return $this->_sOutDir . '/';
  944. }
  945. }
  946. /**
  947. * Returns path to out dir
  948. *
  949. * @param bool $blAbsolute mode - absolute/relative path
  950. *
  951. * @return string
  952. */
  953. public function getViewsDir($blAbsolute = true)
  954. {
  955. if ($blAbsolute) {
  956. return $this->getConfigParam('sShopDir') . 'application/views/';
  957. } else {
  958. return 'application/views/';
  959. }
  960. }
  961. /**
  962. * Returns path to translations dir
  963. *
  964. * @param string $sFile File name
  965. * @param string $sDir Directory name
  966. * @param bool $blAbsolute mode - absolute/relative path
  967. *
  968. * @return string
  969. */
  970. public function getTranslationsDir($sFile, $sDir, $blAbsolute = true)
  971. {
  972. $sPath = $blAbsolute ? $this->getConfigParam('sShopDir') : '';
  973. $sPath .= 'application/translations/';
  974. if (is_readable($sPath . $sDir . '/' . $sFile)) {
  975. return $sPath . $sDir . '/' . $sFile;
  976. }
  977. return false;
  978. }
  979. /**
  980. * Returns path to out dir
  981. *
  982. * @param bool $blAbsolute mode - absolute/relative path
  983. *
  984. * @return string
  985. */
  986. public function getAppDir($blAbsolute = true)
  987. {
  988. if ($blAbsolute) {
  989. return $this->getConfigParam('sShopDir') . 'application/';
  990. } else {
  991. return 'application/';
  992. }
  993. }
  994. /**
  995. * Returns url to out dir
  996. *
  997. * @param bool $blSSL Whether to force ssl
  998. * @param bool $blAdmin Whether to force admin
  999. * @param bool $blNativeImg Whether to force native image dirs
  1000. *
  1001. * @return string
  1002. */
  1003. public function getOutUrl($blSSL = null, $blAdmin = null, $blNativeImg = false)
  1004. {
  1005. $blSSL = is_null($blSSL) ? $this->isSsl() : $blSSL;
  1006. $blAdmin = is_null($blAdmin) ? $this->isAdmin() : $blAdmin;
  1007. if ($blSSL) {
  1008. if ($blNativeImg && !$blAdmin) {
  1009. $sUrl = $this->getSslShopUrl();
  1010. } else {
  1011. $sUrl = $this->getConfigParam('sSSLShopURL');
  1012. if (!$sUrl && $blAdmin) {
  1013. $sUrl = $this->getConfigParam('sAdminSSLURL') . '../';
  1014. }
  1015. }
  1016. } else {
  1017. $sUrl = ($blNativeImg && !$blAdmin) ? $this->getShopUrl() : $this->getConfigParam('sShopURL');
  1018. }
  1019. return $sUrl . $this->_sOutDir . '/';
  1020. }
  1021. /**
  1022. * Finds and returns files or folders path in out dir
  1023. *
  1024. * @param string $sFile File name
  1025. * @param string $sDir Directory name
  1026. * @param bool $blAdmin Whether to force admin
  1027. * @param int $iLang Language id
  1028. * @param int $iShop Shop id
  1029. * @param string $sTheme Theme name
  1030. * @param bool $blAbsolute mode - absolute/relative path
  1031. * @param bool $blIgnoreCust Ignore custom theme
  1032. *
  1033. * @return string
  1034. */
  1035. public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true, $blIgnoreCust = false)
  1036. {
  1037. if (is_null($sTheme)) {
  1038. $sTheme = $this->getConfigParam('sTheme');
  1039. }
  1040. if ($blAdmin) {
  1041. $sTheme = 'admin';
  1042. }
  1043. if ($sDir != $this->_sTemplateDir) {
  1044. $sBase = $this->getOutDir($blAbsolute);
  1045. $sAbsBase = $this->getOutDir();
  1046. } else {
  1047. $sBase = $this->getViewsDir($blAbsolute);
  1048. $sAbsBase = $this->getViewsDir();
  1049. }
  1050. $sLang = '-';
  1051. // FALSE means skip language folder check
  1052. if ($iLang !== false) {
  1053. $oLang = oxRegistry::getLang();
  1054. if (is_null($iLang)) {
  1055. $iLang = $oLang->getEditLanguage();
  1056. }
  1057. $sLang = $oLang->getLanguageAbbr($iLang);
  1058. }
  1059. if (is_null($iShop)) {
  1060. $iShop = $this->getShopId();
  1061. }
  1062. //Load from
  1063. $sPath = "{$sTheme}/{$iShop}/{$sLang}/{$sDir}/{$sFile}";
  1064. $sCacheKey = $sPath . "_{$blIgnoreCust}{$blAbsolute}";
  1065. if (($sReturn = oxRegistry::getUtils()->fromStaticCache($sCacheKey)) !== null) {
  1066. return $sReturn;
  1067. }
  1068. $sReturn = false;
  1069. // Check for custom template
  1070. $sCustomTheme = $this->getConfigParam('sCustomTheme');
  1071. if (!$blAdmin && !$blIgnoreCust && $sCustomTheme && $sCustomTheme != $sTheme) {
  1072. $sReturn = $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShop, $sCustomTheme, $blAbsolute);
  1073. }
  1074. //test lang level ..
  1075. if (!$sReturn && !$blAdmin && is_readable($sAbsBase . $sPath)) {
  1076. $sReturn = $sBase . $sPath;
  1077. }
  1078. //test shop level ..
  1079. $sPath = "$sTheme/$iShop/$sDir/$sFile";
  1080. if (!$sReturn && !$blAdmin && is_readable($sAbsBase . $sPath)) {
  1081. $sReturn = $sBase . $sPath;
  1082. }
  1083. //test theme language level ..
  1084. $sPath = "$sTheme/$sLang/$sDir/$sFile";
  1085. if (!$sReturn && $iLang !== false && is_readable($sAbsBase . $sPath)) {
  1086. $sReturn = $sBase . $sPath;
  1087. }
  1088. //test theme level ..
  1089. $sPath = "$sTheme/$sDir/$sFile";
  1090. if (!$sReturn && is_readable($sAbsBase . $sPath)) {
  1091. $sReturn = $sBase . $sPath;
  1092. }
  1093. //test out language level ..
  1094. $sPath = "$sLang/$sDir/$sFile";
  1095. if (!$sReturn && $iLang !== false && is_readable($sAbsBase . $sPath)) {
  1096. $sReturn = $sBase . $sPath;
  1097. }
  1098. //test out level ..
  1099. $sPath = "$sDir/$sFile";
  1100. if (!$sReturn && is_readable($sAbsBase . $sPath)) {
  1101. $sReturn = $sBase . $sPath;
  1102. }
  1103. if (!$sReturn) {
  1104. // TODO: implement logic to log missing paths
  1105. }
  1106. // to cache
  1107. oxRegistry::getUtils()->toStaticCache($sCacheKey, $sReturn);
  1108. return $sReturn;
  1109. }
  1110. /**
  1111. * Finds and returns file or folder url in out dir
  1112. *
  1113. * @param string $sFile File name
  1114. * @param string $sDir Directory name
  1115. * @param bool $blAdmin Whether to force admin
  1116. * @param bool $blSSL Whether to force ssl
  1117. * @param bool $blNativeImg Whether to force native image dirs
  1118. * @param int $iLang Language id
  1119. * @param int $iShop Shop id
  1120. * @param string $sTheme Theme name
  1121. *
  1122. * @return string
  1123. */
  1124. public function getUrl($sFile, $sDir, $blAdmin = null, $blSSL = null, $blNativeImg = false, $iLang = null, $iShop = null, $sTheme = null)
  1125. {
  1126. $sUrl = str_replace(
  1127. $this->getOutDir(),
  1128. $this->getOutUrl($blSSL, $blAdmin, $blNativeImg),
  1129. $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShop, $sTheme)
  1130. );
  1131. return $sUrl;
  1132. }
  1133. /**
  1134. * Finds and returns image files or folders path
  1135. *
  1136. * @param string $sFile File name
  1137. * @param bool $blAdmin Whether to force admin
  1138. *
  1139. * @return string
  1140. */
  1141. public function getImagePath($sFile, $blAdmin = false)
  1142. {
  1143. return $this->getDir($sFile, $this->_sImageDir, $blAdmin);
  1144. }
  1145. /**
  1146. * Finds and returns image folder url
  1147. *
  1148. * @param bool $blAdmin Whether to force admin
  1149. * @param bool $blSSL Whether to force ssl
  1150. * @param bool $blNativeImg Whether to force native image dirs
  1151. * @param string $sFile Image file name
  1152. *
  1153. * @return string
  1154. */
  1155. public function getImageUrl($blAdmin = false, $blSSL = null, $blNativeImg = null, $sFile = null)
  1156. {
  1157. $blNativeImg = is_null($blNativeImg) ? $this->getConfigParam('blNativeImages') : $blNativeImg;
  1158. return $this->getUrl($sFile, $this->_sImageDir, $blAdmin, $blSSL, $blNativeImg);
  1159. }
  1160. /**
  1161. * Finds and returns image folders path
  1162. *
  1163. * @param bool $blAdmin Whether to force admin
  1164. *
  1165. * @return string
  1166. */
  1167. public function getImageDir($blAdmin = false)
  1168. {
  1169. return $this->getDir(null, $this->_sImageDir, $blAdmin);
  1170. }
  1171. /**
  1172. * Finds and returns product pictures files or folders path
  1173. *
  1174. * @param string $sFile File name
  1175. * @param bool $blAdmin Whether to force admin
  1176. * @param int $iLang Language
  1177. * @param int $iShop Shop id
  1178. * @param string $sTheme theme name
  1179. *
  1180. * @return string
  1181. */
  1182. public function getPicturePath($sFile, $blAdmin = false, $iLang = null, $iShop = null, $sTheme = null)
  1183. {
  1184. return $this->getDir($sFile, $this->_sPictureDir, $blAdmin, $iLang, $iShop, $sTheme);
  1185. }
  1186. /**
  1187. * Finds and returns master pictures folder path
  1188. *
  1189. * @param bool $blAdmin Whether to force admin
  1190. *
  1191. * @return string
  1192. */
  1193. public function getMasterPictureDir($blAdmin = false)
  1194. {
  1195. return $this->getDir(null, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin);
  1196. }
  1197. /**
  1198. * Finds and returns master picture path
  1199. *
  1200. * @param string $sFile File name
  1201. * @param bool $blAdmin Whether to force admin
  1202. *
  1203. * @return string
  1204. */
  1205. public function getMasterPicturePath($sFile, $blAdmin = false)
  1206. {
  1207. return $this->getDir($sFile, $this->_sPictureDir . "/" . $this->_sMasterPictureDir, $blAdmin);
  1208. }
  1209. /**
  1210. * Finds and returns product picture file or folder url
  1211. *
  1212. * @param string $sFile File name
  1213. * @param bool $blAdmin Whether to force admin
  1214. * @param bool $blSSL Whether to force ssl
  1215. * @param int $iLang Language
  1216. * @param int $iShopId Shop id
  1217. * @param string $sDefPic Default (nopic) image path ["0/nopic.jpg"]
  1218. *
  1219. * @return string
  1220. */
  1221. public function getPictureUrl($sFile, $blAdmin = false, $blSSL = null, $iLang = null, $iShopId = null, $sDefPic = "master/nopic.jpg")
  1222. {
  1223. if ($sAltUrl = oxRegistry::get("oxPictureHandler")->getAltImageUrl('/', $sFile, $blSSL)) {
  1224. return $sAltUrl;
  1225. }
  1226. $blNativeImg = $this->getConfigParam('blNativeImages');
  1227. $sUrl = $this->getUrl($sFile, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId);
  1228. //anything is better than empty name, because <img src=""> calls shop once more = x2 SLOW.
  1229. if (!$sUrl && $sDefPic) {
  1230. $sUrl = $this->getUrl($sDefPic, $this->_sPictureDir, $blAdmin, $blSSL, $blNativeImg, $iLang, $iShopId);
  1231. }
  1232. return $sUrl;
  1233. }
  1234. /**
  1235. * Finds and returns product pictures folders path
  1236. *
  1237. * @param bool $blAdmin Whether to force admin
  1238. *
  1239. * @return string
  1240. */
  1241. public function getPictureDir($blAdmin)
  1242. {
  1243. return $this->getDir(null, $this->_sPictureDir, $blAdmin);
  1244. }
  1245. /**
  1246. * Finds and returns templates files or folders path
  1247. *
  1248. * @param string $sFile File name
  1249. * @param bool $blAdmin Whether to force admin
  1250. *
  1251. * @return string
  1252. */
  1253. public function getTemplatePath($sFile, $blAdmin)
  1254. {
  1255. $sTemplatePath = $this->getDir($sFile, $this->_sTemplateDir, $blAdmin);
  1256. if (!$sTemplatePath) {
  1257. $sBasePath = getShopBasePath();
  1258. $aModuleTemplates = $this->getConfigParam('aModuleTemplates');
  1259. $oModulelist = oxNew('oxmodulelist');
  1260. $aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
  1261. if (is_array($aModuleTemplates) && is_array($aActiveModuleInfo)) {
  1262. foreach ($aModuleTemplates as $sModuleId => $aTemplates) {
  1263. if (isset($aTemplates[$sFile]) && isset($aActiveModuleInfo[$sModuleId])) {
  1264. $sPath = $aTemplates[$sFile];
  1265. $sPath = $sBasePath . 'modules/' . $sPath;
  1266. if (is_file($sPath) && is_readable($sPath)) {
  1267. $sTemplatePath = $sPath;
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. return $sTemplatePath;
  1274. }
  1275. /**
  1276. * Finds and returns templates folders path
  1277. *
  1278. * @param bool $blAdmin Whether to force admin
  1279. *
  1280. * @return string
  1281. */
  1282. public function getTemplateDir($blAdmin = false)
  1283. {
  1284. return $this->getDir(null, $this->_sTemplateDir, $blAdmin);
  1285. }
  1286. /**
  1287. * Finds and returns template file or folder url
  1288. *
  1289. * @param string $sFile File name
  1290. * @param bool $blAdmin Whether to force admin
  1291. * @param bool $blSSL Whether to force ssl
  1292. * @param int $iLang Language id
  1293. *
  1294. * @return string
  1295. */
  1296. public function getTemplateUrl($sFile = null, $blAdmin = false, $blSSL = null, $iLang = null)
  1297. {
  1298. return $this->getShopMainUrl() . $this->getDir($sFile, $this->_sTemplateDir, $blAdmin, $iLang, null, null, false);
  1299. }
  1300. /**
  1301. * Finds and returns base template folder url
  1302. *
  1303. * @param bool $blAdmin Whether to force admin
  1304. *
  1305. * @return string
  1306. */
  1307. public function getTemplateBase($blAdmin = false)
  1308. {
  1309. // Base template dir is the parent dir of template dir
  1310. return str_replace($this->_sTemplateDir . '/', '', $this->getDir(null, $this->_sTemplateDir, $blAdmin, null, null, null, false));
  1311. }
  1312. /**
  1313. * Finds and returns resource (css, js, etc..) files or folders path
  1314. *
  1315. * @param string $sFile File name
  1316. * @param bool $blAdmin Whether to force admin
  1317. *
  1318. * @return string
  1319. */
  1320. public function getResourcePath($sFile = '', $blAdmin = false)
  1321. {
  1322. return $this->getDir($sFile, $this->_sResourceDir, $blAdmin);
  1323. }
  1324. /**
  1325. * Returns path to modules dir
  1326. *
  1327. * @param bool $blAbsolute mode - absolute/relative path
  1328. *
  1329. * @return string
  1330. */
  1331. public function getModulesDir($blAbsolute = true)
  1332. {
  1333. if ($blAbsolute) {
  1334. return $this->getConfigParam('sShopDir') . $this->_sModulesDir . '/';
  1335. } else {
  1336. return $this->_sModulesDir . '/';
  1337. }
  1338. }
  1339. /**
  1340. * Finds and returns resource (css, js, etc..) file or folder url
  1341. *
  1342. * @param string $sFile File name
  1343. * @param bool $blAdmin Whether to force admin
  1344. * @param bool $blSSL Whether to force ssl
  1345. * @param int $iLang Language id
  1346. *
  1347. * @return string
  1348. */
  1349. public function getResourceUrl($sFile = '', $blAdmin = false, $blSSL = null, $iLang = null)
  1350. {
  1351. $blNativeImg = $this->getConfigParam('blNativeImages');
  1352. return $this->getUrl($sFile, $this->_sResourceDir, $blAdmin, $blSSL, $blNativeImg, $iLang);
  1353. }
  1354. /**
  1355. * Finds and returns resource (css, js, etc..) folders path
  1356. *
  1357. * @param bool $blAdmin Whether to force admin
  1358. *
  1359. * @return string
  1360. */
  1361. public function getResourceDir($blAdmin)
  1362. {
  1363. return $this->getDir(null, $this->_sResourceDir, $blAdmin);
  1364. }
  1365. /**
  1366. * Returns array of available currencies
  1367. *
  1368. * @param integer $iCurrency Active currency number (default null)
  1369. *
  1370. * @return array
  1371. */
  1372. public function getCurrencyArray($iCurrency = null)
  1373. {
  1374. $aConfCurrencies = $this->getConfigParam('aCurrencies');
  1375. if (!is_array($aConfCurrencies)) {
  1376. return array();
  1377. }
  1378. if (defined('OXID_PHP_UNIT')) {
  1379. if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) {
  1380. try {
  1381. $aAltCurrencies = modConfig::getInstance()->getConfigParam('modaCurrencies');
  1382. if (isset($aAltCurrencies)) {
  1383. $aConfCurrencies = $aAltCurrencies;
  1384. }
  1385. } catch (Exception $e) {
  1386. // if exception is thrown, use default
  1387. }
  1388. }
  1389. }
  1390. // processing currency configuration data
  1391. $aCurrencies = array();
  1392. reset($aConfCurrencies);
  1393. while (list($key, $val) = each($aConfCurrencies)) {
  1394. if ($val) {
  1395. $oCur = new stdClass();
  1396. $oCur->id = $key;
  1397. $sCur = explode('@', $val);
  1398. $oCur->name = trim($sCur[0]);
  1399. $oCur->rate = trim($sCur[1]);
  1400. $oCur->dec = trim($sCur[2]);
  1401. $oCur->thousand = trim($sCur[3]);
  1402. $oCur->sign = trim($sCur[4]);
  1403. $oCur->decimal = trim($sCur[5]);
  1404. // change for US version
  1405. if (isset($sCur[6])) {
  1406. $oCur->side = trim($sCur[6]);
  1407. }
  1408. if (isset($iCurrency) && $key == $iCurrency) {
  1409. $oCur->selected = 1;
  1410. } else {
  1411. $oCur->selected = 0;
  1412. }
  1413. $aCurrencies[$key] = $oCur;
  1414. }
  1415. // #861C - performance, do not load other currencies
  1416. if (!$this->getConfigParam('bl_perfLoadCurrency')) {
  1417. break;
  1418. }
  1419. }
  1420. return $aCurrencies;
  1421. }
  1422. /**
  1423. * Returns currency object.
  1424. *
  1425. * @param string $sName Name of active currency
  1426. *
  1427. * @return object
  1428. */
  1429. public function getCurrencyObject($sName)
  1430. {
  1431. $aSearch = $this->getCurrencyArray();
  1432. foreach ($aSearch as $oCur) {
  1433. if ($oCur->name == $sName) {
  1434. return $oCur;
  1435. }
  1436. }
  1437. }
  1438. /**
  1439. * Checks if the shop is in demo mode.
  1440. *
  1441. * @return bool
  1442. */
  1443. public function isDemoShop()
  1444. {
  1445. return $this->getConfigParam('blDemoShop');
  1446. }
  1447. /**
  1448. * Returns OXID eShop edition
  1449. *
  1450. * @return string
  1451. */
  1452. public function getEdition()
  1453. {
  1454. return "CE";
  1455. }
  1456. /**
  1457. * Returns full eShop edition name
  1458. *
  1459. * @return string
  1460. */
  1461. public function getFullEdition()
  1462. {
  1463. $sEdition = $this->getEdition();
  1464. if ($sEdition == "CE") {
  1465. return "Community Edition";
  1466. }
  1467. return $sEdition;
  1468. }
  1469. /**
  1470. * Returns shops version number (eg. '4.4.2')
  1471. *
  1472. * @return string
  1473. */
  1474. public function getVersion()
  1475. {
  1476. $sVersion = $this->getActiveShop()->oxshops__oxversion->value;
  1477. return $sVersion;
  1478. }
  1479. /**
  1480. * Returns build revision number or false on read error.
  1481. *
  1482. * @return int
  1483. */
  1484. public function getRevision()
  1485. {
  1486. $sFileName = $this->getConfigParam('sShopDir') . "/pkg.rev";
  1487. $sRev = trim(@file_get_contents($sFileName));
  1488. if (!$sRev) {
  1489. return false;
  1490. }
  1491. return $sRev;
  1492. }
  1493. /**
  1494. * Returns build package info file content.
  1495. *
  1496. * @return bool|string
  1497. */
  1498. public function getPackageInfo()
  1499. {
  1500. $sFileName = $this->getConfigParam('sShopDir') . "/pkg.info";
  1501. $sRev = @file_get_contents($sFileName);
  1502. $sRev = str_replace("\n", "<br>", $sRev);
  1503. if (!$sRev) {
  1504. return false;
  1505. }
  1506. return $sRev;
  1507. }
  1508. /**
  1509. * Counts OXID mandates
  1510. *
  1511. * @return int
  1512. */
  1513. public function getMandateCount()
  1514. {
  1515. $iShopCount = 1;
  1516. return $iShopCount;
  1517. }
  1518. /**
  1519. * Checks if shop is MALL. Returns true on success.
  1520. *
  1521. * @return bool
  1522. */
  1523. public function isMall()
  1524. {
  1525. return false;
  1526. }
  1527. /**
  1528. * Checks version of shop, returns:
  1529. * 0 - version is bellow 2.2
  1530. * 1 - Demo or unlicensed
  1531. * 2 - Pro
  1532. * 3 - Enterprise
  1533. *
  1534. * @return int
  1535. */
  1536. public function detectVersion()
  1537. {
  1538. }
  1539. /**
  1540. * Updates or adds new shop configuration parameters to DB.
  1541. * Arrays must be passed not serialized, serialized values are supported just for backward compatibility.
  1542. *
  1543. * @param string $sVarType Variable Type
  1544. * @param string $sVarName Variable name
  1545. * @param mixed $sVarVal Variable value (can be string, integer or array)
  1546. * @param string $sShopId Shop ID, default is current shop
  1547. * @param string $sModule Module name (empty for base options)
  1548. */
  1549. public function saveShopConfVar($sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '')
  1550. {
  1551. switch ($sVarType) {
  1552. case 'arr':
  1553. case 'aarr':
  1554. $sValue = serialize($sVarVal);
  1555. break;
  1556. case 'bool':
  1557. //config param
  1558. $sVarVal = (($sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
  1559. //db value
  1560. $sValue = $sVarVal ? "1" : "";
  1561. break;
  1562. case 'num':
  1563. //config param
  1564. $sVarVal = $sVarVal != '' ? oxRegistry::getUtils()->string2Float($sVarVal) : '';
  1565. $sValue = $sVarVal;
  1566. break;
  1567. default:
  1568. $sValue = $sVarVal;
  1569. break;
  1570. }
  1571. if (!$sShopId) {
  1572. $sShopId = $this->getShopId();
  1573. }
  1574. // Update value only for current shop
  1575. if ($sShopId

Large files files are truncated, but you can click here to view the full file