This extension is designed to protect email addresses from harvesting by spambots, through obfuscation. It then uses jQuery to clarify the email address, presenting a valid email address to the user (optionally in a mailto: link).
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.0.11 or above
Installation ¶
- Extract the release file under
protected/extensions
- Add the class as a component in your application's main.php config file.
Config code:
'components'=>array(
...
'obfuscator'=>array(
'class' =>'application.extensions.obfuscator.Obfuscator',
),
...
),
Usage ¶
The class has a single public function: disguise(). This function takes 2 parameters:
- $email (string): The email address to be obfuscated
- $link (bool): Whether the email address should be displayed to the user as a mailto link - default is 'true'
Wherever you want an email address inserted, call the disguise function according to the following examples:
With a mailto link:
<?php echo Yii::app()->obfuscator->disguise('email@example.com',true); ?>
Without a link:
<?php echo Yii::app()->obfuscator->disguise('email@example.com',false); ?>
Change Log ¶
February 2, 2010 ¶
- Initial release.
Great!!!
That's a very useful extension
Thanks!!!
Bug?
Hey, the following e-mail (numeric, but valid) is totally corrupted:
21345@wtr.com
shows as 76890@wtr.com when obfuscated.
How come? it shouldn't change!
Actually it's not obfuscated at all
Solution for number not decode bugs
because this extension use php function str_rot13, which is not encode the numeric character, therefore, to quickly fix this bugs, your may edit the javascript rot13 function by replace: (just to remove "0-9") for replacement
$rot13function = ' $.fn.rot13 = function() { this.each(function() { $(this).text($(this).text().replace(/[a-z0-9]/ig, function(chr) { var cc = chr.charCodeAt(0); if (cc >= 65 && cc <= 90) cc = 65 + ((cc - 52) % 26); else if (cc >= 97 && cc <= 122) cc = 97 + ((cc - 84) % 26); else if (cc >= 48 && cc <= 57) cc = 48 + ((cc - 43) % 10); return String.fromCharCode(cc); })); }); return this; }; ';
to
$rot13function = ' $.fn.rot13 = function() { this.each(function() { $(this).text($(this).text().replace(/[a-z]/ig, function(chr) { var cc = chr.charCodeAt(0); if (cc >= 65 && cc <= 90) cc = 65 + ((cc - 52) % 26); else if (cc >= 97 && cc <= 122) cc = 97 + ((cc - 84) % 26); else if (cc >= 48 && cc <= 57) cc = 48 + ((cc - 43) % 10); return String.fromCharCode(cc); })); }); return this; }; ';
another alternative will be creating a new str_rot function in the class, and use it to do encrpyption, sample as below:
private function str_rot($s) { $n = 13;//rot 13 - for alphabet $l = 5;//rot 5 - for - number for ($i = 0, $l = strlen($s); $i < $l; $i++) { $c = ord($s[$i]); if($c >= 97 && $c <= 122)//a-z { $s[$i] = chr(($c - 71 + $n) % 26 + 97); } elseif($c >= 65 && $c <= 90)//A-Z { $s[$i] = chr(($c - 39 + $n) % 26 + 65); } elseif($c >= 48 && $c <= 57)//0-9 { $s[$i] = chr(($c - 10 + $l) % 10 + 48); } } return $s; }
then kindly replace in function "disguise":
to
$user = $this->str_rot($user); $host = $this->str_rot($host);
str_rot fix
bugs fix for the custom str_rot function, which crash the variable $l
let use code below:
private function str_rot($s) { $n = 13;//rot 13 - for alphabet $m = 5;//rot 5 - for - number for ($i = 0, $l = strlen($s); $i < $l; $i++) { $c = ord($s[$i]); if($c >= 97 && $c <= 122)//a-z { $s[$i] = chr(($c - 71 + $n) % 26 + 97); } elseif($c >= 65 && $c <= 90)//A-Z { $s[$i] = chr(($c - 39 + $n) % 26 + 65); } elseif($c >= 48 && $c <= 57)//0-9 { $s[$i] = chr(($c - 38 + $m) % 10 + 48); } } return $s; }
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.