Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
cookies.php
1
<?php
2
namespace
Bitrix\Landing\Hook\Page
;
3
4
use \Bitrix\Landing\Help;
5
use \Bitrix\Landing\Rights;
6
use \Bitrix\Landing\Site;
7
use \Bitrix\Landing\Field;
8
use \Bitrix\Landing\Manager;
9
use \Bitrix\Main\Localization\Loc;
10
11
class
Cookies
extends
\Bitrix\Landing\Hook\Page
12
{
16
const
MODE_A
=
'A'
;
17
const
MODE_I
=
'I'
;
18
23
public
static
$enabled
=
false
;
24
29
protected
function
getMap
(): array
30
{
31
$helpUrl =
Help::getHelpUrl
(
'COOKIES_EDIT'
);
32
33
return
[
34
'USE'
=>
new
Field\Checkbox
(
'USE'
, [
35
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_COOKIES_USE'
)
36
]),
37
'AGREEMENT_ID'
=>
new
Field\Checkbox
(
'AGREEMENT_ID'
, [
38
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_COOKIES_AGREEMENT_ID'
)
39
]),
40
'COLOR_BG'
=>
new
Field\Text
(
'COLOR_BG'
, [
41
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_COOKIES_COLOR_BG'
),
42
'default'
=>
'#03c1fe'
43
]),
44
'COLOR_TEXT'
=>
new
Field\Text
(
'COLOR_TEXT'
, [
45
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_COOKIES_COLOR_TEXT'
),
46
'default'
=>
'#fff'
47
]),
48
'POSITION'
=>
new
Field\Select
(
'POSITION'
, [
49
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_COOKIES_POSITION'
),
50
'default'
=>
'bottom_left'
,
51
'options'
=> [
52
'bottom_left'
=>
Loc::getMessage
(
'LANDING_HOOK_COOKIES_POSITION_BL'
),
53
'bottom_right'
=>
Loc::getMessage
(
'LANDING_HOOK_COOKIES_POSITION_BR'
),
54
]
55
]),
56
'MODE'
=>
new
Field\Select
(
'MODE'
, [
57
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_COOKIES_MODE'
),
58
'default'
=>
'A'
,
59
'options'
=> [
60
self::MODE_A =>
Loc::getMessage
(
'LANDING_HOOK_COOKIES_MODE_A'
),
61
self::MODE_I =>
Loc::getMessage
(
'LANDING_HOOK_COOKIES_MODE_I'
),
62
],
63
'help'
=> $helpUrl
64
?
'<a href="'
. $helpUrl .
'" target="_blank">'
.
65
Loc::getMessage
(
'LANDING_HOOK_COOKIES_MODE_HELP'
) .
66
'</a>'
67
:
''
68
])
69
];
70
}
71
76
public
function
getTitle
(): string
77
{
78
return
Loc::getMessage
(
'LANDING_HOOK_COOKIES_TITLE'
);
79
}
80
85
public
function
enabledInEditMode
(): bool
86
{
87
return
false
;
88
}
89
94
public
function
getSort
()
95
{
96
return
50;
97
}
98
103
public
function
enabled
(): bool
104
{
105
// this hook are enabled always
106
return
!$this->
isPage
();
107
}
108
113
public
function
isInformationMode
(): bool
114
{
115
$mode = $this->fields[
'MODE'
]->getValue();
116
return
$mode == self::MODE_I || (!$mode &&
Manager::availableOnlyForZone
(
'ru'
));
117
}
118
123
public
function
exec
(): void
124
{
125
if
($this->
execCustom
())
126
{
127
return
;
128
}
129
130
if
($this->fields[
'USE'
]->getValue() ==
'Y'
)
131
{
132
$infoMode = $this->
isInformationMode
();
133
134
if
(!$infoMode)
135
{
136
self::$enabled =
true
;
137
Manager::clearPageView
(
'Noscript'
);
138
}
139
140
ob_start();
141
Manager::getApplication
()->includeComponent(
142
'bitrix:landing.cookies'
,
143
''
,
144
[
145
'USE'
=> $this->fields[
'USE'
]->getValue(),
146
'POSITION'
=> $this->fields[
'POSITION'
]->getValue(),
147
'COLOR_BG'
=> $this->fields[
'COLOR_BG'
]->getValue(),
148
'COLOR_TEXT'
=> $this->fields[
'COLOR_TEXT'
]->getValue(),
149
'AGREEMENT_ID'
=> $this->fields[
'AGREEMENT_ID'
]->getValue(),
150
'INFORMATION'
=> $infoMode ?
'Y'
:
'N'
151
],
152
false
153
);
154
$hookContent = ob_get_contents();
155
ob_end_clean();
156
157
echo $hookContent;
158
}
159
}
160
167
public
static
function
addCookieScript
(
string
$cookieCode,
string
$functionBody): void
168
{
169
if
(self::$enabled)
170
{
171
Manager::setPageView
(
'AfterHeadOpen'
,
172
'<script data-skip-moving="true">
173
window["bxCookies"] = window["bxCookies"] || {};
174
window["bxCookies"]["'
. $cookieCode .
'"] = false;
175
window.addEventListener("load", function() {
176
BX.addCustomEvent(
177
"BX.Landing.Cookies:onAccept",
178
function(acceptedCookies)
179
{
180
if (
181
!window["bxCookies"]["'
. $cookieCode .
'"] &&
182
BX.util.in_array("'
. $cookieCode .
'", acceptedCookies)
183
)
184
{
185
window["bxCookies"]["'
. $cookieCode .
'"] = true;
186
'
. $functionBody .
'
187
}
188
}
189
);
190
});
191
</script>'
192
);
193
}
194
else
195
{
196
Manager::setPageView
(
'AfterHeadOpen'
,
197
'<script data-skip-moving="true">
198
'
. $functionBody .
'
199
</script>'
200
);
201
}
202
}
203
209
public
static
function
getAgreementIdBySiteId
(
int
$siteId): ?int
210
{
211
Rights::setOff
();
212
$fields
=
Site::getAdditionalFields
($siteId);
213
Rights::setOn
();
214
215
$mode =
$fields
[
'COOKIES_MODE'
]->getValue();
216
$informationMode = $mode == self::MODE_I || (!$mode &&
Manager::availableOnlyForZone
(
'ru'
));
217
218
if
($informationMode)
219
{
220
return
null
;
221
}
222
223
return
isset(
$fields
[
'COOKIES_AGREEMENT_ID'
])
224
?
$fields
[
'COOKIES_AGREEMENT_ID'
]->getValue()
225
:
null
;
226
}
227
}
Bitrix\Landing\Controller\Cookies
Definition
cookies.php:7
Bitrix\Landing\Field\Checkbox
Definition
checkbox.php:5
Bitrix\Landing\Field\Select
Definition
select.php:9
Bitrix\Landing\Field\Text
Definition
text.php:5
Bitrix\Landing\Help\getHelpUrl
static getHelpUrl(string $code)
Definition
help.php:268
Bitrix\Landing\Hook\Page\Cookies\getAgreementIdBySiteId
static getAgreementIdBySiteId(int $siteId)
Definition
cookies.php:209
Bitrix\Landing\Hook\Page\Cookies\MODE_A
const MODE_A
Definition
cookies.php:16
Bitrix\Landing\Hook\Page\Cookies\MODE_I
const MODE_I
Definition
cookies.php:17
Bitrix\Landing\Hook\Page\Cookies\isInformationMode
isInformationMode()
Definition
cookies.php:113
Bitrix\Landing\Hook\Page\Cookies\getMap
getMap()
Definition
cookies.php:29
Bitrix\Landing\Hook\Page\Cookies\$enabled
static $enabled
Definition
cookies.php:23
Bitrix\Landing\Hook\Page\Cookies\getTitle
getTitle()
Definition
cookies.php:76
Bitrix\Landing\Hook\Page\Cookies\getSort
getSort()
Definition
cookies.php:94
Bitrix\Landing\Hook\Page\Cookies\enabledInEditMode
enabledInEditMode()
Definition
cookies.php:85
Bitrix\Landing\Hook\Page\Cookies\enabled
enabled()
Definition
cookies.php:103
Bitrix\Landing\Hook\Page\Cookies\addCookieScript
static addCookieScript(string $cookieCode, string $functionBody)
Definition
cookies.php:167
Bitrix\Landing\Hook\Page\Cookies\exec
exec()
Definition
cookies.php:123
Bitrix\Landing\Hook\Page
Definition
page.php:7
Bitrix\Landing\Hook\Page\isPage
isPage()
Definition
page.php:66
Bitrix\Landing\Hook\Page\$fields
$fields
Definition
page.php:18
Bitrix\Landing\Hook\Page\execCustom
execCustom()
Definition
page.php:262
Bitrix\Landing\Manager\getApplication
static getApplication()
Definition
manager.php:71
Bitrix\Landing\Manager\availableOnlyForZone
static availableOnlyForZone(string $zone)
Definition
manager.php:975
Bitrix\Landing\Manager\setPageView
static setPageView(string $marker, string $content, bool $skipTrim=false)
Definition
manager.php:465
Bitrix\Landing\Manager\clearPageView
static clearPageView($marker)
Definition
manager.php:488
Bitrix\Landing\Rights\setOff
static setOff()
Definition
rights.php:87
Bitrix\Landing\Rights\setOn
static setOn()
Definition
rights.php:96
Bitrix\Landing\Site\getAdditionalFields
static getAdditionalFields($id)
Definition
site.php:250
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Landing\Hook\Page
Definition
b24button.php:2
modules
landing
lib
hook
page
cookies.php
Создано системой
1.10.0