Index: branches/5.1.x/core/units/helpers/site_helper.php =================================================================== diff -u -N -r13559 -r13874 --- branches/5.1.x/core/units/helpers/site_helper.php (.../site_helper.php) (revision 13559) +++ branches/5.1.x/core/units/helpers/site_helper.php (.../site_helper.php) (revision 13874) @@ -1,6 +1,6 @@ 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 { + $sql = 'SELECT * + FROM ' . TABLE_PREFIX . 'SiteDomains + ORDER BY Priority DESC'; + $cache = $this->Conn->Query($sql, 'DomainId'); + + 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; + } + + /** + * 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) ) { + if (!$site_domain[$field . 'UsesRegExp']) { + // not regular expression -> escape manually + $site_domain[$field] = preg_quote($site_domain[$field], '/'); + } + + if (preg_match('/^' . $site_domain[$field] . ($field == 'DomainName' ? '$' : '') . '/', $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; + } }