Rev 277 | Rev 386 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
250 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
20 | class OIDplusMailUtils { |
||
21 | |||
22 | public static function validMailAddress($email) { |
||
23 | return !empty(filter_var($email, FILTER_VALIDATE_EMAIL)); |
||
24 | } |
||
360 | daniel-mar | 25 | |
250 | daniel-mar | 26 | public static function secureEmailAddress($email, $linktext, $level=1) { |
360 | daniel-mar | 27 | |
250 | daniel-mar | 28 | // see http://www.spamspan.de/ |
360 | daniel-mar | 29 | |
250 | daniel-mar | 30 | /* Level 1 */ |
31 | /* |
||
32 | <span class="spamspan"> |
||
33 | <span class="u">user</span> |
||
34 | @ |
||
35 | <span class="d">beispiel.de</span> |
||
36 | (<span class="t">Spam Hasser</span>) |
||
37 | </span> |
||
38 | */ |
||
360 | daniel-mar | 39 | |
250 | daniel-mar | 40 | if ($level == 1) { |
41 | @list($user, $domain) = explode('@', $email); |
||
42 | if (($linktext == $email) || empty($linktext)) { |
||
43 | return '<span class="spamspan"><span class="u">'.htmlentities($user).'</span>@<span class="d">'.htmlentities($domain).'</span></span>'; |
||
44 | } else { |
||
45 | return '<span class="spamspan"><span class="u">'.htmlentities($user).'</span>@<span class="d">'.htmlentities($domain).'</span>(<span class="t">'.htmlentities($linktext).'</span>)</span>'; |
||
46 | } |
||
47 | } |
||
360 | daniel-mar | 48 | |
250 | daniel-mar | 49 | /* Level 2 */ |
50 | /* |
||
51 | <span class="spamspan"> |
||
52 | <span class="u">user</span> |
||
53 | <img alt="at" width="10" src="@.png"> |
||
54 | <span class="d">beispiel.de</span> |
||
55 | </span> |
||
56 | */ |
||
360 | daniel-mar | 57 | |
250 | daniel-mar | 58 | if ($level == 2) { |
59 | list($user, $domain) = explode('@', $email); |
||
60 | return '<span class="spamspan"><span class="u">'.htmlentities($user).'</span><img alt="at" width="10" src="@.png"><span class="d">'.htmlentities($domain).'</span></span>'; |
||
61 | } |
||
360 | daniel-mar | 62 | |
250 | daniel-mar | 63 | /* Level 3 */ |
64 | /* |
||
65 | <span class="spamspan"> |
||
66 | <span class="u">user</span> |
||
67 | [at] |
||
68 | <span class="d">beispiel [dot] de</span> |
||
69 | </span> |
||
70 | */ |
||
360 | daniel-mar | 71 | |
250 | daniel-mar | 72 | if ($level == 3) { |
73 | list($user, $domain) = explode('@', $email); |
||
360 | daniel-mar | 74 | $domain = str_replace('.', ' '._L('[dot]').' ', $domain); |
75 | return '<span class="spamspan"><span class="u">'.htmlentities($user).'</span> '._L('[at]').' <span class="d">'.htmlentities($domain).'</span></span>'; |
||
250 | daniel-mar | 76 | } |
360 | daniel-mar | 77 | |
250 | daniel-mar | 78 | return null; |
360 | daniel-mar | 79 | |
80 | |||
250 | daniel-mar | 81 | // --- Old code --- |
360 | daniel-mar | 82 | |
250 | daniel-mar | 83 | // Attention: document.write() JavaScript will damage the browser cache, which leads to bugs if you navigate back&forth with the browser navigation |
360 | daniel-mar | 84 | |
250 | daniel-mar | 85 | // No new lines to avoid a JavaScript error! |
86 | $linktext = str_replace("\r", ' ', $linktext); |
||
87 | $linktext = str_replace("\n", ' ', $linktext); |
||
360 | daniel-mar | 88 | |
250 | daniel-mar | 89 | if (!function_exists('alas_js_crypt')) |
90 | { |
||
91 | function alas_js_crypt($text) |
||
92 | { |
||
93 | $tmp = ''; |
||
94 | for ($i=0; $i<strlen($text); $i++) |
||
95 | { |
||
96 | $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");'; |
||
97 | } |
||
98 | return $tmp; |
||
99 | } |
||
100 | } |
||
360 | daniel-mar | 101 | |
250 | daniel-mar | 102 | if (!function_exists('alas_js_write')) |
103 | { |
||
104 | function alas_js_write($text) |
||
105 | { |
||
106 | $text = str_replace('\\', '\\\\', $text); |
||
107 | $text = str_replace('"', '\"', $text); |
||
108 | $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a> |
||
109 | return 'document.write("'.$text.'");'; |
||
110 | } |
||
111 | } |
||
360 | daniel-mar | 112 | |
250 | daniel-mar | 113 | $aus = ''; |
114 | if ($email != '') |
||
115 | { |
||
116 | $aus .= '<script><!--'."\n"; // type="text/javascript" is not necessary in HTML5 |
||
117 | $aus .= alas_js_write('<a href="'); |
||
118 | $aus .= alas_js_crypt('mailto:'.$email); |
||
119 | $aus .= alas_js_write('">'); |
||
120 | $aus .= $crypt_linktext ? alas_js_crypt($linktext) : alas_js_write($linktext); |
||
121 | $aus .= alas_js_write('</a>').'// --></script>'; |
||
122 | } |
||
360 | daniel-mar | 123 | |
250 | daniel-mar | 124 | if ($crypt_linktext) $linktext = str_replace('@', '&', $linktext); |
125 | $email = str_replace('@', '&', $email); |
||
126 | return $aus.'<noscript>'.htmlentities($linktext).' ('.htmlentities($email).')</noscript>'; |
||
127 | } |
||
360 | daniel-mar | 128 | |
250 | daniel-mar | 129 | public static function sendMail($to, $title, $msg, $cc='', $bcc='') { |
130 | $h = new SecureMailer(); |
||
360 | daniel-mar | 131 | |
250 | daniel-mar | 132 | $title = $title; |
360 | daniel-mar | 133 | |
250 | daniel-mar | 134 | $h->addHeader('From', OIDplus::config()->getValue('admin_email')); |
360 | daniel-mar | 135 | |
250 | daniel-mar | 136 | if (!empty($cc)) $h->addHeader('Cc', $cc); |
137 | if (!empty($bcc)) $h->addHeader('Bcc', $bcc); |
||
360 | daniel-mar | 138 | |
250 | daniel-mar | 139 | $h->addHeader('X-Mailer', 'PHP/'.phpversion()); |
140 | if (isset($_SERVER['REMOTE_ADDR'])) $h->addHeader('X-RemoteAddr', $_SERVER['REMOTE_ADDR']); |
||
141 | $h->addHeader('MIME-Version', '1.0'); |
||
142 | $h->addHeader('Content-Type', 'text/plain; charset=ISO-8859-1'); |
||
360 | daniel-mar | 143 | |
250 | daniel-mar | 144 | $sent = $h->sendMail($to, $title, $msg); |
145 | if (!$sent) { |
||
360 | daniel-mar | 146 | throw new OIDplusMailException(_L('Sending mail failed')); |
250 | daniel-mar | 147 | } |
148 | } |
||
149 | |||
360 | daniel-mar | 150 | } |