X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/53f4633144ed68c8b8fb5861f992b5489894a940..3d39054f012aefe514b3f5509e32f09fc4feda44:/wp-content/plugins/akismet/class.akismet-admin.php diff --git a/wp-content/plugins/akismet/class.akismet-admin.php b/wp-content/plugins/akismet/class.akismet-admin.php index 960739f8..2d29cab2 100644 --- a/wp-content/plugins/akismet/class.akismet-admin.php +++ b/wp-content/plugins/akismet/class.akismet-admin.php @@ -4,7 +4,25 @@ class Akismet_Admin { const NONCE = 'akismet-update-key'; private static $initiated = false; - private static $notices = array(); + private static $notices = array(); + private static $allowed = array( + 'a' => array( + 'href' => true, + 'title' => true, + ), + 'b' => array(), + 'code' => array(), + 'del' => array( + 'datetime' => true, + ), + 'em' => array(), + 'i' => array(), + 'q' => array( + 'cite' => true, + ), + 'strike' => array(), + 'strong' => array(), + ); public static function init() { if ( ! self::$initiated ) { @@ -41,7 +59,6 @@ class Akismet_Admin { add_filter( 'plugin_action_links', array( 'Akismet_Admin', 'plugin_action_links' ), 10, 2 ); add_filter( 'comment_row_actions', array( 'Akismet_Admin', 'comment_row_action' ), 10, 2 ); - add_filter( 'comment_text', array( 'Akismet_Admin', 'text_add_link_class' ) ); add_filter( 'plugin_action_links_'.plugin_basename( plugin_dir_path( __FILE__ ) . 'akismet.php'), array( 'Akismet_Admin', 'admin_plugin_settings_link' ) ); @@ -92,11 +109,12 @@ class Akismet_Admin { 'post.php', 'settings_page_akismet-key-config', 'jetpack_page_akismet-key-config', + 'plugins.php', ) ) ) { - wp_register_style( 'akismet.css', AKISMET__PLUGIN_URL . '_inc/akismet.css', array(), AKISMET_VERSION ); + wp_register_style( 'akismet.css', plugin_dir_url( __FILE__ ) . '_inc/akismet.css', array(), AKISMET_VERSION ); wp_enqueue_style( 'akismet.css'); - wp_register_script( 'akismet.js', AKISMET__PLUGIN_URL . '_inc/akismet.js', array('jquery','postbox'), AKISMET_VERSION ); + wp_register_script( 'akismet.js', plugin_dir_url( __FILE__ ) . '_inc/akismet.js', array('jquery','postbox'), AKISMET_VERSION ); wp_enqueue_script( 'akismet.js' ); wp_localize_script( 'akismet.js', 'WPAkismet', array( 'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' ), @@ -129,8 +147,8 @@ class Akismet_Admin { 'title' => __( 'Overview' , 'akismet'), 'content' => '

' . esc_html__( 'Akismet Setup' , 'akismet') . '

' . - '

' . esc_html__( 'Akismet filters out your comment and trackback spam for you, so you can focus on more important things.' , 'akismet') . '

' . - '

' . esc_html__( 'On this page, you are able to setup the Akismet plugin.' , 'akismet') . '

', + '

' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '

' . + '

' . esc_html__( 'On this page, you are able to set up the Akismet plugin.' , 'akismet') . '

', ) ); @@ -141,7 +159,7 @@ class Akismet_Admin { 'content' => '

' . esc_html__( 'Akismet Setup' , 'akismet') . '

' . '

' . esc_html__( 'You need to enter an API key to activate the Akismet service on your site.' , 'akismet') . '

' . - '

' . sprintf( __( 'Signup for an account on %s to get an API Key.' , 'akismet'), 'Akismet.com' ) . '

', + '

' . sprintf( __( 'Sign up for an account on %s to get an API Key.' , 'akismet'), 'Akismet.com' ) . '

', ) ); @@ -167,7 +185,7 @@ class Akismet_Admin { 'title' => __( 'Overview' , 'akismet'), 'content' => '

' . esc_html__( 'Akismet Stats' , 'akismet') . '

' . - '

' . esc_html__( 'Akismet filters out your comment and trackback spam for you, so you can focus on more important things.' , 'akismet') . '

' . + '

' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '

' . '

' . esc_html__( 'On this page, you are able to view stats on spam filtered on your site.' , 'akismet') . '

', ) ); @@ -180,7 +198,7 @@ class Akismet_Admin { 'title' => __( 'Overview' , 'akismet'), 'content' => '

' . esc_html__( 'Akismet Configuration' , 'akismet') . '

' . - '

' . esc_html__( 'Akismet filters out your comment and trackback spam for you, so you can focus on more important things.' , 'akismet') . '

' . + '

' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '

' . '

' . esc_html__( 'On this page, you are able to enter/remove an API key, view account information and view spam stats.' , 'akismet') . '

', ) ); @@ -258,8 +276,10 @@ class Akismet_Admin { if ( in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) ) ) update_option( 'wordpress_api_key', $api_key ); - if ( $akismet_user->status == 'active' ) + if ( $akismet_user->status == 'active' ) self::$notices['status'] = 'new-key-valid'; + elseif ( $akismet_user->status == 'notice' ) + self::$notices['status'] = $akismet_user; else self::$notices['status'] = $akismet_user->status; } @@ -337,63 +357,15 @@ class Akismet_Admin { Akismet::fix_scheduled_recheck(); - if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) ) + 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::is_test_mode() ) - $c['is_test'] = 'true'; - - add_comment_meta( $c['comment_ID'], 'akismet_rechecking', true ); - $response = Akismet::http_post( Akismet::build_query( $c ), 'comment-check' ); - - 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' ); - delete_comment_meta( $c['comment_ID'], 'akismet_delayed_moderation_email' ); - Akismet::update_comment_history( $c['comment_ID'], '', 'recheck-spam' ); - - } elseif ( 'false' == $response[1] ) { - update_comment_meta( $c['comment_ID'], 'akismet_result', 'false' ); - delete_comment_meta( $c['comment_ID'], 'akismet_error' ); - delete_comment_meta( $c['comment_ID'], 'akismet_delayed_moderation_email' ); - Akismet::update_comment_history( $c['comment_ID'], '', 'recheck-ham' ); - // abnormal result: error - } else { - update_comment_meta( $c['comment_ID'], 'akismet_result', 'error' ); - Akismet::update_comment_history( - $c['comment_ID'], - '', - 'recheck-error', - array( 'response' => substr( $response[1], 0, 50 ) ) - ); - } + $result_counts = self::recheck_queue_portion( empty( $_POST['offset'] ) ? 0 : $_POST['offset'], empty( $_POST['limit'] ) ? 100 : $_POST['limit'] ); - delete_comment_meta( $c['comment_ID'], 'akismet_rechecking' ); - } if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { wp_send_json( array( - 'processed' => count((array) $moderation), + 'counts' => $result_counts, )); } else { @@ -402,11 +374,51 @@ class Akismet_Admin { exit; } } + + public static function recheck_queue_portion( $start = 0, $limit = 100 ) { + global $wpdb; + + $paginate = ''; + + if ( $limit <= 0 ) { + $limit = 100; + } + + if ( $start < 0 ) { + $start = 0; + } + + $moderation = $wpdb->get_col( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0' LIMIT %d OFFSET %d", $limit, $start ) ); + + $result_counts = array( + 'processed' => count( $moderation ), + 'spam' => 0, + 'ham' => 0, + 'error' => 0, + ); + + foreach ( $moderation as $comment_id ) { + $api_response = Akismet::recheck_comment( $comment_id, 'recheck_queue' ); + + if ( 'true' === $api_response ) { + ++$result_counts['spam']; + } + elseif ( 'false' === $api_response ) { + ++$result_counts['ham']; + } + else { + ++$result_counts['error']; + } + } + + return $result_counts; + } // Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link public static function remove_comment_author_url() { if ( !empty( $_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) { - $comment = get_comment( intval( $_POST['id'] ), ARRAY_A ); + $comment_id = intval( $_POST['id'] ); + $comment = get_comment( $comment_id, ARRAY_A ); if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) { $comment['comment_author_url'] = ''; do_action( 'comment_remove_author_url' ); @@ -418,7 +430,8 @@ class Akismet_Admin { public static function add_comment_author_url() { if ( !empty( $_POST['id'] ) && !empty( $_POST['url'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) { - $comment = get_comment( intval( $_POST['id'] ), ARRAY_A ); + $comment_id = intval( $_POST['id'] ); + $comment = get_comment( $comment_id, ARRAY_A ); if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) { $comment['comment_author_url'] = esc_url( $_POST['url'] ); do_action( 'comment_add_author_url' ); @@ -585,25 +598,13 @@ class Akismet_Admin { } public static function plugin_action_links( $links, $file ) { - if ( $file == plugin_basename( AKISMET__PLUGIN_URL . '/akismet.php' ) ) { + if ( $file == plugin_basename( plugin_dir_url( __FILE__ ) . '/akismet.php' ) ) { $links[] = ''.esc_html__( 'Settings' , 'akismet').''; } return $links; } - public static function text_add_link_callback( $m ) { - // bare link? - if ( $m[4] == $m[2] ) - return ''.$m[4].''; - else - return ''.$m[4].''; - } - - public static function text_add_link_class( $comment_text ) { - return preg_replace_callback( '#]*)href="([^"]+)"([^>]*)>(.*?)#i', array( 'Akismet_Admin', 'text_add_link_callback' ), $comment_text ); - } - // Total spam in queue // get_option( 'akismet_spam_count' ) is the total caught ever public static function get_spam_count( $type = false ) { @@ -672,9 +673,14 @@ class Akismet_Admin { update_option('akismet_available_servers', $servers); update_option('akismet_connectivity_time', time()); } - - $response = wp_remote_get( 'http://rest.akismet.com/1.1/test' ); - + + if ( function_exists( 'wp_http_supports' ) && ( wp_http_supports( array( 'ssl' ) ) ) ) { + $response = wp_remote_get( 'https://rest.akismet.com/1.1/test' ); + } + else { + $response = wp_remote_get( 'http://rest.akismet.com/1.1/test' ); + } + $debug[ 'gethostbynamel' ] = function_exists('gethostbynamel') ? 'exists' : 'not here'; $debug[ 'Servers' ] = $servers; $debug[ 'Test Connection' ] = $response; @@ -714,7 +720,7 @@ class Akismet_Admin { public static function get_akismet_user( $api_key ) { $akismet_user = false; - $subscription_verification = Akismet::http_post( Akismet::build_query( array( 'key' => $api_key, 'blog' => get_bloginfo( 'url' ) ) ), 'get-subscription' ); + $subscription_verification = Akismet::http_post( Akismet::build_query( array( 'key' => $api_key, 'blog' => get_option( 'home' ) ) ), 'get-subscription' ); if ( ! empty( $subscription_verification[1] ) ) { if ( 'invalid' !== $subscription_verification[1] ) { @@ -729,7 +735,7 @@ class Akismet_Admin { $stat_totals = array(); foreach( array( '6-months', 'all' ) as $interval ) { - $response = Akismet::http_post( Akismet::build_query( array( 'blog' => get_bloginfo( 'url' ), 'key' => $api_key, 'from' => $interval ) ), 'get-stats' ); + $response = Akismet::http_post( Akismet::build_query( array( 'blog' => get_option( 'home' ), 'key' => $api_key, 'from' => $interval ) ), 'get-stats' ); if ( ! empty( $response[1] ) ) { $stat_totals[$interval] = json_decode( $response[1] ); @@ -880,11 +886,11 @@ class Akismet_Admin { $cleaning_up = __( 'Cleaning up spam takes time.' , 'akismet'); if ( $total_in_days > 1 ) - $time_saved = $cleaning_up . ' ' . sprintf( __( 'Since you joined us, Akismet has saved you %s days!' , 'akismet'), number_format_i18n( $total_in_days ) ); + $time_saved = $cleaning_up . ' ' . sprintf( _n( 'Akismet has saved you %s day!', 'Akismet has saved you %s days!', $total_in_days, 'akismet' ), number_format_i18n( $total_in_days ) ); elseif ( $total_in_hours > 1 ) - $time_saved = $cleaning_up . ' ' . sprintf( __( 'Since you joined us, Akismet has saved you %d hours!' , 'akismet'), $total_in_hours ); + $time_saved = $cleaning_up . ' ' . sprintf( _n( 'Akismet has saved you %d hour!', 'Akismet has saved you %d hours!', $total_in_hours, 'akismet' ), $total_in_hours ); elseif ( $total_in_minutes >= 30 ) - $time_saved = $cleaning_up . ' ' . sprintf( __( 'Since you joined us, Akismet has saved you %d minutes!' , 'akismet'), $total_in_minutes ); + $time_saved = $cleaning_up . ' ' . sprintf( _n( 'Akismet has saved you %d minute!', 'Akismet has saved you %d minutes!', $total_in_minutes, 'akismet' ), $total_in_minutes ); } Akismet::view( 'notice', array( 'type' => 'active-notice', 'time_saved' => $time_saved ) ); @@ -931,8 +937,24 @@ class Akismet_Admin { if ( !empty( $type ) ) Akismet::view( 'notice', compact( 'type' ) ); elseif ( !empty( self::$notices ) ) { - foreach ( self::$notices as $type ) - Akismet::view( 'notice', compact( 'type' ) ); + foreach ( self::$notices as $type ) { + if ( is_object( $type ) ) { + $notice_header = $notice_text = ''; + + if ( property_exists( $type, 'notice_header' ) ) + $notice_header = wp_kses( $type->notice_header, self::$allowed ); + + if ( property_exists( $type, 'notice_text' ) ) + $notice_text = wp_kses( $type->notice_text, self::$allowed ); + + if ( property_exists( $type, 'status' ) ) { + $type = wp_kses( $type->status, self::$allowed ); + Akismet::view( 'notice', compact( 'type', 'notice_header', 'notice_text' ) ); + } + } + else + Akismet::view( 'notice', compact( 'type' ) ); + } } }