Email Encoder Bundle – Protect Email Address - Version 0.80

Version Description

(latest) = * Added screen settings * Registered metaboxes * Fixed bug random method * Workaround for display with special characters (like Chinese), works only with enc_html

Download this release

Release Info

Developer freelancephp
Plugin Icon 128x128 Email Encoder Bundle – Protect Email Address
Version 0.80
Comparing to
See all releases

Code changes from version 0.71 to 0.80

email-encoder-bundle.php CHANGED
@@ -4,23 +4,25 @@ 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)
@@ -35,9 +37,9 @@ class WP_Email_Encoder_Bundle {
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
@@ -64,11 +66,6 @@ class WP_Email_Encoder_Bundle {
64
  */
65
  var $skip_posts = array();
66
 
67
- /**
68
- * @var boolead
69
- */
70
- var $logged_in = FALSE;
71
-
72
  /**
73
  * @var string
74
  */
@@ -79,22 +76,6 @@ class WP_Email_Encoder_Bundle {
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
  */
@@ -143,196 +124,388 @@ class WP_Email_Encoder_Bundle {
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>
@@ -343,13 +516,8 @@ ABOUT;
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>
@@ -360,13 +528,8 @@ SHORTCODES;
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) {
@@ -375,316 +538,218 @@ function extra_encode_filters(\$filter_callback, \$object) {
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
  /**
@@ -695,7 +760,7 @@ SIDEBAR;
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);
@@ -706,6 +771,12 @@ SIDEBAR;
706
  $content = preg_replace_callback($this->regexp_patterns['email'], array($this, 'callback_encode_email'), $content);
707
  }
708
 
 
 
 
 
 
 
709
  return $content;
710
  }
711
 
@@ -724,45 +795,63 @@ SIDEBAR;
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
@@ -774,13 +863,15 @@ SIDEBAR;
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
  /**
@@ -792,22 +883,25 @@ SIDEBAR;
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'];
@@ -817,7 +911,7 @@ SIDEBAR;
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);
@@ -827,6 +921,28 @@ SIDEBAR;
827
  return $mailto;
828
  }
829
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
830
  /**
831
  * ASCII method
832
  * Based on function from Tyler Akins (http://rumkin.com/tools/mailto_encoder/)
@@ -862,14 +978,13 @@ SIDEBAR;
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>';
@@ -887,7 +1002,7 @@ SIDEBAR;
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 */
@@ -896,7 +1011,7 @@ SIDEBAR;
896
  }
897
  }
898
 
899
- $out .= "'))" . '/*]]>*/</script><noscript>'
900
  . $this->options['protection_text']
901
  . '</noscript>';
902
 
@@ -914,34 +1029,37 @@ SIDEBAR;
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
 
@@ -958,6 +1076,11 @@ if (!empty($_GET['ajaxEncodeEmail'])):
958
  exit;
959
  endif;
960
 
 
 
 
 
 
961
  /**
962
  * Template function for encoding email
963
  * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
@@ -1000,7 +1123,7 @@ endif;
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
 
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.80
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_Admin
14
  * @package WP_Email_Encoder_Bundle
15
  * @category WordPress Plugins
16
  */
17
+ if (!class_exists('WP_Email_Encoder_Bundle_Admin')):
18
+
19
+ class WP_Email_Encoder_Bundle_Admin {
20
 
21
  /**
22
  * Current version
23
  * @var string
24
  */
25
+ var $version = '0.80';
26
 
27
  /**
28
  * Used as prefix for options entry and could be used as text domain (for translations)
37
  var $options_name = 'WP_Email_Encoder_Bundle_options';
38
 
39
  /**
40
+ * @var boolead
41
  */
42
+ var $is_admin_user = FALSE;
43
 
44
  /**
45
  * @var array
66
  */
67
  var $skip_posts = array();
68
 
 
 
 
 
 
69
  /**
70
  * @var string
71
  */
76
  */
77
  var $methods = array();
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  /**
80
  * PHP5 constructor
81
  */
124
  }
125
 
126
  /**
127
+ * Set options from save values or defaults
 
128
  */
129
+ function set_options() {
130
+ // set options
131
+ $saved_options = get_option($this->options_name);
 
 
 
 
 
132
 
133
+ // backwards compatible (old values)
134
+ if (empty($saved_options)) {
135
+ $saved_options = get_option($this->domain . 'options');
136
+ }
 
137
 
138
+ // set all options
139
+ if (!empty($saved_options)) {
140
+ foreach ($saved_options AS $key => $value) {
141
+ $this->options[$key] = $value;
 
 
 
 
142
  }
143
+ }
144
 
145
+ // set encode method
146
+ $this->method = $this->get_method($this->options['method']);
147
 
148
+ // set widget_content filter of Widget Logic plugin
149
+ $widget_logic_opts = get_option('widget_logic');
150
+ if (is_array($widget_logic_opts) AND key_exists('widget_logic-options-filter', $widget_logic_opts)) {
151
+ $this->options['widget_logic_filter'] = ($widget_logic_opts['widget_logic-options-filter'] == 'checked') ? 1 : 0;
152
+ }
153
+ }
154
 
155
+ /**
156
+ * Get method name
157
+ * @param string $method
158
+ * @param string $defaultMethod Optional, default 'enc_html'
159
+ * @return string
160
+ */
161
+ function get_method($method, $defaultMethod = 'enc_html') {
162
+ $method = strtolower($method);
163
 
164
+ if ('random' == $method) {
165
+ // set a random method
166
+ $method = array_rand($this->methods);
167
 
168
+ if ('random' == $method) {
169
+ $method = $this->get_method($method, $defaultMethod);
 
170
  }
171
+ } else {
172
+ if (!method_exists($this, $method)) {
173
+ $method = $defaultMethod; // set default method
174
  }
175
  }
176
 
177
+ return $method;
 
178
  }
179
 
180
  /**
181
+ * Deactivation plugin method
 
182
  */
183
+ function deactivation() {
184
+ delete_option($this->options_name);
185
+ unregister_setting($this->domain, $this->options_name);
 
 
186
  }
187
 
188
  /**
189
+ * wp action
 
 
190
  */
191
+ function wp() {
192
+ // check admin
193
+ $this->is_admin_user = current_user_can('manage_options');
 
 
 
 
 
 
 
 
194
  }
195
 
196
  /**
197
+ * admin_init action
 
 
 
198
  */
199
+ function admin_init() {
200
+ // register settings
201
+ register_setting($this->domain, $this->options_name);
202
 
203
+ // actions
204
+ add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
205
  }
206
 
207
  /**
208
+ * admin_enqueue_scripts action
209
+ * @param string $hook_suffix
210
  */
211
+ function admin_enqueue_scripts($hook_suffix) {
212
+ global $wp_version;
213
+
214
+ if ($hook_suffix == 'settings_page_email-encoder-bundle/email-encoder-bundle' || $hook_suffix == 'toplevel_page_email-encoder-bundle/email-encoder-bundle') {
215
+ // set dashboard postbox
216
+ wp_enqueue_script('dashboard');
217
+
218
+ // set dashboard style for wp < 3.2.0
219
+ if (version_compare(preg_replace('/-.*$/', '', $wp_version), '3.2.0', '<')) {
220
+ wp_admin_css('dashboard');
221
+ }
222
+
223
+ // add style and script for ajax encoder
224
+ wp_enqueue_script('email_encoder', plugins_url('js/email-encoder-bundle.js', __FILE__), array('jquery'), $this->version);
225
+ wp_enqueue_script('email_encoder_admin', plugins_url('js/email-encoder-bundle-admin.js', __FILE__), array('jquery'), $this->version);
226
+ }
227
  }
228
 
229
  /**
230
+ * admin_menu action
 
 
231
  */
232
+ function admin_menu() {
233
+ if ($this->is_admin_user) {
234
+ return;
235
+ }
236
 
237
+ // add page and menu item
238
+ if ($this->options['own_admin_menu']) {
239
+ // create main menu item
240
+ $page_hook = add_menu_page(__('Email Encoder Bundle', $this->domain), __('Email Encoder Bundle', $this->domain),
241
+ 'manage_options', __FILE__, array($this, 'show_options_page'),
242
+ plugins_url('images/icon-email-encoder-bundle-16.png', __FILE__));
243
+ } else {
244
+ // create submenu item under "Settings"
245
+ $page_hook = add_options_page(__('Email Encoder Bundle', $this->domain), __('Email Encoder Bundle', $this->domain),
246
+ 'manage_options', __FILE__, array($this, 'show_options_page'));
247
  }
248
 
249
+ // load plugin page
250
+ add_action('load-' . $page_hook, array($this, 'load_options_page'));
251
  }
252
 
253
+ /* -------------------------------------------------------------------------
254
+ * Admin Options Page
255
+ * ------------------------------------------------------------------------*/
256
+
257
  /**
258
+ * Load admin options page
 
 
259
  */
260
+ function load_options_page() {
261
+ // add help tabs
262
+ $this->add_help_tabs();
263
+
264
+ // screen settings
265
+ if (function_exists('add_screen_option')) {
266
+ add_screen_option('layout_columns', array(
267
+ 'max' => 2,
268
+ 'default' => 2
269
+ ));
270
+ }
271
+
272
+ // add meta boxes
273
+ add_meta_box('general_settings', __('General Settings'), array($this, 'show_meta_box_content'), null, 'normal', 'core', array('general_settings'));
274
+ add_meta_box('admin_settings', __('Admin Settings'), array($this, 'show_meta_box_content'), null, 'normal', 'core', array('admin_settings'));
275
+ add_meta_box('encode_form', __('Email Encoder Form'), array($this, 'show_meta_box_content'), null, 'normal', 'core', array('encode_form'));
276
+ add_meta_box('other_plugins', __('Other Plugins'), array($this, 'show_meta_box_content'), null, 'side', 'core', array('other_plugins'));
277
  }
278
 
279
  /**
280
+ * Show admin options page
281
  */
282
+ function show_options_page() {
283
+ $this->set_options();
284
+ ?>
285
+ <div class="wrap">
286
+ <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>
287
+ <h2><?php echo get_admin_page_title() ?> - <em><small><?php _e('Protecting Email Addresses', $this->domain) ?></small></em></h2>
 
 
 
 
 
288
 
289
+ <?php if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true'): ?>
290
+ <div class="updated settings-error" id="setting-error-settings_updated">
291
+ <p><strong><?php _e('Settings saved.' ) ?></strong></p>
292
+ </div>
293
+ <?php endif; ?>
294
+
295
+ <form method="post" action="options.php">
296
+ <?php settings_fields($this->domain); ?>
297
+
298
+ <input type="hidden" name="<?php echo $this->domain ?>_nonce" value="<?php echo wp_create_nonce($this->domain) ?>" />
299
+ <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?>
300
+ <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?>
301
+
302
+ <div id="poststuff">
303
+ <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
304
+ <!--<div id="post-body-content"></div>-->
305
+
306
+ <div id="postbox-container-1" class="postbox-container">
307
+ <?php do_meta_boxes('', 'side', ''); ?>
308
+ </div>
309
+
310
+ <div id="postbox-container-2" class="postbox-container">
311
+ <?php do_meta_boxes('', 'normal', ''); ?>
312
+ <?php do_meta_boxes('', 'advanced', ''); ?>
313
+ </div>
314
+ </div> <!-- #post-body -->
315
+ </div> <!-- #poststuff -->
316
+ </form>
317
+ <script type="text/javascript">
318
+ var methodInfo = <?php echo json_encode($this->methods) ?>;
319
+ </script>
320
+ </div>
321
+ <?php
322
  }
323
 
324
  /**
325
+ * Show content of metabox (callback)
326
+ * @param array $post
327
+ * @param array $meta_box
 
 
328
  */
329
+ function show_meta_box_content($post, $meta_box) {
330
+ $key = $meta_box['args'][0];
331
+ $options = $this->options;
 
332
 
333
+ if ($key === 'general_settings') {
334
+ ?>
335
+ <?php if (is_plugin_active('wp-mailto-links/wp-mailto-links.php')): ?>
336
+ <p class="description"><?php _e('Warning: "WP Mailto Links"-plugin is also activated, which could cause conflicts.', $this->domain) ?></p>
337
+ <?php endif; ?>
338
+ <fieldset class="options">
339
+ <table class="form-table">
340
+ <tr>
341
+ <th><?php _e('Encoding Method for Protection', $this->domain) ?></th>
342
+ <td><select id="<?php echo $this->options_name ?>[method]" name="<?php echo $this->options_name ?>[method]" class="method-info-select postform">
343
+ <?php foreach ($this->methods AS $method => $info): ?>
344
+ <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>
345
+ <?php endforeach; ?>
346
+ </select>
347
+ <br />
348
+ <label><span class="description"></span></label>
349
+ </td>
350
+ </tr>
351
+ <tr>
352
+ <th><?php _e('Auto-Protect Emails', $this->domain) ?></th>
353
+ <td>
354
+ <label><input type="checkbox" id="encode_mailtos" name="<?php echo $this->options_name ?>[encode_mailtos]" value="1" <?php checked('1', (int) $options['encode_mailtos']); ?> />
355
+ <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>
356
+ </label>
357
+ <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']); ?> />
358
+ <span><?php _e('Replace plain email addresses to protected mailto links', $this->domain) ?></span> <span class="description"><?php _e('(not recommended)', $this->domain) ?></span>
359
+ </label>
360
+ <br/>
361
+ <br/>
362
+ Apply on:
363
+ <br/>
364
+ <label><input type="checkbox" name="<?php echo $this->options_name ?>[filter_posts]" value="1" <?php checked('1', (int) $options['filter_posts']); ?> />
365
+ <span><?php _e('All posts', $this->domain) ?></span>
366
+ </label>
367
+ <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']); ?> />
368
+ <span><?php _e('All comments', $this->domain) ?></span></label>
369
+ <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']); ?> />
370
+ <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>
371
+ <br/>
372
+ <br/>
373
+ <label>
374
+ <span><?php _e('Do <strong>not</strong> apply Auto-Protect on posts with ID:', $this->domain) ?></span>
375
+ <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']; ?>" />
376
+ <span class="description"><?php _e('(comma seperated, f.e.: 2, 7, 13, 32)', $this->domain) ?></span>
377
+ <br/><span class="description"><?php _e('Notice: shortcodes will still work on these posts.', $this->domain) ?></span>
378
+ </label>
379
+ </td>
380
+ </tr>
381
+ <tr>
382
+ <th><?php _e('Class for Protected Links', $this->domain) ?></th>
383
+ <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']; ?>" />
384
+ <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>
385
+ </tr>
386
+ <tr>
387
+ <th><?php _e('Protect Emails in RSS Feeds', $this->domain) ?></th>
388
+ <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']); ?> />
389
+ <span><?php _e('Replace emails in RSS feeds with the following text:', $this->domain) ?></span></label>
390
+ <label><input type="text" id="protection_text" name="<?php echo $this->options_name ?>[protection_text]" value="<?php echo $options['protection_text']; ?>" />
391
+ </td>
392
+ </tr>
393
+ </table>
394
+ </fieldset>
395
+ <p class="submit">
396
+ <input class="button-primary" type="submit" disabled="disabled" value="<?php _e('Save Changes') ?>" />
397
+ </p>
398
+ <br class="clear" />
399
+ <?php
400
+ } else if ($key === 'admin_settings') {
401
+ ?>
402
+ <fieldset class="options">
403
+ <table class="form-table">
404
+ <tr>
405
+ <th><?php _e('Check encoded content', $this->domain) ?></th>
406
+ <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 "successfully 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>
407
+ </tr>
408
+ <tr>
409
+ <th><?php _e('Admin menu position', $this->domain) ?></th>
410
+ <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>
411
+ </tr>
412
+ <tr>
413
+ <th><?php _e('Email Encoder Form Settings', $this->domain) ?></th>
414
+ <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>
415
+ </tr>
416
+ </table>
417
+ </fieldset>
418
+ <p class="submit">
419
+ <input class="button-primary" type="submit" disabled="disabled" value="<?php _e('Save Changes') ?>" />
420
+ </p>
421
+ <br class="clear" />
422
+ <?php
423
+ } else if ($key === 'encode_form') {
424
+ echo $this->get_encoder_form();
425
+ } else if ($key === 'other_plugins') {
426
+ ?>
427
+ <h4><img src="<?php echo plugins_url('images/icon-wp-external-links.png', __FILE__) ?>" width="16" height="16" /> WP External Links -
428
+ <?php if (is_plugin_active('wp-external-links/wp-external-links.php')): ?>
429
+ <a href="<?php echo get_bloginfo('url') ?>/wp-admin/options-general.php?page=wp-external-links/wp-external-links.php"><?php _e('Settings') ?></a>
430
+ <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-external-links/wp-external-links.php')): ?>
431
+ <a href="<?php echo get_bloginfo('url') ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e('Activate', $this->domain) ?></a>
432
+ <?php else: ?>
433
+ <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', $this->domain) ?></a>
434
+ <?php endif; ?>
435
+ </h4>
436
+ <p><?php _e('Manage external links on your site: open in new window/tab, set icon, add "external", add "nofollow" and more.', $this->domain) ?>
437
+ <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>
438
+ </p>
439
+
440
+ <h4><img src="<?php echo plugins_url('images/icon-wp-mailto-links.png', __FILE__) ?>" width="16" height="16" /> WP Mailto Links -
441
+ <?php if (is_plugin_active('wp-mailto-links/wp-mailto-links.php')): ?>
442
+ <a href="<?php echo get_bloginfo('url') ?>/wp-admin/options-general.php?page=wp-mailto-links/wp-mailto-links.php"><?php _e('Settings') ?></a>
443
+ <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-mailto-links/wp-mailto-links.php')): ?>
444
+ <a href="<?php echo get_bloginfo('url') ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e('Activate', $this->domain) ?></a>
445
+ <?php else: ?>
446
+ <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', $this->domain) ?></a>
447
+ <?php endif; ?>
448
+ </h4>
449
+ <p><?php _e('Manage mailto links on your site and protect emails from spambots, set mail icon and more.', $this->domain) ?>
450
+ <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>
451
+ </p>
452
+ <?php
453
+ }
454
  }
455
 
456
+ /* -------------------------------------------------------------------------
457
+ * Help Tabs
458
+ * ------------------------------------------------------------------------*/
459
+
460
  /**
461
+ * Add help tabs
462
  */
463
+ function add_help_tabs() {
464
  if (!function_exists('get_current_screen')) {
465
  return;
466
  }
467
 
468
  $screen = get_current_screen();
469
 
470
+ $screen->set_help_sidebar($this->get_help_text('sidebar'));
471
+
 
 
472
  $screen->add_help_tab(array(
473
  'id' => 'about',
474
  'title' => __('About'),
475
+ 'content' => $this->get_help_text('about'),
476
+ ));
477
+ $screen->add_help_tab(array(
478
+ 'id' => 'shortcodes',
479
+ 'title' => __('Shortcodes'),
480
+ 'content' => $this->get_help_text('shortcodes'),
481
+ ));
482
+ $screen->add_help_tab(array(
483
+ 'id' => 'templatefunctions',
484
+ 'title' => __('Template functions'),
485
+ 'content' => $this->get_help_text('templatefunctions'),
486
+ ));
487
+ $screen->add_help_tab(array(
488
+ 'id' => 'hooks',
489
+ 'title' => __('Hooks'),
490
+ 'content' => $this->get_help_text('hooks'),
491
  ));
492
+ }
493
 
494
+ /**
495
+ * Get text for given help tab
496
+ * @param string $key
497
+ * @return string
498
+ */
499
+ function get_help_text($key) {
500
+ if ($key === 'about') {
501
+ $plugin_title = get_admin_page_title();
502
+ $icon_url = plugins_url('images/icon-email-encoder-bundle.png', __FILE__);
503
+ $content = <<<ABOUT
504
+ <p><strong><img src="{$icon_url}" width="16" height="16" /> {$plugin_title} - version {$this->version}</strong></p>
505
+ <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>
506
+ ABOUT;
507
+ } else if ($key === 'shortcodes') {
508
+ $content = <<<SHORTCODES
509
  <p>Encode an email address:
510
  <br/><code>[encode_email email="..." display="..."]</code> ("display" is optional)
511
  </p>
516
  <br/><code>[email_encoder_form]</code>
517
  </p>
518
  SHORTCODES;
519
+ } else if ($key === 'templatefunctions') {
520
+ $content = <<<TEMPLATEFUNCTIONS
 
 
 
 
 
521
  <p>Encode the given email (other params are optional):
522
  <br/><code><&#63;php echo encode_email(\$email, [\$display], [\$method], [\$extra_attrs]); &#63;></code>
523
  </p>
528
  <br/><code><&#63;php echo encode_email_filter(\$content, [\$enc_tags], [\$enc_mailtos], [\$enc_plain_emails]); &#63;></code>
529
  </p>
530
  TEMPLATEFUNCTIONS;
531
+ } else if ($key === 'hooks') {
532
+ $content = <<<HOOKS
 
 
 
 
 
533
  <p>Add extra code on initializing this plugin, like extra filters for encoding.</p>
534
  <pre>
535
  function extra_encode_filters(\$filter_callback, \$object) {
538
  add_action('init_email_encoder_bundle', 'extra_encode_filters');
539
  </pre>
540
  HOOKS;
541
+ } else if ($key === 'sidebar') {
542
+ $content = <<<SIDEBAR
 
 
 
 
 
543
  <p>See <a href="http://wordpress.org/extend/plugins/email-encoder-bundle/faq/" target="_blank">FAQ</a> at WordPress.org</p>
544
  <p>Send your <a href="http://www.freelancephp.net/contact/" target="_blank">question</a></p>
545
  <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>
546
  SIDEBAR;
547
+ }
548
+
549
+ return ((empty($content)) ? '' : __($content, $this->domain));
550
  }
551
 
552
+ /* -------------------------------------------------------------------------
553
+ * Encoder Form
554
+ * -------------------------------------------------------------------------/
555
+
556
  /**
557
+ * Get the encoder form (to use as a demo, like on the options page)
558
+ * @return string
559
  */
560
+ function get_encoder_form() {
561
+ $lang_email = __('Email Address:', $this->domain);
562
+ $lang_display = __('Display Text:', $this->domain);
563
+ $lang_mailto = __('Mailto Link:', $this->domain);
564
+ $lang_method = __('Encoding Method:', $this->domain);
565
+ $lang_create = __('Create Protected Mail Link &gt;&gt;', $this->domain);
566
+ $lang_output = __('Protected Mail Link (code):', $this->domain);
567
+
568
+ $method_options = '';
569
+ foreach ($this->methods as $method => $info) {
570
+ $method_options .= '<option value="' . $method . '"' . (($this->method == $method) ? ' selected="selected"' : '') . '>' . $info['name'] . '</option>';
571
+ }
572
 
573
+ $powered_by = '';
574
+ if ($this->options['powered_by']) {
575
+ $powered_by .= '<p class="powered-by">' . __('Powered by', $this->domain) . ' <a rel="external" href="http://www.freelancephp.net/email-encoder-php-class-wp-plugin/">Email Encoder Bundle</a></p>';
576
+ }
577
+
578
+ return <<<FORM
579
+ <div class="email-encoder-form">
580
+ <form>
581
+ <fieldset>
582
+ <div class="input">
583
+ <table>
584
+ <tbody>
585
+ <tr>
586
+ <th><label for="email">{$lang_email}</label></th>
587
+ <td><input type="text" class="regular-text" id="email" name="email" /></td>
588
+ </tr>
589
+ <tr>
590
+ <th><label for="display">{$lang_display}</label></th>
591
+ <td><input type="text" class="regular-text" id="display" name="display" /></td>
592
+ </tr>
593
+ <tr>
594
+ <th>{$lang_mailto}</th>
595
+ <td><span id="example"></span></td>
596
+ </tr>
597
+ <tr>
598
+ <th><label for="encode_method">{$lang_method}</label></th>
599
+ <td><select id="encode_method" name="encode_method" class="postform">
600
+ {$method_options}
601
+ </select>
602
+ <input type="button" id="ajax_encode" value="{$lang_create}" />
603
+ </td>
604
+ </tr>
605
+ </tbody>
606
+ </table>
607
+ </div>
608
+ <div class="output nodis">
609
+ <table>
610
+ <tbody>
611
+ <tr>
612
+ <th><label for="encoded_output">{$lang_output}</label></th>
613
+ <td><textarea class="large-text node" id="encoded_output" name="encoded_output" cols="50" rows="4"></textarea></td>
614
+ </tr>
615
+ </tbody>
616
+ </table>
617
+ </div>
618
+ {$powered_by}
619
+ </fieldset>
620
+ </form>
621
+ </div>
622
+ FORM;
623
  }
624
 
625
+ } // end class WP_Email_Encoder_Bundle_Admin
626
+
627
+ endif;
628
+
629
+
630
+ /**
631
+ * Class WP_Email_Encoder_Bundle
632
+ * @package WP_Email_Encoder_Bundle
633
+ * @category WordPress Plugins
634
+ */
635
+ if (!class_exists('WP_Email_Encoder_Bundle')):
636
+
637
+ class WP_Email_Encoder_Bundle extends WP_Email_Encoder_Bundle_Admin {
638
+
639
  /**
640
+ * Regexp
641
+ * @var array
642
  */
643
+ var $regexp_patterns = array(
644
+ 'mailto' => '/<a([^<>]*?)href=["\']mailto:(.*?)["\'](.*?)>(.*?)<\/a[\s+]*>/is',
645
+ 'email' => '/([A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6})/is',
646
+ );
 
 
 
 
 
 
 
 
 
 
647
 
648
  /**
649
+ * PHP4 constructor
650
  */
651
+ function WP_Email_Encoder_Bundle() {
652
+ parent::__construct();
 
653
  }
654
 
655
  /**
656
+ * wp action
657
  */
658
+ function wp() {
659
+ parent::wp();
 
 
 
660
 
661
+ if (is_feed()) {
662
+ // rss feed
663
+ if ($this->options['filter_rss']) {
664
+ $rss_filters = array('the_title', 'the_content', 'the_excerpt', 'the_title_rss', 'the_content_rss', 'the_excerpt_rss',
665
+ 'comment_text_rss', 'comment_author_rss', 'the_category_rss', 'the_content_feed', 'author_feed_link', 'feed_link');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
666
 
667
+ foreach($rss_filters as $filter) {
668
+ add_filter($filter, array($this, 'callback_filter_rss'), 100);
669
+ }
670
+ }
671
+ } else {
672
+ // site
673
+ $filters = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
674
 
675
+ // post content
676
+ if ($this->options['filter_posts']) {
677
+ array_push($filters, 'the_title', 'the_content', 'the_excerpt', 'get_the_excerpt');
678
+ }
679
+
680
+ // comments
681
+ if ($this->options['filter_comments']) {
682
+ array_push($filters, 'comment_text', 'comment_excerpt', 'comment_url', 'get_comment_author_url', 'get_comment_author_link', 'get_comment_author_url_link');
683
+ }
684
+
685
+ // widgets
686
+ if ($this->options['filter_widgets']) {
687
+ array_push($filters, 'widget_title', 'widget_text', 'widget_content');
688
+
689
+ // also replace shortcodes
690
+ add_filter('widget_text', 'do_shortcode', 100);
691
+ add_filter('widget_content', 'do_shortcode', 100); // widget_content id filter of Widget Logic plugin
692
+ }
693
+
694
+ foreach($filters as $filter) {
695
+ add_filter($filter, array($this, 'callback_filter'), 100);
696
+ }
697
+ }
698
+
699
+ // shortcodes
700
+ add_shortcode('email_encoder_form', array($this, 'shortcode_email_encoder_form'));
701
+ add_shortcode('encode_email', array($this, 'shortcode_encode_email'));
702
+ add_shortcode('encode_content', array($this, 'shortcode_encode_content'));
703
+
704
+ // actions
705
+ add_action('wp_head', array($this, 'wp_head'));
706
+
707
+ // hook
708
+ do_action('init_email_encoder_bundle', array($this, 'callback_filter'), $this);
 
 
 
 
 
 
 
 
709
  }
710
 
711
  /**
712
+ * WP head
 
713
  */
714
+ function wp_head() {
715
+ // add styling for encoding check message + icon
716
+ if ($this->is_admin_user && $this->options['show_encoded_check']) {
717
+ echo <<<CSS
718
+ <style type="text/css">
719
+ a.encoded-check { opacity:0.5; position:absolute; text-decoration:none !important; font:10px Arial !important; margin-top:-3px; color:#629632; font-weight:bold; }
720
+ a.encoded-check:hover { opacity:1; cursor:help; }
721
+ a.encoded-check img { width:10px; height:10px; }
722
+ </style>
723
+ CSS;
724
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
725
  }
726
 
727
+ /* -------------------------------------------------------------------------
728
+ * Filter Callbacks
729
+ * -------------------------------------------------------------------------/
730
+
731
  /**
732
+ * WP filter callback
733
+ * @param string $content
734
+ * @return string
735
  */
736
+ function callback_filter($content) {
737
+ global $post;
 
 
 
 
 
 
738
 
739
+ if (isset($post) && in_array($post->ID, $this->skip_posts)) {
740
+ return $content;
 
 
 
741
  }
742
 
743
+ return $this->encode_email_filter($content, TRUE, $this->options['encode_mailtos'], $this->options['encode_emails']);
744
+ }
745
 
746
+ /**
747
+ * RSS Filter callback
748
+ * @param string $content
749
+ * @return string
750
+ */
751
+ function callback_filter_rss($content) {
752
+ return preg_replace($this->regexp_patterns, $this->options['protection_text'], $content);
753
  }
754
 
755
  /**
760
  * @param boolean $enc_plain_emails Optional, default TRUE
761
  * @return string
762
  */
763
+ function encode_email_filter($content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE) {
764
  // encode mailto links
765
  if ($enc_mailtos) {
766
  $content = preg_replace_callback($this->regexp_patterns['mailto'], array($this, 'callback_encode_email'), $content);
771
  $content = preg_replace_callback($this->regexp_patterns['email'], array($this, 'callback_encode_email'), $content);
772
  }
773
 
774
+ // workaround for double encoding bug when auto-protect mailto is enabled and method is enc_html
775
+ if ($this->options['encode_mailtos'] == 1) {
776
+ // change back to html tag
777
+ $content = str_replace('[a-replacement]', '<a', $content);
778
+ }
779
+
780
  return $content;
781
  }
782
 
795
  return $this->encode_email($match[2], $match[4], null, $match[1] . ' ' . $match[3]);
796
  }
797
 
798
+ /* -------------------------------------------------------------------------
799
+ * Shortcode Functions
800
+ * -------------------------------------------------------------------------/
801
+
802
  /**
803
+ * Shortcode showing encoder form
 
 
804
  * @return string
805
  */
806
+ function shortcode_email_encoder_form() {
807
+ // add style and script for ajax encoder
808
+ wp_enqueue_script('email_encoder', plugins_url('js/email-encoder-bundle.js', __FILE__), array('jquery'), $this->version);
809
 
810
+ return $this->get_encoder_form();
811
+ }
812
+
813
+ /**
814
+ * Shortcode encoding email
815
+ * @param array $attrs
816
+ * @return string
817
+ */
818
+ function shortcode_encode_email($attrs) {
819
+ if (!is_array($attrs) || !key_exists('email', $attrs)) {
820
+ return '';
821
  }
822
 
823
+ $email = $attrs['email'];
824
+ $display = (key_exists('display', $attrs)) ? $attrs['display'] : $attrs['email'];
825
+ $method = (key_exists('method', $attrs)) ? $attrs['method'] : NULL;
826
+ $extra_attrs = (key_exists('extra_attrs', $attrs)) ? $attrs['extra_attrs'] : NULL;
827
+
828
+ $encoded = $this->encode_email($email, $display, $method, $extra_attrs);
829
+
830
+ // workaround for double encoding bug when auto-protect mailto is enabled and method is enc_html
831
+ if ($this->options['encode_mailtos'] == 1 && $method === 'enc_html') {
832
+ // change html tag to entity
833
+ $encoded = str_replace('<a', '[a-replacement]', $encoded);
834
+ }
835
+
836
+ return $encoded;
837
  }
838
 
839
  /**
840
+ * Shortcode encoding content
841
+ * @param array $attrs
842
+ * @param string $content Optional
843
  * @return string
844
  */
845
+ function shortcode_encode_content($attrs, $content = '') {
846
+ $method = (is_array($attrs) && key_exists('method', $attrs)) ? $attrs['method'] : NULL;
 
 
847
 
848
+ return $this->encode($content, $method);
 
 
 
 
 
849
  }
850
 
851
+ /* -------------------------------------------------------------------------
852
+ * Encode Functions
853
+ * -------------------------------------------------------------------------/
854
+
855
  /**
856
  * Encode the given email into an encoded HTML link
857
  * @param string $content
863
  // get encode method
864
  $method = $this->get_method($method, $this->method);
865
 
866
+ // get encoded email code
867
+ $content = $this->{$method}($content);
868
+
869
  // add visual check
870
  if ($no_html_checked !== TRUE) {
871
+ $content = $this->get_success_check($content);
872
  }
873
 
874
+ return $content;
 
875
  }
876
 
877
  /**
883
  * @return string
884
  */
885
  function encode_email($email, $display = NULL, $method = NULL, $extra_attrs = '', $no_html_checked = FALSE) {
886
+ // get encode method
887
+ $method = $this->get_method($method, $this->method);
888
+
889
  // decode entities
890
  $email = html_entity_decode($email);
891
 
892
  // set email as display
893
  if ($display === NULL) {
894
  $display = $email;
895
+
896
+ if ($method === 'enc_html') {
897
+ $display = $this->enc_html($display);
898
+ }
899
  } else {
900
  $display = html_entity_decode($display);
901
  }
902
 
 
 
 
903
  if ($method === 'enc_html') {
904
  $email = $this->enc_html($email);
 
905
  }
906
 
907
  $class = $this->options['class_name'];
911
  if ($method === 'enc_html') {
912
  // add visual check
913
  if ($no_html_checked !== TRUE) {
914
+ $mailto = $this->get_success_check($mailto);
915
  }
916
  } else {
917
  $mailto = $this->encode($mailto, $method, $no_html_checked);
921
  return $mailto;
922
  }
923
 
924
+ /**
925
+ * Add html to encoded content to show check icon and text
926
+ * @param string $content
927
+ * @return string
928
+ */
929
+ function get_success_check($content) {
930
+ if (!$this->is_admin_user || !$this->options['show_encoded_check']) {
931
+ return $content;
932
+ }
933
+
934
+ return $content
935
+ . '<a href="javascript:;" class="encoded-check"'
936
+ . ' title="' . __('Successfully Encoded (this is a check and only visible when logged in as admin)', $this->domain) . '">'
937
+ . '<img class="encoded-check-icon" src="' . plugins_url('images/icon-email-encoder-bundle.png', __FILE__)
938
+ . '" alt="' . __('Encoded', $this->domain) . '" />'
939
+ . __('Successfully Encoded', $this->domain) . '</a>';
940
+ }
941
+
942
+ /* -------------------------------------------------------------------------
943
+ * Different Encoding Methods
944
+ * -------------------------------------------------------------------------/
945
+
946
  /**
947
  * ASCII method
948
  * Based on function from Tyler Akins (http://rumkin.com/tools/mailto_encoder/)
978
  $mail_indices = str_replace("\\", "\\\\", $mail_indices);
979
  $mail_indices = str_replace("\"", "\\\"", $mail_indices);
980
 
981
+ return '<script type="text/javascript">'
982
  . '(function(){'
983
+ . 'var ml="'. $mail_letters_enc .'",mi="'. $mail_indices .'",o="";'
984
+ . 'for(var j=0,l=mi.length;j<l;j++){'
985
+ . 'o+=ml.charAt(mi.charCodeAt(j)-48);'
986
+ . '}document.write(o);'
987
  . '}());'
 
988
  . '</script><noscript>'
989
  . $this->options['protection_text']
990
  . '</noscript>';
1002
 
1003
  /* break string into array of characters, we can't use string_split because its php5 only :( */
1004
  $split = preg_split('||', $string);
1005
+ $out = '<script type="text/javascript">' . "eval(unescape('";
1006
 
1007
  foreach ($split as $c) {
1008
  /* preg split will return empty first and last characters, check for them and ignore */
1011
  }
1012
  }
1013
 
1014
+ $out .= "'))" . '</script><noscript>'
1015
  . $this->options['protection_text']
1016
  . '</noscript>';
1017
 
1029
  function enc_html($value) {
1030
  // check for built-in WP function
1031
  if (function_exists('antispambot')) {
1032
+ $emailNOSPAMaddy = antispambot($value);
1033
  } else {
1034
+ $emailNOSPAMaddy = '';
1035
+ srand ((float) microtime() * 1000000);
1036
+ for ($i = 0; $i < strlen($emailaddy); $i = $i + 1) {
1037
+ $j = floor(rand(0, 1+$mailto));
1038
+ if ($j==0) {
1039
+ $emailNOSPAMaddy .= '&#'.ord(substr($emailaddy,$i,1)).';';
1040
+ } elseif ($j==1) {
1041
+ $emailNOSPAMaddy .= substr($emailaddy,$i,1);
1042
+ } elseif ($j==2) {
1043
+ $emailNOSPAMaddy .= '%'.zeroise(dechex(ord(substr($emailaddy, $i, 1))), 2);
1044
  }
1045
  }
1046
+ $emailNOSPAMaddy = str_replace('@','&#64;',$emailNOSPAMaddy);
1047
  }
1048
 
1049
+ $emailNOSPAMaddy = str_replace('@', '&#64;', $emailNOSPAMaddy);
1050
 
1051
+ return $emailNOSPAMaddy;
1052
  }
1053
 
1054
  } // end class WP_Email_Encoder_Bundle
1055
 
1056
+ endif;
1057
 
1058
 
1059
+ /*******************************************************************************
1060
  * Create instance
1061
+ *******************************************************************************/
1062
+
1063
  $WP_Email_Encoder_Bundle = new WP_Email_Encoder_Bundle;
1064
 
1065
 
1076
  exit;
1077
  endif;
1078
 
1079
+
1080
+ /*******************************************************************************
1081
+ * Template Functions
1082
+ *******************************************************************************/
1083
+
1084
  /**
1085
  * Template function for encoding email
1086
  * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
1123
  if (!function_exists('encode_email_filter')):
1124
  function encode_email_filter($content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE) {
1125
  global $WP_Email_Encoder_Bundle;
1126
+ return $WP_Email_Encoder_Bundle->encode_email_filter($content, $enc_tags, $enc_mailtos, $enc_plain_emails);
1127
  }
1128
  endif;
1129
 
js/email-encoder-bundle-admin.js CHANGED
@@ -1,10 +1,14 @@
 
1
  /*global jQuery*/
2
- // Email Encoder Bundle Plugin - Admin
3
  jQuery(function ($) {
4
  'use strict';
5
 
6
  var methodInfo = window.methodInfo;
7
 
 
 
 
 
8
  // set info text for selected encoding method
9
  $('.method-info-select')
10
  .bind('change', function () {
@@ -47,24 +51,7 @@ jQuery(function ($) {
47
  // add form-table class to Encoder Form tables
48
  $('.email-encoder-form table').addClass('form-table');
49
 
50
- // remove message
51
- $('.settings-error:first')
52
- .hide()
53
- .fadeIn(600)
54
- .delay(3000)
55
- .fadeOut(600);
56
-
57
- // slide postbox
58
- $('.postbox').find('.handlediv, .hndle').click(function(){
59
- var $inside = $(this).parent().find('.inside');
60
-
61
- if ($inside.css('display') === 'block') {
62
- $inside.css({ display:'block' }).fadeOut();
63
- } else {
64
- $inside.css({ display:'none' }).fadeIn();
65
- }
66
- });
67
-
68
  // prepare checkboxes before submit
69
  $('.wrap form').submit(function () {
70
  // force value 0 being saved in options
@@ -76,7 +63,7 @@ jQuery(function ($) {
76
  });
77
  });
78
 
79
- // enable
80
  $('*[type="submit"]').attr('disabled', false);
81
 
82
  });
1
+ /* Email Encoder Bundle Plugin - Admin */
2
  /*global jQuery*/
 
3
  jQuery(function ($) {
4
  'use strict';
5
 
6
  var methodInfo = window.methodInfo;
7
 
8
+ $('#setting-error-settings_updated').click(function () {
9
+ $(this).hide();
10
+ });
11
+
12
  // set info text for selected encoding method
13
  $('.method-info-select')
14
  .bind('change', function () {
51
  // add form-table class to Encoder Form tables
52
  $('.email-encoder-form table').addClass('form-table');
53
 
54
+ // Workaround for saving disabled checkboxes in options db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  // prepare checkboxes before submit
56
  $('.wrap form').submit(function () {
57
  // force value 0 being saved in options
63
  });
64
  });
65
 
66
+ // enable submit buttons
67
  $('*[type="submit"]').attr('disabled', false);
68
 
69
  });
js/email-encoder-bundle.js CHANGED
@@ -1,5 +1,5 @@
 
1
  /*global jQuery*/
2
- // Email Encoder Bundle Plugin
3
  jQuery(function($){
4
  'use strict';
5
 
1
+ /* Email Encoder Bundle Plugin */
2
  /*global jQuery*/
 
3
  jQuery(function($){
4
  'use strict';
5
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: freelancephp
3
  Tags: email address, protect, antispam, mailto, spambot, secure, e-mail, email, mail, obfuscate, encode, encoder, encrypt, hide, bot, crawl, spider, robots, spam, protection, harvest, harvesting, security
4
  Requires at least: 3.0.0
5
  Tested up to: 3.5.1
6
- Stable tag: 0.71
7
 
8
  Encode mailto links and (plain) email addresses on your site and hide them from spambots. Easy to use, plugin works directly when activated.
9
 
@@ -71,6 +71,11 @@ function extra_encode_filters($filter_callback) {
71
  add_filter('bbp_get_topic_content', $filter_callback);
72
  }`
73
 
 
 
 
 
 
74
  = How to encode emails in all widgets (and not only text widgets)? =
75
 
76
  If the option 'All text widgets' is activated, only text widgets will be filtered for encoding.
@@ -86,7 +91,13 @@ It's possible to filter all widgets by using the Widget Logic plugin and activat
86
 
87
  == Changelog ==
88
 
89
- = 0.71 (latest) =
 
 
 
 
 
 
90
  * Option to make own menu item (in admin panel) for this plugin
91
  * Option for showing "successfully encoded" check
92
  * Fixed bug showing errors for calling wrong translate function
3
  Tags: email address, protect, antispam, mailto, spambot, secure, e-mail, email, mail, obfuscate, encode, encoder, encrypt, hide, bot, crawl, spider, robots, spam, protection, harvest, harvesting, security
4
  Requires at least: 3.0.0
5
  Tested up to: 3.5.1
6
+ Stable tag: 0.80
7
 
8
  Encode mailto links and (plain) email addresses on your site and hide them from spambots. Easy to use, plugin works directly when activated.
9
 
71
  add_filter('bbp_get_topic_content', $filter_callback);
72
  }`
73
 
74
+ = Can I use special characters (like Chinese)? =
75
+ It's only possible to use special characters for the display. And only works by using the shortcode with the HTML encode method.
76
+ Example:
77
+ `[email_encode method="enc_html" email="myname@myemail.nl" display="我的郵箱"]`
78
+
79
  = How to encode emails in all widgets (and not only text widgets)? =
80
 
81
  If the option 'All text widgets' is activated, only text widgets will be filtered for encoding.
91
 
92
  == Changelog ==
93
 
94
+ = 0.80 (latest) =
95
+ * Added screen settings
96
+ * Registered metaboxes
97
+ * Fixed bug random method
98
+ * Workaround for display with special characters (like Chinese), works only with enc_html
99
+
100
+ = 0.71 =
101
  * Option to make own menu item (in admin panel) for this plugin
102
  * Option for showing "successfully encoded" check
103
  * Fixed bug showing errors for calling wrong translate function