2
0
forked from Wavyzz/dolibarr

Fix: Better html detection

This commit is contained in:
Laurent Destailleur
2014-05-07 19:06:15 +02:00
parent 182dd774b6
commit 1bc3558307
2 changed files with 73 additions and 19 deletions

View File

@@ -3414,13 +3414,13 @@ function picto_required()
* Clean a string from all HTML tags and entities
*
* @param string $StringHtml String to clean
* @param string $removelinefeed Replace also all lines feeds by a space
* @param string $removelinefeed Replace also all lines feeds by a space, otherwise only last one are removed
* @param string $pagecodeto Encoding of input/output string
* @return string String cleaned
*/
function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8')
{
$pattern = "/<[^>]+>/";
$pattern = "/<[^<>]+>/";
$temp = dol_html_entity_decode($StringHtml,ENT_COMPAT,$pagecodeto);
$temp = preg_replace($pattern,"",$temp);
@@ -3486,7 +3486,6 @@ function dol_htmlentitiesbr($stringtoencode,$nl2brmode=0,$pagecodefrom='UTF-8')
$newstring=strtr($newstring,array('&'=>'__and__','<'=>'__lt__','>'=>'__gt__','"'=>'__dquot__'));
$newstring=dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding
$newstring=strtr($newstring,array('__and__'=>'&','__lt__'=>'<','__gt__'=>'>','__dquot__'=>'"'));
//$newstring=strtr($newstring,array('__li__'=>"<li>\n")); // Restore <li>\n
}
else
{
@@ -3530,7 +3529,7 @@ function dol_htmlcleanlastbr($stringtodecode)
* Replace html_entity_decode functions to manage errors
*
* @param string $a Operand a
* @param string $b Operand b
* @param string $b Operand b (ENT_QUOTES=convert simple and double quotes)
* @param string $c Operand c
* @return string String decoded
*/
@@ -3670,17 +3669,10 @@ function dol_textishtml($msg,$option=0)
{
if (preg_match('/<html/i',$msg)) return true;
elseif (preg_match('/<body/i',$msg)) return true;
elseif (preg_match('/<b>/i',$msg)) return true;
elseif (preg_match('/<br/i',$msg)) return true;
elseif (preg_match('/<div/i',$msg)) return true;
elseif (preg_match('/<em>/i',$msg)) return true;
elseif (preg_match('/<font/i',$msg)) return true;
elseif (preg_match('/<img/i',$msg)) return true;
elseif (preg_match('/<i>/i',$msg)) return true;
elseif (preg_match('/<li/i',$msg)) return true;
elseif (preg_match('/<span/i',$msg)) return true;
elseif (preg_match('/<strong/i',$msg)) return true;
elseif (preg_match('/<table/i',$msg)) return true;
elseif (preg_match('/<(b|em|i)>/i',$msg)) return true;
elseif (preg_match('/<(br|div|font|img|li|span|strong|table)>/i',$msg)) return true;
elseif (preg_match('/<(br|div|font|img|li|span|strong|table)\s+[^<>\/]*>/i',$msg)) return true;
elseif (preg_match('/<(br|div|font|img|li|span|strong|table)\s+[^<>\/]*\/>/i',$msg)) return true;
elseif (preg_match('/&[A-Z0-9]{1,6};/i',$msg)) return true; // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
elseif (preg_match('/&#[0-9]{2,3};/i',$msg)) return true; // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
return false;
@@ -3688,7 +3680,7 @@ function dol_textishtml($msg,$option=0)
}
/**
* Concat 2 descriptions (second one after first one)
* Concat 2 descriptions (second one after first one with a new line separator if required)
* text1 html + text2 html => text1 + '<br>' + text2
* text1 html + text2 txt => text1 + '<br>' + dol_nl2br(text2)
* text1 txt + text2 html => dol_nl2br(text1) + '<br>' + text2