summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2016-09-11 08:05:14 -0400
committerAnthony G. Basile <blueness@gentoo.org>2016-09-11 08:05:14 -0400
commit061978f388440351592eab7cde0b81a5ec5be683 (patch)
tree1230eb6d73b924facc0d714637a079fac398d78d /plugins/akismet/class.akismet-admin.php
parentUpdate plugin wordpress-mobile-pack to 2.2.5 (diff)
downloadblogs-gentoo-061978f388440351592eab7cde0b81a5ec5be683.tar.gz
blogs-gentoo-061978f388440351592eab7cde0b81a5ec5be683.tar.bz2
blogs-gentoo-061978f388440351592eab7cde0b81a5ec5be683.zip
Update plugin akismet to 3.2
Diffstat (limited to 'plugins/akismet/class.akismet-admin.php')
-rw-r--r--plugins/akismet/class.akismet-admin.php115
1 files changed, 52 insertions, 63 deletions
diff --git a/plugins/akismet/class.akismet-admin.php b/plugins/akismet/class.akismet-admin.php
index c9e82eb0..2d29cab2 100644
--- a/plugins/akismet/class.akismet-admin.php
+++ b/plugins/akismet/class.akismet-admin.php
@@ -357,85 +357,68 @@ 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;
+ }
+
+ $result_counts = self::recheck_queue_portion( empty( $_POST['offset'] ) ? 0 : $_POST['offset'], empty( $_POST['limit'] ) ? 100 : $_POST['limit'] );
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
+ wp_send_json( array(
+ 'counts' => $result_counts,
+ ));
+ }
+ else {
+ $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : admin_url( 'edit-comments.php' );
+ wp_safe_redirect( $redirect_to );
+ exit;
+ }
+ }
+
+ public static function recheck_queue_portion( $start = 0, $limit = 100 ) {
+ global $wpdb;
+
$paginate = '';
- if ( isset( $_POST['limit'] ) && isset( $_POST['offset'] ) ) {
- $paginate = $wpdb->prepare( " LIMIT %d OFFSET %d", array( $_POST['limit'], $_POST['offset'] ) );
+
+ if ( $limit <= 0 ) {
+ $limit = 100;
+ }
+
+ if ( $start < 0 ) {
+ $start = 0;
}
- $moderation = $wpdb->get_results( "SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0'{$paginate}", ARRAY_A );
+
+ $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 ( (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']);
+ foreach ( $moderation as $comment_id ) {
+ $api_response = Akismet::recheck_comment( $comment_id, 'recheck_queue' );
- 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' );
+ if ( 'true' === $api_response ) {
++$result_counts['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' );
+ }
+ elseif ( 'false' === $api_response ) {
++$result_counts['ham'];
- } else {
- // abnormal result: error
- 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 ) )
- );
+ }
+ else {
++$result_counts['error'];
}
-
- 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 {
- $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : admin_url( 'edit-comments.php' );
- wp_safe_redirect( $redirect_to );
- exit;
}
+
+ 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' );
@@ -447,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' );
@@ -689,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;
@@ -731,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] ) {
@@ -746,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] );