Fogliarini Brolesi

Educação e programação

Email Encrypt Class

Posted on | outubro 29, 2008 | No Comments

 
<?php
 
/**
* Class Email Encrypt
* From http://www.freesandbox.net/
* Under a GPL License v 2.0
* see http://www.gnu.org/licenses/gpl-2.0.html for further informations
*
*/
Class EmailEncrypt {
public $email;
public $return;
public $temp;
public $enc_type;
 
/**
* Construct function
* Do nothing
*/
function __construct() {
 
}
 
/**
* Private function email
* encode a email in a specific format
* @param $email        = email to encode
* @param $codification = type of codification
* @param $link         = the mail has a link?
*/
 
private function email($email, $codification = "none", $link = 1) {
switch ($codification) {
 
/**
* Case Javascript
*/
case "javascript" :
if ($link == 1)
$string = "document.write('<a href=\"mailto:{$email}\">{$email}</a>')";
else
$string = "document.write('{$email}')";
for ($x = 0; $x < strlen($string); $x++) {
$js_encode .= '%' . bin2hex($string[$x]);
}
return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>';
break;
 
/**
* Case Javascript Charcode
*/
case "javascript_charcode" :
if ($link == 1)
$string = "<a href=\"mailto:{$email}\">{$email}</a>";
else
$string = "{$email}";
for ($x = 0, $y = strlen($string); $x < $y; $x++) {
$ord[] = ord($string[$x]);
}
 
$_ret = "<script type=\"text/javascript\" language=\"javascript\">\n";
$_ret .= "<!--\n";
$_ret .= "{document.write(String.fromCharCode(";
$_ret .= implode(',', $ord);
$_ret .= "))";
$_ret .= "}\n";
$_ret .= "//-->\n";
$_ret .= "</script>\n";
 
return $_ret;
break;
 
/**
* Case Hex
*/
case "hex" :
$mailto = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;";
$mail_encoded = "";
for ($x = 0; $x < strlen($email); $x++) {
$mail_encoded .= preg_match('/^[A-Za-z0-9]$/', $email[$x]) ? '&#x' . bin2hex($email[$x]) . ';' : $email[$x];
}
if ($link)
return "<a href=\"{$mailto}{$mail_encoded}\">{$mail_encoded}</a>";
else
return "{$mail_encoded}";
break;
 
/**
* Case Paranoid
*/
case "paranoid" :
$temp = "";
$mail = explode("@", $email);
for ($i = 0; $i < strlen($mail[0]); $i++) {
$temp .= (rand(0, 1) ? "<!-- " . uniqid(md5(time()), true) . " -->" : "<span style=\"visibility: hidden; display: none;\">\n" . uniqid(md5(time()), true) . "\m</span>") . substr($mail[0], $i, 1);
}
$temp .= "<script type=\"text/javascript\">\n<!--\n\tdocument.write(unescape(\"%40\"))\n//-->\n</script>";
for ($i = 0; $i < strlen($mail[1]); $i++) {
$temp .= (rand(0, 1) ? "<!-- " . uniqid(md5(time()), true) . " -->" : "<span style=\"visibility: hidden; display: none;\">\n" . uniqid(md5(time()), true) . "</span>") . substr($mail[1], $i, 1);
}
 
return $temp;
break;
 
/**
* Case Paranoid + CSS
*/
case "paranoid_css" :
$mail = explode("@", $email);
$temp = "";
$temp .= "<style type=\"text/css\">\n.J";
$rand = md5(time());
$temp .= $rand;
$temp .= ":";
$temp .= (rand(0, 1)) ? "before" : "after";
$temp .= " {\n\tcontent: \"@\";\n}\n</style>";
$mail = explode("@", $email);
$temp .= "{$mail[0]}<span class=\"J{$rand}\"></span>{$mail[1]}";
return $temp;
break;
/**
* Case none / default
*/
case "none" :
default :
if ($link == 1)
return "<a href=\"mailto:{$email}\">{$email}</a>";
else
return "{$email}";
 
break;
}
$title_encoded = null;
for ($ii = 0; $ii < strlen($email); $ii++) {
$title_encoded .= preg_match('/^[A-Za-z0-9]$/', $email[$ii]) ? '&#x' . bin2hex($email[$ii]) . ';' : $email[$ii];
}
$js_encode = '';
//$js_encode;
echo '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>';
}
 
/**
* Public Static function js
* Puts a email in a javascript encode
* @param $email = email to encrypt
* @param $link  = bool to put (or not) a mailto reference
*/
public static function js($email, $link = 0) {
return self :: email($email, "javascript", $link);
}
 
/**
* Public Static function jsc
* Puts a email in a javascript charcode encode
* @param $email = email to encrypt
* @param $link  = bool to put (or not) a mailto reference
*/
public static function jsc($email, $link = 0) {
return self :: email($email, "javascript_charcode", $link);
}
 
/**
* Public Static function hex
* Puts a email in a hexadecimal encode
* @param $email = email to encrypt
* @param $link  = bool to put (or not) a mailto reference
*/
public static function hex($email, $link = 0) {
return self :: email($email, "hex", $link);
}
 
/**
* Public Static function paranoid
* Puts a email in a paranoid encode
* @param $email = email to encrypt
*/
public static function paranoid($email) {
return self :: email($email, "paranoid");
}
 
/**
* Public Static function paranoid
* Puts a email in a paranoid encode with CSS
* @param $email = email to encrypt
*/
public static function paranoidc($email) {
return self :: email($email, "paranoid_css");
}
}
echo EmailEncrypt :: paranoidc("meu@email.com");
?>

Comments

Leave a Reply





    About

    This is an area on your website where you can add text. This will serve as an informative location on your website, where you can talk about your site.

    Subscribe to our feed

    Search

    Admin

Blog performance enhanced by PHP Speedy Blog performance enhanced by PHP Speedy