CBPTaskResult::convertBCodeAnchorTag

  1. Bitrix24 API (v. 23.675.0)
  2. bizproc
  3. CBPTaskResult
  4. convertBCodeAnchorTag
  • Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/classes/general/taskservice.php
  • Класс: CBPTaskResult
  • Вызов: CBPTaskResult::convertBCodeAnchorTag
function convertBCodeAnchorTag($url, $text = '')
{
	if (is_array($url))
	{
		$text = isset($url[2]) ? $url[2] : $url[1];
		$url = $url[1];
	}

	$result = "";

	if ($url === $text)
	{
		$arUrl = explode(", ", $url);
		$arText = $arUrl;
	}
	else
	{
		$arUrl = array($url);
		$arText = array($text);
	}

	for ($i = 0, $n = count($arUrl); $i < $n; $i++)
	{
		$url = $arUrl[$i];
		$text = $arText[$i];

		$text = str_replace("\"", """, $text);
		$end = "";

		if (preg_match("/([.,?]|!)$/".BX_UTF_PCRE_MODIFIER, $url, $match))
		{
			$end = $match[1];
			$url = preg_replace("/([.,?]|!)$/".BX_UTF_PCRE_MODIFIER, "", $url);
			$text = preg_replace("/([.,?]|!)$/".BX_UTF_PCRE_MODIFIER, "", $text);
		}

		$url = preg_replace(
			array("/&/".BX_UTF_PCRE_MODIFIER, "/javascript:/i".BX_UTF_PCRE_MODIFIER),
			array("&", "java script: "),
			$url
		);
		if (mb_substr($url, 0, 1) != "/" && !preg_match("/^(http|news|https|ftp|aim|mailto):///i".BX_UTF_PCRE_MODIFIER, $url))
			$url = 'http://'.$url;
		if (!preg_match("/^((http|https|news|ftp|aim)://[-_:.a-z0-9@]+)*([^"'])+$/i".BX_UTF_PCRE_MODIFIER, $url))
			return $text." (".$url.")".$end;

		$text = preg_replace(
			array("/&/i".BX_UTF_PCRE_MODIFIER, "/javascript:/i".BX_UTF_PCRE_MODIFIER),
			array("&", "javascript: "),
			$text
		);

		if ($result !== "")
			$result .= ", ";

		$result .= "".$text."".$end;
	}

	return $result;
}

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