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

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

aksimet 2.6.c if aksimet says ok, but csi image missing then reject comment

  • 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  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        if (!isset($_SESSION['csi']))
44        {
45                $_POST['cr'][] = 'csi';
46        }
47
48  $akismet = new Akismet(get_absolute_root_url(), $conf['akismet_api_key'], $aki_comm);
49
50  if( !$akismet->errorsExist() )
51  {
52    $counters = explode('/', $conf['akismet_counters']);
53    if ( $akismet->isSpam() )
54    {
55      $action = $conf['akismet_spam_action'];
56      if ('reject'==$action && !is_a_guest() && isset($_SESSION['csi']) && (!isset($_POST['url']) || strlen($_POST['url'])==0))
57        $action='moderate';
58      $counters[0]++;
59      $_POST['cr'][] = 'aki';
60                        if ('reject'!=$action)
61                                set_status_header(403);
62    }
63    else
64    {
65      $_POST['cr'][] = 'aki-ok';
66      if (!isset($_SESSION['csi']) /*&& isset($_POST['url']) && strlen($_POST['url']) */)
67      {
68        $action = $conf['akismet_spam_action'];
69      }
70    }
71    $counters[1]++;
72    $conf['akismet_counters'] = implode('/', $counters);
73    $query = 'UPDATE '.CONFIG_TABLE.' SET value="'.$conf['akismet_counters'].'" WHERE param="akismet_counters" LIMIT 1';
74    pwg_query($query);
75  }
76  else {
77    $_POST['cr'][] = 'aki-FAIL';
78    if (is_admin())
79      var_export( $akismet->getErrors() );
80  }
81
82  return $action;
83}
84
85?>
Note: See TracBrowser for help on using the repository browser.