Revision 1208
Added by Dietmar over 14 years ago
filter-routines.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2009, Ryan Djurovich |
|
9 |
|
|
10 |
Website Baker is free software; you can redistribute it and/or modify |
|
11 |
it under the terms of the GNU General Public License as published by |
|
12 |
the Free Software Foundation; either version 2 of the License, or |
|
13 |
(at your option) any later version. |
|
14 |
|
|
15 |
Website Baker is distributed in the hope that it will be useful, |
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
GNU General Public License for more details. |
|
19 |
|
|
20 |
You should have received a copy of the GNU General Public License |
|
21 |
along with Website Baker; if not, write to the Free Software |
|
22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
|
|
24 |
*/ |
|
25 |
|
|
26 |
// prevent this file from being accessed directly |
|
27 |
if(!defined('WB_PATH')) die(header('Location: ../index.php')); |
|
28 |
|
|
29 |
// function to read the current filter settings |
|
30 |
if (!function_exists('get_output_filter_settings')) { |
|
31 |
function get_output_filter_settings() { |
|
32 |
global $database, $admin; |
|
33 |
// connect to database and read out filter settings |
|
34 |
$result = $database->query("SELECT * FROM " .TABLE_PREFIX ."mod_output_filter"); |
|
35 |
if($result && $result->numRows() > 0) { |
|
36 |
// get all data |
|
37 |
$data = $result->fetchRow(); |
|
38 |
$filter_settings['email_filter'] = $admin->strip_slashes($data['email_filter']); |
|
39 |
$filter_settings['mailto_filter'] = $admin->strip_slashes($data['mailto_filter']); |
|
40 |
$filter_settings['at_replacement'] = $admin->strip_slashes($data['at_replacement']); |
|
41 |
$filter_settings['dot_replacement'] = $admin->strip_slashes($data['dot_replacement']); |
|
42 |
} else { |
|
43 |
// something went wrong, use default values |
|
44 |
$filter_settings['email_filter'] = '0'; |
|
45 |
$filter_settings['mailto_filter'] = '0'; |
|
46 |
$filter_settings['at_replacement'] = '(at)'; |
|
47 |
$filter_settings['dot_replacement'] = '(dot)'; |
|
48 |
} |
|
49 |
|
|
50 |
// return array with filter settings |
|
51 |
return $filter_settings; |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
// function to filter the output before displaying it on the frontend |
|
56 |
if (!function_exists('filter_frontend_output')) { |
|
57 |
function filter_frontend_output($content) { |
|
58 |
// get output filter settings from database |
|
59 |
$filter_settings = get_output_filter_settings(); |
|
60 |
|
|
61 |
// work out the defined output filter mode: possible output filter modes: [0], 1, 2, 3, 6, 7 |
|
62 |
// 2^0 * (0.. disable, 1.. enable) filtering of mail addresses in text |
|
63 |
// 2^1 * (0.. disable, 1.. enable) filtering of mail addresses in mailto links |
|
64 |
// 2^2 * (0.. disable, 1.. enable) Javascript mailto encryption (only if mailto filtering enabled) |
|
65 |
|
|
66 |
// only filter output if we are supposed to |
|
67 |
if($filter_settings['email_filter'] != '1' && $filter_settings['mailto_filter'] != '1'){ |
|
68 |
// nothing to do ... |
|
69 |
return $content; |
|
70 |
} |
|
71 |
|
|
72 |
// check if non mailto mail addresses needs to be filtered |
|
73 |
$output_filter_mode = ($filter_settings['email_filter'] == '1') ? 1 : 0; // 0|1 |
|
74 |
|
|
75 |
// check if mailto mail addresses needs to be filtered |
|
76 |
if($filter_settings['mailto_filter'] == '1') { |
|
77 |
$output_filter_mode = $output_filter_mode + 2; // 0|2 |
|
78 |
|
|
79 |
// check if Javascript mailto encryption is enabled (call register_frontend_functions in the template) |
|
80 |
$search = '<script type="text/javascript" src="' .WB_URL .'/modules/output_filter/js/mdcr.js"></script>'; |
|
81 |
$search_droplet = '<script type="text/javascript" src="' .WB_URL .'/modules/droplets/js/mdcr.js"></script>'; |
|
82 |
if(strpos($content, $search) !== false || strpos($content, $search_droplet) !== false) { |
|
83 |
$output_filter_mode = $output_filter_mode + 4; // 0|4 |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
// define some constants so we do not call the database in the callback function again |
|
88 |
define('OUTPUT_FILTER_MODE', (int) $output_filter_mode); |
|
89 |
define('OUTPUT_FILTER_AT_REPLACEMENT', $filter_settings['at_replacement']); |
|
90 |
define('OUTPUT_FILTER_DOT_REPLACEMENT', $filter_settings['dot_replacement']); |
|
91 |
|
|
92 |
// first search part to find all mailto email addresses |
|
93 |
$pattern = '#(<a[^<]*href\s*?=\s*?"\s*?mailto\s*?:\s*?)([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4})([^"]*?)"([^>]*>)(.*?)</a>'; |
|
94 |
// second part to find all non mailto email addresses |
|
95 |
$pattern .= '|(value\s*=\s*"|\')??\b([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4})\b#i'; |
|
96 |
/* |
|
97 |
Sub 1:\b(<a.[^<]*href\s*?=\s*?"\s*?mailto\s*?:\s*?) --> "<a id="yyy" class="xxx" href = " mailto :" ignoring white spaces |
|
98 |
Sub 2:([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}) --> the email address in the mailto: part of the mail link |
|
99 |
Sub 3:([^"]*?)" --> possible ?Subject&cc... stuff attached to the mail address |
|
100 |
Sub 4:([^>]*>) --> all class or id statements after the mailto but before closing ..> |
|
101 |
Sub 5:(.*?)</a>\b --> the mailto text; all characters between >xxxxx</a> |
|
102 |
Sub 6:|\b([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4})\b --> email addresses which may appear in the text (require word boundaries) |
|
103 |
*/ |
|
104 |
|
|
105 |
// find all email addresses embedded in the content and filter them using a callback function |
|
106 |
$content = preg_replace_callback($pattern, 'filter_mail_addresses', $content); |
|
107 |
return $content; |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
|
|
112 |
// function to filter mail addresses embedded in text or mailto links before outputing them on the frontend |
|
113 |
if (!function_exists('filter_mail_addresses')) { |
|
114 |
function filter_mail_addresses($match) { |
|
115 |
|
|
116 |
// check if required output filter mode is defined |
|
117 |
if(!(defined('OUTPUT_FILTER_MODE') && defined('OUTPUT_FILTER_MODE') && defined('OUTPUT_FILTER_MODE'))) { |
|
118 |
return $match[0]; |
|
119 |
} |
|
120 |
|
|
121 |
$search = array('@', '.'); |
|
122 |
$replace = array(OUTPUT_FILTER_AT_REPLACEMENT ,OUTPUT_FILTER_DOT_REPLACEMENT); |
|
123 |
|
|
124 |
// check if the match contains the expected number of subpatterns (6|8) |
|
125 |
if(count($match) == 8) { |
|
126 |
/** |
|
127 |
OUTPUT FILTER FOR EMAIL ADDRESSES EMBEDDED IN TEXT |
|
128 |
**/ |
|
129 |
|
|
130 |
// 1.. text mails only, 3.. text mails + mailto (no JS), 7 text mails + mailto (JS) |
|
131 |
if(!in_array(OUTPUT_FILTER_MODE, array(1,3,7))) return $match[0]; |
|
132 |
|
|
133 |
// do not filter mail addresses included in input tags (<input ... value = "test@mail) |
|
134 |
if (strpos($match[6], 'value') !== false) return $match[0]; |
|
135 |
|
|
136 |
// filtering of non mailto email addresses enabled |
|
137 |
return str_replace($search, $replace, $match[0]); |
|
138 |
|
|
139 |
} elseif(count($match) == 6) { |
|
140 |
/** |
|
141 |
OUTPUT FILTER FOR EMAIL ADDRESSES EMBEDDED IN MAILTO LINKS |
|
142 |
**/ |
|
143 |
|
|
144 |
// 2.. mailto only (no JS), 3.. text mails + mailto (no JS), 6.. mailto only (JS), 7.. all filters active |
|
145 |
if(!in_array(OUTPUT_FILTER_MODE, array(2,3,6,7))) return $match[0]; |
|
146 |
|
|
147 |
// check if last part of the a href link: >xxxx</a> contains a email address we need to filter |
|
148 |
$pattern = '#[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}#i'; |
|
149 |
if(preg_match_all($pattern, $match[5], $matches)) { |
|
150 |
foreach($matches as $submatch) { |
|
151 |
foreach($submatch as $value) { |
|
152 |
// replace all . and all @ in email address parts by (dot) and (at) strings |
|
153 |
$match[5] = str_replace($value, str_replace($search, $replace, $value), $match[5]); |
|
154 |
} |
|
155 |
} |
|
156 |
} |
|
157 |
|
|
158 |
// check if Javascript encryption routine is enabled |
|
159 |
if(in_array(OUTPUT_FILTER_MODE, array(6,7))) { |
|
160 |
/** USE JAVASCRIPT ENCRYPTION FOR MAILTO LINKS **/ |
|
161 |
|
|
162 |
// extract possible class and id attribute from ahref link |
|
163 |
preg_match('/class\s*?=\s*?("|\')(.*?)\1/ix', $match[0], $class_attr); |
|
164 |
$class_attr = empty($class_attr) ? '' : 'class="' . $class_attr[2] . '" '; |
|
165 |
preg_match('/id\s*?=\s*?("|\')(.*?)\1/ix', $match[0], $id_attr); |
|
166 |
$id_attr = empty($id_attr) ? '' : 'id="' . $id_attr[2] . '" '; |
|
167 |
|
|
168 |
// preprocess mailto link parts for further usage |
|
169 |
$search = array('@', '.', '_', '-'); $replace = array('F', 'Z', 'X', 'K'); |
|
170 |
$email_address = str_replace($search, $replace, strtolower($match[2])); |
|
171 |
$email_subject = rawurlencode(html_entity_decode($match[3])); |
|
172 |
|
|
173 |
// create a random encryption key for the Caesar cipher |
|
174 |
mt_srand((double)microtime()*1000000); // (PHP < 4.2.0) |
|
175 |
$shift = mt_rand(1, 25); |
|
176 |
|
|
177 |
// encrypt the email using an adapted Caesar cipher |
|
178 |
$encrypted_email = ""; |
|
179 |
for($i = strlen($email_address) -1; $i > -1; $i--) { |
|
180 |
if(preg_match('#[FZXK0-9]#', $email_address[$i], $characters)) { |
|
181 |
$encrypted_email .= $email_address[$i]; |
|
182 |
} else { |
|
183 |
$encrypted_email .= chr((ord($email_address[$i]) -97 + $shift) % 26 + 97); |
|
184 |
} |
|
185 |
} |
|
186 |
$encrypted_email .= chr($shift + 97); |
|
187 |
|
|
188 |
// build the encrypted Javascript mailto link |
|
189 |
$mailto_link = "<a {$class_attr}{$id_attr}href=\"javascript:mdcr('$encrypted_email','$email_subject')\">" .$match[5] ."</a>"; |
|
190 |
|
|
191 |
return $mailto_link; |
|
192 |
|
|
193 |
} else { |
|
194 |
/** DO NOT USE JAVASCRIPT ENCRYPTION FOR MAILTO LINKS **/ |
|
195 |
|
|
196 |
// as minimum protection, replace replace @ in the mailto part by (at) |
|
197 |
// dots are not transformed as this would transform my.name@domain.com into: my(dot)name(at)domain(dot)com |
|
198 |
|
|
199 |
// rebuild the mailto link from the subpatterns (at the missing characters " and </a>") |
|
200 |
return $match[1] .str_replace('@', OUTPUT_FILTER_AT_REPLACEMENT, $match[2]) .$match[3] .'"' .$match[4] .$match[5] .'</a>'; |
|
201 |
// if you want to protect both, @ and dots, comment out the line above and remove the comment from the line below |
|
202 |
// return $match[1] .str_replace($search, $replace, $match[2]) .$match[3] .'"' .$match[4] .$match[5] .'</a>'; |
|
203 |
} |
|
204 |
|
|
205 |
} |
|
206 |
|
|
207 |
// number of subpatterns do not match the requirements ... do nothing |
|
208 |
return $match[0]; |
|
209 |
} |
|
210 |
} |
|
211 |
|
|
212 |
?> |
|
1 |
<?php |
|
2 |
|
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2009, Ryan Djurovich |
|
9 |
|
|
10 |
Website Baker is free software; you can redistribute it and/or modify |
|
11 |
it under the terms of the GNU General Public License as published by |
|
12 |
the Free Software Foundation; either version 2 of the License, or |
|
13 |
(at your option) any later version. |
|
14 |
|
|
15 |
Website Baker is distributed in the hope that it will be useful, |
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
GNU General Public License for more details. |
|
19 |
|
|
20 |
You should have received a copy of the GNU General Public License |
|
21 |
along with Website Baker; if not, write to the Free Software |
|
22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
* @category frontend |
|
24 |
* @package outputfilter |
|
25 |
* @author(s) Dietmar W?llbrink <Luisehahne>, Dietrich Roland Pehlke <Aldus> |
|
26 |
* @platform WB 2.8.0 |
|
27 |
* @require PHP 5.2.x |
|
28 |
* @license http://www.gnu.org/licenses/gpl.html |
|
29 |
* @link http://project.websitebaker2.org/browser/branches/2.8.x/wb/modules/output_filter/filter-routines.php |
|
30 |
* @changeset 2009/12/03 change searchstring mdcr.js, workout crypt emails |
|
31 |
|
|
32 |
*/ |
|
33 |
|
|
34 |
// prevent this file from being accessed directly |
|
35 |
if(!defined('WB_PATH')) die(header('Location: ../index.php')); |
|
36 |
|
|
37 |
// function to read the current filter settings |
|
38 |
if (!function_exists('get_output_filter_settings')) { |
|
39 |
function get_output_filter_settings() { |
|
40 |
global $database, $admin; |
|
41 |
// connect to database and read out filter settings |
|
42 |
$result = $database->query("SELECT * FROM " .TABLE_PREFIX ."mod_output_filter"); |
|
43 |
if($result && $result->numRows() > 0) { |
|
44 |
// get all data |
|
45 |
$data = $result->fetchRow(); |
|
46 |
$filter_settings['email_filter'] = $admin->strip_slashes($data['email_filter']); |
|
47 |
$filter_settings['mailto_filter'] = $admin->strip_slashes($data['mailto_filter']); |
|
48 |
$filter_settings['at_replacement'] = $admin->strip_slashes($data['at_replacement']); |
|
49 |
$filter_settings['dot_replacement'] = $admin->strip_slashes($data['dot_replacement']); |
|
50 |
} else { |
|
51 |
// something went wrong, use default values |
|
52 |
$filter_settings['email_filter'] = '0'; |
|
53 |
$filter_settings['mailto_filter'] = '0'; |
|
54 |
$filter_settings['at_replacement'] = '(at)'; |
|
55 |
$filter_settings['dot_replacement'] = '(dot)'; |
|
56 |
} |
|
57 |
|
|
58 |
// return array with filter settings |
|
59 |
return $filter_settings; |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
// function to filter the output before displaying it on the frontend |
|
64 |
if (!function_exists('filter_frontend_output')) { |
|
65 |
function filter_frontend_output($content) { |
|
66 |
// get output filter settings from database |
|
67 |
$filter_settings = get_output_filter_settings(); |
|
68 |
|
|
69 |
// work out the defined output filter mode: possible output filter modes: [0], 1, 2, 3, 6, 7 |
|
70 |
// 2^0 * (0.. disable, 1.. enable) filtering of mail addresses in text |
|
71 |
// 2^1 * (0.. disable, 1.. enable) filtering of mail addresses in mailto links |
|
72 |
// 2^2 * (0.. disable, 1.. enable) Javascript mailto encryption (only if mailto filtering enabled) |
|
73 |
|
|
74 |
// only filter output if we are supposed to |
|
75 |
if($filter_settings['email_filter'] != '1' && $filter_settings['mailto_filter'] != '1'){ |
|
76 |
// nothing to do ... |
|
77 |
return $content; |
|
78 |
} |
|
79 |
|
|
80 |
// check if non mailto mail addresses needs to be filtered |
|
81 |
$output_filter_mode = ($filter_settings['email_filter'] == '1') ? 1 : 0; // 0|1 |
|
82 |
|
|
83 |
// check if mailto mail addresses needs to be filtered |
|
84 |
if($filter_settings['mailto_filter'] == '1') { |
|
85 |
$output_filter_mode = $output_filter_mode + 2; // 0|2 |
|
86 |
|
|
87 |
// check if Javascript mailto encryption is enabled (call register_frontend_functions in the template) |
|
88 |
$search = '<script src="' .WB_URL .'/modules/output_filter/js/mdcr.js" type="text/javascript"></script>'; |
|
89 |
$search_droplet = '<script src="' .WB_URL .'/modules/droplets/js/mdcr.js" type="text/javascript"></script>'; |
|
90 |
if(strpos($content, $search) !== false || strpos($content, $search_droplet) !== false) { |
|
91 |
$output_filter_mode = $output_filter_mode + 4; // 0|4 |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
// define some constants so we do not call the database in the callback function again |
|
96 |
define('OUTPUT_FILTER_MODE', (int) $output_filter_mode); |
|
97 |
define('OUTPUT_FILTER_AT_REPLACEMENT', $filter_settings['at_replacement']); |
|
98 |
define('OUTPUT_FILTER_DOT_REPLACEMENT', $filter_settings['dot_replacement']); |
|
99 |
|
|
100 |
// first search part to find all mailto email addresses |
|
101 |
$pattern = '#(<a[^<]*href\s*?=\s*?"\s*?mailto\s*?:\s*?)([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4})([^"]*?)"([^>]*>)(.*?)</a>'; |
|
102 |
// second part to find all non mailto email addresses |
|
103 |
$pattern .= '|(value\s*=\s*"|\')??\b([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4})\b#i'; |
|
104 |
/* |
|
105 |
Sub 1:\b(<a.[^<]*href\s*?=\s*?"\s*?mailto\s*?:\s*?) --> "<a id="yyy" class="xxx" href = " mailto :" ignoring white spaces |
|
106 |
Sub 2:([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}) --> the email address in the mailto: part of the mail link |
|
107 |
Sub 3:([^"]*?)" --> possible ?Subject&cc... stuff attached to the mail address |
|
108 |
Sub 4:([^>]*>) --> all class or id statements after the mailto but before closing ..> |
|
109 |
Sub 5:(.*?)</a>\b --> the mailto text; all characters between >xxxxx</a> |
|
110 |
Sub 6:|\b([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4})\b --> email addresses which may appear in the text (require word boundaries) |
|
111 |
*/ |
|
112 |
|
|
113 |
// find all email addresses embedded in the content and filter them using a callback function |
|
114 |
$content = preg_replace_callback($pattern, 'filter_mail_addresses', $content); |
|
115 |
return $content; |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
|
|
120 |
// function to filter mail addresses embedded in text or mailto links before outputing them on the frontend |
|
121 |
if (!function_exists('filter_mail_addresses')) { |
|
122 |
function filter_mail_addresses($match) { |
|
123 |
|
|
124 |
// check if required output filter mode is defined |
|
125 |
if(!(defined('OUTPUT_FILTER_MODE') && defined('OUTPUT_FILTER_MODE') && defined('OUTPUT_FILTER_MODE'))) { |
|
126 |
return $match[0]; |
|
127 |
} |
|
128 |
|
|
129 |
$search = array('@', '.'); |
|
130 |
$replace = array(OUTPUT_FILTER_AT_REPLACEMENT ,OUTPUT_FILTER_DOT_REPLACEMENT); |
|
131 |
|
|
132 |
// check if the match contains the expected number of subpatterns (6|8) |
|
133 |
if(count($match) == 8) { |
|
134 |
/** |
|
135 |
OUTPUT FILTER FOR EMAIL ADDRESSES EMBEDDED IN TEXT |
|
136 |
**/ |
|
137 |
|
|
138 |
// 1.. text mails only, 3.. text mails + mailto (no JS), 7 text mails + mailto (JS) |
|
139 |
if(!in_array(OUTPUT_FILTER_MODE, array(1,3,7))) return $match[0]; |
|
140 |
|
|
141 |
// do not filter mail addresses included in input tags (<input ... value = "test@mail) |
|
142 |
if (strpos($match[6], 'value') !== false) return $match[0]; |
|
143 |
|
|
144 |
// filtering of non mailto email addresses enabled |
|
145 |
return str_replace($search, $replace, $match[0]); |
|
146 |
|
|
147 |
} elseif(count($match) == 6) { |
|
148 |
/** |
|
149 |
OUTPUT FILTER FOR EMAIL ADDRESSES EMBEDDED IN MAILTO LINKS |
|
150 |
**/ |
|
151 |
|
|
152 |
// 2.. mailto only (no JS), 3.. text mails + mailto (no JS), 6.. mailto only (JS), 7.. all filters active |
|
153 |
if(!in_array(OUTPUT_FILTER_MODE, array(2,3,6,7))) return $match[0]; |
|
154 |
|
|
155 |
// check if last part of the a href link: >xxxx</a> contains a email address we need to filter |
|
156 |
$pattern = '#[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}#i'; |
|
157 |
if(preg_match_all($pattern, $match[5], $matches)) { |
|
158 |
foreach($matches as $submatch) { |
|
159 |
foreach($submatch as $value) { |
|
160 |
// replace all . and all @ in email address parts by (dot) and (at) strings |
|
161 |
$match[5] = str_replace($value, str_replace($search, $replace, $value), $match[5]); |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
// check if Javascript encryption routine is enabled |
|
167 |
if(in_array(OUTPUT_FILTER_MODE, array(6,7))) { |
|
168 |
/** USE JAVASCRIPT ENCRYPTION FOR MAILTO LINKS **/ |
|
169 |
|
|
170 |
// extract possible class and id attribute from ahref link |
|
171 |
preg_match('/class\s*?=\s*?("|\')(.*?)\1/ix', $match[0], $class_attr); |
|
172 |
$class_attr = empty($class_attr) ? '' : 'class="' . $class_attr[2] . '" '; |
|
173 |
preg_match('/id\s*?=\s*?("|\')(.*?)\1/ix', $match[0], $id_attr); |
|
174 |
$id_attr = empty($id_attr) ? '' : 'id="' . $id_attr[2] . '" '; |
|
175 |
|
|
176 |
// preprocess mailto link parts for further usage |
|
177 |
$search = array('@', '.', '_', '-'); $replace = array('F', 'Z', 'X', 'K'); |
|
178 |
$email_address = str_replace($search, $replace, strtolower($match[2])); |
|
179 |
$email_subject = rawurlencode(html_entity_decode($match[3])); |
|
180 |
|
|
181 |
// create a random encryption key for the Caesar cipher |
|
182 |
mt_srand((double)microtime()*1000000); // (PHP < 4.2.0) |
|
183 |
$shift = mt_rand(1, 25); |
|
184 |
|
|
185 |
// encrypt the email using an adapted Caesar cipher |
|
186 |
$encrypted_email = ""; |
|
187 |
for($i = strlen($email_address) -1; $i > -1; $i--) { |
|
188 |
if(preg_match('#[FZXK0-9]#', $email_address[$i], $characters)) { |
|
189 |
$encrypted_email .= $email_address[$i]; |
|
190 |
} else { |
|
191 |
$encrypted_email .= chr((ord($email_address[$i]) -97 + $shift) % 26 + 97); |
|
192 |
} |
|
193 |
} |
|
194 |
$encrypted_email .= chr($shift + 97); |
|
195 |
|
|
196 |
// build the encrypted Javascript mailto link |
|
197 |
$mailto_link = "<a {$class_attr}{$id_attr}href=\"javascript:mdcr('$encrypted_email','$email_subject')\">" .$match[5] ."</a>"; |
|
198 |
|
|
199 |
return $mailto_link; |
|
200 |
|
|
201 |
} else { |
|
202 |
/** DO NOT USE JAVASCRIPT ENCRYPTION FOR MAILTO LINKS **/ |
|
203 |
|
|
204 |
// as minimum protection, replace replace @ in the mailto part by (at) |
|
205 |
// dots are not transformed as this would transform my.name@domain.com into: my(dot)name(at)domain(dot)com |
|
206 |
|
|
207 |
// rebuild the mailto link from the subpatterns (at the missing characters " and </a>") |
|
208 |
return $match[1] .str_replace('@', OUTPUT_FILTER_AT_REPLACEMENT, $match[2]) .$match[3] .'"' .$match[4] .$match[5] .'</a>'; |
|
209 |
// if you want to protect both, @ and dots, comment out the line above and remove the comment from the line below |
|
210 |
// return $match[1] .str_replace($search, $replace, $match[2]) .$match[3] .'"' .$match[4] .$match[5] .'</a>'; |
|
211 |
} |
|
212 |
|
|
213 |
} |
|
214 |
|
|
215 |
// number of subpatterns do not match the requirements ... do nothing |
|
216 |
return $match[0]; |
|
217 |
} |
|
218 |
} |
|
219 |
|
|
220 |
?> |
Also available in: Unified diff
change searchstring mdcr.js, workout crypt emails in output_filter/filter-routines.php
comment out ob_end_flush line 259 in form/view.php