Email Encoder Bundle – Protect Email Address - Version 1.3.0

Version Description

  • Also support special chars for the javascript methods, like , , , Chinese chars etcetera
  • Fixed bug unchecking options "use shortcode" and "use deprecated"
Download this release

Release Info

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

Code changes from version 1.2.1 to 1.3.0

email-encoder-bundle.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Email Encoder Bundle - Protect Email Address
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: 1.2.1
8
  Author URI: http://www.freelancephp.net
9
  License: Dual licensed under the MIT and GPL licenses
10
  Text Domain: email-encoder-bundle
@@ -12,7 +12,7 @@ Domain Path: /languages
12
  */
13
 
14
  // constants
15
- if (!defined('EMAIL_ENCODER_BUNDLE_VERSION')) { define('EMAIL_ENCODER_BUNDLE_VERSION', '1.2.1'); }
16
  if (!defined('EMAIL_ENCODER_BUNDLE_FILE')) { define('EMAIL_ENCODER_BUNDLE_FILE', __FILE__); }
17
  if (!defined('EMAIL_ENCODER_BUNDLE_KEY')) { define('EMAIL_ENCODER_BUNDLE_KEY', 'WP_Email_Encoder_Bundle'); }
18
  if (!defined('EMAIL_ENCODER_BUNDLE_DOMAIN')) { define('EMAIL_ENCODER_BUNDLE_DOMAIN', '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: 1.3.0
8
  Author URI: http://www.freelancephp.net
9
  License: Dual licensed under the MIT and GPL licenses
10
  Text Domain: email-encoder-bundle
12
  */
13
 
14
  // constants
15
+ if (!defined('EMAIL_ENCODER_BUNDLE_VERSION')) { define('EMAIL_ENCODER_BUNDLE_VERSION', '1.3.0'); }
16
  if (!defined('EMAIL_ENCODER_BUNDLE_FILE')) { define('EMAIL_ENCODER_BUNDLE_FILE', __FILE__); }
17
  if (!defined('EMAIL_ENCODER_BUNDLE_KEY')) { define('EMAIL_ENCODER_BUNDLE_KEY', 'WP_Email_Encoder_Bundle'); }
18
  if (!defined('EMAIL_ENCODER_BUNDLE_DOMAIN')) { define('EMAIL_ENCODER_BUNDLE_DOMAIN', 'email-encoder-bundle'); }
includes/class-eeb-admin.php CHANGED
@@ -18,7 +18,6 @@ abstract class Eeb_Admin {
18
  * @var array
19
  */
20
  private $default_options = array(
21
- 'version' => null,
22
  'method' => 'enc_ascii',
23
  'encode_mailtos' => 1,
24
  'encode_emails' => 0,
@@ -109,8 +108,6 @@ abstract class Eeb_Admin {
109
  * Set options from save values or defaults
110
  */
111
  private function set_options() {
112
- $upgrade = false;
113
-
114
  // first set defaults
115
  $this->options = $this->default_options;
116
 
@@ -119,49 +116,26 @@ abstract class Eeb_Admin {
119
 
120
  // backwards compatible (old values)
121
  if (empty($saved_options)) {
 
122
  $saved_options = get_option(EMAIL_ENCODER_BUNDLE_KEY . 'options');
123
 
124
  // cleanup old values
125
  delete_option(EMAIL_ENCODER_BUNDLE_KEY . 'options');
126
- }
127
-
128
- $version = get_option('eeb_version');
129
- if ($version !== false) {
130
- $saved_options['version'] = $version;
131
-
132
- // cleanup old value
133
- delete_option('eeb_version');
134
- }
135
-
136
- // set all options
137
- if (!empty($saved_options)) {
138
- $upgrade = true;
139
-
140
  foreach ($saved_options AS $key => $value) {
141
  $this->options[$key] = $value;
142
  }
143
  }
144
 
145
- if (!isset($saved_options['version']) || $saved_options['version'] != EMAIL_ENCODER_BUNDLE_VERSION) {
146
- if (empty($saved_options['version'])) {
147
- if ($upgrade) {
148
- // upgrade from version < 1.0.0
149
- $this->options['support_deprecated_names'] = 1;
150
- $this->options['shortcodes_in_widgets'] = 1;
151
-
152
- //update_option(EMAIL_ENCODER_BUNDLE_OPTIONS_NAME, $this->options);
153
- } else {
154
- // first time
155
- $this->initial_metabox_settings = true;
156
- }
157
- } else {
158
- // upgrading from version >= 1.0.0
159
-
160
- }
161
-
162
- // update version
163
- update_option(EMAIL_ENCODER_BUNDLE_OPTIONS_NAME, $this->options);
164
- }
165
 
166
  // set encode method
167
  $this->method = $this->get_method($this->options['method'], 'enc_ascii');
@@ -486,7 +460,7 @@ abstract class Eeb_Admin {
486
  <th><?php _e('Choose admin menu position', EMAIL_ENCODER_BUNDLE_DOMAIN) ?></th>
487
  <td><label><input type="checkbox" id="<?php echo EMAIL_ENCODER_BUNDLE_OPTIONS_NAME ?>[own_admin_menu]" name="<?php echo EMAIL_ENCODER_BUNDLE_OPTIONS_NAME ?>[own_admin_menu]" value="1" <?php checked('1', (int) $options['own_admin_menu']); ?> />
488
  <span><?php _e('Show as main menu item.', EMAIL_ENCODER_BUNDLE_DOMAIN) ?></span>
489
- <br /><span class="description">When disabled this page will be available under "General settings".</span>
490
  </label>
491
  </td>
492
  </tr>
18
  * @var array
19
  */
20
  private $default_options = array(
 
21
  'method' => 'enc_ascii',
22
  'encode_mailtos' => 1,
23
  'encode_emails' => 0,
108
  * Set options from save values or defaults
109
  */
110
  private function set_options() {
 
 
111
  // first set defaults
112
  $this->options = $this->default_options;
113
 
116
 
117
  // backwards compatible (old values)
118
  if (empty($saved_options)) {
119
+ // check old values
120
  $saved_options = get_option(EMAIL_ENCODER_BUNDLE_KEY . 'options');
121
 
122
  // cleanup old values
123
  delete_option(EMAIL_ENCODER_BUNDLE_KEY . 'options');
124
+ } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  foreach ($saved_options AS $key => $value) {
126
  $this->options[$key] = $value;
127
  }
128
  }
129
 
130
+ // @todo Update current version value
131
+ // $version = get_option('eeb_version');
132
+ // if ($version !== EMAIL_ENCODER_BUNDLE_VERSION) {
133
+ // update_option('eeb_version', $version);
134
+ // delete_option('eeb_version');
135
+ //
136
+ // // on first time loading
137
+ // $this->initial_metabox_settings = true;
138
+ // }
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  // set encode method
141
  $this->method = $this->get_method($this->options['method'], 'enc_ascii');
460
  <th><?php _e('Choose admin menu position', EMAIL_ENCODER_BUNDLE_DOMAIN) ?></th>
461
  <td><label><input type="checkbox" id="<?php echo EMAIL_ENCODER_BUNDLE_OPTIONS_NAME ?>[own_admin_menu]" name="<?php echo EMAIL_ENCODER_BUNDLE_OPTIONS_NAME ?>[own_admin_menu]" value="1" <?php checked('1', (int) $options['own_admin_menu']); ?> />
462
  <span><?php _e('Show as main menu item.', EMAIL_ENCODER_BUNDLE_DOMAIN) ?></span>
463
+ <br /><span class="description">When disabled this page will be available under "<?php _e('Settings') ?>".</span>
464
  </label>
465
  </td>
466
  </tr>
includes/class-eeb-site.php CHANGED
@@ -251,6 +251,7 @@ CSS;
251
  */
252
  public function shortcode_email_encoder_form() {
253
  // add style and script for ajax encoder
 
254
  wp_enqueue_script('email_encoder', plugins_url('js/email-encoder-bundle.min.js', EMAIL_ENCODER_BUNDLE_FILE), array('jquery'), EMAIL_ENCODER_BUNDLE_VERSION);
255
 
256
  return $this->get_encoder_form();
@@ -432,6 +433,9 @@ CSS;
432
  private function enc_ascii($value) {
433
  $mail_link = $value;
434
 
 
 
 
435
  $mail_letters = '';
436
 
437
  for ($i = 0; $i < strlen($mail_link); $i ++) {
@@ -460,21 +464,26 @@ CSS;
460
  return '<script type="text/javascript">'
461
  . '(function(){'
462
  . 'var ml="'. $mail_letters_enc .'",mi="'. $mail_indices .'",o="";'
463
- // . 'console.log("-----");'
464
- // . 'console.log("' . $mail_letters_enc . '");'
465
- // . 'console.log("' . $this->encodeURIComponent($mail_letters_enc) . '");'
466
- // . 'var test = decodeURIComponent(\'' . $this->encodeURIComponent($mail_letters_enc) . '\');'
467
- // . 'test = test.replace("\", "");'
468
- // . 'console.log(test);'
469
  . 'for(var j=0,l=mi.length;j<l;j++){'
470
  . 'o+=ml.charAt(mi.charCodeAt(j)-48);'
471
- . '}document.write(o);'
472
  . '}());'
473
  . '</script><noscript>'
474
  . $this->options['protection_text']
475
  . '</noscript>';
476
  }
477
 
 
 
 
 
 
 
 
 
 
 
 
478
  /**
479
  * Escape method
480
  * Taken from the plugin "Email Spam Protection" by Adam Hunter (http://blueberryware.net/2008/09/14/email-spam-protection/)
@@ -487,7 +496,7 @@ CSS;
487
 
488
  // break string into array of characters, we can't use string_split because its php5 only
489
  $split = preg_split('||', $string);
490
- $out = '<script type="text/javascript">' . "eval(unescape('";
491
 
492
  foreach ($split as $c) {
493
  // preg split will return empty first and last characters, check for them and ignore
251
  */
252
  public function shortcode_email_encoder_form() {
253
  // add style and script for ajax encoder
254
+ // wp_enqueue_script('email_encoder', plugins_url('js/src/email-encoder-bundle.js', EMAIL_ENCODER_BUNDLE_FILE), array('jquery'), EMAIL_ENCODER_BUNDLE_VERSION);
255
  wp_enqueue_script('email_encoder', plugins_url('js/email-encoder-bundle.min.js', EMAIL_ENCODER_BUNDLE_FILE), array('jquery'), EMAIL_ENCODER_BUNDLE_VERSION);
256
 
257
  return $this->get_encoder_form();
433
  private function enc_ascii($value) {
434
  $mail_link = $value;
435
 
436
+ // first encode, so special chars can be supported
437
+ $mail_link = $this->encodeURIComponent($mail_link);
438
+
439
  $mail_letters = '';
440
 
441
  for ($i = 0; $i < strlen($mail_link); $i ++) {
464
  return '<script type="text/javascript">'
465
  . '(function(){'
466
  . 'var ml="'. $mail_letters_enc .'",mi="'. $mail_indices .'",o="";'
 
 
 
 
 
 
467
  . 'for(var j=0,l=mi.length;j<l;j++){'
468
  . 'o+=ml.charAt(mi.charCodeAt(j)-48);'
469
+ . '}document.write(decodeURIComponent(o));' // decode at the end, this way special chars can be supported
470
  . '}());'
471
  . '</script><noscript>'
472
  . $this->options['protection_text']
473
  . '</noscript>';
474
  }
475
 
476
+ /**
477
+ * This is the opponent of JavaScripts decodeURIComponent()
478
+ * @link http://stackoverflow.com/questions/1734250/what-is-the-equivalent-of-javascripts-encodeuricomponent-in-php
479
+ * @param string $str
480
+ * @return string
481
+ */
482
+ private function encodeURIComponent($str) {
483
+ $revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
484
+ return strtr(rawurlencode($str), $revert);
485
+ }
486
+
487
  /**
488
  * Escape method
489
  * Taken from the plugin "Email Spam Protection" by Adam Hunter (http://blueberryware.net/2008/09/14/email-spam-protection/)
496
 
497
  // break string into array of characters, we can't use string_split because its php5 only
498
  $split = preg_split('||', $string);
499
+ $out = '<script type="text/javascript">' . "eval(decodeURIComponent('";
500
 
501
  foreach ($split as $c) {
502
  // preg split will return empty first and last characters, check for them and ignore
readme.txt CHANGED
@@ -2,10 +2,10 @@
2
  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.4.0
5
- Tested up to: 4.1.0
6
- Stable tag: 1.2.1
7
 
8
- Encode mailto links, email addresses, phone numbers and any text to hide them from (spam)bots. Mailto links will be protected automatically after activating plugin.
9
 
10
  == Description ==
11
 
@@ -13,8 +13,10 @@ Encode mailto links, email addresses, phone numbers and any text to hide them fr
13
 
14
  = Features =
15
  * Protect mailto links and plain email addresses
16
- * Protect phone numbers (or any text/html)
 
17
  * Also protect your RSS feeds
 
18
  * Use shortcodes, template functions, action and filter hooks
19
  * Use the Encoder Form to manually create encoded scripts
20
 
@@ -99,9 +101,8 @@ function extra_encode_filters($filter_callback) {
99
  }`
100
 
101
  = Can I use special characters (like Chinese)? =
102
- It's only possible to use special characters for the display. And only works by using the shortcode with the HTML encode method.
103
- Example:
104
- `[eeb_email method="enc_html" email="myname@myemail.nl" display="我的郵箱"]`
105
 
106
  = How to encode emails in all widgets (and not only text widgets)? =
107
 
@@ -124,6 +125,10 @@ It's possible to filter all widgets by using the [Widget Logic Plugin](https://w
124
 
125
  == Changelog ==
126
 
 
 
 
 
127
  = 1.2.1 =
128
  * Fixed bug index php error
129
 
2
  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.4.0
5
+ Tested up to: 4.1.1
6
+ Stable tag: 1.3.0
7
 
8
+ Encode mailto links, email addresses, phone numbers and any text to hide them from (spam)bots. Mailto links will be protected automatically.
9
 
10
  == Description ==
11
 
13
 
14
  = Features =
15
  * Protect mailto links and plain email addresses
16
+ * Protect phone numbers (or any text or html)
17
+ * Also supports special chars, like é, â, ö, Chinese characters etcetera
18
  * Also protect your RSS feeds
19
+
20
  * Use shortcodes, template functions, action and filter hooks
21
  * Use the Encoder Form to manually create encoded scripts
22
 
101
  }`
102
 
103
  = Can I use special characters (like Chinese)? =
104
+
105
+ Yes, since version 1.3.0 also specail characters are supported.
 
106
 
107
  = How to encode emails in all widgets (and not only text widgets)? =
108
 
125
 
126
  == Changelog ==
127
 
128
+ = 1.3.0 =
129
+ * Also support special chars for the javascript methods, like é, â, ö, Chinese chars etcetera
130
+ * Fixed bug unchecking options "use shortcode" and "use deprecated"
131
+
132
  = 1.2.1 =
133
  * Fixed bug index php error
134