├── akismet ├── index.php ├── _inc │ ├── img │ │ ├── logo-a-2x.png │ │ └── logo-full-2x.png │ ├── akismet.js │ └── akismet.css ├── views │ ├── title.php │ ├── activate.php │ ├── setup.php │ ├── predefined.php │ ├── stats.php │ ├── get.php │ ├── enter.php │ ├── start.php │ ├── connect-jp.php │ ├── config.php │ └── notice.php ├── akismet.php ├── class.akismet-widget.php ├── readme.txt ├── class.akismet-cli.php ├── wrapper.php ├── class.akismet-rest-api.php ├── LICENSE.txt ├── changelog.txt └── class.akismet-admin.php ├── index.php └── hello.php /akismet/index.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | -------------------------------------------------------------------------------- /akismet/views/activate.php: -------------------------------------------------------------------------------- 1 | 5 |%s %s
', 62 | __( 'Quote from Hello Dolly song, by Jerry Herman:' ), 63 | $lang, 64 | $chosen 65 | ); 66 | } 67 | 68 | // Now we set that function up to execute when the admin_notices action is called. 69 | add_action( 'admin_notices', 'hello_dolly' ); 70 | 71 | // We need some CSS to position the paragraph. 72 | function dolly_css() { 73 | echo " 74 | 97 | "; 98 | } 99 | 100 | add_action( 'admin_head', 'dolly_css' ); 101 | -------------------------------------------------------------------------------- /akismet/class.akismet-widget.php: -------------------------------------------------------------------------------- 1 | __( 'Display the number of spam comments Akismet has caught' , 'akismet') ) 14 | ); 15 | 16 | if ( is_active_widget( false, false, $this->id_base ) ) { 17 | add_action( 'wp_head', array( $this, 'css' ) ); 18 | } 19 | } 20 | 21 | function css() { 22 | ?> 23 | 24 | 60 | 61 | 72 | 73 |74 | 75 | 76 |
77 | 78 | 100 | 101 | 126 | 127 | 7 | 69 |24 | 25 | 26 | 27 | 28 |
32 | 33 |
https://akismet.com/errors/' . $code . '' ); 37 | 38 | ?> 39 |
40 |' . esc_html__( 'Akismet Setup' , 'akismet') . '
' . 182 | '' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '
' . 183 | '' . esc_html__( 'On this page, you are able to set up the Akismet plugin.' , 'akismet') . '
', 184 | ) 185 | ); 186 | 187 | $current_screen->add_help_tab( 188 | array( 189 | 'id' => 'setup-signup', 190 | 'title' => __( 'New to Akismet' , 'akismet'), 191 | 'content' => 192 | '' . esc_html__( 'Akismet Setup' , 'akismet') . '
' . 193 | '' . esc_html__( 'You need to enter an API key to activate the Akismet service on your site.' , 'akismet') . '
' . 194 | '' . sprintf( __( 'Sign up for an account on %s to get an API Key.' , 'akismet'), 'Akismet.com' ) . '
', 195 | ) 196 | ); 197 | 198 | $current_screen->add_help_tab( 199 | array( 200 | 'id' => 'setup-manual', 201 | 'title' => __( 'Enter an API Key' , 'akismet'), 202 | 'content' => 203 | '' . esc_html__( 'Akismet Setup' , 'akismet') . '
' . 204 | '' . esc_html__( 'If you already have an API key' , 'akismet') . '
' . 205 | '' . esc_html__( 'Akismet Stats' , 'akismet') . '
' . 220 | '' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '
' . 221 | '' . esc_html__( 'On this page, you are able to view stats on spam filtered on your site.' , 'akismet') . '
', 222 | ) 223 | ); 224 | } 225 | else { 226 | //configuration page 227 | $current_screen->add_help_tab( 228 | array( 229 | 'id' => 'overview', 230 | 'title' => __( 'Overview' , 'akismet'), 231 | 'content' => 232 | '' . esc_html__( 'Akismet Configuration' , 'akismet') . '
' . 233 | '' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '
' . 234 | '' . esc_html__( 'On this page, you are able to update your Akismet settings and view spam stats.' , 'akismet') . '
', 235 | ) 236 | ); 237 | 238 | $current_screen->add_help_tab( 239 | array( 240 | 'id' => 'settings', 241 | 'title' => __( 'Settings' , 'akismet'), 242 | 'content' => 243 | '' . esc_html__( 'Akismet Configuration' , 'akismet') . '
' . 244 | ( Akismet::predefined_api_key() ? '' : '' . esc_html__( 'API Key' , 'akismet') . ' - ' . esc_html__( 'Enter/remove an API key.' , 'akismet') . '
' ) . 245 | '' . esc_html__( 'Comments' , 'akismet') . ' - ' . esc_html__( 'Show the number of approved comments beside each comment author in the comments list page.' , 'akismet') . '
' . 246 | '' . esc_html__( 'Strictness' , 'akismet') . ' - ' . esc_html__( 'Choose to either discard the worst spam automatically or to always put all spam in spam folder.' , 'akismet') . '
', 247 | ) 248 | ); 249 | 250 | if ( ! Akismet::predefined_api_key() ) { 251 | $current_screen->add_help_tab( 252 | array( 253 | 'id' => 'account', 254 | 'title' => __( 'Account' , 'akismet'), 255 | 'content' => 256 | '' . esc_html__( 'Akismet Configuration' , 'akismet') . '
' . 257 | '' . esc_html__( 'Subscription Type' , 'akismet') . ' - ' . esc_html__( 'The Akismet subscription plan' , 'akismet') . '
' . 258 | '' . esc_html__( 'Status' , 'akismet') . ' - ' . esc_html__( 'The subscription status - active, cancelled or suspended' , 'akismet') . '
', 259 | ) 260 | ); 261 | } 262 | } 263 | } 264 | 265 | // Help Sidebar 266 | $current_screen->set_help_sidebar( 267 | '' . esc_html__( 'For more information:' , 'akismet') . '
' . 268 | '' . esc_html__( 'Akismet FAQ' , 'akismet') . '
' . 269 | '' . esc_html__( 'Akismet Support' , 'akismet') . '
' 270 | ); 271 | } 272 | 273 | public static function enter_api_key() { 274 | if ( ! current_user_can( 'manage_options' ) ) { 275 | die( __( 'Cheatin’ uh?', 'akismet' ) ); 276 | } 277 | 278 | if ( !wp_verify_nonce( $_POST['_wpnonce'], self::NONCE ) ) 279 | return false; 280 | 281 | foreach( array( 'akismet_strictness', 'akismet_show_user_comments_approved' ) as $option ) { 282 | update_option( $option, isset( $_POST[$option] ) && (int) $_POST[$option] == 1 ? '1' : '0' ); 283 | } 284 | 285 | if ( ! empty( $_POST['akismet_comment_form_privacy_notice'] ) ) { 286 | self::set_form_privacy_notice_option( $_POST['akismet_comment_form_privacy_notice'] ); 287 | } else { 288 | self::set_form_privacy_notice_option( 'hide' ); 289 | } 290 | 291 | if ( Akismet::predefined_api_key() ) { 292 | return false; //shouldn't have option to save key if already defined 293 | } 294 | 295 | $new_key = preg_replace( '/[^a-f0-9]/i', '', $_POST['key'] ); 296 | $old_key = Akismet::get_api_key(); 297 | 298 | if ( empty( $new_key ) ) { 299 | if ( !empty( $old_key ) ) { 300 | delete_option( 'wordpress_api_key' ); 301 | self::$notices[] = 'new-key-empty'; 302 | } 303 | } 304 | elseif ( $new_key != $old_key ) { 305 | self::save_key( $new_key ); 306 | } 307 | 308 | return true; 309 | } 310 | 311 | public static function save_key( $api_key ) { 312 | $key_status = Akismet::verify_key( $api_key ); 313 | 314 | if ( $key_status == 'valid' ) { 315 | $akismet_user = self::get_akismet_user( $api_key ); 316 | 317 | if ( $akismet_user ) { 318 | if ( in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) ) ) 319 | update_option( 'wordpress_api_key', $api_key ); 320 | 321 | if ( $akismet_user->status == 'active' ) 322 | self::$notices['status'] = 'new-key-valid'; 323 | elseif ( $akismet_user->status == 'notice' ) 324 | self::$notices['status'] = $akismet_user; 325 | else 326 | self::$notices['status'] = $akismet_user->status; 327 | } 328 | else 329 | self::$notices['status'] = 'new-key-invalid'; 330 | } 331 | elseif ( in_array( $key_status, array( 'invalid', 'failed' ) ) ) 332 | self::$notices['status'] = 'new-key-'.$key_status; 333 | } 334 | 335 | public static function dashboard_stats() { 336 | if ( did_action( 'rightnow_end' ) ) { 337 | return; // We already displayed this info in the "Right Now" section 338 | } 339 | 340 | if ( !$count = get_option('akismet_spam_count') ) 341 | return; 342 | 343 | global $submenu; 344 | 345 | echo ''.sprintf( _n( 348 | 'Akismet has protected your site from %3$s spam comment.', 349 | 'Akismet has protected your site from %3$s spam comments.', 350 | $count 351 | , '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) ).'
'; 352 | } 353 | 354 | // WP 2.5+ 355 | public static function rightnow_stats() { 356 | if ( $count = get_option('akismet_spam_count') ) { 357 | $intro = sprintf( _n( 358 | 'Akismet has protected your site from %2$s spam comment already. ', 359 | 'Akismet has protected your site from %2$s spam comments already. ', 360 | $count 361 | , 'akismet'), 'https://akismet.com/wordpress/', number_format_i18n( $count ) ); 362 | } else { 363 | $intro = sprintf( __('Akismet blocks spam from getting to your blog. ', 'akismet'), 'https://akismet.com/wordpress/' ); 364 | } 365 | 366 | $link = add_query_arg( array( 'comment_status' => 'spam' ), admin_url( 'edit-comments.php' ) ); 367 | 368 | if ( $queue_count = self::get_spam_count() ) { 369 | $queue_text = sprintf( _n( 370 | 'There’s %1$s comment in your spam queue right now.', 371 | 'There are %1$s comments in your spam queue right now.', 372 | $queue_count 373 | , 'akismet'), number_format_i18n( $queue_count ), esc_url( $link ) ); 374 | } else { 375 | $queue_text = sprintf( __( "There’s nothing in your spam queue at the moment." , 'akismet'), esc_url( $link ) ); 376 | } 377 | 378 | $text = $intro . 'wp_check_comment_disallowed_list' : 'wp_blacklist_check'
620 | );
621 | break;
622 | case 'report-spam':
623 | if ( isset( $row['user'] ) ) {
624 | $message = esc_html( sprintf( __( '%s reported this comment as spam.', 'akismet' ), $row['user'] ) );
625 | }
626 | else if ( ! $message ) {
627 | $message = esc_html( __( 'This comment was reported as spam.', 'akismet' ) );
628 | }
629 | break;
630 | case 'report-ham':
631 | if ( isset( $row['user'] ) ) {
632 | $message = esc_html( sprintf( __( '%s reported this comment as not spam.', 'akismet' ), $row['user'] ) );
633 | }
634 | else if ( ! $message ) {
635 | $message = esc_html( __( 'This comment was reported as not spam.', 'akismet' ) );
636 | }
637 | break;
638 | case 'cron-retry-spam':
639 | $message = esc_html( __( 'Akismet caught this comment as spam during an automatic retry.' , 'akismet') );
640 | break;
641 | case 'cron-retry-ham':
642 | $message = esc_html( __( 'Akismet cleared this comment during an automatic retry.', 'akismet') );
643 | break;
644 | case 'check-error':
645 | if ( isset( $row['meta'], $row['meta']['response'] ) ) {
646 | $message = sprintf( esc_html( __( 'Akismet was unable to check this comment (response: %s) but will automatically retry later.', 'akismet') ), '' . esc_html( $row['meta']['response'] ) . '' );
647 | }
648 | else {
649 | $message = esc_html( __( 'Akismet was unable to check this comment but will automatically retry later.', 'akismet' ) );
650 | }
651 | break;
652 | case 'recheck-error':
653 | if ( isset( $row['meta'], $row['meta']['response'] ) ) {
654 | $message = sprintf( esc_html( __( 'Akismet was unable to recheck this comment (response: %s).', 'akismet') ), '' . esc_html( $row['meta']['response'] ) . '' );
655 | }
656 | else {
657 | $message = esc_html( __( 'Akismet was unable to recheck this comment.', 'akismet' ) );
658 | }
659 | break;
660 | default:
661 | if ( preg_match( '/^status-changed/', $row['event'] ) ) {
662 | // Half of these used to be saved without the dash after 'status-changed'.
663 | // See https://plugins.trac.wordpress.org/changeset/1150658/akismet/trunk
664 | $new_status = preg_replace( '/^status-changed-?/', '', $row['event'] );
665 | $message = sprintf( esc_html( __( 'Comment status was changed to %s', 'akismet' ) ), '' . esc_html( $new_status ) . '' );
666 | }
667 | else if ( preg_match( '/^status-/', $row['event'] ) ) {
668 | $new_status = preg_replace( '/^status-/', '', $row['event'] );
669 |
670 | if ( isset( $row['user'] ) ) {
671 | $message = sprintf( esc_html( __( '%1$s changed the comment status to %2$s.', 'akismet' ) ), $row['user'], '' . esc_html( $new_status ) . '' );
672 | }
673 | }
674 | break;
675 |
676 | }
677 |
678 | if ( ! empty( $message ) ) {
679 | echo ''; 680 | echo '' . sprintf( esc_html__('%s ago', 'akismet'), human_time_diff( $row['time'] ) ) . ''; 681 | echo ' - '; 682 | echo $message; // esc_html() is done above so that we can use HTML in some messages. 683 | echo '
'; 684 | } 685 | } 686 | } 687 | else { 688 | echo ''; 689 | echo esc_html( __( 'No comment history.', 'akismet' ) ); 690 | echo '
'; 691 | } 692 | } 693 | 694 | public static function plugin_action_links( $links, $file ) { 695 | if ( $file == plugin_basename( plugin_dir_url( __FILE__ ) . '/akismet.php' ) ) { 696 | $links[] = ''.esc_html__( 'Settings' , 'akismet').''; 697 | } 698 | 699 | return $links; 700 | } 701 | 702 | // Total spam in queue 703 | // get_option( 'akismet_spam_count' ) is the total caught ever 704 | public static function get_spam_count( $type = false ) { 705 | global $wpdb; 706 | 707 | if ( !$type ) { // total 708 | $count = wp_cache_get( 'akismet_spam_count', 'widget' ); 709 | if ( false === $count ) { 710 | $count = wp_count_comments(); 711 | $count = $count->spam; 712 | wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 ); 713 | } 714 | return $count; 715 | } elseif ( 'comments' == $type || 'comment' == $type ) { // comments 716 | $type = ''; 717 | } 718 | 719 | return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_approved = 'spam' AND comment_type = %s", $type ) ); 720 | } 721 | 722 | // Check connectivity between the WordPress blog and Akismet's servers. 723 | // 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). 724 | public static function check_server_ip_connectivity() { 725 | 726 | $servers = $ips = array(); 727 | 728 | // Some web hosts may disable this function 729 | if ( function_exists('gethostbynamel') ) { 730 | 731 | $ips = gethostbynamel( 'rest.akismet.com' ); 732 | if ( $ips && is_array($ips) && count($ips) ) { 733 | $api_key = Akismet::get_api_key(); 734 | 735 | foreach ( $ips as $ip ) { 736 | $response = Akismet::verify_key( $api_key, $ip ); 737 | // even if the key is invalid, at least we know we have connectivity 738 | if ( $response == 'valid' || $response == 'invalid' ) 739 | $servers[$ip] = 'connected'; 740 | else 741 | $servers[$ip] = $response ? $response : 'unable to connect'; 742 | } 743 | } 744 | } 745 | 746 | return $servers; 747 | } 748 | 749 | // Simpler connectivity check 750 | public static function check_server_connectivity($cache_timeout = 86400) { 751 | 752 | $debug = array(); 753 | $debug[ 'PHP_VERSION' ] = PHP_VERSION; 754 | $debug[ 'WORDPRESS_VERSION' ] = $GLOBALS['wp_version']; 755 | $debug[ 'AKISMET_VERSION' ] = AKISMET_VERSION; 756 | $debug[ 'AKISMET__PLUGIN_DIR' ] = AKISMET__PLUGIN_DIR; 757 | $debug[ 'SITE_URL' ] = site_url(); 758 | $debug[ 'HOME_URL' ] = home_url(); 759 | 760 | $servers = get_option('akismet_available_servers'); 761 | if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false ) { 762 | $servers = self::check_server_ip_connectivity(); 763 | update_option('akismet_available_servers', $servers); 764 | update_option('akismet_connectivity_time', time()); 765 | } 766 | 767 | if ( wp_http_supports( array( 'ssl' ) ) ) { 768 | $response = wp_remote_get( 'https://rest.akismet.com/1.1/test' ); 769 | } 770 | else { 771 | $response = wp_remote_get( 'http://rest.akismet.com/1.1/test' ); 772 | } 773 | 774 | $debug[ 'gethostbynamel' ] = function_exists('gethostbynamel') ? 'exists' : 'not here'; 775 | $debug[ 'Servers' ] = $servers; 776 | $debug[ 'Test Connection' ] = $response; 777 | 778 | Akismet::log( $debug ); 779 | 780 | if ( $response && 'connected' == wp_remote_retrieve_body( $response ) ) 781 | return true; 782 | 783 | return false; 784 | } 785 | 786 | // Check the server connectivity and store the available servers in an option. 787 | public static function get_server_connectivity($cache_timeout = 86400) { 788 | return self::check_server_connectivity( $cache_timeout ); 789 | } 790 | 791 | /** 792 | * Find out whether any comments in the Pending queue have not yet been checked by Akismet. 793 | * 794 | * @return bool 795 | */ 796 | public static function are_any_comments_waiting_to_be_checked() { 797 | return !! get_comments( array( 798 | // Exclude comments that are not pending. This would happen if someone manually approved or spammed a comment 799 | // that was waiting to be checked. The akismet_error meta entry will eventually be removed by the cron recheck job. 800 | 'status' => 'hold', 801 | 802 | // This is the commentmeta that is saved when a comment couldn't be checked. 803 | 'meta_key' => 'akismet_error', 804 | 805 | // We only need to know whether at least one comment is waiting for a check. 806 | 'number' => 1, 807 | ) ); 808 | } 809 | 810 | public static function get_page_url( $page = 'config' ) { 811 | 812 | $args = array( 'page' => 'akismet-key-config' ); 813 | 814 | if ( $page == 'stats' ) 815 | $args = array( 'page' => 'akismet-key-config', 'view' => 'stats' ); 816 | elseif ( $page == 'delete_key' ) 817 | $args = array( 'page' => 'akismet-key-config', 'view' => 'start', 'action' => 'delete-key', '_wpnonce' => wp_create_nonce( self::NONCE ) ); 818 | 819 | $url = add_query_arg( $args, class_exists( 'Jetpack' ) ? admin_url( 'admin.php' ) : admin_url( 'options-general.php' ) ); 820 | 821 | return $url; 822 | } 823 | 824 | public static function get_akismet_user( $api_key ) { 825 | $akismet_user = false; 826 | 827 | $subscription_verification = Akismet::http_post( Akismet::build_query( array( 'key' => $api_key, 'blog' => get_option( 'home' ) ) ), 'get-subscription' ); 828 | 829 | if ( ! empty( $subscription_verification[1] ) ) { 830 | if ( 'invalid' !== $subscription_verification[1] ) { 831 | $akismet_user = json_decode( $subscription_verification[1] ); 832 | } 833 | } 834 | 835 | return $akismet_user; 836 | } 837 | 838 | public static function get_stats( $api_key ) { 839 | $stat_totals = array(); 840 | 841 | foreach( array( '6-months', 'all' ) as $interval ) { 842 | $response = Akismet::http_post( Akismet::build_query( array( 'blog' => get_option( 'home' ), 'key' => $api_key, 'from' => $interval ) ), 'get-stats' ); 843 | 844 | if ( ! empty( $response[1] ) ) { 845 | $stat_totals[$interval] = json_decode( $response[1] ); 846 | } 847 | } 848 | 849 | return $stat_totals; 850 | } 851 | 852 | public static function verify_wpcom_key( $api_key, $user_id, $extra = array() ) { 853 | $akismet_account = Akismet::http_post( Akismet::build_query( array_merge( array( 854 | 'user_id' => $user_id, 855 | 'api_key' => $api_key, 856 | 'get_account_type' => 'true' 857 | ), $extra ) ), 'verify-wpcom-key' ); 858 | 859 | if ( ! empty( $akismet_account[1] ) ) 860 | $akismet_account = json_decode( $akismet_account[1] ); 861 | 862 | Akismet::log( compact( 'akismet_account' ) ); 863 | 864 | return $akismet_account; 865 | } 866 | 867 | public static function connect_jetpack_user() { 868 | 869 | if ( $jetpack_user = self::get_jetpack_user() ) { 870 | if ( isset( $jetpack_user['user_id'] ) && isset( $jetpack_user['api_key'] ) ) { 871 | $akismet_user = self::verify_wpcom_key( $jetpack_user['api_key'], $jetpack_user['user_id'], array( 'action' => 'connect_jetpack_user' ) ); 872 | 873 | if ( is_object( $akismet_user ) ) { 874 | self::save_key( $akismet_user->api_key ); 875 | return in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) ); 876 | } 877 | } 878 | } 879 | 880 | return false; 881 | } 882 | 883 | public static function display_alert() { 884 | Akismet::view( 'notice', array( 885 | 'type' => 'alert', 886 | 'code' => (int) get_option( 'akismet_alert_code' ), 887 | 'msg' => get_option( 'akismet_alert_msg' ) 888 | ) ); 889 | } 890 | 891 | public static function get_usage_limit_alert_data() { 892 | return array( 893 | 'type' => 'usage-limit', 894 | 'code' => (int) get_option( 'akismet_alert_code' ), 895 | 'msg' => get_option( 'akismet_alert_msg' ), 896 | 'api_calls' => get_option( 'akismet_alert_api_calls' ), 897 | 'usage_limit' => get_option( 'akismet_alert_usage_limit' ), 898 | 'upgrade_plan' => get_option( 'akismet_alert_upgrade_plan' ), 899 | 'upgrade_url' => get_option( 'akismet_alert_upgrade_url' ), 900 | 'upgrade_type' => get_option( 'akismet_alert_upgrade_type' ), 901 | ); 902 | } 903 | 904 | public static function display_usage_limit_alert() { 905 | Akismet::view( 'notice', self::get_usage_limit_alert_data() ); 906 | } 907 | 908 | public static function display_spam_check_warning() { 909 | Akismet::fix_scheduled_recheck(); 910 | 911 | if ( wp_next_scheduled('akismet_schedule_cron_recheck') > time() && self::are_any_comments_waiting_to_be_checked() ) { 912 | $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() ) ) ); 913 | Akismet::view( 'notice', array( 'type' => 'spam-check', 'link_text' => $link_text ) ); 914 | } 915 | } 916 | 917 | public static function display_api_key_warning() { 918 | Akismet::view( 'notice', array( 'type' => 'plugin' ) ); 919 | } 920 | 921 | public static function display_page() { 922 | if ( !Akismet::get_api_key() || ( isset( $_GET['view'] ) && $_GET['view'] == 'start' ) ) 923 | self::display_start_page(); 924 | elseif ( isset( $_GET['view'] ) && $_GET['view'] == 'stats' ) 925 | self::display_stats_page(); 926 | else 927 | self::display_configuration_page(); 928 | } 929 | 930 | public static function display_start_page() { 931 | if ( isset( $_GET['action'] ) ) { 932 | if ( $_GET['action'] == 'delete-key' ) { 933 | if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], self::NONCE ) ) 934 | delete_option( 'wordpress_api_key' ); 935 | } 936 | } 937 | 938 | if ( $api_key = Akismet::get_api_key() && ( empty( self::$notices['status'] ) || 'existing-key-invalid' != self::$notices['status'] ) ) { 939 | self::display_configuration_page(); 940 | return; 941 | } 942 | 943 | //the user can choose to auto connect their API key by clicking a button on the akismet done page 944 | //if jetpack, get verified api key by using connected wpcom user id 945 | //if no jetpack, get verified api key by using an akismet token 946 | 947 | $akismet_user = false; 948 | 949 | if ( isset( $_GET['token'] ) && preg_match('/^(\d+)-[0-9a-f]{20}$/', $_GET['token'] ) ) 950 | $akismet_user = self::verify_wpcom_key( '', '', array( 'token' => $_GET['token'] ) ); 951 | elseif ( $jetpack_user = self::get_jetpack_user() ) 952 | $akismet_user = self::verify_wpcom_key( $jetpack_user['api_key'], $jetpack_user['user_id'] ); 953 | 954 | if ( isset( $_GET['action'] ) ) { 955 | if ( $_GET['action'] == 'save-key' ) { 956 | if ( is_object( $akismet_user ) ) { 957 | self::save_key( $akismet_user->api_key ); 958 | self::display_configuration_page(); 959 | return; 960 | } 961 | } 962 | } 963 | 964 | Akismet::view( 'start', compact( 'akismet_user' ) ); 965 | 966 | /* 967 | // To see all variants when testing. 968 | $akismet_user->status = 'no-sub'; 969 | Akismet::view( 'start', compact( 'akismet_user' ) ); 970 | $akismet_user->status = 'cancelled'; 971 | Akismet::view( 'start', compact( 'akismet_user' ) ); 972 | $akismet_user->status = 'suspended'; 973 | Akismet::view( 'start', compact( 'akismet_user' ) ); 974 | $akismet_user->status = 'other'; 975 | Akismet::view( 'start', compact( 'akismet_user' ) ); 976 | $akismet_user = false; 977 | */ 978 | } 979 | 980 | public static function display_stats_page() { 981 | Akismet::view( 'stats' ); 982 | } 983 | 984 | public static function display_configuration_page() { 985 | $api_key = Akismet::get_api_key(); 986 | $akismet_user = self::get_akismet_user( $api_key ); 987 | 988 | if ( ! $akismet_user ) { 989 | // This could happen if the user's key became invalid after it was previously valid and successfully set up. 990 | self::$notices['status'] = 'existing-key-invalid'; 991 | self::display_start_page(); 992 | return; 993 | } 994 | 995 | $stat_totals = self::get_stats( $api_key ); 996 | 997 | // If unset, create the new strictness option using the old discard option to determine its default. 998 | // If the old option wasn't set, default to discarding the blatant spam. 999 | if ( get_option( 'akismet_strictness' ) === false ) { 1000 | add_option( 'akismet_strictness', ( get_option( 'akismet_discard_month' ) === 'false' ? '0' : '1' ) ); 1001 | } 1002 | 1003 | // Sync the local "Total spam blocked" count with the authoritative count from the server. 1004 | if ( isset( $stat_totals['all'], $stat_totals['all']->spam ) ) { 1005 | update_option( 'akismet_spam_count', $stat_totals['all']->spam ); 1006 | } 1007 | 1008 | $notices = array(); 1009 | 1010 | if ( empty( self::$notices ) ) { 1011 | if ( ! empty( $stat_totals['all'] ) && isset( $stat_totals['all']->time_saved ) && $akismet_user->status == 'active' && $akismet_user->account_type == 'free-api-key' ) { 1012 | 1013 | $time_saved = false; 1014 | 1015 | if ( $stat_totals['all']->time_saved > 1800 ) { 1016 | $total_in_minutes = round( $stat_totals['all']->time_saved / 60 ); 1017 | $total_in_hours = round( $total_in_minutes / 60 ); 1018 | $total_in_days = round( $total_in_hours / 8 ); 1019 | $cleaning_up = __( 'Cleaning up spam takes time.' , 'akismet'); 1020 | 1021 | if ( $total_in_days > 1 ) 1022 | $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 ) ); 1023 | elseif ( $total_in_hours > 1 ) 1024 | $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 ); 1025 | elseif ( $total_in_minutes >= 30 ) 1026 | $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 ); 1027 | } 1028 | 1029 | $notices[] = array( 'type' => 'active-notice', 'time_saved' => $time_saved ); 1030 | } 1031 | 1032 | if ( !empty( $akismet_user->limit_reached ) && in_array( $akismet_user->limit_reached, array( 'yellow', 'red' ) ) ) { 1033 | $notices[] = array( 'type' => 'limit-reached', 'level' => $akismet_user->limit_reached ); 1034 | } 1035 | } 1036 | 1037 | if ( !isset( self::$notices['status'] ) && in_array( $akismet_user->status, array( 'cancelled', 'suspended', 'missing', 'no-sub' ) ) ) { 1038 | $notices[] = array( 'type' => $akismet_user->status ); 1039 | } 1040 | 1041 | $alert_code = get_option( 'akismet_alert_code' ); 1042 | if ( isset( Akismet::$limit_notices[ $alert_code ] ) ) { 1043 | $notices[] = self::get_usage_limit_alert_data(); 1044 | } 1045 | 1046 | /* 1047 | // To see all variants when testing. 1048 | $notices[] = array( 'type' => 'active-notice', 'time_saved' => 'Cleaning up spam takes time. Akismet has saved you 1 minute!' ); 1049 | $notices[] = array( 'type' => 'plugin' ); 1050 | $notices[] = array( 'type' => 'spam-check', 'link_text' => 'Link text.' ); 1051 | $notices[] = array( 'type' => 'notice', 'notice_header' => 'This is the notice header.', 'notice_text' => 'This is the notice text.' ); 1052 | $notices[] = array( 'type' => 'missing-functions' ); 1053 | $notices[] = array( 'type' => 'servers-be-down' ); 1054 | $notices[] = array( 'type' => 'active-dunning' ); 1055 | $notices[] = array( 'type' => 'cancelled' ); 1056 | $notices[] = array( 'type' => 'suspended' ); 1057 | $notices[] = array( 'type' => 'missing' ); 1058 | $notices[] = array( 'type' => 'no-sub' ); 1059 | $notices[] = array( 'type' => 'new-key-valid' ); 1060 | $notices[] = array( 'type' => 'new-key-invalid' ); 1061 | $notices[] = array( 'type' => 'existing-key-invalid' ); 1062 | $notices[] = array( 'type' => 'new-key-failed' ); 1063 | $notices[] = array( 'type' => 'limit-reached', 'level' => 'yellow' ); 1064 | $notices[] = array( 'type' => 'limit-reached', 'level' => 'red' ); 1065 | $notices[] = array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_plan' => 'Enterprise', 'upgrade_url' => 'https://akismet.com/account/' ); 1066 | */ 1067 | 1068 | Akismet::log( compact( 'stat_totals', 'akismet_user' ) ); 1069 | Akismet::view( 'config', compact( 'api_key', 'akismet_user', 'stat_totals', 'notices' ) ); 1070 | } 1071 | 1072 | public static function display_notice() { 1073 | global $hook_suffix; 1074 | 1075 | if ( in_array( $hook_suffix, array( 'jetpack_page_akismet-key-config', 'settings_page_akismet-key-config' ) ) ) { 1076 | // This page manages the notices and puts them inline where they make sense. 1077 | return; 1078 | } 1079 | 1080 | if ( in_array( $hook_suffix, array( 'edit-comments.php' ) ) && (int) get_option( 'akismet_alert_code' ) > 0 ) { 1081 | Akismet::verify_key( Akismet::get_api_key() ); //verify that the key is still in alert state 1082 | 1083 | $alert_code = get_option( 'akismet_alert_code' ); 1084 | if ( isset( Akismet::$limit_notices[ $alert_code ] ) ) { 1085 | self::display_usage_limit_alert(); 1086 | } elseif ( $alert_code > 0 ) { 1087 | self::display_alert(); 1088 | } 1089 | } 1090 | elseif ( ( 'plugins.php' === $hook_suffix || 'edit-comments.php' === $hook_suffix ) && ! Akismet::get_api_key() ) { 1091 | // Show the "Set Up Akismet" banner on the comments and plugin pages if no API key has been set. 1092 | self::display_api_key_warning(); 1093 | } 1094 | elseif ( $hook_suffix == 'edit-comments.php' && wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) { 1095 | self::display_spam_check_warning(); 1096 | } 1097 | 1098 | if ( isset( $_GET['akismet_recheck_complete'] ) ) { 1099 | $recheck_count = (int) $_GET['recheck_count']; 1100 | $spam_count = (int) $_GET['spam_count']; 1101 | 1102 | if ( $recheck_count === 0 ) { 1103 | $message = __( 'There were no comments to check. Akismet will only check comments awaiting moderation.', 'akismet' ); 1104 | } 1105 | else { 1106 | $message = sprintf( _n( 'Akismet checked %s comment.', 'Akismet checked %s comments.', $recheck_count, 'akismet' ), number_format( $recheck_count ) ); 1107 | $message .= ' '; 1108 | 1109 | if ( $spam_count === 0 ) { 1110 | $message .= __( 'No comments were caught as spam.', 'akismet' ); 1111 | } 1112 | else { 1113 | $message .= sprintf( _n( '%s comment was caught as spam.', '%s comments were caught as spam.', $spam_count, 'akismet' ), number_format( $spam_count ) ); 1114 | } 1115 | } 1116 | 1117 | echo '' . esc_html( $message ) . '
' . esc_html( __( 'Akismet could not recheck your comments for spam.', 'akismet' ) ) . '