• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/classes/general/task.php
  • Класс: CTasks
  • Вызов: CTasks::convertBbcode2Html
static function convertBbcode2Html($arStringsInBbcode)
{
	if (!is_array($arStringsInBbcode))
	{
		throw new TasksException();
	}

	static $delimiter = '--------This is unique BB-code strings delimiter at high confidence level (CL)--------';

	$stringsCount = count($arStringsInBbcode);
	$arStringsKeys = array_keys($arStringsInBbcode);

	$concatenatedStrings = implode($delimiter, $arStringsInBbcode);

	// While not unique identifier, try to
	$i = -150;
	while (count(explode($delimiter, $concatenatedStrings)) !== $stringsCount)
	{
		// prevent an infinite loop
		if (!($i++))
		{
			throw new TasksException();
		}

		$delimiter = '--------' . sha1(uniqid()) . '--------';
		$concatenatedStrings = implode($delimiter, $arStringsInBbcode);
	}

	$oParser = new CTextParser();

	$arHtmlStringsWoKeys = explode(
		$delimiter,
		str_replace(
			"t",
			'    ',
			$oParser->convertText($concatenatedStrings)
		)
	);

	$arHtmlStrings = [];

	// Do job in compatibility mode, if count of resulted strings not match source
	if (count($arHtmlStringsWoKeys) !== $stringsCount)
	{
		foreach ($arStringsInBbcode as $key => $str)
		{
			$oParser = new CTextParser();
			$arHtmlStrings[$key] = str_replace(
				"t",
				'    ',
				$oParser->convertText($str)
			);
			unset($oParser);
		}
	}
	else
	{
		// Maintain original array keys
		$i = 0;
		foreach ($arStringsKeys as $key)
		{
			$arHtmlStrings[$key] = $arHtmlStringsWoKeys[$i++];
		}
	}

	return ($arHtmlStrings);
}