- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/update/block/duplicateimages.php
- Класс: BitrixLandingUpdateBlockDuplicateImages
- Вызов: DuplicateImages::update
public function update(bool $needSave = false): string
{
$srcForReplace = [];
if (isset($this->manifest['nodes']) && is_array($this->manifest['nodes']))
{
foreach ($this->manifest['nodes'] as $selector => $node)
{
if (in_array($node['type'], self::IMG_TYPES, true))
{
$nodeClass = NodeType::getClassName($node['type']);
$previousValues = call_user_func([$nodeClass, 'getNode'], $this->block, $selector);
foreach ($previousValues as $previousValue)
{
if (!($previousValue['id'] ?? null) && !($previousValue['id2x'] ?? null))
{
continue;
}
if (
($previousValue['id'] && !File::getFilePath($previousValue['id']))
|| ($previousValue['id2x'] && !File::getFilePath($previousValue['id2x']))
)
{
continue;
}
$hostUrl = '//' . Manager::getHttpHost();
$newSrc = File::getFilePath($previousValue['id']);
$newSrc = Manager::getUrlFromFile($newSrc);
$previousSrc =
$previousValue['isLazy'] === 'Y'
? $previousValue['lazyOrigSrc']
: $previousValue['src']
;
if ($previousSrc !== $newSrc)
{
$srcForReplace[$previousSrc] = $newSrc;
// add urls w/o host url too
if (strpos($newSrc, $hostUrl) === 0)
{
$srcForReplace[str_replace($hostUrl, '', $previousSrc)] =
str_replace($hostUrl, '', $newSrc);
}
}
if ($previousValue['id2x'])
{
$newSrc2x = File::getFilePath($previousValue['id2x']);
$newSrc2x = Manager::getUrlFromFile($newSrc2x);
$previousSrc2x =
$previousValue['isLazy'] === 'Y'
? $previousValue['lazyOrigSrc2x']
: $previousValue['src2x']
;
if ($previousSrc2x !== $newSrc2x)
{
$srcForReplace[$previousSrc2x] = $newSrc2x;
// add urls w/o host url too
if (strpos($newSrc2x, $hostUrl) === 0)
{
$srcForReplace[str_replace($hostUrl, '', $previousSrc2x)] =
str_replace($hostUrl, '', $newSrc2x);
}
}
}
}
}
}
}
if (!empty($srcForReplace))
{
$this->content = str_replace(
array_keys($srcForReplace),
array_values($srcForReplace),
$this->content
);
if ($needSave)
{
$this->block->saveContent($this->content);
$this->block->save();
}
}
return $this->content;
}