Rev 444 | Rev 730 | 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 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
250 | daniel-mar | 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 | |||
511 | daniel-mar | 20 | if (!defined('INSIDE_OIDPLUS')) die(); |
21 | |||
250 | daniel-mar | 22 | class OIDplusMailUtils { |
23 | |||
24 | public static function validMailAddress($email) { |
||
25 | return !empty(filter_var($email, FILTER_VALIDATE_EMAIL)); |
||
26 | } |
||
360 | daniel-mar | 27 | |
250 | daniel-mar | 28 | public static function secureEmailAddress($email, $linktext, $level=1) { |
360 | daniel-mar | 29 | |
250 | daniel-mar | 30 | // see http://www.spamspan.de/ |
360 | daniel-mar | 31 | |
250 | daniel-mar | 32 | /* Level 1 */ |
33 | /* |
||
34 | <span class="spamspan"> |
||
35 | <span class="u">user</span> |
||
36 | @ |
||
37 | <span class="d">beispiel.de</span> |
||
38 | (<span class="t">Spam Hasser</span>) |
||
39 | </span> |
||
40 | */ |
||
360 | daniel-mar | 41 | |
250 | daniel-mar | 42 | if ($level == 1) { |
43 | @list($user, $domain) = explode('@', $email); |
||
44 | if (($linktext == $email) || empty($linktext)) { |
||
45 | return '<span class="spamspan"><span class="u">'.htmlentities($user).'</span>@<span class="d">'.htmlentities($domain).'</span></span>'; |
||
46 | } else { |
||
47 | return '<span class="spamspan"><span class="u">'.htmlentities($user).'</span>@<span class="d">'.htmlentities($domain).'</span>(<span class="t">'.htmlentities($linktext).'</span>)</span>'; |
||
48 | } |
||
49 | } |
||
360 | daniel-mar | 50 | |
250 | daniel-mar | 51 | /* Level 2 */ |
52 | /* |
||
53 | <span class="spamspan"> |
||
54 | <span class="u">user</span> |
||
55 | <img alt="at" width="10" src="@.png"> |
||
56 | <span class="d">beispiel.de</span> |
||
57 | </span> |
||
58 | */ |
||
360 | daniel-mar | 59 | |
250 | daniel-mar | 60 | if ($level == 2) { |
61 | list($user, $domain) = explode('@', $email); |
||
62 | return '<span class="spamspan"><span class="u">'.htmlentities($user).'</span><img alt="at" width="10" src="@.png"><span class="d">'.htmlentities($domain).'</span></span>'; |
||
63 | } |
||
360 | daniel-mar | 64 | |
250 | daniel-mar | 65 | /* Level 3 */ |
66 | /* |
||
67 | <span class="spamspan"> |
||
68 | <span class="u">user</span> |
||
69 | [at] |
||
70 | <span class="d">beispiel [dot] de</span> |
||
71 | </span> |
||
72 | */ |
||
360 | daniel-mar | 73 | |
250 | daniel-mar | 74 | if ($level == 3) { |
75 | list($user, $domain) = explode('@', $email); |
||
360 | daniel-mar | 76 | $domain = str_replace('.', ' '._L('[dot]').' ', $domain); |
77 | return '<span class="spamspan"><span class="u">'.htmlentities($user).'</span> '._L('[at]').' <span class="d">'.htmlentities($domain).'</span></span>'; |
||
250 | daniel-mar | 78 | } |
360 | daniel-mar | 79 | |
250 | daniel-mar | 80 | return null; |
360 | daniel-mar | 81 | |
82 | |||
250 | daniel-mar | 83 | // --- Old code --- |
360 | daniel-mar | 84 | |
386 | daniel-mar | 85 | /* |
250 | daniel-mar | 86 | // Attention: document.write() JavaScript will damage the browser cache, which leads to bugs if you navigate back&forth with the browser navigation |
400 | daniel-mar | 87 | |
386 | daniel-mar | 88 | $crypt_linktext = true; |
360 | daniel-mar | 89 | |
250 | daniel-mar | 90 | // No new lines to avoid a JavaScript error! |
91 | $linktext = str_replace("\r", ' ', $linktext); |
||
92 | $linktext = str_replace("\n", ' ', $linktext); |
||
360 | daniel-mar | 93 | |
250 | daniel-mar | 94 | if (!function_exists('alas_js_crypt')) |
95 | { |
||
96 | function alas_js_crypt($text) |
||
97 | { |
||
98 | $tmp = ''; |
||
99 | for ($i=0; $i<strlen($text); $i++) |
||
100 | { |
||
101 | $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");'; |
||
102 | } |
||
103 | return $tmp; |
||
104 | } |
||
105 | } |
||
360 | daniel-mar | 106 | |
250 | daniel-mar | 107 | if (!function_exists('alas_js_write')) |
108 | { |
||
109 | function alas_js_write($text) |
||
110 | { |
||
111 | $text = str_replace('\\', '\\\\', $text); |
||
112 | $text = str_replace('"', '\"', $text); |
||
113 | $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a> |
||
114 | return 'document.write("'.$text.'");'; |
||
115 | } |
||
116 | } |
||
360 | daniel-mar | 117 | |
250 | daniel-mar | 118 | $aus = ''; |
119 | if ($email != '') |
||
120 | { |
||
121 | $aus .= '<script><!--'."\n"; // type="text/javascript" is not necessary in HTML5 |
||
122 | $aus .= alas_js_write('<a href="'); |
||
123 | $aus .= alas_js_crypt('mailto:'.$email); |
||
124 | $aus .= alas_js_write('">'); |
||
125 | $aus .= $crypt_linktext ? alas_js_crypt($linktext) : alas_js_write($linktext); |
||
126 | $aus .= alas_js_write('</a>').'// --></script>'; |
||
127 | } |
||
360 | daniel-mar | 128 | |
250 | daniel-mar | 129 | if ($crypt_linktext) $linktext = str_replace('@', '&', $linktext); |
130 | $email = str_replace('@', '&', $email); |
||
131 | return $aus.'<noscript>'.htmlentities($linktext).' ('.htmlentities($email).')</noscript>'; |
||
400 | daniel-mar | 132 | |
386 | daniel-mar | 133 | */ |
250 | daniel-mar | 134 | } |
360 | daniel-mar | 135 | |
250 | daniel-mar | 136 | public static function sendMail($to, $title, $msg, $cc='', $bcc='') { |
137 | $h = new SecureMailer(); |
||
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 | |
444 | daniel-mar | 144 | $h->addHeader('X-Mailer', 'PHP/'.PHP_VERSION); |
250 | daniel-mar | 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 | } |