Rev 360 | Rev 400 | 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 | |
386 | daniel-mar | 83 | /* |
250 | daniel-mar | 84 | // Attention: document.write() JavaScript will damage the browser cache, which leads to bugs if you navigate back&forth with the browser navigation |
386 | daniel-mar | 85 | |
86 | $crypt_linktext = true; |
||
360 | daniel-mar | 87 | |
250 | daniel-mar | 88 | // No new lines to avoid a JavaScript error! |
89 | $linktext = str_replace("\r", ' ', $linktext); |
||
90 | $linktext = str_replace("\n", ' ', $linktext); |
||
360 | daniel-mar | 91 | |
250 | daniel-mar | 92 | if (!function_exists('alas_js_crypt')) |
93 | { |
||
94 | function alas_js_crypt($text) |
||
95 | { |
||
96 | $tmp = ''; |
||
97 | for ($i=0; $i<strlen($text); $i++) |
||
98 | { |
||
99 | $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");'; |
||
100 | } |
||
101 | return $tmp; |
||
102 | } |
||
103 | } |
||
360 | daniel-mar | 104 | |
250 | daniel-mar | 105 | if (!function_exists('alas_js_write')) |
106 | { |
||
107 | function alas_js_write($text) |
||
108 | { |
||
109 | $text = str_replace('\\', '\\\\', $text); |
||
110 | $text = str_replace('"', '\"', $text); |
||
111 | $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a> |
||
112 | return 'document.write("'.$text.'");'; |
||
113 | } |
||
114 | } |
||
360 | daniel-mar | 115 | |
250 | daniel-mar | 116 | $aus = ''; |
117 | if ($email != '') |
||
118 | { |
||
119 | $aus .= '<script><!--'."\n"; // type="text/javascript" is not necessary in HTML5 |
||
120 | $aus .= alas_js_write('<a href="'); |
||
121 | $aus .= alas_js_crypt('mailto:'.$email); |
||
122 | $aus .= alas_js_write('">'); |
||
123 | $aus .= $crypt_linktext ? alas_js_crypt($linktext) : alas_js_write($linktext); |
||
124 | $aus .= alas_js_write('</a>').'// --></script>'; |
||
125 | } |
||
360 | daniel-mar | 126 | |
250 | daniel-mar | 127 | if ($crypt_linktext) $linktext = str_replace('@', '&', $linktext); |
128 | $email = str_replace('@', '&', $email); |
||
129 | return $aus.'<noscript>'.htmlentities($linktext).' ('.htmlentities($email).')</noscript>'; |
||
386 | daniel-mar | 130 | |
131 | */ |
||
250 | daniel-mar | 132 | } |
360 | daniel-mar | 133 | |
250 | daniel-mar | 134 | public static function sendMail($to, $title, $msg, $cc='', $bcc='') { |
135 | $h = new SecureMailer(); |
||
360 | daniel-mar | 136 | |
250 | daniel-mar | 137 | $title = $title; |
360 | daniel-mar | 138 | |
250 | daniel-mar | 139 | $h->addHeader('From', OIDplus::config()->getValue('admin_email')); |
360 | daniel-mar | 140 | |
250 | daniel-mar | 141 | if (!empty($cc)) $h->addHeader('Cc', $cc); |
142 | if (!empty($bcc)) $h->addHeader('Bcc', $bcc); |
||
360 | daniel-mar | 143 | |
250 | daniel-mar | 144 | $h->addHeader('X-Mailer', 'PHP/'.phpversion()); |
145 | if (isset($_SERVER['REMOTE_ADDR'])) $h->addHeader('X-RemoteAddr', $_SERVER['REMOTE_ADDR']); |
||
146 | $h->addHeader('MIME-Version', '1.0'); |
||
147 | $h->addHeader('Content-Type', 'text/plain; charset=ISO-8859-1'); |
||
360 | daniel-mar | 148 | |
250 | daniel-mar | 149 | $sent = $h->sendMail($to, $title, $msg); |
150 | if (!$sent) { |
||
360 | daniel-mar | 151 | throw new OIDplusMailException(_L('Sending mail failed')); |
250 | daniel-mar | 152 | } |
153 | } |
||
154 | |||
360 | daniel-mar | 155 | } |