• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/componenthelper.php
  • Класс: BitrixSocialnetworkComponentHelper
  • Вызов: ComponentHelper::convertDiskFileBBCode
static function convertDiskFileBBCode($text, $entityType, $entityId, $authorId, $attachmentList = [])
{
	$text = trim((string)$text);
	$authorId = (int)$authorId;
	$entityType = (string)$entityType;
	$entityId = (int)$entityId;

	if (
		$text === ''
		|| empty($attachmentList)
		|| $authorId <= 0
		|| $entityType === ''
		|| $entityId <= 0
	)
	{
		return $text;
	}

	if (preg_match_all('|[DISKsFILEsID=([n]*d+)]|', $text, $matches))
	{
		$attachmentUrlList = self::getAttachmentUrlList(
			$matches[1],
			$entityType,
			$entityId,
			$authorId,
			$attachmentList
		);

		foreach($matches[1] as $inlineFileId)
		{
			if (!empty($attachmentUrlList[$inlineFileId]))
			{
				$needCreatePicture = false;
				$sizeSource = $sizeDestination = [];
				CFile::scaleImage(
					$attachmentUrlList[$inlineFileId]['WIDTH'], $attachmentUrlList[$inlineFileId]['HEIGHT'],
					[ 'width' => 400, 'height' => 1000 ], BX_RESIZE_IMAGE_PROPORTIONAL,
					$needCreatePicture, $sizeSource, $sizeDestination
				);

				$replacement = (
					$attachmentUrlList[$inlineFileId]["TYPE"] === 'image'
						? '[IMG WIDTH='.(int)$sizeDestination['width'].' HEIGHT='.(int)$sizeDestination['height'].']'.htmlspecialcharsBack($attachmentUrlList[$inlineFileId]["URL"]).'[/IMG]'
						: '[MAIL DISK FILE ID='.$inlineFileId.']'
				);
				$text = preg_replace(
					'|[DISKsFILEsID='.$inlineFileId.']|',
					$replacement,
					$text
				);
			}
		}
	}

	return $text;
}