1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
displayproperties.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Web\DOM;
4
6{
7 public const DISPLAY = 'display';
8 public const FONT = 'font';
9
10 public const DISPLAY_HIDDEN = 'hidden';
11 public const DISPLAY_BLOCK = 'block';
12 public const DISPLAY_INLINE = 'inline';
13
14 public const FONT_NORMAL = 'normal';
15 public const FONT_BOLD = 'bold';
16 public const FONT_ITALIC = 'italic';
17 public const FONT_UNDERLINED = 'underlined';
18 public const FONT_DELETED = 'deleted';
19
20 protected $properties = [];
21
22 public function __construct(Node $node, array $properties = [], array $defaultProperties = [])
23 {
24 $this->properties = array_merge(
25 $this->getDefaultProperties(),
26 $defaultProperties,
27 $this->getNodeProperties($node),
29 );
30 }
31
35 public function isHidden()
36 {
37 return isset($this->properties[static::DISPLAY]) && $this->properties[static::DISPLAY] === static::DISPLAY_HIDDEN;
38 }
39
43 public function isDisplayBlock()
44 {
45 return isset($this->properties[static::DISPLAY]) && $this->properties[static::DISPLAY] === static::DISPLAY_BLOCK;
46 }
47
51 public function isDisplayInline()
52 {
53 return isset($this->properties[static::DISPLAY]) && $this->properties[static::DISPLAY] === static::DISPLAY_INLINE;
54 }
55
59 public function isFontBold()
60 {
61 return
62 isset($this->properties[static::FONT][static::FONT_BOLD])
63 && $this->properties[static::FONT][static::FONT_BOLD] === true;
64 }
65
69 public function isFontItalic()
70 {
71 return
72 isset($this->properties[static::FONT][static::FONT_ITALIC])
73 && $this->properties[static::FONT][static::FONT_ITALIC] === true;
74 }
75
79 public function isFontUnderlined()
80 {
81 return
82 isset($this->properties[static::FONT][static::FONT_UNDERLINED])
83 && $this->properties[static::FONT][static::FONT_UNDERLINED] === true;
84 }
85
89 public function isFontDeleted()
90 {
91 return
92 isset($this->properties[static::FONT][static::FONT_DELETED])
93 && $this->properties[static::FONT][static::FONT_DELETED] === true;
94 }
95
99 public function getProperties()
100 {
101 return $this->properties;
102 }
103
107 protected function getDefaultProperties()
108 {
109 return [
110 static::DISPLAY => static::DISPLAY_INLINE,
111 'font' => [],
112 ];
113 }
114
121 protected function isHiddenNode(Node $node)
122 {
123 static $hiddenNodeNames = [
124 '#comment' => true, 'STYLE' => true, 'SCRIPT' => true,
125 ];
126
127 return isset($hiddenNodeNames[$node->getNodeName()]);
128 }
129
136 protected function isBlockTag($tagName)
137 {
138 $blockTagNames = [
139 'address' => true, 'article' => true, 'aside' => true, 'blockquote' => true, 'details' => true,
140 'dialog' => true, 'dd' => true, 'div' => true, 'dl' => true, 'dt' => true, 'fieldset' => true,
141 'figcaption' => true, 'figure' => true, 'footer' => true, 'form' => true, 'h1' => true, 'h2' => true,
142 'h3' => true, 'h4' => true, 'h5' => true, 'h6' => true, 'header' => true, 'hgroup' => true, 'hr' => true,
143 'li' => true, 'main' => true, 'nav' => true, 'ol' => true, 'p' => true, 'pre' => true, 'section' => true, 'table' => true,
144 'ul' => true,
145 ];
146
147 return isset($blockTagNames[mb_strtolower($tagName)]);
148 }
149
156 protected function isBoldTag($tagName)
157 {
158 $boldTagNames = [
159 'b' => true, 'mark' => true, 'em' => true, 'strong' => true, 'h1' => true, 'h2' => true, 'h3' => true,
160 'h4' => true, 'h5' => true, 'h6' => true,
161 ];
162
163 return isset($boldTagNames[mb_strtolower($tagName)]);
164 }
165
172 protected function isItalicTag($tagName)
173 {
174 $italicTagNames = [
175 'i' => true, 'cite' => true, 'dfn' => true,
176 ];
177
178 return isset($italicTagNames[mb_strtolower($tagName)]);
179 }
180
187 protected function isUnderlinedTag($tagName)
188 {
189 return mb_strtolower($tagName) == 'u';
190 }
191
198 protected function isDeletedTag($tagName)
199 {
200 $deletedTagNames = [
201 'del' => true, 's' => true,
202 ];
203
204 return isset($deletedTagNames[mb_strtolower($tagName)]);
205 }
206
211 protected function getNodeProperties(Node $node)
212 {
213 $result = [];
214
215 if($this->isHiddenNode($node))
216 {
217 $result[static::DISPLAY] = static::DISPLAY_HIDDEN;
218
219 return $result;
220 }
221
222 if($node instanceof Element)
223 {
224 $styles = $node->getStyle();
225 $display = false;
226 $font = [];
227 if($styles)
228 {
229 $stylePairs = explode(';', $styles);
230 foreach($stylePairs as $pair)
231 {
232 [$name, $value] = explode(':', $pair);
233 if($name && $value)
234 {
235 $name = trim($name);
236 $value = trim($value);
237 if($name == static::DISPLAY)
238 {
239 if($value == 'none')
240 {
241 $display = static::DISPLAY_HIDDEN;
242 }
243 elseif($value == 'block')
244 {
245 $display = static::DISPLAY_BLOCK;
246 }
247 elseif($value == 'inline')
248 {
249 $display = static::DISPLAY_INLINE;
250 }
251 }
252 elseif($name == 'font-weight')
253 {
254 if(intval($value) > 500 || $value == 'bold')
255 {
256 $font[static::FONT_BOLD] = true;
257 }
258 elseif(intval($value) < 500 || $value == 'normal')
259 {
260 $font[static::FONT_BOLD] = false;
261 }
262 }
263 elseif($name == 'font-style')
264 {
265 if($value == 'italic' || str_starts_with($value, 'oblique'))
266 {
267 $font[static::FONT_ITALIC] = true;
268 }
269 elseif($value == 'normal')
270 {
271 $font[static::FONT_ITALIC] = false;
272 }
273 }
274 elseif($name == 'text-decoration')
275 {
276 if(str_contains($value, 'underline'))
277 {
278 $font[static::FONT_UNDERLINED] = true;
279 }
280 if(str_contains($value, 'line-through'))
281 {
282 $font[static::FONT_DELETED] = true;
283 }
284 if($value == 'none')
285 {
286 $font[static::FONT_UNDERLINED] = false;
287 $font[static::FONT_DELETED] = false;
288 }
289 }
290 }
291 }
292 }
293 if($display == static::DISPLAY_HIDDEN)
294 {
295 $result[static::DISPLAY] = $display;
296
297 return $result;
298 }
299 if(!$display && $this->isBlockTag($node->getTagName()))
300 {
301 $display = static::DISPLAY_BLOCK;
302 }
303
304 if(!isset($font[static::FONT_BOLD]) && $this->isBoldTag($node->getTagName()))
305 {
306 $font[static::FONT_BOLD] = true;
307 }
308 if(!isset($font[static::FONT_ITALIC]) && $this->isItalicTag($node->getTagName()))
309 {
310 $font[static::FONT_ITALIC] = true;
311 }
312 if(!isset($font[static::FONT_UNDERLINED]) && $this->isUnderlinedTag($node->getTagName()))
313 {
314 $font[static::FONT_UNDERLINED] = true;
315 }
316 if($this->isDeletedTag($node->getTagName()))
317 {
318 $font[static::FONT_DELETED] = true;
319 }
320
321 if($display)
322 {
323 $result[static::DISPLAY] = $display;
324 }
325 $result['font'] = $font;
326 }
327
328 return $result;
329 }
330}
__construct(Node $node, array $properties=[], array $defaultProperties=[])
Определения displayproperties.php:22
Определения node.php:5
getNodeName()
Определения node.php:107
</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
$name
Определения menu_edit.php:35
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393