Index: plugins/antispam/inc/class.dc.spamfilter.php
===================================================================
--- plugins/antispam/inc/class.dc.spamfilter.php	(revision 3396)
+++ plugins/antispam/inc/class.dc.spamfilter.php	(revision 3730)
@@ -10,158 +10,158 @@
 #
 # -- END LICENSE BLOCK -----------------------------------------
-if (!defined('DC_RC_PATH')) { return; }
+if (!defined('DC_RC_PATH')) {return;}
 
 class dcSpamFilter
 {
-	public $name;
-	public $description;
-	public $active = true;
-	public $order = 100;
-	public $auto_delete = false;
-	public $help = null;
+    public $name;
+    public $description;
+    public $active      = true;
+    public $order       = 100;
+    public $auto_delete = false;
+    public $help        = null;
 
-	protected $has_gui = false;
-	protected $gui_url = null;
+    protected $has_gui = false;
+    protected $gui_url = null;
 
-	protected $core;
+    protected $core;
 
-	/**
-	Object constructor
+    /**
+    Object constructor
 
-	@param	core		<b>dcCore</b>		Dotclear core object
-	*/
-	public function __construct($core)
-	{
-		$this->core =& $core;
-		$this->setInfo();
+    @param    core        <b>dcCore</b>        Dotclear core object
+     */
+    public function __construct($core)
+    {
+        $this->core = &$core;
+        $this->setInfo();
 
-		if (!$this->name) {
-			$this->name = get_class($this);
-		}
+        if (!$this->name) {
+            $this->name = get_class($this);
+        }
 
-		if ($core && isset($core->adminurl)) {
-	        $this->gui_url = $core->adminurl->get('admin.plugin.antispam',array('f' => get_class($this)),'&');
-		}
-	}
+        if ($core && isset($core->adminurl)) {
+            $this->gui_url = $core->adminurl->get('admin.plugin.antispam', array('f' => get_class($this)), '&');
+        }
+    }
 
-	/**
-	This method is called by the constructor and allows you to change some
-	object properties without overloading object constructor.
-	*/
-	protected function setInfo()
-	{
-		$this->description = __('No description');
-	}
+    /**
+    This method is called by the constructor and allows you to change some
+    object properties without overloading object constructor.
+     */
+    protected function setInfo()
+    {
+        $this->description = __('No description');
+    }
 
-	/**
-	This method should return if a comment is a spam or not. If it returns true
-	or false, execution of next filters will be stoped. If should return nothing
-	to let next filters apply.
+    /**
+    This method should return if a comment is a spam or not. If it returns true
+    or false, execution of next filters will be stoped. If should return nothing
+    to let next filters apply.
 
-	Your filter should also fill $status variable with its own information if
-	comment is a spam.
+    Your filter should also fill $status variable with its own information if
+    comment is a spam.
 
-	@param		type		<b>string</b>		Comment type (comment or trackback)
-	@param		author	<b>string</b>		Comment author
-	@param		email	<b>string</b>		Comment author email
-	@param		site		<b>string</b>		Comment author website
-	@param		ip		<b>string</b>		Comment author IP address
-	@param		content	<b>string</b>		Comment content
-	@param		post_id	<b>integer</b>		Comment post_id
-	@param[out]	status	<b>integer</b>		Comment status
-	@return	<b>boolean</b>
-	*/
-	public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status)
-	{
-	}
+    @param        type        <b>string</b>        Comment type (comment or trackback)
+    @param        author    <b>string</b>        Comment author
+    @param        email    <b>string</b>        Comment author email
+    @param        site        <b>string</b>        Comment author website
+    @param        ip        <b>string</b>        Comment author IP address
+    @param        content    <b>string</b>        Comment content
+    @param        post_id    <b>integer</b>        Comment post_id
+    @param[out]    status    <b>integer</b>        Comment status
+    @return    <b>boolean</b>
+     */
+    public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status)
+    {
+    }
 
-	/**
-	This method is called when a non-spam (ham) comment becomes spam or when a
-	spam becomes a ham.
+    /**
+    This method is called when a non-spam (ham) comment becomes spam or when a
+    spam becomes a ham.
 
-	@param	type		<b>string</b>		Comment type (comment or trackback)
-	@param	filter	<b>string</b>		Filter name
-	@param	author	<b>string</b>		Comment author
-	@param	email	<b>string</b>		Comment author email
-	@param	site		<b>string</b>		Comment author website
-	@param	ip		<b>string</b>		Comment author IP address
-	@param	content	<b>string</b>		Comment content
-	@param	post_url	<b>string</b>		Post URL
-	@param	rs		<b>record</b>		Comment record
-	@return	<b>boolean</b>
-	*/
-	public function trainFilter($status,$filter,$type,$author,$email,$site,$ip,$content,$rs)
-	{
-	}
+    @param    type        <b>string</b>        Comment type (comment or trackback)
+    @param    filter    <b>string</b>        Filter name
+    @param    author    <b>string</b>        Comment author
+    @param    email    <b>string</b>        Comment author email
+    @param    site        <b>string</b>        Comment author website
+    @param    ip        <b>string</b>        Comment author IP address
+    @param    content    <b>string</b>        Comment content
+    @param    post_url    <b>string</b>        Post URL
+    @param    rs        <b>record</b>        Comment record
+    @return    <b>boolean</b>
+     */
+    public function trainFilter($status, $filter, $type, $author, $email, $site, $ip, $content, $rs)
+    {
+    }
 
-	/**
-	This method returns filter status message. You can overload this method to
-	return a custom message. Message is shown in comment details and in
-	comments list.
+    /**
+    This method returns filter status message. You can overload this method to
+    return a custom message. Message is shown in comment details and in
+    comments list.
 
-	@param	status		<b>string</b>		Filter status.
-	@param	comment_id	<b>record</b>		Comment record
-	@return	<b>string</b>
-	*/
-	public function getStatusMessage($status,$comment_id)
-	{
-		return sprintf(__('Filtered by %1$s (%2$s)'),$this->guiLink(),$status);
-	}
+    @param    status        <b>string</b>        Filter status.
+    @param    comment_id    <b>record</b>        Comment record
+    @return    <b>string</b>
+     */
+    public function getStatusMessage($status, $comment_id)
+    {
+        return sprintf(__('Filtered by %1$s (%2$s)'), $this->guiLink(), $status);
+    }
 
-	/**
-	This method is called when you enter filter configuration. Your class should
-	have $has_gui property set to "true" to enable GUI.
+    /**
+    This method is called when you enter filter configuration. Your class should
+    have $has_gui property set to "true" to enable GUI.
 
-	In this method you should put everything related to filter configuration.
-	$url variable is the URL of GUI <i>unescaped</i>.
+    In this method you should put everything related to filter configuration.
+    $url variable is the URL of GUI <i>unescaped</i>.
 
-	@param	url		<b>string</b>		GUI URL.
-	*/
-	public function gui($url)
-	{
-	}
+    @param    url        <b>string</b>        GUI URL.
+     */
+    public function gui($url)
+    {
+    }
 
-	public function hasGUI()
-	{
-		if (!$this->core->auth->check('admin',$this->core->blog->id)) {
-			return false;
-		}
+    public function hasGUI()
+    {
+        if (!$this->core->auth->check('admin', $this->core->blog->id)) {
+            return false;
+        }
 
-		if (!$this->has_gui) {
-			return false;
-		}
+        if (!$this->has_gui) {
+            return false;
+        }
 
-		return true;
-	}
+        return true;
+    }
 
-	public function guiURL()
-	{
-		if (!$this->hasGui()) {
-			return false;
-		}
+    public function guiURL()
+    {
+        if (!$this->hasGui()) {
+            return false;
+        }
 
-		return $this->gui_url;
-	}
+        return $this->gui_url;
+    }
 
-	/**
-	Returns a link to filter GUI if exists or only filter name if has_gui
-	property is false.
+    /**
+    Returns a link to filter GUI if exists or only filter name if has_gui
+    property is false.
 
-	@return	<b>string</b>
-	*/
-	public function guiLink()
-	{
-		if (($url = $this->guiURL()) !== false) {
-			$url = html::escapeHTML($url);
-			$link = '<a href="%2$s">%1$s</a>';
-		} else {
-			$link = '%1$s';
-		}
+    @return    <b>string</b>
+     */
+    public function guiLink()
+    {
+        if (($url = $this->guiURL()) !== false) {
+            $url  = html::escapeHTML($url);
+            $link = '<a href="%2$s">%1$s</a>';
+        } else {
+            $link = '%1$s';
+        }
 
-		return sprintf($link,$this->name,$url);
-	}
+        return sprintf($link, $this->name, $url);
+    }
 
-	public function help()
-	{
-	}
+    public function help()
+    {
+    }
 }
Index: plugins/antispam/inc/class.dc.spamfilters.php
===================================================================
--- plugins/antispam/inc/class.dc.spamfilters.php	(revision 3159)
+++ plugins/antispam/inc/class.dc.spamfilters.php	(revision 3730)
@@ -10,154 +10,147 @@
 #
 # -- END LICENSE BLOCK -----------------------------------------
-if (!defined('DC_RC_PATH')) { return; }
+if (!defined('DC_RC_PATH')) {return;}
 
 class dcSpamFilters
 {
-	private $filters = array();
-	private $filters_opt = array();
-	private $core;
+    private $filters     = array();
+    private $filters_opt = array();
+    private $core;
 
-	public function __construct($core)
-	{
-		$this->core =& $core;
-	}
+    public function __construct($core)
+    {
+        $this->core = &$core;
+    }
 
-	public function init($filters)
-	{
-		foreach ($filters as $f)
-		{
-			if (!class_exists($f)) {
-				continue;
-			}
+    public function init($filters)
+    {
+        foreach ($filters as $f) {
+            if (!class_exists($f)) {
+                continue;
+            }
 
-			$r = new ReflectionClass($f);
-			$p = $r->getParentClass();
+            $r = new ReflectionClass($f);
+            $p = $r->getParentClass();
 
-			if (!$p || $p->name != 'dcSpamFilter') {
-				continue;
-			}
+            if (!$p || $p->name != 'dcSpamFilter') {
+                continue;
+            }
 
-			$this->filters[$f] = new $f($this->core);
-		}
+            $this->filters[$f] = new $f($this->core);
+        }
 
-		$this->setFilterOpts();
-		if (!empty($this->filters_opt)) {
-			uasort($this->filters,array($this,'orderCallBack'));
-		}
-	}
+        $this->setFilterOpts();
+        if (!empty($this->filters_opt)) {
+            uasort($this->filters, array($this, 'orderCallBack'));
+        }
+    }
 
-	public function getFilters()
-	{
-		return $this->filters;
-	}
+    public function getFilters()
+    {
+        return $this->filters;
+    }
 
-	public function isSpam($cur)
-	{
-		foreach ($this->filters as $fid => $f)
-		{
-			if (!$f->active) {
-				continue;
-			}
+    public function isSpam($cur)
+    {
+        foreach ($this->filters as $fid => $f) {
+            if (!$f->active) {
+                continue;
+            }
 
-			$type = $cur->comment_trackback ? 'trackback' : 'comment';
-			$author = $cur->comment_author;
-			$email = $cur->comment_email;
-			$site = $cur->comment_site;
-			$ip = $cur->comment_ip;
-			$content = $cur->comment_content;
-			$post_id = $cur->post_id;
+            $type    = $cur->comment_trackback ? 'trackback' : 'comment';
+            $author  = $cur->comment_author;
+            $email   = $cur->comment_email;
+            $site    = $cur->comment_site;
+            $ip      = $cur->comment_ip;
+            $content = $cur->comment_content;
+            $post_id = $cur->post_id;
 
-			$is_spam = $f->isSpam($type,$author,$email,$site,$ip,$content,$post_id,$status);
+            $is_spam = $f->isSpam($type, $author, $email, $site, $ip, $content, $post_id, $status);
 
-			if ($is_spam === true) {
-				if ($f->auto_delete) {
-					$cur->clean();
-				} else {
-					$cur->comment_status = -2;
-					$cur->comment_spam_status = $status;
-					$cur->comment_spam_filter = $fid;
-				}
-				return true;
-			} elseif ($is_spam === false) {
-				return false;
-			}
-		}
+            if ($is_spam === true) {
+                if ($f->auto_delete) {
+                    $cur->clean();
+                } else {
+                    $cur->comment_status      = -2;
+                    $cur->comment_spam_status = $status;
+                    $cur->comment_spam_filter = $fid;
+                }
+                return true;
+            } elseif ($is_spam === false) {
+                return false;
+            }
+        }
 
-		return false;
-	}
+        return false;
+    }
 
-	public function trainFilters($rs,$status,$filter_name)
-	{
-		foreach ($this->filters as $fid => $f)
-		{
-			if (!$f->active) {
-				continue;
-			}
+    public function trainFilters($rs, $status, $filter_name)
+    {
+        foreach ($this->filters as $fid => $f) {
+            if (!$f->active) {
+                continue;
+            }
 
-			$type = $rs->comment_trackback ? 'trackback' : 'comment';
-			$author = $rs->comment_author;
-			$email = $rs->comment_email;
-			$site = $rs->comment_site;
-			$ip = $rs->comment_ip;
-			$content = $rs->comment_content;
+            $type    = $rs->comment_trackback ? 'trackback' : 'comment';
+            $author  = $rs->comment_author;
+            $email   = $rs->comment_email;
+            $site    = $rs->comment_site;
+            $ip      = $rs->comment_ip;
+            $content = $rs->comment_content;
 
-			$f->trainFilter($status,$filter_name,$type,$author,$email,$site,$ip,$content,$rs);
-		}
-	}
+            $f->trainFilter($status, $filter_name, $type, $author, $email, $site, $ip, $content, $rs);
+        }
+    }
 
-	public function statusMessage($rs,$filter_name)
-	{
-		$f = isset($this->filters[$filter_name]) ? $this->filters[$filter_name] : null;
+    public function statusMessage($rs, $filter_name)
+    {
+        $f = isset($this->filters[$filter_name]) ? $this->filters[$filter_name] : null;
 
-		if ($f === null)
-		{
-			return __('Unknown filter.');
-		}
-		else
-		{
-			$status = $rs->exists('comment_spam_status') ? $rs->comment_spam_status : null;
+        if ($f === null) {
+            return __('Unknown filter.');
+        } else {
+            $status = $rs->exists('comment_spam_status') ? $rs->comment_spam_status : null;
 
-			return $f->getStatusMessage($status,$rs->comment_id);
-		}
-	}
+            return $f->getStatusMessage($status, $rs->comment_id);
+        }
+    }
 
-	public function saveFilterOpts($opts,$global=false)
-	{
-		$this->core->blog->settings->addNamespace('antispam');
-		if ($global) {
-			$this->core->blog->settings->antispam->drop('antispam_filters');
-		}
-		$this->core->blog->settings->antispam->put('antispam_filters',$opts,'array','Antispam Filters',true,$global);
-	}
+    public function saveFilterOpts($opts, $global = false)
+    {
+        $this->core->blog->settings->addNamespace('antispam');
+        if ($global) {
+            $this->core->blog->settings->antispam->drop('antispam_filters');
+        }
+        $this->core->blog->settings->antispam->put('antispam_filters', $opts, 'array', 'Antispam Filters', true, $global);
+    }
 
-	private function setFilterOpts()
-	{
-		if ($this->core->blog->settings->antispam->antispam_filters !== null) {
-			$this->filters_opt = $this->core->blog->settings->antispam->antispam_filters;
-		}
+    private function setFilterOpts()
+    {
+        if ($this->core->blog->settings->antispam->antispam_filters !== null) {
+            $this->filters_opt = $this->core->blog->settings->antispam->antispam_filters;
+        }
 
-		# Create default options if needed
-		if (!is_array($this->filters_opt)) {
-			$this->saveFilterOpts(array(),true);
-			$this->filters_opt = array();
-		}
+        # Create default options if needed
+        if (!is_array($this->filters_opt)) {
+            $this->saveFilterOpts(array(), true);
+            $this->filters_opt = array();
+        }
 
-		foreach ($this->filters_opt as $k => $o)
-		{
-			if (isset($this->filters[$k]) && is_array($o)) {
-				$this->filters[$k]->active = isset($o[0])?$o[0]:false;
-				$this->filters[$k]->order = isset($o[1])?$o[1]:0;
-				$this->filters[$k]->auto_delete = isset($o[2])?$o[2]:false;
-			}
-		}
-	}
+        foreach ($this->filters_opt as $k => $o) {
+            if (isset($this->filters[$k]) && is_array($o)) {
+                $this->filters[$k]->active      = isset($o[0]) ? $o[0] : false;
+                $this->filters[$k]->order       = isset($o[1]) ? $o[1] : 0;
+                $this->filters[$k]->auto_delete = isset($o[2]) ? $o[2] : false;
+            }
+        }
+    }
 
-	private function orderCallBack($a,$b)
-	{
-		if ($a->order == $b->order) {
-			return 0;
-		}
+    private function orderCallBack($a, $b)
+    {
+        if ($a->order == $b->order) {
+            return 0;
+        }
 
-		return $a->order > $b->order ? 1 : -1;
-	}
+        return $a->order > $b->order ? 1 : -1;
+    }
 }
Index: plugins/antispam/inc/lib.dc.antispam.php
===================================================================
--- plugins/antispam/inc/lib.dc.antispam.php	(revision 3627)
+++ plugins/antispam/inc/lib.dc.antispam.php	(revision 3730)
@@ -10,203 +10,201 @@
 #
 # -- END LICENSE BLOCK -----------------------------------------
-if (!defined('DC_RC_PATH')) { return; }
+if (!defined('DC_RC_PATH')) {return;}
 
 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 dashboardIcon($core, $icons)
-	{
-		if (($count = self::countSpam($core)) > 0) {
-			$str = ($count > 1) ? __('(including %d spam comments)') : __('(including %d spam comment)');
-			$icons['comments'][0] .= '</span></a> <br /><a href="'.$core->adminurl->get('admin.comments',array('status' => '-2')).'"><span>'.
-				sprintf($str,$count);
-		}
-	}
-
-	public static function dashboardIconTitle($core)
-	{
-		if (($count = self::countSpam($core)) > 0) {
-			$str = ($count > 1) ? __('(including %d spam comments)') : __('(including %d spam comment)');
-			return '</span></a> <br /><a href="'.$core->adminurl->get('admin.comments',array('status' => '-2')).'"><span>'.
-				sprintf($str,$count);
-		} else {
-			return '';
-		}
-	}
-
-	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, $beforeDate = null)
-	{
-		$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 ';
-		if ($beforeDate) {
-			$strReq .= 'AND comment_dt < \''.$beforeDate.'\' ';
-		}
-
-		$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*',$core->auth->cryptLegacy($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('H*hex',substr($code,32));
-
-		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 ($core->auth->cryptLegacy($rs->user_pwd) != $pwd) {
-			return false;
-		}
-
-		$permissions = $core->getBlogPermissions($core->blog->id);
-
-		if ( empty($permissions[$rs->user_id]) ) {
-			return false;
-		}
-
-		return $rs->user_id;
-	}
-
-	public static function purgeOldSpam($core)
-	{
-		$defaultDateLastPurge = time();
-		$defaultModerationTTL = '7';
-		$init = false;
-
-		// settings
-		$core->blog->settings->addNamespace('antispam');
-
-		$dateLastPurge = $core->blog->settings->antispam->antispam_date_last_purge;
-		if ($dateLastPurge === null) {
-			$init = true;
-			$core->blog->settings->antispam->put('antispam_date_last_purge',$defaultDateLastPurge,'integer','Antispam Date Last Purge (unix timestamp)',true,false);
-			$dateLastPurge = $defaultDateLastPurge;
-		}
-		$moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl;
-		if ($moderationTTL === null) {
-			$core->blog->settings->antispam->put('antispam_moderation_ttl',$defaultModerationTTL,'integer','Antispam Moderation TTL (days)',true,false);
-			$moderationTTL = $defaultModerationTTL;
-		}
-
-		if ($moderationTTL < 0) {
-			// disabled
-			return;
-		}
-
-		// we call the purge every day
-		if ((time()-$dateLastPurge) > (86400)) {
-			// update dateLastPurge
-			if (!$init) {
-				$core->blog->settings->antispam->put('antispam_date_last_purge',time(),null,null,true,false);
-			}
-			$date = date('Y-m-d H:i:s', time() - $moderationTTL*86400);
-			dcAntispam::delAllSpam($core, $date);
-		}
-	}
+    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 dashboardIcon($core, $icons)
+    {
+        if (($count = self::countSpam($core)) > 0) {
+            $str = ($count > 1) ? __('(including %d spam comments)') : __('(including %d spam comment)');
+            $icons['comments'][0] .= '</span></a> <br /><a href="' . $core->adminurl->get('admin.comments', array('status' => '-2')) . '"><span>' .
+            sprintf($str, $count);
+        }
+    }
+
+    public static function dashboardIconTitle($core)
+    {
+        if (($count = self::countSpam($core)) > 0) {
+            $str = ($count > 1) ? __('(including %d spam comments)') : __('(including %d spam comment)');
+            return '</span></a> <br /><a href="' . $core->adminurl->get('admin.comments', array('status' => '-2')) . '"><span>' .
+            sprintf($str, $count);
+        } else {
+            return '';
+        }
+    }
+
+    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, $beforeDate = null)
+    {
+        $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 ';
+        if ($beforeDate) {
+            $strReq .= 'AND comment_dt < \'' . $beforeDate . '\' ';
+        }
+
+        $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*', $core->auth->cryptLegacy($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('H*hex', substr($code, 32));
+
+        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 ($core->auth->cryptLegacy($rs->user_pwd) != $pwd) {
+            return false;
+        }
+
+        $permissions = $core->getBlogPermissions($core->blog->id);
+
+        if (empty($permissions[$rs->user_id])) {
+            return false;
+        }
+
+        return $rs->user_id;
+    }
+
+    public static function purgeOldSpam($core)
+    {
+        $defaultDateLastPurge = time();
+        $defaultModerationTTL = '7';
+        $init                 = false;
+
+        // settings
+        $core->blog->settings->addNamespace('antispam');
+
+        $dateLastPurge = $core->blog->settings->antispam->antispam_date_last_purge;
+        if ($dateLastPurge === null) {
+            $init = true;
+            $core->blog->settings->antispam->put('antispam_date_last_purge', $defaultDateLastPurge, 'integer', 'Antispam Date Last Purge (unix timestamp)', true, false);
+            $dateLastPurge = $defaultDateLastPurge;
+        }
+        $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl;
+        if ($moderationTTL === null) {
+            $core->blog->settings->antispam->put('antispam_moderation_ttl', $defaultModerationTTL, 'integer', 'Antispam Moderation TTL (days)', true, false);
+            $moderationTTL = $defaultModerationTTL;
+        }
+
+        if ($moderationTTL < 0) {
+            // disabled
+            return;
+        }
+
+        // we call the purge every day
+        if ((time() - $dateLastPurge) > (86400)) {
+            // update dateLastPurge
+            if (!$init) {
+                $core->blog->settings->antispam->put('antispam_date_last_purge', time(), null, null, true, false);
+            }
+            $date = date('Y-m-d H:i:s', time() - $moderationTTL * 86400);
+            dcAntispam::delAllSpam($core, $date);
+        }
+    }
 }
Index: plugins/antispam/inc/lib.dc.antispam.url.php
===================================================================
--- plugins/antispam/inc/lib.dc.antispam.url.php	(revision 2566)
+++ plugins/antispam/inc/lib.dc.antispam.url.php	(revision 3730)
@@ -10,89 +10,88 @@
 #
 # -- END LICENSE BLOCK -----------------------------------------
-if (!defined('DC_RC_PATH')) { return; }
+if (!defined('DC_RC_PATH')) {return;}
 
 class dcAntispamURL extends dcUrlHandlers
 {
-	public static function hamFeed($args)
-	{
-		self::genFeed('ham',$args);
-	}
+    public static function hamFeed($args)
+    {
+        self::genFeed('ham', $args);
+    }
 
-	public static function spamFeed($args)
-	{
-		self::genFeed('spam',$args);
-	}
+    public static function spamFeed($args)
+    {
+        self::genFeed('spam', $args);
+    }
 
-	private static function genFeed($type,$args)
-	{
-		global $core;
-		$user_id = dcAntispam::checkUserCode($core,$args);
+    private static function genFeed($type, $args)
+    {
+        global $core;
+        $user_id = dcAntispam::checkUserCode($core, $args);
 
-		if ($user_id === false) {
-			self::p404();
-			return;
-		}
+        if ($user_id === false) {
+            self::p404();
+            return;
+        }
 
-		$core->auth->checkUser($user_id,null,null);
+        $core->auth->checkUser($user_id, null, null);
 
-		header('Content-Type: application/xml; charset=UTF-8');
+        header('Content-Type: application/xml; charset=UTF-8');
 
-		$title = $core->blog->name.' - '.__('Spam moderation'). ' - ';
-		$params = array();
-		$end_url = '';
-		if ($type == 'spam') {
-			$title .= __('Spam');
-			$params['comment_status'] = -2;
-			$end_url = '?status=-2';
-		} else {
-			$title .= __('Ham');
-			$params['sql'] = ' AND comment_status IN (1,-1) ';
-		}
+        $title   = $core->blog->name . ' - ' . __('Spam moderation') . ' - ';
+        $params  = array();
+        $end_url = '';
+        if ($type == 'spam') {
+            $title .= __('Spam');
+            $params['comment_status'] = -2;
+            $end_url                  = '?status=-2';
+        } else {
+            $title .= __('Ham');
+            $params['sql'] = ' AND comment_status IN (1,-1) ';
+        }
 
-		echo
-		'<?xml version="1.0" encoding="utf-8"?>'."\n".
-		'<rss version="2.0"'."\n".
-		'xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n".
-		'xmlns:content="http://purl.org/rss/1.0/modules/content/">'."\n".
-		'<channel>'."\n".
-		'<title>'.html::escapeHTML($title).'</title>'."\n".
-		'<link>'.(DC_ADMIN_URL ? DC_ADMIN_URL.'comments.php'.$end_url : 'about:blank').'</link>'."\n".
-		'<description></description>'."\n";
+        echo
+        '<?xml version="1.0" encoding="utf-8"?>' . "\n" .
+        '<rss version="2.0"' . "\n" .
+        'xmlns:dc="http://purl.org/dc/elements/1.1/"' . "\n" .
+        'xmlns:content="http://purl.org/rss/1.0/modules/content/">' . "\n" .
+        '<channel>' . "\n" .
+        '<title>' . html::escapeHTML($title) . '</title>' . "\n" .
+            '<link>' . (DC_ADMIN_URL ? DC_ADMIN_URL . 'comments.php' . $end_url : 'about:blank') . '</link>' . "\n" .
+            '<description></description>' . "\n";
 
-		$rs = $core->blog->getComments($params);
-		$maxitems = 20;
-		$nbitems = 0;
+        $rs       = $core->blog->getComments($params);
+        $maxitems = 20;
+        $nbitems  = 0;
 
-		while ($rs->fetch() && ($nbitems < $maxitems))
-		{
-			$nbitems++;
-			$uri = DC_ADMIN_URL ? DC_ADMIN_URL.'comment.php?id='.$rs->comment_id : 'about:blank';
-			$author = $rs->comment_author;
-			$title = $rs->post_title.' - '.$author;
-			if ($type == 'spam') {
-				$title .= '('.$rs->comment_spam_filter.')';
-			}
-			$id = $rs->getFeedID();
+        while ($rs->fetch() && ($nbitems < $maxitems)) {
+            $nbitems++;
+            $uri    = DC_ADMIN_URL ? DC_ADMIN_URL . 'comment.php?id=' . $rs->comment_id : 'about:blank';
+            $author = $rs->comment_author;
+            $title  = $rs->post_title . ' - ' . $author;
+            if ($type == 'spam') {
+                $title .= '(' . $rs->comment_spam_filter . ')';
+            }
+            $id = $rs->getFeedID();
 
-			$content = '<p>IP: '.$rs->comment_ip;
+            $content = '<p>IP: ' . $rs->comment_ip;
 
-			if (trim($rs->comment_site)) {
-				$content .= '<br />URL: <a href="'.$rs->comment_site.'">'.$rs->comment_site.'</a>';
-			}
-			$content .= "</p><hr />\n";
-			$content .= $rs->comment_content;
+            if (trim($rs->comment_site)) {
+                $content .= '<br />URL: <a href="' . $rs->comment_site . '">' . $rs->comment_site . '</a>';
+            }
+            $content .= "</p><hr />\n";
+            $content .= $rs->comment_content;
 
-			echo
-			'<item>'."\n".
-			'  <title>'.html::escapeHTML($title).'</title>'."\n".
-			'  <link>'.$uri.'</link>'."\n".
-			'  <guid>'.$id.'</guid>'."\n".
-			'  <pubDate>'.$rs->getRFC822Date().'</pubDate>'."\n".
-			'  <dc:creator>'.html::escapeHTML($author).'</dc:creator>'."\n".
-			'  <description>'.html::escapeHTML($content).'</description>'."\n".
-			'</item>';
-		}
+            echo
+            '<item>' . "\n" .
+            '  <title>' . html::escapeHTML($title) . '</title>' . "\n" .
+            '  <link>' . $uri . '</link>' . "\n" .
+            '  <guid>' . $id . '</guid>' . "\n" .
+            '  <pubDate>' . $rs->getRFC822Date() . '</pubDate>' . "\n" .
+            '  <dc:creator>' . html::escapeHTML($author) . '</dc:creator>' . "\n" .
+            '  <description>' . html::escapeHTML($content) . '</description>' . "\n" .
+                '</item>';
+        }
 
-		echo "</channel>\n</rss>";
-	}
+        echo "</channel>\n</rss>";
+    }
 }
