[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / couteau_suisse / couteau_suisse / outils / mailcrypt_fonctions.php
1 <?php
2
3 function mailcrypt_init() {
4 static $ok = NULL;
5 if(is_null($ok)) {
6 $ok = true;
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', '..&aring;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\'>&nbsp;</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.']*)?),');
17 }
18 }
19
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);
25 }
26
27 function mailcrypt($texte) {
28 if(strpos($texte, '@')===false) return $texte;
29 mailcrypt_init();
30
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);
40
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);
46
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');
51 }
52
53 function maildecrypt($texte) {
54 if(strpos($texte, 'spancrypt')===false && strpos($texte, 'lancerlien')===false) return $texte;
55 mailcrypt_init();
56
57 // traiter les <span class='spancrypt'>chez</span>
58 $texte = preg_replace(',<span class=[\'"]spancrypt[\'"]>(.*)</span>,U','@',$texte);
59 // traiter les liens
60 $texte = preg_replace(
61 ',href="#" (title=["\'].*?["\']) onclick="location.href=lancerlien\(\'(\S*?)\'\,\'(\S*?)\'\); return false;",',
62 '$1 href="mailto:$2@$3"', $texte);
63 // traiter les title
64 return str_replace(_mailcrypt_AROBASE_JS, '@', $texte);
65 }
66 ?>