CAllCrmActivity::PrepareDescriptionFields

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmActivity
  4. PrepareDescriptionFields
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_activity.php
  • Класс: \CAllCrmActivity
  • Вызов: CAllCrmActivity::PrepareDescriptionFields
static function PrepareDescriptionFields(array &$fields, array $options = null)
{

	if(!is_array($options))
	{
		$options = array();
	}

	$enableHtml = !isset($options['ENABLE_HTML']) || $options['ENABLE_HTML'] === true;
	$enableBBCode = !isset($options['ENABLE_BBCODE']) || $options['ENABLE_BBCODE'] === true;
	$limit = isset($options['LIMIT']) ? (int)$options['LIMIT'] : 0;

	$description = isset($fields['DESCRIPTION']) ? $fields['DESCRIPTION'] : '';
	$descriptionType = isset($fields['DESCRIPTION_TYPE']) ? (int)$fields['DESCRIPTION_TYPE'] : \CCrmContentType::PlainText;


	if($descriptionType === \CCrmContentType::Html)
	{
		if($enableBBCode)
		{
			$fields['DESCRIPTION_BBCODE'] = '';
		}

		if($enableHtml)
		{
			$fields['DESCRIPTION_HTML'] = $description;
		}

		$description = preg_replace('/]*>.*?<\/style>/is', '', $description);
		$description = preg_replace('/]*>.*?<\/blockquote>/is', '', $description);
		$description = preg_replace('/]*>.*?<\/script>/is', '', $description);
		$fields['DESCRIPTION_RAW'] = strip_tags(
				preg_replace(
					'/(]*>)+/is'.BX_UTF_PCRE_MODIFIER,
					"\n",
					html_entity_decode($description, ENT_QUOTES)
				)
		);
	}
	elseif($descriptionType === \CCrmContentType::BBCode)
	{
		$parser = new \CTextParser();
		$parser->allow['SMILES'] = 'N';

		if($enableBBCode)
		{
			$fields['DESCRIPTION_BBCODE'] = $description;
		}

		$descriptionHtml = $parser->convertText($description);
		if($enableHtml)
		{
			$fields['DESCRIPTION_HTML'] = $descriptionHtml;
		}

		$fields['DESCRIPTION_RAW'] = strip_tags(
			preg_replace(
				array(
					'/(]*>)+/is'.BX_UTF_PCRE_MODIFIER,
					'/( )+/is'.BX_UTF_PCRE_MODIFIER,
					'/\[[0-9a-z\W\=]+\]/iUs'.BX_UTF_PCRE_MODIFIER
				),
				array(
					"\n",
					" ",
					""
				),
				html_entity_decode($descriptionHtml, ENT_QUOTES)
			)
		);
	}
	else//if($descriptionType === CCrmContentType::PlainText)
	{
		if($enableBBCode)
		{
			$fields['DESCRIPTION_BBCODE'] = '';
		}

		if($enableHtml)
		{
			$fields['DESCRIPTION_HTML'] = preg_replace("/[\r\n]+/".BX_UTF_PCRE_MODIFIER, "
", htmlspecialcharsbx($description)); } $fields['DESCRIPTION_RAW'] = $description; } unset($fields['DESCRIPTION']); if($limit > 0 && mb_strlen($fields['DESCRIPTION_RAW']) > $limit) { $fields['DESCRIPTION_RAW'] = mb_substr($fields['DESCRIPTION_RAW'], 0, $limit); } $fields['DESCRIPTION_RAW'] = \Bitrix\Main\Text\Emoji::decode($fields['DESCRIPTION_RAW']); if(isset($fields['SUBJECT'])) { $fields['SUBJECT'] = \Bitrix\Main\Text\Emoji::decode($fields['SUBJECT']); } }

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