source: extensions/rv_akismet/check.inc.php @ 13799

Last change on this file since 13799 was 13799, checked in by rvelices, 12 years ago

rv_akismet - added a technique to detect robots (as of today my tests show 100% spams caught) :)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 1.5 KB
Line 
1<?php
2function akismet_user_comment_check($action, $comment)
3{
4  global $conf;
5  if ('reject'==$action or $conf['akismet_spam_action']==$action)
6    return $action; // already rejecting
7  if ( empty($conf['akismet_api_key']) )
8    return $action; // need to config it
9  /*if ( !is_a_guest() )
10    return $action;*/
11
12  include_once( dirname(__FILE__).'/akismet.class.php' );
13
14  set_make_full_url();
15  $url = duplicate_picture_url( array('image_id'=>$comment['image_id']) );
16  unset_make_full_url();
17  $aki_comm = array(
18    'author' => $comment['author'],
19    'body' => $comment['content'],
20    'permalink' => $url,
21    'referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',
22  );
23  if (isset($_POST['url']) && strlen($_POST['url']))
24    $aki_comm['comment_author_url'] = $_POST['url'];
25
26  $akismet = new Akismet(get_absolute_root_url(), $conf['akismet_api_key'], $aki_comm);
27
28  if( !$akismet->errorsExist() )
29  {
30    $counters = explode('/', $conf['akismet_counters']);
31    if ( $akismet->isSpam() )
32    {
33      $action = $conf['akismet_spam_action'];
34      if ('reject'!=$action) set_status_header(403);
35      $counters[0]++;
36      $_POST['cr'][] = 'aki';
37    }
38    else
39      $_POST['cr'][] = 'aki-ok';
40    $counters[1]++;
41    $conf['akismet_counters'] = implode('/', $counters);
42    $query = 'UPDATE '.CONFIG_TABLE.' SET value="'.$conf['akismet_counters'].'" WHERE param="akismet_counters" LIMIT 1';
43    pwg_query($query);
44  }
45  else {
46    $_POST['cr'][] = 'aki-FAIL';
47    if (is_admin())
48      var_export( $akismet->getErrors() );
49  }
50
51  return $action;
52}
53
54?>
Note: See TracBrowser for help on using the repository browser.