/**
* Clean display value deleting html tags
*
* @param $value string: string value
* @param $striptags bool: strip all html tags
* @param $keep_bad int:
* 1 : neutralize tag anb content,
* 2 : remove tag and neutralize content
* @return clean value
**/
static function clean($value, $striptags = true, $keep_bad = 2)
{
include_once GLPI_HTMLAWED;
$value = Html::entity_decode_deep($value);
// Clean MS office tags
$value = str_replace(array("<![if !supportLists]>", "<![endif]>"), '', $value);
if ($striptags) {
$specialfilter = array('@<div[^>]*?tooltip_picture[^>]*?>.*?</div[^>]*?>@si');
// Strip ToolTips
$value = preg_replace($specialfilter, '', $value);
$specialfilter = array('@<div[^>]*?tooltip_text[^>]*?>.*?</div[^>]*?>@si');
// Strip ToolTips
$value = preg_replace($specialfilter, '', $value);
$specialfilter = array('@<div[^>]*?tooltip_picture_border[^>]*?>.*?</div[^>]*?>@si');
// Strip ToolTips
$value = preg_replace($specialfilter, '', $value);
$specialfilter = array('@<div[^>]*?invisible[^>]*?>.*?</div[^>]*?>@si');
// Strip ToolTips
$value = preg_replace($specialfilter, '', $value);
$value = preg_replace("/<(p|br|div)( [^>]*)?" . ">/i", "\n", $value);
$value = preg_replace("/( | )+/", " ", $value);
$search = array('@<script[^>]*?>.*?</script[^>]*?>@si', '@<style[^>]*?>.*?</style[^>]*?>@si', '@<!DOCTYPE[^>]*?>@si');
$value = preg_replace($search, '', $value);
}
$value = htmLawed($value, array('elements' => $striptags ? 'none' : '', 'keep_bad' => $keep_bad, 'comment' => 1, 'cdata' => 1));
$value = str_replace(array('<', '>'), array('&lt;', '&gt;'), $value);
/*
$specialfilter = array('@<span[^>]*?x-hidden[^>]*?>.*?</span[^>]*?>@si'); // Strip ToolTips
$value = preg_replace($specialfilter, ' ', $value);
$search = array('@<script[^>]*?>.*?</script[^>]*?>@si', // Strip out javascript
'@<style[^>]*?>.*?</style[^>]*?>@si', // Strip style tags properly
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<![\s\S]*?--[ \t\n\r]*>@'); // Strip multi-line comments including CDATA
$value = preg_replace($search, ' ', $value);
// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
$value = str_replace("’", "'", $value);
*/
// Problem with this regex : may crash
// $value = preg_replace("/ +/u", " ", $value);
// Revert back htmlawed & -> &
//$value = str_replace("&", "&", $value);
$value = str_replace(array("\r\n", "\r"), "\n", $value);
$value = preg_replace("/(\n[ ]*){2,}/", "\n\n", $value, -1);
return trim($value);
}