- Timestamp:
- 05/08/11 21:44:10 (14 years ago)
- Branch:
- default
- Children:
- 224:23ec5a339bcf, 225:411ee50a8664, 249:d0a17b7ca6e0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/antispam/filters/class.dc.filter.words.php
r3 r223 16 16 public $has_gui = true; 17 17 public $name = 'Bad Words'; 18 18 19 19 private $style_list = 'height: 200px; overflow: auto; margin-bottom: 1em; '; 20 20 private $style_p = 'margin: 1px 0 0 0; padding: 0.2em 0.5em; '; 21 21 private $style_global = 'background: #ccff99; '; 22 22 23 23 private $con; 24 24 private $table; 25 25 26 26 public function __construct($core) 27 27 { … … 30 30 $this->table = $core->prefix.'spamrule'; 31 31 } 32 32 33 33 protected function setInfo() 34 34 { 35 35 $this->description = __('Words Blacklist'); 36 36 } 37 37 38 38 public function getStatusMessage($status,$comment_id) 39 39 { 40 40 return sprintf(__('Filtered by %1$s with word %2$s.'),$this->guiLink(),'<em>'.$status.'</em>'); 41 41 } 42 42 43 43 public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) 44 44 { 45 45 $str = $author.' '.$email.' '.$site.' '.$content; 46 46 47 47 $rs = $this->getRules(); 48 48 49 49 while ($rs->fetch()) 50 50 { 51 51 $word = $rs->rule_content; 52 52 53 53 if (substr($word,0,1) == '/' && substr($word,-1,1) == '/') { 54 54 $reg = substr(substr($word,1),0,-1); … … 57 57 $reg = '(^|\s+|>|<)'.$reg.'(>|<|\s+|\.|$)'; 58 58 } 59 59 60 60 if (preg_match('/'.$reg.'/msiu',$str)) { 61 61 $status = $word; … … 64 64 } 65 65 } 66 66 67 67 public function gui($url) 68 68 { 69 69 $core =& $this->core; 70 70 71 71 # Create list 72 72 if (!empty($_POST['createlist'])) … … 79 79 } 80 80 } 81 81 82 82 # Adding a word 83 83 if (!empty($_POST['swa'])) 84 84 { 85 85 $globalsw = !empty($_POST['globalsw']) && $core->auth->isSuperAdmin(); 86 86 87 87 try { 88 88 $this->addRule($_POST['swa'],$globalsw); … … 92 92 } 93 93 } 94 94 95 95 # Removing spamwords 96 96 if (!empty($_POST['swd']) && is_array($_POST['swd'])) … … 103 103 } 104 104 } 105 105 106 106 /* DISPLAY 107 107 ---------------------------------------------- */ 108 108 $res = ''; 109 109 110 110 if (!empty($_GET['list'])) { 111 111 $res .= '<p class="message">'.__('Words have been successfully added.').'</p>'; … … 117 117 $res .= '<p class="message">'.__('Words have been successfully removed.').'</p>'; 118 118 } 119 119 120 120 $res .= 121 121 '<form action="'.html::escapeURL($url).'" method="post">'. 122 122 '<fieldset><legend>'.__('Add a word').'</legend>'. 123 '<p> '.form::field('swa',20,128).'';124 123 '<p><label class="classic" for="swa">'.__('Add a word').' '.form::field('swa',20,128).'</label>'; 124 125 125 if ($core->auth->isSuperAdmin()) { 126 $res .= '<label class="classic" >'.form::checkbox('globalsw',1).' '.126 $res .= '<label class="classic" for="globalsw">'.form::checkbox('globalsw',1).' '. 127 127 __('Global word').'</label> '; 128 128 } 129 129 130 130 $res .= 131 131 $core->formNonce(). … … 133 133 '</fieldset>'. 134 134 '</form>'; 135 135 136 136 $rs = $this->getRules(); 137 137 if ($rs->isEmpty()) … … 145 145 '<fieldset><legend>' . __('List') . '</legend>'. 146 146 '<div style="'.$this->style_list.'">'; 147 147 148 148 while ($rs->fetch()) 149 149 { … … 154 154 $p_style .= $this->style_global; 155 155 } 156 156 157 157 $res .= 158 158 '<p style="'.$p_style.'"><label class="classic">'. 159 form::checkbox(array('swd[]'),$rs->rule_id,false,'','',$disabled_word ).' '.159 form::checkbox(array('swd[]'),$rs->rule_id,false,'','',$disabled_word, 'title="'.html::escapeHTML($rs->rule_content).'"').' '. 160 160 html::escapeHTML($rs->rule_content). 161 161 '</label></p>'; 162 162 } 163 163 164 164 $res .= 165 165 '</div>'. … … 169 169 '</fieldset></form>'; 170 170 } 171 171 172 172 if ($core->auth->isSuperAdmin()) 173 173 { … … 180 180 '</form>'; 181 181 } 182 182 183 183 return $res; 184 184 } 185 185 186 186 private function getRules() 187 187 { … … 192 192 "OR blog_id IS NULL ) ". 193 193 'ORDER BY blog_id ASC, rule_content ASC '; 194 194 195 195 return $this->con->select($strReq); 196 196 } 197 197 198 198 private function addRule($content,$general=false) 199 199 { … … 202 202 "AND rule_content = '".$this->con->escape($content)."' "; 203 203 $rs = $this->con->select($strReq); 204 204 205 205 if (!$rs->isEmpty()) { 206 206 throw new Exception(__('This word exists')); 207 207 } 208 208 209 209 $rs = $this->con->select('SELECT MAX(rule_id) FROM '.$this->table); 210 210 $id = (integer) $rs->f(0) + 1; 211 211 212 212 $cur = $this->con->openCursor($this->table); 213 213 $cur->rule_id = $id; 214 214 $cur->rule_type = 'word'; 215 215 $cur->rule_content = (string) $content; 216 216 217 217 if ($general && $this->core->auth->isSuperAdmin()) { 218 218 $cur->blog_id = null; … … 220 220 $cur->blog_id = $this->core->blog->id; 221 221 } 222 222 223 223 $cur->insert(); 224 224 } 225 225 226 226 private function removeRule($ids) 227 227 { 228 228 $strReq = 'DELETE FROM '.$this->table.' '; 229 229 230 230 if (is_array($ids)) { 231 231 foreach ($ids as &$v) { … … 237 237 $strReq .= 'WHERE rule_id = '.$ids.' '; 238 238 } 239 239 240 240 if (!$this->core->auth->isSuperAdmin()) { 241 241 $strReq .= "AND blog_id = '".$this->con->escape($this->core->blog->id)."' "; 242 242 } 243 243 244 244 $this->con->execute($strReq); 245 245 } 246 246 247 247 public function defaultWordsList() 248 248 { … … 347 347 'zolus' 348 348 ); 349 349 350 350 foreach ($words as $w) { 351 351 try { … … 356 356 } 357 357 ?> 358
Note: See TracChangeset
for help on using the changeset viewer.
