CBPHelper::convertTextForMail

  1. Bitrix24 API (v. 23.675.0)
  2. bizproc
  3. CBPHelper
  4. convertTextForMail
  • Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/classes/general/helper.php
  • Класс: CBPHelper
  • Вызов: CBPHelper::convertTextForMail
static function convertTextForMail($text, $siteId = false)
{
	if (is_array($text))
	{
		$text = implode(', ', $text);
	}

	$text = trim($text);
	if ($text == '')
	{
		return "";
	}

	if (!$siteId)
	{
		$siteId = SITE_ID;
	}

	$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[] = "/^(r|n)+?(.*)$/";
	$arReplace[] = "\2";

	$arPattern[] = "/[b](.+?)[/b]/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)([^]]*)]/is".BX_UTF_PCRE_MODIFIER;
	$arReplace[] = "";

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

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

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

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

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

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


	$dbSite = CSite::GetByID($siteId);
	$arSite = $dbSite->Fetch();
	static::$serverName = $arSite["SERVER_NAME"];
	if (static::$serverName == '')
	{
		if (defined("SITE_SERVER_NAME") && SITE_SERVER_NAME <> '')
		{
			static::$serverName = SITE_SERVER_NAME;
		}
		else
		{
			static::$serverName = COption::GetOptionString("main", "server_name", "");
		}
	}

	$text = preg_replace_callback(
		"/[url]([^]]+?)[/url]/i".BX_UTF_PCRE_MODIFIER,
		array("CBPHelper", "__ConvertAnchorTag"),
		$text
	);
	$text = preg_replace_callback(
		"/[urls*=s*([^]]+?)s*](.*?)[/url]/is".BX_UTF_PCRE_MODIFIER,
		array("CBPHelper", "__ConvertAnchorTag"),
		$text
	);

	return $text;
}

Добавить комментарий