• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_message_param.php
  • Класс: CIMMessageParamAttach
  • Вызов: CIMMessageParamAttach::PrepareAttach
static function PrepareAttach($attach)
{
	if (!is_array($attach))
	{
		return $attach;
	}

	$isCollection = true;
	if(BitrixMainTypeCollection::isAssociative($attach))
	{
		$isCollection = false;
		$attach = array($attach);
	}

	foreach ($attach as $attachKey => &$attachBody)
	{
		if (!is_array($attachBody))
		{
			// wrong ATTACH value like TS
			continue;
		}
		$findFirstMessage = false;
		$attachBody['DESCRIPTION'] ??= null;
		if ($attachBody['DESCRIPTION'] === self::FIRST_MESSAGE)
		{
			$attachBody['DESCRIPTION'] = '';
			$findFirstMessage = true;
		}

		if (isset($attachBody['BLOCKS']) && is_array($attachBody['BLOCKS']))
		{
			foreach ($attachBody['BLOCKS'] as &$block)
			{
				if (isset($block['HTML']))
				{
					$block['HTML'] = BitrixImText::convertHtmlToBbCode($block['HTML']);
				}
				else if (isset($block['MESSAGE']))
				{
					if ($findFirstMessage)
					{
						$attachBody['DESCRIPTION'] = $block['MESSAGE'];
						$findFirstMessage = false;
					}
				}
			}
		}
	}

	return $isCollection? $attach: $attach[0];
}