1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
styleinliner.php
См. документацию.
1<?php
2namespace Bitrix\Main\Web\DOM;
3
5{
11 public static function inlineDocument(Document $document, array $styleList = null)
12 {
13 if(!$styleList)
14 {
15 $styleList = CssParser::parseDocument($document, true);
16 }
17
18 foreach($styleList as $rule)
19 {
20 $nodeList = $document->querySelectorAll($rule['SELECTOR']);
21 foreach($nodeList as $node)
22 {
23 static::setStyle($node, $rule['STYLE'], true);
24 }
25 }
26 }
27
28 public static function inlineHtml($html, array $styleList = null)
29 {
30 $document = new Document;
31 $document->loadHTML($html);
32
33 static::inlineDocument($document, $styleList);
34
35 return $document->saveHTML();
36 }
37
38 /*
39 * @param Element $node
40 * @param bool $singleStyle
41 * @return array
42 */
43 public static function getStyle(Element $node, $singleStyle = true)
44 {
45 $styleList = array();
46 $style = $node->getAttribute("style");
47 if($style)
48 {
49 $styleList = CssParser::getDeclarationArray($style, $singleStyle);
50 }
51
52 return $styleList;
53 }
54
55 /*
56 * @param Element $node
57 * @param array $styleList
58 * @param bool $append
59 * @return void
60 */
61 public static function setStyle(Element $node, $styleList, $append = false)
62 {
63 if($append)
64 {
65 if(empty($styleList))
66 {
67 return;
68 }
69
70 $result = static::getStyle($node);
71 foreach($styleList as $k => $v)
72 {
73 if("!important" !== mb_substr(mb_strtolower($styleList[$k]), -10))
74 {
75 if(array_key_exists($k, $result))
76 {
77 continue;
78 }
79 }
80
81 $result[$k] = $v;
82 }
83 }
84 else
85 {
86 $result = $styleList;
87 }
88
90 }
91}
static getDeclarationString($declarationList)
Определения cssparser.php:139
static getDeclarationArray($declarationBlock, $singleStyle=true)
Определения cssparser.php:91
static parseDocument(Document $document, $sort=false)
Определения cssparser.php:8
loadHTML($source)
Определения document.php:31
setAttribute($name, $value)
Определения element.php:202
getAttribute($name)
Определения element.php:238
querySelectorAll($queryString)
Определения node.php:395
static inlineDocument(Document $document, array $styleList=null)
Определения styleinliner.php:11
static setStyle(Element $node, $styleList, $append=false)
Определения styleinliner.php:61
static inlineHtml($html, array $styleList=null)
Определения styleinliner.php:28
static getStyle(Element $node, $singleStyle=true)
Определения styleinliner.php:43
</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
$k
Определения template_pdf.php:567