E-mail Address Obfuscator (txp:dtj_obfuscated_email /) main page
A simple plugin that encodes ("obfuscates") an e-mail address link for you, helping to reduce the likelihood of your e-mail address getting harvested.
It's quite simple to use. The tag takes an email
attribute (the address to be encoded) and an encoding mode
(case
insensitive).
The dtj_obfuscated_email
tag is a Single_Tag. Textpattern will replace this tag with an encoded mailto: link, according to the
attributes set.
This attribute is not case-sensitive.
This attribute is not case-sensitive.
<txp:dtj_obfuscated_email email="encoded address" />
<txp:dtj_obfuscated_email email="noone@example.tld" mode="iso" />
<txp:dtj_obfuscated_email email="noone@example.tld" mode="hex" output="plain" />
// dotjay obfuscated e-mail address plugin
function dtj_obfuscated_email($atts) {
extract(lAtts(array(
'email' => '',
'mode' => 'mixed',
'output' => 'link'
),$atts));
$mode = strtolower($mode);
$output = strtolower($output);
// Normal mode
if ($mode == 'basic') {
list($username, $domain) = split("@", $email);
if ($output == 'link') return '<a href="'.str_replace(".",'%2e','mailto:'.$username.'%40'.$domain).'">'.str_replace(".",'.',$username.'@'.$domain).'</a>';
else if ($output == 'plain') return str_replace(".",'.',$username.'@'.$domain);
else return false;
}
// Hex/ISO/Mixed modes
else {
$encoded = '';
$reencoded = '';
for ($i=0;$i<strlen($email);++$i) {
if ($mode == 'hex') $encoded .= '&#x'.sprintf("%X",ord($email{$i})).';';
else if ($mode == 'iso') $encoded .= '&#'.ord($email{$i}).';';
else if ($mode == 'mixed') $encoded .= rand(0,1) ? '&#x'.sprintf("%X",ord($email{$i})).';' : '&#'.ord($email{$i}).';';
}
if ($output == 'link') {
$email = 'mailto:'.$email;
for ($i=0;$i<strlen($email);++$i) {
if ($mode == 'hex') $reencoded .= '&#x'.sprintf("%X",ord($email{$i})).';';
else if ($mode == 'iso') $reencoded .= '&#'.ord($email{$i}).';';
else if ($mode == 'mixed') $reencoded .= rand(0,1) ? '&#x'.sprintf("%X",ord($email{$i})).';' : '&#'.ord($email{$i}).';';
}
}
// if all went well, we should have an encoded e-mail address
if (!empty($encoded)) {
if ($output == 'link') return '<a href="'.$reencoded.'">'.$encoded.'</a>';
else if ($output == 'plain') return $encoded;
else return false;
}
// unknown mode was set
else return false;
}
}
Textpattern plugins are base64 encoded. To install, copy and paste the plugin code into the textarea on the plugin tab in Textpattern admin.
Remember to activate the plugin before you use it... I always forget.