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

Last change on this file since 26859 was 26859, checked in by mistic100, 11 years ago

compatibility with guestbook and command on albums

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1<?php
2function akismet_user_comment_check($action, $comment, $where)
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  switch($where)
16  {
17    case 'guestbook':
18      $url = defined('GUESTBOOK_URL') ? GUESTBOOK_URL : get_absolute_root_url();
19      break;
20    case 'album':
21      // build category url with minimum data (only id is always known)
22      $url = duplicate_index_url( array(
23        'section'=>'categories',
24        'category'=>array('id'=>$comment['category_id'], 'name'=>'', 'permalink'=>'')
25        ) );
26      break;
27    default:
28      $url = duplicate_picture_url( array('image_id'=>$comment['image_id']) );
29  }   
30  unset_make_full_url();
31
32  $aki_comm = array(
33    'author' => $comment['author'],
34    'body' => $comment['content'],
35    'comment_author_url' => $comment['website_url'],
36    'comment_author_email' => $comment['email'],
37    'permalink' => $url,
38    'referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',
39  );
40  /*if (isset($_POST['url']) && strlen($_POST['url']))
41    $aki_comm['comment_author_url'] = $_POST['url'];*/
42
43  $akismet = new Akismet(get_absolute_root_url(), $conf['akismet_api_key'], $aki_comm);
44
45  if( !$akismet->errorsExist() )
46  {
47    $counters = explode('/', $conf['akismet_counters']);
48    if ( $akismet->isSpam() )
49    {
50      $action = $conf['akismet_spam_action'];
51      if ('reject'==$action && !is_a_guest() && isset($_SESSION['csi']) && (!isset($_POST['url']) || strlen($_POST['url'])==0))
52        $action='moderate';
53      if ('reject'!=$action) set_status_header(403);
54      $counters[0]++;
55      $_POST['cr'][] = 'aki';
56    }
57    else
58    {
59      $_POST['cr'][] = 'aki-ok';
60      if (!isset($_SESSION['csi']) /*&& isset($_POST['url']) && strlen($_POST['url']) */)
61      {
62        $action = 'moderate';
63        $_POST['cr'][] = 'csi';
64      }
65    }
66    $counters[1]++;
67    $conf['akismet_counters'] = implode('/', $counters);
68    $query = 'UPDATE '.CONFIG_TABLE.' SET value="'.$conf['akismet_counters'].'" WHERE param="akismet_counters" LIMIT 1';
69    pwg_query($query);
70  }
71  else {
72    $_POST['cr'][] = 'aki-FAIL';
73    if (is_admin())
74      var_export( $akismet->getErrors() );
75  }
76
77  return $action;
78}
79
80?>
Note: See TracBrowser for help on using the repository browser.