• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/format/texthelper.php
  • Класс: Bitrix\Crm\Format\TextHelper
  • Вызов: TextHelper::sanitizeHtml
static function sanitizeHtml($html)
{
	$html = strval($html);
	if($html === '' || mb_strpos($html, '<') === false)
	{
		return $html;
	}

	$sanitizer = new \CBXSanitizer();
	$sanitizer->ApplyDoubleEncode(false);

	//region Method #1 (Disable when CBXSanitizer::DeleteAttributes will be released)
	$tags = [
		'a'		=> ['href', 'title','name','style','class','shape','coords','alt','target'],
		'b'		=> ['style','class'],
		'br'		=> ['style','class'],
		'big'		=> ['style','class'],
		'blockquote'	=> ['title','style','class'],
		'caption'	=> ['style','class'],
		'code'		=> ['style','class'],
		'del'		=> ['title','style','class'],
		'div'		=> ['title','style','class','align'],
		'dt'		=> ['style','class'],
		'dd'		=> ['style','class'],
		'font'		=> ['color','size','face','style','class'],
		'h1'		=> ['style','class','align'],
		'h2'		=> ['style','class','align'],
		'h3'		=> ['style','class','align'],
		'h4'		=> ['style','class','align'],
		'h5'		=> ['style','class','align'],
		'h6'		=> ['style','class','align'],
		'hr'		=> ['style','class'],
		'i'		=> ['style','class'],
		'img'		=> ['style','class','src','alt','height','width','title'],
		'ins'		=> ['title','style','class'],
		'li'		=> ['style','class'],
		'map'		=> ['shape','coords','href','alt','title','style','class','name'],
		'ol'		=> ['style','class'],
		'p'		=> ['style','class','align'],
		'pre'		=> ['style','class'],
		's'		=> ['style','class'],
		'small'		=> ['style','class'],
		'strong'	=> ['style','class'],
		'span'		=> ['title','style','class','align'],
		'sub'		=> ['style','class'],
		'sup'		=> ['style','class'],
		'table'		=> ['border','width','style','class','cellspacing','cellpadding'],
		'tbody'		=> ['align','valign','style','class'],
		'td'		=> ['width','height','style','class','align','valign','colspan','rowspan'],
		'tfoot'		=> ['align','valign','style','class','align','valign'],
		'th'		=> ['width','height','style','class','colspan','rowspan'],
		'thead'		=> ['align','valign','style','class'],
		'tr'		=> ['align','valign','style','class'],
		'u'		=> ['style','class'],
		'ul'		=> ['style','class']
	];

	$sanitizer->DelAllTags();
	$sanitizer->AddTags($tags);
	//endregion
	//region Method #2 (Enable when CBXSanitizer::DeleteAttributes will be released)
	//$sanitizer->SetLevel(\CBXSanitizer::SECURE_LEVEL_LOW);
	//$sanitizer->DeleteAttributes(array('id'));
	//endregion

	return $sanitizer->SanitizeHtml($html);
}