Index: admin_templates/site_domains/site_domain_edit.tpl =================================================================== --- admin_templates/site_domains/site_domain_edit.tpl (revision 0) +++ admin_templates/site_domains/site_domain_edit.tpl (revision 0) @@ -0,0 +1,123 @@ + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + onchange="update_checkbox(this, document.getElementById(''));"/> + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
+ + + + Index: admin_templates/site_domains/site_domain_list.tpl =================================================================== --- admin_templates/site_domains/site_domain_list.tpl (revision 0) +++ admin_templates/site_domains/site_domain_list.tpl (revision 0) @@ -0,0 +1,48 @@ + + + + + + + + + + + +
+ +
+ + + + Index: install/english.lang =================================================================== --- install/english.lang (revision 13470) +++ install/english.lang (working copy) @@ -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= @@ -343,6 +348,7 @@ QWN0aW9u QWRkcmVzcyBMaW5lIDE= QWRkcmVzcyBMaW5lIDI= + TWVzc2FnZXMgZnJvbSBTaXRlIEFkbWluIGFyZSBmcm9t QWRtaW4gUHJpbWFyeQ== QWR2YW5jZWQgQ1NT QWR2YW5jZWQgU2VhcmNo @@ -394,6 +400,8 @@ RGlzcGxheQ== RGlzcGxheSBpbiBHcmlk RmllbGQgTGFiZWw= + UmFuZ2Ugb2YgSVBz + RG9tYWluIE5hbWU= QXMgUGxhaW4gVGV4dA== RHVyYXRpb24= RWRpdG9ycyBQaWNr @@ -477,6 +485,7 @@ TGFuZ3VhZ2U= TGFuZ3VhZ2UgRmlsZQ== TGFuZ3VhZ2UgSUQ= + TGFuZ3VhZ2Vz TGFzdCBOYW1l TGFzdCBSdW4gT24= TGFzdCBSdW4gU3RhdHVz @@ -545,6 +554,7 @@ UHJpbWFyeSBMYW5ndWFnZSBQaHJhc2U= T3JkZXI= UmF0aW5n + Rm9yY2UgUmVkaXJlY3QgKHdoZW4gdXNlcidzIElQIG1hdGNoZXMp UmVmZXJyZXIgVVJM S2V5d29yZA== VHlwZQ== @@ -579,6 +589,7 @@ TmFtZQ== U2tpcCBGaXJzdCBSb3c= U29ydCBWYWx1ZXM= + U1NMIEZ1bGwgVVJM U3RhdGU= U3RhdGUgQ291bnRyeQ== U3RhdHVz @@ -595,6 +606,8 @@ VGV4dCBBbGlnbg== VGV4dCBEZWNvcmF0aW9u VGV4dCBWZXJzaW9u + VGhlbWU= + VGhlbWVz VGhlc2F1cnVzIFRlcm0= VGhlc2F1cnVzIFR5cGU= VGhvdXNhbmRzIFNlcGFyYXRvcg== @@ -631,12 +644,15 @@ SGlkZQ== QWxsIEZpbGVz Q1NWIEZpbGVz + U2luZ2xlIElQIG9yIHJhbmdlIHJlY29yZCBwZXIgbGluZSAoZm9ybWF0czogMS4yLjMuNCBvciAxLjIuMyBvciAxLjIuMy4zMi0xLjIuMy41NCBvciAxLjIuMy4zMi8yNyBvciAxLjIuMy4zMi8yNTUuMjU1LjI1NS4yMjQp U2luZ2xlIEVtYWlsIEV2ZW50IHBlciBsaW5lIChmb3JtYXRzOiBVU0VSLkFERCwgT1JERVIuU1VCTUlUKQ== U2luZ2xlIFBocmFzZSBMYWJlbCBwZXIgbGluZSAoZm9ybWF0czogbGFfU2FtcGxlTGFiZWwsIGx1X0Zyb250RW5kTGFiZWwp VXNlciB3aWxsIGJlIGF1dG9tYXRpY2FsbHkgcmVkaXJlY3RlZCB0byB0aGUgc2VsZWN0ZWQgVXJsIEVuZGluZyBpbiBjYXNlIHdoZW4gY3VycmVudCBwYWdlIHVybCBoYXMgYSBkaWZmZXJlbnQgZW5kaW5n SW1hZ2UgRmlsZXM= UE9QMyBTZXJ2ZXIgUG9ydC4gRm9yIGV4LiAiMTEwIiBmb3IgcmVndWxhciBjb25uZWN0aW9uLCAiOTk1IiBmb3Igc2VjdXJlIGNvbm5lY3Rpb24u UE9QMyBTZXJ2ZXIgQWRkcmVzcy4gRm9yIGV4LiB1c2UgInNzbDovL3BvcC5nbWFpbC5jb20iIGZvciBHbWFpbCwgInBvcC5tYWlsLnlhaG9vLmNvbSIgZm9yIFlhaG9vLg== + aHR0cHM6Ly93d3cuZG9tYWluLmNvbS9wYXRo + VXNpbmcgUmVndWxhciBFeHByZXNzaW9u SG90 SFRNTA== SUQgRmllbGQ= @@ -710,6 +726,7 @@ Q29tbWVudCBUZXh0 Q291bnRyeQ== Q3JlYXRlZCBPbg== + Q3VycmVudCBEb21haW4= ZGF5KHMp RGVueQ== RGVzY3JpcHRpb24= @@ -721,6 +738,7 @@ RXZlcnlvbmU= RXhhY3Q= RXhwaXJlZA== + RXh0ZXJuYWwgVXJs RmFpbGVk Rmlyc3QgTmFtZQ== R3Vlc3RzIE9ubHk= @@ -954,6 +972,7 @@ U2VhcmNoIFVzZXJz VmFsdWVz U2VsZWN0IENvbHVtbnM= + U2VsZWN0ZWQgSXRlbXM= U2VsZWN0aW5nIFNlY3Rpb25z T25lIGZpZWxkIGZvciBlYWNoIHNlY3Rpb24gbGV2ZWw= Q2xvbmU= @@ -1116,6 +1135,7 @@ QWRkaW5nIEN1c3RvbSBGaWVsZA== QWRkaW5nIEZpbGU= QWRkaW5nIE1haWxpbmcgTGlzdA== + QWRkaW5nIFNpdGUgRG9tYWlu QWRkaW5nIFNraW4= QWRkaW5nIFNwZWxsaW5nIERpY3Rpb25hcnk= QWRkaW5nIFN0b3AgV29yZA== @@ -1163,6 +1183,7 @@ RWRpdGluZyBFbWFpbCBFdmVudA== RWRpdGluZyBGaWxl RWRpdGluZyBNZW1iZXJzaGlw + RWRpdGluZyBTaXRlIERvbWFpbg== RWRpdGluZyBTa2lu RWRpdGluZyBTcGVsbGluZyBEaWN0aW9uYXJ5 RWRpdGluZyBTdG9wIFdvcmQ= @@ -1239,6 +1260,7 @@ U2VuZCBFLW1haWw= U2VuZGluZyBQcmVwYXJlZCBFLW1haWxz TWFpbCBoYXMgYmVlbiBzZW50IFN1Y2Nlc3NmdWxseQ== + U2l0ZSBEb21haW5z U3BlbGxpbmcgRGljdGlvbmFyeQ== U3RvcCBXb3Jkcw== U3RydWN0dXJlICYgRGF0YQ== @@ -1296,6 +1318,7 @@ TmV3IFBocmFzZQ== TmV3IENvbW1lbnQ= TmV3IFNlYXJjaCBGaWVsZA== + TmV3IFNpdGUgRG9tYWlu TmV3IFN0b3AgV29yZA== TmV3IFN0eWxlc2hlZXQ= TmV3IFRlcm0= Index: install/install_schema.sql =================================================================== --- install/install_schema.sql (revision 13470) +++ install/install_schema.sql (working copy) @@ -1183,6 +1183,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, @@ -1193,5 +1194,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: install/remove_schema.sql =================================================================== --- install/remove_schema.sql (revision 13470) +++ install/remove_schema.sql (working copy) @@ -70,3 +70,4 @@ DROP TABLE Forms; DROP TABLE Semaphores; DROP TABLE CachedUrls; +DROP TABLE SiteDomains; Index: install/upgrades.sql =================================================================== --- install/upgrades.sql (revision 13476) +++ install/upgrades.sql (working copy) @@ -1670,6 +1670,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, @@ -1680,7 +1681,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); @@ -1810,3 +1812,35 @@ UPDATE Phrase SET l<%PRIMARY_LANGUAGE%>_Translation = 'Enable SEO-friendly URLs mode (MOD-REWRITE)' WHERE Phrase = 'la_config_use_modrewrite' AND l<%PRIMARY_LANGUAGE%>_Translation = 'Use MOD REWRITE'; + +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: kernel/application.php =================================================================== --- kernel/application.php (revision 13488) +++ kernel/application.php (working copy) @@ -220,6 +220,13 @@ */ var $isAdmin = false; + /** + * Instance of site domain object + * + * @var kDBItem + */ + var $siteDomain = null; + /** * Returns kApplication instance anywhere in the script. * @@ -599,30 +606,63 @@ return $theme_id; } + /** + * Returns site primary currency ISO code + * + * @return string + */ function GetPrimaryCurrency() { - $cache_key = 'primary_currency[%CurrSerial%]'; - $primary_currency = $this->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 @@ -1530,21 +1570,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') { @@ -2023,27 +2058,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'); @@ -2273,6 +2317,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: kernel/constants.php =================================================================== --- kernel/constants.php (revision 13471) +++ kernel/constants.php (working copy) @@ -162,4 +162,8 @@ define('SUBMISSION_LOG_ATTACHMENT_PATH', WRITEBALE_BASE . '/user_files/submission_log/'); - define('TIMENOW', adodb_mktime()); // for faster message processing \ No newline at end of file + define('TIMENOW', adodb_mktime()); // for faster message processing + + // site domains + define('SITE_DOMAIN_REDIRECT_CURRENT', 1); + define('SITE_DOMAIN_REDIRECT_EXTERNAL', 2); \ No newline at end of file Index: kernel/globals.php =================================================================== --- kernel/globals.php (revision 13400) +++ kernel/globals.php (working copy) @@ -563,17 +563,26 @@ return $ip_match; } - function netMatch($network, $ip) { + function netMatch($network, $ip) + { $network = trim($network); $ip = trim($ip); if ($network == $ip) { - // comparing 2 ip addresses directly + // comparing two ip addresses directly return true; } $d = strpos($network, '-'); - if ($d === false) { + if ($d !== false) { + // 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); + } + 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: kernel/processors/main_processor.php =================================================================== --- kernel/processors/main_processor.php (revision 13400) +++ kernel/processors/main_processor.php (working copy) @@ -833,10 +833,14 @@ if (!$ssl) { // not in admin or admin ssl url is empty - $ssl = $this->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: units/admin/admin_tag_processor.php =================================================================== --- units/admin/admin_tag_processor.php (revision 13401) +++ units/admin/admin_tag_processor.php (working copy) @@ -147,7 +147,6 @@ return ''; } - if (array_key_exists('parent', $params) && $params['parent']) { do { $section = $section_data['parent']; @@ -175,13 +174,15 @@ break; case 'label': - $res = $section_data['label']; - if ($section != 'in-portal:root') { + if ($section && ($section != 'in-portal:root')) { // don't translate label for top section, because it's already translated $no_editing = array_key_exists('no_editing', $params) ? $params['no_editing'] : false; - $res = $this->Application->Phrase($res, !$no_editing); + $res = $this->Application->Phrase($section_data['label'], !$no_editing); } + else { + $res = ''; + } break; default: Index: units/helpers/helpers_config.php =================================================================== --- units/helpers/helpers_config.php (revision 13471) +++ units/helpers/helpers_config.php (working copy) @@ -65,5 +65,6 @@ Array ('pseudo' => '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 Index: units/helpers/mod_rewrite_helper.php =================================================================== --- units/helpers/mod_rewrite_helper.php (revision 13473) +++ units/helpers/mod_rewrite_helper.php (working copy) @@ -44,7 +44,21 @@ */ var $_templateAliases = null; + /** + * Domain-based primary language id + * + * @var int + */ + var $primaryLanguageId = false; + /** + * Domain-based primary theme id + * + * @var int + */ + var $primaryThemeId = false; + + /** * Possible url endings from ModRewriteUrlEnding configuration variable * * @var Array @@ -61,6 +75,12 @@ parent::kHelper(); $this->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: units/helpers/site_helper.php =================================================================== --- units/helpers/site_helper.php (revision 0) +++ units/helpers/site_helper.php (revision 0) @@ -0,0 +1,44 @@ +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: units/languages/languages_event_handler.php =================================================================== --- units/languages/languages_event_handler.php (revision 13453) +++ units/languages/languages_event_handler.php (working copy) @@ -174,12 +174,28 @@ */ function SetCustomQuery(&$event) { - if ($event->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: units/languages/languages_item.php =================================================================== --- units/languages/languages_item.php (revision 13400) +++ units/languages/languages_item.php (working copy) @@ -60,13 +60,30 @@ { $default = false; if ($id == 'default') { - $id = 1; - $id_field_name = 'PrimaryLang'; + // domain based primary language + $id = $this->Application->siteDomainField('PrimaryLanguageId'); + + if (!$id) { + $id = 1; + $id_field_name = 'PrimaryLang'; + } + $default = true; } $res = parent::Load($id, $id_field_name, true); + if ($res) { + $available_languages = $this->Application->siteDomainField('Languages'); + + if ($available_languages) { + if (strpos($available_languages, '|' . $this->GetID() . '|') === false) { + // language isn't allowed in site domain + return $this->Clear(); + } + } + } + if ($default) { if (!$res) { if ($this->Application->isAdmin) { Index: units/site_domains/site_domain_eh.php =================================================================== --- units/site_domains/site_domain_eh.php (revision 0) +++ units/site_domains/site_domain_eh.php (revision 0) @@ -0,0 +1,319 @@ + 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: units/site_domains/site_domains_config.php =================================================================== --- units/site_domains/site_domains_config.php (revision 0) +++ units/site_domains/site_domains_config.php (revision 0) @@ -0,0 +1,140 @@ + '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: units/themes/theme_item.php =================================================================== --- units/themes/theme_item.php (revision 13400) +++ units/themes/theme_item.php (working copy) @@ -20,13 +20,30 @@ { $default = false; if ($id == 'default') { - $id = 1; - $id_field_name = 'PrimaryTheme'; + // domain based primary theme + $id = $this->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: units/themes/themes_eh.php =================================================================== --- units/themes/themes_eh.php (revision 13400) +++ units/themes/themes_eh.php (working copy) @@ -168,13 +168,28 @@ { parent::SetCustomQuery($event); - if ($event->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: units/users/users_event_handler.php =================================================================== --- units/users/users_event_handler.php (revision 13471) +++ units/users/users_event_handler.php (working copy) @@ -1370,7 +1370,15 @@ parent::OnAfterConfigRead($event); // 1. arrange user registration countries - $first_country = $this->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); } } - } /**