protected function initializeSite() { $context = $this->application->getContext(); $request = $context->getRequest(); $currentDirectory = $request->getRequestedPageDirectory(); $currentHost = ""; $currentHostScheme = ""; if ($request instanceof IHttpRequest) { /** @var $request \Bitrix\Main\HttpRequest */ $currentHost = $request->getHttpHost(); $currentHostScheme = $request->isHttps() ? "https://" : "http://"; } $url = new Web\Uri($currentHostScheme . $currentHost, Web\UriType::ABSOLUTE); $currentDomain = $url->parse(Web\UriPart::HOST); $currentDomain = trim($currentDomain, "\t\r\n ."); $connection = Application::getDbConnection(); $helper = $connection->getSqlHelper(); $sql = "\n\t\t\tSELECT L.*, L.LID as ID, L.LID as SITE_ID\n\t\t\tFROM b_lang L\n\t\t\t\tLEFT JOIN b_lang_domain LD ON L.LID=LD.LID AND '" . $helper->forSql($currentDomain, 255) . "' LIKE CONCAT('%', LD.DOMAIN)\n\t\t\tWHERE ('" . $helper->forSql($currentDirectory) . "' LIKE CONCAT(L.DIR, '%') OR LD.LID IS NOT NULL)\n\t\t\t\tAND L.ACTIVE='Y'\n\t\t\tORDER BY\n\t\t\t\tIF((L.DOMAIN_LIMITED='Y' AND LD.LID IS NOT NULL) OR L.DOMAIN_LIMITED<>'Y',\n\t\t\t\t\tIF('" . $helper->forSql($currentDomain) . "' LIKE CONCAT(L.DIR, '%'), 3, 1),\n\t\t\t\t\tIF('" . $helper->forSql($currentDirectory) . "' LIKE CONCAT(L.DIR, '%'), 2, 0)\n\t\t\t\t) DESC,\n\t\t\t\tLENGTH(L.DIR) DESC,\n\t\t\t\tL.DOMAIN_LIMITED DESC,\n\t\t\t\tSORT,\n\t\t\t\tLENGTH(LD.DOMAIN) DESC\n\t\t"; //get site by path and domain $siteList = $connection->query($sql); $site = $siteList->fetch(); //get site by default sorting if ($site === false) { $sql = "\n\t\t\t\tSELECT L.*, L.LID as ID, L.LID as SITE_ID\n\t\t\t\tFROM b_lang L\n\t\t\t\tWHERE L.ACTIVE='Y'\n\t\t\t\tORDER BY L.DEF DESC, L.SORT\n\t\t\t"; $siteList = $connection->query($sql); $site = $siteList->fetch(); } if ($site !== false) { $culture = Context\Culture::wakeUp($site["CULTURE_ID"]); if ($culture === null) { $culture = new Context\Culture(); } $this->site = new Context\Site($site); $this->site->setCulture($culture); } else { throw new SystemException("Site not found."); } }
public function getHttpHost($raw = true) { if ($raw) { return $this->server->getHttpHost(); } static $host = null; if ($host === null) { $host = $this->server->getHttpHost(); $hostScheme = $this->isHttps() ? "https://" : "http://"; $url = new Web\Uri($hostScheme . $host, Web\UriType::ABSOLUTE); $host = $url->parse(Web\UriPart::HOST); $host = trim($host, "\t\r\n ."); } return $host; }