Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
domain.php
1<?php
3
4use \Bitrix\Landing\Site;
5use \Bitrix\Landing\Domain as DomainCore;
6use \Bitrix\Landing\PublicActionResult;
7use \Bitrix\Landing\Manager;
8use \Bitrix\Landing\Domain\Register;
9use \Bitrix\Main\SystemException;
10
11class Domain
12{
13 protected const DOMAIN_MAX_LENGTH = 63;
14 protected const DOMAIN_SYMBOLS_REGEXP = '/^[a-z\d.-]+$/i';
15 protected const DOMAIN_WRONG_SYMBOLS_REGEXP = '/(--|-\.|\.\.|^\.|\.$|^-|-$)/i';
16
22 public static function getList(array $params = array())
23 {
24 $result = new PublicActionResult();
25 $params = $result->sanitizeKeys($params);
26
27 $data = array();
28 $res = DomainCore::getList($params);
29 while ($row = $res->fetch())
30 {
31 if (isset($row['DATE_CREATE']))
32 {
33 $row['DATE_CREATE'] = (string) $row['DATE_CREATE'];
34 }
35 if (isset($row['DATE_MODIFY']))
36 {
37 $row['DATE_MODIFY'] = (string) $row['DATE_MODIFY'];
38 }
39 $data[] = $row;
40 }
41 $result->setResult($data);
42
43 return $result;
44 }
45
51 public static function add(array $fields)
52 {
53 $result = new PublicActionResult();
54 $error = new \Bitrix\Landing\Error;
55
56 $res = DomainCore::add($fields);
57
58 if ($res->isSuccess())
59 {
60 $result->setResult($res->getId());
61 }
62 else
63 {
64 $error->addFromResult($res);
65 $result->setError($error);
66 }
67
68 return $result;
69 }
70
77 public static function update($id, array $fields)
78 {
79 $result = new PublicActionResult();
80 $error = new \Bitrix\Landing\Error;
81
82 $res = DomainCore::update($id, $fields);
83
84 if ($res->isSuccess())
85 {
86 $result->setResult(true);
87 }
88 else
89 {
90 $error->addFromResult($res);
91 $result->setError($error);
92 }
93
94 return $result;
95 }
96
102 public static function delete($id)
103 {
104 $result = new PublicActionResult();
105 $error = new \Bitrix\Landing\Error;
106
107 $res = DomainCore::delete($id);
108
109 if ($res->isSuccess())
110 {
111 $result->setResult(true);
112 }
113 else
114 {
115 $error->addFromResult($res);
116 $result->setError($error);
117 }
118
119 return $result;
120 }
121
127 public static function punycode($domain)
128 {
129 $puny = new \CBXPunycode;
130 $result = new PublicActionResult();
131 $result->setResult(
132 $puny->encode($domain)
133 );
134 return $result;
135 }
136
143 public static function check($domain, array $filter = [])
144 {
145 $result = new PublicActionResult();
146
147 if (!is_string($domain))
148 {
149 return $result;
150 }
151
152 $puny = new \CBXPunycode;
153 $domainOrig = $domain;
154 $domain = $puny->encode(trim($domain));
155 $tld = DomainCore::getTLD($domain);
156 $return = [
157 'available' => true,
158 'deleted' => false,
159 'errors' => null,
160 'domain' => $domain,
161 'length' => [
162 'length' => mb_strlen($domain),
163 'limit' => self::DOMAIN_MAX_LENGTH,
164 ],
165 'tld' => $tld,
166 'dns' => Register::getDNSRecords($tld)
167 ];
168
169 // check domain name restrictions
170 if (mb_strlen($domain) > self::DOMAIN_MAX_LENGTH)
171 {
172 $return['errors']['wrongLength'] = true;
173 }
174 if (!preg_match(self::DOMAIN_SYMBOLS_REGEXP, $domain))
175 {
176 $return['errors']['wrongSymbols'] = true;
177 }
178 if (preg_match(self::DOMAIN_WRONG_SYMBOLS_REGEXP, $domainOrig))
179 {
180 $return['errors']['wrongSymbolCombination'] = true;
181 }
182 if (strpos($domain, '.') === false)
183 {
184 $return['errors']['wrongDomainLevel'] = true;
185 }
186 if (is_array($return['errors']))
187 {
188 $return['available'] = false;
189 $result->setResult($return);
190
191 return $result;
192 }
193
194 // additional filter
195 if (!is_array($filter))
196 {
197 $filter = [];
198 }
199 $filter['=DOMAIN'] = $return['domain'];
200
201 // check domain
202 $res = DomainCore::getList([
203 'select' => [
204 'ID'
205 ],
206 'filter' => $filter
207 ]);
208 $return['available'] = !($domainRow = $res->fetch());
209
210 // check sites in trash
211 if (!$return['available'])
212 {
213 $resSite = Site::getList(array(
214 'select' => array(
215 'ID'
216 ),
217 'filter' => array(
218 'DOMAIN_ID' => $domainRow['ID'],
219 '=DELETED' => 'Y',
220 'CHECK_PERMISSIONS' => 'N'
221 )
222 ));
223 if ($resSite->fetch())
224 {
225 $return['available'] = false;
226 $return['deleted'] = true;
227 }
228 }
229
230 // external available check
231 if (
232 $return['available'] &&
233 $return['domain'] &&
235 )
236 {
237 try
238 {
239 $siteController = Manager::getExternalSiteController();
240 if ($siteController)
241 {
242 //todo: revert changes after change .by domain
243 $domainName = $return['domain'];
244 $byDomainName = '';
245 $isOnlineSite = str_ends_with($domainName, '.b24site.online');
246 $isOnlineShop = str_ends_with($domainName, '.b24shop.online');
247 if ($isOnlineSite)
248 {
249 $byDomainName = str_replace('.b24site.online', '.bitrix24site.by', $domainName);
250 }
251 if ($isOnlineShop)
252 {
253 $byDomainName = str_replace('.b24shop.online', '.bitrix24shop.by', $domainName);
254 }
255 $checkResult = $siteController::isDomainExists(
256 $domainName
257 );
258 if ($byDomainName === '')
259 {
260 $return['available'] = $checkResult < 2;
261 }
262 else
263 {
264 $checkResultBy = $siteController::isDomainExists(
265 $byDomainName
266 );
267 $return['available'] = $checkResult < 2 && $checkResultBy < 2;
268 }
269 }
270 }
271 catch (SystemException $ex)
272 {
273 }
274 }
275
276 // set result and return
277 $result->setResult($return);
278 return $result;
279 }
280
287 public static function whois(string $domainName, array $tld): PublicActionResult
288 {
289 $result = new PublicActionResult();
290 $domainName = trim($domainName);
291 $return = [
292 'enable' => false,
293 'suggest' => []
294 ];
295
296 // registrator instance
297 $regInstance = Register::getInstance();
298 if ($regInstance && !$regInstance->enable())
299 {
300 $result->setResult($return);
301 return $result;
302 }
303
304 // internal enable first
305 $res = DomainCore::getList([
306 'select' => [
307 'ID'
308 ],
309 'filter' => [
310 '=DOMAIN' => $domainName
311 ]
312 ]);
313 if (!$res->fetch())
314 {
315 $return['enable'] = $regInstance->isEnableForRegistration($domainName);
316 }
317
318 // get suggested domains
319 if (!$return['enable'])
320 {
321 $return['suggest'] = $regInstance->getSuggestedDomains($domainName, $tld);
322 }
323
324 $result->setResult($return);
325
326 return $result;
327 }
328}
static getDNSRecords(?string $tld=null)
Definition register.php:58
static getExternalSiteController()
Definition manager.php:1324
static check($domain, array $filter=[])
Definition domain.php:143
static getList(array $params=array())
Definition domain.php:22
static whois(string $domainName, array $tld)
Definition domain.php:287
static add(array $fields)
Definition domain.php:51
static update($id, array $fields)
Definition domain.php:77