Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
domain.php
1<?php
2namespace Bitrix\Landing;
3
4use \Bitrix\Main\Config\Option;
5use \Bitrix\Main\Context;
6use \Bitrix\Main\Web\Uri;
7
9{
14 const B24_DOMAINS = [
15 'bitrix24.site',
16 'bitrix24.shop',
17 'bitrix24site.by',
18 'bitrix24shop.by',
19 'bitrix24site.ua',
20 'bitrix24site.ru',
21 'bitrix24shop.ru',
22 'b24site.online',
23 'b24shop.online',
24 ];
25
30 public static $internalClass = 'DomainTable';
31
36 protected static function getDomainName()
37 {
38 static $domain = null;
39
40 if (!$domain)
41 {
42 $context = \Bitrix\Main\Application::getInstance()->getContext();
43 $server = $context->getServer();
44 $domain = $server->getServerName();
45 if (!$domain)
46 {
47 $domain = $server->getHttpHost();
48 }
49 }
50
51 return $domain;
52 }
53
61 public static function getBitrix24Subdomain(string $domainName, ?string &$baseUrl = null): ?string
62 {
63 $re = '/^([^\.]+)\.(' . implode('|', self::B24_DOMAINS) . ')$/i';
64 if (preg_match($re, $domainName, $matches))
65 {
66 $baseUrl = ".{$matches[2]}";
67 return $matches[1];
68 }
69
70 return null;
71 }
72
80 public static function getBitrix24Postfix(string $type): string
81 {
82 $zone = Manager::getZone();
83 $postfix = ($type === 'STORE') ? '.bitrix24.shop' : '.bitrix24.site';
84 $type = mb_strtoupper($type);
85
86 // local domain
87 if (in_array($zone, ['ru']))
88 {
89 $postfix = '.';
90 $postfix .= ($type === 'STORE') ? 'bitrix24shop' : 'bitrix24site';
91 $postfix .= '.' . $zone;
92 }
93 if (in_array($zone, ['by']))
94 {
95 if ($type === 'STORE')
96 {
97 $postfix = '.b24shop.online';
98 }
99 else
100 {
101 $postfix = '.b24site.online';
102 }
103 }
104
105 return $postfix;
106 }
107
112 public static function canRegisterInBitrix24(): bool
113 {
114 try
115 {
116 Manager::getExternalSiteController()::isDomainExists('repo.bitrix24.site');
117 }
118 catch (\Bitrix\Main\SystemException $ex)
119 {
120 return false;
121 }
122
123 return true;
124 }
125
130 public static function createDefault()
131 {
132 $res = self::add(array(
133 'ACTIVE' => 'Y',
134 'DOMAIN' => self::getDomainName()
135 ));
136 if ($res->isSuccess())
137 {
138 return $res->getId();
139 }
140
141 return false;
142 }
143
148 public static function getCurrentId()
149 {
150 $res = self::getList(array(
151 'filter' => array(
152 '=ACTIVE' => 'Y',
153 '=DOMAIN' => self::getDomainName()
154 )
155 ));
156 if ($row = $res->fetch())
157 {
158 return $row['ID'];
159 }
160 else
161 {
162 return self::createDefault();
163 }
164 }
165
170 public static function getProtocolList()
171 {
172 return \Bitrix\Landing\Internals\DomainTable::getProtocolList();
173 }
174
179 public static function getHostUrl()
180 {
181 static $hostUrl = null;
182
183 if ($hostUrl !== null)
184 {
185 return $hostUrl;
186 }
187
188 $request = Context::getCurrent()->getRequest();
189 $protocol = ($request->isHttps() ? 'https://' : 'http://');
190
191 if (defined('SITE_SERVER_NAME') && SITE_SERVER_NAME)
192 {
193 $host = SITE_SERVER_NAME;
194 }
195 else
196 {
197 $host = Option::get('main', 'server_name', $request->getHttpHost());
198 }
199
200 $hostUrl = rtrim($protocol . $host, '/');
201
202 return $hostUrl;
203 }
204
210 public static function getTLD(string $domainName): string
211 {
212 $domainName = mb_strtolower(trim($domainName));
213 $domainNameParts = explode('.', $domainName);
214 $domainNameTld = $domainNameParts[count($domainNameParts) - 1];
215
216 if ($domainNameParts[count($domainNameParts) - 2] == 'com')
217 {
218 $domainNameTld = 'com.' . $domainNameTld;
219 }
220
221 return $domainNameTld;
222 }
223}
static getBitrix24Postfix(string $type)
Definition domain.php:80
static getProtocolList()
Definition domain.php:170
static getCurrentId()
Definition domain.php:148
static getDomainName()
Definition domain.php:36
static createDefault()
Definition domain.php:130
static getBitrix24Subdomain(string $domainName, ?string &$baseUrl=null)
Definition domain.php:61
static getTLD(string $domainName)
Definition domain.php:210
static canRegisterInBitrix24()
Definition domain.php:112
static getExternalSiteController()
Definition manager.php:1324