web/wp-content/plugins/akismet/akismet.php
author Anthony Ly <anthonyly.com@gmail.com>
Tue, 12 Mar 2013 18:21:39 +0100
changeset 206 919b4ddb13fa
parent 204 09a1c134465b
permissions -rw-r--r--
modification logo footer cccb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     1
<?php
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
     2
/**
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
     3
 * @package Akismet
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
     4
 */
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     5
/*
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     6
Plugin Name: Akismet
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
     7
Plugin URI: http://akismet.com/?return=true
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
     8
Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from comment and trackback spam</strong>. It keeps your site protected from spam even while you sleep. To get started: 1) Click the "Activate" link to the left of this description, 2) <a href="http://akismet.com/get/?return=true">Sign up for an Akismet API key</a>, and 3) Go to your Akismet configuration page, and save your API key.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
     9
Version: 2.5.7
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    10
Author: Automattic
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    11
Author URI: http://automattic.com/wordpress-plugins/
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    12
License: GPLv2 or later
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    13
*/
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    14
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    15
/*
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    16
This program is free software; you can redistribute it and/or
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    17
modify it under the terms of the GNU General Public License
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    18
as published by the Free Software Foundation; either version 2
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    19
of the License, or (at your option) any later version.
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    20
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    21
This program is distributed in the hope that it will be useful,
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    22
but WITHOUT ANY WARRANTY; without even the implied warranty of
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    23
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    24
GNU General Public License for more details.
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    25
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    26
You should have received a copy of the GNU General Public License
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    27
along with this program; if not, write to the Free Software
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    28
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    29
*/
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    30
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
    31
// Make sure we don't expose any info if called directly
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
    32
if ( !function_exists( 'add_action' ) ) {
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
    33
	echo 'Hi there!  I\'m just a plugin, not much I can do when called directly.';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
    34
	exit;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
    35
}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
    36
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
    37
define('AKISMET_VERSION', '2.5.7');
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    38
define('AKISMET_PLUGIN_URL', plugin_dir_url( __FILE__ ));
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    39
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    40
/** If you hardcode a WP.com API key here, all key config screens will be hidden */
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    41
if ( defined('WPCOM_API_KEY') )
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    42
	$wpcom_api_key = constant('WPCOM_API_KEY');
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    43
else
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    44
	$wpcom_api_key = '';
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    45
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    46
if ( isset($wp_db_version) && $wp_db_version <= 9872 )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    47
	include_once dirname( __FILE__ ) . '/legacy.php';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    48
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    49
include_once dirname( __FILE__ ) . '/widget.php';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    50
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    51
if ( is_admin() )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    52
	require_once dirname( __FILE__ ) . '/admin.php';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    53
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    54
function akismet_init() {
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    55
	global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    56
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    57
	if ( $wpcom_api_key )
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    58
		$akismet_api_host = $wpcom_api_key . '.rest.akismet.com';
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    59
	else
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    60
		$akismet_api_host = get_option('wordpress_api_key') . '.rest.akismet.com';
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    61
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    62
	$akismet_api_port = 80;
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    63
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    64
add_action('init', 'akismet_init');
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    65
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    66
function akismet_get_key() {
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    67
	global $wpcom_api_key;
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    68
	if ( !empty($wpcom_api_key) )
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    69
		return $wpcom_api_key;
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    70
	return get_option('wordpress_api_key');
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    71
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    72
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    73
function akismet_check_key_status( $key, $ip = null ) {
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    74
	global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    75
	$blog = urlencode( get_option('home') );
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    76
	if ( $wpcom_api_key )
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    77
		$key = $wpcom_api_key;
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    78
	$response = akismet_http_post("key=$key&blog=$blog", 'rest.akismet.com', '/1.1/verify-key', $akismet_api_port, $ip);
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    79
	return $response;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    80
}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    81
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    82
// given a response from an API call like akismet_check_key_status(), update the alert code options if an alert is present.
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    83
function akismet_update_alert( $response ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    84
	$code = $msg = null;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    85
	if ( isset($response[0]['x-akismet-alert-code']) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    86
		$code = $response[0]['x-akismet-alert-code'];
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    87
		$msg = $response[0]['x-akismet-alert-msg'];
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    88
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    89
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    90
	// only call update_option() if the value has changed
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    91
	if ( $code != get_option( 'akismet_alert_code' ) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    92
		update_option( 'akismet_alert_code', $code );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    93
		update_option( 'akismet_alert_msg', $msg );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    94
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    95
}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    96
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    97
function akismet_verify_key( $key, $ip = null ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    98
	$response = akismet_check_key_status( $key, $ip );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
    99
	akismet_update_alert( $response );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   100
	if ( !is_array($response) || !isset($response[1]) || $response[1] != 'valid' && $response[1] != 'invalid' )
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   101
		return 'failed';
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   102
	return $response[1];
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   103
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   104
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   105
// if we're in debug or test modes, use a reduced service level so as not to polute training or stats data
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   106
function akismet_test_mode() {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   107
	if ( defined('AKISMET_TEST_MODE') && AKISMET_TEST_MODE )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   108
		return true;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   109
	return false;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   110
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   111
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   112
// return a comma-separated list of role names for the given user
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   113
function akismet_get_user_roles( $user_id ) {
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   114
	$roles = false;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   115
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   116
	if ( !class_exists('WP_User') )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   117
		return false;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   118
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   119
	if ( $user_id > 0 ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   120
		$comment_user = new WP_User($user_id);
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   121
		if ( isset($comment_user->roles) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   122
			$roles = join(',', $comment_user->roles);
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   123
	}
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   124
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   125
	if ( is_multisite() && is_super_admin( $user_id ) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   126
		if ( empty( $roles ) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   127
			$roles = 'super_admin';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   128
		} else {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   129
			$comment_user->roles[] = 'super_admin';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   130
			$roles = join( ',', $comment_user->roles );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   131
		}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   132
	}
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   133
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   134
	return $roles;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   135
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   137
// Returns array with headers in $response[0] and body in $response[1]
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   138
function akismet_http_post($request, $host, $path, $port = 80, $ip=null) {
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   139
	global $wp_version;
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   140
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   141
	$akismet_ua = "WordPress/{$wp_version} | ";
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   142
	$akismet_ua .= 'Akismet/' . constant( 'AKISMET_VERSION' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   143
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   144
	$akismet_ua = apply_filters( 'akismet_ua', $akismet_ua );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   145
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   146
	$content_length = strlen( $request );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   147
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   148
	$http_host = $host;
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   149
	// use a specific IP if provided
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   150
	// needed by akismet_check_server_connectivity()
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   151
	if ( $ip && long2ip( ip2long( $ip ) ) ) {
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   152
		$http_host = $ip;
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   153
	} else {
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   154
		$http_host = $host;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   155
	}
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   156
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   157
	// use the WP HTTP class if it is available
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   158
	if ( function_exists( 'wp_remote_post' ) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   159
		$http_args = array(
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   160
			'body'			=> $request,
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   161
			'headers'		=> array(
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   162
				'Content-Type'	=> 'application/x-www-form-urlencoded; ' .
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   163
									'charset=' . get_option( 'blog_charset' ),
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   164
				'Host'			=> $host,
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   165
				'User-Agent'	=> $akismet_ua
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   166
			),
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   167
			'httpversion'	=> '1.0',
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   168
			'timeout'		=> 15
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   169
		);
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   170
		$akismet_url = "http://{$http_host}{$path}";
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   171
		$response = wp_remote_post( $akismet_url, $http_args );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   172
		if ( is_wp_error( $response ) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   173
			return '';
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   174
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   175
		return array( $response['headers'], $response['body'] );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   176
	} else {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   177
		$http_request  = "POST $path HTTP/1.0\r\n";
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   178
		$http_request .= "Host: $host\r\n";
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   179
		$http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n";
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   180
		$http_request .= "Content-Length: {$content_length}\r\n";
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   181
		$http_request .= "User-Agent: {$akismet_ua}\r\n";
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   182
		$http_request .= "\r\n";
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   183
		$http_request .= $request;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   184
		
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   185
		$response = '';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   186
		if( false != ( $fs = @fsockopen( $http_host, $port, $errno, $errstr, 10 ) ) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   187
			fwrite( $fs, $http_request );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   188
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   189
			while ( !feof( $fs ) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   190
				$response .= fgets( $fs, 1160 ); // One TCP-IP packet
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   191
			fclose( $fs );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   192
			$response = explode( "\r\n\r\n", $response, 2 );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   193
		}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   194
		return $response;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   195
	}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   196
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   197
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   198
// filter handler used to return a spam result to pre_comment_approved
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   199
function akismet_result_spam( $approved ) {
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   200
	// bump the counter here instead of when the filter is added to reduce the possibility of overcounting
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   201
	if ( $incr = apply_filters('akismet_spam_count_incr', 1) )
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   202
		update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   203
	// this is a one-shot deal
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   204
	remove_filter( 'pre_comment_approved', 'akismet_result_spam' );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   205
	return 'spam';
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   206
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   207
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   208
function akismet_result_hold( $approved ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   209
	// once only
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   210
	remove_filter( 'pre_comment_approved', 'akismet_result_hold' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   211
	return '0';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   212
}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   213
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   214
// how many approved comments does this author have?
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   215
function akismet_get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   216
	global $wpdb;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   217
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   218
	if ( !empty($user_id) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   219
		return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE user_id = %d AND comment_approved = 1", $user_id ) );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   220
		
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   221
	if ( !empty($comment_author_email) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   222
		return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_author_email = %s AND comment_author = %s AND comment_author_url = %s AND comment_approved = 1", $comment_author_email, $comment_author, $comment_author_url ) );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   223
		
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   224
	return 0;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   225
}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   226
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   227
function akismet_microtime() {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   228
	$mtime = explode( ' ', microtime() );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   229
	return $mtime[1] + $mtime[0];
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   230
}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   231
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   232
// log an event for a given comment, storing it in comment_meta
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   233
function akismet_update_comment_history( $comment_id, $message, $event=null ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   234
	global $current_user;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   235
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   236
	// failsafe for old WP versions
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   237
	if ( !function_exists('add_comment_meta') )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   238
		return false;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   239
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   240
	$user = '';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   241
	if ( is_object($current_user) && isset($current_user->user_login) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   242
		$user = $current_user->user_login;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   243
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   244
	$event = array(
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   245
		'time' => akismet_microtime(),
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   246
		'message' => $message,
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   247
		'event' => $event,
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   248
		'user' => $user,
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   249
	);
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   250
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   251
	// $unique = false so as to allow multiple values per comment
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   252
	$r = add_comment_meta( $comment_id, 'akismet_history', $event, false );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   253
}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   254
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   255
// get the full comment history for a given comment, as an array in reverse chronological order
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   256
function akismet_get_comment_history( $comment_id ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   257
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   258
	// failsafe for old WP versions
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   259
	if ( !function_exists('add_comment_meta') )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   260
		return false;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   261
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   262
	$history = get_comment_meta( $comment_id, 'akismet_history', false );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   263
	usort( $history, 'akismet_cmp_time' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   264
	return $history;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   265
}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   266
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   267
function akismet_cmp_time( $a, $b ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   268
	return $a['time'] > $b['time'] ? -1 : 1;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   269
}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   270
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   271
// this fires on wp_insert_comment.  we can't update comment_meta when akismet_auto_check_comment() runs
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   272
// because we don't know the comment ID at that point.
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   273
function akismet_auto_check_update_meta( $id, $comment ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   274
	global $akismet_last_comment;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   275
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   276
	// failsafe for old WP versions
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   277
	if ( !function_exists('add_comment_meta') )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   278
		return false;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   279
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   280
	if ( !isset( $akismet_last_comment['comment_author_email'] ) )
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   281
		$akismet_last_comment['comment_author_email'] = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   282
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   283
	// wp_insert_comment() might be called in other contexts, so make sure this is the same comment
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   284
	// as was checked by akismet_auto_check_comment
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   285
	if ( is_object($comment) && !empty($akismet_last_comment) && is_array($akismet_last_comment) ) {
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   286
		if ( isset($akismet_last_comment['comment_post_ID']) && intval($akismet_last_comment['comment_post_ID']) == intval($comment->comment_post_ID)
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   287
			&& $akismet_last_comment['comment_author'] == $comment->comment_author
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   288
			&& $akismet_last_comment['comment_author_email'] == $comment->comment_author_email ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   289
				// normal result: true or false
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   290
				if ( $akismet_last_comment['akismet_result'] == 'true' ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   291
					update_comment_meta( $comment->comment_ID, 'akismet_result', 'true' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   292
					akismet_update_comment_history( $comment->comment_ID, __('Akismet caught this comment as spam'), 'check-spam' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   293
					if ( $comment->comment_approved != 'spam' )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   294
						akismet_update_comment_history( $comment->comment_ID, sprintf( __('Comment status was changed to %s'), $comment->comment_approved), 'status-changed'.$comment->comment_approved );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   295
				} elseif ( $akismet_last_comment['akismet_result'] == 'false' ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   296
					update_comment_meta( $comment->comment_ID, 'akismet_result', 'false' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   297
					akismet_update_comment_history( $comment->comment_ID, __('Akismet cleared this comment'), 'check-ham' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   298
					if ( $comment->comment_approved == 'spam' ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   299
						if ( wp_blacklist_check($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   300
							akismet_update_comment_history( $comment->comment_ID, __('Comment was caught by wp_blacklist_check'), 'wp-blacklisted' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   301
						else
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   302
							akismet_update_comment_history( $comment->comment_ID, sprintf( __('Comment status was changed to %s'), $comment->comment_approved), 'status-changed-'.$comment->comment_approved );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   303
					}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   304
				// abnormal result: error
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   305
				} else {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   306
					update_comment_meta( $comment->comment_ID, 'akismet_error', time() );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   307
					akismet_update_comment_history( $comment->comment_ID, sprintf( __('Akismet was unable to check this comment (response: %s), will automatically retry again later.'), substr($akismet_last_comment['akismet_result'], 0, 50)), 'check-error' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   308
				}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   309
				
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   310
				// record the complete original data as submitted for checking
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   311
				if ( isset($akismet_last_comment['comment_as_submitted']) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   312
					update_comment_meta( $comment->comment_ID, 'akismet_as_submitted', $akismet_last_comment['comment_as_submitted'] );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   313
		}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   314
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   315
}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   316
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   317
add_action( 'wp_insert_comment', 'akismet_auto_check_update_meta', 10, 2 );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   318
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   319
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   320
function akismet_auto_check_comment( $commentdata ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   321
	global $akismet_api_host, $akismet_api_port, $akismet_last_comment;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   322
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   323
	$comment = $commentdata;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   324
	$comment['user_ip']    = $_SERVER['REMOTE_ADDR'];
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   325
	$comment['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; 
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   326
	$comment['referrer']   = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   327
	$comment['blog']       = get_option('home');
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   328
	$comment['blog_lang']  = get_locale();
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   329
	$comment['blog_charset'] = get_option('blog_charset');
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   330
	$comment['permalink']  = get_permalink($comment['comment_post_ID']);
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   331
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   332
	if ( !empty( $comment['user_ID'] ) ) {
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   333
		$comment['user_role'] = akismet_get_user_roles( $comment['user_ID'] );
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   334
	}
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   335
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   336
	$akismet_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   337
	$comment['akismet_comment_nonce'] = 'inactive';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   338
	if ( $akismet_nonce_option == 'true' || $akismet_nonce_option == '' ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   339
		$comment['akismet_comment_nonce'] = 'failed';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   340
		if ( isset( $_POST['akismet_comment_nonce'] ) && wp_verify_nonce( $_POST['akismet_comment_nonce'], 'akismet_comment_nonce_' . $comment['comment_post_ID'] ) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   341
			$comment['akismet_comment_nonce'] = 'passed';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   342
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   343
		// comment reply in wp-admin
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   344
		if ( isset( $_POST['_ajax_nonce-replyto-comment'] ) && check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   345
			$comment['akismet_comment_nonce'] = 'passed';
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   346
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   347
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   348
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   349
	if ( akismet_test_mode() )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   350
		$comment['is_test'] = 'true';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   351
		
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   352
	foreach ($_POST as $key => $value ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   353
		if ( is_string($value) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   354
			$comment["POST_{$key}"] = $value;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   355
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   356
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   357
	$ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   358
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   359
	foreach ( $_SERVER as $key => $value ) {
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   360
		if ( !in_array( $key, $ignore ) && is_string($value) )
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   361
			$comment["$key"] = $value;
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   362
		else
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   363
			$comment["$key"] = '';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   364
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   365
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   366
	$post = get_post( $comment['comment_post_ID'] );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   367
	$comment[ 'comment_post_modified_gmt' ] = $post->post_modified_gmt;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   368
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   369
	$query_string = '';
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   370
	foreach ( $comment as $key => $data )
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   371
		$query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   372
		
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   373
	$commentdata['comment_as_submitted'] = $comment;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   374
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   375
	$response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   376
	do_action( 'akismet_comment_check_response', $response );
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   377
	akismet_update_alert( $response );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   378
	$commentdata['akismet_result'] = $response[1];
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   379
	if ( 'true' == $response[1] ) {
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   380
		// akismet_spam_count will be incremented later by akismet_result_spam()
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   381
		add_filter('pre_comment_approved', 'akismet_result_spam');
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   382
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   383
		do_action( 'akismet_spam_caught' );
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   384
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   385
		$last_updated = strtotime( $post->post_modified_gmt );
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   386
		$diff = time() - $last_updated;
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   387
		$diff = $diff / 86400;
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   388
		
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   389
		if ( $post->post_type == 'post' && $diff > 30 && get_option( 'akismet_discard_month' ) == 'true' && empty($comment['user_ID']) ) {
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   390
			// akismet_result_spam() won't be called so bump the counter here
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   391
			if ( $incr = apply_filters('akismet_spam_count_incr', 1) )
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   392
				update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   393
			$redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : get_permalink( $post );
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   394
			wp_safe_redirect( $redirect_to );
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   395
			die();
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   396
		}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   397
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   398
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   399
	// if the response is neither true nor false, hold the comment for moderation and schedule a recheck
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   400
	if ( 'true' != $response[1] && 'false' != $response[1] ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   401
		if ( !current_user_can('moderate_comments') ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   402
			add_filter('pre_comment_approved', 'akismet_result_hold');
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   403
		}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   404
		if ( !wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   405
			wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   406
		}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   407
	}
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   408
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   409
	if ( function_exists('wp_next_scheduled') && function_exists('wp_schedule_event') ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   410
		// WP 2.1+: delete old comments daily
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   411
		if ( !wp_next_scheduled('akismet_scheduled_delete') )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   412
			wp_schedule_event(time(), 'daily', 'akismet_scheduled_delete');
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   413
	} elseif ( (mt_rand(1, 10) == 3) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   414
		// WP 2.0: run this one time in ten
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   415
		akismet_delete_old();
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   416
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   417
	$akismet_last_comment = $commentdata;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   418
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   419
	akismet_fix_scheduled_recheck();
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   420
	return $commentdata;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   421
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   422
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   423
add_action('preprocess_comment', 'akismet_auto_check_comment', 1);
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   424
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   425
function akismet_delete_old() {
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   426
	global $wpdb;
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   427
	$now_gmt = current_time('mysql', 1);
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   428
	$comment_ids = $wpdb->get_col("SELECT comment_id FROM $wpdb->comments WHERE DATE_SUB('$now_gmt', INTERVAL 15 DAY) > comment_date_gmt AND comment_approved = 'spam'");
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   429
	if ( empty( $comment_ids ) )
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   430
		return;
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   431
		
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   432
	$comma_comment_ids = implode( ', ', array_map('intval', $comment_ids) );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   433
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   434
	do_action( 'delete_comment', $comment_ids );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   435
	$wpdb->query("DELETE FROM $wpdb->comments WHERE comment_id IN ( $comma_comment_ids )");
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   436
	$wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id IN ( $comma_comment_ids )");
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   437
	clean_comment_cache( $comment_ids );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   438
	$n = mt_rand(1, 5000);
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   439
	if ( apply_filters('akismet_optimize_table', ($n == 11)) ) // lucky number
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   440
		$wpdb->query("OPTIMIZE TABLE $wpdb->comments");
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   441
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   442
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   443
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   444
function akismet_delete_old_metadata() { 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   445
	global $wpdb; 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   446
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   447
	$now_gmt = current_time( 'mysql', 1 ); 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   448
	$interval = apply_filters( 'akismet_delete_commentmeta_interval', 15 );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   449
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   450
	# enfore a minimum of 1 day
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   451
	$interval = absint( $interval );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   452
	if ( $interval < 1 ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   453
		return;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   454
	}
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   455
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   456
	// akismet_as_submitted meta values are large, so expire them 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   457
	// after $interval days regardless of the comment status 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   458
	while ( TRUE ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   459
		$comment_ids = $wpdb->get_col( "SELECT $wpdb->comments.comment_id FROM $wpdb->commentmeta INNER JOIN $wpdb->comments USING(comment_id) WHERE meta_key = 'akismet_as_submitted' AND DATE_SUB('$now_gmt', INTERVAL {$interval} DAY) > comment_date_gmt LIMIT 10000" ); 
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   460
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   461
		if ( empty( $comment_ids ) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   462
			return; 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   463
		}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   464
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   465
		foreach ( $comment_ids as $comment_id ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   466
			delete_comment_meta( $comment_id, 'akismet_as_submitted' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   467
		}
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   468
	}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   469
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   470
	/*
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   471
	$n = mt_rand( 1, 5000 ); 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   472
	if ( apply_filters( 'akismet_optimize_table', ( $n == 11 ), 'commentmeta' ) ) { // lucky number 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   473
		$wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" ); 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   474
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   475
	*/
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   476
} 
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   477
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   478
add_action('akismet_scheduled_delete', 'akismet_delete_old');
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   479
add_action('akismet_scheduled_delete', 'akismet_delete_old_metadata'); 
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   480
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   481
function akismet_check_db_comment( $id, $recheck_reason = 'recheck_queue' ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   482
    global $wpdb, $akismet_api_host, $akismet_api_port;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   483
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   484
    $id = (int) $id;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   485
    $c = $wpdb->get_row( "SELECT * FROM $wpdb->comments WHERE comment_ID = '$id'", ARRAY_A );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   486
    if ( !$c )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   487
        return;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   488
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   489
    $c['user_ip']    = $c['comment_author_IP'];
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   490
    $c['user_agent'] = $c['comment_agent'];
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   491
    $c['referrer']   = '';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   492
    $c['blog']       = get_option('home');
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   493
    $c['blog_lang']  = get_locale();
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   494
    $c['blog_charset'] = get_option('blog_charset');
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   495
    $c['permalink']  = get_permalink($c['comment_post_ID']);
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   496
    $id = $c['comment_ID'];
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   497
	if ( akismet_test_mode() )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   498
		$c['is_test'] = 'true';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   499
	$c['recheck_reason'] = $recheck_reason;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   500
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   501
    $query_string = '';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   502
    foreach ( $c as $key => $data )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   503
    $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   504
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   505
    $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   506
    return ( is_array( $response ) && isset( $response[1] ) ) ? $response[1] : false;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   507
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   508
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   509
function akismet_cron_recheck() {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   510
	global $wpdb;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   511
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   512
	$status = akismet_verify_key( akismet_get_key() );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   513
	if ( get_option( 'akismet_alert_code' ) || $status == 'invalid' ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   514
		// since there is currently a problem with the key, reschedule a check for 6 hours hence
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   515
		wp_schedule_single_event( time() + 21600, 'akismet_schedule_cron_recheck' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   516
		return false;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   517
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   518
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   519
	delete_option('akismet_available_servers');
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   520
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   521
	$comment_errors = $wpdb->get_col( "
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   522
		SELECT comment_id
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   523
		FROM {$wpdb->prefix}commentmeta
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   524
		WHERE meta_key = 'akismet_error'
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   525
		LIMIT 100
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   526
	" );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   527
	
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   528
	foreach ( (array) $comment_errors as $comment_id ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   529
		// if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   530
		$comment = get_comment( $comment_id );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   531
		if ( !$comment || strtotime( $comment->comment_date_gmt ) < strtotime( "-15 days" ) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   532
			delete_comment_meta( $comment_id, 'akismet_error' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   533
			continue;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   534
		}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   535
		
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   536
		add_comment_meta( $comment_id, 'akismet_rechecking', true );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   537
		$status = akismet_check_db_comment( $comment_id, 'retry' );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   538
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   539
		$msg = '';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   540
		if ( $status == 'true' ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   541
			$msg = __( 'Akismet caught this comment as spam during an automatic retry.' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   542
		} elseif ( $status == 'false' ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   543
			$msg = __( 'Akismet cleared this comment during an automatic retry.' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   544
		}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   545
		
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   546
		// If we got back a legit response then update the comment history
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   547
		// other wise just bail now and try again later.  No point in
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   548
		// re-trying all the comments once we hit one failure.
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   549
		if ( !empty( $msg ) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   550
			delete_comment_meta( $comment_id, 'akismet_error' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   551
			akismet_update_comment_history( $comment_id, $msg, 'cron-retry' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   552
			update_comment_meta( $comment_id, 'akismet_result', $status );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   553
			// make sure the comment status is still pending.  if it isn't, that means the user has already moved it elsewhere.
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   554
			$comment = get_comment( $comment_id );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   555
			if ( $comment && 'unapproved' == wp_get_comment_status( $comment_id ) ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   556
				if ( $status == 'true' ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   557
					wp_spam_comment( $comment_id );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   558
				} elseif ( $status == 'false' ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   559
					// comment is good, but it's still in the pending queue.  depending on the moderation settings
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   560
					// we may need to change it to approved.
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   561
					if ( check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type) )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   562
						wp_set_comment_status( $comment_id, 1 );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   563
				}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   564
			}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   565
		} else {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   566
			delete_comment_meta( $comment_id, 'akismet_rechecking' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   567
			wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   568
			return;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   569
		}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   570
		delete_comment_meta( $comment_id, 'akismet_rechecking' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   571
	}
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   572
	
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents: 194
diff changeset
   573
	$remaining = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" );
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   574
	if ( $remaining && !wp_next_scheduled('akismet_schedule_cron_recheck') ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   575
		wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   576
	}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   577
}
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   578
add_action( 'akismet_schedule_cron_recheck', 'akismet_cron_recheck' );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   579
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   580
function akismet_add_comment_nonce( $post_id ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   581
	echo '<p style="display: none;">';
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   582
	wp_nonce_field( 'akismet_comment_nonce_' . $post_id, 'akismet_comment_nonce', FALSE );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   583
	echo '</p>';
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   584
}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   585
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   586
$akismet_comment_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   587
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   588
if ( $akismet_comment_nonce_option == 'true' || $akismet_comment_nonce_option == '' )
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   589
	add_action( 'comment_form', 'akismet_add_comment_nonce' );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   590
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   591
global $wp_version;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   592
if ( '3.0.5' == $wp_version ) { 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   593
	remove_filter( 'comment_text', 'wp_kses_data' ); 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   594
	if ( is_admin() ) 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   595
		add_filter( 'comment_text', 'wp_kses_post' ); 
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   596
}
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   597
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   598
function akismet_fix_scheduled_recheck() {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   599
	$future_check = wp_next_scheduled( 'akismet_schedule_cron_recheck' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   600
	if ( !$future_check ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   601
		return;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   602
	}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   603
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   604
	if ( get_option( 'akismet_alert_code' ) > 0 ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   605
		return;
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   606
	}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   607
194
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   608
	$check_range = time() + 1200;
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   609
	if ( $future_check > $check_range ) {
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   610
		wp_clear_scheduled_hook( 'akismet_schedule_cron_recheck' );
32102edaa81b MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents: 136
diff changeset
   611
		wp_schedule_single_event( time() + 300, 'akismet_schedule_cron_recheck' );
136
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   612
	}
bde1974c263b merge from wordpress
ymh@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   613
}