Index: branches/5.1.x/core/units/helpers/mod_rewrite_helper.php
===================================================================
diff -u -r13489 -r13559
--- branches/5.1.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 13489)
+++ branches/5.1.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 13559)
@@ -1,6 +1,6 @@
HTTPQuery =& $this->Application->recallObject('HTTPQuery');
+
+ // domain based primary language
+ $this->primaryLanguageId = $this->Application->siteDomainField('PrimaryLanguageId');
+
+ // domain based primary theme
+ $this->primaryThemeId = $this->Application->siteDomainField('PrimaryThemeId');
}
function processRewriteURL()
@@ -129,7 +149,7 @@
$sql = 'SELECT *
FROM ' . TABLE_PREFIX . 'CachedUrls
- WHERE Hash = ' . crc32($url);
+ WHERE Hash = ' . crc32($url) . ' AND DomainId = ' . (int)$this->Application->siteDomainField('DomainId');
$data = $this->Conn->GetRow($sql);
if ($data) {
@@ -194,6 +214,7 @@
$fields_hash = Array (
'Url' => $url,
'Hash' => crc32($url),
+ 'DomainId' => (int)$this->Application->siteDomainField('DomainId'),
'Prefixes' => $prefixes ? '|' . implode('|', $prefixes) . '|' : '',
'ParsedVars' => serialize($data),
'Cached' => adodb_mktime(),
@@ -409,8 +430,12 @@
}
// add language
- $default_language_id = $this->Application->GetDefaultLanguageId();
- if ($processed_params['m_lang'] && ($processed_params['m_lang'] != $default_language_id)) {
+ if (!$this->primaryLanguageId) {
+ // when domain-based language not found -> use site-wide language
+ $this->primaryLanguageId = $this->Application->GetDefaultLanguageId();
+ }
+
+ if ($processed_params['m_lang'] && ($processed_params['m_lang'] != $this->primaryLanguageId)) {
$language_name = $this->Application->getCache('language_names[%LangIDSerial:' . $processed_params['m_lang'] . '%]');
if ($language_name === false) {
$sql = 'SELECT PackName
@@ -425,8 +450,12 @@
}
// add theme
- $default_theme_id = $this->Application->GetDefaultThemeId(true);
- if ($processed_params['m_theme'] && ($processed_params['m_theme'] != $default_theme_id)) {
+ if (!$this->primaryThemeId) {
+ // when domain-based theme not found -> use site-wide theme
+ $this->primaryThemeId = $this->Application->GetDefaultThemeId(true);
+ }
+
+ if ($processed_params['m_theme'] && ($processed_params['m_theme'] != $this->primaryThemeId)) {
$theme_name = $this->Application->getCache('theme_names[%ThemeIDSerial:' . $processed_params['m_theme'] . '%]');
if ($theme_name === false) {
$sql = 'SELECT Name
@@ -533,6 +562,10 @@
// language was found by pack name
array_shift($url_parts);
}
+ elseif ($this->primaryLanguageId) {
+ // use domain-based primary language instead of site-wide primary language
+ $vars['m_lang'] = $this->primaryLanguageId;
+ }
return true;
}
@@ -577,6 +610,10 @@
// theme was found by name
array_shift($url_parts);
}
+ elseif ($this->primaryThemeId) {
+ // use domain-based primary theme instead of site-wide primary theme
+ $vars['m_theme'] = $this->primaryThemeId;
+ }
return true;
}
@@ -1076,17 +1113,31 @@
}
/**
- * Sets default parsed values before actual url parsing
+ * Sets default parsed values before actual url parsing (only, for empty url)
*
* @param Array $vars
*/
function _setDefaultValues(&$vars)
{
- $defaults = Array ('m_cat_id' => 0, 'm_cat_page' => 1, 'm_opener' => 's', 't' => 'index');
+ $defaults = Array (
+ 'm_cat_id' => 0, // no category
+ 'm_cat_page' => 1, // first category page
+ 'm_opener' => 's', // stay on same page
+ 't' => 'index' // main site page
+ );
+ if ($this->primaryLanguageId) {
+ // domain-based primary language
+ $defaults['m_lang'] = $this->primaryLanguageId;
+ }
+
+ if ($this->primaryThemeId) {
+ // domain-based primary theme
+ $defaults['m_theme'] = $this->primaryThemeId;
+ }
+
foreach ($defaults as $default_key => $default_value) {
- // bug: null is never returned
- if ($this->HTTPQuery->Get($default_key) == null) {
+ if ($this->HTTPQuery->Get($default_key) === false) {
$vars[$default_key] = $default_value;
}
}
Index: branches/5.1.x/core/kernel/processors/main_processor.php
===================================================================
diff -u -r13545 -r13559
--- branches/5.1.x/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 13545)
+++ branches/5.1.x/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 13559)
@@ -1,6 +1,6 @@
Application->ConfigValue('SSL_URL');
+ $ssl_url = $this->Application->siteDomainField('SSLUrl');
+ $ssl = $ssl_url !== false ? $ssl_url : $this->Application->ConfigValue('SSL_URL');
}
- if (!$ssl) return; //SSL URL is not set - no way to require SSL
+ if (!$ssl) {
+ // SSL URL is not set - no way to require SSL
+ return;
+ }
$require = false;
Index: branches/5.1.x/core/units/languages/languages_item.php
===================================================================
diff -u -r13545 -r13559
--- branches/5.1.x/core/units/languages/languages_item.php (.../languages_item.php) (revision 13545)
+++ branches/5.1.x/core/units/languages/languages_item.php (.../languages_item.php) (revision 13559)
@@ -1,6 +1,6 @@
$language_quality) {
$language_id = $this->getAvailableLanguage($language_locale);
if ($language_id) {
return $language_id;
}
}
-
+
return false;
}
@@ -118,18 +118,24 @@
if (strpos($locale, '-') !== false) {
// exact language match requested
- return array_key_exists($locale, $available_languages) ? $available_languages[$locale] : false;
+ $language_id = array_key_exists($locale, $available_languages) ? $available_languages[$locale] : false;
+
+ if ($language_id && $this->siteDomainLanguageEnabled($language_id)) {
+ return $language_id;
+ }
+
+ return false;
}
// partial (like "en" matches "en-GB" and "en-US") language match required
foreach ($available_languages as $language_code => $language_id) {
list ($language_code, ) = explode('-', $language_code);
- if ($locale == $language_code) {
+ if (($locale == $language_code) && $this->siteDomainLanguageEnabled($language_id)) {
return $language_id;
}
}
-
+
return false;
}
@@ -151,9 +157,17 @@
{
$default = false;
if ($id == 'default') {
+ // domain based primary language
$default = true;
- $res = parent::Load(1, 'PrimaryLang', true);
+ $id = $this->Application->siteDomainField('PrimaryLanguageId');
+ if ($id) {
+ $res = parent::Load($id, $id_field_name, true);
+ }
+ else {
+ $res = parent::Load(1, 'PrimaryLang', true);
+ }
+
if (
!$this->Application->isAdmin && $this->isEmptyUrl() &&
$this->Application->ConfigValue('UseContentLanguageNegotiation')
@@ -176,6 +190,13 @@
$res = parent::Load($id, $id_field_name, true);
}
+ if ($res) {
+ if (!$this->siteDomainLanguageEnabled($this->GetID())) {
+ // language isn't allowed in site domain
+ return $this->Clear();
+ }
+ }
+
if ($default) {
if (!$res) {
if ($this->Application->isAdmin) {
@@ -198,4 +219,21 @@
return $res;
}
+
+ /**
+ * Checks, that language is enabled in site domain
+ *
+ * @param int $id
+ * @return bool
+ */
+ function siteDomainLanguageEnabled($id)
+ {
+ $available_languages = $this->Application->siteDomainField('Languages');
+
+ if ($available_languages) {
+ return strpos($available_languages, '|' .$id . '|') !== false;
+ }
+
+ return true;
+ }
}
\ No newline at end of file
Index: branches/5.1.x/core/units/users/users_event_handler.php
===================================================================
diff -u -r13545 -r13559
--- branches/5.1.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 13545)
+++ branches/5.1.x/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 13559)
@@ -1,6 +1,6 @@
Application->ConfigValue('User_Default_Registration_Country');
+ $site_helper =& $this->Application->recallObject('SiteHelper');
+ /* @var $site_helper SiteHelper */
+
+ $first_country = $site_helper->getDefaultCountry('', false);
+
+ if ($first_country === false) {
+ $first_country = $this->Application->ConfigValue('User_Default_Registration_Country');
+ }
+
if ($first_country) {
// update user country dropdown sql
$fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
@@ -1414,7 +1422,6 @@
$this->Application->setUnitOption($event->Prefix, 'EditTabPresets', $edit_tab_presets);
}
}
-
}
/**
Index: branches/5.1.x/core/admin_templates/site_domains/site_domain_list.tpl
===================================================================
diff -u
--- branches/5.1.x/core/admin_templates/site_domains/site_domain_list.tpl (revision 0)
+++ branches/5.1.x/core/admin_templates/site_domains/site_domain_list.tpl (revision 13559)
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
Index: branches/5.1.x/core/install/install_schema.sql
===================================================================
diff -u -r13545 -r13559
--- branches/5.1.x/core/install/install_schema.sql (.../install_schema.sql) (revision 13545)
+++ branches/5.1.x/core/install/install_schema.sql (.../install_schema.sql) (revision 13559)
@@ -1184,6 +1184,7 @@
CREATE TABLE CachedUrls (
UrlId int(11) NOT NULL AUTO_INCREMENT,
Url varchar(255) NOT NULL DEFAULT '',
+ DomainId int(11) NOT NULL DEFAULT '0',
`Hash` int(11) NOT NULL DEFAULT '0',
Prefixes varchar(255) NOT NULL DEFAULT '',
ParsedVars text NOT NULL,
@@ -1194,5 +1195,38 @@
KEY `Hash` (`Hash`),
KEY Prefixes (Prefixes),
KEY Cached (Cached),
- KEY LifeTime (LifeTime)
+ KEY LifeTime (LifeTime),
+ KEY DomainId (DomainId)
+);
+
+CREATE TABLE SiteDomains (
+ DomainId int(11) NOT NULL AUTO_INCREMENT,
+ DomainName varchar(255) NOT NULL DEFAULT '',
+ DomainNameUsesRegExp tinyint(4) NOT NULL DEFAULT '0',
+ SSLUrl varchar(255) NOT NULL DEFAULT '',
+ SSLUrlUsesRegExp tinyint(4) NOT NULL DEFAULT '0',
+ AdminEmail varchar(255) NOT NULL DEFAULT '',
+ Country varchar(3) NOT NULL DEFAULT '',
+ PrimaryLanguageId int(11) NOT NULL DEFAULT '0',
+ Languages varchar(255) NOT NULL DEFAULT '',
+ PrimaryThemeId int(11) NOT NULL DEFAULT '0',
+ Themes varchar(255) NOT NULL DEFAULT '',
+ DomainIPRange text,
+ ExternalUrl varchar(255) NOT NULL DEFAULT '',
+ RedirectOnIPMatch tinyint(4) NOT NULL DEFAULT '0',
+ Priority int(11) NOT NULL DEFAULT '0',
+ PRIMARY KEY (DomainId),
+ KEY DomainName (DomainName),
+ KEY DomainNameUsesRegExp (DomainNameUsesRegExp),
+ KEY SSLUrl (SSLUrl),
+ KEY SSLUrlUsesRegExp (SSLUrlUsesRegExp),
+ KEY AdminEmail (AdminEmail),
+ KEY Country (Country),
+ KEY PrimaryLanguageId (PrimaryLanguageId),
+ KEY Languages (Languages),
+ KEY PrimaryThemeId (PrimaryThemeId),
+ KEY Themes (Themes),
+ KEY ExternalUrl (ExternalUrl),
+ KEY RedirectOnIPMatch (RedirectOnIPMatch),
+ KEY Priority (Priority)
);
\ No newline at end of file
Index: branches/5.1.x/core/units/languages/languages_event_handler.php
===================================================================
diff -u -r13453 -r13559
--- branches/5.1.x/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 13453)
+++ branches/5.1.x/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 13559)
@@ -1,6 +1,6 @@
Special == 'enabled') {
- $object =& $event->getObject();
- /* @var $object kDBList */
+ $object =& $event->getObject();
+ /* @var $object kDBList */
- $object->addFilter('enabled_filter', '%1$s.Enabled = 1');
+ if (in_array($event->Special, Array ('enabled', 'selected', 'available'))) {
+ $object->addFilter('enabled_filter', '%1$s.Enabled = ' . STATUS_ACTIVE);
}
+
+ // site domain language picker
+ if ($event->Special == 'selected' || $event->Special == 'available') {
+ $edit_picker_helper =& $this->Application->recallObject('EditPickerHelper');
+ /* @var $edit_picker_helper EditPickerHelper */
+
+ $edit_picker_helper->applyFilter($event, 'Languages');
+ }
+
+ // apply domain-based language filtering
+ $languages = $this->Application->siteDomainField('Languages');
+
+ if (strlen($languages)) {
+ $languages = explode('|', substr($languages, 1, -1));
+ $object->addFilter('domain_filter', '%1$s.LanguageId IN (' . implode(',', $languages) . ')');
+ }
}
/**
Index: branches/5.1.x/core/units/site_domains/site_domains_config.php
===================================================================
diff -u
--- branches/5.1.x/core/units/site_domains/site_domains_config.php (revision 0)
+++ branches/5.1.x/core/units/site_domains/site_domains_config.php (revision 13559)
@@ -0,0 +1,155 @@
+ 'site-domain',
+ 'ItemClass' => Array ('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'),
+ 'ListClass' => Array ('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'),
+ 'EventHandlerClass' => Array ('class' => 'SiteDomainEventHandler', 'file' => 'site_domain_eh.php', 'build_event' => 'OnBuild'),
+ 'TagProcessorClass' => Array ('class' => 'kDBTagProcessor', 'file' => '', 'build_event' => 'OnBuild'),
+
+ 'AutoLoad' => true,
+
+ 'QueryString' => Array (
+ 1 => 'id',
+ 2 => 'Page',
+ 3 => 'event',
+ 4 => 'mode',
+ ),
+
+ 'IDField' => 'DomainId',
+
+ 'TableName' => TABLE_PREFIX . 'SiteDomains',
+
+ 'TitleField' => 'DomainName',
+
+ 'TitlePresets' => Array (
+ 'default' => Array (
+ 'new_status_labels' => Array ('site-domain' => '!la_title_AddingSiteDomain!'),
+ 'edit_status_labels' => Array ('site-domain' => '!la_title_EditingSiteDomain!'),
+ ),
+
+ 'site_domain_list' => Array (
+ 'prefixes' => Array ('site-domain_List'), 'format' => "!la_title_SiteDomains!",
+ 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'view', 'dbl-click'),
+ ),
+
+ 'site_domain_edit' => Array (
+ 'prefixes' => Array ('site-domain'), 'format' => "#site-domain_status# '#site-domain_titlefield#' - !la_title_General!",
+ 'toolbar_buttons' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'),
+ ),
+ ),
+
+ 'EditTabPresets' => Array (
+ 'Default' => Array (
+ 'general' => Array ('title' => 'la_tab_General', 't' => 'site_domains/site_domain_edit', 'priority' => 1),
+ ),
+ ),
+
+ 'PermSection' => Array('main' => 'in-portal:site_domains'),
+
+ 'Sections' => Array (
+ 'in-portal:site_domains' => Array (
+ 'parent' => 'in-portal:website_setting_folder',
+ 'icon' => 'site_domain',
+ 'label' => 'la_title_SiteDomains',
+ 'url' => Array('t' => 'site_domains/site_domain_list', 'pass' => 'm'),
+ 'permissions' => Array('view', 'add', 'edit', 'delete'),
+ 'priority' => 7,
+ 'type' => stTREE,
+ ),
+ ),
+
+ 'ListSQLs' => Array (
+ '' => ' SELECT %1$s.* %2$s FROM %1$s',
+ ),
+
+ 'ListSortings' => Array (
+ '' => Array (
+ 'Sorting' => Array ('Priority' => 'desc', 'DomainName' => 'asc'),
+ )
+ ),
+
+ 'Fields' => Array (
+ 'DomainId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
+ 'DomainName' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'required' => 1, 'default' => ''),
+ 'DomainNameUsesRegExp' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 0
+ ),
+ 'SSLUrl' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''),
+ 'SSLUrlUsesRegExp' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 0
+ ),
+ 'AdminEmail' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''),
+ 'Country' => Array (
+ 'type' => 'string', 'max_len' => 3,
+ 'formatter' => 'kOptionsFormatter',
+ 'options_sql' => ' SELECT IF(l%2$s_Name = "", l%3$s_Name, l%2$s_Name) AS Name, IsoCode
+ FROM ' . TABLE_PREFIX . 'CountryStates
+ WHERE Type = ' . DESTINATION_TYPE_COUNTRY . '
+ ORDER BY Name',
+ 'option_key_field' => 'IsoCode', 'option_title_field' => 'Name',
+ 'not_null' => 1, 'default' => ''
+ ),
+ 'PrimaryLanguageId' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Language WHERE Enabled = 1 ORDER BY PackName ASC', 'option_key_field' => 'LanguageId', 'option_title_field' => 'PackName',
+ 'not_null' => 1, 'default' => 0
+ ),
+ 'Languages' => Array (
+ 'type' => 'string', 'max_len' => 255,
+ 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Language WHERE Enabled = 1 ORDER BY PackName ASC', 'option_key_field' => 'LanguageId', 'option_title_field' => 'PackName',
+ 'not_null' => 1, 'default' => ''
+ ),
+ 'PrimaryThemeId' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Theme WHERE Enabled = 1 ORDER BY Name ASC', 'option_key_field' => 'ThemeId', 'option_title_field' => 'Name',
+ 'not_null' => 1, 'default' => 0
+ ),
+ 'Themes' => Array (
+ 'type' => 'string', 'max_len' => 255,
+ 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Theme WHERE Enabled = 1 ORDER BY Name ASC', 'option_key_field' => 'ThemeId', 'option_title_field' => 'Name',
+ 'not_null' => 1, 'default' => ''
+ ),
+ 'DomainIPRange' => Array ('type' => 'string', 'default' => NULL),
+ 'ExternalUrl' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''),
+ 'RedirectOnIPMatch' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'la_Disabled', 1 => 'la_opt_CurrentDomain', 2 => 'la_opt_ExternalUrl'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 0
+ ),
+ 'Priority' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
+ ),
+
+ 'Grids' => Array (
+ 'Default' => Array (
+ 'Icons' => Array ('default' => 'icon16_item.png'),
+ 'Fields' => Array (
+ 'DomainId' => Array ('title' => 'la_col_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 70, ),
+ 'DomainName' => Array ('title' => 'la_col_DomainName', 'filter_block' => 'grid_like_filter', 'width' => 250, ),
+ 'SSLUrl' => Array ('title' => 'la_col_SSLUrl', 'filter_block' => 'grid_like_filter', 'width' => 250, ),
+ 'Country' => Array ('title' => 'la_col_Country', 'filter_block' => 'grid_options_filter', 'width' => 250, ),
+ 'PrimaryLanguageId' => Array ('title' => 'la_col_Language', 'filter_block' => 'grid_options_filter', 'width' => 250, ),
+ 'PrimaryThemeId' => Array ('title' => 'la_col_Theme', 'filter_block' => 'grid_options_filter', 'width' => 250, ),
+ 'Priority' => Array ('title' => 'la_col_Priority', 'filter_block' => 'grid_range_filter', 'width' => 70, ),
+ ),
+ ),
+ ),
+ );
Index: branches/5.1.x/core/units/themes/theme_item.php
===================================================================
diff -u -r13168 -r13559
--- branches/5.1.x/core/units/themes/theme_item.php (.../theme_item.php) (revision 13168)
+++ branches/5.1.x/core/units/themes/theme_item.php (.../theme_item.php) (revision 13559)
@@ -1,6 +1,6 @@
Application->siteDomainField('PrimaryThemeId');
+
+ if (!$id) {
+ $id = 1;
+ $id_field_name = 'PrimaryTheme';
+ }
+
$default = true;
}
$res = parent::Load($id, $id_field_name, true);
+ if ($res) {
+ $available_themes = $this->Application->siteDomainField('Themes');
+
+ if ($available_themes) {
+ if (strpos($available_themes, '|' . $this->GetID() . '|') === false) {
+ // theme isn't allowed in site domain
+ return $this->Clear();
+ }
+ }
+ }
+
if ($default) {
if (!$res) {
if ($this->Application->isAdmin) {
Index: branches/5.1.x/core/units/themes/themes_eh.php
===================================================================
diff -u -r13168 -r13559
--- branches/5.1.x/core/units/themes/themes_eh.php (.../themes_eh.php) (revision 13168)
+++ branches/5.1.x/core/units/themes/themes_eh.php (.../themes_eh.php) (revision 13559)
@@ -1,6 +1,6 @@
Special == 'enabled' || !$this->Application->isAdminUser) {
+ $object =& $event->getObject();
+ /* @var $object kDBList */
+
+ if (in_array($event->Special, Array ('enabled', 'selected', 'available')) || !$this->Application->isAdminUser) {
// "enabled" special or Front-End
+ $object->addFilter('enabled_filter', '%1$s.Enabled = ' . STATUS_ACTIVE);
+ }
- $object =& $event->getObject();
- /* @var $object kDBList */
+ // site domain theme picker
+ if ($event->Special == 'selected' || $event->Special == 'available') {
+ $edit_picker_helper =& $this->Application->recallObject('EditPickerHelper');
+ /* @var $edit_picker_helper EditPickerHelper */
- $object->addFilter('enabled_filter', '%1$s.Enabled = 1');
+ $edit_picker_helper->applyFilter($event, 'Themes');
}
+
+ // apply domain-based theme filtering
+ $themes = $this->Application->siteDomainField('Themes');
+
+ if (strlen($themes)) {
+ $themes = explode('|', substr($themes, 1, -1));
+ $object->addFilter('domain_filter', '%1$s.ThemeId IN (' . implode(',', $themes) . ')');
+ }
}
}
Index: branches/5.1.x/core/install/english.lang
===================================================================
diff -u -r13545 -r13559
--- branches/5.1.x/core/install/english.lang (.../english.lang) (revision 13545)
+++ branches/5.1.x/core/install/english.lang (.../english.lang) (revision 13559)
@@ -13,6 +13,7 @@
QXV0bw==
QXV0b21hdGlj
QXZhaWxhYmxlIENvbHVtbnM=
+ QXZhaWxhYmxlIEl0ZW1z
QmFja2dyb3VuZA==
Qm9yZGVycw==
QnJvd3NlIE1vZGU=
@@ -60,8 +61,10 @@
U2VjdGlvbiBOYW1l
Q2hhbmdlcw==
Q2hhcnNldA==
+ Q291bnRyeQ==
Q3JlYXRlZCBPbg==
RGVzY3JpcHRpb24=
+ RG9tYWluIE5hbWU=
RHVyYXRpb24=
RWZmZWN0aXZl
RW1haWw=
@@ -179,6 +182,7 @@
U2hvcnQgSVNPIENvZGU=
TmFtZQ==
U29ydCBieQ==
+ U1NMIFVybA==
U3RhdGUgQ291bnRyeQ==
U3RhdHVz
U3RvcCBXb3Jk
@@ -189,6 +193,7 @@
SXRlbQ==
SXRlbSBUeXBl
VGVtcGxhdGU=
+ VGhlbWU=
VGhlc2F1cnVzIFRlcm0=
VGhlc2F1cnVzIFR5cGU=
VGl0bGU=
@@ -344,6 +349,7 @@
QWN0aW9u
QWRkcmVzcyBMaW5lIDE=
QWRkcmVzcyBMaW5lIDI=
+ TWVzc2FnZXMgZnJvbSBTaXRlIEFkbWluIGFyZSBmcm9t
QWRtaW4gUHJpbWFyeQ==
QWR2YW5jZWQgQ1NT
QWR2YW5jZWQgU2VhcmNo
@@ -395,6 +401,8 @@
RGlzcGxheQ==
RGlzcGxheSBpbiBHcmlk
RmllbGQgTGFiZWw=
+ UmFuZ2Ugb2YgSVBz
+ RG9tYWluIE5hbWU=
QXMgUGxhaW4gVGV4dA==
RHVyYXRpb24=
RWRpdG9ycyBQaWNr
@@ -479,6 +487,7 @@
TGFuZ3VhZ2U=
TGFuZ3VhZ2UgRmlsZQ==
TGFuZ3VhZ2UgSUQ=
+ TGFuZ3VhZ2Vz
TGFzdCBOYW1l
TGFzdCBSdW4gT24=
TGFzdCBSdW4gU3RhdHVz
@@ -548,6 +557,7 @@
T3JkZXI=
UXVhbnRpdHk=
UmF0aW5n
+ Rm9yY2UgUmVkaXJlY3QgKHdoZW4gdXNlcidzIElQIG1hdGNoZXMp
UmVmZXJyZXIgVVJM
S2V5d29yZA==
VHlwZQ==
@@ -582,6 +592,7 @@
TmFtZQ==
U2tpcCBGaXJzdCBSb3c=
U29ydCBWYWx1ZXM=
+ U1NMIEZ1bGwgVVJM
U3RhdGU=
U3RhdGUgQ291bnRyeQ==
U3RhdHVz
@@ -598,6 +609,8 @@
VGV4dCBBbGlnbg==
VGV4dCBEZWNvcmF0aW9u
VGV4dCBWZXJzaW9u
+ VGhlbWU=
+ VGhlbWVz
VGhlc2F1cnVzIFRlcm0=
VGhlc2F1cnVzIFR5cGU=
VGhvdXNhbmRzIFNlcGFyYXRvcg==
@@ -634,12 +647,15 @@
SGlkZQ==
QWxsIEZpbGVz
Q1NWIEZpbGVz
+ U2luZ2xlIElQIG9yIHJhbmdlIHJlY29yZCBwZXIgbGluZSAoZm9ybWF0czogMS4yLjMuNCBvciAxLjIuMyBvciAxLjIuMy4zMi0xLjIuMy41NCBvciAxLjIuMy4zMi8yNyBvciAxLjIuMy4zMi8yNTUuMjU1LjI1NS4yMjQp
U2luZ2xlIEVtYWlsIEV2ZW50IHBlciBsaW5lIChmb3JtYXRzOiBVU0VSLkFERCwgT1JERVIuU1VCTUlUKQ==
U2luZ2xlIFBocmFzZSBMYWJlbCBwZXIgbGluZSAoZm9ybWF0czogbGFfU2FtcGxlTGFiZWwsIGx1X0Zyb250RW5kTGFiZWwp
VXNlciB3aWxsIGJlIGF1dG9tYXRpY2FsbHkgcmVkaXJlY3RlZCB0byB0aGUgc2VsZWN0ZWQgVXJsIEVuZGluZyBpbiBjYXNlIHdoZW4gY3VycmVudCBwYWdlIHVybCBoYXMgYSBkaWZmZXJlbnQgZW5kaW5n
SW1hZ2UgRmlsZXM=
UE9QMyBTZXJ2ZXIgUG9ydC4gRm9yIGV4LiAiMTEwIiBmb3IgcmVndWxhciBjb25uZWN0aW9uLCAiOTk1IiBmb3Igc2VjdXJlIGNvbm5lY3Rpb24u
UE9QMyBTZXJ2ZXIgQWRkcmVzcy4gRm9yIGV4LiB1c2UgInNzbDovL3BvcC5nbWFpbC5jb20iIGZvciBHbWFpbCwgInBvcC5tYWlsLnlhaG9vLmNvbSIgZm9yIFlhaG9vLg==
+ aHR0cHM6Ly93d3cuZG9tYWluLmNvbS9wYXRo
+ VXNpbmcgUmVndWxhciBFeHByZXNzaW9u
SG90
SFRNTA==
SUQgRmllbGQ=
@@ -713,6 +729,7 @@
Q29tbWVudCBUZXh0
Q291bnRyeQ==
Q3JlYXRlZCBPbg==
+ Q3VycmVudCBEb21haW4=
ZGF5KHMp
RGVueQ==
RGVzY3JpcHRpb24=
@@ -724,6 +741,7 @@
RXZlcnlvbmU=
RXhhY3Q=
RXhwaXJlZA==
+ RXh0ZXJuYWwgVXJs
RmFpbGVk
Rmlyc3QgTmFtZQ==
R3Vlc3RzIE9ubHk=
@@ -957,6 +975,7 @@
U2VhcmNoIFVzZXJz
VmFsdWVz
U2VsZWN0IENvbHVtbnM=
+ U2VsZWN0ZWQgSXRlbXM=
U2VsZWN0aW5nIFNlY3Rpb25z
T25lIGZpZWxkIGZvciBlYWNoIHNlY3Rpb24gbGV2ZWw=
Q2xvbmU=
@@ -1119,6 +1138,7 @@
QWRkaW5nIEN1c3RvbSBGaWVsZA==
QWRkaW5nIEZpbGU=
QWRkaW5nIE1haWxpbmcgTGlzdA==
+ QWRkaW5nIFNpdGUgRG9tYWlu
QWRkaW5nIFNraW4=
QWRkaW5nIFNwZWxsaW5nIERpY3Rpb25hcnk=
QWRkaW5nIFN0b3AgV29yZA==
@@ -1166,6 +1186,7 @@
RWRpdGluZyBFbWFpbCBFdmVudA==
RWRpdGluZyBGaWxl
RWRpdGluZyBNZW1iZXJzaGlw
+ RWRpdGluZyBTaXRlIERvbWFpbg==
RWRpdGluZyBTa2lu
RWRpdGluZyBTcGVsbGluZyBEaWN0aW9uYXJ5
RWRpdGluZyBTdG9wIFdvcmQ=
@@ -1242,6 +1263,7 @@
U2VuZCBFLW1haWw=
U2VuZGluZyBQcmVwYXJlZCBFLW1haWxz
TWFpbCBoYXMgYmVlbiBzZW50IFN1Y2Nlc3NmdWxseQ==
+ U2l0ZSBEb21haW5z
U3BlbGxpbmcgRGljdGlvbmFyeQ==
U3RvcCBXb3Jkcw==
U3RydWN0dXJlICYgRGF0YQ==
@@ -1299,6 +1321,7 @@
TmV3IFBocmFzZQ==
TmV3IENvbW1lbnQ=
TmV3IFNlYXJjaCBGaWVsZA==
+ TmV3IFNpdGUgRG9tYWlu
TmV3IFN0b3AgV29yZA==
TmV3IFN0eWxlc2hlZXQ=
TmV3IFRlcm0=
Index: branches/5.1.x/core/admin_templates/site_domains/site_domain_edit.tpl
===================================================================
diff -u
--- branches/5.1.x/core/admin_templates/site_domains/site_domain_edit.tpl (revision 0)
+++ branches/5.1.x/core/admin_templates/site_domains/site_domain_edit.tpl (revision 13559)
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ onchange="update_checkbox(this, document.getElementById(''));"/>
+
+
+ |
+
+
+
+
+
+
+
+
+
+
Index: branches/5.1.x/core/kernel/constants.php
===================================================================
diff -u -r13471 -r13559
--- branches/5.1.x/core/kernel/constants.php (.../constants.php) (revision 13471)
+++ branches/5.1.x/core/kernel/constants.php (.../constants.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;
Index: branches/5.1.x/core/kernel/globals.php
===================================================================
diff -u -r13393 -r13559
--- branches/5.1.x/core/kernel/globals.php (.../globals.php) (revision 13393)
+++ branches/5.1.x/core/kernel/globals.php (.../globals.php) (revision 13559)
@@ -1,6 +1,6 @@
= $from && $ip <= $to);
+ }
+ elseif (strpos($network, '/') !== false) {
// sigle subnet specified
$ip_arr = explode('/', $network);
@@ -589,14 +598,8 @@
return ($ip_long & $mask) == ($network_long & $mask);
}
- else {
- // ip address range specified
- $from = ip2long(trim(substr($network, 0, $d)));
- $to = ip2long(trim(substr($network, $d + 1)));
- $ip = ip2long($ip);
- return ($ip >= $from && $ip <= $to);
- }
+ return false;
}
function request_headers()
Index: branches/5.1.x/core/units/helpers/site_helper.php
===================================================================
diff -u
--- branches/5.1.x/core/units/helpers/site_helper.php (revision 0)
+++ branches/5.1.x/core/units/helpers/site_helper.php (revision 13559)
@@ -0,0 +1,58 @@
+Application->siteDomainField($country_prefix . 'Country');
+
+ if ($iso_format && !$country) {
+ $country = 'USA';
+ }
+
+ if (!$iso_format && strlen($country)) {
+ return $this->getCountryId($country);
+ }
+
+ return $country;
+ }
+
+ /**
+ * Returns country id based on it's ISO code
+ *
+ * @param string $iso_code
+ * @return int
+ */
+ function getCountryId($iso_code)
+ {
+ static $cache = null;
+
+ if (!isset($cache)) {
+ $sql = 'SELECT CountryStateId, IsoCode
+ FROM ' . $this->Application->getUnitOption('country-state', 'TableName') . '
+ WHERE Type = ' . DESTINATION_TYPE_COUNTRY;
+ $cache = $this->Conn->GetCol($sql, 'IsoCode');
+ }
+
+ return $cache[$iso_code];
+ }
+ }
Index: branches/5.1.x/core/install/upgrades.sql
===================================================================
diff -u -r13545 -r13559
--- branches/5.1.x/core/install/upgrades.sql (.../upgrades.sql) (revision 13545)
+++ branches/5.1.x/core/install/upgrades.sql (.../upgrades.sql) (revision 13559)
@@ -1687,6 +1687,7 @@
CREATE TABLE CachedUrls (
UrlId int(11) NOT NULL AUTO_INCREMENT,
Url varchar(255) NOT NULL DEFAULT '',
+ DomainId int(11) NOT NULL DEFAULT '0',
`Hash` int(11) NOT NULL DEFAULT '0',
Prefixes varchar(255) NOT NULL DEFAULT '',
ParsedVars text NOT NULL,
@@ -1697,7 +1698,8 @@
KEY `Hash` (`Hash`),
KEY Prefixes (Prefixes),
KEY Cached (Cached),
- KEY LifeTime (LifeTime)
+ KEY LifeTime (LifeTime),
+ KEY DomainId (DomainId)
);
INSERT INTO ConfigurationAdmin VALUES ('CacheHandler', 'la_section_SettingsCaching', 'la_config_CacheHandler', 'select', NULL, 'Fake=la_None,Memcache=+Memcached,Apc=+Alternative PHP Cache,XCache=+XCache', 80.02, 0, 0);
@@ -1830,3 +1832,35 @@
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'UseContentLanguageNegotiation', '0', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsWebsite', 'la_config_UseContentLanguageNegotiation', 'checkbox', '', '', 10.023, 0, 0, NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'SessionCookieDomains', '', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsSession', 'la_config_SessionCookieDomains', 'textarea', '', 'rows="5" cols="40"', 20.021, 0, 0, NULL);
+
+CREATE TABLE SiteDomains (
+ DomainId int(11) NOT NULL AUTO_INCREMENT,
+ DomainName varchar(255) NOT NULL DEFAULT '',
+ DomainNameUsesRegExp tinyint(4) NOT NULL DEFAULT '0',
+ SSLUrl varchar(255) NOT NULL DEFAULT '',
+ SSLUrlUsesRegExp tinyint(4) NOT NULL DEFAULT '0',
+ AdminEmail varchar(255) NOT NULL DEFAULT '',
+ Country varchar(3) NOT NULL DEFAULT '',
+ PrimaryLanguageId int(11) NOT NULL DEFAULT '0',
+ Languages varchar(255) NOT NULL DEFAULT '',
+ PrimaryThemeId int(11) NOT NULL DEFAULT '0',
+ Themes varchar(255) NOT NULL DEFAULT '',
+ DomainIPRange text,
+ ExternalUrl varchar(255) NOT NULL DEFAULT '',
+ RedirectOnIPMatch tinyint(4) NOT NULL DEFAULT '0',
+ Priority int(11) NOT NULL DEFAULT '0',
+ PRIMARY KEY (DomainId),
+ KEY DomainName (DomainName),
+ KEY DomainNameUsesRegExp (DomainNameUsesRegExp),
+ KEY SSLUrl (SSLUrl),
+ KEY SSLUrlUsesRegExp (SSLUrlUsesRegExp),
+ KEY AdminEmail (AdminEmail),
+ KEY Country (Country),
+ KEY PrimaryLanguageId (PrimaryLanguageId),
+ KEY Languages (Languages),
+ KEY PrimaryThemeId (PrimaryThemeId),
+ KEY Themes (Themes),
+ KEY ExternalUrl (ExternalUrl),
+ KEY RedirectOnIPMatch (RedirectOnIPMatch),
+ KEY Priority (Priority)
+);
Index: branches/5.1.x/core/units/admin/admin_tag_processor.php
===================================================================
diff -u -r13401 -r13559
--- branches/5.1.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 13401)
+++ branches/5.1.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 13559)
@@ -1,6 +1,6 @@
Application->Phrase($res, !$no_editing);
+ $res = $this->Application->Phrase($section_data['label'], !$no_editing);
}
+ else {
+ $res = '';
+ }
break;
default:
Index: branches/5.1.x/core/units/site_domains/site_domain_eh.php
===================================================================
diff -u
--- branches/5.1.x/core/units/site_domains/site_domain_eh.php (revision 0)
+++ branches/5.1.x/core/units/site_domains/site_domain_eh.php (revision 13559)
@@ -0,0 +1,333 @@
+ Array ('self' => true),
+ );
+
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
+ /**
+ * Returns ID of site domain, that matches current url
+ *
+ * @param kEvent $event
+ */
+ function getPassedID(&$event)
+ {
+ if ($event->Special == 'current') {
+ if ($this->Application->isAdmin) {
+ $event->setEventParam('raise_warnings', 0);
+ }
+ else {
+ if (PROTOCOL == 'https://') {
+ return $this->querySiteDomain('SSLUrl', rtrim($this->Application->BaseURL(), '/'));
+ }
+
+ return $this->querySiteDomain('DomainName', $_SERVER['HTTP_HOST']);
+ }
+ }
+
+ return parent::getPassedID($event);
+ }
+
+ function querySiteDomain($field, $value)
+ {
+ $site_domains = $this->getSiteDomains();
+
+ $domain_by_name = $this->getDomainByName($field, $value);
+ $domain_by_ip = $this->getDomainByIP();
+
+ if ($domain_by_ip) {
+ $site_domain = $site_domains[$domain_by_ip];
+ $redirect_mode = $site_domain['RedirectOnIPMatch'];
+
+ if (($redirect_mode == SITE_DOMAIN_REDIRECT_EXTERNAL) && ($domain_by_ip == $domain_by_name)) {
+ // redirect to external url (when visiting protected domain)
+ $external_url = $site_domain['ExternalUrl'];
+
+ if (preg_match('/^http[s]{0,1}:\/\//', $external_url)) {
+ $this->Application->Redirect('external:' . $external_url);
+ }
+ else {
+ $this->Application->Redirect('external:' . PROTOCOL . $external_url . $_SERVER['REQUEST_URI']);
+ }
+ }
+ elseif (($redirect_mode == SITE_DOMAIN_REDIRECT_CURRENT) && ($domain_by_ip != $domain_by_name)) {
+ // redirect to a domain detected by IP (when not already on it)
+ if ((PROTOCOL == 'https://') && !$site_domain['SSLUrlUsesRegExp'] && $site_domain['SSLUrl']) {
+ // need to remove sub folder from ssl url
+ $ssl_url = preg_replace('/^(https:\/\/[^\/]*)(\/.*){0,1}$/', '\\1', $site_domain['SSLUrl']);
+ $this->Application->Redirect('external:' . $ssl_url . $_SERVER['REQUEST_URI']);
+ }
+ elseif ((PROTOCOL == 'http://') && !$site_domain['DomainNameUsesRegExp']) {
+ $this->Application->Redirect('external:http://' . $site_domain['DomainName'] . $_SERVER['REQUEST_URI']);
+ }
+ }
+
+ return $domain_by_ip;
+ }
+
+ return $domain_by_name;
+ }
+
+ /**
+ * Try to match visited domain to any of existing
+ *
+ * @param string $field
+ * @param string $value
+ * @return int
+ */
+ function getDomainByName($field, $value)
+ {
+ $site_domains = $this->getSiteDomains();
+ $name_fields = Array ('DomainName', 'SSLUrl');
+
+ foreach ($site_domains as $id => $site_domain) {
+ if (in_array($field, $name_fields) && $site_domain[$field . 'UsesRegExp']) {
+ if (preg_match('/^' . $site_domain[$field] . '$/', $value)) {
+ return $id;
+ }
+ }
+ elseif ($site_domain[$field] == $value) {
+ return $id;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Try to match domain settings based on visitor's IP address
+ *
+ * @return int
+ */
+ function getDomainByIP()
+ {
+ $site_domains = $this->getSiteDomains();
+
+ foreach ($site_domains as $id => $site_domain) {
+ if (ipMatch($site_domain['DomainIPRange'], "\n")) {
+ return $id;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Load item if id is available
+ *
+ * @param kEvent $event
+ */
+ function LoadItem(&$event)
+ {
+ if ($this->Application->isAdmin) {
+ // don't load domain data from cache
+ parent::LoadItem($event);
+
+ return ;
+ }
+
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $id = (int)$this->getPassedID($event);
+
+ if ($object->isLoaded() && ($object->GetID() == $id)) {
+ // object is already loaded by same id
+ return ;
+ }
+
+ $site_domains = $this->getSiteDomains();
+ $domain_data = array_key_exists($id, $site_domains) ? $site_domains[$id] : false;
+
+ if ($object->LoadFromHash($domain_data)) {
+ $actions =& $this->Application->recallObject('kActions');
+ $actions->Set($event->Prefix_Special.'_id', $object->GetID() );
+ }
+ else {
+ $object->setID($id);
+ }
+ }
+
+ function getSiteDomains()
+ {
+ static $cache = null;
+
+ if (!isset($cache)) {
+ if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
+ $cache = $this->Application->getCache('master:domains_parsed', false);
+ }
+ else {
+ $cache = $this->Application->getDBCache('domains_parsed');
+ }
+
+ if ($cache) {
+ $cache = unserialize($cache);
+ }
+ else {
+ $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName');
+
+ $sql = 'SELECT *
+ FROM ' . $table_name . '
+ ORDER BY Priority DESC';
+ $cache = $this->Conn->Query($sql, $id_field);
+
+ if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
+ $this->Application->setCache('master:domains_parsed', serialize($cache));
+ }
+ else {
+ $this->Application->setDBCache('domains_parsed', serialize($cache));
+ }
+ }
+ }
+
+ return $cache;
+ }
+
+ /**
+ * Removes In-Commerce related fields, when it's not installed
+ *
+ * @param kEvent $event
+ */
+ function OnAfterConfigRead(&$event)
+ {
+ parent::OnAfterConfigRead($event);
+
+ if (!$this->Application->isModuleEnabled('In-Commerce')) {
+ $remove_fields = Array (
+ 'BillingCountry', 'ShippingCountry',
+ 'PrimaryCurrencyId', 'Currencies',
+ 'PrimaryPaymentTypeId', 'PaymentTypes'
+ );
+
+ // remove field definitions
+ $fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
+
+ foreach ($remove_fields as $remove_field) {
+ unset($fields[$remove_field]);
+ }
+
+ $this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
+
+ // remove grid columns
+ $grids = $this->Application->getUnitOption($event->Prefix, 'Grids');
+
+ foreach ($grids as $grid_name => $grid_info) {
+ foreach ($remove_fields as $remove_field) {
+ if (array_key_exists($remove_field, $grid_info['Fields'])) {
+ unset($grids[$grid_name]['Fields'][$remove_field]);
+ }
+ }
+ }
+
+ $this->Application->setUnitOption($event->Prefix, 'Grids', $grids);
+ }
+ }
+
+ /**
+ * Delete cached information about site domains
+ *
+ * @param kEvent $event
+ */
+ function OnSave(&$event)
+ {
+ parent::OnSave($event);
+
+ if ($event->status == erSUCCESS) {
+ $this->_deleteCache();
+ }
+ }
+
+ /**
+ * Deletes cached information about site domains
+ */
+ function _deleteCache()
+ {
+ if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
+ $this->Application->deleteCache('master:domains_parsed');
+ }
+ else {
+ $this->Application->deleteDBCache('domains_parsed');
+ }
+
+ $sql = 'DELETE FROM ' . TABLE_PREFIX . 'CachedUrls';
+ $this->Conn->Query($sql);
+ }
+
+ /**
+ * Set's required fields based on redirect mode
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemLoad(&$event)
+ {
+ parent::OnAfterItemLoad($event);
+
+ $this->_setRequired($event);
+ }
+
+ /**
+ * Set's required fields based on redirect mode
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemCreate(&$event)
+ {
+ parent::OnBeforeItemCreate($event);
+
+ $this->_setRequired($event);
+ }
+
+ /**
+ * Set's required fields based on redirect mode
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemUpdate(&$event)
+ {
+ parent::OnBeforeItemUpdate($event);
+
+ $this->_setRequired($event);
+ }
+
+ /**
+ * Set's required fields
+ *
+ * @param kEvent $event
+ */
+ function _setRequired(&$event)
+ {
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $redirect_mode = $object->GetDBField('RedirectOnIPMatch');
+ $object->setRequired('ExternalUrl', $redirect_mode == SITE_DOMAIN_REDIRECT_EXTERNAL);
+ $object->setRequired('DomainIPRange', $redirect_mode > 0);
+ }
+ }
Index: branches/5.1.x/core/install/remove_schema.sql
===================================================================
diff -u -r13470 -r13559
--- branches/5.1.x/core/install/remove_schema.sql (.../remove_schema.sql) (revision 13470)
+++ branches/5.1.x/core/install/remove_schema.sql (.../remove_schema.sql) (revision 13559)
@@ -70,3 +70,4 @@
DROP TABLE Forms;
DROP TABLE Semaphores;
DROP TABLE CachedUrls;
+DROP TABLE SiteDomains;
Index: branches/5.1.x/core/units/helpers/helpers_config.php
===================================================================
diff -u -r13471 -r13559
--- branches/5.1.x/core/units/helpers/helpers_config.php (.../helpers_config.php) (revision 13471)
+++ branches/5.1.x/core/units/helpers/helpers_config.php (.../helpers_config.php) (revision 13559)
@@ -1,6 +1,6 @@
'POP3Helper', 'class' => 'POP3Helper', 'file' => 'pop3_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'),
Array ('pseudo' => 'MimeDecodeHelper', 'class' => 'MimeDecodeHelper', 'file' => 'mime_decode_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'),
Array ('pseudo' => 'UserHelper', 'class' => 'UserHelper', 'file' => 'user_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'),
+ Array ('pseudo' => 'SiteHelper', 'class' => 'SiteHelper', 'file' => 'site_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'),
),
);
\ No newline at end of file