24 public static function parse($text, $params = Array())
26 $linkParam = $params[
'LINK'] ??
null;
27 $smilesParam = $params[
'SMILES'] ??
null;
28 $linkLimitParam = $params[
'LINK_LIMIT'] ??
null;
29 $textLimitParam = $params[
'TEXT_LIMIT'] ??
null;
30 $cutStrikeParam = $params[
'CUT_STRIKE'] ??
null;
32 $parseId = md5($linkParam.$smilesParam.$linkLimitParam.$textLimitParam);
33 if (isset(self::$parsers[$parseId]))
35 $parser = self::$parsers[$parseId];
39 $parser = new \CTextParser();
40 $parser->serverName = Common::getPublicDomain();
41 $parser->maxStringLen = intval($textLimitParam);
43 $parser->anchorType =
'bbcode';
44 $parser->maxAnchorLength = intval($linkLimitParam)? $linkLimitParam: 55;
46 foreach ($parser->allow as $tag => $value)
48 $parser->allow[$tag] =
'N';
50 $parser->allow[
'EMOJI'] =
'Y';
51 $parser->allow[
'HTML'] =
'Y';
52 $parser->allow[
'ANCHOR'] =
'Y';
53 $parser->allow[
'TEXT_ANCHOR'] =
'Y';
55 self::$parsers[$parseId] = $parser;
58 $text = preg_replace_callback(
"/\[CODE\](.*?)\[\/CODE\]/si", Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
59 $text = preg_replace_callback(
"/\[PUT(?:=(.+?))?\](.+?)?\[\/PUT\]/i", Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
60 $text = preg_replace_callback(
"/\[SEND(?:=(.+?))?\](.+?)?\[\/SEND\]/i", Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
61 $text = preg_replace_callback(
"/\[USER=([0-9]{1,})\]\[\/USER\]/i", Array(
'\Bitrix\Im\Text',
'modifyShortUserTag'), $text);
63 if ($cutStrikeParam ===
'Y')
65 $text = preg_replace(
"/\[s\].*?\[\/s\]/i",
"", $text);
68 $text = $parser->convertText($text);
70 $text = str_replace([
'<br />',
'#BR#',
'[br]'],
"\n", $text);
71 $text = str_replace([
"©",
"™",
"®"], [
"(c)",
"(tm)",
"(r)"], $text);
72 $text = str_replace(
" ",
" ", $text);
73 $text = str_replace(
""",
"\"", $text);
74 $text = str_replace(
"\",
"\\", $text);
75 $text = str_replace(
"$",
"\$", $text);
76 $text = str_replace(
"!",
"!", $text);
77 $text = str_replace(
"[",
"[", $text);
78 $text = str_replace(
"]",
"]", $text);
79 $text = str_replace(
"'",
"'", $text);
80 $text = str_replace(
"<",
"<", $text);
81 $text = str_replace(
">",
">", $text);
82 $text = str_replace(
"|",
'|', $text);
83 $text = str_replace(
"&",
"&", $text);
85 $text = self::recoverReplacements($text);
97 $safeParam = $params[
'SAFE'] ??
null;
98 $linkParam = $params[
'LINK'] ??
null;
99 $fontParam = $params[
'FONT'] ??
null;
100 $smilesParam = $params[
'SMILES'] ??
null;
101 $textAnchorParam = $params[
'TEXT_ANCHOR'] ??
null;
102 $linkLimitParam = $params[
'LINK_LIMIT'] ??
null;
103 $textLimitParam = $params[
'TEXT_LIMIT'] ??
null;
104 $linkTargetSelfParam = $params[
'LINK_TARGET_SELF'] ??
null;
105 $cutStrikeParam = $params[
'CUT_STRIKE'] ??
null;
107 if (!$safeParam || $safeParam ===
'Y')
109 $text = htmlspecialcharsbx($text);
115 'ANCHOR' => $linkParam ===
'N' ?
'N' :
'Y',
120 'FONT' => $fontParam ===
'Y' ?
'Y' :
'N',
123 'SMILES' => $smilesParam ===
'N' ?
'N' :
'Y',
129 'SHORT_ANCHOR' =>
'N',
131 'TEXT_ANCHOR' => $textAnchorParam ===
'N' ?
'N' :
'Y',
134 $parseId = md5(
'legacy'.$linkParam.$smilesParam.$linkLimitParam.$textLimitParam.$linkTargetSelfParam);
135 if (isset(self::$parsers[$parseId]))
137 $parser = self::$parsers[$parseId];
141 $parser = new \CTextParser();
142 $parser->serverName = Common::getPublicDomain();
143 $parser->maxAnchorLength = intval($linkLimitParam)? $linkLimitParam: 55;
144 $parser->maxStringLen = intval($textLimitParam);
145 $parser->allow = $allowTags;
146 if ($linkTargetSelfParam ===
'Y')
148 $parser->link_target =
"_self";
151 self::$parsers[$parseId] = $parser;
154 $text = preg_replace_callback(
"/\[PUT(?:=(.+?))?\](.+?)?\[\/PUT\]/i", Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
155 $text = preg_replace_callback(
"/\[SEND(?:=(.+?))?\](.+?)?\[\/SEND\]/i", Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
156 $text = preg_replace_callback(
"/\[CODE\](.*?)\[\/CODE\]/si", Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
157 $text = preg_replace_callback(
"/\[USER=([0-9]{1,})\]\[\/USER\]/i", Array(
'\Bitrix\Im\Text',
'modifyShortUserTag'), $text);
159 if ($cutStrikeParam ===
'Y')
161 $text = preg_replace(
"/\[s\].*?\[\/s\]/i",
"", $text);
164 $text = $parser->convertText($text);
166 $text = str_replace(array(
'#BR#',
'[br]',
'[BR]'),
'<br/>', $text);
168 $text = self::recoverReplacements($text);
177 $dates = self::getDateConverterParams($text);
178 foreach ($dates as $result)
182 'TEXT' => $result->getText(),
183 'VALUE' => $result->getDate(),
184 'START' => $result->getTextPosition(),
185 'END' => $result->getTextPosition()+$result->getTextLength(),
189 return self::resolveIntersect($replaces);
220 $text = preg_replace_callback(
"/\[PUT(?:=(.+?))?\](.+?)?\[\/PUT\]/i", Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
221 $text = preg_replace_callback(
"/\[SEND(?:=(.+?))?\](.+?)?\[\/SEND\]/i", Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
222 $text = preg_replace_callback(
'/\[URL\=([^\]]*)\]([^\]]*)\[\/URL\]/i', Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
223 $text = preg_replace_callback(
'/(https?):\/\/(([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+(:([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+)?@)?(?#)((([a-z0-9]\.|[a-z0-9][a-z0-9-]*[a-z0-9]\.)*[a-z][a-z0-9-]*[a-z0-9]|((\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5]))(:\d+)?)(((\/+([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)*(\?([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)?)?)?(#([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)?/im', Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
224 $text = preg_replace_callback(
'#\-{54}(.+?)\-{54}#s', Array(
'\Bitrix\Im\Text',
'setReplacement'), $text);
226 return \Bitrix\Main\Text\DateConverter::decode($text, 1000);
268 if (empty(self::$replacements))
273 foreach(self::$replacements as $code => $value)
275 $text = str_replace($code, $value, $text);
278 if (mb_strpos($text,
'####REPLACEMENT_MARK_') !==
false)
280 $text = self::recoverReplacements($text);
283 self::$replacements = Array();
472 preg_match(
'/title\=(.*[^\s\]])/i', $text, $match);
476 if (mb_strpos($title,
'width=') !==
false)
478 $title = mb_substr($title, 0, mb_strpos($title,
'width='));
480 if (mb_strpos($title,
'height=') !==
false)
482 $title = mb_substr($title, 0, mb_strpos($title,
'height='));
484 if (mb_strpos($title,
'size=') !==
false)
486 $title = mb_substr($title, 0, mb_strpos($title,
'size='));
488 $title = trim($title);
491 return '('.$title.
')';