diff -r 490d5cc509ed -r cf61fcea0001 wp/wp-content/plugins/akismet/class.akismet-admin.php
--- a/wp/wp-content/plugins/akismet/class.akismet-admin.php Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-content/plugins/akismet/class.akismet-admin.php Mon Oct 14 17:39:30 2019 +0200
@@ -4,7 +4,25 @@
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 ) {
@@ -14,6 +32,10 @@
if ( isset( $_POST['action'] ) && $_POST['action'] == 'enter-key' ) {
self::enter_api_key();
}
+
+ if ( ! empty( $_GET['akismet_comment_form_privacy_notice'] ) && empty( $_GET['settings-updated']) ) {
+ self::set_form_privacy_notice_option( $_GET['akismet_comment_form_privacy_notice'] );
+ }
}
public static function init_hooks() {
@@ -41,16 +63,29 @@
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' ) );
add_filter( 'wxr_export_skip_commentmeta', array( 'Akismet_Admin', 'exclude_commentmeta_from_export' ), 10, 3 );
+
+ add_filter( 'all_plugins', array( 'Akismet_Admin', 'modify_plugin_description' ) );
+
+ if ( class_exists( 'Jetpack' ) ) {
+ add_filter( 'akismet_comment_form_privacy_notice_url_display', array( 'Akismet_Admin', 'jetpack_comment_form_privacy_notice_url' ) );
+ add_filter( 'akismet_comment_form_privacy_notice_url_hide', array( 'Akismet_Admin', 'jetpack_comment_form_privacy_notice_url' ) );
+ }
}
public static function admin_init() {
load_plugin_textdomain( 'akismet' );
add_meta_box( 'akismet-status', __('Comment History', 'akismet'), array( 'Akismet_Admin', 'comment_status_meta_box' ), 'comment', 'normal' );
+
+ if ( function_exists( 'wp_add_privacy_policy_content' ) ) {
+ wp_add_privacy_policy_content(
+ __( 'Akismet', 'akismet' ),
+ __( 'We collect information about visitors who comment on Sites that use our Akismet anti-spam service. The information we collect depends on how the User sets up Akismet for the Site, but typically includes the commenter\'s IP address, user agent, referrer, and Site URL (along with other information directly provided by the commenter such as their name, username, email address, and the comment itself).', 'akismet' )
+ );
+ }
}
public static function admin_menu() {
@@ -72,12 +107,14 @@
}
public static function load_menu() {
- if ( class_exists( 'Jetpack' ) )
- $hook = add_submenu_page( 'jetpack', __( 'Akismet' , 'akismet'), __( 'Akismet' , 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
- else
- $hook = add_options_page( __('Akismet', 'akismet'), __('Akismet', 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
-
- if ( version_compare( $GLOBALS['wp_version'], '3.3', '>=' ) ) {
+ if ( class_exists( 'Jetpack' ) ) {
+ $hook = add_submenu_page( 'jetpack', __( 'Akismet Anti-Spam' , 'akismet'), __( 'Akismet Anti-Spam' , 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
+ }
+ else {
+ $hook = add_options_page( __('Akismet Anti-Spam', 'akismet'), __('Akismet Anti-Spam', 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
+ }
+
+ if ( $hook ) {
add_action( "load-$hook", array( 'Akismet_Admin', 'admin_help' ) );
}
}
@@ -85,20 +122,22 @@
public static function load_resources() {
global $hook_suffix;
- if ( in_array( $hook_suffix, array(
+ if ( in_array( $hook_suffix, apply_filters( 'akismet_admin_page_hook_suffixes', array(
'index.php', # dashboard
'edit-comments.php',
'comment.php',
'post.php',
'settings_page_akismet-key-config',
'jetpack_page_akismet-key-config',
- ) ) ) {
- wp_register_style( 'akismet.css', AKISMET__PLUGIN_URL . '_inc/akismet.css', array(), AKISMET_VERSION );
+ 'plugins.php',
+ ) ) ) ) {
+ 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'), AKISMET_VERSION );
wp_enqueue_script( 'akismet.js' );
- wp_localize_script( 'akismet.js', 'WPAkismet', array(
+
+ $inline_js = array(
'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' ),
'strings' => array(
'Remove this URL' => __( 'Remove this URL' , 'akismet'),
@@ -107,7 +146,13 @@
'(undo)' => __( '(undo)' , 'akismet'),
'Re-adding...' => __( 'Re-adding...' , 'akismet'),
)
- ) );
+ );
+
+ if ( isset( $_GET['akismet_recheck'] ) && wp_verify_nonce( $_GET['akismet_recheck'], 'akismet_recheck' ) ) {
+ $inline_js['start_recheck'] = true;
+ }
+
+ wp_localize_script( 'akismet.js', 'WPAkismet', $inline_js );
}
}
@@ -129,8 +174,8 @@
'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 +186,7 @@
'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 +212,7 @@
'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,8 +225,8 @@
'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__( 'On this page, you are able to enter/remove an API key, view account information and view spam stats.' , '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 update your Akismet settings and view spam stats.' , 'akismet') . '
',
)
);
@@ -191,22 +236,24 @@
'title' => __( 'Settings' , 'akismet'),
'content' =>
'' . esc_html__( 'Akismet Configuration' , 'akismet') . '
' .
- '' . esc_html__( 'API Key' , 'akismet') . ' - ' . esc_html__( 'Enter/remove an API key.' , 'akismet') . '
' .
+ ( Akismet::predefined_api_key() ? '' : '' . esc_html__( 'API Key' , 'akismet') . ' - ' . esc_html__( 'Enter/remove an API key.' , 'akismet') . '
' ) .
'' . esc_html__( 'Comments' , 'akismet') . ' - ' . esc_html__( 'Show the number of approved comments beside each comment author in the comments list page.' , 'akismet') . '
' .
'' . esc_html__( 'Strictness' , 'akismet') . ' - ' . esc_html__( 'Choose to either discard the worst spam automatically or to always put all spam in spam folder.' , 'akismet') . '
',
)
);
- $current_screen->add_help_tab(
- array(
- 'id' => 'account',
- 'title' => __( 'Account' , 'akismet'),
- 'content' =>
- '' . esc_html__( 'Akismet Configuration' , 'akismet') . '
' .
- '' . esc_html__( 'Subscription Type' , 'akismet') . ' - ' . esc_html__( 'The Akismet subscription plan' , 'akismet') . '
' .
- '' . esc_html__( 'Status' , 'akismet') . ' - ' . esc_html__( 'The subscription status - active, cancelled or suspended' , 'akismet') . '
',
- )
- );
+ if ( ! Akismet::predefined_api_key() ) {
+ $current_screen->add_help_tab(
+ array(
+ 'id' => 'account',
+ 'title' => __( 'Account' , 'akismet'),
+ 'content' =>
+ '' . esc_html__( 'Akismet Configuration' , 'akismet') . '
' .
+ '' . esc_html__( 'Subscription Type' , 'akismet') . ' - ' . esc_html__( 'The Akismet subscription plan' , 'akismet') . '
' .
+ '' . esc_html__( 'Status' , 'akismet') . ' - ' . esc_html__( 'The subscription status - active, cancelled or suspended' , 'akismet') . '
',
+ )
+ );
+ }
}
}
@@ -219,8 +266,9 @@
}
public static function enter_api_key() {
- if ( function_exists('current_user_can') && !current_user_can('manage_options') )
- die(__('Cheatin’ uh?', 'akismet'));
+ if ( ! current_user_can( 'manage_options' ) ) {
+ die( __( 'Cheatin’ uh?', 'akismet' ) );
+ }
if ( !wp_verify_nonce( $_POST['_wpnonce'], self::NONCE ) )
return false;
@@ -229,9 +277,16 @@
update_option( $option, isset( $_POST[$option] ) && (int) $_POST[$option] == 1 ? '1' : '0' );
}
- if ( defined( 'WPCOM_API_KEY' ) )
+ if ( ! empty( $_POST['akismet_comment_form_privacy_notice'] ) ) {
+ self::set_form_privacy_notice_option( $_POST['akismet_comment_form_privacy_notice'] );
+ } else {
+ self::set_form_privacy_notice_option( 'hide' );
+ }
+
+ if ( Akismet::predefined_api_key() ) {
return false; //shouldn't have option to save key if already defined
-
+ }
+
$new_key = preg_replace( '/[^a-f0-9]/i', '', $_POST['key'] );
$old_key = Akismet::get_api_key();
@@ -258,8 +313,10 @@
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;
}
@@ -271,8 +328,9 @@
}
public static function dashboard_stats() {
- if ( !function_exists('did_action') || did_action( 'rightnow_end' ) )
+ if ( did_action( 'rightnow_end' ) ) {
return; // We already displayed this info in the "Right Now" section
+ }
if ( !$count = get_option('akismet_spam_count') )
return;
@@ -324,12 +382,25 @@
return;
}
- if ( function_exists('plugins_url') )
- $link = add_query_arg( array( 'action' => 'akismet_recheck_queue' ), admin_url( 'admin.php' ) );
- else
- $link = add_query_arg( array( 'page' => 'akismet-admin', 'recheckqueue' => 'true', 'noheader' => 'true' ), admin_url( 'edit-comments.php' ) );
+ $link = add_query_arg( array( 'action' => 'akismet_recheck_queue' ), admin_url( 'admin.php' ) );
- echo '';
+ echo '';
+ echo '
';
+ echo '' . esc_html__('Check for Spam', 'akismet') . '';
+ echo '';
+ echo '';
+ echo '
';
+
}
public static function recheck_queue() {
@@ -337,63 +408,15 @@
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' );
+ $result_counts = self::recheck_queue_portion( empty( $_POST['offset'] ) ? 0 : $_POST['offset'], empty( $_POST['limit'] ) ? 100 : $_POST['limit'] );
- } 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 ) )
- );
- }
-
- 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 +425,51 @@
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 +481,8 @@
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' );
@@ -429,11 +493,6 @@
}
public static function comment_row_action( $a, $comment ) {
-
- // failsafe for old WP versions
- if ( !function_exists('add_comment_meta') )
- return $a;
-
$akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
$akismet_error = get_comment_meta( $comment->comment_ID, 'akismet_error', true );
$user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
@@ -462,7 +521,7 @@
$b[ $k ] = $item;
if (
$k == 'edit'
- || ( $k == 'unspam' && $GLOBALS['wp_version'] >= 3.4 )
+ || $k == 'unspam'
) {
$b['history'] = '
'. esc_html__('History', 'akismet') . '';
}
@@ -474,7 +533,14 @@
if ( $desc )
echo '
'.esc_html( $desc ).'';
- $show_user_comments = apply_filters( 'akismet_show_user_comments_approved', get_option('akismet_show_user_comments_approved') );
+ $show_user_comments_option = get_option( 'akismet_show_user_comments_approved' );
+
+ if ( $show_user_comments_option === false ) {
+ // Default to active if the user hasn't made a decision.
+ $show_user_comments_option = '1';
+ }
+
+ $show_user_comments = apply_filters( 'akismet_show_user_comments_approved', $show_user_comments_option );
$show_user_comments = $show_user_comments === 'false' ? false : $show_user_comments; //option used to be saved as 'false' / 'true'
if ( $show_user_comments ) {
@@ -585,25 +651,13 @@
}
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 '';
- else
- return '';
- }
-
- 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 ) {
@@ -612,12 +666,8 @@
if ( !$type ) { // total
$count = wp_cache_get( 'akismet_spam_count', 'widget' );
if ( false === $count ) {
- if ( function_exists('wp_count_comments') ) {
- $count = wp_count_comments();
- $count = $count->spam;
- } else {
- $count = (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_approved = 'spam'");
- }
+ $count = wp_count_comments();
+ $count = $count->spam;
wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 );
}
return $count;
@@ -672,9 +722,14 @@
update_option('akismet_available_servers', $servers);
update_option('akismet_connectivity_time', time());
}
-
- $response = wp_remote_get( 'http://rest.akismet.com/1.1/test' );
-
+
+ if ( 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;
@@ -692,9 +747,23 @@
return self::check_server_connectivity( $cache_timeout );
}
- public static function get_number_spam_waiting() {
- global $wpdb;
- return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'" );
+ /**
+ * Find out whether any comments in the Pending queue have not yet been checked by Akismet.
+ *
+ * @return bool
+ */
+ public static function are_any_comments_waiting_to_be_checked() {
+ return !! get_comments( array(
+ // Exclude comments that are not pending. This would happen if someone manually approved or spammed a comment
+ // that was waiting to be checked. The akismet_error meta entry will eventually be removed by the cron recheck job.
+ 'status' => 'hold',
+
+ // This is the commentmeta that is saved when a comment couldn't be checked.
+ 'meta_key' => 'akismet_error',
+
+ // We only need to know whether at least one comment is waiting for a check.
+ 'number' => 1,
+ ) );
}
public static function get_page_url( $page = 'config' ) {
@@ -712,13 +781,16 @@
}
public static function get_akismet_user( $api_key ) {
- $akismet_user = Akismet::http_post( Akismet::build_query( array( 'key' => $api_key, 'blog' => get_bloginfo( 'url' ) ) ), 'get-subscription' );
+ $akismet_user = false;
+
+ $subscription_verification = Akismet::http_post( Akismet::build_query( array( 'key' => $api_key, 'blog' => get_option( 'home' ) ) ), 'get-subscription' );
- if ( ! empty( $akismet_user[1] ) )
- $akismet_user = json_decode( $akismet_user[1] );
- else
- $akismet_user = false;
-
+ if ( ! empty( $subscription_verification[1] ) ) {
+ if ( 'invalid' !== $subscription_verification[1] ) {
+ $akismet_user = json_decode( $subscription_verification[1] );
+ }
+ }
+
return $akismet_user;
}
@@ -726,7 +798,7 @@
$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] );
@@ -775,19 +847,23 @@
) );
}
+ public static function display_privacy_notice_control_warning() {
+ if ( !current_user_can( 'manage_options' ) )
+ return;
+ Akismet::view( 'notice', array(
+ 'type' => 'privacy',
+ ) );
+ }
+
public static function display_spam_check_warning() {
Akismet::fix_scheduled_recheck();
- if ( wp_next_scheduled('akismet_schedule_cron_recheck') > time() && self::get_number_spam_waiting() > 0 ) {
+ if ( wp_next_scheduled('akismet_schedule_cron_recheck') > time() && self::are_any_comments_waiting_to_be_checked() ) {
$link_text = apply_filters( 'akismet_spam_check_warning_link_text', sprintf( __( 'Please check your
Akismet configuration and contact your web host if problems persist.', 'akismet'), esc_url( self::get_page_url() ) ) );
Akismet::view( 'notice', array( 'type' => 'spam-check', 'link_text' => $link_text ) );
}
}
- public static function display_invalid_version() {
- Akismet::view( 'notice', array( 'type' => 'version' ) );
- }
-
public static function display_api_key_warning() {
Akismet::view( 'notice', array( 'type' => 'plugin' ) );
}
@@ -809,7 +885,7 @@
}
}
- if ( $api_key = Akismet::get_api_key() ) {
+ if ( $api_key = Akismet::get_api_key() && ( empty( self::$notices['status'] ) || 'existing-key-invalid' != self::$notices['status'] ) ) {
self::display_configuration_page();
return;
}
@@ -829,18 +905,26 @@
if ( $_GET['action'] == 'save-key' ) {
if ( is_object( $akismet_user ) ) {
self::save_key( $akismet_user->api_key );
- self::display_notice();
self::display_configuration_page();
- return;
+ return;
}
}
}
- echo '';
+ Akismet::view( 'start', compact( 'akismet_user' ) );
- self::display_status();
-
+ /*
+ // To see all variants when testing.
+ $akismet_user->status = 'no-sub';
+ Akismet::view( 'start', compact( 'akismet_user' ) );
+ $akismet_user->status = 'cancelled';
Akismet::view( 'start', compact( 'akismet_user' ) );
+ $akismet_user->status = 'suspended';
+ Akismet::view( 'start', compact( 'akismet_user' ) );
+ $akismet_user->status = 'other';
+ Akismet::view( 'start', compact( 'akismet_user' ) );
+ $akismet_user = false;
+ */
}
public static function display_stats_page() {
@@ -850,14 +934,30 @@
public static function display_configuration_page() {
$api_key = Akismet::get_api_key();
$akismet_user = self::get_akismet_user( $api_key );
- $stat_totals = self::get_stats( $api_key );
- // If unset, create the new strictness option using the old discard option to determine its default
- if ( get_option( 'akismet_strictness' ) === false )
- add_option( 'akismet_strictness', (get_option('akismet_discard_month') === 'true' ? '1' : '0') );
+ if ( ! $akismet_user ) {
+ // This could happen if the user's key became invalid after it was previously valid and successfully set up.
+ self::$notices['status'] = 'existing-key-invalid';
+ self::display_start_page();
+ return;
+ }
+
+ $stat_totals = self::get_stats( $api_key );
+
+ // If unset, create the new strictness option using the old discard option to determine its default.
+ // If the old option wasn't set, default to discarding the blatant spam.
+ if ( get_option( 'akismet_strictness' ) === false ) {
+ add_option( 'akismet_strictness', ( get_option( 'akismet_discard_month' ) === 'false' ? '0' : '1' ) );
+ }
+
+ // Sync the local "Total spam blocked" count with the authoritative count from the server.
+ if ( isset( $stat_totals['all'], $stat_totals['all']->spam ) ) {
+ update_option( 'akismet_spam_count', $stat_totals['all']->spam );
+ }
+
+ $notices = array();
if ( empty( self::$notices ) ) {
- //show status
if ( ! empty( $stat_totals['all'] ) && isset( $stat_totals['all']->time_saved ) && $akismet_user->status == 'active' && $akismet_user->account_type == 'free-api-key' ) {
$time_saved = false;
@@ -869,32 +969,63 @@
$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 ) );
+
+ $notices[] = array( 'type' => 'active-notice', 'time_saved' => $time_saved );
}
if ( !empty( $akismet_user->limit_reached ) && in_array( $akismet_user->limit_reached, array( 'yellow', 'red' ) ) ) {
- Akismet::view( 'notice', array( 'type' => 'limit-reached', 'level' => $akismet_user->limit_reached ) );
+ $notices[] = array( 'type' => 'limit-reached', 'level' => $akismet_user->limit_reached );
}
}
- if ( !isset( self::$notices['status'] ) && in_array( $akismet_user->status, array( 'cancelled', 'suspended', 'missing', 'no-sub' ) ) )
- Akismet::view( 'notice', array( 'type' => $akismet_user->status ) );
+ if ( !isset( self::$notices['status'] ) && in_array( $akismet_user->status, array( 'cancelled', 'suspended', 'missing', 'no-sub' ) ) ) {
+ $notices[] = array( 'type' => $akismet_user->status );
+ }
+
+ if ( false === get_option( 'akismet_comment_form_privacy_notice' ) ) {
+ $notices[] = array( 'type' => 'privacy' );
+ }
+ /*
+ // To see all variants when testing.
+ $notices[] = array( 'type' => 'active-notice', 'time_saved' => 'Cleaning up spam takes time. Akismet has saved you 1 minute!' );
+ $notices[] = array( 'type' => 'plugin' );
+ $notices[] = array( 'type' => 'spam-check', 'link_text' => 'Link text.' );
+ $notices[] = array( 'type' => 'notice', 'notice_header' => 'This is the notice header.', 'notice_text' => 'This is the notice text.' );
+ $notices[] = array( 'type' => 'missing-functions' );
+ $notices[] = array( 'type' => 'servers-be-down' );
+ $notices[] = array( 'type' => 'active-dunning' );
+ $notices[] = array( 'type' => 'cancelled' );
+ $notices[] = array( 'type' => 'suspended' );
+ $notices[] = array( 'type' => 'missing' );
+ $notices[] = array( 'type' => 'no-sub' );
+ $notices[] = array( 'type' => 'new-key-valid' );
+ $notices[] = array( 'type' => 'new-key-invalid' );
+ $notices[] = array( 'type' => 'existing-key-invalid' );
+ $notices[] = array( 'type' => 'new-key-failed' );
+ $notices[] = array( 'type' => 'limit-reached', 'level' => 'yellow' );
+ $notices[] = array( 'type' => 'limit-reached', 'level' => 'red' );
+ */
+
Akismet::log( compact( 'stat_totals', 'akismet_user' ) );
- Akismet::view( 'config', compact( 'api_key', 'akismet_user', 'stat_totals' ) );
+ Akismet::view( 'config', compact( 'api_key', 'akismet_user', 'stat_totals', 'notices' ) );
}
public static function display_notice() {
global $hook_suffix;
- if ( in_array( $hook_suffix, array( 'jetpack_page_akismet-key-config', 'settings_page_akismet-key-config', 'edit-comments.php' ) ) && (int) get_option( 'akismet_alert_code' ) > 0 ) {
+ if ( in_array( $hook_suffix, array( 'jetpack_page_akismet-key-config', 'settings_page_akismet-key-config' ) ) ) {
+ // This page manages the notices and puts them inline where they make sense.
+ return;
+ }
+
+ if ( in_array( $hook_suffix, array( 'edit-comments.php' ) ) && (int) get_option( 'akismet_alert_code' ) > 0 ) {
Akismet::verify_key( Akismet::get_api_key() ); //verify that the key is still in alert state
if ( get_option( 'akismet_alert_code' ) > 0 )
@@ -906,22 +1037,67 @@
elseif ( $hook_suffix == 'edit-comments.php' && wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) {
self::display_spam_check_warning();
}
- elseif ( in_array( $hook_suffix, array( 'jetpack_page_akismet-key-config', 'settings_page_akismet-key-config' ) ) && Akismet::get_api_key() ) {
- self::display_status();
+ else if ( isset( $_GET['akismet_recheck_complete'] ) ) {
+ $recheck_count = (int) $_GET['recheck_count'];
+ $spam_count = (int) $_GET['spam_count'];
+
+ if ( $recheck_count === 0 ) {
+ $message = __( 'There were no comments to check. Akismet will only check comments in the Pending queue.', 'akismet' );
+ }
+ else {
+ $message = sprintf( _n( 'Akismet checked %s comment.', 'Akismet checked %s comments.', $recheck_count, 'akismet' ), number_format( $recheck_count ) );
+ $message .= ' ';
+
+ if ( $spam_count === 0 ) {
+ $message .= __( 'No comments were caught as spam.' );
+ }
+ else {
+ $message .= sprintf( _n( '%s comment was caught as spam.', '%s comments were caught as spam.', $spam_count, 'akismet' ), number_format( $spam_count ) );
+ }
+ }
+
+ echo '
' . esc_html( $message ) . '
';
+ }
+
+ $akismet_comment_form_privacy_notice_option = get_option( 'akismet_comment_form_privacy_notice' );
+ if ( ! in_array( $akismet_comment_form_privacy_notice_option, array( 'hide', 'display' ) ) ) {
+ $api_key = Akismet::get_api_key();
+ if ( ! empty( $api_key ) ) {
+ self::display_privacy_notice_control_warning();
+ }
}
}
public static function display_status() {
- $type = '';
-
- if ( !self::get_server_connectivity() )
- $type = 'servers-be-down';
-
- if ( !empty( $type ) )
- Akismet::view( 'notice', compact( 'type' ) );
- elseif ( !empty( self::$notices ) ) {
- foreach ( self::$notices as $type )
- Akismet::view( 'notice', compact( 'type' ) );
+ if ( ! self::get_server_connectivity() ) {
+ Akismet::view( 'notice', array( 'type' => 'servers-be-down' ) );
+ }
+ else if ( ! empty( self::$notices ) ) {
+ foreach ( self::$notices as $index => $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' ) );
+
+ unset( self::$notices[ $index ] );
+ }
+ }
+ else {
+ Akismet::view( 'notice', compact( 'type' ) );
+
+ unset( self::$notices[ $index ] );
+ }
+ }
}
}
@@ -941,8 +1117,22 @@
if ( !$xml->isError() ) {
$responses = $xml->getResponse();
if ( count( $responses ) > 1 ) {
- $api_key = array_shift( $responses[0] );
- $user_id = (int) array_shift( $responses[1] );
+ // Due to a quirk in how Jetpack does multi-calls, the response order
+ // can't be trusted to match the call order. It's a good thing our
+ // return values can be mostly differentiated from each other.
+ $first_response_value = array_shift( $responses[0] );
+ $second_response_value = array_shift( $responses[1] );
+
+ // If WPCOM ever reaches 100 billion users, this will fail. :-)
+ if ( preg_match( '/^[a-f0-9]{12}$/i', $first_response_value ) ) {
+ $api_key = $first_response_value;
+ $user_id = (int) $second_response_value;
+ }
+ else {
+ $api_key = $second_response_value;
+ $user_id = (int) $first_response_value;
+ }
+
return compact( 'api_key', 'user_id' );
}
}
@@ -964,4 +1154,30 @@
return $exclude;
}
-}
\ No newline at end of file
+
+ /**
+ * When Akismet is active, remove the "Activate Akismet" step from the plugin description.
+ */
+ public static function modify_plugin_description( $all_plugins ) {
+ if ( isset( $all_plugins['akismet/akismet.php'] ) ) {
+ if ( Akismet::get_api_key() ) {
+ $all_plugins['akismet/akismet.php']['Description'] = __( 'Used by millions, Akismet is quite possibly the best way in the world to
protect your blog from spam. Your site is fully configured and being protected, even while you sleep.', 'akismet' );
+ }
+ else {
+ $all_plugins['akismet/akismet.php']['Description'] = __( 'Used by millions, Akismet is quite possibly the best way in the world to
protect your blog from spam. It keeps your site protected even while you sleep. To get started, just go to
your Akismet Settings page to set up your API key.', 'akismet' );
+ }
+ }
+
+ return $all_plugins;
+ }
+
+ private static function set_form_privacy_notice_option( $state ) {
+ if ( in_array( $state, array( 'display', 'hide' ) ) ) {
+ update_option( 'akismet_comment_form_privacy_notice', $state );
+ }
+ }
+
+ public static function jetpack_comment_form_privacy_notice_url( $url ) {
+ return str_replace( 'options-general.php', 'admin.php', $url );
+ }
+}