function akismet_recheck_queue() { global $wpdb, $akismet_api_host, $akismet_api_port; 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_option('home'); $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']); } $id = (int) $c['comment_ID']; $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); if ('true' == $response[1]) { wp_set_comment_status($c['comment_ID'], 'spam'); update_comment_meta($c['comment_ID'], 'akismet_result', 'true'); 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'); 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)'), $response[1]), 'check-error'); } } wp_redirect($_SERVER['HTTP_REFERER']); exit; }
function akismet_recheck_queue() { global $wpdb, $akismet_api_host, $akismet_api_port; 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_option('home'); $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']); } $id = (int) $c['comment_ID']; $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); if ('true' == $response[1]) { if (function_exists('wp_set_comment_status')) { wp_set_comment_status($id, 'spam'); } else { $wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = 'spam' WHERE comment_ID = {$id}"); } } } wp_redirect($_SERVER['HTTP_REFERER']); exit; }
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; }
/** * Build a data package for the Akismet service to inspect * * @param BP_Activity_Activity $activity * @see http://akismet.com/development/api/#comment-check * @since BuddyPress (1.6) * @static */ public static function build_akismet_data_package($activity) { $userdata = get_userdata($activity->user_id); $activity_data = array(); $activity_data['akismet_comment_nonce'] = 'inactive'; $activity_data['comment_author'] = $userdata->display_name; $activity_data['comment_author_email'] = $userdata->user_email; $activity_data['comment_author_url'] = bp_core_get_userlink($userdata->ID, false, true); $activity_data['comment_content'] = $activity->content; $activity_data['comment_type'] = $activity->type; $activity_data['permalink'] = bp_activity_get_permalink($activity->id, $activity); $activity_data['user_ID'] = $userdata->ID; $activity_data['user_role'] = akismet_get_user_roles($userdata->ID); /** * Get the nonce if the new activity was submitted through the "what's up, Paul?" form. * This helps Akismet ensure that the update was a valid form submission. */ if (!empty($_POST['_bp_as_nonce'])) { $activity_data['akismet_comment_nonce'] = wp_verify_nonce($_POST['_bp_as_nonce'], "_bp_as_nonce_{$userdata->ID}") ? 'passed' : 'failed'; } elseif (!empty($activity->secondary_item_id) && !empty($_POST['_bp_as_nonce_' . $activity->secondary_item_id])) { $activity_data['akismet_comment_nonce'] = wp_verify_nonce($_POST["_bp_as_nonce_{$activity->secondary_item_id}"], "_bp_as_nonce_{$userdata->ID}_{$activity->secondary_item_id}") ? 'passed' : 'failed'; } return apply_filters('bp_akismet_build_akismet_data_package', $activity_data, $activity); }
/** * Submit a post for spamming or hamming * * @since bbPress (r3277) * * @param int $post_id * * @global WP_Query $wpdb * @global string $akismet_api_host * @global string $akismet_api_port * @global object $current_user * @global object $current_site * * @uses current_filter() To get the reply_id * @uses get_post() To get the post object * @uses get_the_author_meta() To get the author meta * @uses get_post_meta() To get the post meta * @uses bbp_get_user_profile_url() To get a user's profile url * @uses get_permalink() To get the permalink of the post_parent * @uses akismet_get_user_roles() To get the role(s) of the post_author * @uses bbp_current_author_ip() To get the IP address of the current user * @uses BBP_Akismet::maybe_spam() To submit the post as ham or spam * @uses update_post_meta() To update the post meta with some Akismet data * @uses do_action() To call the 'bbp_akismet_submit_spam_post' and 'bbp_akismet_submit_ham_post' hooks * * @return array Array of existing topic terms */ public function submit_post($post_id = 0) { global $current_user, $current_site; // Innocent until proven guilty $request_type = 'ham'; $current_filter = current_filter(); // Check this filter and adjust the $request_type accordingly switch ($current_filter) { // Mysterious, and straight from the can case 'bbp_spammed_topic': case 'bbp_spammed_reply': $request_type = 'spam'; break; // Honey-glazed, a straight off the bone // Honey-glazed, a straight off the bone case 'bbp_unspammed_topic': case 'bbp_unspammed_reply': $request_type = 'ham'; break; // Possibly poison... // Possibly poison... default: return; } // Setup some variables $post_id = (int) $post_id; // Make sure we have a post $_post = get_post($post_id); // Bail if get_post() fails if (empty($_post)) { return; } // Bail if we're spamming, but the post_status isn't spam if ('spam' == $request_type && bbp_get_spam_status_id() != $_post->post_status) { return; } // Set some default post_data $post_data = array('comment_approved' => $_post->post_status, 'comment_author' => $_post->post_author ? get_the_author_meta('display_name', $_post->post_author) : get_post_meta($post_id, '_bbp_anonymous_name', true), 'comment_author_email' => $_post->post_author ? get_the_author_meta('email', $_post->post_author) : get_post_meta($post_id, '_bbp_anonymous_email', true), 'comment_author_url' => $_post->post_author ? bbp_get_user_profile_url($_post->post_author) : get_post_meta($post_id, '_bbp_anonymous_website', true), 'comment_content' => $_post->post_content, 'comment_date' => $_post->post_date, 'comment_ID' => $post_id, 'comment_post_ID' => $_post->post_parent, 'comment_type' => $_post->post_type, 'permalink' => get_permalink($post_id), 'user_ID' => $_post->post_author, 'user_ip' => get_post_meta($post_id, '_bbp_author_ip', true), 'user_role' => akismet_get_user_roles($_post->post_author)); // Use the original version stored in post_meta if available $as_submitted = get_post_meta($post_id, '_bbp_akismet_as_submitted', true); if ($as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content'])) { $post_data = array_merge($post_data, $as_submitted); } // Add the reporter IP address $post_data['reporter_ip'] = bbp_current_author_ip(); // Add some reporter info if (is_object($current_user)) { $post_data['reporter'] = $current_user->user_login; } // Add the current site domain if (is_object($current_site)) { $post_data['site_domain'] = $current_site->domain; } // Place your slide beneath the microscope $post_data = $this->maybe_spam($post_data, 'submit', $request_type); // Manual user action if (isset($post_data['reporter'])) { // What kind of action switch ($request_type) { // Spammy case 'spam': $this->update_post_history($post_id, sprintf(__('%1$s reported this %2$s as spam', 'bbpress'), $post_data['reporter'], $post_data['comment_type']), 'report-spam'); update_post_meta($post_id, '_bbp_akismet_user_result', 'true'); update_post_meta($post_id, '_bbp_akismet_user', $post_data['reporter']); break; // Hammy // Hammy case 'ham': $this->update_post_history($post_id, sprintf(__('%1$s reported this %2$s as not spam', 'bbpress'), $post_data['reporter'], $post_data['comment_type']), 'report-ham'); update_post_meta($post_id, '_bbp_akismet_user_result', 'false'); update_post_meta($post_id, '_bbp_akismet_user', $post_data['reporter']); // @todo Topic term revision history break; // Possible other actions // Possible other actions default: break; } } do_action('bbp_akismet_submit_' . $request_type . '_post', $post_id, $post_data['bbp_akismet_result']); }
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; } $paginate = ''; if (isset($_POST['limit']) && isset($_POST['offset'])) { $paginate = $wpdb->prepare(" LIMIT %d OFFSET %d", array($_POST['limit'], $_POST['offset'])); } $moderation = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0'{$paginate}", 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'); } if (defined('DOING_AJAX') && DOING_AJAX) { wp_send_json(array('processed' => count((array) $moderation))); } else { $redirect_to = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : admin_url('edit-comments.php'); wp_safe_redirect($redirect_to); exit; } }
function digressit_live_spam_check_comment($comment) { global $akismet_api_host, $akismet_api_port; if (function_exists('akismet_verify_key')) { if (akismet_verify_key(akismet_get_key())) { $comment['user_ip'] = $_SERVER['REMOTE_ADDR']; $comment['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $comment['referrer'] = $_SERVER['HTTP_REFERER']; $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']); $comment['user_role'] = akismet_get_user_roles($comment['user_ID']); $ignore = array('HTTP_COOKIE'); foreach ($_SERVER as $key => $value) { if (!in_array($key, $ignore) && is_string($value)) { $comment["{$key}"] = $value; } } $query_string = ''; foreach ($comment 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); if ('true' == $response[1]) { return true; } return false; } } return false; }