PluginProbe ʕ •ᴥ•ʔ
Akismet Anti-spam: Spam Protection / 3.3.2
Akismet Anti-spam: Spam Protection v3.3.2
5.7 3.0.4 3.0.5 3.1 3.1.1 3.1.10 3.1.11 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2 3.3 3.3.1 3.3.2 3.3.3 3.3.4 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 5.0 5.0.1 5.0.2 5.1 5.2 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.4 5.5 5.6 trunk 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.4.0 2.4.1 2.5.0 2.5.1 2.5.10 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 3.0.0 3.0.0-RC1 3.0.1 3.0.2 3.0.3
akismet / class.akismet-admin.php
akismet Last commit date
_inc 9 years ago views 9 years ago .htaccess 10 years ago LICENSE.txt 10 years ago akismet.php 9 years ago class.akismet-admin.php 9 years ago class.akismet-cli.php 9 years ago class.akismet-widget.php 9 years ago class.akismet.php 9 years ago index.php 12 years ago readme.txt 8 years ago wrapper.php 9 years ago
class.akismet-admin.php
1100 lines
1 <?php
2
3 class Akismet_Admin {
4 const NONCE = 'akismet-update-key';
5
6 private static $initiated = false;
7 private static $notices = array();
8 private static $allowed = array(
9 'a' => array(
10 'href' => true,
11 'title' => true,
12 ),
13 'b' => array(),
14 'code' => array(),
15 'del' => array(
16 'datetime' => true,
17 ),
18 'em' => array(),
19 'i' => array(),
20 'q' => array(
21 'cite' => true,
22 ),
23 'strike' => array(),
24 'strong' => array(),
25 );
26
27 public static function init() {
28 if ( ! self::$initiated ) {
29 self::init_hooks();
30 }
31
32 if ( isset( $_POST['action'] ) && $_POST['action'] == 'enter-key' ) {
33 self::enter_api_key();
34 }
35 }
36
37 public static function init_hooks() {
38 // The standalone stats page was removed in 3.0 for an all-in-one config and stats page.
39 // Redirect any links that might have been bookmarked or in browser history.
40 if ( isset( $_GET['page'] ) && 'akismet-stats-display' == $_GET['page'] ) {
41 wp_safe_redirect( esc_url_raw( self::get_page_url( 'stats' ) ), 301 );
42 die;
43 }
44
45 self::$initiated = true;
46
47 add_action( 'admin_init', array( 'Akismet_Admin', 'admin_init' ) );
48 add_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 ); # Priority 5, so it's called before Jetpack's admin_menu.
49 add_action( 'admin_notices', array( 'Akismet_Admin', 'display_notice' ) );
50 add_action( 'admin_enqueue_scripts', array( 'Akismet_Admin', 'load_resources' ) );
51 add_action( 'activity_box_end', array( 'Akismet_Admin', 'dashboard_stats' ) );
52 add_action( 'rightnow_end', array( 'Akismet_Admin', 'rightnow_stats' ) );
53 add_action( 'manage_comments_nav', array( 'Akismet_Admin', 'check_for_spam_button' ) );
54 add_action( 'admin_action_akismet_recheck_queue', array( 'Akismet_Admin', 'recheck_queue' ) );
55 add_action( 'wp_ajax_akismet_recheck_queue', array( 'Akismet_Admin', 'recheck_queue' ) );
56 add_action( 'wp_ajax_comment_author_deurl', array( 'Akismet_Admin', 'remove_comment_author_url' ) );
57 add_action( 'wp_ajax_comment_author_reurl', array( 'Akismet_Admin', 'add_comment_author_url' ) );
58 add_action( 'jetpack_auto_activate_akismet', array( 'Akismet_Admin', 'connect_jetpack_user' ) );
59
60 add_filter( 'plugin_action_links', array( 'Akismet_Admin', 'plugin_action_links' ), 10, 2 );
61 add_filter( 'comment_row_actions', array( 'Akismet_Admin', 'comment_row_action' ), 10, 2 );
62
63 add_filter( 'plugin_action_links_'.plugin_basename( plugin_dir_path( __FILE__ ) . 'akismet.php'), array( 'Akismet_Admin', 'admin_plugin_settings_link' ) );
64
65 add_filter( 'wxr_export_skip_commentmeta', array( 'Akismet_Admin', 'exclude_commentmeta_from_export' ), 10, 3 );
66
67 add_filter( 'all_plugins', array( 'Akismet_Admin', 'modify_plugin_description' ) );
68 }
69
70 public static function admin_init() {
71 load_plugin_textdomain( 'akismet' );
72 add_meta_box( 'akismet-status', __('Comment History', 'akismet'), array( 'Akismet_Admin', 'comment_status_meta_box' ), 'comment', 'normal' );
73 }
74
75 public static function admin_menu() {
76 if ( class_exists( 'Jetpack' ) )
77 add_action( 'jetpack_admin_menu', array( 'Akismet_Admin', 'load_menu' ) );
78 else
79 self::load_menu();
80 }
81
82 public static function admin_head() {
83 if ( !current_user_can( 'manage_options' ) )
84 return;
85 }
86
87 public static function admin_plugin_settings_link( $links ) {
88 $settings_link = '<a href="'.esc_url( self::get_page_url() ).'">'.__('Settings', 'akismet').'</a>';
89 array_unshift( $links, $settings_link );
90 return $links;
91 }
92
93 public static function load_menu() {
94 if ( class_exists( 'Jetpack' ) )
95 $hook = add_submenu_page( 'jetpack', __( 'Akismet' , 'akismet'), __( 'Akismet' , 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
96 else
97 $hook = add_options_page( __('Akismet', 'akismet'), __('Akismet', 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
98
99 if ( version_compare( $GLOBALS['wp_version'], '3.3', '>=' ) ) {
100 add_action( "load-$hook", array( 'Akismet_Admin', 'admin_help' ) );
101 }
102 }
103
104 public static function load_resources() {
105 global $hook_suffix;
106
107 if ( in_array( $hook_suffix, apply_filters( 'akismet_admin_page_hook_suffixes', array(
108 'index.php', # dashboard
109 'edit-comments.php',
110 'comment.php',
111 'post.php',
112 'settings_page_akismet-key-config',
113 'jetpack_page_akismet-key-config',
114 'plugins.php',
115 ) ) ) ) {
116 wp_register_style( 'akismet.css', plugin_dir_url( __FILE__ ) . '_inc/akismet.css', array(), AKISMET_VERSION );
117 wp_enqueue_style( 'akismet.css');
118
119 wp_register_script( 'akismet.js', plugin_dir_url( __FILE__ ) . '_inc/akismet.js', array('jquery'), AKISMET_VERSION );
120 wp_enqueue_script( 'akismet.js' );
121
122 $inline_js = array(
123 'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' ),
124 'strings' => array(
125 'Remove this URL' => __( 'Remove this URL' , 'akismet'),
126 'Removing...' => __( 'Removing...' , 'akismet'),
127 'URL removed' => __( 'URL removed' , 'akismet'),
128 '(undo)' => __( '(undo)' , 'akismet'),
129 'Re-adding...' => __( 'Re-adding...' , 'akismet'),
130 )
131 );
132
133 if ( isset( $_GET['akismet_recheck'] ) && wp_verify_nonce( $_GET['akismet_recheck'], 'akismet_recheck' ) ) {
134 $inline_js['start_recheck'] = true;
135 }
136
137 wp_localize_script( 'akismet.js', 'WPAkismet', $inline_js );
138 }
139 }
140
141 /**
142 * Add help to the Akismet page
143 *
144 * @return false if not the Akismet page
145 */
146 public static function admin_help() {
147 $current_screen = get_current_screen();
148
149 // Screen Content
150 if ( current_user_can( 'manage_options' ) ) {
151 if ( !Akismet::get_api_key() || ( isset( $_GET['view'] ) && $_GET['view'] == 'start' ) ) {
152 //setup page
153 $current_screen->add_help_tab(
154 array(
155 'id' => 'overview',
156 'title' => __( 'Overview' , 'akismet'),
157 'content' =>
158 '<p><strong>' . esc_html__( 'Akismet Setup' , 'akismet') . '</strong></p>' .
159 '<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '</p>' .
160 '<p>' . esc_html__( 'On this page, you are able to set up the Akismet plugin.' , 'akismet') . '</p>',
161 )
162 );
163
164 $current_screen->add_help_tab(
165 array(
166 'id' => 'setup-signup',
167 'title' => __( 'New to Akismet' , 'akismet'),
168 'content' =>
169 '<p><strong>' . esc_html__( 'Akismet Setup' , 'akismet') . '</strong></p>' .
170 '<p>' . esc_html__( 'You need to enter an API key to activate the Akismet service on your site.' , 'akismet') . '</p>' .
171 '<p>' . sprintf( __( 'Sign up for an account on %s to get an API Key.' , 'akismet'), '<a href="https://akismet.com/plugin-signup/" target="_blank">Akismet.com</a>' ) . '</p>',
172 )
173 );
174
175 $current_screen->add_help_tab(
176 array(
177 'id' => 'setup-manual',
178 'title' => __( 'Enter an API Key' , 'akismet'),
179 'content' =>
180 '<p><strong>' . esc_html__( 'Akismet Setup' , 'akismet') . '</strong></p>' .
181 '<p>' . esc_html__( 'If you already have an API key' , 'akismet') . '</p>' .
182 '<ol>' .
183 '<li>' . esc_html__( 'Copy and paste the API key into the text field.' , 'akismet') . '</li>' .
184 '<li>' . esc_html__( 'Click the Use this Key button.' , 'akismet') . '</li>' .
185 '</ol>',
186 )
187 );
188 }
189 elseif ( isset( $_GET['view'] ) && $_GET['view'] == 'stats' ) {
190 //stats page
191 $current_screen->add_help_tab(
192 array(
193 'id' => 'overview',
194 'title' => __( 'Overview' , 'akismet'),
195 'content' =>
196 '<p><strong>' . esc_html__( 'Akismet Stats' , 'akismet') . '</strong></p>' .
197 '<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '</p>' .
198 '<p>' . esc_html__( 'On this page, you are able to view stats on spam filtered on your site.' , 'akismet') . '</p>',
199 )
200 );
201 }
202 else {
203 //configuration page
204 $current_screen->add_help_tab(
205 array(
206 'id' => 'overview',
207 'title' => __( 'Overview' , 'akismet'),
208 'content' =>
209 '<p><strong>' . esc_html__( 'Akismet Configuration' , 'akismet') . '</strong></p>' .
210 '<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '</p>' .
211 '<p>' . esc_html__( 'On this page, you are able to enter/remove an API key, view account information and view spam stats.' , 'akismet') . '</p>',
212 )
213 );
214
215 $current_screen->add_help_tab(
216 array(
217 'id' => 'settings',
218 'title' => __( 'Settings' , 'akismet'),
219 'content' =>
220 '<p><strong>' . esc_html__( 'Akismet Configuration' , 'akismet') . '</strong></p>' .
221 '<p><strong>' . esc_html__( 'API Key' , 'akismet') . '</strong> - ' . esc_html__( 'Enter/remove an API key.' , 'akismet') . '</p>' .
222 '<p><strong>' . esc_html__( 'Comments' , 'akismet') . '</strong> - ' . esc_html__( 'Show the number of approved comments beside each comment author in the comments list page.' , 'akismet') . '</p>' .
223 '<p><strong>' . esc_html__( 'Strictness' , 'akismet') . '</strong> - ' . esc_html__( 'Choose to either discard the worst spam automatically or to always put all spam in spam folder.' , 'akismet') . '</p>',
224 )
225 );
226
227 $current_screen->add_help_tab(
228 array(
229 'id' => 'account',
230 'title' => __( 'Account' , 'akismet'),
231 'content' =>
232 '<p><strong>' . esc_html__( 'Akismet Configuration' , 'akismet') . '</strong></p>' .
233 '<p><strong>' . esc_html__( 'Subscription Type' , 'akismet') . '</strong> - ' . esc_html__( 'The Akismet subscription plan' , 'akismet') . '</p>' .
234 '<p><strong>' . esc_html__( 'Status' , 'akismet') . '</strong> - ' . esc_html__( 'The subscription status - active, cancelled or suspended' , 'akismet') . '</p>',
235 )
236 );
237 }
238 }
239
240 // Help Sidebar
241 $current_screen->set_help_sidebar(
242 '<p><strong>' . esc_html__( 'For more information:' , 'akismet') . '</strong></p>' .
243 '<p><a href="https://akismet.com/faq/" target="_blank">' . esc_html__( 'Akismet FAQ' , 'akismet') . '</a></p>' .
244 '<p><a href="https://akismet.com/support/" target="_blank">' . esc_html__( 'Akismet Support' , 'akismet') . '</a></p>'
245 );
246 }
247
248 public static function enter_api_key() {
249 if ( function_exists('current_user_can') && !current_user_can('manage_options') )
250 die(__('Cheatin&#8217; uh?', 'akismet'));
251
252 if ( !wp_verify_nonce( $_POST['_wpnonce'], self::NONCE ) )
253 return false;
254
255 foreach( array( 'akismet_strictness', 'akismet_show_user_comments_approved' ) as $option ) {
256 update_option( $option, isset( $_POST[$option] ) && (int) $_POST[$option] == 1 ? '1' : '0' );
257 }
258
259 if ( defined( 'WPCOM_API_KEY' ) )
260 return false; //shouldn't have option to save key if already defined
261
262 $new_key = preg_replace( '/[^a-f0-9]/i', '', $_POST['key'] );
263 $old_key = Akismet::get_api_key();
264
265 if ( empty( $new_key ) ) {
266 if ( !empty( $old_key ) ) {
267 delete_option( 'wordpress_api_key' );
268 self::$notices[] = 'new-key-empty';
269 }
270 }
271 elseif ( $new_key != $old_key ) {
272 self::save_key( $new_key );
273 }
274
275 return true;
276 }
277
278 public static function save_key( $api_key ) {
279 $key_status = Akismet::verify_key( $api_key );
280
281 if ( $key_status == 'valid' ) {
282 $akismet_user = self::get_akismet_user( $api_key );
283
284 if ( $akismet_user ) {
285 if ( in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) ) )
286 update_option( 'wordpress_api_key', $api_key );
287
288 if ( $akismet_user->status == 'active' )
289 self::$notices['status'] = 'new-key-valid';
290 elseif ( $akismet_user->status == 'notice' )
291 self::$notices['status'] = $akismet_user;
292 else
293 self::$notices['status'] = $akismet_user->status;
294 }
295 else
296 self::$notices['status'] = 'new-key-invalid';
297 }
298 elseif ( in_array( $key_status, array( 'invalid', 'failed' ) ) )
299 self::$notices['status'] = 'new-key-'.$key_status;
300 }
301
302 public static function dashboard_stats() {
303 if ( !function_exists('did_action') || did_action( 'rightnow_end' ) )
304 return; // We already displayed this info in the "Right Now" section
305
306 if ( !$count = get_option('akismet_spam_count') )
307 return;
308
309 global $submenu;
310
311 echo '<h3>' . esc_html( _x( 'Spam', 'comments' , 'akismet') ) . '</h3>';
312
313 echo '<p>'.sprintf( _n(
314 '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comment</a>.',
315 '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.',
316 $count
317 , 'akismet'), 'https://akismet.com/wordpress/', esc_url( add_query_arg( array( 'page' => 'akismet-admin' ), admin_url( isset( $submenu['edit-comments.php'] ) ? 'edit-comments.php' : 'edit.php' ) ) ), number_format_i18n($count) ).'</p>';
318 }
319
320 // WP 2.5+
321 public static function rightnow_stats() {
322 if ( $count = get_option('akismet_spam_count') ) {
323 $intro = sprintf( _n(
324 '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comment already. ',
325 '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comments already. ',
326 $count
327 , 'akismet'), 'https://akismet.com/wordpress/', number_format_i18n( $count ) );
328 } else {
329 $intro = sprintf( __('<a href="%s">Akismet</a> blocks spam from getting to your blog. ', 'akismet'), 'https://akismet.com/wordpress/' );
330 }
331
332 $link = add_query_arg( array( 'comment_status' => 'spam' ), admin_url( 'edit-comments.php' ) );
333
334 if ( $queue_count = self::get_spam_count() ) {
335 $queue_text = sprintf( _n(
336 'There&#8217;s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
337 'There are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
338 $queue_count
339 , 'akismet'), number_format_i18n( $queue_count ), esc_url( $link ) );
340 } else {
341 $queue_text = sprintf( __( "There&#8217;s nothing in your <a href='%s'>spam queue</a> at the moment." , 'akismet'), esc_url( $link ) );
342 }
343
344 $text = $intro . '<br />' . $queue_text;
345 echo "<p class='akismet-right-now'>$text</p>\n";
346 }
347
348 public static function check_for_spam_button( $comment_status ) {
349 // The "Check for Spam" button should only appear when the page might be showing
350 // a comment with comment_approved=0, which means an un-trashed, un-spammed,
351 // not-yet-moderated comment.
352 if ( 'all' != $comment_status && 'moderated' != $comment_status ) {
353 return;
354 }
355
356 if ( function_exists('plugins_url') )
357 $link = add_query_arg( array( 'action' => 'akismet_recheck_queue' ), admin_url( 'admin.php' ) );
358 else
359 $link = add_query_arg( array( 'page' => 'akismet-admin', 'recheckqueue' => 'true', 'noheader' => 'true' ), admin_url( 'edit-comments.php' ) );
360
361 echo '</div>';
362 echo '<div class="alignleft">';
363 echo '<a
364 class="button-secondary checkforspam"
365 href="' . esc_url( $link ) . '"
366 data-active-label="' . esc_attr( __( 'Checking for Spam', 'akismet' ) ) . '"
367 data-progress-label-format="' . esc_attr( __( '(%1$s...)', 'akismet' ) ) . '"
368 data-success-url="' . esc_attr( remove_query_arg( 'akismet_recheck', add_query_arg( array( 'akismet_recheck_complete' => 1, 'recheck_count' => urlencode( '__recheck_count__' ), 'spam_count' => urlencode( '__spam_count__' ) ) ) ) ) . '"
369 >';
370 echo '<span class="akismet-label">' . esc_html__('Check for Spam', 'akismet') . '</span>';
371 echo '<span class="checkforspam-progress"></span>';
372 echo '</a>';
373 echo '<span class="checkforspam-spinner"></span>';
374
375 }
376
377 public static function recheck_queue() {
378 global $wpdb;
379
380 Akismet::fix_scheduled_recheck();
381
382 if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) ) {
383 return;
384 }
385
386 $result_counts = self::recheck_queue_portion( empty( $_POST['offset'] ) ? 0 : $_POST['offset'], empty( $_POST['limit'] ) ? 100 : $_POST['limit'] );
387
388 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
389 wp_send_json( array(
390 'counts' => $result_counts,
391 ));
392 }
393 else {
394 $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : admin_url( 'edit-comments.php' );
395 wp_safe_redirect( $redirect_to );
396 exit;
397 }
398 }
399
400 public static function recheck_queue_portion( $start = 0, $limit = 100 ) {
401 global $wpdb;
402
403 $paginate = '';
404
405 if ( $limit <= 0 ) {
406 $limit = 100;
407 }
408
409 if ( $start < 0 ) {
410 $start = 0;
411 }
412
413 $moderation = $wpdb->get_col( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0' LIMIT %d OFFSET %d", $limit, $start ) );
414
415 $result_counts = array(
416 'processed' => count( $moderation ),
417 'spam' => 0,
418 'ham' => 0,
419 'error' => 0,
420 );
421
422 foreach ( $moderation as $comment_id ) {
423 $api_response = Akismet::recheck_comment( $comment_id, 'recheck_queue' );
424
425 if ( 'true' === $api_response ) {
426 ++$result_counts['spam'];
427 }
428 elseif ( 'false' === $api_response ) {
429 ++$result_counts['ham'];
430 }
431 else {
432 ++$result_counts['error'];
433 }
434 }
435
436 return $result_counts;
437 }
438
439 // Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link
440 public static function remove_comment_author_url() {
441 if ( !empty( $_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
442 $comment_id = intval( $_POST['id'] );
443 $comment = get_comment( $comment_id, ARRAY_A );
444 if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) {
445 $comment['comment_author_url'] = '';
446 do_action( 'comment_remove_author_url' );
447 print( wp_update_comment( $comment ) );
448 die();
449 }
450 }
451 }
452
453 public static function add_comment_author_url() {
454 if ( !empty( $_POST['id'] ) && !empty( $_POST['url'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
455 $comment_id = intval( $_POST['id'] );
456 $comment = get_comment( $comment_id, ARRAY_A );
457 if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) {
458 $comment['comment_author_url'] = esc_url( $_POST['url'] );
459 do_action( 'comment_add_author_url' );
460 print( wp_update_comment( $comment ) );
461 die();
462 }
463 }
464 }
465
466 public static function comment_row_action( $a, $comment ) {
467
468 // failsafe for old WP versions
469 if ( !function_exists('add_comment_meta') )
470 return $a;
471
472 $akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
473 $akismet_error = get_comment_meta( $comment->comment_ID, 'akismet_error', true );
474 $user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
475 $comment_status = wp_get_comment_status( $comment->comment_ID );
476 $desc = null;
477 if ( $akismet_error ) {
478 $desc = __( 'Awaiting spam check' , 'akismet');
479 } elseif ( !$user_result || $user_result == $akismet_result ) {
480 // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
481 if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' )
482 $desc = __( 'Flagged as spam by Akismet' , 'akismet');
483 elseif ( $akismet_result == 'false' && $comment_status == 'spam' )
484 $desc = __( 'Cleared by Akismet' , 'akismet');
485 } else {
486 $who = get_comment_meta( $comment->comment_ID, 'akismet_user', true );
487 if ( $user_result == 'true' )
488 $desc = sprintf( __('Flagged as spam by %s', 'akismet'), $who );
489 else
490 $desc = sprintf( __('Un-spammed by %s', 'akismet'), $who );
491 }
492
493 // add a History item to the hover links, just after Edit
494 if ( $akismet_result ) {
495 $b = array();
496 foreach ( $a as $k => $item ) {
497 $b[ $k ] = $item;
498 if (
499 $k == 'edit'
500 || ( $k == 'unspam' && $GLOBALS['wp_version'] >= 3.4 )
501 ) {
502 $b['history'] = '<a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="'. esc_attr__( 'View comment history' , 'akismet') . '"> '. esc_html__('History', 'akismet') . '</a>';
503 }
504 }
505
506 $a = $b;
507 }
508
509 if ( $desc )
510 echo '<span class="akismet-status" commentid="'.$comment->comment_ID.'"><a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="' . esc_attr__( 'View comment history' , 'akismet') . '">'.esc_html( $desc ).'</a></span>';
511
512 $show_user_comments_option = get_option( 'akismet_show_user_comments_approved' );
513
514 if ( $show_user_comments_option === false ) {
515 // Default to active if the user hasn't made a decision.
516 $show_user_comments_option = '1';
517 }
518
519 $show_user_comments = apply_filters( 'akismet_show_user_comments_approved', $show_user_comments_option );
520 $show_user_comments = $show_user_comments === 'false' ? false : $show_user_comments; //option used to be saved as 'false' / 'true'
521
522 if ( $show_user_comments ) {
523 $comment_count = Akismet::get_user_comments_approved( $comment->user_id, $comment->comment_author_email, $comment->comment_author, $comment->comment_author_url );
524 $comment_count = intval( $comment_count );
525 echo '<span class="akismet-user-comment-count" commentid="'.$comment->comment_ID.'" style="display:none;"><br><span class="akismet-user-comment-counts">'. sprintf( esc_html( _n( '%s approved', '%s approved', $comment_count , 'akismet') ), number_format_i18n( $comment_count ) ) . '</span></span>';
526 }
527
528 return $a;
529 }
530
531 public static function comment_status_meta_box( $comment ) {
532 $history = Akismet::get_comment_history( $comment->comment_ID );
533
534 if ( $history ) {
535 echo '<div class="akismet-history" style="margin: 13px;">';
536
537 foreach ( $history as $row ) {
538 $time = date( 'D d M Y @ h:i:m a', $row['time'] ) . ' GMT';
539
540 $message = '';
541
542 if ( ! empty( $row['message'] ) ) {
543 // Old versions of Akismet stored the message as a literal string in the commentmeta.
544 // New versions don't do that for two reasons:
545 // 1) Save space.
546 // 2) The message can be translated into the current language of the blog, not stuck
547 // in the language of the blog when the comment was made.
548 $message = $row['message'];
549 }
550
551 // If possible, use a current translation.
552 switch ( $row['event'] ) {
553 case 'recheck-spam';
554 $message = __( 'Akismet re-checked and caught this comment as spam.', 'akismet' );
555 break;
556 case 'check-spam':
557 $message = __( 'Akismet caught this comment as spam.', 'akismet' );
558 break;
559 case 'recheck-ham':
560 $message = __( 'Akismet re-checked and cleared this comment.', 'akismet' );
561 break;
562 case 'check-ham':
563 $message = __( 'Akismet cleared this comment.', 'akismet' );
564 break;
565 case 'wp-blacklisted':
566 $message = __( 'Comment was caught by wp_blacklist_check.', 'akismet' );
567 break;
568 case 'report-spam':
569 if ( isset( $row['user'] ) ) {
570 $message = sprintf( __( '%s reported this comment as spam.', 'akismet' ), $row['user'] );
571 }
572 else if ( ! $message ) {
573 $message = __( 'This comment was reported as spam.', 'akismet' );
574 }
575 break;
576 case 'report-ham':
577 if ( isset( $row['user'] ) ) {
578 $message = sprintf( __( '%s reported this comment as not spam.', 'akismet' ), $row['user'] );
579 }
580 else if ( ! $message ) {
581 $message = __( 'This comment was reported as not spam.', 'akismet' );
582 }
583 break;
584 case 'cron-retry-spam':
585 $message = __( 'Akismet caught this comment as spam during an automatic retry.' , 'akismet');
586 break;
587 case 'cron-retry-ham':
588 $message = __( 'Akismet cleared this comment during an automatic retry.', 'akismet');
589 break;
590 case 'check-error':
591 if ( isset( $row['meta'], $row['meta']['response'] ) ) {
592 $message = sprintf( __( 'Akismet was unable to check this comment (response: %s) but will automatically retry later.', 'akismet'), $row['meta']['response'] );
593 }
594 break;
595 case 'recheck-error':
596 if ( isset( $row['meta'], $row['meta']['response'] ) ) {
597 $message = sprintf( __( 'Akismet was unable to recheck this comment (response: %s).', 'akismet'), $row['meta']['response'] );
598 }
599 break;
600 default:
601 if ( preg_match( '/^status-changed/', $row['event'] ) ) {
602 // Half of these used to be saved without the dash after 'status-changed'.
603 // See https://plugins.trac.wordpress.org/changeset/1150658/akismet/trunk
604 $new_status = preg_replace( '/^status-changed-?/', '', $row['event'] );
605 $message = sprintf( __( 'Comment status was changed to %s', 'akismet' ), $new_status );
606 }
607 else if ( preg_match( '/^status-/', $row['event'] ) ) {
608 $new_status = preg_replace( '/^status-/', '', $row['event'] );
609
610 if ( isset( $row['user'] ) ) {
611 $message = sprintf( __( '%1$s changed the comment status to %2$s.', 'akismet' ), $row['user'], $new_status );
612 }
613 }
614 break;
615
616 }
617
618 echo '<div style="margin-bottom: 13px;">';
619 echo '<span style="color: #999;" alt="' . $time . '" title="' . $time . '">' . sprintf( esc_html__('%s ago', 'akismet'), human_time_diff( $row['time'] ) ) . '</span>';
620 echo ' - ';
621 echo esc_html( $message );
622 echo '</div>';
623 }
624
625 echo '</div>';
626 }
627 }
628
629 public static function plugin_action_links( $links, $file ) {
630 if ( $file == plugin_basename( plugin_dir_url( __FILE__ ) . '/akismet.php' ) ) {
631 $links[] = '<a href="' . esc_url( self::get_page_url() ) . '">'.esc_html__( 'Settings' , 'akismet').'</a>';
632 }
633
634 return $links;
635 }
636
637 // Total spam in queue
638 // get_option( 'akismet_spam_count' ) is the total caught ever
639 public static function get_spam_count( $type = false ) {
640 global $wpdb;
641
642 if ( !$type ) { // total
643 $count = wp_cache_get( 'akismet_spam_count', 'widget' );
644 if ( false === $count ) {
645 if ( function_exists('wp_count_comments') ) {
646 $count = wp_count_comments();
647 $count = $count->spam;
648 } else {
649 $count = (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_approved = 'spam'");
650 }
651 wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 );
652 }
653 return $count;
654 } elseif ( 'comments' == $type || 'comment' == $type ) { // comments
655 $type = '';
656 }
657
658 return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_approved = 'spam' AND comment_type = %s", $type ) );
659 }
660
661 // Check connectivity between the WordPress blog and Akismet's servers.
662 // Returns an associative array of server IP addresses, where the key is the IP address, and value is true (available) or false (unable to connect).
663 public static function check_server_ip_connectivity() {
664
665 $servers = $ips = array();
666
667 // Some web hosts may disable this function
668 if ( function_exists('gethostbynamel') ) {
669
670 $ips = gethostbynamel( 'rest.akismet.com' );
671 if ( $ips && is_array($ips) && count($ips) ) {
672 $api_key = Akismet::get_api_key();
673
674 foreach ( $ips as $ip ) {
675 $response = Akismet::verify_key( $api_key, $ip );
676 // even if the key is invalid, at least we know we have connectivity
677 if ( $response == 'valid' || $response == 'invalid' )
678 $servers[$ip] = 'connected';
679 else
680 $servers[$ip] = $response ? $response : 'unable to connect';
681 }
682 }
683 }
684
685 return $servers;
686 }
687
688 // Simpler connectivity check
689 public static function check_server_connectivity($cache_timeout = 86400) {
690
691 $debug = array();
692 $debug[ 'PHP_VERSION' ] = PHP_VERSION;
693 $debug[ 'WORDPRESS_VERSION' ] = $GLOBALS['wp_version'];
694 $debug[ 'AKISMET_VERSION' ] = AKISMET_VERSION;
695 $debug[ 'AKISMET__PLUGIN_DIR' ] = AKISMET__PLUGIN_DIR;
696 $debug[ 'SITE_URL' ] = site_url();
697 $debug[ 'HOME_URL' ] = home_url();
698
699 $servers = get_option('akismet_available_servers');
700 if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false ) {
701 $servers = self::check_server_ip_connectivity();
702 update_option('akismet_available_servers', $servers);
703 update_option('akismet_connectivity_time', time());
704 }
705
706 if ( function_exists( 'wp_http_supports' ) && ( wp_http_supports( array( 'ssl' ) ) ) ) {
707 $response = wp_remote_get( 'https://rest.akismet.com/1.1/test' );
708 }
709 else {
710 $response = wp_remote_get( 'http://rest.akismet.com/1.1/test' );
711 }
712
713 $debug[ 'gethostbynamel' ] = function_exists('gethostbynamel') ? 'exists' : 'not here';
714 $debug[ 'Servers' ] = $servers;
715 $debug[ 'Test Connection' ] = $response;
716
717 Akismet::log( $debug );
718
719 if ( $response && 'connected' == wp_remote_retrieve_body( $response ) )
720 return true;
721
722 return false;
723 }
724
725 // Check the server connectivity and store the available servers in an option.
726 public static function get_server_connectivity($cache_timeout = 86400) {
727 return self::check_server_connectivity( $cache_timeout );
728 }
729
730 public static function get_number_spam_waiting() {
731 global $wpdb;
732 return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'" );
733 }
734
735 public static function get_page_url( $page = 'config' ) {
736
737 $args = array( 'page' => 'akismet-key-config' );
738
739 if ( $page == 'stats' )
740 $args = array( 'page' => 'akismet-key-config', 'view' => 'stats' );
741 elseif ( $page == 'delete_key' )
742 $args = array( 'page' => 'akismet-key-config', 'view' => 'start', 'action' => 'delete-key', '_wpnonce' => wp_create_nonce( self::NONCE ) );
743
744 $url = add_query_arg( $args, class_exists( 'Jetpack' ) ? admin_url( 'admin.php' ) : admin_url( 'options-general.php' ) );
745
746 return $url;
747 }
748
749 public static function get_akismet_user( $api_key ) {
750 $akismet_user = false;
751
752 $subscription_verification = Akismet::http_post( Akismet::build_query( array( 'key' => $api_key, 'blog' => get_option( 'home' ) ) ), 'get-subscription' );
753
754 if ( ! empty( $subscription_verification[1] ) ) {
755 if ( 'invalid' !== $subscription_verification[1] ) {
756 $akismet_user = json_decode( $subscription_verification[1] );
757 }
758 }
759
760 return $akismet_user;
761 }
762
763 public static function get_stats( $api_key ) {
764 $stat_totals = array();
765
766 foreach( array( '6-months', 'all' ) as $interval ) {
767 $response = Akismet::http_post( Akismet::build_query( array( 'blog' => get_option( 'home' ), 'key' => $api_key, 'from' => $interval ) ), 'get-stats' );
768
769 if ( ! empty( $response[1] ) ) {
770 $stat_totals[$interval] = json_decode( $response[1] );
771 }
772 }
773
774 return $stat_totals;
775 }
776
777 public static function verify_wpcom_key( $api_key, $user_id, $extra = array() ) {
778 $akismet_account = Akismet::http_post( Akismet::build_query( array_merge( array(
779 'user_id' => $user_id,
780 'api_key' => $api_key,
781 'get_account_type' => 'true'
782 ), $extra ) ), 'verify-wpcom-key' );
783
784 if ( ! empty( $akismet_account[1] ) )
785 $akismet_account = json_decode( $akismet_account[1] );
786
787 Akismet::log( compact( 'akismet_account' ) );
788
789 return $akismet_account;
790 }
791
792 public static function connect_jetpack_user() {
793
794 if ( $jetpack_user = self::get_jetpack_user() ) {
795 if ( isset( $jetpack_user['user_id'] ) && isset( $jetpack_user['api_key'] ) ) {
796 $akismet_user = self::verify_wpcom_key( $jetpack_user['api_key'], $jetpack_user['user_id'], array( 'action' => 'connect_jetpack_user' ) );
797
798 if ( is_object( $akismet_user ) ) {
799 self::save_key( $akismet_user->api_key );
800 return in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) );
801 }
802 }
803 }
804
805 return false;
806 }
807
808 public static function display_alert() {
809 Akismet::view( 'notice', array(
810 'type' => 'alert',
811 'code' => (int) get_option( 'akismet_alert_code' ),
812 'msg' => get_option( 'akismet_alert_msg' )
813 ) );
814 }
815
816 public static function display_spam_check_warning() {
817 Akismet::fix_scheduled_recheck();
818
819 if ( wp_next_scheduled('akismet_schedule_cron_recheck') > time() && self::get_number_spam_waiting() > 0 ) {
820 $link_text = apply_filters( 'akismet_spam_check_warning_link_text', sprintf( __( 'Please check your <a href="%s">Akismet configuration</a> and contact your web host if problems persist.', 'akismet'), esc_url( self::get_page_url() ) ) );
821 Akismet::view( 'notice', array( 'type' => 'spam-check', 'link_text' => $link_text ) );
822 }
823 }
824
825 public static function display_api_key_warning() {
826 Akismet::view( 'notice', array( 'type' => 'plugin' ) );
827 }
828
829 public static function display_page() {
830 if ( !Akismet::get_api_key() || ( isset( $_GET['view'] ) && $_GET['view'] == 'start' ) )
831 self::display_start_page();
832 elseif ( isset( $_GET['view'] ) && $_GET['view'] == 'stats' )
833 self::display_stats_page();
834 else
835 self::display_configuration_page();
836 }
837
838 public static function display_start_page() {
839 if ( isset( $_GET['action'] ) ) {
840 if ( $_GET['action'] == 'delete-key' ) {
841 if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], self::NONCE ) )
842 delete_option( 'wordpress_api_key' );
843 }
844 }
845
846 if ( $api_key = Akismet::get_api_key() && ( empty( self::$notices['status'] ) || 'existing-key-invalid' != self::$notices['status'] ) ) {
847 self::display_configuration_page();
848 return;
849 }
850
851 //the user can choose to auto connect their API key by clicking a button on the akismet done page
852 //if jetpack, get verified api key by using connected wpcom user id
853 //if no jetpack, get verified api key by using an akismet token
854
855 $akismet_user = false;
856
857 if ( isset( $_GET['token'] ) && preg_match('/^(\d+)-[0-9a-f]{20}$/', $_GET['token'] ) )
858 $akismet_user = self::verify_wpcom_key( '', '', array( 'token' => $_GET['token'] ) );
859 elseif ( $jetpack_user = self::get_jetpack_user() )
860 $akismet_user = self::verify_wpcom_key( $jetpack_user['api_key'], $jetpack_user['user_id'] );
861
862 if ( isset( $_GET['action'] ) ) {
863 if ( $_GET['action'] == 'save-key' ) {
864 if ( is_object( $akismet_user ) ) {
865 self::save_key( $akismet_user->api_key );
866 self::display_configuration_page();
867 return;
868 }
869 }
870 }
871
872 Akismet::view( 'start', compact( 'akismet_user' ) );
873
874 /*
875 // To see all variants when testing.
876 $akismet_user->status = 'no-sub';
877 Akismet::view( 'start', compact( 'akismet_user' ) );
878 $akismet_user->status = 'cancelled';
879 Akismet::view( 'start', compact( 'akismet_user' ) );
880 $akismet_user->status = 'suspended';
881 Akismet::view( 'start', compact( 'akismet_user' ) );
882 $akismet_user->status = 'other';
883 Akismet::view( 'start', compact( 'akismet_user' ) );
884 $akismet_user = false;
885 */
886 }
887
888 public static function display_stats_page() {
889 Akismet::view( 'stats' );
890 }
891
892 public static function display_configuration_page() {
893 $api_key = Akismet::get_api_key();
894 $akismet_user = self::get_akismet_user( $api_key );
895
896 if ( ! $akismet_user ) {
897 // This could happen if the user's key became invalid after it was previously valid and successfully set up.
898 self::$notices['status'] = 'existing-key-invalid';
899 self::display_start_page();
900 return;
901 }
902
903 $stat_totals = self::get_stats( $api_key );
904
905 // If unset, create the new strictness option using the old discard option to determine its default.
906 // If the old option wasn't set, default to discarding the blatant spam.
907 if ( get_option( 'akismet_strictness' ) === false ) {
908 add_option( 'akismet_strictness', ( get_option( 'akismet_discard_month' ) === 'false' ? '0' : '1' ) );
909 }
910
911 $notices = array();
912
913 if ( empty( self::$notices ) ) {
914 if ( ! empty( $stat_totals['all'] ) && isset( $stat_totals['all']->time_saved ) && $akismet_user->status == 'active' && $akismet_user->account_type == 'free-api-key' ) {
915
916 $time_saved = false;
917
918 if ( $stat_totals['all']->time_saved > 1800 ) {
919 $total_in_minutes = round( $stat_totals['all']->time_saved / 60 );
920 $total_in_hours = round( $total_in_minutes / 60 );
921 $total_in_days = round( $total_in_hours / 8 );
922 $cleaning_up = __( 'Cleaning up spam takes time.' , 'akismet');
923
924 if ( $total_in_days > 1 )
925 $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 ) );
926 elseif ( $total_in_hours > 1 )
927 $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 );
928 elseif ( $total_in_minutes >= 30 )
929 $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 );
930 }
931
932 $notices[] = array( 'type' => 'active-notice', 'time_saved' => $time_saved );
933 }
934
935 if ( !empty( $akismet_user->limit_reached ) && in_array( $akismet_user->limit_reached, array( 'yellow', 'red' ) ) ) {
936 $notices[] = array( 'type' => 'limit-reached', 'level' => $akismet_user->limit_reached );
937 }
938 }
939
940 if ( !isset( self::$notices['status'] ) && in_array( $akismet_user->status, array( 'cancelled', 'suspended', 'missing', 'no-sub' ) ) ) {
941 $notices[] = array( 'type' => $akismet_user->status );
942 }
943
944 /*
945 // To see all variants when testing.
946 $notices[] = array( 'type' => 'active-notice', 'time_saved' => 'Cleaning up spam takes time. Akismet has saved you 1 minute!' );
947 $notices[] = array( 'type' => 'plugin' );
948 $notices[] = array( 'type' => 'spam-check', 'link_text' => 'Link text.' );
949 $notices[] = array( 'type' => 'notice', 'notice_header' => 'This is the notice header.', 'notice_text' => 'This is the notice text.' );
950 $notices[] = array( 'type' => 'missing-functions' );
951 $notices[] = array( 'type' => 'servers-be-down' );
952 $notices[] = array( 'type' => 'active-dunning' );
953 $notices[] = array( 'type' => 'cancelled' );
954 $notices[] = array( 'type' => 'suspended' );
955 $notices[] = array( 'type' => 'missing' );
956 $notices[] = array( 'type' => 'no-sub' );
957 $notices[] = array( 'type' => 'new-key-valid' );
958 $notices[] = array( 'type' => 'new-key-invalid' );
959 $notices[] = array( 'type' => 'existing-key-invalid' );
960 $notices[] = array( 'type' => 'new-key-failed' );
961 $notices[] = array( 'type' => 'limit-reached', 'level' => 'yellow' );
962 $notices[] = array( 'type' => 'limit-reached', 'level' => 'red' );
963 */
964
965 Akismet::log( compact( 'stat_totals', 'akismet_user' ) );
966 Akismet::view( 'config', compact( 'api_key', 'akismet_user', 'stat_totals', 'notices' ) );
967 }
968
969 public static function display_notice() {
970 global $hook_suffix;
971
972 if ( in_array( $hook_suffix, array( 'jetpack_page_akismet-key-config', 'settings_page_akismet-key-config' ) ) ) {
973 // This page manages the notices and puts them inline where they make sense.
974 return;
975 }
976
977 if ( in_array( $hook_suffix, array( 'edit-comments.php' ) ) && (int) get_option( 'akismet_alert_code' ) > 0 ) {
978 Akismet::verify_key( Akismet::get_api_key() ); //verify that the key is still in alert state
979
980 if ( get_option( 'akismet_alert_code' ) > 0 )
981 self::display_alert();
982 }
983 elseif ( $hook_suffix == 'plugins.php' && !Akismet::get_api_key() ) {
984 self::display_api_key_warning();
985 }
986 elseif ( $hook_suffix == 'edit-comments.php' && wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) {
987 self::display_spam_check_warning();
988 }
989 else if ( isset( $_GET['akismet_recheck_complete'] ) ) {
990 $recheck_count = (int) $_GET['recheck_count'];
991 $spam_count = (int) $_GET['spam_count'];
992
993 if ( $recheck_count === 0 ) {
994 $message = __( 'There were no comments to check. Akismet will only check comments in the Pending queue.', 'akismet' );
995 }
996 else {
997 $message = sprintf( _n( 'Akismet checked %s comment.', 'Akismet checked %s comments.', $recheck_count, 'akismet' ), number_format( $recheck_count ) );
998 $message .= ' ';
999
1000 if ( $spam_count === 0 ) {
1001 $message .= __( 'No comments were caught as spam.' );
1002 }
1003 else {
1004 $message .= sprintf( _n( '%s comment was caught as spam.', '%s comments were caught as spam.', $spam_count, 'akismet' ), number_format( $spam_count ) );
1005 }
1006 }
1007
1008 echo '<div class="notice notice-success"><p>' . esc_html( $message ) . '</p></div>';
1009 }
1010 }
1011
1012 public static function display_status() {
1013 if ( ! self::get_server_connectivity() ) {
1014 Akismet::view( 'notice', compact( 'servers-be-down' ) );
1015 }
1016 else if ( ! empty( self::$notices ) ) {
1017 foreach ( self::$notices as $index => $type ) {
1018 if ( is_object( $type ) ) {
1019 $notice_header = $notice_text = '';
1020
1021 if ( property_exists( $type, 'notice_header' ) ) {
1022 $notice_header = wp_kses( $type->notice_header, self::$allowed );
1023 }
1024
1025 if ( property_exists( $type, 'notice_text' ) ) {
1026 $notice_text = wp_kses( $type->notice_text, self::$allowed );
1027 }
1028
1029 if ( property_exists( $type, 'status' ) ) {
1030 $type = wp_kses( $type->status, self::$allowed );
1031 Akismet::view( 'notice', compact( 'type', 'notice_header', 'notice_text' ) );
1032
1033 unset( self::$notices[ $index ] );
1034 }
1035 }
1036 else {
1037 Akismet::view( 'notice', compact( 'type' ) );
1038
1039 unset( self::$notices[ $index ] );
1040 }
1041 }
1042 }
1043 }
1044
1045 private static function get_jetpack_user() {
1046 if ( !class_exists('Jetpack') )
1047 return false;
1048
1049 Jetpack::load_xml_rpc_client();
1050 $xml = new Jetpack_IXR_ClientMulticall( array( 'user_id' => get_current_user_id() ) );
1051
1052 $xml->addCall( 'wpcom.getUserID' );
1053 $xml->addCall( 'akismet.getAPIKey' );
1054 $xml->query();
1055
1056 Akismet::log( compact( 'xml' ) );
1057
1058 if ( !$xml->isError() ) {
1059 $responses = $xml->getResponse();
1060 if ( count( $responses ) > 1 ) {
1061 $api_key = array_shift( $responses[0] );
1062 $user_id = (int) array_shift( $responses[1] );
1063 return compact( 'api_key', 'user_id' );
1064 }
1065 }
1066 return false;
1067 }
1068
1069 /**
1070 * Some commentmeta isn't useful in an export file. Suppress it (when supported).
1071 *
1072 * @param bool $exclude
1073 * @param string $key The meta key
1074 * @param object $meta The meta object
1075 * @return bool Whether to exclude this meta entry from the export.
1076 */
1077 public static function exclude_commentmeta_from_export( $exclude, $key, $meta ) {
1078 if ( in_array( $key, array( 'akismet_as_submitted', 'akismet_rechecking', 'akismet_delayed_moderation_email' ) ) ) {
1079 return true;
1080 }
1081
1082 return $exclude;
1083 }
1084
1085 /**
1086 * When Akismet is active, remove the "Activate Akismet" step from the plugin description.
1087 */
1088 public static function modify_plugin_description( $all_plugins ) {
1089 if ( isset( $all_plugins['akismet/akismet.php'] ) ) {
1090 if ( Akismet::get_api_key() ) {
1091 $all_plugins['akismet/akismet.php']['Description'] = __( 'Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. Your site is fully configured and being protected, even while you sleep.', 'akismet' );
1092 }
1093 else {
1094 $all_plugins['akismet/akismet.php']['Description'] = __( 'Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. It keeps your site protected even while you sleep. To get started, just go to <a href="admin.php?page=akismet-key-config">your Akismet Settings page</a> to set up your API key.', 'akismet' );
1095 }
1096 }
1097
1098 return $all_plugins;
1099 }
1100 }