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

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

akismet for piwigo 2.5

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 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    'comment_author_url' => $comment['website_url'],
21    'comment_author_email' => $comment['email'],
22    'permalink' => $url,
23    'referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',
24  );
25  /*if (isset($_POST['url']) && strlen($_POST['url']))
26    $aki_comm['comment_author_url'] = $_POST['url'];*/
27
28  $akismet = new Akismet(get_absolute_root_url(), $conf['akismet_api_key'], $aki_comm);
29
30  if( !$akismet->errorsExist() )
31  {
32    $counters = explode('/', $conf['akismet_counters']);
33    if ( $akismet->isSpam() )
34    {
35      $action = $conf['akismet_spam_action'];
36      if ('reject'==$action && !is_a_guest() && isset($_SESSION['csi']) && (!isset($_POST['url']) || strlen($_POST['url'])==0))
37        $action='moderate';
38      if ('reject'!=$action) set_status_header(403);
39      $counters[0]++;
40      $_POST['cr'][] = 'aki';
41    }
42    else
43    {
44      $_POST['cr'][] = 'aki-ok';
45      if (!isset($_SESSION['csi']) /*&& isset($_POST['url']) && strlen($_POST['url']) */)
46      {
47        $action = 'moderate';
48        $_POST['cr'][] = 'csi';
49      }
50    }
51    $counters[1]++;
52    $conf['akismet_counters'] = implode('/', $counters);
53    $query = 'UPDATE '.CONFIG_TABLE.' SET value="'.$conf['akismet_counters'].'" WHERE param="akismet_counters" LIMIT 1';
54    pwg_query($query);
55  }
56  else {
57    $_POST['cr'][] = 'aki-FAIL';
58    if (is_admin())
59      var_export( $akismet->getErrors() );
60  }
61
62  return $action;
63}
64
65?>
Note: See TracBrowser for help on using the repository browser.