PluginProbe
CryptX / 1.0
CryptX v1.0
4.2.0 4.1.1 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.9 2.0 2.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 92 releases
cryptx / cryptx.php

cryptx.php in CryptX 1.0, at cryptx.php

319 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: CryptX
4 Plugin URI: http://weber-nrw.de/
5 Description: En-/Decrypt mailto-Links to prevent Spam Bots scanning Sorcecode for Emails.
6 Version: 1.0
7 Author: Ralf Weber
8 Author URI: http://weber-nrw.de/
9 */
10
11 /////////////////////////////////////////////////////////////////////////////
12
13 /**
14 * @internal prevent from direct calls
15 */
16 if (!defined('ABSPATH')) {
17 return ;
18 }
19
20 /**
21 * @internal prevent from second inclusion
22 */
23 if (!class_exists('cryptX')) {
24
25 /////////////////////////////////////////////////////////////////////////////
26
27 load_plugin_textdomain('cryptx', PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)) );
28
29 $cryptX_var = (array) get_option('cryptX');
30
31 /**
32 * "CryptX" WordPress Plugin
33 *
34 * @author Ralf Weber <ralf@weber-nrw.de>
35 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
36 */
37 Class cryptX {
38
39 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40
41 /**
42 * Constructor
43 *
44 * This constructor attaches the needer plugin hook callbacks
45 */
46 function cryptX() {
47
48 global $cryptX_var;
49
50 // attach the converstion handlers
51 //
52 if (@$cryptX_var[theContent]) {
53 if (@$cryptX_var[java]) {
54 add_filter('the_content',
55 array(&$this, '_encrypt'));
56 } else {
57 add_filter('the_content',
58 array(&$this, '_unicode'));
59 }
60 }
61 if (@$cryptX_var[theExcerpt]) {
62 if (@$cryptX_var[java]) {
63 add_filter('the_content',
64 array(&$this, '_encrypt'));
65 } else {
66 add_filter('the_content',
67 array(&$this, '_unicode'));
68 }
69 }
70
71 // attach to admin menu
72 //
73 if (is_admin()) {
74 add_action('admin_menu',
75 array(&$this, '_menu')
76 );
77 }
78
79 // attach to plugin installation
80 //
81 add_action(
82 'activate_' . str_replace(
83 DIRECTORY_SEPARATOR, '/',
84 str_replace(
85 realpath(ABSPATH . PLUGINDIR) . DIRECTORY_SEPARATOR,
86 '', __FILE__
87 )
88 ),
89 array(&$this, '_install')
90 );
91
92 // attach javascript to Header
93 //
94 if (@$cryptX_var[java]) {
95 add_action(
96 'wp_head',
97 array(&$this, '_header')
98 );
99 }
100
101 } // End function
102
103 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
104
105 /**
106 * Wrap _encrypt
107 * @param string $content
108 * @return string
109 */
110 function _encrypt($content)
111 {
112 global $cryptX_var;
113
114 preg_match_all('/<a[^>]*href=["|\'](.*)["|\']*>(.*)<\/a>/iUs', $content, $links, PREG_SET_ORDER);
115
116 foreach( $links as $link ) {
117
118 if(preg_match('/mailto:(.*)/', $link[1], $mail)) {
119 $crypt = '';
120 $ascii = 0;
121 for ($i = 0; $i < strlen( $mail[1] ); $i++) {
122 $ascii = ord ( substr ( $mail[1], $i ) );
123 if (8364 <= $char) {
124 $ascii = 128;
125 }
126 $crypt .= chr($ascii + 1);
127 }
128 $content = str_replace( $link[1], "javascript:DeCryptX('" . $crypt . "')", $content);
129 $new_mail = str_replace( "@", $cryptX_var[at], $link[2]);
130 $new_mail = str_replace( ".", $cryptX_var[dot], $new_mail);
131 $content = str_replace( $link[2], $new_mail, $content);
132 }
133
134 } // foreach
135 return $content;
136 }
137
138 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
139
140 /**
141 * Wrap _unicode
142 * @param string $content
143 * @return string
144 */
145 function _unicode($content)
146 {
147 global $cryptX_var;
148
149 preg_match_all('/<a[^>]*href=["|\'](.*)["|\']*>(.*)<\/a>/iUs', $content, $links, PREG_SET_ORDER);
150
151 foreach( $links as $link ) {
152
153 if(preg_match('/mailto:(.*)/', $link[1], $mail)) {
154 $mailto = "mailto:" . $mail[1];
155 $crypt = '';
156 for ($i = 0; $i < strlen( $mailto ); $i++) {
157 $crypt .= "&#".ord ( substr ( $mailto, $i ) );
158 }
159 $content = str_replace( $mailto, $crypt, $content);
160 $new_mail = str_replace( "@", $cryptX_var[at], $link[2]);
161 $new_mail = str_replace( ".", $cryptX_var[dot], $new_mail);
162 $content = str_replace( $link[2], $new_mail, $content);
163 }
164
165 } // foreach
166 return $content;
167 }
168
169 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
170
171 /**
172 * Performs the routines required at plugin installation:
173 * in general introducing the settings array
174 */
175 function _install() {
176 add_option(
177 'cryptX',
178 array(
179 'at' => ' [at] ',
180 'dot' => ' [dot] ',
181 'theContent' => 1,
182 'theExcerpt' => 0,
183 'java' => 1,
184 )
185 );
186 }
187
188 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
189
190 /**
191 * Attach the menu page to the `Options` tab
192 */
193 function _header()
194 {
195 $cryptX_script.= "<script type=\"text/javascript\" src=\"" . get_option('siteurl') . '/' . PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)) . "/js/cryptx.js\"></script>\n";
196 print($cryptX_script);
197 }
198
199 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
200
201 /**
202 * Attach the menu page to the `Options` tab
203 */
204 function _menu() {
205 add_submenu_page('options-general.php',
206 'CryptX',
207 'CryptX', 9,
208 __FILE__,
209 array($this, '_submenu')
210 );
211 }
212
213 /**
214 * Handles and renders the menu page
215 */
216 function _submenu() {
217 global $cryptX_var;
218
219 // sanitize referrer
220 //
221 $_SERVER['HTTP_REFERER'] = preg_replace(
222 '~&saved=.*$~Uis','', $_SERVER['HTTP_REFERER']
223 );
224
225 // information updated ?
226 //
227 if ($_POST['submit']) {
228
229 // save
230 //
231 update_option(
232 'cryptX',
233 $_POST['cryptX_var']
234 );
235
236 die("<script>document.location.href = '{$_SERVER['HTTP_REFERER']}&saved=settings:" . time() . "';</script>");
237 }
238
239 // operation report detected
240 //
241 if (@$_GET['saved']) {
242
243 list($saved, $ts) = explode(':', $_GET['saved']);
244 if (time() - $ts < 10) {
245 echo '<div id="message" class="updated fade"><p><strong>';
246
247 switch ($saved) {
248 case 'settings' :
249 echo 'Settings saved.';
250 break;
251 }
252
253 echo '</strong></p></div>';
254 }
255 }
256
257 // read the settings
258 //
259 //$cryptX = (array) get_option('cryptX');
260
261 ?>
262 <!-- Start Optionen im Adminbereich (xhtml, au�erhalb PHP) -->
263 <div class="wrap">
264 <h2><?php _e("CryptX Options...",'cryptx'); ?></h2>
265 <form method="post">
266 <blockquote>
267 <table>
268 <tr>
269 <td valign="top"><?php _e("Replacement for '@'",'cryptx'); ?>
270 <input name="cryptX_var[at]" value="<?php echo $cryptX_var[at]; ?>" type="text" /></td>
271 </tr>
272 <tr>
273 <td valign="top"><?php _e("Replacement for '.'",'cryptx'); ?>
274 <input name="cryptX_var[dot]" value="<?php echo $cryptX_var[dot]; ?>" type="text" /></td>
275 </tr>
276 <tr>
277 <td valign="top"><input name="cryptX_var[theContent]" <?php echo ($cryptX_var[theContent]) ? 'checked="checked"' : ''; ?> type="checkbox" />
278 <?php _e("Apply CryptX to the Content",'cryptx'); ?></td>
279 </tr>
280 <tr>
281 <td valign="top"><input name="cryptX_var[theExcerpt]" <?php echo ($cryptX_var[theExcerpt]) ? 'checked="checked"' : ''; ?> type="checkbox" />
282 <?php _e("Apply CryptX to the Excerpt",'cryptx'); ?></td>
283 </tr>
284 <tr>
285 <td valign="top">
286 <input name="cryptX_var[java]" <?php echo ($cryptX_var[java]) ? 'checked="checked"' : ''; ?> type="radio" value="1" />
287 <?php _e("Use javascript to hide the Email-Link.",'cryptx'); ?><br />
288 <input name="cryptX_var[java]" <?php echo (!$cryptX_var[java]) ? 'checked="checked"' : ''; ?> type="radio" value="0" />
289 <?php _e("Use Unicode to hide the Email-Link.",'cryptx'); ?>
290 </td>
291 </tr>
292 <tr>
293 <td><input type="submit" name="submit" value="Update &raquo;" /></td>
294 </tr>
295 </table>
296 </blockquote>
297 </form>
298 </div>
299 <?php
300 }
301
302 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
303
304
305 //--end-of-class
306 }
307
308 }
309
310 /////////////////////////////////////////////////////////////////////////////
311
312 /**
313 * Initiating the plugin...
314 * @see cryptX
315 */
316 new cryptX;
317
318 ?>
319