Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
service.php
1<?php
3
6
11final class Service
12{
21 public static function landingDomainVerificationHandler(Main\Event $event): Main\Entity\EventResult
22 {
23 $result = new Main\Entity\EventResult;
24
25 if (class_exists('\LandingPubComponent'))
26 {
27 $code = $event->getParameter('code');
28 if ($code === \LandingPubComponent::ERROR_STATUS_NOT_FOUND)
29 {
30 $landingInstance = \LandingPubComponent::getMainInstance();
31 if ($landingInstance)
32 {
33 $res = Landing\Site::getList([
34 'select' => [
35 'DOMAIN_NAME' => 'DOMAIN.DOMAIN'
36 ],
37 'filter' => [
38 'CHECK_PERMISSIONS' => 'N',
39 'ID' => $landingInstance['SITE_ID']
40 ]
41 ]);
42 if ($row = $res->fetch())
43 {
44 $context = Main\Application::getInstance()->getContext();
45
46 $realFilePath = $context->getServer()->get('REAL_FILE_PATH');
47 if (!$realFilePath)
48 {
49 $realFilePath = $_SERVER['REAL_FILE_PATH'] ?? null;
50 }
51 if (!$realFilePath)
52 {
53 $realFilePath = $context->getServer()->get('SCRIPT_NAME');
54 }
55
56 $requestURL = $context->getRequest()->getRequestedPage();
57
58 $landingUrl = Landing\Site::getPublicUrl($landingInstance['SITE_ID']);
59 $realFilePath = str_replace('/index.php', '/', $realFilePath);
60 if (mb_strpos($landingUrl, $realFilePath) === false)
61 {
62 $requestURL = str_replace($realFilePath.$landingInstance['SITE_ID'], '', $requestURL);
63 }
64
65 $domainVerification = BaseManager::searchByRequest($row['DOMAIN_NAME'], $requestURL);
66
67 if (!$domainVerification)
68 {
69 $pubPath = \Bitrix\Landing\Manager::getPublicationPath($landingInstance['SITE_ID']);
70 $domainVerification = BaseManager::searchByRequest($row['DOMAIN_NAME'], substr($requestURL, strlen($pubPath)-1));
71 }
72
73 if ($domainVerification)
74 {
75 $result->modifyFields([
76 'code' => \LandingPubComponent::ERROR_STATUS_OK
77 ]);
78
79 self::setEndBufferContentHandler($domainVerification['CONTENT']);
80 }
81 }
82 }
83 }
84 }
85
86 return $result;
87 }
88
96 public static function b24DomainVerificationHandler(): void
97 {
98 if (!Main\ModuleManager::isModuleInstalled('bitrix24'))
99 {
100 return;
101 }
102
103 $isFound = false;
104 $managerList = BaseManager::getManagerList();
105
107 foreach (array_keys($managerList) as $manager)
108 {
109 if (strpos($_SERVER['REQUEST_URI'], $manager::getPathPrefix()) !== false)
110 {
111 $isFound = true;
112 break;
113 }
114 }
115
116 if ($isFound)
117 {
118 $context = Main\Application::getInstance()->getContext();
119 $serverName = $context->getServer()->getServerName();
120 $requestUri = $context->getServer()->getRequestUri();
121
122 $hasParams = strpos($requestUri, '?');
123 $requestUriWithoutParams = ($hasParams !== false)
124 ? substr($requestUri, 0, $hasParams)
125 : $requestUri;
126
127 $domainVerification = BaseManager::searchByRequest($serverName, $requestUriWithoutParams);
128 if ($domainVerification)
129 {
130 self::setEndBufferContentHandler($domainVerification['CONTENT']);
131 }
132
133 \CHTTP::SetStatus('200 OK');
134 }
135 }
136
140 public static function setEndBufferContentHandler($content): void
141 {
142 $eventManager = Main\EventManager::getInstance();
143 $eventManager->addEventHandler(
144 'main',
145 'onEndBufferContent',
146 static function(&$resultContent) use ($content)
147 {
148 header('Content-Type: text/plain');
149 $resultContent = $content;
150 }
151 );
152 }
153}
static isModuleInstalled($moduleName)
static landingDomainVerificationHandler(Main\Event $event)
Definition service.php:21
static setEndBufferContentHandler($content)
Definition service.php:140