31 $doc = $block->getDom();
32 $resultList = $doc->querySelectorAll($selector);
33 $valueBefore = static::getNode($block, $selector);
36 foreach ($data as $pos => $value)
39 $src = (isset($value[
'src']) && is_string($value[
'src'])) ? trim($value[
'src']) :
'';
40 $src2x = (isset($value[
'src2x']) && is_string($value[
'src2x'])) ? trim($value[
'src2x']) :
'';
41 $alt = (isset($value[
'alt']) && is_string($value[
'alt'])) ? trim($value[
'alt']) :
'';
42 $id = isset($value[
'id']) ? intval($value[
'id']) : 0;
43 $id2x = isset($value[
'id2x']) ? intval($value[
'id2x']) : 0;
44 $isLazy = isset($value[
'isLazy']) && $value[
'isLazy'] ===
'Y';
48 $src = str_replace(
'http://',
'https://', $src);
52 $src2x = str_replace(
'http://',
'https://', $src2x);
55 if (isset($value[
'url']))
57 $url = is_array($value[
'url'])
58 ? json_encode($value[
'url'])
66 if (isset($resultList[$pos]))
75 if (!in_array($id, $files))
79 if (!in_array($id2x, $files))
85 if ($resultList[$pos]->getTagName() !==
'IMG')
87 $styles = StyleInliner::getStyle($resultList[$pos]);
91 foreach ($styles as $key => $styleValue)
93 if ($key !==
'background' && $key !==
'background-image')
95 $oldStyles[] =
"{$key}: {$styleValue};";
103 "background-image: url('{$src}');",
107 $newStyles = array_merge(
110 "background-image: -webkit-image-set(url('{$src}') 1x, url('{$src2x}') 2x);",
111 "background-image: image-set(url('{$src}') 1x, url('{$src2x}') 2x);",
119 foreach ([
'fileid',
'fileid2x'] as $dataCode)
121 $oldId = $resultList[$pos]->getAttribute(
134 $style = array_merge($oldStyles, $newStyles);
135 $style = implode(
' ', $style);
136 $resultList[$pos]->setAttribute(
'style', $style);
141 $resultList[$pos]->setAttribute(
'data-lazy-bg',
'Y');
142 $lazyOrigSrc = ($value[
'lazyOrigSrc'] ??
null);
145 $resultList[$pos]->setAttribute(
'data-src', $lazyOrigSrc);
147 $lazyOrigSrc2x = ($value[
'lazyOrigSrc2x'] ??
null);
150 $resultList[$pos]->setAttribute(
'data-src2x', $lazyOrigSrc2x);
152 $lazyOrigStyle = ($value[
'lazyOrigStyle'] ??
null);
155 $resultList[$pos]->setAttribute(
'data-style', $lazyOrigStyle);
161 $resultList[$pos]->setAttribute(
'alt', $alt);
162 $resultList[$pos]->setAttribute(
'src', $src);
165 $resultList[$pos]->setAttribute(
'srcset',
"{$src2x} 2x");
169 $resultList[$pos]->setAttribute(
'srcset',
'');
175 $resultList[$pos]->setAttribute(
'data-lazy-img',
'Y');
176 $resultList[$pos]->setAttribute(
'loading',
'lazy');
177 if ($lazyOrigSrc = $value[
'lazyOrigSrc'])
179 $resultList[$pos]->setAttribute(
'data-src', $lazyOrigSrc);
181 if ($lazyOrigSrcset = $value[
'lazyOrigSrcset'])
183 $resultList[$pos]->setAttribute(
'data-srcset', $lazyOrigSrcset);
188 ? $resultList[$pos]->setAttribute(
'data-fileid', $id)
189 : $resultList[$pos]->removeAttribute(
'data-fileid')
192 ? $resultList[$pos]->setAttribute(
'data-fileid2x', $id2x)
193 : $resultList[$pos]->removeAttribute(
'data-fileid2x')
196 ? $resultList[$pos]->setAttribute(
'data-pseudo-url', $url)
197 : $resultList[$pos]->removeAttribute(
'data-pseudo-url')
203 $history->push(
'EDIT_IMG', [
205 'selector' => $selector,
206 'position' => (
int)$pos,
207 'valueBefore' => $valueBefore[$pos],
208 'valueAfter' => $value,
224 $doc = $block->getDom();
225 $resultList = $doc->querySelectorAll($selector);
228 $resultList = Node\Style::getNodesBySelector($block, $selector);
231 foreach ($resultList as $pos => $res)
242 if ($res->getTagName() !==
'IMG')
244 $styles = StyleInliner::getStyle($res);
245 if (isset($styles[
'background-image']))
247 $src = $src2x =
null;
251 '/url\(\'*([^\']+)\'*\)\s*([\d]*x*)/is',
252 $styles[
'background-image'],
257 for ($i = 0, $c = count($matches[1]); $i < $c; $i++)
259 if ($matches[2][$i] ===
'2x')
261 $src2x = $matches[1][$i];
265 $src = $matches[1][$i];
283 ($isLazy = $res->getAttribute(
'data-lazy-bg'))
287 $data[$pos][
'isLazy'] =
'Y';
288 if ($lazyOrigSrc = $res->getAttribute(
'data-src'))
290 $data[$pos][
'lazyOrigSrc'] = $lazyOrigSrc;
292 if ($lazyOrigSrc2x = $res->getAttribute(
'data-src2x'))
294 $data[$pos][
'lazyOrigSrc2x'] = $lazyOrigSrc2x;
296 if ($lazyOrigStyle = $res->getAttribute(
'data-style'))
298 $data[$pos][
'lazyOrigStyle'] = $lazyOrigStyle;
305 $src = $res->getAttribute(
'src');
306 $srcSet = $res->getAttribute(
'srcset');
309 $data[$pos][
'alt'] = $res->getAttribute(
'alt');
311 if (preg_match(
'/[\,\s]*(.*?)\s+2x/is', $srcSet, $matches))
317 $isLazy = $res->getAttribute(
'data-lazy-img');
320 $data[$pos][
'isLazy'] =
'Y';
321 $lazyOrigSrc = $res->getAttribute(
'data-src');
324 $data[$pos][
'lazyOrigSrc'] = $lazyOrigSrc;
326 $lazyOrigSrcset = $res->getAttribute(
'data-srcset');
330 preg_match(
'/([^ ]+) 2x/i', $lazyOrigSrcset, $matches)
334 $data[$pos][
'lazyOrigSrc2x'] = $matches[1];
337 $data[$pos][
'lazyOrigSrcset'] = $lazyOrigSrcset;
342 if ($val = $res->getAttribute(
'data-pseudo-url'))
344 $data[$pos][
'url'] = $val;
347 if ($val = $res->getAttribute(
'data-fileid'))
349 $data[$pos][
'id'] = $val;
353 (isset($data[$pos][
'src2x']) || isset($data[$pos][
'lazyOrigSrc2x']))
354 && ($val = $res->getAttribute(
'data-fileid2x'))
357 $data[$pos][
'id2x'] = $val;