+ $response = self::http_post( Akismet::build_query( $c ), 'comment-check' );
+
+ if ( ! empty( $response[1] ) ) {
+ return $response[1];
+ }
+
+ return false;
+ }
+
+ public static function recheck_comment( $id, $recheck_reason = 'recheck_queue' ) {
+ add_comment_meta( $id, 'akismet_rechecking', true );
+
+ $api_response = self::check_db_comment( $id, $recheck_reason );
+
+ delete_comment_meta( $id, 'akismet_rechecking' );
+
+ if ( is_wp_error( $api_response ) ) {
+ // Invalid comment ID.
+ }
+ else if ( 'true' === $api_response ) {
+ wp_set_comment_status( $id, 'spam' );
+ update_comment_meta( $id, 'akismet_result', 'true' );
+ delete_comment_meta( $id, 'akismet_error' );
+ delete_comment_meta( $id, 'akismet_delayed_moderation_email' );
+ Akismet::update_comment_history( $id, '', 'recheck-spam' );
+ }
+ elseif ( 'false' === $api_response ) {
+ update_comment_meta( $id, 'akismet_result', 'false' );
+ delete_comment_meta( $id, 'akismet_error' );
+ delete_comment_meta( $id, 'akismet_delayed_moderation_email' );
+ Akismet::update_comment_history( $id, '', 'recheck-ham' );
+ }
+ else {
+ // abnormal result: error
+ update_comment_meta( $id, 'akismet_result', 'error' );
+ Akismet::update_comment_history(
+ $id,
+ '',
+ 'recheck-error',
+ array( 'response' => substr( $api_response, 0, 50 ) )
+ );
+ }
+
+ return $api_response;
+ }
+
+ public static function transition_comment_status( $new_status, $old_status, $comment ) {
+
+ if ( $new_status == $old_status )
+ return;
+
+ # we don't need to record a history item for deleted comments
+ if ( $new_status == 'delete' )
+ return;
+
+ if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) && !current_user_can( 'moderate_comments' ) )
+ return;
+
+ if ( defined('WP_IMPORTING') && WP_IMPORTING == true )
+ return;
+
+ // if this is present, it means the status has been changed by a re-check, not an explicit user action
+ if ( get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) )
+ return;
+
+ global $current_user;
+ $reporter = '';
+ if ( is_object( $current_user ) )
+ $reporter = $current_user->user_login;
+
+ // Assumption alert:
+ // We want to submit comments to Akismet only when a moderator explicitly spams or approves it - not if the status
+ // is changed automatically by another plugin. Unfortunately WordPress doesn't provide an unambiguous way to
+ // determine why the transition_comment_status action was triggered. And there are several different ways by which
+ // to spam and unspam comments: bulk actions, ajax, links in moderation emails, the dashboard, and perhaps others.
+ // We'll assume that this is an explicit user action if certain POST/GET variables exist.
+ if ( ( isset( $_POST['status'] ) && in_array( $_POST['status'], array( 'spam', 'unspam' ) ) ) ||
+ ( isset( $_POST['spam'] ) && (int) $_POST['spam'] == 1 ) ||
+ ( isset( $_POST['unspam'] ) && (int) $_POST['unspam'] == 1 ) ||
+ ( isset( $_POST['comment_status'] ) && in_array( $_POST['comment_status'], array( 'spam', 'unspam' ) ) ) ||
+ ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'spam', 'unspam', 'spamcomment', 'unspamcomment', ) ) ) ||
+ ( isset( $_POST['action'] ) && in_array( $_POST['action'], array( 'editedcomment' ) ) ) ||
+ ( isset( $_GET['for'] ) && ( 'jetpack' == $_GET['for'] ) ) // Moderation via WP.com notifications/WP app/etc.
+ ) {
+ if ( $new_status == 'spam' && ( $old_status == 'approved' || $old_status == 'unapproved' || !$old_status ) ) {
+ return self::submit_spam_comment( $comment->comment_ID );
+ } elseif ( $old_status == 'spam' && ( $new_status == 'approved' || $new_status == 'unapproved' ) ) {
+ return self::submit_nonspam_comment( $comment->comment_ID );
+ }
+ }
+
+ self::update_comment_history( $comment->comment_ID, '', 'status-' . $new_status );
+ }
+
+ public static function submit_spam_comment( $comment_id ) {
+ global $wpdb, $current_user, $current_site;
+
+ $comment_id = (int) $comment_id;
+
+ $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $comment_id ) );
+
+ if ( !$comment ) // it was deleted
+ return;
+
+ if ( 'spam' != $comment->comment_approved )
+ return;
+
+ // use the original version stored in comment_meta if available
+ $as_submitted = self::sanitize_comment_as_submitted( get_comment_meta( $comment_id, 'akismet_as_submitted', true ) );
+
+ if ( $as_submitted && is_array( $as_submitted ) && isset( $as_submitted['comment_content'] ) )
+ $comment = (object) array_merge( (array)$comment, $as_submitted );
+
+ $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 ( is_object($current_user) )
+ $comment->reporter = $current_user->user_login;
+
+ if ( is_object($current_site) )
+ $comment->site_domain = $current_site->domain;
+
+ $comment->user_role = '';
+ if ( isset( $comment->user_ID ) )
+ $comment->user_role = Akismet::get_user_roles( $comment->user_ID );
+
+ if ( self::is_test_mode() )
+ $comment->is_test = 'true';
+
+ $post = get_post( $comment->comment_post_ID );
+ $comment->comment_post_modified_gmt = $post->post_modified_gmt;