[1560] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
| 3 | # This file is part of dcFilterDuplicate, a plugin for Dotclear 2. |
---|
| 4 | # |
---|
[2902] | 5 | # Copyright (c) 2009-2011 JC Denis and contributors |
---|
[1560] | 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 | |
---|
| 13 | if (!defined('DC_RC_PATH')){return;} |
---|
| 14 | |
---|
| 15 | class dcFilterDuplicate extends dcSpamFilter |
---|
| 16 | { |
---|
| 17 | public $name = 'Duplicate comment filter'; |
---|
| 18 | public $has_gui = true; |
---|
[2305] | 19 | |
---|
[1560] | 20 | protected function setInfo() |
---|
| 21 | { |
---|
| 22 | $this->description = __('Same comments on others blogs of a multiblog.'); |
---|
| 23 | } |
---|
[2305] | 24 | |
---|
[1560] | 25 | public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) |
---|
| 26 | { |
---|
| 27 | if ($type != 'comment') return null; |
---|
[2305] | 28 | |
---|
| 29 | $minlen = abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen); |
---|
[1981] | 30 | if (strlen($content) < $minlen) return null; |
---|
[2305] | 31 | |
---|
[1560] | 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 | } |
---|
[2305] | 45 | catch (Exception $e) |
---|
| 46 | { |
---|
| 47 | throw new Exception($e->getMessage()); |
---|
| 48 | } |
---|
[1560] | 49 | } |
---|
[2305] | 50 | |
---|
[1560] | 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 | } |
---|
[2305] | 63 | |
---|
[1560] | 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'); |
---|
[2305] | 68 | |
---|
[1560] | 69 | $cur->comment_status = -2; |
---|
| 70 | $cur->comment_spam_status = 'Duplicate on other blog'; |
---|
[1566] | 71 | $cur->comment_spam_filter = 'dcFilterDuplicate'; |
---|
[2305] | 72 | |
---|
[1560] | 73 | $cur->update( |
---|
| 74 | "WHERE comment_content='".$this->core->con->escape($content)."' ". |
---|
| 75 | "AND comment_ip='".$ip."' " |
---|
| 76 | ); |
---|
| 77 | $this->core->con->unlock(); |
---|
[2305] | 78 | |
---|
[1981] | 79 | $this->triggerOtherBlogs($content,$ip); |
---|
[1560] | 80 | } |
---|
[1981] | 81 | |
---|
[1560] | 82 | public function gui($url) |
---|
| 83 | { |
---|
[2305] | 84 | $minlen = abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen); |
---|
[1560] | 85 | if (isset($_POST['dcfilterduplicate_minlen'])) |
---|
| 86 | { |
---|
| 87 | $minlen = abs((integer) $_POST['dcfilterduplicate_minlen']); |
---|
[2305] | 88 | $this->core->blog->settings->dcFilterDuplicate->put('dcfilterduplicate_minlen',$minlen,'integer'); |
---|
[1560] | 89 | } |
---|
[2305] | 90 | |
---|
[1560] | 91 | $res = |
---|
| 92 | '<form action="'.html::escapeURL($url).'" method="post">'. |
---|
[1981] | 93 | '<p><label class="classic">'.__('Minimum content length before check for duplicate:').'<br />'. |
---|
[1560] | 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 | } |
---|
[2305] | 101 | |
---|
[1981] | 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 | ); |
---|
[2305] | 111 | |
---|
[1981] | 112 | while ($rs->fetch()) |
---|
| 113 | { |
---|
| 114 | $b = new dcBlog($this,$rs->blog_id); |
---|
| 115 | $b->triggerBlog(); |
---|
| 116 | unset($b); |
---|
| 117 | } |
---|
| 118 | } |
---|
[1560] | 119 | } |
---|
| 120 | ?> |
---|