• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/textparser.php
  • Класс: CTextParser
  • Вызов: CTextParser::convert4mail
public function convert4mail($text)
{
	$text = trim($text);
	if ($text == '')
	{
		return '';
	}

	$arPattern = [];
	$arReplace = [];

	$arPattern[] = "/\[(code|quote)(.*?)\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "n>================== \1 ===================n";

	$arPattern[] = "/\[\/(code|quote)(.*?)\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "n>===========================================n";

	$arPattern[] = "/\/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "";

	$arPattern[] = "/\[\*\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "- ";

	$arPattern[] = "/^(r|n)+?(.*)$/";
	$arReplace[] = "\2";

	$arPattern[] = "/\[b\](.+?)\[\/b\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "\1";

	$arPattern[] = "/\[p\](.*?)\[\/p\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "\1";

	$arPattern[] = "/\[i\](.+?)\[\/i\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "\1";

	$arPattern[] = "/\[u\](.+?)\[\/u\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "_\1_";

	$arPattern[] = "/\[s\](.+?)\[\/s\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "_\1_";

	$arPattern[] = "/\[(\/?)(color|font|size|left|right|center)([^\]]*)\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "";

	$arPattern[] = "/\[url\](\S+?)\[\/url\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "(URL: \1 )";

	$arPattern[] = "/\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "\2 (URL: \1 )";

	$arPattern[] = "/\[img([^\]]*)\](.+?)\[\/img\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "(IMAGE: \2)";

	$arPattern[] = "/\[video([^\]]*)\](.+?)\[\/video[\s]*\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "(VIDEO: \2)";

	$arPattern[] = "/\[(\/?)list(.*?)\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "n";

	$arPattern[] = "/\[user([^\]]*)\](.+?)\[\/user\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "\2";

	$arPattern[] = "/\[project([^\]]*)\](.+?)\[\/project\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "\2";

	$arPattern[] = "/\[department([^\]]*)\](.+?)\[\/department\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "\2";

	$arPattern[] = "/\[DOCUMENT([^\]]*)\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "";

	$arPattern[] = "/\[DISK(.+?)\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "";

	$arPattern[] = "/\[(table)(.*?)\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "n>================== \1 ===================";

	$arPattern[] = "/\[\/table(.*?)\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "n>===========================================n";

	$arPattern[] = "/\[tr\]\s*/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "n";

	$arPattern[] = "/\[(\/?)(tr|td)\]/is" . BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "";

	$text = preg_replace($arPattern, $arReplace, $text);

	$text = str_replace('­', '', $text);
	if (preg_match("/[cut(([^]])*)]/is" . BX_UTF_PCRE_MODIFIER, $text))
	{
		$text = preg_replace(
			[
				"/[cut(([^]])*)]/is" . BX_UTF_PCRE_MODIFIER,
				"/[/cut]/is" . BX_UTF_PCRE_MODIFIER,
			],
			[
				"01\102",
				"03",
			],
			$text
		);
		while (preg_match("/(01([^02]*)02([^010203]+)03)/is" . BX_UTF_PCRE_MODIFIER, $text))
		{
			$text = preg_replace(
				"/(01([^02]*)02([^010203]+)03)/is" . BX_UTF_PCRE_MODIFIER,
				"n>================== CUT ===================n\3n>==========================================n",
				$text
			);
		}
		$text = preg_replace(
			[
				"/01([^02]+)02/",
				"/0102/",
				"/03/",
			],
			[
				"[cut\1]",
				"[cut]",
				"[/cut]",
			],
			$text
		);
	}
	$text = str_replace(" ", " ", $text);
	$text = str_replace(""", """, $text);
	$text = str_replace("\", "\", $text);
	$text = str_replace("$", "$", $text);
	$text = str_replace("!", "!", $text);
	$text = str_replace("[", "[", $text);
	$text = str_replace("]", "]", $text);
	$text = str_replace("'", "'", $text);
	$text = str_replace("<", "<", $text);
	$text = str_replace(">", ">", $text);
	$text = str_replace(" ", " ", $text);
	$text = str_replace("|", '|', $text);
	$text = str_replace("&", "&", $text);

	return $text;
}