Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
background.php
1
<?php
2
namespace
Bitrix\Landing\Hook\Page
;
3
4
use
Bitrix\Landing\Field
;
5
use
Bitrix\Landing\File
;
6
use
Bitrix\Landing\Manager
;
7
use
Bitrix\Landing\PublicAction
;
8
use
Bitrix\Main\Localization\Loc
;
9
use Bitrix\Main\Page\Asset;
10
11
Loc::loadMessages
(__FILE__);
12
13
class
Background
extends
\Bitrix\Landing\Hook\Page
14
{
19
protected
function
getMap
()
20
{
21
return
array(
22
'USE'
=>
new
Field
\
Checkbox
(
'USE'
, array(
23
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_BG_USE'
),
24
'help'
=>
Loc::getMessage
(
'LANDING_HOOK_BG_DESCRIPTION'
),
25
)),
26
'PICTURE'
=>
new
Field
\
Hidden
(
'PICTURE'
, array(
27
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_BG_PICTURE'
),
28
'fetch_data_modification'
=>
function
($value)
29
{
30
if
(
PublicAction::restApplication
())
31
{
32
if
($value > 0)
33
{
34
$path =
File::getFilePath
($value);
35
if
($path)
36
{
37
$path =
Manager::getUrlFromFile
($path);
38
return
$path;
39
}
40
}
41
}
42
return
$value;
43
}
44
)),
45
'POSITION'
=>
new
Field\Select
(
'POSITION'
, array(
46
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_BG_POSITION'
),
47
'help'
=>
Loc::getMessage
(
'LANDING_HOOK_BG_POSITION_HELP_3'
),
48
'htmlHelp'
=>
true
,
49
'options'
=> array(
50
'center'
=>
Loc::getMessage
(
'LANDING_HOOK_BG_POSITION_CENTER_2'
),
51
'repeat'
=>
Loc::getMessage
(
'LANDING_HOOK_BG_POSITION_REPEAT_2'
),
52
'center_repeat_y'
=>
Loc::getMessage
(
'LANDING_HOOK_BG_POSITION_CENTER_REPEAT_Y'
),
53
'no_repeat'
=>
Loc::getMessage
(
'LANDING_HOOK_BG_POSITION_CENTER_NO_REPEAT'
),
54
)
55
)),
56
'COLOR'
=>
new
Field\Text
(
'COLOR'
, array(
57
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_BG_COLOR'
)
58
)),
59
);
60
}
61
66
public
function
getTitle
()
67
{
68
return
Loc::getMessage
(
'LANDING_HOOK_BG_NAME'
);
69
}
70
75
public
function
getDescription
(): string
76
{
77
return
Loc::getMessage
(
'LANDING_HOOK_BG_DESCRIPTION'
);
78
}
79
84
public
function
enabled
()
85
{
86
if
($this->
issetCustomExec
())
87
{
88
return
true
;
89
}
90
91
return
$this->fields[
'USE'
]->getValue() ==
'Y'
;
92
}
93
98
public
function
exec
()
99
{
100
if
($this->
execCustom
())
101
{
102
return
;
103
}
104
105
$picture = \htmlspecialcharsbx(trim($this->fields[
'PICTURE'
]->getValue()));
106
$color = \htmlspecialcharsbx(trim($this->fields[
'COLOR'
]->getValue()));
107
$position = trim($this->fields[
'POSITION'
]->getValue());
108
109
$this->
setBackground
($picture, $color, $position);
110
}
111
119
public
static
function
setBackground
(?
string
$picture, ?
string
$color =
null
, ?
string
$position =
null
): void
120
{
127
if
($picture && is_numeric($picture) && (
int
)$picture > 0)
128
{
129
$picture = \htmlspecialcharsbx(
130
File::getFilePath
((
int
)$picture)
131
);
132
}
133
134
if
($picture)
135
{
136
if
($position ===
'center'
)
137
{
138
Asset::getInstance()->addString(
139
'<style type="text/css">
140
body {
141
background-image: url("'
. $picture .
'");
142
background-attachment: fixed;
143
background-size: cover;
144
background-position: center;
145
background-repeat: no-repeat;
146
}
147
.bx-ios.bx-touch body:before {
148
content: "";
149
background-image: url("'
. $picture .
'");
150
background-position: center;
151
background-size: cover;
152
position: fixed;
153
left: 0;
154
right: 0;
155
top: 0;
156
bottom: 0;
157
z-index: -1;
158
}
159
.bx-ios.bx-touch body {
160
background-image: none;
161
}
162
</style>'
163
);
164
}
165
elseif ($position ===
'repeat'
)
166
{
167
Asset::getInstance()->addString(
168
'<style type="text/css">
169
body {
170
background-image: url("'
. $picture .
'");
171
background-attachment: fixed;
172
background-position: center;
173
background-repeat: repeat;
174
}
175
</style>'
176
);
177
}
178
elseif ($position ===
'no_repeat'
)
179
{
180
Asset::getInstance()->addString(
181
'<style type="text/css">
182
body {
183
background-image: url("'
. $picture .
'");
184
background-size: 100%;
185
background-attachment: fixed;
186
background-position: top center;
187
background-repeat: no-repeat;
188
}
189
</style>'
190
);
191
}
192
else
193
{
194
Asset::getInstance()->addString(
195
'<style type="text/css">
196
body {
197
background-image: url("'
. $picture .
'");
198
background-attachment: scroll;
199
background-position: top;
200
background-repeat: repeat-y;
201
background-size: 100%;
202
}
203
</style>'
204
);
205
}
206
}
207
208
if
($color)
209
{
210
Asset::getInstance()->addString(
211
'<style type="text/css">
212
body {
213
background-color: '
. $color .
'!important;
214
}
215
</style>'
216
);
217
}
218
}
219
}
Bitrix\Landing\Assets\Manager
Definition
manager.php:20
Bitrix\Landing\Field\Checkbox
Definition
checkbox.php:5
Bitrix\Landing\Field\Hidden
Definition
hidden.php:5
Bitrix\Landing\Field\Select
Definition
select.php:9
Bitrix\Landing\Field\Text
Definition
text.php:5
Bitrix\Landing\Field
Definition
field.php:5
Bitrix\Landing\File
Definition
file.php:7
Bitrix\Landing\File\getFilePath
static getFilePath($fileId)
Definition
file.php:600
Bitrix\Landing\Hook\Page\Background
Definition
background.php:14
Bitrix\Landing\Hook\Page\Background\getDescription
getDescription()
Definition
background.php:75
Bitrix\Landing\Hook\Page\Background\setBackground
static setBackground(?string $picture, ?string $color=null, ?string $position=null)
Definition
background.php:119
Bitrix\Landing\Hook\Page\Background\getMap
getMap()
Definition
background.php:19
Bitrix\Landing\Hook\Page\Background\getTitle
getTitle()
Definition
background.php:66
Bitrix\Landing\Hook\Page\Background\enabled
enabled()
Definition
background.php:84
Bitrix\Landing\Hook\Page\Background\exec
exec()
Definition
background.php:98
Bitrix\Landing\Hook\Page
Definition
page.php:7
Bitrix\Landing\Hook\Page\issetCustomExec
issetCustomExec()
Definition
page.php:253
Bitrix\Landing\Hook\Page\execCustom
execCustom()
Definition
page.php:262
Bitrix\Landing\Manager\getUrlFromFile
static getUrlFromFile($file)
Definition
manager.php:1067
Bitrix\Landing\PublicAction\restApplication
static restApplication()
Definition
publicaction.php:540
Bitrix\Main\Localization\Loc
Definition
loc.php:11
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\Field
Definition
checkbox.php:2
Bitrix\Landing\Hook\Page
Definition
b24button.php:2
Bitrix\Landing\PublicAction
Definition
block.php:2
modules
landing
lib
hook
page
background.php
Создано системой
1.10.0