- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_tools.php
- Класс: logTextParser
- Вызов: logTextParser::convert
function convert($text, $arImages = array(), $allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "Y", "NL2BR" => "N", "VIDEO" => "Y", "TABLE" => "Y", "CUT_ANCHOR" => "N", "SHORT_ANCHOR" => "N"), $arParams = Array())
{
$this->allow = array(
"HTML" => ($allow["HTML"] === "Y" ? "Y" : "N"),
"NL2BR" => ($allow["NL2BR"] === "Y" ? "Y" : "N"),
"LOG_NL2BR" => (($allow["LOG_NL2BR"] ?? null) === "N" ? "N" : "Y"),
"MULTIPLE_BR" => (($allow["MULTIPLE_BR"] ?? null) === "N" ? "N" : "Y"),
"CODE" => ($allow["CODE"] === "N" ? "N" : "Y"),
"LOG_CODE" => (isset($allow["LOG_CODE"]) && $allow["LOG_CODE"] === "N" ? "N" : "Y"),
"VIDEO" => ($allow["VIDEO"] === "N" ? "N" : "Y"),
"LOG_VIDEO" => ($allow["LOG_VIDEO"] === "N" ? "N" : "Y"),
"ANCHOR" => ($allow["ANCHOR"] === "N" ? "N" : "Y"),
"LOG_ANCHOR" => (isset($allow["LOG_ANCHOR"]) && $allow["LOG_ANCHOR"] === "N" ? "N" : "Y"),
"BIU" => ($allow["BIU"] === "N" ? "N" : "Y"),
"IMG" => ($allow["IMG"] === "N" ? "N" : "Y"),
"LOG_IMG" => (isset($allow["LOG_IMG"]) && $allow["LOG_IMG"] === "N" ? "N" : "Y"),
"QUOTE" => ($allow["QUOTE"] === "N" ? "N" : "Y"),
"LOG_QUOTE" => (isset($allow["LOG_QUOTE"]) && $allow["LOG_QUOTE"] === "N" ? "N" : "Y"),
"FONT" => ($allow["FONT"] === "N" ? "N" : "Y"),
"LOG_FONT" => (isset($allow["LOG_FONT"]) && $allow["LOG_FONT"] === "N" ? "N" : "Y"),
"LIST" => ($allow["LIST"] === "N" ? "N" : "Y"),
"SMILES" => ($allow["SMILES"] === "N" ? "N" : "Y"),
"TABLE" => (isset($allow["TABLE"]) && $allow["TABLE"] === "N" ? "N" : "Y"),
"ALIGN" => (isset($allow["ALIGN"]) && $allow["ALIGN"] === "N" ? "N" : "Y"),
"CUT_ANCHOR" => (($allow["CUT_ANCHOR"] ?? null) === "Y" ? "Y" : "N"),
"SHORT_ANCHOR" => (isset($allow["SHORT_ANCHOR"]) && $allow["SHORT_ANCHOR"] === "Y" ? "Y" : "N"),
"HEADER" => (isset($allow["HEADER"]) && $allow["HEADER"] === "N" ? "N" : "Y"),
"USERFIELDS" => (isset($allow["USERFIELDS"]) && $allow["USERFIELDS"] ? $allow["USERFIELDS"] : "N"),
"USER" => (isset($allow["USER"]) && $allow["USER"] === "N" ? "N" : "Y")
);
if ($this->allow["HTML"] !== "Y")
{
$text = preg_replace("#(
)#is".BX_UTF_PCRE_MODIFIER, "", $text);
$text = preg_replace(
array(
"#]+hrefs*=s*('|")(.+?)(?:\1)[^>]*>(.*?)]*>#is".BX_UTF_PCRE_MODIFIER,
"#]+href(s*=s*)([^'">])+>(.*?)]*>#is".BX_UTF_PCRE_MODIFIER),
"[url=\2]\3[/url]", $text);
$replaced = 0;
do
{
$text = preg_replace(
"/<([busi])[^>a-z]*>(.+?)<\/(\1)[^>a-z]*>/is".BX_UTF_PCRE_MODIFIER,
"[\1]\2[/\1]",
$text, -1, $replaced);
}
while($replaced > 0);
$text = preg_replace(
"#
]+srcs*=[s'"]*(((http|https|ftp)://[.-_:a-z0-9@]+)*(/[-_/=:.a-z0-9@{}&?%]+)+)[s'"]*[^>]*>#is".BX_UTF_PCRE_MODIFIER,
"[img]\1[/img]", $text);
$text = preg_replace(
array(
"/]+sizes*=[s'"]*([0-9]+)[s'"]*[^>]*>(.+?)]*>/is".BX_UTF_PCRE_MODIFIER,
"/]+colors*=[s'"]*(#[a-f0-9]{6})[^>]*>(.+?)]*>/is".BX_UTF_PCRE_MODIFIER,
"/]+faces*=[s'"]*([a-zs-]+)[s'"]*[^>]*>(.+?)]*>/is".BX_UTF_PCRE_MODIFIER),
array(
"[size=\1]\2[/size]",
"[color=\1]\2[/color]",
"[font=\1]\2[/font]"),
$text);
$text = preg_replace(
array(
"/- ]*)|(s*))>(.+?)
- ]*)|(s*))>(.+?)
", "n", $text); } $text = $this->convertText($text); if ($this->allow["LOG_NL2BR"] === "Y") { $text = str_replace("n", "
", $text); } $text = preg_replace("#^(
[sn]*)+#is".BX_UTF_PCRE_MODIFIER, "", $text); $text = preg_replace("#(
[sn]*)+$#is".BX_UTF_PCRE_MODIFIER, "", $text); if ($this->allow["MULTIPLE_BR"] === "N") $text = preg_replace("#(
[sn]*)+#is".BX_UTF_PCRE_MODIFIER, "
", $text); return trim($text); }