| Current Path : /home/magalijoj/www/blog/plugins/antispam/inc/ |
| Current File : /home/magalijoj/www/blog/plugins/antispam/inc/lib.dc.antispam.php |
<?php
# ***** BEGIN LICENSE BLOCK *****
# This is Antispam, a plugin for DotClear.
# Copyright (c) 2007 Alain Vagner and contributors. All rights
# reserved.
#
# DotClear 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 2 of the License, or
# (at your option) any later version.
#
# DotClear 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 DotClear; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
class dcAntispam
{
public static $filters;
public static function initFilters()
{
global $core;
if (!isset($core->spamfilters)) {
return;
}
self::$filters = new dcSpamFilters($core);
self::$filters->init($core->spamfilters);
}
public static function isSpam(&$cur)
{
self::initFilters();
self::$filters->isSpam($cur);
}
public static function trainFilters(&$blog,&$cur,&$rs)
{
$status = null;
# From ham to spam
if ($rs->comment_status != -2 && $cur->comment_status == -2) {
$status = 'spam';
}
# From spam to ham
if ($rs->comment_status == -2 && $cur->comment_status == 1) {
$status = 'ham';
}
# the status of this comment has changed
if ($status)
{
$filter_name = $rs->exists('comment_spam_filter') ? $rs->comment_spam_filter : null;
self::initFilters();
self::$filters->trainFilters($rs,$status,$filter_name);
}
}
public static function statusMessage(&$rs)
{
if ($rs->exists('comment_status') && $rs->comment_status == -2)
{
$filter_name = $rs->exists('comment_spam_filter') ? $rs->comment_spam_filter : null;
self::initFilters();
return
'<p><strong>'.__('This comment is a spam:').'</strong> '.
self::$filters->statusMessage($rs,$filter_name).'</p>';
}
}
public static function countSpam(&$core)
{
return $core->blog->getComments(array('comment_status'=>-2),true)->f(0);
}
public static function countPublishedComments(&$core)
{
return $core->blog->getComments(array('comment_status'=>1),true)->f(0);
}
public static function delAllSpam(&$core)
{
$strReq =
'SELECT comment_id '.
'FROM '.$core->prefix.'comment C '.
'JOIN '.$core->prefix.'post P ON P.post_id = C.post_id '.
"WHERE blog_id = '".$core->con->escape($core->blog->id)."' ".
'AND comment_status = -2 ';
$rs = $core->con->select($strReq);
$r = array();
while ($rs->fetch()) {
$r[] = (integer) $rs->comment_id;
}
if (empty($r)) {
return;
}
$strReq =
'DELETE FROM '.$core->prefix.'comment '.
'WHERE comment_id '.$core->con->in($r).' ';
$core->con->execute($strReq);
}
public static function getUserCode($core)
{
$code =
pack('a32',$core->auth->userID()).
pack('H*',crypt::hmac(DC_MASTER_KEY,$core->auth->getInfo('user_pwd')));
return bin2hex($code);
}
public static function checkUserCode($core,$code)
{
$code = pack('H*',$code);
$user_id = trim(@pack('a32',substr($code,0,32)));
$pwd = @unpack('H40hex',substr($code,32,40));
if ($user_id === false || $pwd === false) {
return false;
}
$pwd = $pwd['hex'];
$strReq = 'SELECT user_id, user_pwd '.
'FROM '.$core->prefix.'user '.
"WHERE user_id = '".$core->con->escape($user_id)."' ";
$rs = $core->con->select($strReq);
if ($rs->isEmpty()) {
return false;
}
if (crypt::hmac(DC_MASTER_KEY,$rs->user_pwd) != $pwd) {
return false;
}
return $rs->user_id;
}
}
?>