PluginProbe
CryptX / 3.0
CryptX v3.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 3.0, at cryptx.php

667 lines 26.9 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/wordpress/cryptx/
5 Description: No more SPAM by spiders scanning you site for email adresses. With CryptX you can hide all your email adresses, with and without a mailto-link, by converting them using javascript or UNICODE. Although you can choose to add a mailto-link to all unlinked email adresses with only one klick at the settings. That's great, isn't it?
6 Version: 3.0
7 Author: Ralf Weber
8 Author URI: http://weber-nrw.de/
9 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4026696
10 */
11 /**
12 * "CryptX" WordPress Plugin
13 *
14 * @author Ralf Weber <ralf@weber-nrw.de>
15 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
16 */
17
18 if (!defined('ABSPATH')) {
19 return ;
20 }
21
22 define( 'CRYPTX_BASENAME', plugin_basename( __FILE__ ) );
23 define( 'CRYPTX_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
24 define( 'CRYPTX_FILENAME', str_replace( CRYPTX_BASEFOLDER.'/', '', plugin_basename(__FILE__) ) );
25
26 load_plugin_textdomain('cryptx', false, 'cryptx/languages/');
27
28 $cryptX_var = (array) get_option('cryptX');
29
30
31 global $cryptX_var, $wp_version;
32
33 if (@$cryptX_var['theContent']) {
34 rw_cryptx_filter('the_content');
35 }
36 if (@$cryptX_var['theExcerpt']) {
37 rw_cryptx_filter('the_excerpt');
38 }
39 if (@$cryptX_var['commentText']) {
40 rw_cryptx_filter('comment_text');
41 }
42 if (@$cryptX_var['widgetText']) {
43 rw_cryptx_filter('widget_text');
44 }
45
46 if (is_admin()) {
47 add_action('admin_menu', 'rw_cryptx_menu');
48 }
49
50 add_action( 'activate_' . str_replace( DIRECTORY_SEPARATOR, '/', str_replace( realpath(ABSPATH . PLUGINDIR) . DIRECTORY_SEPARATOR, '', __FILE__ ) ), 'rw_cryptx_install' );
51
52 if (@$cryptX_var['java']) {
53 if (@$cryptX_var['load_java']) {
54 add_action( 'wp_footer', 'rw_cryptx_header', 9 );
55 } else {
56 add_action( 'wp_head', 'rw_cryptx_header', 9 );
57 }
58 }
59
60 if (@$cryptX_var[metaBox]) {
61 add_action('admin_menu', 'rw_cryptx_meta_box');
62 add_action('wp_insert_post', 'rw_cryptx_insert_post' );
63 add_action('wp_update_post', 'rw_cryptx_insert_post' );
64 }
65
66 if ( version_compare( $wp_version, '2.8', '>' ) ) {
67 add_filter( 'plugin_row_meta', 'rw_cryptx_init_row_meta', 10, 2 ); // only 2.8 and higher
68 } else {
69 add_filter( 'plugin_action_links', 'rw_cryptx_init_row_meta', 10, 2 );
70 }
71
72 add_filter( 'init', 'rw_cryptx_init_tinyurl');
73 add_action( 'parse_request', 'rw_cryptx_parse_request');
74
75 add_shortcode( 'cryptx', 'rw_cryptx_shortcode');
76
77 function rw_cryptx_shortcode( $atts, $content=null) {
78 global $cryptX_var;
79
80 if (@$cryptX_var[autolink]) $content = rw_cryptx_autolink($content, true);
81 $content = rw_cryptx_encryptx($content, true);
82 $content = rw_cryptx_linktext($content, true);
83
84 return $content;
85 }
86
87 function rw_cryptx_parse_request( $wp ) {
88 if ( isset($_GET['cryptx']) ) {
89 switch( $_GET['cryptx'] ) {
90 case 'news':
91 include( 'ajax/news.php' );
92 break;
93 }
94 exit;
95 }
96 }
97
98 function rw_cryptx_init_tinyurl() {
99 global $cryptX_var;
100 $url = $_SERVER['REQUEST_URI'];
101 $params = explode( '/', $url );
102 if ( count( $params ) > 1 ) {
103 $tiny_url = $params[count( $params ) -2];
104 if ( $tiny_url == md5( get_bloginfo('url') ) ) {
105 $font = $cryptX_var['c2i_font'];
106 $msg = $params[count( $params ) -1];
107 $size = $cryptX_var['c2i_fontSize'];
108 $pad = 1;
109 $transparent = 1;
110 $red = hexdec(substr($cryptX_var['c2i_fontRGB'],0,2));
111 $grn = hexdec(substr($cryptX_var['c2i_fontRGB'],2,2));
112 $blu = hexdec(substr($cryptX_var['c2i_fontRGB'],4,2));
113 $bg_red = 255 - $red;
114 $bg_grn = 255 - $grn;
115 $bg_blu = 255 - $blu;
116 $width = 0;
117 $height = 0;
118 $offset_x = 0;
119 $offset_y = 0;
120 $bounds = array();
121 $image = "";
122 $bounds = ImageTTFBBox($size, 0, $font, "W");
123 $font_height = abs($bounds[7]-$bounds[1]);
124 $bounds = ImageTTFBBox($size, 0, $font, $msg);
125 $width = abs($bounds[4]-$bounds[6]);
126 $height = abs($bounds[7]-$bounds[1]);
127 $offset_y = $font_height+abs(($height - $font_height)/2)-1;
128 $offset_x = 0;
129 $image = imagecreatetruecolor($width+($pad*2),$height+($pad*2));
130 imagesavealpha($image, true);
131 $foreground = ImageColorAllocate($image, $red, $grn, $blu);
132 $background = imagecolorallocatealpha($image, 0, 0, 0, 127);
133 imagefill($image, 0, 0, $background);
134 ImageTTFText($image, $size, 0, $offset_x+$pad, $offset_y+$pad, $foreground, $font, $msg);
135 Header("Content-type: image/png");
136 imagePNG($image);
137 die;
138 }
139 }
140 }
141
142 function rw_cryptx_init_row_meta($links, $file) {
143 if (CRYPTX_BASENAME == $file) {
144 return array_merge(
145 $links,
146 array(
147 sprintf(
148 '<a href="options-general.php?page=%s">%s</a>',
149 CRYPTX_BASENAME,
150 __('Settings')
151 )
152 ),
153 array(
154 sprintf(
155 '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4026696">%s</a>',
156 __('Donate', 'cryptx')
157 )
158 )
159 );
160 }
161 return $links;
162 }
163
164 function rw_cryptx_filter($apply) {
165 global $cryptX_var, $post, $shortcode_tags;
166 if (@$cryptX_var['autolink']) {
167 add_filter($apply, 'rw_cryptx_autolink', 5);
168 if (!empty($shortcode_tags) || is_array($shortcode_tags)) {
169 add_filter($apply, 'rw_cryptx_autolink', 11);
170 }
171 }
172 add_filter($apply, 'rw_cryptx_encryptx', 12);
173 add_filter($apply, 'rw_cryptx_linktext', 13);
174 }
175
176 function rw_cryptx_excluded($ID) {
177 global $cryptX_var;
178 $return = false;
179 $exIDs = explode(",", $cryptX_var['excludedIDs']);
180 if(in_array($ID, $exIDs) > 0 ) $return = true;
181 return $return;
182 }
183
184 function rw_cryptx_linktext($content, $shortcode=false) {
185 global $post;
186 if (!rw_cryptx_excluded($post->ID) OR $shortcode!=false) {
187 $content = preg_replace_callback("/([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/i", 'rw_cryptx_do_Linktext', $content );
188 }
189 return $content;
190 }
191
192 function rw_cryptx_do_linktext($Match) {
193 global $cryptX_var;
194 switch ($cryptX_var['opt_linktext']) {
195
196 case 1: // alternative text for mail link
197 $linktext = $cryptX_var['alt_linktext'];
198 break;
199
200 case 2: // alternative image for mail link
201 $linktext = "<img src=\"" . $cryptX_var['alt_linkimage'] . "\" class=\"cryptxImage\" alt=\"" . $cryptX_var['alt_linkimage_title'] . "\" title=\"" . $cryptX_var['alt_linkimage_title'] . "\" />";
202 break;
203
204 case 3: // uploaded image for mail link
205 $imgurl = $cryptX_var['alt_uploadedimage'];
206 $linktext = "<img src=\"" . $imgurl . "\" class=\"cryptxImage\" alt=\"" . $cryptX_var['http_linkimage_title'] . "\" title=\"" . $cryptX_var['http_linkimage_title'] . "\" />";
207 break;
208
209 case 4: // text scrambled by antispambot
210 $linktext = antispambot($Match[1]);
211 break;
212
213 case 5: // convert to image
214 $linktext = "<img src=\"" . get_bloginfo('url') . "/" . md5( get_bloginfo('url') ) . "/" . antispambot($Match[1]) . "\" class=\"cryptxImage\" style=\"vertical-align:text-bottom\" alt=\"" . antispambot($Match[1]) . "\" title=\"" . antispambot($Match[1]) . "\" />";
215 break;
216
217 default:
218 $linktext = str_replace( "@", $cryptX_var['at'], $Match[1]);
219 $linktext = str_replace( ".", $cryptX_var['dot'], $linktext);
220
221 }
222 return $linktext;
223 }
224
225 function rw_cryptx_dirImages() {
226 $dir = plugin_dir_path( __FILE__ ).'images';
227 $fh = opendir($dir);
228 $verzeichnisinhalt = array();
229 while (true == ($file = readdir($fh)))
230 {
231 if ((substr(strtolower($file), -3)=="jpg") or (substr(strtolower($file), -3)=="gif"))
232 {
233 $verzeichnisinhalt[] = $file;
234 }
235 }
236 return $verzeichnisinhalt;
237 }
238
239 function rw_cryptx_dirFonts() {
240 $dir = plugin_dir_path( __FILE__ ).'fonts';
241 $fh = opendir($dir);
242 $verzeichnisinhalt = array();
243 while (true == ($file = readdir($fh)))
244 {
245 if ((substr(strtolower($file), -3)=="ttf") or (substr(strtolower($file), -3)=="ttf"))
246 {
247 $verzeichnisinhalt[] = $file;
248 }
249 }
250 return $verzeichnisinhalt;
251 }
252
253 function rw_cryptx_encryptx($content, $shortcode=false) {
254 global $post;
255
256 if (!rw_cryptx_excluded($post->ID) OR $shortcode!=false) {
257 $content = preg_replace_callback('/<a (.*?)(href=("|\')mailto:(.*?)("|\')(.*?)|)>(.*?)<\/a>/i', 'rw_cryptx_mailtocrypt', $content );
258 }
259 return $content;
260 }
261
262 function rw_cryptx_mailtocrypt($Match) {
263 global $cryptX_var;
264 $return = $Match[0];
265 $mailto = "mailto:" . $Match[4];
266 if (substr($Match[4], 0, 9) =="?subject=") return $return;
267 if (@$cryptX_var['java']) {
268 $crypt = '';
269 $ascii = 0;
270 for ($i = 0; $i < strlen( $Match[4] ); $i++) {
271 $ascii = ord ( substr ( $Match[4], $i ) );
272 if (8364 <= $ascii) {
273 $ascii = 128;
274 }
275 $crypt .= chr($ascii + 1);
276 }
277 $javascript="javascript:DeCryptX('" . $crypt . "')";
278 $return = str_replace( "mailto:".$Match[4], $javascript, $return);
279 } else {
280 $return = str_replace( $mailto, antispambot($mailto), $return);
281 }
282 return $return;
283 }
284
285 function rw_cryptx_autolink($content, $shortcode=false) {
286 global $post;
287 if (rw_cryptx_excluded($post->ID) AND $shortcode==false) return $content;
288 $src[]="/([\s])([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si";
289 $src[]="/(>)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))(<)/si";
290 $src[]="/(\()([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))(\))/si";
291 $src[]="/(>)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))([\s])/si";
292 $src[]="/([\s])([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))(<)/si";
293 $src[]="/^([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si";
294 $src[]="/(<a[^>]*>)<a[^>]*>/";
295 $src[]="/(<\/A>)<\/A>/i";
296 $tar[]="\\1<a href=\"mailto:\\2\">\\2</a>";
297 $tar[]="\\1<a href=\"mailto:\\2\">\\2</a>\\6";
298 $tar[]="\\1<a href=\"mailto:\\2\">\\2</a>\\6";
299 $tar[]="\\1<a href=\"mailto:\\2\">\\2</a>\\6";
300 $tar[]="\\1<a href=\"mailto:\\2\">\\2</a>\\6";
301 $tar[]="<a href=\"mailto:\\0\">\\0</a>";
302 $tar[]="\\1";
303 $tar[]="\\1";
304 $content = preg_replace($src,$tar,$content);
305 return $content;
306 }
307
308 function rw_cryptx_install() {
309 global $cryptX_var, $wpdb;
310 $firstImage = rw_cryptx_dirImages();
311 $firstFont = rw_cryptx_dirFonts();
312 $cryptX_var = (array) get_option('cryptX'); // reread Options
313 $defaults = array(
314 'at' => ' [at] ',
315 'dot' => ' [dot] ',
316 'theContent' => 1,
317 'theExcerpt' => 0,
318 'commentText' => 1,
319 'widgetText' => 0,
320 'java' => 1,
321 'load_java' => 0,
322 'opt_linktext' => 0,
323 'autolink' => 1,
324 'alt_linktext' => '',
325 'alt_linkimage' => '',
326 'http_linkimage_title' => '',
327 'alt_linkimage_title' => '',
328 'excludedIDs' => '',
329 'metaBox' => 1,
330 'alt_uploadedimage' => plugins_url('cryptx/images/').$firstImage[0],
331 'c2i_font' => plugin_dir_path( __FILE__ ).'fonts/'.$firstFont[0],
332 'c2i_fontSize' => 10,
333 'c2i_fontRGB' => '000000'
334 );
335 $cryptX_var = $cryptX_var + $defaults;
336 if ($cryptX_var['excludedIDs'] == "") {
337 $tmp = array();
338 $excludes = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'cryptxoff' AND meta_value = 'true'");
339 if(count($excludes) > 0) {
340 foreach ($excludes as $exclude) {
341 $tmp[] = $exclude->post_id;
342 }
343 sort($tmp);
344 $cryptX_var['excludedIDs'] = implode(",", $tmp);
345 update_option( 'cryptX', $cryptX_var);
346 $cryptX_var = (array) get_option('cryptX'); // reread Options
347 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = 'cryptxoff'");
348 }
349 }
350 if (empty($cryptX_var['c2i_font'])) {
351 $cryptX_var['c2i_font'] = plugin_dir_path( __FILE__ ).'fonts/'.$firstFont[0];
352 }
353 if (empty($cryptX_var['c2i_fontSize'])) {
354 $cryptX_var['c2i_fontSize'] = 10;
355 }
356 if (empty($cryptX_var['c2i_fontRGB'])) {
357 $cryptX_var['c2i_fontRGB'] = '000000';
358 }
359 update_option( 'cryptX', $cryptX_var);
360 $cryptX_var = (array) get_option('cryptX'); // reread Options
361 }
362
363 function rw_cryptx_header() {
364 $cryptX_script = "<script type=\"text/javascript\" src=\"" . site_url() . '/' . PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)) . "/js/cryptx.js\"></script>\n";
365 print($cryptX_script);
366 }
367
368 function rw_cryptx_meta() {
369 global $post;
370 ?>
371 <input type="checkbox" name="cryptxoff" <?php if (rw_cryptx_excluded($post->ID)) { echo 'checked="checked"'; } ?>/> Disable CryptX for this post/page
372 <?php
373 }
374
375 function rw_cryptx_option() {
376 global $post;
377 if ( current_user_can('edit_posts') ) { ?>
378 <fieldset id="cryptxoption" class="dbx-box">
379 <h3 class="dbx-handle">CryptX</h3>
380 <div class="dbx-content">
381 <input type="checkbox" name="cryptxoff" <?php if (rw_cryptx_excluded($post->ID)) { echo 'checked="checked"'; } ?>/> Disable CryptX for this post/page
382 </div>
383 </fieldset>
384 <?php
385 }
386 }
387
388 function rw_cryptx_meta_box() {
389 if ( function_exists('add_meta_box') ) {
390 add_meta_box('cryptx','CryptX', 'rw_cryptx_meta','post');
391 add_meta_box('cryptx','CryptX', 'rw_cryptx_meta','page');
392 } else {
393 add_action('dbx_post_sidebar', 'rw_cryptx_option');
394 add_action('dbx_page_sidebar', 'rw_cryptx_option');
395 }
396 }
397
398 function rw_cryptx_insert_post($pID) {
399 global $cryptX_var, $post;
400 $rev = wp_is_post_revision($pID);
401 if($rev) $pID = $rev;
402 $b = explode(",", $cryptX_var['excludedIDs']);
403 if($b[0] == '') unset($b[0]);
404 foreach($b as $x=>$y) {
405 if($y == $pID) {
406 unset($b[$x]);
407 break;
408 }
409 }
410 if (isset($_POST['cryptxoff'])) $b[] = $pID;
411 $b = array_unique($b);
412 sort($b);
413 $cryptX_var['excludedIDs'] = implode(",", $b);
414 update_option( 'cryptX', $cryptX_var);
415 $cryptX_var = (array) get_option('cryptX'); // reread Options
416 }
417
418 function rw_cryptx_menu() {
419 add_options_page(
420 'CryptX',
421 (version_compare($GLOBALS['wp_version'], '2.6.999', '>') ? '<img src="' .@plugins_url('cryptx/icon.png'). '" width="10" height="10" alt="CryptX Icon" />' : ''). 'CryptX',
422 'manage_options',
423 __FILE__,
424 'rw_cryptx_submenu'
425 );
426 }
427
428 function rw_cryptx_submenu() {
429 global $cryptX_var;
430 if (isset($_POST) && !empty($_POST)) {
431 if (function_exists('current_user_can') === true && (current_user_can('manage_options') === false || current_user_can('edit_plugins') === false)) {
432 wp_die("You don't have permission to access!");
433 }
434 check_admin_referer('cryptX');
435 update_option( 'cryptX', $_POST['cryptX_var']);
436 $cryptX_var = (array) get_option('cryptX'); // reread Options
437 ?>
438 <div id="message" class="updated fade">
439 <p><strong><?php _e('Settings saved.') ?></strong></p>
440 </div>
441 <?php } ?>
442
443 <div class="wrap">
444 <?php if (version_compare($GLOBALS['wp_version'], '2.6.999', '>')) { ?>
445 <div class="icon32" style="background: url(<?php echo @plugins_url('cryptx/icon32.png') ?>) no-repeat"><br /></div>
446 <?php } ?>
447 <h2>CryptX</h2>
448 <br class="clear" />
449 <form method="post" action="">
450 <?php wp_nonce_field('cryptX') ?>
451 <div id="poststuff" class="ui-sortable">
452 <div id="rw_cryptx_information_box" class="postbox">
453 <h3><?php _e("Information",'cryptx'); ?></h3>
454 <div class="inside">
455 <table class="form-table">
456 <tr>
457 <td valign="top" width="1%" nowrap><b><i><u>NEWS:</u></i>&nbsp;</b></td>
458 <td valign="top"><div id="cryptx-news-content" style="display:none;"></div></td>
459 <td valign="top" width="50%" style="border-left: 1px solid #999;"><?php
460 $data = get_plugin_data(__FILE__);
461 echo sprintf(
462 '%1$s: %2$s <br /> %3$s: %4$s <br /> %5$s: <a href="http://weber-nrw.de" target="_blank">Ralf Weber</a> | <a href="http://twitter.com/Weber_NRW" target="_blank">%6$s</a> | <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4026696">%7$s</a><br />',
463 __('Plugin'),
464 'CryptX',
465 __('Version'),
466 $data['Version'],
467 __('Author'),
468 __('Follow on Twitter', 'cryptx'),
469 __('Donate', 'cryptx')
470 );
471 ?>
472 </td>
473 </tr>
474 <tr>
475 <td colspan="3" align="center">
476 Please support me by translating CryptX into other languages. You can download the cryptx.pot file from my <a href="http://weber-nrw.de/wordpress/cryptx/downloads/">site</a> and mail me the zipped language files. Thanks for it.
477 </td>
478 </tr>
479 </table>
480 </div>
481 </div>
482 <div id="rw_cryptx_presentation_box" class="postbox">
483 <h3><?php _e("Presentation",'cryptx'); ?></h3>
484 <div class="inside">
485 <table class="form-table">
486 <tr valign="top">
487 <td><input name="cryptX_var[opt_linktext]" type="radio" id="opt_linktext" value="0" <?php echo ($cryptX_var['opt_linktext'] == 0) ? 'checked="checked"' : ''; ?> /></td>
488 <th scope="row"><label for="cryptX_var[at]"><?php _e("Replacement for '@'",'cryptx'); ?></label></th>
489 <td><input name="cryptX_var[at]" value="<?php echo $cryptX_var['at']; ?>" type="text" class="regular-text" /></td>
490 </tr>
491 <tr valign="top">
492 <td>&nbsp;</td>
493 <th scope="row"><label for="cryptX_var[dot]"><?php _e("Replacement for '.'",'cryptx'); ?></label></th>
494 <td><input name="cryptX_var[dot]" value="<?php echo $cryptX_var['dot']; ?>" type="text" class="regular-text" /></td>
495 </tr>
496 <tr valign="top">
497 <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext2" value="1" <?php echo ($cryptX_var['opt_linktext'] == 1) ? 'checked="checked"' : ''; ?>/></td>
498 <th><label for="cryptX_var[alt_linktext]"><?php _e("Text for link",'cryptx'); ?></label></th>
499 <td><input name="cryptX_var[alt_linktext]" value="<?php echo $cryptX_var['alt_linktext']; ?>" type="text" class="regular-text" /></td>
500 </tr>
501 <tr valign="top">
502 <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext3" value="2" <?php echo ($cryptX_var['opt_linktext'] == 2) ? 'checked="checked"' : ''; ?>/></td>
503 <th><label for="cryptX_var[alt_linkimage]"><?php _e("Image-URL",'cryptx'); ?></label></th>
504 <td><input name="cryptX_var[alt_linkimage]" value="<?php echo $cryptX_var['alt_linkimage']; ?>" type="text" class="regular-text" /></td>
505 </tr>
506 <tr valign="top">
507 <td scope="row">&nbsp;</td>
508 <th><label for="cryptX_var[http_linkimage_title]"><?php _e("Title-Tag for the Image",'cryptx'); ?></label></th>
509 <td><input name="cryptX_var[http_linkimage_title]" value="<?php echo $cryptX_var['http_linkimage_title']; ?>" type="text" class="regular-text" /></td>
510 </tr>
511 <tr valign="top">
512 <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext4" value="3" <?php echo ($cryptX_var['opt_linktext'] == 3) ? 'checked="checked"' : ''; ?>/></td>
513 <th><label for="cryptX_var[alt_uploadedimage]"><?php _e("Select image from folder",'cryptx'); ?></label></th>
514 <td> <select name="cryptX_var[alt_uploadedimage]" onchange="cryptX_bild_wechsel(this)">
515 <?php foreach(rw_cryptx_dirImages() as $image) {
516 ?>
517 <option value="<?php echo plugins_url('cryptx/images/').$image; ?>" <?php echo ($cryptX_var['alt_uploadedimage'] == plugins_url('cryptx/images/').$image) ? 'selected' : ''; ?> ><?php echo $image; ?></option>
518 <?php } ?>
519 </select>
520 <br/><?php _e("the selected image: ",'cryptx'); ?><img src="<?php echo $cryptX_var['alt_uploadedimage']; ?>" id="cryptXmailTo" align="top" style="padding: 3px;"><br/>
521 <span class="setting-description"><?php echo sprintf( __("Upload your favorite email-image to '%s'. Only .jpg and .gif Supported!",'cryptx'), plugin_dir_path( __FILE__ ).'images/' ); ?></span></td>
522 </tr>
523 <tr valign="top">
524 <td>&nbsp;</td>
525 <th><label for="cryptX_var[alt_linkimage_title]"><?php _e("Title-Tag for the Image",'cryptx'); ?></label></th>
526 <td><input name="cryptX_var[alt_linkimage_title]" value="<?php echo $cryptX_var['alt_linkimage_title']; ?>" type="text" class="regular-text" /></td>
527 </tr>
528 <tr valign="top">
529 <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext4" value="4" <?php echo ($cryptX_var['opt_linktext'] == 4) ? 'checked="checked"' : ''; ?>/></td>
530 <th colspan="2"><?php _e("Text scrambled by AntiSpamBot (<small>Try it and look at your site and check the html source!</small>)",'cryptx'); ?></th>
531 </tr>
532 <tr valign="top">
533 <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext5" value="5" <?php echo ($cryptX_var['opt_linktext'] == 5) ? 'checked="checked"' : ''; ?>/></td>
534 <th><?php _e("Convert Email to PNG-image",'cryptx'); ?></th>
535 <td><?php _e("Example with the saved options: ",'cryptx'); ?><img src="<?php echo get_bloginfo('url'); ?>/<?php echo md5( get_bloginfo('url') ); ?>/<?php echo antispambot("test@example.com"); ?>" align="absmiddle" alt="<?php echo antispambot("test@example.com"); ?>" title="<?php echo antispambot("test@example.com"); ?>"></td>
536 </tr>
537 <tr valign="top">
538 <td>&nbsp;</td>
539 <th><label for="cryptX_var[c2i_font]"><?php _e("Choose a Font",'cryptx'); ?></label></th>
540 <td><select name="cryptX_var[c2i_font]">
541 <?php foreach(rw_cryptx_dirFonts() as $font) { ?>
542 <option value="<?php echo plugin_dir_path( __FILE__ ).'fonts/'.$font; ?>" <?php echo ($cryptX_var['c2i_font'] == plugin_dir_path( __FILE__ ).'fonts/'.$font) ? 'selected' : ''; ?> ><?php echo $font; ?></option>
543 <?php } ?>
544 </select><br/>
545 <span class="setting-description"><?php echo sprintf( __("Upload your favorite font to '%s'. Only .ttf is Supported!",'cryptx'), plugin_dir_path( __FILE__ ).'fonts/' ); ?></span>
546 </td>
547 </tr>
548 <tr valign="top">
549 <td>&nbsp;</td>
550 <th><label for="cryptX_var[c2i_fontSize]"><?php _e("Font size (pixel)",'cryptx'); ?></label></th>
551 <td><input name="cryptX_var[c2i_fontSize]" value="<?php echo $cryptX_var['c2i_fontSize']; ?>" type="text" class="regular-text" /></td>
552 </tr>
553 <tr valign="top">
554 <td>&nbsp;</td>
555 <th><label for="cryptX_var[c2i_fontRGB]"><?php _e("Font color (RGB)",'cryptx'); ?></label></th>
556 <td><input name="cryptX_var[c2i_fontRGB]" value="<?php echo $cryptX_var['c2i_fontRGB']; ?>" type="text" class="regular-text" /></td>
557 </tr>
558 </table>
559 <p><input type="submit" name="cryptX" class="button-primary" value="<?php _e('Save Changes') ?>" /></p>
560 </div>
561 </div>
562 <div id="rw_cryptx_general_box" class="postbox">
563 <h3><?php _e("General",'cryptx'); ?></h3>
564 <div class="inside">
565 <table class="form-table">
566 <tr valign="top">
567 <th scope="row"><?php _e("Apply CryptX to...",'cryptx'); ?></th>
568 <td><input name="cryptX_var[theContent]" type="checkbox" <?php echo (isset($cryptX_var['theContent']) == true) ? 'checked="checked"' : ''; ?> />&nbsp;&nbsp;<?php _e("Content",'cryptx'); ?> <?php _e("(<i>this can be disabled per Post by an Option</i>)",'cryptx'); ?><br/>
569 <input name="cryptX_var[theExcerpt]" type="checkbox" <?php echo (isset($cryptX_var['theExcerpt']) == true) ? 'checked="checked"' : ''; ?> />&nbsp;&nbsp;<?php _e("Excerpt",'cryptx'); ?><br/>
570 <input name="cryptX_var[commentText]" type="checkbox" <?php echo (isset($cryptX_var['commentText']) == true) ? 'checked="checked"' : ''; ?> />&nbsp;&nbsp;<?php _e("Comments",'cryptx'); ?><br/>
571 <input name="cryptX_var[widgetText]" type="checkbox" <?php echo (isset($cryptX_var['widgetText']) == true) ? 'checked="checked"' : ''; ?> />&nbsp;&nbsp;<?php _e("Widgets",'cryptx'); ?> <?php _e("(<i>works only on all widgets, not on a single widget</i>!)",'cryptx'); ?></td>
572 </tr>
573 <tr valign="top">
574 <th scope="row"><?php _e("Excluded ID's...",'cryptx'); ?></th>
575 <td><input name="cryptX_var[excludedIDs]" value="<?php echo $cryptX_var['excludedIDs']; ?>" type="text" class="regular-text" />
576 <br/><span class="setting-description"><?php _e("Enter all Page/Post ID's to exclude from CryptX as comma seperated list.",'cryptx'); ?></span>
577 <br/><input name="cryptX_var[metaBox]" <?php echo (isset($cryptX_var['metaBox']) == true) ? 'checked="checked"' : ''; ?> type="checkbox" />&nbsp;&nbsp;<?php _e("Enable the CryptX Widget on editing a post or page.",'cryptx'); ?></td>
578 </tr>
579 <tr valign="top">
580 <th scope="row"><?php _e("Type of decryption",'cryptx'); ?></th>
581 <td><input name="cryptX_var[java]" <?php echo (isset($cryptX_var['java']) == true) ? 'checked="checked"' : ''; ?> type="radio" value="1" />&nbsp;&nbsp;<?php _e("Use javascript to hide the Email-Link.",'cryptx'); ?><br/>
582 <input name="cryptX_var[java]" <?php echo (isset($cryptX_var['java']) != true) ? 'checked="checked"' : ''; ?> type="radio" value="0" />&nbsp;&nbsp;<?php _e("Use Unicode to hide the Email-Link.",'cryptx'); ?></td>
583 </tr>
584 <tr valign="top">
585 <th scope="row"><?php _e("Where to load the needed javascript...",'cryptx'); ?></th>
586 <td><input name="cryptX_var[load_java]" <?php echo (isset($cryptX_var['load_java']) != true) ? 'checked="checked"' : ''; ?> type="radio" value="0" />&nbsp;&nbsp;<?php _e("Load the javascript in the <b>header</b> of the page.",'cryptx'); ?><br/>
587 <input name="cryptX_var[load_java]" <?php echo (isset($cryptX_var['load_java']) == true) ? 'checked="checked"' : ''; ?> type="radio" value="1" />&nbsp;&nbsp;<?php _e("Load the javascript in the <b>footer</b> of the page.",'cryptx'); ?></td>
588 </tr>
589 <tr valign="top">
590 <th scope="row" colspan="2"><input name="cryptX_var[autolink]" <?php echo (isset($cryptX_var['autolink']) == true) ? 'checked="checked"' : ''; ?> type="checkbox" />&nbsp;&nbsp;<?php _e("Add mailto to all unlinked email addresses",'cryptx'); ?></th>
591 </tr>
592 </table>
593 <p><input type="submit" name="cryptX" class="button-primary" value="<?php _e('Save Changes') ?>" /></p>
594 </div>
595 </div>
596 <div id="rw_cryptx_howto_box" class="postbox">
597 <h3><?php _e("How to use CryptX in your Template",'cryptx'); ?></h3>
598 <div class="inside">
599 <table class="form-table">
600 <tr>
601 <td>In your Template you can use the following function to encrypt a email address:
602 <p style="border:1px solid #000; background-color: #e9e9e9;padding: 10px;">
603 <i>
604 &lt;?php <br/>
605 &nbsp;&nbsp;&nbsp;&nbsp; $mail="name@example.com"; <br/>
606 &nbsp;&nbsp;&nbsp;&nbsp; $text="Contact"; <br/>
607 &nbsp;&nbsp;&nbsp;&nbsp; $css ="email"; <br/>
608 &nbsp;&nbsp;&nbsp;&nbsp; if (function_exists('cryptx')) { <br/>
609 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cryptx($mail, $text, $css, 1); <br/>
610 &nbsp;&nbsp;&nbsp;&nbsp; } else { <br/>
611 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo sprintf('&lt;a href="mailto:%s" class="%s"&gt;%s&lt;/a&gt;', $mail, $css, ($text != "" ? $text : $mail)); <br/>
612 &nbsp;&nbsp;&nbsp;&nbsp; } <br/>
613 ?&gt;
614 </i></p>
615 <ol><li>parameter is the email address.</li>
616 <li>parameter is the linktext. If none given the email address is used.</li>
617 <li>parameter is a css class added to the link.</li>
618 <li>parameter is 1 for echo the encrypted email address or 0 to return the redult to a variable.</li></ol></td>
619 </tr>
620 </table>
621 </div>
622 </div>
623 </form>
624 <script type="text/javascript">
625 function cryptX_bild_wechsel(select){
626 document.getElementById("cryptXmailTo").src = select.options[select.options.selectedIndex].value;
627 return true;
628 }
629 </script>
630 <script type="text/javascript">
631 jQuery.ajax({
632 url: "<?php bloginfo('wpurl'); ?>?cryptx=news",
633 success: function(data) {
634 jQuery("#cryptx-news-content").html(data).fadeIn();
635 },
636 error: function() {
637 jQuery("#cryptx-news-content").html('An error ocured while loading News.').fadeIn();
638 }
639 });
640 </script>
641 </div>
642 </div>
643 <?php
644 }
645
646 /**
647 * Create Template functions...
648 * $content = string to convert
649 * $text = string to replace linktext
650 * $css = assign a css class to the link
651 * $echo = 0: keep result in a variable, 1: show result
652 */
653 function cryptx( $content, $text="", $css="", $echo=1 ) {
654 global $cryptX_var;
655 $content = rw_cryptx_autolink( $content, true );
656 $content = rw_cryptx_encryptx( $content, true );
657 $content = rw_cryptx_linktext( $content, true );
658 if("" != $text) {
659 $content = preg_replace( "/(<a[^>]*>)(.*)(<\/a>)/i", '$1'.$text.'$3', $content );
660 }
661 if("" != $css) {
662 $content = preg_replace( "/(<a[^>]*)(>)/i", '$1 class="'.$css.'"$2', $content );
663 }
664 if(1 == $echo) echo $content;
665 return $content;
666 }
667 ?>