3 * @package Akismet |
3 * @package Akismet |
4 */ |
4 */ |
5 /* |
5 /* |
6 Plugin Name: Akismet |
6 Plugin Name: Akismet |
7 Plugin URI: http://akismet.com/?return=true |
7 Plugin URI: http://akismet.com/?return=true |
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 <a href="admin.php?page=akismet-key-config">Akismet configuration</a> page, and save your API key. |
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. |
9 Version: 2.5.6 |
9 Version: 2.5.7 |
10 Author: Automattic |
10 Author: Automattic |
11 Author URI: http://automattic.com/wordpress-plugins/ |
11 Author URI: http://automattic.com/wordpress-plugins/ |
12 License: GPLv2 or later |
12 License: GPLv2 or later |
13 */ |
13 */ |
14 |
14 |
26 You should have received a copy of the GNU General Public License |
26 You should have received a copy of the GNU General Public License |
27 along with this program; if not, write to the Free Software |
27 along with this program; if not, write to the Free Software |
28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
29 */ |
29 */ |
30 |
30 |
31 define('AKISMET_VERSION', '2.5.6'); |
31 // Make sure we don't expose any info if called directly |
|
32 if ( !function_exists( 'add_action' ) ) { |
|
33 echo 'Hi there! I\'m just a plugin, not much I can do when called directly.'; |
|
34 exit; |
|
35 } |
|
36 |
|
37 define('AKISMET_VERSION', '2.5.7'); |
32 define('AKISMET_PLUGIN_URL', plugin_dir_url( __FILE__ )); |
38 define('AKISMET_PLUGIN_URL', plugin_dir_url( __FILE__ )); |
33 |
39 |
34 /** If you hardcode a WP.com API key here, all key config screens will be hidden */ |
40 /** If you hardcode a WP.com API key here, all key config screens will be hidden */ |
35 if ( defined('WPCOM_API_KEY') ) |
41 if ( defined('WPCOM_API_KEY') ) |
36 $wpcom_api_key = constant('WPCOM_API_KEY'); |
42 $wpcom_api_key = constant('WPCOM_API_KEY'); |
37 else |
43 else |
38 $wpcom_api_key = ''; |
44 $wpcom_api_key = ''; |
39 |
|
40 // Make sure we don't expose any info if called directly |
|
41 if ( !function_exists( 'add_action' ) ) { |
|
42 echo "Hi there! I'm just a plugin, not much I can do when called directly."; |
|
43 exit; |
|
44 } |
|
45 |
45 |
46 if ( isset($wp_db_version) && $wp_db_version <= 9872 ) |
46 if ( isset($wp_db_version) && $wp_db_version <= 9872 ) |
47 include_once dirname( __FILE__ ) . '/legacy.php'; |
47 include_once dirname( __FILE__ ) . '/legacy.php'; |
48 |
48 |
49 include_once dirname( __FILE__ ) . '/widget.php'; |
49 include_once dirname( __FILE__ ) . '/widget.php'; |
275 |
275 |
276 // failsafe for old WP versions |
276 // failsafe for old WP versions |
277 if ( !function_exists('add_comment_meta') ) |
277 if ( !function_exists('add_comment_meta') ) |
278 return false; |
278 return false; |
279 |
279 |
|
280 if ( !isset( $akismet_last_comment['comment_author_email'] ) ) |
|
281 $akismet_last_comment['comment_author_email'] = ''; |
|
282 |
280 // wp_insert_comment() might be called in other contexts, so make sure this is the same comment |
283 // wp_insert_comment() might be called in other contexts, so make sure this is the same comment |
281 // as was checked by akismet_auto_check_comment |
284 // as was checked by akismet_auto_check_comment |
282 if ( is_object($comment) && !empty($akismet_last_comment) && is_array($akismet_last_comment) ) { |
285 if ( is_object($comment) && !empty($akismet_last_comment) && is_array($akismet_last_comment) ) { |
283 if ( intval($akismet_last_comment['comment_post_ID']) == intval($comment->comment_post_ID) |
286 if ( isset($akismet_last_comment['comment_post_ID']) && intval($akismet_last_comment['comment_post_ID']) == intval($comment->comment_post_ID) |
284 && $akismet_last_comment['comment_author'] == $comment->comment_author |
287 && $akismet_last_comment['comment_author'] == $comment->comment_author |
285 && $akismet_last_comment['comment_author_email'] == $comment->comment_author_email ) { |
288 && $akismet_last_comment['comment_author_email'] == $comment->comment_author_email ) { |
286 // normal result: true or false |
289 // normal result: true or false |
287 if ( $akismet_last_comment['akismet_result'] == 'true' ) { |
290 if ( $akismet_last_comment['akismet_result'] == 'true' ) { |
288 update_comment_meta( $comment->comment_ID, 'akismet_result', 'true' ); |
291 update_comment_meta( $comment->comment_ID, 'akismet_result', 'true' ); |
317 function akismet_auto_check_comment( $commentdata ) { |
320 function akismet_auto_check_comment( $commentdata ) { |
318 global $akismet_api_host, $akismet_api_port, $akismet_last_comment; |
321 global $akismet_api_host, $akismet_api_port, $akismet_last_comment; |
319 |
322 |
320 $comment = $commentdata; |
323 $comment = $commentdata; |
321 $comment['user_ip'] = $_SERVER['REMOTE_ADDR']; |
324 $comment['user_ip'] = $_SERVER['REMOTE_ADDR']; |
322 $comment['user_agent'] = $_SERVER['HTTP_USER_AGENT']; |
325 $comment['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; |
323 $comment['referrer'] = $_SERVER['HTTP_REFERER']; |
326 $comment['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; |
324 $comment['blog'] = get_option('home'); |
327 $comment['blog'] = get_option('home'); |
325 $comment['blog_lang'] = get_locale(); |
328 $comment['blog_lang'] = get_locale(); |
326 $comment['blog_charset'] = get_option('blog_charset'); |
329 $comment['blog_charset'] = get_option('blog_charset'); |
327 $comment['permalink'] = get_permalink($comment['comment_post_ID']); |
330 $comment['permalink'] = get_permalink($comment['comment_post_ID']); |
328 |
331 |
329 if ( !empty( $comment['user_ID'] ) ) { |
332 if ( !empty( $comment['user_ID'] ) ) { |
330 $comment['user_role'] = akismet_get_user_roles($comment['user_ID']); |
333 $comment['user_role'] = akismet_get_user_roles( $comment['user_ID'] ); |
331 } |
334 } |
332 |
335 |
333 $akismet_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) ); |
336 $akismet_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) ); |
334 $comment['akismet_comment_nonce'] = 'inactive'; |
337 $comment['akismet_comment_nonce'] = 'inactive'; |
335 if ( $akismet_nonce_option == 'true' || $akismet_nonce_option == '' ) { |
338 if ( $akismet_nonce_option == 'true' || $akismet_nonce_option == '' ) { |
368 $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&'; |
371 $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&'; |
369 |
372 |
370 $commentdata['comment_as_submitted'] = $comment; |
373 $commentdata['comment_as_submitted'] = $comment; |
371 |
374 |
372 $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); |
375 $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); |
|
376 do_action( 'akismet_comment_check_response', $response ); |
373 akismet_update_alert( $response ); |
377 akismet_update_alert( $response ); |
374 $commentdata['akismet_result'] = $response[1]; |
378 $commentdata['akismet_result'] = $response[1]; |
375 if ( 'true' == $response[1] ) { |
379 if ( 'true' == $response[1] ) { |
376 // akismet_spam_count will be incremented later by akismet_result_spam() |
380 // akismet_spam_count will be incremented later by akismet_result_spam() |
377 add_filter('pre_comment_approved', 'akismet_result_spam'); |
381 add_filter('pre_comment_approved', 'akismet_result_spam'); |
384 |
388 |
385 if ( $post->post_type == 'post' && $diff > 30 && get_option( 'akismet_discard_month' ) == 'true' && empty($comment['user_ID']) ) { |
389 if ( $post->post_type == 'post' && $diff > 30 && get_option( 'akismet_discard_month' ) == 'true' && empty($comment['user_ID']) ) { |
386 // akismet_result_spam() won't be called so bump the counter here |
390 // akismet_result_spam() won't be called so bump the counter here |
387 if ( $incr = apply_filters('akismet_spam_count_incr', 1) ) |
391 if ( $incr = apply_filters('akismet_spam_count_incr', 1) ) |
388 update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr ); |
392 update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr ); |
389 wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
393 $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : get_permalink( $post ); |
|
394 wp_safe_redirect( $redirect_to ); |
390 die(); |
395 die(); |
391 } |
396 } |
392 } |
397 } |
393 |
398 |
394 // if the response is neither true nor false, hold the comment for moderation and schedule a recheck |
399 // if the response is neither true nor false, hold the comment for moderation and schedule a recheck |
496 $query_string = ''; |
501 $query_string = ''; |
497 foreach ( $c as $key => $data ) |
502 foreach ( $c as $key => $data ) |
498 $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&'; |
503 $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&'; |
499 |
504 |
500 $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); |
505 $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); |
501 return $response[1]; |
506 return ( is_array( $response ) && isset( $response[1] ) ) ? $response[1] : false; |
502 } |
507 } |
503 |
508 |
504 function akismet_cron_recheck() { |
509 function akismet_cron_recheck() { |
505 global $wpdb; |
510 global $wpdb; |
506 |
511 |
563 return; |
568 return; |
564 } |
569 } |
565 delete_comment_meta( $comment_id, 'akismet_rechecking' ); |
570 delete_comment_meta( $comment_id, 'akismet_rechecking' ); |
566 } |
571 } |
567 |
572 |
568 $remaining = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ) ); |
573 $remaining = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ); |
569 if ( $remaining && !wp_next_scheduled('akismet_schedule_cron_recheck') ) { |
574 if ( $remaining && !wp_next_scheduled('akismet_schedule_cron_recheck') ) { |
570 wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' ); |
575 wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' ); |
571 } |
576 } |
572 } |
577 } |
573 add_action( 'akismet_schedule_cron_recheck', 'akismet_cron_recheck' ); |
578 add_action( 'akismet_schedule_cron_recheck', 'akismet_cron_recheck' ); |