PHPEnkoder
PHPEnkoder is a port of the excellent Hivelogic Enkoder to PHP and, more specifically, to Wordpress. It is used to display text in a way that users can see and bots can’t.
The encoding system is directly and unabashedly stolen from the BSD-licensed source of Hivelogic Enkoder, which works by randomly encoding a piece of text and sending to the browser self-evaluating Javascript that will generate the original text. This works in two ways: first, a bot must first have a fairly complete Javascript implementation; second, the decoding process can be made arbitrarily computationally intensive. This is similar to the idea of charging computational payments to send e-mail, only this is actually implemented.
The code is released under the New BSD license, where I am the copyright holder, but the work is acknowledged as a derivative of the Hivelogic Enkoder. What this really means is that you can do whatever you want with the code so long as you leave the license and copyright information at the top.
New versions will be announced on the main site feed. The latest version is 1.2.
Download
- Version 1.2
- Download as .tgz
- Download as .zip
- Version 1.1
- Download as .tgz
- Download as .zip
- Version 1.0
- Download as .tgz
- Download as .zip
Installation
To install, extract the archive in your wordpress directory (the one containing the directory wp-content). PHPEnkoder can then be configured in the PHPEnkoder subpage of the Options configuration menu; by default, it will mask plaintext e-mails in addition to explicit mailto: links. (Note that attributes of the mailto: links, such as title and class, work fine — the entire anchor element is encoded.) In RSS, it will replace e-mails with customizable text (by default, email hidden; JavaScript is required). There is a bug in excerpt behavior, please see below.
To request support, bug fixes, and features, please send e-mail to .
New in version 1.2
Steve Huston noticed a bug in a elements that had both a mailto: href and an e-mail address in the PCDATA; the problem is fixed in this version. Thanks Steve!
New in version 1.1
Apart from a few bugfixes in RSS handling, version 1.1 supports a configurable message for non-JavaScript capable readers, which (optionally) includes RSS. Message configuration is in the usual configuration menu.
Manual use
If you’d like to use the encoding functions in your own code, they are documented in the source file. For quick reference, here are their formal signatures:
-
function enkode_mailto($email, $text, $subject = "", $title = "")
-
function enkode($content, $max_passes = 20, $max_length = 1024)
$text is the text of the generated link. $title is the “title” attribute of the link; it will be turned into a tooltip. $max_passes is the maximum number of encodings to perform; $max_length is the maximum length (in characters) of the generated Javascript. To give a vague idea, about four passes encode a mailto: link into around 1000 characters. The constant cost of the Javascript is 157 characters.
And some examples of use:
-
// generate a subject-less, title-less mailto link
-
enkode_mailto("secret@email", "send the mail (link text)");
We can also encode arbitrary text:
-
// up to (approximately) 1024 characters (usually about 4 passes)
-
enkode("A little secret. Any text, can <i>include</i> tags.");
-
// up to 10K characters, a lot of passes (lots of client computation)
-
enkode("A serious secret. Shh!", 40, 10000);
Known bugs
Wordpress creates excerpts by simply stripping tags from truncated content. This results in some Javascript-protecting comments appearing in the excerpt text, as I haven’t found a convenient way to determine if content being rendered is meant for an excerpt or the page. For now, a customizable message appears; by default, it will be rendered as /* email hidden; JavaScript is required */. Any ideas for workarounds would be appreciated; please .
In general, there’s a bug in Wordpress 2.0.2 and 2.0.3 (and possibly earlier) where RSS filters are called inappropriately. This can be fixed in one of three ways. The best option is to upgrade to 2.0.4. If you’re stuck in an older version, one option is ot just edit wp-rss2.php, changing the call to the_content (around line 45) to be a call to the_content_rss. Another is to use this patch; it can be applied by running patch </path/to/wp-rss_content-1.0.patch in your Wordpress root. It’s only been tested on 2.0.3.