Dotclear

source: plugins/dcFilterDuplicate/inc/class.filter.duplicate.php @ 2902

Revision 2902, 3.4 KB checked in by JcDenis, 12 years ago (diff)

dcFlterDuplicate 0.4

  • Fixed call to blog object on prepend
  • New year copyright
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of dcFilterDuplicate, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009-2011 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12
13if (!defined('DC_RC_PATH')){return;}
14
15class dcFilterDuplicate extends dcSpamFilter
16{
17     public $name = 'Duplicate comment filter';
18     public $has_gui = true;
19     
20     protected function setInfo()
21     {
22          $this->description = __('Same comments on others blogs of a multiblog.');
23     }
24     
25     public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status)
26     {
27          if ($type != 'comment') return null;
28         
29          $minlen = abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen);
30          if (strlen($content) < $minlen) return null;
31         
32          try
33          {
34               if ($this->isDuplicate($content,$ip))
35               {
36                    $this->markDuplicate($content,$ip);
37                    $status = 'Duplicate on other blog';
38                    return true;
39               }
40               else
41               {
42                    return null;
43               }
44          }
45          catch (Exception $e)
46          {
47               throw new Exception($e->getMessage());
48          }
49     }
50     
51     public function isDuplicate($content,$ip)
52     {
53          $rs = $this->core->con->select(
54               'SELECT C.comment_id '.
55               'FROM '.$this->core->prefix.'comment C '.
56               'LEFT JOIN '.$this->core->prefix.'post P ON C.post_id=P.post_id '.
57               "WHERE P.blog_id != '".$this->core->blog->id."' ".
58               "AND C.comment_content='".$this->core->con->escape($content)."' ".
59               "AND C.comment_ip='".$ip."' "
60          );
61          return !$rs->isEmpty();
62     }
63     
64     public function markDuplicate($content,$ip)
65     {
66          $cur = $this->core->con->openCursor($this->core->prefix.'comment');
67          $this->core->con->writeLock($this->core->prefix.'comment');
68         
69          $cur->comment_status = -2;
70          $cur->comment_spam_status = 'Duplicate on other blog';
71          $cur->comment_spam_filter = 'dcFilterDuplicate';
72         
73          $cur->update(
74               "WHERE comment_content='".$this->core->con->escape($content)."' ".
75               "AND comment_ip='".$ip."' "
76          );
77          $this->core->con->unlock();
78         
79          $this->triggerOtherBlogs($content,$ip);
80     }
81
82     public function gui($url)
83     {
84          $minlen = abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen);
85          if (isset($_POST['dcfilterduplicate_minlen']))
86          {
87               $minlen = abs((integer) $_POST['dcfilterduplicate_minlen']);
88               $this->core->blog->settings->dcFilterDuplicate->put('dcfilterduplicate_minlen',$minlen,'integer');
89          }
90         
91          $res =
92          '<form action="'.html::escapeURL($url).'" method="post">'.
93          '<p><label class="classic">'.__('Minimum content length before check for duplicate:').'<br />'.
94          form::field(array('dcfilterduplicate_minlen'),65,255,$minlen).
95          '</label></p>'.
96          '<p><input type="submit" name="save" value="'.__('save').'" />'.
97          $this->core->formNonce().'</p>'.
98          '</form>';
99          return $res;
100     }
101     
102     public function triggerOtherBlogs($content,$ip)
103     {
104          $rs = $this->core->con->select(
105               'SELECT P.blog_id '.
106               'FROM '.$this->core->prefix.'comment C '.
107               'LEFT JOIN '.$this->core->prefix.'post P ON C.post_id=P.post_id '.
108               "WHERE C.comment_content='".$this->core->con->escape($content)."' ".
109               "AND C.comment_ip='".$ip."' "
110          );
111         
112          while ($rs->fetch())
113          {
114               $b = new dcBlog($this,$rs->blog_id);
115               $b->triggerBlog();
116               unset($b);
117          }
118     }
119}
120?>
Note: See TracBrowser for help on using the repository browser.

Sites map