Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
speed.php
1
<?php
2
3
namespace
Bitrix\Landing\Hook\Page
;
4
5
use \Bitrix\Landing\Assets;
6
use \Bitrix\Landing\Field;
7
use \Bitrix\Landing\Help;
8
use \Bitrix\Landing\Landing;
9
use \Bitrix\Main\Localization\Loc;
10
11
Loc::loadMessages
(__FILE__);
12
13
class
Speed
extends
\Bitrix\Landing\Hook\Page
14
{
15
const
LAZYLOAD_EXTENSION_NAME
=
'landing_lazyload'
;
16
17
protected
$isNeedPublication
=
true
;
18
23
protected
function
getMap
()
24
{
25
$helpUrl =
Help::getHelpUrl
(
'SPEED'
);
26
27
return
[
28
'ASSETS'
=>
new
Field\Text
(
'ASSETS'
, []),
29
'USE_LAZY'
=>
new
Field\Checkbox
(
30
'USE_LAZY'
,
31
[
32
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_SPEED_USE_LAZY_NEW'
),
33
'help'
=> $helpUrl
34
?
'<a href="'
. $helpUrl .
'" target="_blank">'
.
35
Loc::getMessage
(
'LANDING_HOOK_SPEED_HELP'
) .
36
'</a>'
37
:
''
,
38
]
39
),
40
'USE_WEBPACK'
=>
new
Field
\
Checkbox
(
41
'USE_WEBPACK'
,
42
[
43
'title'
=> ($mess =
Loc::getMessage
(
'LANDING_HOOK_SPEED_USE_WEBPACK2'
))
44
? $mess
45
:
Loc::getMessage
(
'LANDING_HOOK_SPEED_USE_WEBPACK'
),
46
]
47
),
48
];
49
}
50
55
public
function
getTitle
()
56
{
57
return
Loc::getMessage
(
'LANDING_HOOK_SPEED_TTILE'
);
58
}
59
66
public
function
addData
($field, $data)
67
{
68
if
(!is_array($data))
69
{
70
$data = [$data];
71
}
72
if
(
73
$this->fields[$field]
74
&& ($hookData = $this->fields[$field]->getValue())
75
)
76
{
77
$mergedData = array_unique(array_merge(unserialize($hookData, [
'allowed_classes'
=>
false
]), $data));
78
}
79
else
80
{
81
$mergedData = $data;
82
}
83
84
return
serialize($mergedData);
85
}
86
91
public
function
enabled
()
92
{
93
if
($this->
issetCustomExec
())
94
{
95
return
true
;
96
}
97
98
if
($this->
isPage
())
99
{
100
return
false
;
101
}
102
103
return
true
;
104
}
105
110
public
function
exec
(): void
111
{
112
if
(Landing::getEditMode())
113
{
114
$this->
disableWebpack
();
115
}
116
else
117
{
118
$this->
execWebpack
();
119
$this->
execLazyLoad
();
120
}
121
}
122
123
protected
function
disableWebpack
(): void
124
{
125
$assets = Assets\Manager::getInstance();
126
$assets->setStandartMode();
127
}
128
129
protected
function
execWebpack
(): void
130
{
131
$assets = Assets\Manager::getInstance();
132
if
($this->fields[
'USE_WEBPACK'
]->getValue() !==
'N'
)
133
{
134
$assets->setWebpackMode();
135
}
136
else
137
{
138
$assets->setStandartMode();
139
}
140
}
141
142
protected
function
execLazyLoad
(): void
143
{
144
if
($this->fields[
'USE_LAZY'
]->getValue() !==
'N'
)
145
{
146
$assets = Assets\Manager::getInstance();
147
$assets->addAsset(self::LAZYLOAD_EXTENSION_NAME, Assets\
Location::LOCATION_BEFORE_ALL
);
148
}
149
}
150
}
Bitrix\Landing\Assets\Location\LOCATION_BEFORE_ALL
const LOCATION_BEFORE_ALL
Definition
location.php:7
Bitrix\Landing\Field\Checkbox
Definition
checkbox.php:5
Bitrix\Landing\Field\Text
Definition
text.php:5
Bitrix\Landing\Field
Definition
field.php:5
Bitrix\Landing\Help\getHelpUrl
static getHelpUrl(string $code)
Definition
help.php:268
Bitrix\Landing\Hook\Page\Speed
Definition
speed.php:14
Bitrix\Landing\Hook\Page\Speed\execLazyLoad
execLazyLoad()
Definition
speed.php:142
Bitrix\Landing\Hook\Page\Speed\disableWebpack
disableWebpack()
Definition
speed.php:123
Bitrix\Landing\Hook\Page\Speed\$isNeedPublication
$isNeedPublication
Definition
speed.php:17
Bitrix\Landing\Hook\Page\Speed\getMap
getMap()
Definition
speed.php:23
Bitrix\Landing\Hook\Page\Speed\getTitle
getTitle()
Definition
speed.php:55
Bitrix\Landing\Hook\Page\Speed\enabled
enabled()
Definition
speed.php:91
Bitrix\Landing\Hook\Page\Speed\exec
exec()
Definition
speed.php:110
Bitrix\Landing\Hook\Page\Speed\execWebpack
execWebpack()
Definition
speed.php:129
Bitrix\Landing\Hook\Page\Speed\LAZYLOAD_EXTENSION_NAME
const LAZYLOAD_EXTENSION_NAME
Definition
speed.php:15
Bitrix\Landing\Hook\Page\Speed\addData
addData($field, $data)
Definition
speed.php:66
Bitrix\Landing\Hook\Page
Definition
page.php:7
Bitrix\Landing\Hook\Page\isPage
isPage()
Definition
page.php:66
Bitrix\Landing\Hook\Page\issetCustomExec
issetCustomExec()
Definition
page.php:253
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
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
speed.php
Создано системой
1.10.0