function akismet_check_db_comment($id, $recheck_reason = 'recheck_queue') { global $wpdb, $akismet_api_host, $akismet_api_port; $id = (int) $id; $c = $wpdb->get_row("SELECT * FROM {$wpdb->comments} WHERE comment_ID = '{$id}'", ARRAY_A); if (!$c) { return; } $c['user_ip'] = $c['comment_author_IP']; $c['user_agent'] = $c['comment_agent']; $c['referrer'] = ''; $c['blog'] = get_option('home'); $c['blog_lang'] = get_locale(); $c['blog_charset'] = get_option('blog_charset'); $c['permalink'] = get_permalink($c['comment_post_ID']); $id = $c['comment_ID']; if (akismet_test_mode()) { $c['is_test'] = 'true'; } $c['recheck_reason'] = $recheck_reason; $query_string = ''; foreach ($c as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&'; } $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); return is_array($response) && isset($response[1]) ? $response[1] : false; }
/** * Contact Akismet to check if this is spam or ham * * Props to WordPress core Akismet plugin for alot of this * * @global string $akismet_api_host * @global string $akismet_api_port * @param array $activity_data Packet of information to submit to Akismet * @param string $check "check" or "submit" * @param string $spam "spam" or "ham" * @since BuddyPress (1.6) */ public function send_akismet_request($activity_data, $check = 'check', $spam = 'spam') { global $akismet_api_host, $akismet_api_port; // Check that host and port are set, if not, set them if (function_exists('akismet_init') && (empty($akismet_api_host) || empty($akismet_api_port))) { akismet_init(); } $query_string = $path = $response = ''; $activity_data['blog'] = bp_get_option('home'); $activity_data['blog_charset'] = bp_get_option('blog_charset'); $activity_data['blog_lang'] = get_locale(); $activity_data['referrer'] = $_SERVER['HTTP_REFERER']; $activity_data['user_agent'] = bp_core_current_user_ua(); $activity_data['user_ip'] = bp_core_current_user_ip(); if (akismet_test_mode()) { $activity_data['is_test'] = 'true'; } // Loop through _POST args and rekey strings foreach ($_POST as $key => $value) { if (is_string($value) && 'cookie' != $key) { $activity_data['POST_' . $key] = $value; } } // Keys to ignore $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'); // Loop through _SERVER args and remove whitelisted keys foreach ($_SERVER as $key => $value) { // Key should not be ignored if (!in_array($key, $ignore) && is_string($value)) { $activity_data[$key] = $value; // Key should be ignored } else { $activity_data[$key] = ''; } } foreach ($activity_data as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&'; } if ('check' == $check) { $path = '/1.1/comment-check'; } elseif ('submit' == $check) { $path = '/1.1/submit-' . $spam; } // Send to Akismet add_filter('akismet_ua', array($this, 'buddypress_ua')); $response = akismet_http_post($query_string, $akismet_api_host, $path, $akismet_api_port); remove_filter('akismet_ua', array($this, 'buddypress_ua')); // Get the response if (!empty($response[1]) && !is_wp_error($response[1])) { $activity_data['bp_as_result'] = $response[1]; } else { $activity_data['bp_as_result'] = false; } // Perform a daily tidy up if (!wp_next_scheduled('bp_activity_akismet_delete_old_metadata')) { wp_schedule_event(time(), 'daily', 'bp_activity_akismet_delete_old_metadata'); } return $activity_data; }
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; }
/** * Ping Akismet service and check for spam/ham response * * @since bbPress (r3277) * * @param array $post_data * @param string $check Accepts check|submit * @param string $spam Accepts spam|ham * * @global string $akismet_api_host * @global string $akismet_api_port * * @uses akismet_test_mode() To determine if Akismet is in test mode * @uses akismet_http_post() To send data to the mothership for processing * * @return array Array of post data */ private function maybe_spam($post_data, $check = 'check', $spam = 'spam') { global $akismet_api_host, $akismet_api_port; // Define variables $query_string = $path = $response = ''; // Populate post data $post_data['blog'] = get_option('home'); $post_data['blog_charset'] = get_option('blog_charset'); $post_data['blog_lang'] = get_locale(); $post_data['referrer'] = $_SERVER['HTTP_REFERER']; $post_data['user_agent'] = $_SERVER['HTTP_USER_AGENT']; // Akismet Test Mode if (akismet_test_mode()) { $post_data['is_test'] = 'true'; } // Loop through _POST args and rekey strings foreach ($_POST as $key => $value) { if (is_string($value)) { $post_data['POST_' . $key] = $value; } } // Keys to ignore $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'); // Loop through _SERVER args and remove whitelisted keys foreach ($_SERVER as $key => $value) { // Key should not be ignored if (!in_array($key, $ignore) && is_string($value)) { $post_data[$key] = $value; // Key should be ignored } else { $post_data[$key] = ''; } } // Ready... foreach ($post_data as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&'; } // Aim... if ('check' == $check) { $path = '/1.1/comment-check'; } elseif ('submit' == $check) { $path = '/1.1/submit-' . $spam; } // Fire! $response = $this->http_post($query_string, $akismet_api_host, $path, $akismet_api_port); // Check the high-speed cam $post_data['bbp_akismet_result'] = $response[1]; // This is ham return $post_data; }