function akismet_auto_check_comment($commentdata) { global $akismet_api_host, $akismet_api_port, $akismet_last_comment; $comment = $commentdata; $comment['user_ip'] = $_SERVER['REMOTE_ADDR']; $comment['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; $comment['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; $comment['blog'] = get_option('home'); $comment['blog_lang'] = get_locale(); $comment['blog_charset'] = get_option('blog_charset'); $comment['permalink'] = get_permalink($comment['comment_post_ID']); if (!empty($comment['user_ID'])) { $comment['user_role'] = akismet_get_user_roles($comment['user_ID']); } $akismet_nonce_option = apply_filters('akismet_comment_nonce', get_option('akismet_comment_nonce')); $comment['akismet_comment_nonce'] = 'inactive'; if ($akismet_nonce_option == 'true' || $akismet_nonce_option == '') { $comment['akismet_comment_nonce'] = 'failed'; if (isset($_POST['akismet_comment_nonce']) && wp_verify_nonce($_POST['akismet_comment_nonce'], 'akismet_comment_nonce_' . $comment['comment_post_ID'])) { $comment['akismet_comment_nonce'] = 'passed'; } // comment reply in wp-admin if (isset($_POST['_ajax_nonce-replyto-comment']) && check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment')) { $comment['akismet_comment_nonce'] = 'passed'; } } if (akismet_test_mode()) { $comment['is_test'] = 'true'; } foreach ($_POST as $key => $value) { if (is_string($value)) { $comment["POST_{$key}"] = $value; } } $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'); foreach ($_SERVER as $key => $value) { if (!in_array($key, $ignore) && is_string($value)) { $comment["{$key}"] = $value; } else { $comment["{$key}"] = ''; } } $post = get_post($comment['comment_post_ID']); $comment['comment_post_modified_gmt'] = $post->post_modified_gmt; $query_string = ''; foreach ($comment as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&'; } $commentdata['comment_as_submitted'] = $comment; $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); do_action('akismet_comment_check_response', $response); akismet_update_alert($response); $commentdata['akismet_result'] = $response[1]; if ('true' == $response[1]) { // akismet_spam_count will be incremented later by akismet_result_spam() add_filter('pre_comment_approved', 'akismet_result_spam'); do_action('akismet_spam_caught'); $last_updated = strtotime($post->post_modified_gmt); $diff = time() - $last_updated; $diff = $diff / 86400; if ($post->post_type == 'post' && $diff > 30 && get_option('akismet_discard_month') == 'true' && empty($comment['user_ID'])) { // akismet_result_spam() won't be called so bump the counter here if ($incr = apply_filters('akismet_spam_count_incr', 1)) { update_option('akismet_spam_count', get_option('akismet_spam_count') + $incr); } $redirect_to = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : get_permalink($post); wp_safe_redirect($redirect_to); die; } } // if the response is neither true nor false, hold the comment for moderation and schedule a recheck if ('true' != $response[1] && 'false' != $response[1]) { if (!current_user_can('moderate_comments')) { add_filter('pre_comment_approved', 'akismet_result_hold'); } if (!wp_next_scheduled('akismet_schedule_cron_recheck')) { wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck'); } } if (function_exists('wp_next_scheduled') && function_exists('wp_schedule_event')) { // WP 2.1+: delete old comments daily if (!wp_next_scheduled('akismet_scheduled_delete')) { wp_schedule_event(time(), 'daily', 'akismet_scheduled_delete'); } } elseif (mt_rand(1, 10) == 3) { // WP 2.0: run this one time in ten akismet_delete_old(); } $akismet_last_comment = $commentdata; akismet_fix_scheduled_recheck(); return $commentdata; }
function akismet_recheck_queue() { global $wpdb, $akismet_api_host, $akismet_api_port; akismet_fix_scheduled_recheck(); if (!(isset($_GET['recheckqueue']) || isset($_REQUEST['action']) && 'akismet_recheck_queue' == $_REQUEST['action'])) { return; } $moderation = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0'", ARRAY_A); foreach ((array) $moderation as $c) { $c['user_ip'] = $c['comment_author_IP']; $c['user_agent'] = $c['comment_agent']; $c['referrer'] = ''; $c['blog'] = get_bloginfo('url'); $c['blog_lang'] = get_locale(); $c['blog_charset'] = get_option('blog_charset'); $c['permalink'] = get_permalink($c['comment_post_ID']); $c['user_role'] = ''; if (isset($c['user_ID'])) { $c['user_role'] = akismet_get_user_roles($c['user_ID']); } if (akismet_test_mode()) { $c['is_test'] = 'true'; } $id = (int) $c['comment_ID']; $query_string = ''; foreach ($c as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&'; } add_comment_meta($c['comment_ID'], 'akismet_rechecking', true); $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); if ('true' == $response[1]) { wp_set_comment_status($c['comment_ID'], 'spam'); update_comment_meta($c['comment_ID'], 'akismet_result', 'true'); delete_comment_meta($c['comment_ID'], 'akismet_error'); akismet_update_comment_history($c['comment_ID'], __('Akismet re-checked and caught this comment as spam'), 'check-spam'); } elseif ('false' == $response[1]) { update_comment_meta($c['comment_ID'], 'akismet_result', 'false'); delete_comment_meta($c['comment_ID'], 'akismet_error'); akismet_update_comment_history($c['comment_ID'], __('Akismet re-checked and cleared this comment'), 'check-ham'); // abnormal result: error } else { update_comment_meta($c['comment_ID'], 'akismet_result', 'error'); akismet_update_comment_history($c['comment_ID'], sprintf(__('Akismet was unable to re-check this comment (response: %s)'), substr($response[1], 0, 50)), 'check-error'); } delete_comment_meta($c['comment_ID'], 'akismet_rechecking'); } $redirect_to = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : admin_url('edit-comments.php'); wp_safe_redirect($redirect_to); exit; }