<?php
/*******************************************************************************
* lutaspam v1.2 is a PHP class to make harder for spambots to get emails
* Copyright (C) 2008 David Sopas Ferreira <coder at davidsopas dot com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
class lutaspam
{
// Define images for @ and .
private $image_at = "at.jpg";
private $image_dot = "dot.jpg";
// Check DNS records to Internet host name of the given email
public function verificadns($email)
{
list($utilizador, $dominio) = split('@', $email);
if (!checkdnsrr($dominio, 'MX'))
{
// Domain valid
return false;
} else
{
// Domain not valid
return true;
}
}
// Function that code and decode the email variable
public function filtra($filtrar, $opcao)
{
$at = $this->image_at;
$dot = $this->image_dot;
if ($opcao == 0)
{
// Condition to check the format of the email address
if (preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix",
$filtrar) && $this->verificadns($filtrar) == true)
{
// Splits the email in two parts (username and domain)
$dominio = substr($filtrar, strrpos($filtrar, "@"), strlen($filtrar) - 1);
$nome = substr($filtrar, 0, strrpos($filtrar, "@"));
// Replaces the . and @ for respective image
$dominio = str_replace(".", "<img src='$dot' border='0'>", $dominio);
$dominio = str_replace("@", "<img src='$at' border='0'>", $dominio);
$nome = str_replace(".", "<img src='$dot' border='0'>", $nome);
$filtrado = $nome . $dominio;
} else
{
$filtrado = "ERROR: email not valid!";
}
} elseif ($opcao == 1)
{
// Replaces the coded email for the original ones
$filtrado = str_replace("<img src='$at' border='0'>", "@", $filtrar);
$filtrado = str_replace("<img src='$dot' border='0'>", ".", $filtrado);
} else
{
$filtrado = "ERROR: option not present!";
}
return $filtrado;
}
}
?>
|