1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
consentbuildermail.php
См. документацию.
1<?php
2
4
14
16{
17 const CODE = iBase::CODE_MAIL;
18 const REQUIRED_FIELDS = ['RECIPIENT_ID', 'CONTACT_ID', 'CONTACT_CODE', 'SITE_ID'];
19 const CONSENT_EVENT = "SENDER_CONSENT";
20 protected const APPLY = 1;
21 protected const REJECT = 2;
22 protected const URI = "/pub/mail/consent.php";
23
24 protected static function getFilter(): \Closure
25 {
26 return function ($item, $key)
27 {
28 return isset($item, $key) && in_array($key, static::REQUIRED_FIELDS);
29 };
30 }
31
32 protected static function filterFields(array $fieldForConsent): array
33 {
34 return array_filter($fieldForConsent, static::getFilter(), ARRAY_FILTER_USE_BOTH);
35 }
36
37 protected static function checkRequireFields($fields): bool
38 {
39 foreach (static::REQUIRED_FIELDS as $field)
40 {
41 if (!array_key_exists($field, $fields))
42 {
43 return false;
44 }
45 }
46 return true;
47 }
48
52 public function buildMessage(): array
53 {
54 ['CONTACT_CODE' => $code, 'SITE_ID' => $siteId] = $this->fields;
57 return [
58 "EVENT_NAME" => static::CONSENT_EVENT,
59 "C_FIELDS" => [
60 "EMAIL" => $code,
61 "SENDER_CONSENT_APPLY" => $this->buildLinkApply(),
62 "SENDER_CONSENT_REJECT" => $this->buildLinkReject(),
63 ],
64 "LID" => is_array($siteId) ? implode(",", $siteId) : $siteId,
65 ];
66 }
67
68 protected function buildLinkApply(): string
69 {
70 return static::buildLink([
71 'CODE' => $this->fields['CONTACT_CODE'] ?? '',
72 'CONTACT' => $this->fields['CONTACT_ID'] ?? '',
73 'RECIPIENT' => $this->fields['RECIPIENT_ID'] ?? '',
74 'POSTING' => $this->fields['POSTING_ID'] ?? '',
75 'CONSENT' => $this->fields['CONSENT_ID'] ?? '',
76 ], $this->fields['SITE_ID'] ?? '', static::APPLY);
77 }
78
79 protected function buildLinkReject(): string
80 {
81 return static::buildLink([
82 'CODE' => $this->fields['CONTACT_CODE'] ?? '',
83 'CONTACT' => $this->fields['CONTACT_ID'] ?? '',
84 'RECIPIENT' => $this->fields['RECIPIENT_ID'] ?? '',
85 'POSTING' => $this->fields['POSTING_ID'] ?? '',
86 'CONSENT' => $this->fields['CONSENT_ID'] ?? '',
87 ], $this->fields['SITE_ID'], static::REJECT);
88 }
89
90 protected static function buildQuery(array $fields): string
91 {
92 return http_build_query($fields);
93 }
94
95 protected static function buildLink($fields, $siteId, $type): string
96 {
97 $tag = Consent::encodeTag($fields);
98 $dir = static::getLink($siteId);
99 switch ($type)
100 {
101 case static::APPLY:
102 $result = $dir . '?' . static::buildQuery(['consent' => 'apply', 'type' => static::CODE, 'tag' => $tag]);
103 break;
104 case static::REJECT:
105 $result = $dir . '?' . static::buildQuery(['consent' => 'reject', 'type' => static::CODE, 'tag' => $tag]);
106 break;
107 default:
108 throw new \InvalidArgumentException("Type is out of range");
109 }
110 return $result;
111 }
112
113 protected static function checkUri($siteId): bool
114 {
115 return $siteId && File::isFileExists(SiteTable::getDocumentRoot($siteId) . DIRECTORY_SEPARATOR . static::URI);
116 }
117
118 protected static function getLink($siteId): ?string
119 {
120 $uri = null;
121 if (static::checkUri($siteId))
122 {
123 $uri = Service::replaceTrackingDomainIfNeed(static::URI);
124 }
125 return $uri;
126 }
127}
$type
Определения options.php:106
Определения site.php:31
static normalize($code, $typeId=Type::EMAIL)
Определения normalizer.php:28
static detect($recipientCode, $isNormalized=false)
Определения type.php:39
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
$siteId
Определения ajax.php:8
Определения Image.php:9
Определения agent.php:8
$dir
Определения quickway.php:303
if(empty($signedUserToken)) $key
Определения quickway.php:257