[ Index ] |
|
Code source de Dotclear 2.0-beta6 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This is Antispam, a plugin for DotClear. 4 # Copyright (c) 2007 Alain Vagner and contributors. All rights 5 # reserved. 6 # 7 # DotClear is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # DotClear is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with DotClear; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 class dcSpamFilters 24 { 25 private $filters = array(); 26 private $filters_opt = array(); 27 private $core; 28 29 public function __construct(&$core) 30 { 31 $this->core =& $core; 32 } 33 34 public function init($filters) 35 { 36 foreach ($filters as $f) 37 { 38 if (!class_exists($f)) { 39 continue; 40 } 41 42 $r = new ReflectionClass($f); 43 $p = $r->getParentClass(); 44 45 if (!$p || $p->name != 'dcSpamFilter') { 46 continue; 47 } 48 49 $this->filters[$f] = new $f($this->core); 50 } 51 52 $this->setFilterOpts(); 53 if (!empty($this->filters_opt)) { 54 uasort($this->filters,array($this,'orderCallBack')); 55 } 56 } 57 58 public function getFilters() 59 { 60 return $this->filters; 61 } 62 63 public function isSpam(&$cur) 64 { 65 foreach ($this->filters as $fid => $f) 66 { 67 if (!$f->active) { 68 continue; 69 } 70 71 $type = $cur->comment_trackback ? 'trackback' : 'comment'; 72 $author = $cur->comment_author; 73 $email = $cur->comment_email; 74 $site = $cur->comment_site; 75 $ip = $cur->comment_ip; 76 $content = $cur->comment_content; 77 $post_id = $cur->post_id; 78 79 $is_spam = $f->isSpam($type,$author,$email,$site,$ip,$content,$post_id,$status); 80 81 if ($is_spam === true) { 82 $cur->comment_status = -2; 83 $cur->comment_spam_status = $status; 84 $cur->comment_spam_filter = $fid; 85 return true; 86 } elseif ($is_spam === false) { 87 return false; 88 } 89 } 90 91 return false; 92 } 93 94 public function trainFilters(&$rs,$status,$filter_name) 95 { 96 foreach ($this->filters as $fid => $f) 97 { 98 if (!$f->active) { 99 continue; 100 } 101 102 $type = $rs->comment_trackback ? 'trackback' : 'comment'; 103 $author = $rs->comment_author; 104 $email = $rs->comment_email; 105 $site = $rs->comment_site; 106 $ip = $rs->comment_ip; 107 $content = $rs->comment_content; 108 109 $f->trainFilter($status,$filter_name,$type,$author,$email,$site,$ip,$content,$rs); 110 } 111 } 112 113 public function statusMessage(&$rs,$filter_name) 114 { 115 $f = isset($this->filters[$filter_name]) ? $this->filters[$filter_name] : null; 116 117 if ($f === null) 118 { 119 return __('Unknown filter.'); 120 } 121 else 122 { 123 $status = $rs->exists('comment_spam_status') ? $rs->comment_spam_status : null; 124 125 return $f->getStatusMessage($status,$rs->comment_id); 126 } 127 } 128 129 public function saveFilterOpts($opts,$global=false) 130 { 131 $this->core->blog->settings->setNameSpace('antispam'); 132 if ($global) { 133 $this->core->blog->settings->drop('antispam_filters'); 134 } 135 $this->core->blog->settings->put('antispam_filters',serialize($opts),'string','Antispam Filters',true,$global); 136 } 137 138 private function setFilterOpts() 139 { 140 if ($this->core->blog->settings->antispam_filters !== null) { 141 $this->filters_opt = @unserialize($this->core->blog->settings->antispam_filters); 142 } 143 144 # Create default options if needed 145 if (!is_array($this->filters_opt)) { 146 $this->saveFilterOpts(array(),true); 147 $this->filters_opt = array(); 148 } 149 150 foreach ($this->filters_opt as $k => $o) 151 { 152 if (isset($this->filters[$k]) && is_array($o)) { 153 $this->filters[$k]->active = $o[0]; 154 $this->filters[$k]->order = $o[1]; 155 } 156 } 157 } 158 159 private function orderCallBack($a,$b) 160 { 161 if ($a->order == $b->order) { 162 return 0; 163 } 164 165 return $a->order > $b->order ? 1 : -1; 166 } 167 } 168 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Feb 23 22:16:06 2007 | par Balluche grâce à PHPXref 0.7 |