Index: branches/5.1.x/core/kernel/application.php =================================================================== diff -u -N -r13545 -r13559 --- branches/5.1.x/core/kernel/application.php (.../application.php) (revision 13545) +++ branches/5.1.x/core/kernel/application.php (.../application.php) (revision 13559) @@ -1,6 +1,6 @@ getCache($cache_key); + $cache_key = 'primary_currency[%CurrSerial%][%SiteDomainSerial%]:' . $this->siteDomainField('DomainId'); + $currency_iso = $this->getCache($cache_key); - if ($primary_currency === false) { + if ($currency_iso === false) { if ($this->isModuleEnabled('In-Commerce')) { $this->Conn->nextQueryCachable = true; + $currency_id = $this->siteDomainField('PrimaryCurrencyId'); + $sql = 'SELECT ISO FROM ' . $this->getUnitOption('curr', 'TableName') . ' - WHERE IsPrimary = 1'; - $primary_currency = $this->Conn->GetOne($sql); + WHERE ' . ($currency_id > 0 ? 'CurrencyId = ' . $currency_id : 'IsPrimary = 1'); + $currency_iso = $this->Conn->GetOne($sql); } else { - $primary_currency = 'USD'; + $currency_iso = 'USD'; } - $this->setCache($cache_key, $primary_currency); + $this->setCache($cache_key, $currency_iso); } - return $primary_currency; + return $currency_iso; } /** + * Returns site domain field. When none of site domains are found false is returned. + * + * @param string $field + * @param bool $formatted + * @param string $format + */ + function siteDomainField($field, $formatted = false, $format = null) + { + if ($this->isAdmin) { + // don't apply any filtering in administrative console + return false; + } + + if (!$this->siteDomain) { + $this->siteDomain =& $this->recallObject('site-domain.current'); + /* @var $site_domain kDBItem */ + } + + if ($this->siteDomain->isLoaded()) { + return $formatted ? $this->siteDomain->GetField($field, $format) : $this->siteDomain->GetDBField($field); + } + + return false; + } + + /** * Registers default classes such as ItemController, GridController and LoginController * * Called automatically while initializing Application @@ -1533,21 +1573,16 @@ $ssl = isset($params['__SSL__']) ? $params['__SSL__'] : null; if ($ssl !== null) { $session =& $this->recallObject('Session'); - $cookie_url = trim($session->CookieDomain.$session->CookiePath, '/.'); - if ($ssl) { - $target_url = defined('ADMIN') && ADMIN ? $this->ConfigValue('AdminSSL_URL') : false; - if (!$target_url) { - $target_url = $this->ConfigValue('SSL_URL'); - } - } - else { - $target_url = 'http://'.DOMAIN.$this->ConfigValue('Site_Path'); - } + /* @var $session Session */ + $target_url = rtrim($this->BaseURL('', $ssl, false), '/'); + $cookie_url = trim($session->CookieDomain . $session->CookiePath, '/.'); + // set session to GET_ONLY, to pass sid only if sid is REAL AND session is set - if (!preg_match('#'.preg_quote($cookie_url).'#', $target_url) && $session->SessionSet) { - $session->SetMode(smGET_ONLY); - } + if (!preg_match('#' . preg_quote($cookie_url) . '#', $target_url) && $session->SessionSet) { + // when SSL<->NON-SSL redirect to different domain pass SID in url + $session->SetMode(smGET_ONLY); + } } if (isset($params['opener']) && $params['opener'] == 'u') { @@ -2033,27 +2068,36 @@ return $ret; } - function BaseURL($prefix='', $ssl=null) + function BaseURL($prefix = '', $ssl = null, $add_port = true) { if ($ssl === null) { - return PROTOCOL.SERVER_NAME.(defined('PORT')?':'.PORT : '').rtrim(BASE_PATH, '/').$prefix.'/'; + // stay on same encryption level + return PROTOCOL . SERVER_NAME . ($add_port && defined('PORT') ? ':' . PORT : '') . rtrim(BASE_PATH, '/') . $prefix . '/'; } - else { - if ($ssl) { - $base_url = defined('ADMIN') && ADMIN ? $this->ConfigValue('AdminSSL_URL') : false; - if (!$base_url) { - $base_url = $this->ConfigValue('SSL_URL'); - } - return rtrim($base_url, '/').$prefix.'/'; + if ($ssl) { + // going from http:// to https:// + $base_url = $this->isAdmin ? $this->ConfigValue('AdminSSL_URL') : false; + + if (!$base_url) { + $ssl_url = $this->siteDomainField('SSLUrl'); + $base_url = $ssl_url !== false ? $ssl_url : $this->ConfigValue('SSL_URL'); } - else { - return 'http://'.DOMAIN.(defined('PORT')?':'.PORT : '').rtrim( $this->ConfigValue('Site_Path'), '/').$prefix.'/'; - } + + return rtrim($base_url, '/') . $prefix . '/'; } + + // going from https:// to http:// + $domain = $this->siteDomainField('DomainName'); + + if ($domain === false) { + $domain = DOMAIN; + } + + return 'http://' . $domain . ($add_port && defined('PORT') ? ':' . PORT : '') . rtrim($this->ConfigValue('Site_Path'), '/') . $prefix . '/'; } - function Redirect($t='', $params=null, $prefix='', $index_file=null) + function Redirect($t = '', $params = Array(), $prefix = '', $index_file = null) { $js_redirect = getArrayValue($params, 'js_redirect'); @@ -2288,6 +2332,14 @@ */ function ConfigValue($name) { + if ($name == 'Smtp_AdminMailFrom') { + $res = $this->siteDomainField('AdminEmail'); + + if ($res) { + return $res; + } + } + $res = array_key_exists($name, $this->ConfigHash) ? $this->ConfigHash[$name] : false; if ($res !== false) { return $res;