static function parse($text, $params = Array())
{
$linkParam = $params['LINK'] ?? null;
$smilesParam = $params['SMILES'] ?? null;
$linkLimitParam = $params['LINK_LIMIT'] ?? null;
$textLimitParam = $params['TEXT_LIMIT'] ?? null;
$cutStrikeParam = $params['CUT_STRIKE'] ?? null;
$parseId = md5($linkParam.$smilesParam.$linkLimitParam.$textLimitParam);
if (isset(self::$parsers[$parseId]))
{
$parser = self::$parsers[$parseId];
}
else
{
$parser = new CTextParser();
$parser->serverName = Common::getPublicDomain();
$parser->maxStringLen = intval($textLimitParam);
$parser->anchorType = 'bbcode';
$parser->maxAnchorLength = intval($linkLimitParam)? $linkLimitParam: 55;
foreach ($parser->allow as $tag => $value)
{
$parser->allow[$tag] = 'N';
}
$parser->allow['EMOJI'] = 'Y';
$parser->allow['HTML'] = 'Y';
$parser->allow['ANCHOR'] = 'Y';
$parser->allow['TEXT_ANCHOR'] = 'Y';
self::$parsers[$parseId] = $parser;
}
$text = preg_replace_callback("/[CODE](.*?)[/CODE]/si", Array('BitrixImText', 'setReplacement'), $text);
$text = preg_replace_callback("/[PUT(?:=(.+?))?](.+?)?[/PUT]/i", Array('BitrixImText', 'setReplacement'), $text);
$text = preg_replace_callback("/[SEND(?:=(.+?))?](.+?)?[/SEND]/i", Array('BitrixImText', 'setReplacement'), $text);
$text = preg_replace_callback("/[USER=([0-9]{1,})][/USER]/i", Array('BitrixImText', 'modifyShortUserTag'), $text);
if ($cutStrikeParam === 'Y')
{
$text = preg_replace("/[s].*?[/s]/i", "", $text);
}
$text = $parser->convertText($text);
$text = str_replace(['
', '#BR#', '[br]'], "n", $text);
$text = str_replace(["©", "™", "®"], ["(c)", "(tm)", "(r)"], $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 = self::recoverReplacements($text);
return $text;
}