Topic: Encode Email-Addresses to prevent SPAM

Hi together,

I just extended the file '[ROOT]/admin/kernel/db/db_pages.class.php'

In the function "get_items" I call my function to find all mail-addresses in the text and then encode them.

Line 502 $tmp_array['content'] = $this->htmlizeEmails($xml->getChild('content'));

For posts you have to edit '[ROOT]/admin/kernel/db/db_posts.class.php':

Line 614 $content = (string) $this->htmlizeEmails($xml->getChild('content'));

Here are my functions (paste them in the classes):

    //Finds email addresses in content
    //Replace every email address with HTML-ASCII Code
    private function htmlizeEmails($text)
    {
        preg_match_all('/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})/', $text, $potentialEmails, PREG_SET_ORDER);

        $potentialEmailsCount = count($potentialEmails);
        for ($i = 0; $i < $potentialEmailsCount; $i++) {
            if (filter_var($potentialEmails[$i][0], FILTER_VALIDATE_EMAIL)) {
                $ascii_mail_address = $this->encode_email_address($potentialEmails[$i][0]);
                $text = str_replace($potentialEmails[$i][0], $ascii_mail_address, $text);
            }
            }
        return $text;
    }

    //Encode a given string in HTML-ASCII
    private function encode_email_address($email)
    {
        $result = '';
        for ($i = 0; $i < strlen($email); $i++)
        {
            $result .= '&#'.ord($email[$i]).';';
        }
        return $result;
    }

Works smart, I hope you like it!

Greetings,

CrazyBread