PageRenderTime 88ms CodeModel.GetById 44ms app.highlight 34ms RepoModel.GetById 1ms app.codeStats 1ms

/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

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

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