- Модуль: imbot
- Путь к файлу: ~/bitrix/modules/imbot/lib/http.php
- Класс: BitrixImBotHttp
- Вызов: Http::getServerAddress
static function getServerAddress(): string
{
static $publicUrl;
if ($publicUrl === null)
{
$publicUrl = Option::get('imbot', 'portal_url');
if (defined('BOT_CLIENT_URL'))
{
$publicUrl = BOT_CLIENT_URL;
}
if (empty($publicUrl))
{
$context = MainApplication::getInstance()->getContext();
$scheme = $context->getRequest()->isHttps() ? 'https' : 'http';
$server = $context->getServer();
$domain = Option::get('main', 'server_name', '');
if (empty($domain))
{
$domain = $server->getServerName();
}
if (preg_match('/^(?.+):(?d+)$/', $domain, $matches))
{
$domain = $matches['domain'];
$port = (int)$matches['port'];
}
else
{
$port = (int)$server->getServerPort();
}
$port = in_array($port, [0, 80, 443]) ? '' : ':'.$port;
$publicUrl = $scheme.'://'.$domain.$port;
}
if (!(mb_strpos($publicUrl, 'https://') === 0 || mb_strpos($publicUrl, 'http://') === 0))
{
$publicUrl = 'https://' . $publicUrl;
}
}
return $publicUrl;
}