4use \Bitrix\Landing\Hook;
5use \Bitrix\Landing\Manager;
6use \Bitrix\Landing\Site;
7use \Bitrix\Landing\Internals\BlockTable;
8use \Bitrix\Landing\Internals\HookDataTable;
9use \Bitrix\Main\Loader;
10use \Bitrix\Main\Localization\Loc;
11use \Bitrix\Main\ORM\Data\AddResult;
12use \Bitrix\Main\ORM\Data\UpdateResult;
13use \Bitrix\Main\EventResult;
14use \Bitrix\Main\UserConsent\Consent;
15use \Bitrix\Main\UserConsent\Agreement;
16use \Bitrix\Main\UserConsent\Internals\AgreementTable;
26 'ga' => [
'type' =>
'analytic'],
27 'gtm' => [
'type' =>
'analytic'],
28 'ym' => [
'type' =>
'analytic'],
29 'fbp' => [
'type' =>
'analytic'],
30 'vkp' => [
'type' =>
'analytic'],
31 'yt' => [
'type' =>
'technical'],
32 'gmap' => [
'type' =>
'technical']
47 $currentLang = LANGUAGE_ID;
48 $agreementCode =
'landing_cookie_agreement';
52 'AGREEMENT_TEXT' =>
Loc::getMessage(
'LANDING_COOKIES_MAIN_AGREEMENT_TEXT'),
53 'LABEL_TEXT' =>
Loc::getMessage(
'LANDING_COOKIES_MAIN_AGREEMENT_LABEL'),
62 $res = AgreementTable::getList([
64 'ID',
'NAME',
'AGREEMENT_TEXT',
'LABEL_TEXT'
73 '=CODE' => $agreementCode,
74 '=LANGUAGE_ID' => $currentLang
77 if ($row = $res->fetch())
83 $res = AgreementTable::add([
84 'CODE' => $agreementCode,
85 'LANGUAGE_ID' => $currentLang,
86 'TYPE' => Agreement::TYPE_CUSTOM,
87 'NAME' => $fields[
'NAME'],
88 'AGREEMENT_TEXT' => $fields[
'AGREEMENT_TEXT'],
89 'LABEL_TEXT' => $fields[
'LABEL_TEXT'],
90 'IS_AGREEMENT_TEXT_HTML' =>
'Y'
92 if ($res->isSuccess())
94 $fields[
'ID'] = $res->getId();
109 if (isset(self::SYSTEM_COOKIES[$code]))
111 return self::SYSTEM_COOKIES[$code][
'type'];
125 public static function getAgreements(
int $siteId,
bool $viewMode =
false): array
136 if (Loader::includeModule(
'bitrix24'))
138 $zone = \CBitrix24::getPortalZone();
140 elseif (file_exists($_SERVER[
"DOCUMENT_ROOT"].
"/bitrix/modules/main/lang/ru")
141 && !file_exists($_SERVER[
"DOCUMENT_ROOT"].
"/bitrix/modules/main/lang/ua"))
147 foreach (self::SYSTEM_COOKIES as $code => $cookieItem)
153 if ($code ===
'fbp' && $zone ===
'ru')
157 $codeUp = strtoupper($code);
158 $agreements[$code] = [
161 'TYPE' => $cookieItem[
'type'],
164 'TITLE' =>
Loc::getMessage(
'LANDING_COOKIES_SYS_' . $codeUp .
'_TITLE'),
165 '~TITLE' => $viewMode ?
'' :
Loc::getMessage(
'LANDING_COOKIES_SYS_' . $codeUp .
'_TITLE'),
166 'CONTENT' =>
Loc::getMessage(
'LANDING_COOKIES_SYS_' . $codeUp .
'_TEXT'),
167 '~CONTENT' => $viewMode ?
'' :
Loc::getMessage(
'LANDING_COOKIES_SYS_' . $codeUp .
'_TEXT')
177 $res = CookiesAgreement::getList([
179 'ID',
'ACTIVE',
'CODE',
'TITLE',
'CONTENT'
185 while ($row = $res->fetch())
187 if (isset($agreements[$row[
'CODE']]))
191 unset($row[
'TITLE']);
193 $agreements[$row[
'CODE']] = array_merge(
194 $agreements[$row[
'CODE']],
200 $row[
'SYSTEM'] =
'N';
202 $row[
'~TITLE'] = $viewMode ?
'' : $row[
'TITLE'];
203 $row[
'~CONTENT'] = $viewMode ?
'' : $row[
'CONTENT'];
204 $agreements[$row[
'CODE']] = $row;
210 $agreements = array_map(
function($item)
212 $parser = new \CTextParser;
213 $item[
'CONTENT'] = $parser->convertText($item[
'CONTENT']);
214 $item[
'TITLE'] = \htmlspecialcharsbx($item[
'TITLE']);
230 return CookiesAgreement::add([
231 'SITE_ID' => $siteId,
232 'CODE' => $fields[
'CODE'] ??
null,
233 'ACTIVE' => $fields[
'ACTIVE'] ??
'Y',
234 'TITLE' => $fields[
'TITLE'] ??
null,
235 'CONTENT' => $fields[
'CONTENT'] ??
null
247 return CookiesAgreement::update($agreementId, $fields);
263 $filter[
'=CODE'] = $code;
265 $res = CookiesAgreement::getList([
271 while ($row = $res->fetch())
273 CookiesAgreement::delete($row[
'ID'])->isSuccess();
285 $agreementId = \Bitrix\Landing\Hook\Page\Cookies::getAgreementIdBySiteId($siteId);
298 foreach ($accepted as $key)
311 self::USER_CONSENT_CODE,
315 'ITEMS' => $consentItems
334 $res = HookDataTable::getList([
339 '=HOOK' =>
'HEADBLOCK',
341 '=ENTITY_ID' => $siteId,
344 'VALUE' =>
'%<script%'
353 $res = HookDataTable::getList([
358 '=HOOK' =>
'HEADBLOCK',
361 '=LANDING.SITE_ID' => $siteId,
363 'VALUE' =>
'%<script%'
368 '\Bitrix\Landing\Internals\LandingTable',
369 [
'=this.ENTITY_ID' =>
'ref.ID']
379 $res = BlockTable::getList([
387 '=LANDING.SITE_ID' => $siteId,
388 'CONTENT' =>
'%<script%'
393 '\Bitrix\Landing\Internals\LandingTable',
394 [
'=this.LID' =>
'ref.ID']
418 'DATA' =>
function ($id =
null) use(&$currentSite)
428 if (!isset($sites[$id]))
430 $sites[$id] = Site::getList([
436 '=DELETED' => [
'Y',
'N']
445 $currentSite = $sites[$id];
453 'NAME' => $sites[$id][
'TITLE'],
454 'URL' => $sites[$id][
'URL']
457 'ITEMS' =>
function ($code =
null) use(&$currentSite)
465 return $currentSite[
'AGREEMENTS'][$code][
'TITLE'] ?? $code;
470 return new EventResult(EventResult::SUCCESS, $parameters,
'landing');
const ENTITY_TYPE_LANDING
static availableOnlyForZone(string $zone)
static getMainAgreement(?int $agreementId=null)
static removeAgreementsForSite(int $siteId, ?string $code=null)
static getAgreements(int $siteId, bool $viewMode=false)
static addAgreementForSite(int $siteId, array $fields)
static onUserConsentProviderList()
static getCookieType(string $code)
static isSiteIncludesScript(int $siteId)
static updateAgreementForSite(int $agreementId, array $fields)
static acceptAgreement(int $siteId, array $accepted=[])
static getPublicUrl($id, bool $full=true, bool $hostInclude=true, bool $previewForNotActive=false)
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static addByContext($agreementId, $originatorId=null, $originId=null, array $params=array())