• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/text.php
  • Класс: BitrixImText
  • Вызов: Text::removeBbCodes
static function removeBbCodes($text, $withFile = false, $attachValue = false)
{
	if ($attachValue)
	{
		if ($attachValue === true || preg_match('/^(d+)$/', $attachValue))
		{
			$text .= " [".Loc::getMessage('IM_MESSAGE_ATTACH')."]";
		}
		else
		{
			$text .= ' '. $attachValue;
		}
	}

	$text = preg_replace("/[s](.*?)[/s]/i", "", $text);
	$text = preg_replace("/[[buis]](.*?)[/[buis]]/i", "$1", $text);
	$text = preg_replace("/[url](.*?)[/url]/i".BX_UTF_PCRE_MODIFIER, "$1", $text);
	$text = preg_replace("/[url\s*=\s*((?:[^\[\]]++|\[ (?: (?>[^\[\]]+) | (?:\1) )* \])+)\s*\](.*?)\[\/url\]/ixs".BX_UTF_PCRE_MODIFIER, "$2", $text);
	$text = preg_replace("/[RATING=([1-5]{1})]/i", " [".Loc::getMessage('IM_MESSAGE_RATING')."] ", $text);
	$text = preg_replace("/[ATTACH=([0-9]{1,})]/i", " [".Loc::getMessage('IM_MESSAGE_ATTACH')."] ", $text);
	$text = preg_replace_callback("/[USER=([0-9]{1,})][/USER]/i", Array('BitrixImText', 'modifyShortUserTag'), $text);
	$text = preg_replace("/[USER=([0-9]+)( REPLACE)?](.*?)[/USER]/i", "$3", $text);
	$text = preg_replace("/[dialog=(chatd+|d+:d)(?: message=(d+))?](.*?)[/dialog]/i", "$3", $text);
	$text = preg_replace("/[context=(chatd+|d+:d+)/(d+)](.*?)[/context]/i", "$3", $text);
	$text = preg_replace("/[CHAT=([0-9]{1,})](.*?)[/CHAT]/i", "$2", $text);
	$text = preg_replace("/[SEND(?:=(.+?))?](.+?)?[/SEND]/i", "$2", $text);
	$text = preg_replace("/[PUT(?:=(.+?))?](.+?)?[/PUT]/i", "$2", $text);
	$text = preg_replace("/[CALL(?:=(.+?))?](.+?)?[/CALL]/i", "$2", $text);
	$text = preg_replace("/[PCH=([0-9]{1,})](.*?)[/PCH]/i", "$2", $text);
	$text = preg_replace("/[size=(d+)](.*?)[/size]/i", "$2", $text);
	$text = preg_replace("/[color=#([0-9a-f]{3}|[0-9a-f]{6})](.*?)[/color]/i", "$2", $text);
	$text = preg_replace_callback("/[ICON=([^]]*)]/i", Array('BitrixImText', 'modifyIcon'), $text);
	$text = preg_replace('#-{54}.+?-{54}#s', " [".Loc::getMessage('IM_QUOTE')."] ", str_replace(array("#BR#"), Array(" "), $text));
	$text = trim($text);

	if ($withFile)
	{
		$text .= " [".Loc::getMessage('IM_MESSAGE_FILE')."]";
	}

	$text = trim($text);

	if ($text == '')
	{
		$text = Loc::getMessage('IM_MESSAGE_DELETE');
	}

	return $text;
}