Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
bitrix24.php
1<?php
3
7use \Bitrix\Main\ModuleManager;
8use \Bitrix\Main\Loader;
9
10class Bitrix24 extends Provider
11{
16 public function getCode(): string
17 {
18 return 'bitrix24';
19 }
20
25 public function enable(): bool
26 {
27 return false;
28 // $zone = Manager::getZone();
29 // return ($zone == 'ru') && ModuleManager::isModuleInstalled('bitrix24');
30 }
31
36 public function getTld(): array
37 {
38 switch (Manager::getZone())
39 {
40 case 'ru':
41 return ['ru'];
42 case 'ua':
43 return ['com.ua'];
44 default:
45 return [];
46 }
47 }
48
53 public function getAgreementURL(): ?string
54 {
55 switch (Manager::getZone())
56 {
57 case 'ru':
58 return 'https://www.bitrix24.ru/about/domainfree.php';
59 case 'ua':
60 return 'https://www.bitrix24.ua/about/domainfree.php';
61 default:
62 return null;
63 }
64 }
65
71 public function isEnableForRegistration(string $domainName): bool
72 {
73 $res = \CControllerClient::executeEvent(
74 'OnMailControllerWhoisDomain',
75 [
76 'DOMAIN' => trim(strtoupper($domainName)),
77 'ZONE' => Manager::getZone()
78 ]
79 );
80 if (!empty($res['error']))
81 {
82 return false;
83 }
84 return $res && !(isset($res['result']) && $res['result'] === true);
85 }
86
92 protected function getKeywordsByDomain(string $domainName): array
93 {
94 $domainName = str_replace('.', '-', $domainName);
95 $domainParts = explode('-', $domainName);
96 if (count($domainParts) > 2)
97 {
98 array_pop($domainParts);
99 }
100
101 return $domainParts;
102 }
103
110 public function getSuggestedDomains(string $domainName, array $tld): array
111 {
112 $domains = [];
113 $words = $this->getKeywordsByDomain($domainName);
114
115 if ($words)
116 {
117 $res = \CControllerClient::executeEvent(
118 'OnMailControllerSuggestDomain',
119 [
120 'WORD1' => $words[0],
121 'WORD2' => isset($words[1]) ? $words[1] : '',
122 'TLDS' => array_map('mb_strtolower', $tld),
123 'ZONE' => Manager::getZone()
124 ]
125 );
126 if ($res && isset($res['result']) && is_array($res['result']))
127 {
128 $domains = $res['result'];
129 }
130 }
131
132 return $domains;
133 }
134
141 public function registrationDomain(string $domainName, array $params = []): bool
142 {
143 $dns = \Bitrix\Landing\Domain\Register::getDNSRecords();
144 $domainName = mb_strtolower(trim($domainName));
145 $domainNameTld = Domain::getTLD($domainName);
146
147 // check tld
148 $tldValid = false;
149 foreach ($this->getTld() as $tld)
150 {
151 if ($domainNameTld == $tld)
152 {
153 $tldValid = true;
154 break;
155 }
156 }
157 if (!$tldValid)
158 {
159 return false;
160 }
161
162 $dnsParams = [];
163 $dnsParams[] = [
164 'type' => 'cname',
165 'name' => 'www',
166 'value' => isset($params['CNAME'])
167 ? $params['CNAME'] : $dns['CNAME']
168 ];
169 $dnsParams[] = [
170 'type' => 'a',
171 'value' => $dns['INA']
172 ];
173
174 $res = \CControllerClient::executeEvent(
175 'OnMailControllerRegDomain',
176 [
177 'DOMAIN' => $domainName,
178 'IP' => $_SERVER['REMOTE_ADDR'],
179 'DNS' => $dnsParams,
180 'ZONE' => Manager::getZone()
181 ]
182 );
183
184 if (isset($res['result']) && $res['result'] === true)
185 {
186 return true;
187 }
188 // we try detect that this domain is property of current portal
189 else
190 {
191 $res = \CControllerClient::executeEvent(
192 'OnMailControllerGetMemberDomains',
193 ['REGISTERED' => true]
194 );
195 if (isset($res['result']) && is_array($res['result']))
196 {
197 $puny = new \CBXPunycode;
198 $domainNameEncoded = $puny->encode($domainName);
199 if (
200 in_array($domainName, $res['result']) ||
201 in_array($domainNameEncoded, $res['result'])
202 )
203 {
204 return true;
205 }
206 }
207 }
208
209 return false;
210 }
211
216 public function getPortalDomains(): array
217 {
218 $res = \CControllerClient::executeEvent(
219 'OnMailControllerGetMemberDomains',
220 ['REGISTERED' => true]
221 );
222 if (isset($res['result']) && is_array($res['result']))
223 {
224 return $res['result'];
225 }
226 return [];
227 }
228}
getKeywordsByDomain(string $domainName)
Definition bitrix24.php:92
getSuggestedDomains(string $domainName, array $tld)
Definition bitrix24.php:110
registrationDomain(string $domainName, array $params=[])
Definition bitrix24.php:141
isEnableForRegistration(string $domainName)
Definition bitrix24.php:71
static getTLD(string $domainName)
Definition domain.php:210