This commit is contained in:
Laurent Destailleur 2014-10-11 23:46:49 +02:00
parent 77ed7bf5df
commit 52e1bd2ad1

View File

@ -480,47 +480,47 @@ function clean_url($url,$http=1)
} }
/** /**
* Returns an email value with obfuscated parts. * Returns an email value with obfuscated parts.
* *
* @param string $mail Email * @param string $mail Email
* @param string $replace Replacement character (defaul : *) * @param string $replace Replacement character (defaul : *)
* @param int $nbreplace Number of replacement character (default : 8) * @param int $nbreplace Number of replacement character (default : 8)
* @param int $nbdisplaymail Number of character unchanged (default: 4) * @param int $nbdisplaymail Number of character unchanged (default: 4)
* @param int $nbdisplaydomain Number of character unchanged of domain (default: 3) * @param int $nbdisplaydomain Number of character unchanged of domain (default: 3)
* @param bool $displaytld Display tld (default: true) * @param bool $displaytld Display tld (default: true)
* @return string Return email with hidden parts or ''; * @return string Return email with hidden parts or '';
*/ */
function dolObfuscateEmail($mail, $replace="*", $nbreplace=8, $nbdisplaymail=4, $nbdisplaydomain=3, $displaytld=true) function dolObfuscateEmail($mail, $replace="*", $nbreplace=8, $nbdisplaymail=4, $nbdisplaydomain=3, $displaytld=true)
{ {
if(!isValidEmail($mail))return ''; if(!isValidEmail($mail))return '';
$tab = explode('@', $mail); $tab = explode('@', $mail);
$tab2 = explode('.',$tab[1]); $tab2 = explode('.',$tab[1]);
$string_replace = ''; $string_replace = '';
$mail_name = $tab[0]; $mail_name = $tab[0];
$mail_domaine = $tab2[0]; $mail_domaine = $tab2[0];
$mail_tld = ''; $mail_tld = '';
for($i=1; $i < count($tab2) && $displaytld ;$i++) for($i=1; $i < count($tab2) && $displaytld ;$i++)
{ {
$mail_tld .= '.'.$tab2[$i]; $mail_tld .= '.'.$tab2[$i];
} }
for($i=0; $i < $nbreplace; $i++){ for($i=0; $i < $nbreplace; $i++){
$string_replace .= $replace; $string_replace .= $replace;
} }
if(strlen($mail_name) > $nbdisplaymail){ if(strlen($mail_name) > $nbdisplaymail){
$mail_name = substr($mail_name, 0, $nbdisplaymail); $mail_name = substr($mail_name, 0, $nbdisplaymail);
} }
if(strlen($mail_domaine) > $nbdisplaydomain){ if(strlen($mail_domaine) > $nbdisplaydomain){
$mail_domaine = substr($mail_domaine, strlen($mail_domaine)-$nbdisplaydomain); $mail_domaine = substr($mail_domaine, strlen($mail_domaine)-$nbdisplaydomain);
} }
return $mail_name . $string_replace . $mail_domaine . $mail_tld; return $mail_name . $string_replace . $mail_domaine . $mail_tld;
} }
/** /**