- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/publicaction/domain.php
- Класс: BitrixLandingPublicActionDomain
- Вызов: Domain::check
static function check($domain, array $filter = [])
{
$result = new PublicActionResult();
if (!is_string($domain))
{
return $result;
}
$puny = new CBXPunycode;
$domainOrig = $domain;
$domain = $puny->encode(trim($domain));
$tld = DomainCore::getTLD($domain);
$return = [
'available' => true,
'deleted' => false,
'errors' => null,
'domain' => $domain,
'length' => [
'length' => mb_strlen($domain),
'limit' => self::DOMAIN_MAX_LENGTH,
],
'tld' => $tld,
'dns' => Register::getDNSRecords($tld)
];
// check domain name restrictions
if (mb_strlen($domain) > self::DOMAIN_MAX_LENGTH)
{
$return['errors']['wrongLength'] = true;
}
if (!preg_match(self::DOMAIN_SYMBOLS_REGEXP, $domain))
{
$return['errors']['wrongSymbols'] = true;
}
if (preg_match(self::DOMAIN_WRONG_SYMBOLS_REGEXP, $domainOrig))
{
$return['errors']['wrongSymbolCombination'] = true;
}
if (strpos($domain, '.') === false)
{
$return['errors']['wrongDomainLevel'] = true;
}
if (is_array($return['errors']))
{
$return['available'] = false;
$result->setResult($return);
return $result;
}
// additional filter
if (!is_array($filter))
{
$filter = [];
}
$filter['=DOMAIN'] = $return['domain'];
// check domain
$res = DomainCore::getList([
'select' => [
'ID'
],
'filter' => $filter
]);
$return['available'] = !($domainRow = $res->fetch());
// check sites in trash
if (!$return['available'])
{
$resSite = Site::getList(array(
'select' => array(
'ID'
),
'filter' => array(
'DOMAIN_ID' => $domainRow['ID'],
'=DELETED' => 'Y',
'CHECK_PERMISSIONS' => 'N'
)
));
if ($resSite->fetch())
{
$return['available'] = false;
$return['deleted'] = true;
}
}
// external available check
if (
$return['available'] &&
$return['domain'] &&
Manager::isB24()
)
{
try
{
$siteController = Manager::getExternalSiteController();
if ($siteController)
{
$checkResult = $siteController::isDomainExists(
$return['domain']
);
$return['available'] = $checkResult < 2;
}
}
catch (SystemException $ex)
{
}
}
// set result and return
$result->setResult($return);
return $result;
}