PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.71
Email Encoder – Protect Email Addresses and Phone Numbers v0.71
2.5.0 2.4.8 trunk 0.10 0.11 0.12 0.20 0.21 0.22 0.30 0.31 0.32 0.40 0.41 0.42 0.50 0.60 0.70 0.71 0.80 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.5 1.5.2 1.51 1.53 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7
email-encoder-bundle / email-encoder-bundle.php
email-encoder-bundle Last commit date
images 13 years ago js 13 years ago lang 13 years ago email-encoder-bundle.php 13 years ago readme.txt 13 years ago screenshot-1.png 13 years ago screenshot-2.png 13 years ago screenshot-3.png 13 years ago
email-encoder-bundle.php
1007 lines
1 <?php
2 /*
3 Plugin Name: Email Encoder Bundle
4 Plugin URI: http://www.freelancephp.net/email-encoder-php-class-wp-plugin/
5 Description: Protect email addresses on your site and hide them from spambots by using an encoding method. Easy to use, flexible .
6 Author: Victor Villaverde Laan
7 Version: 0.71
8 Author URI: http://www.freelancephp.net
9 License: Dual licensed under the MIT and GPL licenses
10 */
11
12 /**
13 * Class WP_Email_Encoder_Bundle
14 * @package WP_Email_Encoder_Bundle
15 * @category WordPress Plugins
16 */
17 class WP_Email_Encoder_Bundle {
18
19 /**
20 * Current version
21 * @var string
22 */
23 var $version = '0.71';
24
25 /**
26 * Used as prefix for options entry and could be used as text domain (for translations)
27 * @var string
28 */
29 var $domain = 'WP_Email_Encoder_Bundle';
30
31 /**
32 * Name of the options
33 * @var string
34 */
35 var $options_name = 'WP_Email_Encoder_Bundle_options';
36
37 /**
38 * @var string
39 */
40 var $page_hook = null;
41
42 /**
43 * @var array
44 */
45 var $options = array(
46 'method' => 'enc_ascii',
47 'encode_mailtos' => 1,
48 'encode_emails' => 0,
49 'skip_posts' => '',
50 'class_name' => 'mailto-link',
51 'filter_posts' => 1,
52 'filter_widgets' => 1,
53 'filter_comments' => 1,
54 'filter_rss' => 1,
55 'protection_text' => '*protected email*',
56 'widget_logic_filter' => 0,
57 'show_encoded_check' => 0,
58 'own_admin_menu' => 1,
59 'powered_by' => 1,
60 );
61
62 /**
63 * @var array
64 */
65 var $skip_posts = array();
66
67 /**
68 * @var boolead
69 */
70 var $logged_in = FALSE;
71
72 /**
73 * @var string
74 */
75 var $method = 'enc_ascii';
76
77 /**
78 * @var array
79 */
80 var $methods = array();
81
82 /**
83 * Regexp
84 * @var array
85 */
86 var $regexp_patterns = array(
87 'mailto' => '/<a([^<>]*?)href=["\']mailto:(.*?)["\'](.*?)>(.*?)<\/a[\s+]*>/is',
88 'email' => '/([A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6})/is',
89 );
90
91 /**
92 * PHP4 constructor
93 */
94 function WP_Email_Encoder_Bundle() {
95 $this->__construct();
96 }
97
98 /**
99 * PHP5 constructor
100 */
101 function __construct() {
102 // load text domain for translations
103 load_plugin_textdomain($this->domain, FALSE, dirname(plugin_basename(__FILE__)) . '/lang/');
104
105 // set methods
106 $this->methods = array(
107 'enc_ascii' => array(
108 'name' => __('JavaScript ASCII (recommended)', $this->domain),
109 'description' => __('This encoding method uses javascript (<a href="http://rumkin.com/tools/mailto_encoder/" target="_blank">original source</a>). <br />Recommended, the savest method.', $this->domain),
110 ),
111 'enc_escape' => array(
112 'name' => __('JavaScript Escape', $this->domain),
113 'description' => __('This encoding method uses the javascript eval() function (<a href="http://blueberryware.net/2008/09/14/email-spam-protection/" target="_blank">original source</a>). <br />Pretty save method.', $this->domain),
114 ),
115 'enc_html' => array(
116 'name' => __('Html Encode', $this->domain),
117 'description' => __('This encoding method uses the antispambot() function, built-in WordPress (<a href="http://codex.wordpress.org/Function_Reference/antispambot" target="_blank">more info</a>). <br />Not recommended, especially when using the shortcode [encode_content]).', $this->domain),
118 ),
119 'random' => array(
120 'name' => __('Random', $this->domain),
121 'description' => __('Pick each time a random encoding method. <br />Not recommended, especially when using the shortcode [encode_content]).', $this->domain),
122 ),
123 );
124
125 // set option values
126 $this->set_options();
127
128 // prepare vars
129 $skip_posts = $this->options['skip_posts'];
130 $skip_posts = str_replace(' ', '', $skip_posts);
131 $skip_posts = explode(',', $skip_posts);
132 $this->skip_posts = $skip_posts;
133
134 // set uninstall hook
135 if (function_exists('register_deactivation_hook')) {
136 register_deactivation_hook(__FILE__, array($this, 'deactivation'));
137 }
138
139 // add actions
140 add_action('wp', array($this, 'wp'));
141 add_action('admin_init', array($this, 'admin_init'));
142 add_action('admin_menu', array($this, 'admin_menu'));
143 }
144
145 /**
146 * wp action
147 * @global type $user_ID
148 */
149 function wp() {
150 global $user_ID;
151 $this->logged_in = (bool) ($user_ID && current_user_can('manage_options'));
152
153 // shortcodes
154 add_shortcode('email_encoder_form', array($this, 'shortcode_email_encoder_form'));
155 add_shortcode('encode_email', array($this, 'shortcode_encode_email'));
156 add_shortcode('encode_content', array($this, 'shortcode_encode_content'));
157
158 if (is_feed()) {
159 // rss feed
160 if ($this->options['filter_rss']) {
161 $rss_filters = array('the_title', 'the_content', 'the_excerpt', 'the_title_rss', 'the_content_rss', 'the_excerpt_rss',
162 'comment_text_rss', 'comment_author_rss', 'the_category_rss', 'the_content_feed', 'author_feed_link', 'feed_link');
163
164 foreach($rss_filters as $filter) {
165 add_filter($filter, array($this, 'filter_rss_callback'), 100);
166 }
167 }
168 } else {
169 // add style when logged in
170 if ($this->logged_in) {
171 add_action('wp_head', array($this, 'wp_head'));
172 }
173
174 $filters = array();
175
176 // post content
177 if ($this->options['filter_posts']) {
178 array_push($filters, 'the_title', 'the_content', 'the_excerpt', 'get_the_excerpt');
179 }
180
181 // comments
182 if ($this->options['filter_comments']) {
183 array_push($filters, 'comment_text', 'comment_excerpt', 'comment_url', 'get_comment_author_url', 'get_comment_author_link', 'get_comment_author_url_link');
184 }
185
186 // widgets
187 if ($this->options['filter_widgets']) {
188 array_push($filters, 'widget_title', 'widget_text', 'widget_content');
189
190 // also replace shortcodes
191 add_filter('widget_text', 'do_shortcode', 100);
192 add_filter('widget_content', 'do_shortcode', 100); // filter of Widget Logic plugin
193 }
194
195 foreach($filters as $filter) {
196 add_filter($filter, array($this, 'filter_callback'), 100);
197 }
198 }
199
200 // action hook
201 do_action('init_email_encoder_bundle', array($this, 'filter_callback'), $this);
202 }
203
204 /**
205 * Shortcode showing encoder form
206 * @return string
207 */
208 function shortcode_email_encoder_form() {
209 // add style and script for ajax encoder
210 wp_enqueue_script('email_encoder', plugins_url('js/email-encoder-bundle.js', __FILE__), array('jquery'), $this->version);
211
212 return $this->get_encoder_form();
213 }
214
215 /**
216 * Shortcode encoding email
217 * @param array $attrs
218 * @return string
219 */
220 function shortcode_encode_email($attrs) {
221 if (!is_array($attrs) || !key_exists('email', $attrs)) {
222 return '';
223 }
224
225 $email = $attrs['email'];
226 $display = (key_exists('display', $attrs)) ? $attrs['display'] : $attrs['email'];
227 $method = (key_exists('method', $attrs)) ? $attrs['method'] : NULL;
228 $extra_attrs = (key_exists('extra_attrs', $attrs)) ? $attrs['extra_attrs'] : NULL;
229
230 return $this->encode_email($email, $display, $method, $extra_attrs);
231 }
232
233 /**
234 * Shortcode encoding content
235 * @param array $attrs
236 * @param string $content Optional
237 * @return string
238 */
239 function shortcode_encode_content($attrs, $content = '') {
240 $method = (is_array($attrs) && key_exists('method', $attrs)) ? $attrs['method'] : NULL;
241
242 return $this->encode($content, $method);
243 }
244
245 /**
246 * Add style/script for encoded mails when logged in
247 */
248 function wp_head() {
249 echo '<style type="text/css">' . "\n";
250 echo 'a.encoded-check { opacity:0.5; position:absolute; text-decoration:none !important; font:10px Arial !important; margin-top:-3px; color:#629632; font-weight:bold; }' . "\n";
251 echo 'a.encoded-check:hover { opacity:1; cursor:help; }' . "\n";
252 echo 'a.encoded-check img { width:10px; height:10px; }' . "\n";
253 echo '</style>' . "\n";
254 }
255
256 /**
257 * WP filter
258 * @param string $content
259 * @return string
260 */
261 function filter_callback($content) {
262 global $post;
263
264 if (isset($post) && in_array($post->ID, $this->skip_posts)) {
265 return $content;
266 }
267
268 return $this->filter($content, TRUE, $this->options['encode_mailtos'], $this->options['encode_emails']);
269 }
270
271 /**
272 * RSS Filter
273 * @param string $content
274 * @return string
275 */
276 function filter_rss_callback($content) {
277 return preg_replace($this->regexp_patterns, $this->options['protection_text'], $content);
278 }
279
280 /**
281 * admin_menu action
282 */
283 function admin_menu() {
284 if (function_exists('add_options_page') AND current_user_can('manage_options')) {
285 // add options page
286 if ($this->options['own_admin_menu']) {
287 $this->page_hook = add_menu_page('Email Encoder Bundle', 'Email Encoder Bundle',
288 'manage_options', __FILE__, array($this, 'options_page'),
289 plugins_url('images/icon-email-encoder-bundle-16.png', __FILE__));
290 } else {
291 $this->page_hook = add_options_page('Email Encoder Bundle', 'Email Encoder Bundle',
292 'manage_options', __FILE__, array($this, 'options_page'));
293 }
294
295 add_action('load-' . $this->page_hook, array($this, 'help_tabs'));
296 add_filter('contextual_help', array($this, 'contextual_help'), 10, 3);
297 }
298 }
299
300 /**
301 * Remove default contextual help text
302 * @param string $contextual_help
303 * @param integer $screen_id
304 * @param object $screen
305 * @return string
306 */
307 function contextual_help($contextual_help, $screen_id, $screen) {
308 if ($screen_id == $this->page_hook) {
309 $contextual_help = '';
310 }
311
312 return $contextual_help;
313 }
314
315 /**
316 * Create help tabs
317 */
318 function help_tabs() {
319 if (!function_exists('get_current_screen')) {
320 return;
321 }
322
323 $screen = get_current_screen();
324
325 $about = <<<ABOUT
326 <p><strong>Email Encoder Bundle - version {$this->version}</strong></p>
327 <p>Encode mailto links and (plain) email addresses and hide them from spambots. Easy to use, plugin works directly when activated. Save way to protect email addresses on your site.</p>
328 ABOUT;
329 $screen->add_help_tab(array(
330 'id' => 'about',
331 'title' => __('About'),
332 'content' => __($about),
333 ));
334
335 $shortcodes = <<<SHORTCODES
336 <p>Encode an email address:
337 <br/><code>[encode_email email="..." display="..."]</code> ("display" is optional)
338 </p>
339 <p>Encode some content:
340 <br/><code>[encode_content method="..."]...[/encode_content]</code> ("method" is optional)
341 </p>
342 <p>Puts an encoder form in your post:
343 <br/><code>[email_encoder_form]</code>
344 </p>
345 SHORTCODES;
346 $screen->add_help_tab(array(
347 'id' => 'shortcodes',
348 'title' => __('Shortcodes'),
349 'content' => __($shortcodes),
350 ));
351
352 $templatefunctions = <<<TEMPLATEFUNCTIONS
353 <p>Encode the given email (other params are optional):
354 <br/><code><&#63;php echo encode_email(\$email, [\$display], [\$method], [\$extra_attrs]); &#63;></code>
355 </p>
356 <p>Encode the given content for emails to encode (other param is optional):
357 <br/><code><&#63;php echo encode_content(\$content, [\$method]); &#63;></code>
358 </p>
359 <p>Filter the given content for emails to encode (other params are optional):
360 <br/><code><&#63;php echo encode_email_filter(\$content, [\$enc_tags], [\$enc_mailtos], [\$enc_plain_emails]); &#63;></code>
361 </p>
362 TEMPLATEFUNCTIONS;
363 $screen->add_help_tab(array(
364 'id' => 'templatefunctions',
365 'title' => __('Template functions'),
366 'content' => __($templatefunctions),
367 ));
368
369 $hooks = <<<HOOKS
370 <p>Add extra code on initializing this plugin, like extra filters for encoding.</p>
371 <pre>
372 function extra_encode_filters(\$filter_callback, \$object) {
373 add_filter('some_filter', \$filter_callback);
374 }
375 add_action('init_email_encoder_bundle', 'extra_encode_filters');
376 </pre>
377 HOOKS;
378 $screen->add_help_tab(array(
379 'id' => 'hooks',
380 'title' => __('Hooks'),
381 'content' => __($hooks),
382 ));
383
384 $sidebar = <<<SIDEBAR
385 <p>See <a href="http://wordpress.org/extend/plugins/email-encoder-bundle/faq/" target="_blank">FAQ</a> at WordPress.org</p>
386 <p>Send your <a href="http://www.freelancephp.net/contact/" target="_blank">question</a></p>
387 <p><strong>Please <a href="http://wordpress.org/extend/plugins/email-encoder-bundle/" target="_blank">rate this plugin</a> and vote if the plugin works.</strong></p>
388 SIDEBAR;
389 $screen->set_help_sidebar(__($sidebar));
390 }
391
392 /**
393 * admin_init action
394 */
395 function admin_init() {
396 // register settings
397 register_setting($this->domain, $this->options_name);
398
399 // actions
400 add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
401 }
402
403 /**
404 * admin_enqueue_scripts action
405 * @param string $hook_suffix
406 */
407 function admin_enqueue_scripts($hook_suffix) {
408 if ($hook_suffix == 'settings_page_email-encoder-bundle/email-encoder-bundle' || $hook_suffix == 'toplevel_page_email-encoder-bundle/email-encoder-bundle') {
409 // set dashboard postbox
410 wp_enqueue_script('dashboard');
411 // set dashboard style for wp < 3.2.0
412 if (isset($wp_version) AND version_compare(preg_replace('/-.*$/', '', $wp_version), '3.2.0', '<')) {
413 wp_admin_css('dashboard');
414 }
415
416 // add style and script for ajax encoder
417 wp_enqueue_script('email_encoder', plugins_url('js/email-encoder-bundle.js', __FILE__), array('jquery'), $this->version);
418 wp_enqueue_script('email_encoder_admin', plugins_url('js/email-encoder-bundle-admin.js', __FILE__), array('jquery'), $this->version);
419 }
420 }
421
422 /**
423 * Deactivation plugin method
424 */
425 function deactivation() {
426 delete_option($this->options_name);
427 unregister_setting($this->domain, $this->options_name);
428 }
429
430 /**
431 * Admin options page
432 */
433 function options_page() {
434 ?>
435 <div class="wrap">
436 <div class="icon32" id="icon-options-custom" style="background:url(<?php echo plugins_url('images/icon-email-encoder-bundle.png', __FILE__) ?>) no-repeat 50% 50%"><br></div>
437 <h2>Email Encoder Bundle - <em><small><?php _e('Protecting Email Addresses', $this->domain) ?></small></em></h2>
438
439 <script type="text/javascript">
440 var methodInfo = <?php echo json_encode($this->methods) ?>;
441 </script>
442 <div class="postbox-container metabox-holder meta-box-sortables" style="width: 68%">
443 <div style="margin:0 2%;">
444 <form method="post" action="options.php">
445 <?php
446 settings_fields($this->domain);
447 $this->set_options();
448 $options = $this->options;
449 ?>
450 <div class="postbox">
451 <div class="handlediv" title="<?php _e('Click to toggle') ?>"><br/></div>
452 <h3 class="hndle"><?php _e('General Settings') ?></h3>
453 <div class="inside">
454 <?php if (is_plugin_active('wp-mailto-links/wp-mailto-links.php')): ?>
455 <p class="description"><?php _e('Warning: "WP Mailto Links"-plugin is also activated, which could cause conflicts.', $this->domain) ?></p>
456 <?php endif; ?>
457 <fieldset class="options">
458 <table class="form-table">
459 <tr>
460 <th><?php _e('Encoding Method for Protection', $this->domain) ?></th>
461 <td><select id="<?php echo $this->options_name ?>[method]" name="<?php echo $this->options_name ?>[method]" class="method-info-select postform">
462 <?php foreach ($this->methods AS $method => $info): ?>
463 <option value="<?php echo $method ?>" <?php if ($this->method == $method) echo 'selected="selected"' ?>><?php echo $info['name']; if ($method == 'lim_email_ascii'){ echo ' (recommended)'; } ?></option>
464 <?php endforeach; ?>
465 </select>
466 <br />
467 <label><span class="description"></span></label>
468 </td>
469 </tr>
470 <tr>
471 <th><?php _e('Auto-Protect Emails', $this->domain) ?></th>
472 <td>
473 <label><input type="checkbox" id="encode_mailtos" name="<?php echo $this->options_name ?>[encode_mailtos]" value="1" <?php checked('1', (int) $options['encode_mailtos']); ?> />
474 <span><?php _e('Protect mailto links', $this->domain) ?></span> <span class="description"><?php _e('(example: &lt;a href="info@myemail.com"&gt;My Email&lt;/a&gt;)', $this->domain) ?></span>
475 </label>
476 <br/><label><input type="checkbox" id="encode_emails" name="<?php echo $this->options_name ?>[encode_emails]" value="1" <?php checked('1', (int) $options['encode_emails']); ?> />
477 <span><?php _e('Replace plain email addresses to protected mailto links', $this->domain) ?></span> <span class="description"><?php _e('(not recommended)', $this->domain) ?></span>
478 </label>
479 <br/>
480 <br/>
481 Apply on:
482 <br/>
483 <label><input type="checkbox" name="<?php echo $this->options_name ?>[filter_posts]" value="1" <?php checked('1', (int) $options['filter_posts']); ?> />
484 <span><?php _e('All posts', $this->domain) ?></span>
485 </label>
486 <br/><label><input type="checkbox" id="<?php echo $this->options_name ?>[filter_comments]" name="<?php echo $this->options_name ?>[filter_comments]" value="1" <?php checked('1', (int) $options['filter_comments']); ?> />
487 <span><?php _e('All comments', $this->domain) ?></span></label>
488 <br/><label><input type="checkbox" id="<?php echo $this->options_name ?>[filter_widgets]" name="<?php echo $this->options_name ?>[filter_widgets]" value="1" <?php checked('1', (int) $options['filter_widgets']); ?> />
489 <span><?php if ($this->options['widget_logic_filter']) { _e('All widgets (uses the <code>widget_content</code> filter of the Widget Logic plugin)', $this->domain); } else { _e('All text widgets', $this->domain); } ?></span></label>
490 <br/>
491 <br/>
492 <label>
493 <span><?php _e('Do <strong>not</strong> apply Auto-Protect on posts with ID:', $this->domain) ?></span>
494 <br/><input type="text" id="<?php echo $this->options_name ?>[skip_posts]" name="<?php echo $this->options_name ?>[skip_posts]" value="<?php echo $options['skip_posts']; ?>" />
495 <span class="description"><?php _e('(comma seperated, f.e.: 2, 7, 13, 32)', $this->domain) ?></span>
496 </label>
497 </td>
498 </tr>
499 <tr>
500 <th><?php _e('Class for Protected Links', $this->domain) ?></th>
501 <td><label><input type="text" id="<?php echo $this->options_name ?>[class_name]" name="<?php echo $this->options_name ?>[class_name]" value="<?php echo $options['class_name']; ?>" />
502 <span class="description"><?php _e('All protected mailto links will get these class(es) <em>(optional, else keep blank)</em>', $this->domain) ?></span></label></td>
503 </tr>
504 <tr>
505 <th><?php _e('Protect Emails in RSS Feeds', $this->domain) ?></th>
506 <td><label><input type="checkbox" id="filter_rss" name="<?php echo $this->options_name ?>[filter_rss]" value="1" <?php checked('1', (int) $options['filter_rss']); ?> />
507 <span><?php _e('Replace emails in RSS feeds with the following text:', $this->domain) ?></span></label>
508 <label><input type="text" id="protection_text" name="<?php echo $this->options_name ?>[protection_text]" value="<?php echo $options['protection_text']; ?>" />
509 </td>
510 </tr>
511 </table>
512 </fieldset>
513 <p class="submit">
514 <input class="button-primary" type="submit" disabled="disabled" value="<?php _e('Save Changes') ?>" />
515 </p>
516 </div>
517 </div>
518
519 <div class="postbox">
520 <div class="handlediv" title="<?php _e('Click to toggle') ?>"><br/></div>
521 <h3 class="hndle"><?php _e('Other Settings') ?></h3>
522 <div class="inside">
523 <fieldset class="options">
524 <table class="form-table">
525 <tr>
526 <th><?php _e('Check encoded content', $this->domain) ?></th>
527 <td><label><input type="checkbox" id="<?php echo $this->options_name ?>[show_encoded_check]" name="<?php echo $this->options_name ?>[show_encoded_check]" value="1" <?php checked('1', (int) $options['show_encoded_check']); ?> /> <span><?php _e('Show "sucessfully encoded" text for all encoded content, only when logged in as admin user', $this->domain) ?></span> <br /><span class="description">(this way you can check if emails are really encoded on your site)</span></label></td>
528 </tr>
529 <tr>
530 <th><?php _e('Admin menu position', $this->domain) ?></th>
531 <td><label><input type="checkbox" id="<?php echo $this->options_name ?>[own_admin_menu]" name="<?php echo $this->options_name ?>[own_admin_menu]" value="1" <?php checked('1', (int) $options['own_admin_menu']); ?> /> <span><?php _e('Show as main menu item', $this->domain) ?></span> <span class="description">(when disabled item will be shown under "General settings")</span></label></td>
532 </tr>
533 <tr>
534 <th><?php _e('Email Encoder Form Settings', $this->domain) ?></th>
535 <td><label><input type="checkbox" id="<?php echo $this->options_name ?>[powered_by]" name="<?php echo $this->options_name ?>[powered_by]" value="1" <?php checked('1', (int) $options['powered_by']); ?> /> <span><?php _e('Show the "powered by"-link on bottom of the encoder form', $this->domain) ?></span></label></td>
536 </tr>
537 </table>
538 </fieldset>
539 <p class="submit">
540 <input class="button-primary" type="submit" disabled="disabled" value="<?php _e('Save Changes') ?>" />
541 </p>
542 </div>
543 </div>
544 </form>
545
546 <div class="postbox">
547 <div class="handlediv" title="<?php _e('Click to toggle') ?>"><br/></div>
548 <h3 class="hndle"><?php _e('Email Encoder Form', $this->domain) ?></h3>
549 <div class="inside">
550 <?php echo $this->get_encoder_form(); ?>
551 </div>
552 </div>
553 </div>
554 </div>
555
556 <div class="postbox-container side metabox-holder meta-box-sortables" style="width:28%;">
557 <div style="margin:0 2%;">
558 <div class="postbox">
559 <div class="handlediv" title="<?php _e('Click to toggle') ?>"><br/></div>
560 <h3 class="hndle"><?php _e('Other Plugins', $this->domain) ?></h3>
561 <div class="inside">
562 <h4><img src="<?php echo plugins_url('images/icon-wp-external-links.png', __FILE__) ?>" width="16" height="16" /> WP External Links -
563 <em>
564 <?php if (is_plugin_active('wp-external-links/wp-external-links.php')): ?>
565 <?php _e('Activated, see', $this->domain) ?> <a href="<?php echo get_bloginfo('url') ?>/wp-admin/options-general.php?page=wp-external-links/wp-external-links.php"><?php _e('Settings') ?></a>
566 <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-external-links/wp-external-links.php')): ?>
567 <a href="<?php echo get_bloginfo('url') ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e('Activate this plugin.', $this->domain) ?></a>
568 <?php else: ?>
569 <a href="<?php echo get_bloginfo('url') ?>/wp-admin/plugin-install.php?tab=search&type=term&s=WP+External+Links+freelancephp&plugin-search-input=Search+Plugins"><?php _e('Get this plugin now', $this->domain) ?></a>
570 <?php endif; ?>
571 </em>
572 </h4>
573 <p><?php _e('Manage external links on your site: open in new window/tab, set icon, add "external", add "nofollow" and more.', $this->domain) ?>
574 <br /><a href="http://wordpress.org/extend/plugins/wp-external-links/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/wp-external-links-plugin/" target="_blank">FreelancePHP.net</a>
575 </p>
576
577 <h4><img src="<?php echo plugins_url('images/icon-wp-mailto-links.png', __FILE__) ?>" width="16" height="16" /> WP Mailto Links -
578 <em>
579 <?php if (is_plugin_active('wp-mailto-links/wp-mailto-links.php')): ?>
580 <?php _e('Activated, see', $this->domain) ?> <a href="<?php echo get_bloginfo('url') ?>/wp-admin/options-general.php?page=wp-mailto-links/wp-mailto-links.php"><?php _e('Settings') ?></a>
581 <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-mailto-links/wp-mailto-links.php')): ?>
582 <a href="<?php echo get_bloginfo('url') ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e('Activate this plugin.', $this->domain) ?></a>
583 <?php else: ?>
584 <a href="<?php echo get_bloginfo('url') ?>/wp-admin/plugin-install.php?tab=search&type=term&s=WP+Mailto+Links+freelancephp&plugin-search-input=Search+Plugins"><?php _e('Get this plugin now', $this->domain) ?></a>
585 <?php endif; ?>
586 </em>
587 </h4>
588 <p><?php _e('Manage mailto links on your site and protect emails from spambots, set mail icon and more.', $this->domain) ?>
589 <br /><a href="http://wordpress.org/extend/plugins/wp-mailto-links/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/wp-mailto-links-plugin/" target="_blank">FreelancePHP.net</a>
590 </p>
591 </div>
592 </div>
593 </div>
594 </div>
595 <div class="clear"></div>
596 </div>
597 <?php
598 }
599
600 /**
601 * Get the encoder form (to use as a demo, like on the options page)
602 * @return string
603 */
604 function get_encoder_form() {
605 ob_start();
606 ?>
607 <div class="email-encoder-form">
608 <form>
609 <fieldset>
610 <div class="input">
611 <table>
612 <tbody>
613 <tr>
614 <th><label for="email"><?php _e('Email Address:', $this->domain) ?></label></th>
615 <td><input type="text" class="regular-text" id="email" name="email" /></td>
616 </tr>
617 <tr>
618 <th><label for="display"><?php _e('Display Text:', $this->domain) ?></label></th>
619 <td><input type="text" class="regular-text" id="display" name="display" /></td>
620 </tr>
621 <tr>
622 <th><?php _e('Mailto Link', $this->domain) ?></th>
623 <td><span id="example"></span></td>
624 </tr>
625 <tr>
626 <th><label for="encode_method"><?php _e('Encoding Method:', $this->domain) ?></label></th>
627 <td><select id="encode_method" name="encode_method" class="postform">
628 <?php foreach ($this->methods AS $method => $info): ?>
629 <option value="<?php echo $method ?>" <?php if ($this->method == $method) echo 'selected="selected"' ?>><?php echo $info['name'] ?></option>
630 <?php endforeach; ?>
631 </select>
632 <input type="button" id="ajax_encode" value="<?php _e('Create Protected Mail Link', $this->domain) ?> &gt;&gt;" />
633 </td>
634 </tr>
635 </tbody>
636 </table>
637 </div>
638 <div class="output nodis">
639 <table>
640 <tbody>
641 <tr>
642 <th><label for="encoded_output"><?php _e('Protected Mail Link (code):', $this->domain) ?></label></th>
643 <td><textarea class="large-text node" id="encoded_output" name="encoded_output" cols="50" rows="4"></textarea></td>
644 </tr>
645 </tbody>
646 </table>
647 </div>
648 <?php if ($this->options['powered_by']): ?>
649 <p class="powered-by"><?php _e('Powered by', $this->domain) ?> <a rel="external" href="http://www.freelancephp.net/email-encoder-php-class-wp-plugin/">Email Encoder Bundle</a></p>
650 <?php endif; ?>
651 </fieldset>
652 </form>
653 </div>
654 <?php
655 $form = ob_get_contents();
656 ob_clean();
657
658 return $form;
659 }
660
661 /**
662 * Set options from save values or defaults
663 */
664 function set_options() {
665 // set options
666 $saved_options = get_option($this->options_name);
667
668 // backwards compatible (old values)
669 if (empty($saved_options)) {
670 $saved_options = get_option($this->domain . 'options');
671 }
672
673 // set all options
674 if (!empty($saved_options)) {
675 foreach ($saved_options AS $key => $value) {
676 $this->options[$key] = $value;
677 }
678 }
679
680 // set encode method
681 $this->method = $this->get_method($this->options['method']);
682
683 // set widget_content filter of Widget Logic plugin
684 $widget_logic_opts = get_option('widget_logic');
685 if (is_array($widget_logic_opts) AND key_exists('widget_logic-options-filter', $widget_logic_opts)) {
686 $this->options['widget_logic_filter'] = ($widget_logic_opts['widget_logic-options-filter'] == 'checked') ? 1 : 0;
687 }
688 }
689
690 /**
691 * Filter content for encoding
692 * @param string $content
693 * @param boolean $enc_tags Optional, default TRUE
694 * @param boolean $enc_mailtos Optional, default TRUE
695 * @param boolean $enc_plain_emails Optional, default TRUE
696 * @return string
697 */
698 function filter($content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE) {
699 // encode mailto links
700 if ($enc_mailtos) {
701 $content = preg_replace_callback($this->regexp_patterns['mailto'], array($this, 'callback_encode_email'), $content);
702 }
703
704 // replace plain emails
705 if ($enc_plain_emails) {
706 $content = preg_replace_callback($this->regexp_patterns['email'], array($this, 'callback_encode_email'), $content);
707 }
708
709 return $content;
710 }
711
712 /**
713 * Callback for encoding email
714 * @param array $match
715 * @return string
716 */
717 function callback_encode_email($match) {
718 if (count($match) < 3) {
719 return $this->encode_email($match[1]);
720 } else if (count($match) == 3) {
721 return $this->encode_email($match[2]);
722 }
723
724 return $this->encode_email($match[2], $match[4], null, $match[1] . ' ' . $match[3]);
725 }
726
727 /**
728 * Get method name
729 * @param string $method
730 * @param string $defaultMethod Optional, default 'enc_html'
731 * @return string
732 */
733 function get_method($method, $defaultMethod = 'enc_html') {
734 $method = strtolower($method);
735
736 if ('random' == $method) {
737 // set a random method
738 $method = array_rand($this->methods);
739 } else {
740 if (!method_exists($this, $method)) {
741 $method = $defaultMethod; // set default method
742 }
743 }
744
745 return $method;
746 }
747
748 /**
749 * Add html to encoded content to show check icon and text
750 * @param string $content
751 * @return string
752 */
753 function get_html_checked($content) {
754 if (!$this->logged_in || !$this->options['show_encoded_check']) {
755 return $content;
756 }
757
758 return $content
759 . '<a href="javascript:;" class="encoded-check"'
760 . ' title="' . __('Successfully Encoded (this is a check and only visible when logged in as admin)', $this->domain) . '">'
761 . '<img class="encoded-check-icon" src="' . plugins_url('images/icon-email-encoder-bundle.png', __FILE__)
762 . '" alt="' . __('Encoded', $this->domain) . '" />'
763 . __('Successfully Encoded', $this->domain) . '</a>';
764 }
765
766 /**
767 * Encode the given email into an encoded HTML link
768 * @param string $content
769 * @param string $method Optional, else the default setted method will; be used
770 * @param boolean $no_html_checked
771 * @return string
772 */
773 function encode($content, $method = NULL, $no_html_checked = FALSE) {
774 // get encode method
775 $method = $this->get_method($method, $this->method);
776
777 // add visual check
778 if ($no_html_checked !== TRUE) {
779 $content = $this->get_html_checked($content);
780 }
781
782 // get encoded email code
783 return $this->{$method}($content);
784 }
785
786 /**
787 * Encode the given email into an encoded HTML link
788 * @param string $email
789 * @param string $display Optional, if not set display will be the email
790 * @param string $method Optional, else the default setted method will; be used
791 * @param string $extra_attrs Optional
792 * @return string
793 */
794 function encode_email($email, $display = NULL, $method = NULL, $extra_attrs = '', $no_html_checked = FALSE) {
795 // decode entities
796 $email = html_entity_decode($email);
797
798 // set email as display
799 if ($display === NULL) {
800 $display = $email;
801 } else {
802 $display = html_entity_decode($display);
803 }
804
805 // get encode method
806 $method = $this->get_method($method, $this->method);
807
808 if ($method === 'enc_html') {
809 $email = $this->enc_html($email);
810 $display = $this->enc_html($display);
811 }
812
813 $class = $this->options['class_name'];
814 $extra_attrs = ' ' . trim($extra_attrs);
815 $mailto = '<a class="'. $class .'" href="mailto:' . $email . '"'. $extra_attrs . '>' . $display . '</a>';
816
817 if ($method === 'enc_html') {
818 // add visual check
819 if ($no_html_checked !== TRUE) {
820 $mailto = $this->get_html_checked($mailto);
821 }
822 } else {
823 $mailto = $this->encode($mailto, $method, $no_html_checked);
824 }
825
826 // get encoded email code
827 return $mailto;
828 }
829
830 /**
831 * ASCII method
832 * Based on function from Tyler Akins (http://rumkin.com/tools/mailto_encoder/)
833 *
834 * @param string $value
835 * @return string
836 */
837 function enc_ascii($value) {
838 $mail_link = $value;
839
840 $mail_letters = '';
841
842 for ($i = 0; $i < strlen($mail_link); $i ++) {
843 $l = substr($mail_link, $i, 1);
844
845 if (strpos($mail_letters, $l) === false) {
846 $p = rand(0, strlen($mail_letters));
847 $mail_letters = substr($mail_letters, 0, $p) .
848 $l . substr($mail_letters, $p, strlen($mail_letters));
849 }
850 }
851
852 $mail_letters_enc = str_replace("\\", "\\\\", $mail_letters);
853 $mail_letters_enc = str_replace("\"", "\\\"", $mail_letters_enc);
854
855 $mail_indices = '';
856 for ($i = 0; $i < strlen($mail_link); $i ++) {
857 $index = strpos($mail_letters, substr($mail_link, $i, 1));
858 $index += 48;
859 $mail_indices .= chr($index);
860 }
861
862 $mail_indices = str_replace("\\", "\\\\", $mail_indices);
863 $mail_indices = str_replace("\"", "\\\"", $mail_indices);
864
865 return '<script type="text/javascript">/*<![CDATA[*/'
866 . '(function(){'
867 . 'var ML="'. $mail_letters_enc .'",MI="'. $mail_indices .'",OT="";'
868 . 'for(var j=0;j<MI.length;j++){'
869 . 'OT+=ML.charAt(MI.charCodeAt(j)-48);'
870 . '}document.write(OT);'
871 . '}());'
872 . '/*]]>*/'
873 . '</script><noscript>'
874 . $this->options['protection_text']
875 . '</noscript>';
876 }
877
878 /**
879 * Escape method
880 * Taken from the plugin "Email Spam Protection" by Adam Hunter (http://blueberryware.net/2008/09/14/email-spam-protection/)
881 *
882 * @param string $value
883 * @return string
884 */
885 function enc_escape($value) {
886 $string = 'document.write(\'' . $value . '\')';
887
888 /* break string into array of characters, we can't use string_split because its php5 only :( */
889 $split = preg_split('||', $string);
890 $out = '<script type="text/javascript">/*<![CDATA[*/ ' . "eval(unescape('";
891
892 foreach ($split as $c) {
893 /* preg split will return empty first and last characters, check for them and ignore */
894 if (!empty($c)) {
895 $out .= '%' . dechex(ord($c));
896 }
897 }
898
899 $out .= "'))" . '/*]]>*/</script><noscript>'
900 . $this->options['protection_text']
901 . '</noscript>';
902
903 return $out;
904 }
905
906 /**
907 * Convert randomly chars to htmlentities
908 * This method is partly taken from WordPress
909 * @link http://codex.wordpress.org/Function_Reference/antispambot
910 *
911 * @param string $value
912 * @return string
913 */
914 function enc_html($value) {
915 // check for built-in WP function
916 if (function_exists('antispambot')) {
917 $enc_value = antispambot($value);
918 } else {
919 $enc_value = '';
920 srand((float) microtime() * 1000000);
921
922 for ($i = 0; $i < strlen($value); $i = $i + 1) {
923 $j = floor(rand( 0, 1));
924
925 if ($j == 0) {
926 $enc_value .= '&#' . ord(substr($value, $i, 1)) . ';';
927 } elseif ($j == 1) {
928 $enc_value .= substr($value, $i, 1);
929 }
930 }
931 }
932
933 $enc_value = str_replace('@', '&#64;', $enc_value);
934
935 return $enc_value;
936 }
937
938 } // end class WP_Email_Encoder_Bundle
939
940
941
942 /**
943 * Create instance
944 */
945 $WP_Email_Encoder_Bundle = new WP_Email_Encoder_Bundle;
946
947
948 /**
949 * Ajax Encoding request
950 */
951 if (!empty($_GET['ajaxEncodeEmail'])):
952 // input vars
953 $method = $_GET['method'];
954 $email = $_GET['email'];
955 $display = (empty($_GET['display'])) ? $email : $_GET['display'];
956
957 echo $WP_Email_Encoder_Bundle->encode_email($email, $display, $method, '', TRUE);
958 exit;
959 endif;
960
961 /**
962 * Template function for encoding email
963 * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
964 * @param string $email
965 * @param string $display if non given will be same as email
966 * @param string $method Optional, else the default setted method will; be used
967 * @param string $extra_attrs Optional
968 * @return string
969 */
970 if (!function_exists('encode_email')):
971 function encode_email($email, $display = NULL, $method = NULL, $extra_attrs = '') {
972 global $WP_Email_Encoder_Bundle;
973 return $WP_Email_Encoder_Bundle->encode_email($email, $display, $method, $extra_attrs);
974 }
975 endif;
976
977 /**
978 * Template function for encoding content
979 * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
980 * @param string $content
981 * @param string $method Optional, default NULL
982 * @return string
983 */
984 if (!function_exists('encode_content')):
985 function encode_content($content, $method = NULL) {
986 global $WP_Email_Encoder_Bundle;
987 return $WP_Email_Encoder_Bundle->encode($content, $method);
988 }
989 endif;
990
991 /**
992 * Template function for encoding emails in the given content
993 * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
994 * @param string $content
995 * @param boolean $enc_tags Optional, default TRUE
996 * @param boolean $enc_mailtos Optional, default TRUE
997 * @param boolean $enc_plain_emails Optional, default TRUE
998 * @return string
999 */
1000 if (!function_exists('encode_email_filter')):
1001 function encode_email_filter($content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE) {
1002 global $WP_Email_Encoder_Bundle;
1003 return $WP_Email_Encoder_Bundle->filter($content, $enc_tags, $enc_mailtos, $enc_plain_emails);
1004 }
1005 endif;
1006
1007 /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */