1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 13 14 15 16
17 abstract class JHtmlEmail
18 {
19 20 21 22 23 24 25 26 27 28 29 30 31 32
33 public static function cloak($mail, $mailto = true, $text = '', $email = true)
34 {
35
36 if ($mailto && (empty($text) || $email))
37 {
38
39 $text = JStringPunycode::emailToUTF8($text ?: $mail);
40 }
41 elseif (!$mailto)
42 {
43
44 $mail = JStringPunycode::emailToUTF8($mail);
45 }
46
47
48 $mail = static::convertEncoding($mail);
49
50
51 $rand = md5($mail . mt_rand(1, 100000));
52
53
54 $mail = explode('@', $mail);
55 $mail_parts = explode('.', $mail[1]);
56
57 if ($mailto)
58 {
59
60 if ($text)
61 {
62
63 $text = static::convertEncoding($text);
64
65 if ($email)
66 {
67
68 $text = explode('@', $text);
69 $text_parts = explode('.', $text[1]);
70 $tmpScript = "var addy_text" . $rand . " = '" . @$text[0] . "' + '@' + '" . implode("' + '.' + '", @$text_parts)
71 . "';";
72 }
73 else
74 {
75 $tmpScript = "var addy_text" . $rand . " = '" . $text . "';";
76 }
77
78 $tmpScript .= "document.getElementById('cloak" . $rand . "').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy"
79 . $rand . " + '\'>'+addy_text" . $rand . "+'<\/a>';";
80 }
81 else
82 {
83 $tmpScript = "document.getElementById('cloak" . $rand . "').innerHTML += '<a ' + path + '\'' + prefix + ':' + addy"
84 . $rand . " + '\'>' +addy" . $rand . "+'<\/a>';";
85 }
86 }
87 else
88 {
89 $tmpScript = "document.getElementById('cloak" . $rand . "').innerHTML += addy" . $rand . ";";
90 }
91
92 $script = "
93 document.getElementById('cloak" . $rand . "').innerHTML = '';
94 var prefix = 'ma' + 'il' + 'to';
95 var path = 'hr' + 'ef' + '=';
96 var addy" . $rand . " = '" . @$mail[0] . "' + '@';
97 addy" . $rand . " = addy" . $rand . " + '" . implode("' + '.' + '", $mail_parts) . "';
98 $tmpScript
99 ";
100
101
102 $inlineScript = "<script type='text/javascript'>" . $script . "</script>";
103
104 return '<span id="cloak' . $rand . '">' . JText::_('JLIB_HTML_CLOAKING') . '</span>' . $inlineScript;
105 }
106
107 108 109 110 111 112 113 114 115
116 protected static function convertEncoding($text)
117 {
118 $text = html_entity_decode($text);
119
120
121 $text = str_replace('a', 'a', $text);
122 $text = str_replace('e', 'e', $text);
123 $text = str_replace('i', 'i', $text);
124 $text = str_replace('o', 'o', $text);
125 $text = str_replace('u', 'u', $text);
126 $text = htmlentities($text, ENT_QUOTES, 'UTF-8', false);
127
128 return $text;
129 }
130 }
131