• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/connector/disk.php
  • Класс: BitrixLandingConnectorDisk
  • Вызов: Disk::sanitizeContent
static function sanitizeContent(string $content, ?string $oldContent = null, bool &$replaced = false): string
{
	if (!BitrixMainLoader::includeModule('disk'))
	{
		return $content;
	}

	$existsFiles = [];

	if ($oldContent)
	{
		if (preg_match_all('/' . self::FILE_MASK_HREF . '/i', $oldContent, $matches))
		{
			foreach ($matches[2] as $objectId)
			{
				$existsFiles[] = $objectId;
			}
		}
	}

	if (preg_match_all('/' . self::FILE_MASK_HREF . '/i', $content, $matches))
	{
		foreach ($matches[2] as $i => $objectId)
		{
			if ($oldContent && in_array($objectId, $existsFiles))
			{
				continue;
			}

			$file = BitrixDiskBaseObject::loadById($objectId);
			if ($file)
			{
				$securityContext = $file->getStorage()->getCurrentUserSecurityContext();
				if ($file->canRead($securityContext))
				{
					continue;
				}
			}

			$replaced = true;
			$content = str_replace($matches[0][$i], '""', $content);
		}
	}

	return $content;
}