49 public static function saveNode(
Block $block, $selector, array $data): void
51 if (!self::isCorrectNodeType($block, $selector))
57 $resultList = Node\Style::getNodesBySelector($block, $selector);
60 foreach ($data as $pos => $value)
62 $id = isset($value[
'id']) ? (int)$value[
'id'] : 0;
63 $id2x = isset($value[
'id2x']) ? (int)$value[
'id2x'] : 0;
72 if (!in_array($id, $files))
76 if (!in_array($id2x, $files))
82 if (isset($resultList[$pos]))
85 if ($resultList[$pos]->getTagName() !==
'IMG')
87 $styles = DOM\StyleInliner::getStyle($resultList[$pos]);
88 if (isset($styles[
'--bg-url']))
90 $styles[
'background-image'] =
'';
92 if (!isset($styles[
'background']))
96 $stylesChanged =
false;
97 $resultList[$pos]->setAttribute(
'data-fileid', $id);
98 foreach (self::STYLES_VARIABLES_WITH_FILES[
'1x'] as $var => $pattern)
100 if (isset($styles[$var]))
102 $fileArray = \CFile::GetFileArray($id);
103 $styles[$var] = str_replace(
104 self::STYLES_URL_MARKER,
108 $stylesChanged =
true;
114 $resultList[$pos]->setAttribute(
'data-fileid2x', $id2x);
115 foreach (self::STYLES_VARIABLES_WITH_FILES[
'2x'] as $var => $pattern)
117 if (isset($styles[$var]))
119 $fileArray = \CFile::GetFileArray($id2x);
120 $styles[$var] = str_replace(
121 self::STYLES_URL_MARKER,
125 $stylesChanged =
true;
132 $classList = $resultList[$pos]->getAttribute(
'class');
133 if (!stripos($classList, self::STYLES_NODE_CLASS))
137 $resultList[$pos]->setAttribute(
'class', $classList);
138 $fileArray1x = \CFile::GetFileArray($id);
139 $src1x = $fileArray1x[
'SRC'];
140 $styles[
'--bg-url'] =
"url('{$src1x}');";
141 if ($id2x <= 0 && $id > 0)
145 $fileArray2x = \CFile::GetFileArray($id2x);
146 $src2x = $fileArray2x[
'SRC'];
147 $styles[
'--bg-url-2x'] =
"url('{$src2x}');";
148 $stylesChanged =
true;
153 DOM\StyleInliner::setStyle($resultList[$pos], $styles);
158 foreach ([
'fileid',
'fileid2x'] as $dataCode)
160 $attribute =
'data-' . $dataCode;
161 $oldId = $resultList[$pos]->getAttribute($attribute);
186 if (!self::isCorrectNodeType($block, $selector))
193 $resultList = Node\Style::getNodesBySelector($block, $selector);
195 foreach ($resultList as $pos => $res)
206 if ($res->getTagName() !==
'IMG')
209 $res->getAttribute(
'data-lazy-styleimg')
210 && $res->getAttribute(
'data-lazy-styleimg') ===
'Y'
220 if (!in_array($nodeData[
'id'], $files))
224 if ($nodeData[
'id2x'] && !in_array($nodeData[
'id'], $files))
226 unset($nodeData[
'id2x'], $nodeData[
'src2x'], $nodeData[
'lazyOrigSrc2x']);
229 $data[$pos] = $nodeData;
271 $styles = $node->getAttribute(
'data-style');
274 $stylesConverted = [];
275 foreach (explode(
';', $styles) as $style)
278 $separator = strpos( $style,
':');
279 $key = substr($style, 0, $separator);
280 $val = substr($style, $separator + 1);
281 $stylesConverted[$key] = trim($val);
284 $fileId = (int)$node->getAttribute(
'data-fileid');
287 $data = [
'isLazy' =>
'Y'];
289 $data[
'id'] = $fileId;
292 $fileId2x = (int)$node->getAttribute(
'data-fileid2x');
295 $data[
'id2x'] = $fileId2x;