diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 4ababc23f73..760791027cb 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -2323,8 +2323,8 @@ class Adherent extends CommonObject if ($this->phone_perso && ! empty($conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO)) $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso; if ($this->phone_mobile && ! empty($conf->global->LDAP_MEMBER_FIELD_MOBILE)) $info[$conf->global->LDAP_MEMBER_FIELD_MOBILE] = $this->phone_mobile; if ($this->fax && ! empty($conf->global->LDAP_MEMBER_FIELD_FAX)) $info[$conf->global->LDAP_MEMBER_FIELD_FAX] = $this->fax; - if ($this->note_private && ! empty($conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 0, 'UTF-8', 1); - if ($this->note_public && ! empty($conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC)) $info[$conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC] = dol_string_nohtmltag($this->note_public, 0, 'UTF-8', 1); + if ($this->note_private && ! empty($conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2); + if ($this->note_public && ! empty($conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC)) $info[$conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC] = dol_string_nohtmltag($this->note_public, 2); if ($this->birth && ! empty($conf->global->LDAP_MEMBER_FIELD_BIRTHDATE)) $info[$conf->global->LDAP_MEMBER_FIELD_BIRTHDATE] = dol_print_date($this->birth,'dayhourldap'); if (isset($this->statut) && ! empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->statut; if ($this->datefin && ! empty($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)) $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] = dol_print_date($this->datefin,'dayhourldap'); diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 6c841c267b8..7c30d7eb352 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -530,7 +530,7 @@ class Contact extends CommonObject if ($this->phone_mobile && ! empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile; if ($this->fax && ! empty($conf->global->LDAP_CONTACT_FIELD_FAX)) $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax; if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype; - if ($this->note_private && ! empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = $this->note_private; + if ($this->note_private && ! empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2); if ($this->email && ! empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email; if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 1adefaca5ab..a24a454d54e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5408,26 +5408,27 @@ function picto_required() /** * Clean a string from all HTML tags and entities. * This function differs from strip_tags because: - * -
are replace with \n - * - if entities are found, they are decoded before the strip - * - you can decide to convert line feed into spaces + * -
are replaced with \n if removelinefeed=0 or 1 + * - if entities are found, they are decoded BEFORE the strip + * - you can decide to convert line feed into a space * * @param string $stringtoclean String to clean - * @param integer $removelinefeed 1=Replace also new lines by a space, 0=Only last one are removed + * @param integer $removelinefeed 1=Replace all new lines by 1 space, 0=Only ending new lines are removed others are replaced with \n, 2=Ending new lines are removed but others are kept with a same number of \n than nb of
when there is both "...
\n..." * @param string $pagecodeto Encoding of input/output string - * @param integer $strip_tags 1=Use strip_tags php function, 0=Use internal pattern + * @param integer $strip_tags 0=Use internal strip, 1=Use strip_tags() php function (bugged when text contains a < char that is not for a html tag) * @return string String cleaned * * @see dol_escape_htmltag strip_tags */ -function dol_string_nohtmltag($stringtoclean,$removelinefeed=1,$pagecodeto='UTF-8',$strip_tags=0) +function dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0) { + if ($removelinefeed == 2) $stringtoclean = preg_replace('/]*>\n+/ims', '
', $stringtoclean); + $temp = preg_replace('/]*>/i', "\n", $stringtoclean); + if ($strip_tags) { - $temp = strip_tags($stringtoclean); + $temp = strip_tags($temp); } else { $pattern = "/<[^<>]+>/"; - $temp = preg_replace('/]*>/', "\n", $stringtoclean); - // Exemple of $temp: 0000-021 $temp = preg_replace($pattern,"",$temp); // pass 1 // $temp after pass 1: 0000-021 @@ -5438,7 +5439,7 @@ function dol_string_nohtmltag($stringtoclean,$removelinefeed=1,$pagecodeto='UTF- $temp = dol_html_entity_decode($temp,ENT_COMPAT,$pagecodeto); // Supprime aussi les retours - if ($removelinefeed) $temp=str_replace(array("\r\n","\r","\n")," ",$temp); + if ($removelinefeed == 1) $temp=str_replace(array("\r\n","\r","\n")," ",$temp); // et les espaces doubles while (strpos($temp," ")) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a0a8597a535..6d992246eea 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2408,7 +2408,7 @@ class User extends CommonObject if ($this->address && ! empty($conf->global->LDAP_FIELD_ADDRESS)) $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address; if ($this->zip && ! empty($conf->global->LDAP_FIELD_ZIP)) $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip; if ($this->town && ! empty($conf->global->LDAP_FIELD_TOWN)) $info[$conf->global->LDAP_FIELD_TOWN] = $this->town; - if ($this->note_public && ! empty($conf->global->LDAP_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_public, 0, 'UTF-8', 1); + if ($this->note_public && ! empty($conf->global->LDAP_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_public, 2); if ($this->socid > 0) { $soc = new Societe($this->db); diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index d852c7ac03a..859c5267d04 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -908,7 +908,7 @@ class UserGroup extends CommonObject // Champs if ($this->name && ! empty($conf->global->LDAP_GROUP_FIELD_FULLNAME)) $info[$conf->global->LDAP_GROUP_FIELD_FULLNAME] = $this->name; //if ($this->name && ! empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name; - if ($this->note && ! empty($conf->global->LDAP_GROUP_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note, 0, 'UTF-8', 1); + if ($this->note && ! empty($conf->global->LDAP_GROUP_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note, 2); if (! empty($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)) { $valueofldapfield=array(); diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index e96cda7d6e5..71b39fc6e51 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -437,17 +437,21 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase */ public function testDolStringNohtmltag() { - $text="A\nstring\n"; + $text="A\nstring\n\nand more\n"; $after=dol_string_nohtmltag($text,0); - $this->assertEquals("A\nstring",$after,"test1"); + $this->assertEquals("A\nstring\n\nand more",$after,"test1a"); - $text="A string\n\nwith html tag and '<' chars
\n"; + $text="A string
\n
\n\nwith html tag
\n"; $after=dol_string_nohtmltag($text, 0); - $this->assertEquals("A string\n\nwith html tag and '<' chars",$after,"test2"); + $this->assertEquals("A string\n\n\n\n\nwith html tag",$after,"test2a 2 br and 3 \n give 5 \n"); - $text="A string\n\nwith tag with < chars
\n"; + $text="A string
\n
\n\nwith html tag
\n"; $after=dol_string_nohtmltag($text, 1); - $this->assertEquals("A string with tag with < chars",$after,"test3"); + $this->assertEquals("A string with html tag",$after,"test2b 2 br and 3 \n give 1 space"); + + $text="A string
\n
\n\nwith html tag
\n"; + $after=dol_string_nohtmltag($text, 2); + $this->assertEquals("A string\n\nwith html tag",$after,"test2c 2 br and 3 \n give 2 \n"); $text="A string
Another string"; $after=dol_string_nohtmltag($text,0); @@ -469,6 +473,14 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase $after=dol_string_nohtmltag($text,0); $this->assertEquals("HIJ",$after,"test8"); + $text="A string\n\nwith html tag and '<' chars
\n"; + $after=dol_string_nohtmltag($text, 0); + $this->assertEquals("A string\n\nwith html tag and '<' chars",$after,"test9"); + + $text="A string\n\nwith tag with < chars
\n"; + $after=dol_string_nohtmltag($text, 1); + $this->assertEquals("A string with tag with < chars",$after,"test10"); + return true; } @@ -830,7 +842,7 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase $s=img_picto('title', 'delete', '', 0, 1); print __METHOD__." s=".$s."\n"; - $this->assertEquals('/theme/eldy/img/delete.png',$s,'testImgPicto5'); + $this->assertEquals(DOL_URL_ROOT.'/theme/eldy/img/delete.png',$s,'testImgPicto5'); } /**