Email Address Encoder - Version 1.0.3

Version Description

  • Added filter to override the function called to encode
  • Improved randomness of encode-function
  • Improved speed by doing fast @-sign existence check
Download this release

Release Info

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

Code changes from version 1.0.2 to 1.0.3

Files changed (2) hide show
  1. email-address-encoder.php +15 -9
  2. readme.txt +47 -11
email-address-encoder.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Email Address Encoder
4
  Plugin URI: http://wordpress.org/extend/plugins/email-address-encoder/
5
  Description: A lightweight plugin to protect email addresses from email-harvesting robots by encoding them into decimal and hexadecimal entities.
6
- Version: 1.0.2
7
  Author: Till Krüss
8
  Author URI: http://tillkruess.com/
9
  License: GPLv3
@@ -31,7 +31,7 @@ License: GPLv3
31
 
32
  /**
33
  * Register filters to encode exposed email addresses in
34
- * posts, pages, comments & widgets.
35
  */
36
  foreach (array('the_content', 'the_excerpt', 'widget_text', 'comment_text', 'comment_excerpt') as $filter) {
37
  add_filter($filter, 'eae_encode_emails', 1000);
@@ -39,19 +39,25 @@ foreach (array('the_content', 'the_excerpt', 'widget_text', 'comment_text', 'com
39
 
40
  /**
41
  * Searches for plain email addresses in given $string and
42
- * encodes them with the help of eae_encode_str().
43
  *
44
  * Regular expression is based on based on John Gruber's Markdown.
45
  * http://daringfireball.net/projects/markdown/
46
  *
47
- * @uses eae_encode_str()
48
- *
49
  * @param string $string Text with email addresses to encode
50
  * @return string $string Given text with encoded email addresses
51
  */
52
  function eae_encode_emails($string) {
53
 
54
- // Use the 'eae_regexp' filter to override
 
 
 
 
 
 
 
 
55
  $regexp = apply_filters(
56
  'eae_regexp',
57
  '{
@@ -74,7 +80,7 @@ function eae_encode_emails($string) {
74
  $regexp,
75
  create_function(
76
  '$matches',
77
- 'return eae_encode_str($matches[0]);'
78
  ),
79
  $string
80
  );
@@ -99,7 +105,7 @@ function eae_encode_emails($string) {
99
  function eae_encode_str($string) {
100
 
101
  $chars = str_split($string);
102
- $seed = (int) abs(crc32($string) / strlen($string));
103
 
104
  foreach ($chars as $key => $char) {
105
 
@@ -109,7 +115,7 @@ function eae_encode_str($string) {
109
 
110
  $r = ($seed * (1 + $key)) % 100; // pseudo "random function"
111
 
112
- if ($r > 80 && $char != '@') ; // plain character (not encoded)
113
  else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; // hexadecimal
114
  else $chars[$key] = '&#'.$ord.';'; // decimal (ascii)
115
 
3
  Plugin Name: Email Address Encoder
4
  Plugin URI: http://wordpress.org/extend/plugins/email-address-encoder/
5
  Description: A lightweight plugin to protect email addresses from email-harvesting robots by encoding them into decimal and hexadecimal entities.
6
+ Version: 1.0.3
7
  Author: Till Krüss
8
  Author URI: http://tillkruess.com/
9
  License: GPLv3
31
 
32
  /**
33
  * Register filters to encode exposed email addresses in
34
+ * posts, pages, excerpts, comments and widgets.
35
  */
36
  foreach (array('the_content', 'the_excerpt', 'widget_text', 'comment_text', 'comment_excerpt') as $filter) {
37
  add_filter($filter, 'eae_encode_emails', 1000);
39
 
40
  /**
41
  * Searches for plain email addresses in given $string and
42
+ * encodes them (by default) with the help of eae_encode_str().
43
  *
44
  * Regular expression is based on based on John Gruber's Markdown.
45
  * http://daringfireball.net/projects/markdown/
46
  *
 
 
47
  * @param string $string Text with email addresses to encode
48
  * @return string $string Given text with encoded email addresses
49
  */
50
  function eae_encode_emails($string) {
51
 
52
+ // abort if $string doesn't contain a @-sign
53
+ if (apply_filters('eae_at_sign_check', true)) {
54
+ if (strpos($string, '@') === false) return $string;
55
+ }
56
+
57
+ // override encoding function with the 'eae_method' filter
58
+ $method = apply_filters('eae_method', 'eae_encode_str');
59
+
60
+ // override regex pattern with the 'eae_regexp' filter
61
  $regexp = apply_filters(
62
  'eae_regexp',
63
  '{
80
  $regexp,
81
  create_function(
82
  '$matches',
83
+ 'return '.$method.'($matches[0]);'
84
  ),
85
  $string
86
  );
105
  function eae_encode_str($string) {
106
 
107
  $chars = str_split($string);
108
+ $seed = mt_rand(0, (int) abs(crc32($string) / strlen($string)));
109
 
110
  foreach ($chars as $key => $char) {
111
 
115
 
116
  $r = ($seed * (1 + $key)) % 100; // pseudo "random function"
117
 
118
+ if ($r > 60 && $char != '@') ; // plain character (not encoded), if not @-sign
119
  else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; // hexadecimal
120
  else $chars[$key] = '&#'.$ord.';'; // decimal (ascii)
121
 
readme.txt CHANGED
@@ -1,37 +1,69 @@
1
  === Email Address Encoder ===
2
  Contributors: tillkruess
 
3
  Tags: antispam, anti spam, spam, email, e-mail, mail, spider, crawler, harvester, robots, spambot, block, obfuscate, obfuscation, encode, encoder, encoding, encrypt, encryption, protect, protection
4
  Requires at least: 2.0
5
- Tested up to: 3.3
6
- Stable tag: 1.0.2
 
 
7
 
8
  A lightweight plugin to protect email addresses from email-harvesting robots by encoding them into decimal and hexadecimal entities.
9
 
 
10
  == Description ==
11
 
12
  A lightweight plugin to protect plain email addresses and mailto links from email-harvesting robots by encoding them into decimal and hexadecimal entities. Has effect on the posts, pages, comments, excerpts and text widgets. No UI, no shortcode, no JavaScript — just simple spam protection.
13
 
14
 
15
- == Usage ==
16
 
17
- To manually encode an single email address use the `eae_encode_str()` function: `<?php echo eae_encode_str('foobar@example.com'); ?>`
18
 
19
- To manually encode all email addresses in a string pass it through the `eae_encode_emails()` function: `<?php echo eae_encode_emails($text); ?>`
 
 
20
 
21
- To override the regular expression used to find email addresses use the `eae_regexp` filter: `<?php add_filter('eae_regexp', $pattern); ?>`
22
 
 
23
 
24
- == Installation ==
25
 
26
- For detailed installation instructions, please read the [standard installation procedure for WordPress plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins).
27
 
28
- 1. Upload the `/email-address-encoder/` directory and its contents to `/wp-content/plugins/`.
29
- 2. Login to your WordPress installation and activate the plugin through the _Plugins_ menu.
30
- 3. Done. This plugin works without a no user interface or configuration options.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
 
33
  == Changelog ==
34
 
 
 
 
 
 
 
35
  = 1.0.2 =
36
 
37
  * Added filter to override the regular expression.
@@ -47,6 +79,10 @@ For detailed installation instructions, please read the [standard installation p
47
 
48
  == Upgrade Notice ==
49
 
 
 
 
 
50
  = 1.0.2 =
51
 
52
  Added filter to override the regular expression.
1
  === Email Address Encoder ===
2
  Contributors: tillkruess
3
+ Donate link: http://tillkruess.com/donations/
4
  Tags: antispam, anti spam, spam, email, e-mail, mail, spider, crawler, harvester, robots, spambot, block, obfuscate, obfuscation, encode, encoder, encoding, encrypt, encryption, protect, protection
5
  Requires at least: 2.0
6
+ Tested up to: 3.5
7
+ Stable tag: 1.0.3
8
+ License: GPLv3
9
+ License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
11
  A lightweight plugin to protect email addresses from email-harvesting robots by encoding them into decimal and hexadecimal entities.
12
 
13
+
14
  == Description ==
15
 
16
  A lightweight plugin to protect plain email addresses and mailto links from email-harvesting robots by encoding them into decimal and hexadecimal entities. Has effect on the posts, pages, comments, excerpts and text widgets. No UI, no shortcode, no JavaScript — just simple spam protection.
17
 
18
 
19
+ == Installation ==
20
 
21
+ For detailed installation instructions, please read the [standard installation procedure for WordPress plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins).
22
 
23
+ 1. Upload the `/email-address-encoder/` directory and its contents to `/wp-content/plugins/`.
24
+ 2. Login to your WordPress installation and activate the plugin through the _Plugins_ menu.
25
+ 3. Done. This plugin has no user interface or configuration options.
26
 
 
27
 
28
+ == Frequently Asked Questions ==
29
 
30
+ = What does this plugin do? =
31
 
32
+ This plugin hooks into the WordPress filters like `the_content`, `widget_text` and others (additional filters can be added). On each filter a quick (disableable) search for an @-sign is performed. If an @-sign is found, a (overridable) regular expression looks for plain text email addresses. Found email addresses are replaced with the return value of `eae_encode_str()` (changeable), which obfuscates the email addresses to protect it from being read by email-harvesting robots. This function is slightly faster than WP's built-in `antispambot()` and uses additional hexadecimal entities.
33
 
34
+ = How can I make sure the plugin works? =
35
+
36
+ You cannot use Firebug, Web Inspector or Dragonfly, because they decode decimal/hexadecimal entities into plain text. To make sure email addresses are encoded, right-click/secondary-click the page, click "View Source", "View Page Source" or "Source" and search for any plain text email addresses.
37
+
38
+ = How can I use WP's antispambot() function instead? =
39
+
40
+ You specify any valid callback function with the `eae_method` filter to apply to found email addresses: `add_filter('eae_method', function() { return 'antispambot'; });`
41
+
42
+ = How can I filter other parts of my site? =
43
+
44
+ * If the content supports WordPress filters, register the `eae_encode_emails()` function to it: `add_filter($tag, 'eae_encode_emails');`.
45
+ * If the content is a PHP string, run it through the `eae_encode_emails()` function: `$text = eae_encode_emails($text);`.
46
+ * If you want to encode a single email address, use the `eae_encode_str()` function: `<?php echo eae_encode_str('user@foobar.com'); ?>`
47
+
48
+ This plugin doesn't encode the entire website for performance reasons, it encodes only the content of the following WordPress filters `the_content`, `the_excerpt`, `widget_text`, `comment_text`, `comment_excerpt`.
49
+
50
+ = How can I change the regular expression pattern? =
51
+
52
+ You can override [the pattern](http://fightingforalostcause.net/misc/2006/compare-email-regex.php "Comparing E-mail Address Validating Regular Expressions") with the `eae_regexp` filter: `add_filter('eae_regexp', function() { return '/^pattern$/'; });`
53
+
54
+ = How can I disable the @-sign check? =
55
+
56
+ Like this: `add_filter('eae_at_sign_check', '__return_false');`
57
 
58
 
59
  == Changelog ==
60
 
61
+ = 1.0.3 =
62
+
63
+ * Added filter to override the function called to encode
64
+ * Improved randomness of encode-function
65
+ * Improved speed by doing fast @-sign existence check
66
+
67
  = 1.0.2 =
68
 
69
  * Added filter to override the regular expression.
79
 
80
  == Upgrade Notice ==
81
 
82
+ = 1.0.3 =
83
+
84
+ Speed and "randomness" improvements.
85
+
86
  = 1.0.2 =
87
 
88
  Added filter to override the regular expression.