NAME

Konstrukt::Plugin::mail::obfuscator - Hide email addresses from SPAM harvesters.

SYNOPSIS

Tag interface

Usage:

<& mail::obfuscator name="John Doe" mail="john@doe.com" / &>

Result:

<!-- used to decrypt the email address -->
<script type="text/javascript">
<!--
function xor_enc(text, key) {
	var result = '';
	for(i = 0; i < text.length; i++)
		result += String.fromCharCode(key.charCodeAt(i % key.length) ^ text.charCodeAt(i));
	return result;
}
// -->
</script>

<script type="text/javascript">
<!--
document.write(xor_enc(unescape('encrypted link'), 'key to decrypt'));
-->
</script>
<noscript>
John Doe: john<img src="/gfx/layout/s.gif" alt="&gt; add @-character here &lt;" />doe.com
</noscript>

You can also optionally specifiy the complete HTML-link and "text link" if you don't like the simple one that the plugin generates:

<& mail::obfuscator
	html="<a href='mailto:john@doe.com' class='some_css_class'>John Doe</a>"
	text="Blabla John Doe: john@doe.com" 
/ &>

This will basically do the same as when you specify the name and description: Encrypt the HTML, obfuscate the text.

Note that you have to use singlequotes instead of doublequotes in the data as doublequotes will collide with those of the mail::obfuscator tag. The singlequotes will be replaced by doublequotes in the result.

Perl interface

my $obfusc = use_plugin 'mail::obfuscator';
print $obfunc->link(mail => 'john@doe.com', name => 'John Doe');

There also are more "low level" methods, which can be used to create a custom composition of the link.

DESCRIPTION

This plugin will put an encrypted/obfuscated email address on the website.

It puts two versions into the website: One for use with JavaScript and one for the case that JS has been disabled.

For JS-capable clients a link will be generated and encrypted on the server. This link will be decrypted and placed on the page using JavaScript.

If the client doesn't support JavaScript, the email address will only be obfuscated and put on the page. The "@" will be replaced by an image (whose alt-attribute can be configured). The letters will be encoded as HTML entities and some useless tags/comments will be inserted.

You may omit the name attribute. The email address will then be used as the text of the link.

CONFIGURATION

You may configure the text, that will replace the @ sign. Defaults:

mail/obfuscator/at_replacement <img src="/at_image.gif" alt="&gt; add @-character here &lt;" />

You may put only an "@" in the alt-attribute, what will allow the user to just copy and paste the address. But this might make it easier for harvesters to find the email address. You may also just replace the @ with the HTML-entity-code &064; which will make is easier for both the user and the harvester.

METHODS

init

Inititalization of this class

prepare

The output static for static input. All work can be done in the prepare step if there is no dynamic content inside the content of this tag.

Parameters:

  • $tag - Reference to the tag (and its children) that shall be handled.

Returns the encrypted/obfuscated link both for JavaScript-capable clients and those which are not.

As every parameter is optional, the parameters to this method must be passed as an hash ("named parameters"):

$obfusc->link(name => 'John Doe', mail => '...', ...)

Parameters:

  • mail - The email address of the addressee.

  • name - The name of the addressee.

  • html - A predefined HTML link - the link will not be generated from mail (and name).

  • text - A predefined text "link" - the "link" will not be generated from mail (and name).

js_function

Returns the JavaScript code that contains the function to decrypt the HTML link.

Usually only used internally.

Parameters: none

Generates the HTML link for the specified name and email address.

Usually only used internally.

Parameters:

  • $mail - The email address of the addressee

  • $name - The name of the addressee. Defaults to $mail, if not specified

Generates the obfuscated text link for the specified name and email address.

Usually only used internally.

Parameters:

  • $mail - The email address of the addressee

  • $name - The name of the addressee. Optional.

encrypt

Encrypts the specified text and returns a piece of HTML/JavaScript which will decrypt it at the client.

Parameters:

  • $text - The text to be encrypted (usually an HTML link to an email address)

obfuscate

Obfuscated the specified text: Encodes each character as HTML entities, inserts comments and invisible tags and replaces any @-character by an image.

Parameters:

  • $text - The text to be obfuscated (e.g. a text "link" to the mail address)

AUTHOR

Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.

This document is free software. It is distributed under the same terms as Perl itself.

SEE ALSO

Konstrukt::Plugin, Konstrukt