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

Last change on this file since 31981 was 29181, checked in by rvelices, 10 years ago

aksimet 2.6.d csi is set earlier...

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