Email Address Encoder - Version 1.0.17

Version Description

  • Offload email detection to web worker
  • Flush WP Super Cache and Cachify when saving settings
  • Ignore emails in admin bar, debug bar and query monitor
Download this release

Release Info

Developer tillkruess
Plugin Icon 128x128 Email Address Encoder
Version 1.0.17
Comparing to
See all releases

Code changes from version 1.0.16 to 1.0.17

email-address-encoder.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Email Address Encoder
4
  Plugin URI: https://encoder.till.im/
5
  Description: A lightweight plugin that protects email addresses from email-harvesting robots by encoding them into decimal and hexadecimal entities.
6
- Version: 1.0.16
7
  Author: Till Krüss
8
  Author URI: https://till.im/
9
  Text Domain: email-address-encoder
3
  Plugin Name: Email Address Encoder
4
  Plugin URI: https://encoder.till.im/
5
  Description: A lightweight plugin that protects email addresses from email-harvesting robots by encoding them into decimal and hexadecimal entities.
6
+ Version: 1.0.17
7
  Author: Till Krüss
8
  Author URI: https://till.im/
9
  Text Domain: email-address-encoder
includes/admin.php CHANGED
@@ -47,6 +47,11 @@ add_action( 'load-settings_page_email-address-encoder', 'eae_transmit_email' );
47
  */
48
  add_action( 'load-options.php', 'eae_clear_caches' );
49
 
 
 
 
 
 
50
  /**
51
  * Register AJAX callback for "eae_dismiss_notice" action.
52
  */
@@ -197,7 +202,7 @@ function eae_enqueue_scripts() {
197
  true
198
  );
199
 
200
- wp_localize_script( 'email-detector', 'eaeDetectorL10n', array(
201
  'one_email' => __( '1 Unprotected Email', 'email-address-encoder' ),
202
  'many_emails' => __( '{number} Unprotected Emails', 'email-address-encoder' ),
203
  ) );
@@ -374,6 +379,11 @@ function eae_clear_caches() {
374
  rocket_clean_domain();
375
  }
376
 
 
 
 
 
 
377
  // JCH Optimize
378
  if ( class_exists( 'JchPlatformCache' ) && method_exists( 'JchPlatformCache', 'deleteCache' ) ) {
379
  JchPlatformCache::deleteCache( true );
@@ -383,4 +393,34 @@ function eae_clear_caches() {
383
  if ( class_exists( 'LiteSpeed_Cache_API' ) && method_exists( 'LiteSpeed_Cache_API', 'purge_all' ) ) {
384
  LiteSpeed_Cache_API::purge_all();
385
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
  }
47
  */
48
  add_action( 'load-options.php', 'eae_clear_caches' );
49
 
50
+ /**
51
+ * Register callback that cleans responses for the email detector.
52
+ */
53
+ add_action( 'wp', 'eae_cleanup_response' );
54
+
55
  /**
56
  * Register AJAX callback for "eae_dismiss_notice" action.
57
  */
202
  true
203
  );
204
 
205
+ wp_localize_script( 'email-detector', 'eae_detector', array(
206
  'one_email' => __( '1 Unprotected Email', 'email-address-encoder' ),
207
  'many_emails' => __( '{number} Unprotected Emails', 'email-address-encoder' ),
208
  ) );
379
  rocket_clean_domain();
380
  }
381
 
382
+ // WP Super Cache
383
+ if ( function_exists( 'wp_cache_clear_cache' ) ) {
384
+ wp_cache_clear_cache();
385
+ }
386
+
387
  // JCH Optimize
388
  if ( class_exists( 'JchPlatformCache' ) && method_exists( 'JchPlatformCache', 'deleteCache' ) ) {
389
  JchPlatformCache::deleteCache( true );
393
  if ( class_exists( 'LiteSpeed_Cache_API' ) && method_exists( 'LiteSpeed_Cache_API', 'purge_all' ) ) {
394
  LiteSpeed_Cache_API::purge_all();
395
  }
396
+
397
+ // Cachify
398
+ if ( class_exists( 'Cachify' ) && method_exists( 'Cachify', 'flush_total_cache' ) ) {
399
+ Cachify::flush_total_cache( true );
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Remove output that might contain email addresses that
405
+ * would lead to false-positive matches.
406
+ *
407
+ * @return void
408
+ */
409
+ function eae_cleanup_response() {
410
+ if ( ! isset( $_SERVER[ 'HTTP_X_EMAIL_DETECTOR' ] ) || $_SERVER[ 'HTTP_X_EMAIL_DETECTOR' ] !== 'true' ) {
411
+ return;
412
+ }
413
+
414
+ // Disable Admin Bar
415
+ add_filter( 'show_admin_bar', '__return_false' );
416
+
417
+ // Disable Debug Bar
418
+ add_filter( 'debug_bar_enable', '__return_false' );
419
+
420
+ // Disable Query Monitor
421
+ add_filter( 'user_has_cap', function ( $caps ) {
422
+ $caps[ 'view_query_monitor' ] = false;
423
+
424
+ return $caps;
425
+ } );
426
  }
includes/email-detector.js CHANGED
@@ -1,14 +1,16 @@
1
  ( function () {
2
  var fetchPageSource = function () {
3
- if ( ! document.getElementById( "wp-admin-bar-root-default" ) ) {
4
  return;
5
  }
6
 
7
- if ( ! ( "fetch" in window ) ) {
8
  return;
9
  }
10
 
11
- fetch( document.location.href ).then( function ( response ) {
 
 
12
  if ( ! response.ok ) {
13
  throw Error( response.statusText );
14
  }
@@ -16,27 +18,53 @@
16
  return response;
17
  } ).then( function ( response ) {
18
  return response.text();
19
- } ).then( function ( pageSource ) {
20
- appendToAdminbar( findEmails( pageSource ) );
21
- } ).catch( function () {
22
  //
23
  } );
24
  };
25
 
26
- var findEmails = function ( content ) {
27
- var match;
28
- var emails = [];
29
- var regex = /(?:mailto:)?(?:[-!#$%&*+/=?^_`.{|}~\w\x80-\xFF]+|".*?")@(?:[-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+|\[[\d.a-fA-F:]+\])/gi;
 
 
 
 
 
 
 
 
 
30
 
31
- while ( ( match = regex.exec( content ) ) !== null ) {
32
- if ( match.index === regex.lastIndex ) {
33
- regex.lastIndex++;
34
  }
 
35
 
36
- emails.push( match[ 0 ] );
37
- }
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- return emails;
 
 
 
 
 
 
 
40
  };
41
 
42
  var appendToAdminbar = function ( emails ) {
@@ -47,8 +75,8 @@
47
  var scannerUrl = "https://encoder.till.im/scanner?utm_source=wp-plugin&utm_medium=adminbar";
48
 
49
  var text = emails.length === 1
50
- ? eaeDetectorL10n.one_email
51
- : eaeDetectorL10n.many_emails.replace( "{number}", emails.length );
52
 
53
  var a = document.createElement( "a" );
54
  a.setAttribute( "class", "ab-item" );
1
  ( function () {
2
  var fetchPageSource = function () {
3
+ if ( ! ( "fetch" in window ) ) {
4
  return;
5
  }
6
 
7
+ if ( ! document.getElementById( "wp-admin-bar-root-default" ) ) {
8
  return;
9
  }
10
 
11
+ fetch( document.location.href, {
12
+ headers: { "X-Email-Detector": "true" },
13
+ }).then( function ( response ) {
14
  if ( ! response.ok ) {
15
  throw Error( response.statusText );
16
  }
18
  return response;
19
  } ).then( function ( response ) {
20
  return response.text();
21
+ } ).then( findEmails ).catch( function () {
 
 
22
  //
23
  } );
24
  };
25
 
26
+ var findEmails = function ( pageSource ) {
27
+ if ( typeof( Worker ) === "undefined" ) {
28
+ return;
29
+ }
30
+
31
+ var worker = new Worker(
32
+ URL.createObjectURL(
33
+ new Blob(
34
+ [ "(", emailWorker.toString(), ")()" ],
35
+ { type: "application/javascript" }
36
+ )
37
+ )
38
+ );
39
 
40
+ worker.addEventListener( "message", function ( message ) {
41
+ if ( message.data.command === "done" ) {
42
+ appendToAdminbar( message.data.emails );
43
  }
44
+ }, false );
45
 
46
+ worker.postMessage({ pageSource: pageSource });
47
+ };
48
+
49
+ var emailWorker = function () {
50
+ self.addEventListener( "message", function ( message ) {
51
+ var match;
52
+ var emails = [];
53
+ var regex = /(?:mailto:)?(?:[-!#$%&*+/=?^_`.{|}~\w\x80-\xFF]+|".*?")@(?:[-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+|\[[\d.a-fA-F:]+\])/gi;
54
+
55
+ while ( ( match = regex.exec( message.data.pageSource ) ) !== null ) {
56
+ if ( match.index === regex.lastIndex ) {
57
+ regex.lastIndex++;
58
+ }
59
 
60
+ emails.push( match[ 0 ] );
61
+ }
62
+
63
+ self.postMessage({
64
+ command: "done",
65
+ emails: emails,
66
+ });
67
+ } );
68
  };
69
 
70
  var appendToAdminbar = function ( emails ) {
75
  var scannerUrl = "https://encoder.till.im/scanner?utm_source=wp-plugin&utm_medium=adminbar";
76
 
77
  var text = emails.length === 1
78
+ ? eae_detector.one_email
79
+ : eae_detector.many_emails.replace( "{number}", emails.length );
80
 
81
  var a = document.createElement( "a" );
82
  a.setAttribute( "class", "ab-item" );
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: antispam, anti spam, spam, email, e-mail, mail, spider, crawler, harvester
5
  Requires at least: 2.0
6
  Tested up to: 5.1
7
  Requires PHP: 5.3
8
- Stable tag: 1.0.16
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
@@ -67,6 +67,12 @@ You can use the "Page Scanner" found under _Settings -> Email Encoder_ to see wh
67
 
68
  == Changelog ==
69
 
 
 
 
 
 
 
70
  = 1.0.16 =
71
 
72
  * Avoid fatal error when using PHP 5.5 or lesser
5
  Requires at least: 2.0
6
  Tested up to: 5.1
7
  Requires PHP: 5.3
8
+ Stable tag: 1.0.17
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
67
 
68
  == Changelog ==
69
 
70
+ = 1.0.17 =
71
+
72
+ * Offload email detection to web worker
73
+ * Flush WP Super Cache and Cachify when saving settings
74
+ * Ignore emails in admin bar, debug bar and query monitor
75
+
76
  = 1.0.16 =
77
 
78
  * Avoid fatal error when using PHP 5.5 or lesser