]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-content/plugins/akismet/class.akismet.php
WordPress 4.1-scripts
[autoinstalls/wordpress.git] / wp-content / plugins / akismet / class.akismet.php
index 17f6b0058acd846465abb38aa3091f2f62536124..bcc5163e769245103dae4cee5f8f8e3a042eed9e 100644 (file)
@@ -54,7 +54,7 @@ class Akismet {
        }
 
        public static function check_key_status( $key, $ip = null ) {
-               return self::http_post( build_query( array( 'key' => $key, 'blog' => get_option('home') ) ), 'verify-key', $ip );
+               return self::http_post( Akismet::build_query( array( 'key' => $key, 'blog' => get_option('home') ) ), 'verify-key', $ip );
        }
 
        public static function verify_key( $key, $ip = null ) {
@@ -117,7 +117,7 @@ class Akismet {
                $post = get_post( $comment['comment_post_ID'] );
                $comment[ 'comment_post_modified_gmt' ] = $post->post_modified_gmt;
 
-               $response = self::http_post( build_query( $comment ), 'comment-check' );
+               $response = self::http_post( Akismet::build_query( $comment ), 'comment-check' );
 
                do_action( 'akismet_comment_check_response', $response );
 
@@ -256,13 +256,31 @@ class Akismet {
        public static function delete_old_comments() {
                global $wpdb;
 
-               while( $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_id FROM {$wpdb->comments} WHERE DATE_SUB(NOW(), INTERVAL 15 DAY) > comment_date_gmt AND comment_approved = 'spam' LIMIT %d", defined( 'AKISMET_DELETE_LIMIT' ) ? AKISMET_DELETE_LIMIT : 10000 ) ) ) {
+               /**
+                * Determines how many comments will be deleted in each batch.
+                *
+                * @param int The default, as defined by AKISMET_DELETE_LIMIT.
+                */
+               $delete_limit = apply_filters( 'akismet_delete_comment_limit', defined( 'AKISMET_DELETE_LIMIT' ) ? AKISMET_DELETE_LIMIT : 10000 );
+               $delete_limit = max( 1, intval( $delete_limit ) );
+
+               /**
+                * Determines how many days a comment will be left in the Spam queue before being deleted.
+                *
+                * @param int The default number of days.
+                */
+               $delete_interval = apply_filters( 'akismet_delete_comment_interval', 15 );
+               $delete_interval = max( 1, intval( $delete_interval ) );
+
+               while ( $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_id FROM {$wpdb->comments} WHERE DATE_SUB(NOW(), INTERVAL %d DAY) > comment_date_gmt AND comment_approved = 'spam' LIMIT %d", $delete_interval, $delete_limit ) ) ) {
                        if ( empty( $comment_ids ) )
                                return;
 
                        $wpdb->queries = array();
 
-                       do_action( 'delete_comment', $comment_ids );
+                       foreach ( $comment_ids as $comment_id ) {
+                               do_action( 'delete_comment', $comment_id );
+                       }
 
                        $comma_comment_ids = implode( ', ', array_map('intval', $comment_ids) );
 
@@ -370,7 +388,7 @@ class Akismet {
                if ( self::is_test_mode() )
                        $c['is_test'] = 'true';
 
-               $response = self::http_post( build_query( $c ), 'comment-check' );
+               $response = self::http_post( Akismet::build_query( $c ), 'comment-check' );
 
                return ( is_array( $response ) && ! empty( $response[1] ) ) ? $response[1] : false;
        }
@@ -464,7 +482,7 @@ class Akismet {
                $post = get_post( $comment->comment_post_ID );
                $comment->comment_post_modified_gmt = $post->post_modified_gmt;
 
-               $response = Akismet::http_post( build_query( $comment ), 'submit-spam' );
+               $response = Akismet::http_post( Akismet::build_query( $comment ), 'submit-spam' );
                if ( $comment->reporter ) {
                        self::update_comment_history( $comment_id, sprintf( __('%s reported this comment as spam', 'akismet'), $comment->reporter ), 'report-spam' );
                        update_comment_meta( $comment_id, 'akismet_user_result', 'true' );
@@ -510,7 +528,7 @@ class Akismet {
                $post = get_post( $comment->comment_post_ID );
                $comment->comment_post_modified_gmt = $post->post_modified_gmt;
 
-               $response = self::http_post( build_query( $comment ), 'submit-ham' );
+               $response = self::http_post( Akismet::build_query( $comment ), 'submit-ham' );
                if ( $comment->reporter ) {
                        self::update_comment_history( $comment_id, sprintf( __('%s reported this comment as not spam', 'akismet'), $comment->reporter ), 'report-ham' );
                        update_comment_meta( $comment_id, 'akismet_user_result', 'false' );
@@ -915,9 +933,27 @@ p {
        public static function plugin_deactivation( ) {
                //tidy up
        }
+       
+       /**
+        * Essentially a copy of WP's build_query but one that doesn't expect pre-urlencoded values.
+        *
+        * @param array $args An array of key => value pairs
+        * @return string A string ready for use as a URL query string.
+        */
+       public static function build_query( $args ) {
+               return _http_build_query( $args, '', '&' );
+       }
 
+       /**
+        * Log debugging info to the error log.
+        *
+        * Enabled when WP_DEBUG_LOG is enabled, but can be disabled via the akismet_debug_log filter.
+        *
+        * @param mixed $akismet_debug The data to log.
+        */
        public static function log( $akismet_debug ) {
-               if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG )
-                       error_log( print_r( compact( 'akismet_debug' ), 1 ) ); //send message to debug.log when in debug mode
+               if ( apply_filters( 'akismet_debug_log', defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) ) {
+                       error_log( print_r( compact( 'akismet_debug' ), true ) );
+               }
        }
 }
\ No newline at end of file