Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
background.php
1<?php
3
9use Bitrix\Main\Page\Asset;
10
11Loc::loadMessages(__FILE__);
12
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 {
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}
static getFilePath($fileId)
Definition file.php:600
static setBackground(?string $picture, ?string $color=null, ?string $position=null)
static getUrlFromFile($file)
Definition manager.php:1067
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29