Changeset 19933
- Timestamp:
- 12/22/08 17:05:58 (2 years ago)
- Files:
-
- branches/ragnaroek/midcom/net.nehmer.comments/comment.php (modified) (4 diffs)
- branches/ragnaroek/midcom/net.nehmer.comments/config/config.inc (modified) (1 diff)
- branches/ragnaroek/midcom/net.nehmer.comments/handler/view.php (modified) (2 diffs)
- branches/ragnaroek/midcom/net.nemein.discussion/config/config.inc (modified) (1 diff)
- branches/ragnaroek/midcom/net.nemein.discussion/handler/post.php (modified) (2 diffs)
- branches/ragnaroek/midcom/net.nemein.discussion/helper_email_import.php (modified) (2 diffs)
- branches/ragnaroek/midcom/net.nemein.discussion/midcom/interfaces.php (modified) (2 diffs)
- branches/ragnaroek/midcom/net.nemein.discussion/post.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/ragnaroek/midcom/net.nehmer.comments/comment.php
r18515 r19933 165 165 return $qb->count_unchecked(); 166 166 } 167 168 /** 169 * Check the post against possible spam filters. 170 * 171 * This will update post status on the background and log the information. 172 */ 173 function check_spam(&$config) 174 { 175 if (!$config->get('enable_mollom_check')) 176 { 177 // Mollom spam checker is not enabled, skip check 178 return; 179 } 180 181 if (!$_MIDCOM->componentloader->is_installed('be.crsolutions.mollom')) 182 { 183 debug_push_class(__CLASS__, __FUNCTION__); 184 debug_add('be.crsolutions.mollom spam checker is enabled but not installed, aborting check', MIDCOM_LOG_INFO); 185 debug_pop(); 186 return; 187 } 188 189 $_MIDCOM->load_library('be.crsolutions.mollom'); 190 191 $mollom = new be_crsolutions_mollom(); 192 if (!$mollom->initialize()) 193 { 194 debug_push_class(__CLASS__, __FUNCTION__); 195 debug_add('be.crsolutions.mollom initialization failed, aborting check', MIDCOM_LOG_INFO); 196 debug_pop(); 197 return; 198 } 199 200 $ret = $mollom->check_content(null, $this->title, $this->content, $this->author); 201 if (!isset($ret['spam'])) 202 { 203 // No need to log here, the mollom class does that. Just abort. 204 return; 205 } 206 207 if ($ret['spam'] == 'ham') 208 { 209 // Quality content 210 debug_push_class(__CLASS__, __FUNCTION__); 211 debug_add("Mollom noted comment \"{$this->title}\" ({$this->guid}) as ham with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 212 debug_pop(); 213 214 $this->status = NET_NEHMER_COMMENTS_MODERATED; 215 $this->update(); 216 $this->_log_moderation('reported_not_junk', 'mollom', "Quality = {$ret['quality']}"); 217 return; 218 } 219 220 if ($ret['spam'] == 'spam') 221 { 222 // Spam 223 debug_push_class(__CLASS__, __FUNCTION__); 224 debug_add("Mollom noted comment \"{$this->title}\" ({$this->guid}) as spam with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 225 debug_pop(); 226 227 $this->status = NET_NEHMER_COMMENTS_JUNK; 228 $this->update(); 229 $this->_log_moderation('confirmed_junk', 'mollom', "Quality = {$ret['quality']}"); 230 return; 231 } 232 233 // Otherwise we let it stay in initial status, as Mollom was unsure 234 235 debug_push_class(__CLASS__, __FUNCTION__); 236 debug_add("Mollom noted comment \"{$this->title}\" ({$this->guid}) as unsure with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 237 debug_pop(); 167 238 239 return; 240 } 241 168 242 function report_abuse() 169 243 { … … 282 356 if (count($log_action) == 2) 283 357 { 284 if ($log_details[0] == 'anonymous')358 switch ($log_details[0]) 285 359 { 286 $reporter = 'anonymous'; 287 } 288 else 289 { 290 $user =& $_MIDCOM->auth->get_user($log_details[0]); 291 $reporter = $user->name; 360 case 'anonymous': 361 $reporter = 'anonymous'; 362 break; 363 case 'mollom': 364 $reporter = 'mollom'; 365 break; 366 default: 367 $user =& $_MIDCOM->auth->get_user($log_details[0]); 368 $reporter = $user->name; 369 break; 292 370 } 293 371 … … 304 382 } 305 383 306 function _log_moderation($action = 'marked_spam') 307 { 308 if ($_MIDCOM->auth->user) 309 { 310 $reporter = $_MIDCOM->auth->user->guid; 311 } 312 else 313 { 314 $reporter = 'anonymous'; 384 function _log_moderation($action = 'marked_spam', $reporter = null, $extra = null) 385 { 386 if ($reporter === null) 387 { 388 if ($_MIDCOM->auth->user) 389 { 390 $reporter = $_MIDCOM->auth->user->guid; 391 } 392 else 393 { 394 $reporter = 'anonymous'; 395 } 315 396 } 316 397 $browser = str_replace(':', '_', $_SERVER['HTTP_USER_AGENT']); … … 329 410 2 => $browser 330 411 ); 412 413 if ($extra !== null) 414 { 415 $log_details[] = $extra; 416 } 331 417 332 418 $this->set_parameter('net.nehmer.comments:moderation_log', implode(':', $log_action), implode(':', $log_details)); branches/ragnaroek/midcom/net.nehmer.comments/config/config.inc
r19119 r19933 14 14 // Allow anonymous posting. 15 15 'allow_anonymous' => true, 16 17 'enable_mollom_check' => false, 16 18 17 19 // Notify authors on new comments branches/ragnaroek/midcom/net.nehmer.comments/handler/view.php
r19753 r19933 601 601 { 602 602 if ( ! $_MIDCOM->auth->user 603 && ! $_MIDCOM->auth->request_sudo( ))603 && ! $_MIDCOM->auth->request_sudo('net.nehmer.comments')) 604 604 { 605 605 $_MIDCOM->generate_error(MIDCOM_ERRCRIT, … … 611 611 { 612 612 case 'save': 613 // Check against comment spam 614 $this->_new_comment->check_spam($this->_config); 615 613 616 $this->_cache_ratings(); 614 617 $this->_notify_authors(); branches/ragnaroek/midcom/net.nemein.discussion/config/config.inc
r15134 r19933 59 59 'moderators' => '', 60 60 61 'enable_mollom_check' => false, 61 62 'remove_unpopular_threads' => false, 62 63 branches/ragnaroek/midcom/net.nemein.discussion/handler/post.php
r19753 r19933 332 332 { 333 333 case 'save': 334 // Check spam 335 $this->_post->check_spam($this->_config); 336 334 337 // Update thread accordingly 335 338 $this->_thread->title = $this->_post->subject; … … 589 592 { 590 593 case 'save': 594 // Check spam 595 $this->_post->check_spam($this->_config); 596 591 597 // Index the article 592 598 $indexer =& $_MIDCOM->get_service('indexer'); branches/ragnaroek/midcom/net.nemein.discussion/helper_email_import.php
r19753 r19933 235 235 } 236 236 } 237 237 238 $post->set_parameter('midcom.helper.datamanager2', 'schema_name', $this->schema_name); 238 239 debug_add("Created new post #{$post->id}", MIDCOM_LOG_INFO); … … 296 297 $post->update(); 297 298 } 299 300 // Handle spam checks 301 $post->check_spam($this->_config); 298 302 299 303 // Index the post ?? branches/ragnaroek/midcom/net.nemein.discussion/midcom/interfaces.php
r18578 r19933 29 29 30 30 $this->_component = 'net.nemein.discussion'; 31 $this->_autoload_files = Array31 $this->_autoload_files = array 32 32 ( 33 33 'viewer.php', … … 36 36 'post.php', 37 37 ); 38 $this->_autoload_libraries = Array( 38 $this->_autoload_libraries = array 39 ( 39 40 'midcom.helper.datamanager2', 40 41 'de.bitfolge.feedcreator', branches/ragnaroek/midcom/net.nemein.discussion/post.php
r18578 r19933 141 141 return $this->subject; 142 142 } 143 144 /** 145 * Check the post against possible spam filters. 146 * 147 * This will update post status on the background and log the information. 148 */ 149 function check_spam(&$config) 150 { 151 if (!$config->get('enable_mollom_check')) 152 { 153 // Mollom spam checker is not enabled, skip check 154 return; 155 } 156 157 if (!$_MIDCOM->componentloader->is_installed('be.crsolutions.mollom')) 158 { 159 debug_push_class(__CLASS__, __FUNCTION__); 160 debug_add('be.crsolutions.mollom spam checker is enabled but not installed, aborting check', MIDCOM_LOG_INFO); 161 debug_pop(); 162 return; 163 } 164 165 $_MIDCOM->load_library('be.crsolutions.mollom'); 166 167 $mollom = new be_crsolutions_mollom(); 168 if (!$mollom->initialize()) 169 { 170 debug_push_class(__CLASS__, __FUNCTION__); 171 debug_add('be.crsolutions.mollom initialization failed, aborting check', MIDCOM_LOG_INFO); 172 debug_pop(); 173 return; 174 } 175 176 $ret = $mollom->check_content(null, $this->subject, $this->content, $this->sendername, $this->senderurl, $this->senderemail); 177 if (!isset($ret['spam'])) 178 { 179 // No need to log here, the mollom class does that. Just abort. 180 return; 181 } 182 183 if ($ret['spam'] == 'ham') 184 { 185 // Quality content 186 debug_push_class(__CLASS__, __FUNCTION__); 187 debug_add("Mollom noted post \"{$this->subject}\" ({$this->guid}) as ham with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 188 debug_pop(); 189 190 $this->status = NET_NEMEIN_DISCUSSION_MODERATED; 191 $this->update(); 192 $this->_log_moderation('reported_not_junk', 'mollom', "Quality = {$ret['quality']}"); 193 return; 194 } 195 196 if ($ret['spam'] == 'spam') 197 { 198 // Spam 199 debug_push_class(__CLASS__, __FUNCTION__); 200 debug_add("Mollom noted post \"{$this->subject}\" ({$this->guid}) as spam with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 201 debug_pop(); 202 203 $this->status = NET_NEMEIN_DISCUSSION_JUNK; 204 $this->update(); 205 $this->_log_moderation('confirmed_junk', 'mollom', "Quality = {$ret['quality']}"); 206 return; 207 } 208 209 // Otherwise we let it stay in initial status, as Mollom was unsure 210 211 debug_push_class(__CLASS__, __FUNCTION__); 212 debug_add("Mollom noted post \"{$this->subject}\" ({$this->guid}) as unsure with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 213 debug_pop(); 214 215 return; 216 } 143 217 144 218 /** … … 258 332 if (count($log_action) == 2) 259 333 { 260 if ($log_details[0] == 'anonymous')334 switch ($log_details[0]) 261 335 { 262 $reporter = 'anonymous'; 263 } 264 else 265 { 266 $user =& $_MIDCOM->auth->get_user($log_details[0]); 267 $reporter = $user->name; 336 case 'anonymous': 337 $reporter = 'anonymous'; 338 break; 339 case 'mollom': 340 $reporter = 'mollom'; 341 break; 342 default: 343 $user =& $_MIDCOM->auth->get_user($log_details[0]); 344 $reporter = $user->name; 345 break; 268 346 } 269 347 … … 280 358 } 281 359 282 function _log_moderation($action = 'marked_spam') 283 { 284 if ($_MIDCOM->auth->user) 285 { 286 $reporter = $_MIDCOM->auth->user->guid; 287 } 288 else 289 { 290 $reporter = 'anonymous'; 360 function _log_moderation($action = 'marked_spam', $reporter = null, $extra = null) 361 { 362 if ($reporter === null) 363 { 364 if ($_MIDCOM->auth->user) 365 { 366 $reporter = $_MIDCOM->auth->user->guid; 367 } 368 else 369 { 370 $reporter = 'anonymous'; 371 } 291 372 } 292 373 $browser = str_replace(':', '_', $_SERVER['HTTP_USER_AGENT']); … … 306 387 ); 307 388 389 if ($extra !== null) 390 { 391 $log_details[] = $extra; 392 } 393 308 394 $this->set_parameter('net.nemein.discussion:moderation_log', implode(':', $log_action), implode(':', $log_details)); 309 395 }
