3 function mailcrypt_init() {
7 // pour _cs_liens_AUTORISE
8 include_spip('outils/inc_cs_liens');
9 // tip visible onMouseOver (title)
10 // jQuery replacera ensuite le '@' comme ceci : title.replace(/\.\..t\.\./,'[\x40]')
11 @define
('_mailcrypt_AROBASE_JS', '..åt..');
12 @define
('_mailcrypt_AROBASE_JSQ', preg_quote(_mailcrypt_AROBASE_JS
,','));
13 // span ayant l'arobase en background
14 @define
('_mailcrypt_AROBASE', '<span class=\'spancrypt\'> </span>');
15 // @define('_mailcrypt_REGEXPR1', ',\b['._cs_liens_AUTORISE.']*@[a-zA-Z][a-zA-Z0-9-.]*\.[a-zA-Z]+(\?['._cs_liens_AUTORISE.']*)?,');
16 @define
('_mailcrypt_REGEXPR2', ',\b(['._cs_liens_AUTORISE
.']+)@([a-zA-Z][a-zA-Z0-9-.]*\.[a-zA-Z]+(\?['._cs_liens_AUTORISE
.']*)?),');
20 // filtre surchargeable pour la balise #EMAIL protegee en public mais pas en prive
21 function mailcrypt_email_dist($texte) {
22 if(strpos($texte, '@')===false) return $texte;
23 if(function_exists('mailcrypt_email')) return mailcrypt_email($texte);
24 return test_espace_prive()?
$texte:mailcrypt($texte);
27 function mailcrypt($texte) {
28 if(strpos($texte, '@')===false) return $texte;
31 // echappement des 'input' au cas ou le serveur y injecte des mails persos
32 if (strpos($texte, '<in')!==false)
33 $texte = preg_replace_callback(',<input [^<]+/>,Umsi', 'cs_liens_echappe_callback', $texte);
34 // echappement des 'protoc://login:mdp@site.ici' afin ne pas les confondre avec un mail
35 if(strpos($texte, '://')!==false)
36 $texte = preg_replace_callback(',[a-z0-9]+://['._cs_liens_AUTORISE
.']+:['._cs_liens_AUTORISE
.']+@,Umsi', 'cs_liens_echappe_callback', $texte);
37 // echappement des domaines .htm/.html : ce ne sont pas des mails
38 if(strpos($texte, '.htm')!==false)
39 $texte = preg_replace_callback(',href=(["\'])[^>]*@[^>]*\.html?\\1,', 'cs_liens_echappe_callback', $texte);
41 // protection des liens HTML
42 $texte = preg_replace(",[\"\']mailto:([^@\"']+)@([^\"']+)[\"\'],",
43 '"#" title="$1' . _mailcrypt_AROBASE_JS
. '$2" onclick="location.href=lancerlien(\'$1\',\'$2\'); return false;"', $texte);
44 // retrait des titles en doublon... un peu sale, mais en attendant mieux ?
45 $texte = preg_replace(',title="[^"]+'._mailcrypt_AROBASE_JSQ
.'[^"]+"([^>]+title=[\"\']),', '$1', $texte);
47 if(strpos($texte, '@')===false) return echappe_retour($texte, 'LIENS');
48 // protection de tout le reste...
49 $texte = preg_replace(_mailcrypt_REGEXPR2
, '$1'._mailcrypt_AROBASE
.'$2', $texte);
50 return echappe_retour($texte, 'LIENS');
53 function maildecrypt($texte) {
54 if(strpos($texte, 'spancrypt')===false && strpos($texte, 'lancerlien')===false) return $texte;
57 // traiter les <span class='spancrypt'>chez</span>
58 $texte = preg_replace(',<span class=[\'"]spancrypt[\'"]>(.*)</span>,U','@',$texte);
60 $texte = preg_replace(
61 ',href="#" (title=["\'].*?["\']) onclick="location.href=lancerlien\(\'(\S*?)\'\,\'(\S*?)\'\); return false;",',
62 '$1 href="mailto:$2@$3"', $texte);
64 return str_replace(_mailcrypt_AROBASE_JS
, '@', $texte);