PHP Classes
elePHPant
Icontem

File: class_mailriddler.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jan Paepke  >  Mail Riddler  >  class_mailriddler.php  >  Download  
File: class_mailriddler.php
Role: Class source
Content type: text/plain
Description: just include this and riddle your mail ;)
Class: Mail Riddler
Encode email addresses in pages to stop harvesting
Author: By
Last change: splitted description from class
Date: 8 years ago
Size: 1,847 bytes
 

Contents

Class file image Download
<?
class mailriddler {
    var
$mailarray = array();
    function
convert() {
       
$returnstring = '';
        foreach (
$this->mailarray as $key => $email) {
           
$tmp = '';
            for (
$i=0; $i<strlen($email);$i++)
               
$tmp .= ", ".ord($email[$i]);
           
$returnstring .= "mailarray[".$key."] = new Array(".substr($tmp, 2).")\n";
        }
        return
$returnstring;
    }
    function
init () {
        echo
'<script language="JavaScript" type="text/javascript">'."\n";
        echo
"var mailarray = new Array();\n";
        echo
$this->convert();
        echo
"function mailoutput(mailtoshow) {\n";
        echo
" var thismail='';\n";
        echo
" for (i=0;i<mailtoshow.length;i++)\n";
        echo
" thismail+=String.fromCharCode(mailtoshow[i]);\n";
        echo
" return thismail;\n";
        echo
"}\n";
        echo
"</script>\n";
    }
    function
add($item) {
        if (
is_array($item)) {
           
$this->mailarray = $this->mailarray + $item;
        } else {
           
$this->mailarray[] = $item;
        }
    }
    function
mailto($item, $title="", $subject = "", $additional = "") {
        if (
$subject != "")
           
$subjectstring = "?subject=".rawurlencode($subject);
        if (isset(
$this->mailarray[$item]) || in_array($item, $this->mailarray)) {
            if (
in_array($item, $this->mailarray))
               
$item = array_search($item, $this->mailarray);
           
$riddled_email = "mailarray[".$item."]";
        } else {
           
$tmp = "";
            for (
$i=0; $i<strlen($item);$i++)
               
$tmp .= ", ".ord($item[$i]);
           
$riddled_email = "Array(".substr($tmp, 2).")";
        }
        if (
$title == "")
           
$title = "'+mailoutput(".$riddled_email.")+'";
        else
           
$title = addslashes($title);
       
$linkstring = "mailto:'+mailoutput(".$riddled_email.")+'";
       
       
$returnstring ='<script language="JavaScript" type="text/javascript">document.write(\'<a href="'.$linkstring.$subjectstring.'" '.addslashes($additional).'>'.$title.'</a>\')</script>';
        return
$returnstring;
    }
}
?>