Email Address Encoder - Version 1.0

Version Description

  • Initial release
Download this release

Release Info

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

Version 1.0

Files changed (2) hide show
  1. email-address-encoder.php +115 -0
  2. readme.txt +35 -0
email-address-encoder.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Email Address Encoder
4
+ Plugin URI: http://wordpress.org/extend/plugins/email-address-encoder/
5
+ Description: A lightweight plugin to protect plain email addresses from email-harvesting robots by encoding them into decimal and hexadecimal entities.
6
+ Version: 1.0
7
+ Author: Till Krüss
8
+ Author URI: http://tillkruess.com/
9
+ License: GPLv3
10
+ */
11
+
12
+ /**
13
+ * Copyright 2011 Till Krüss (www.tillkruess.com)
14
+ *
15
+ * This program is free software: you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License as published by
17
+ * the Free Software Foundation, either version 3 of the License, or
18
+ * (at your option) any later version.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU General Public License
26
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
27
+ *
28
+ * @package Email Address Encoder
29
+ * @copyright 2011 Till Krüss
30
+ */
31
+
32
+ /**
33
+ * Register filters to encode exposed email addresses in
34
+ * posts, pages, comments & widgets.
35
+ */
36
+ foreach (array('the_content', 'widget_text', 'comment_text') as $filter) {
37
+ add_filter($filter, 'eae_encode_emails', 1000);
38
+ }
39
+
40
+ /**
41
+ * WordPress filter callback function. Searches for plain
42
+ * email addresses in given $string and encodes them with
43
+ * the help of eae_encode_str().
44
+ *
45
+ * Regular expression is based on based on John Gruber's Markdown.
46
+ * http://daringfireball.net/projects/markdown/
47
+ *
48
+ * @uses eae_encode_str()
49
+ *
50
+ * @param string $string Text with email addresses to encode
51
+ * @return string $string Given text with encoded email addresses
52
+ */
53
+ function eae_encode_emails($string) {
54
+ return preg_replace_callback('
55
+ {
56
+ (?:mailto:)?
57
+ (?:
58
+ [-!#$%&*+/=?^_`.{|}~\w\x80-\xFF]+
59
+ |
60
+ ".*?"
61
+ )
62
+ \@
63
+ (?:
64
+ [-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+
65
+ |
66
+ \[[\d.a-fA-F:]+\]
67
+ )
68
+ }xi',
69
+ create_function(
70
+ '$matches',
71
+ 'return eae_encode_str($matches[0]);'
72
+ ),
73
+ $string
74
+ );
75
+ }
76
+
77
+ /**
78
+ * Encodes each character of the given string as either a decimal
79
+ * or hexadecimal entity, in the hopes of foiling most email address
80
+ * harvesting bots.
81
+ *
82
+ * Based on Michel Fortin's PHP Markdown:
83
+ * http://michelf.com/projects/php-markdown/
84
+ * Which is based on John Gruber's original Markdown:
85
+ * http://daringfireball.net/projects/markdown/
86
+ * Whose code is based on a filter by Matthew Wickline, posted to
87
+ * the BBEdit-Talk with some optimizations by Milian Wolff.
88
+ *
89
+ * @param string $string Text with email addresses to encode
90
+ * @return string $string Given text with encoded email addresses
91
+ */
92
+ function eae_encode_str($string) {
93
+
94
+ $chars = str_split($string);
95
+ $seed = (int) abs(crc32($string) / strlen($string));
96
+
97
+ foreach ($chars as $key => $char) {
98
+
99
+ $ord = ord($char);
100
+
101
+ if ($ord < 128) { // ignore non-ascii chars
102
+
103
+ $r = ($seed * (1 + $key)) % 100; // pseudo "random function"
104
+
105
+ if ($r > 80 && $char != '@') ; // plain character (not encoded)
106
+ else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; // hexadecimal
107
+ else $chars[$key] = '&#'.$ord.';'; // decimal (ascii)
108
+
109
+ }
110
+
111
+ }
112
+
113
+ return implode('', $chars);
114
+
115
+ }
readme.txt ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
7
+
8
+ A lightweight plugin to protect plain 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 from email-harvesting robots by encoding them into decimal and hexadecimal entities. Has effect on the content of posts, pages, comments 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
+
22
+ == Installation ==
23
+
24
+ For detailed installation instructions, please read the [standard installation procedure for WordPress plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins).
25
+
26
+ 1. Upload the `/email-address-encoder/` directory and its contents to `/wp-content/plugins/`.
27
+ 2. Login to your WordPress installation and activate the plugin through the _Plugins_ menu.
28
+ 3. Done. This plugin has no user interface or configuration options.
29
+
30
+
31
+ == Changelog ==
32
+
33
+ = 1.0 =
34
+
35
+ * Initial release