]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-content/plugins/akismet/class.akismet-admin.php
Wordpress 4.5.3
[autoinstalls/wordpress.git] / wp-content / plugins / akismet / class.akismet-admin.php
index 6a05b2baa089085b9fdd68739d2901600372be5b..c9e82eb04d3f33c9af9aa261cdc0aef22f58e9f0 100644 (file)
@@ -4,7 +4,25 @@ class Akismet_Admin {
        const NONCE = 'akismet-update-key';
 
        private static $initiated = false;
-       private static $notices = array();
+       private static $notices   = array();
+       private static $allowed   = array(
+           'a' => array(
+               'href' => true,
+               'title' => true,
+           ),
+           'b' => array(),
+           'code' => array(),
+           'del' => array(
+               'datetime' => true,
+           ),
+           'em' => array(),
+           'i' => array(),
+           'q' => array(
+               'cite' => true,
+           ),
+           'strike' => array(),
+           'strong' => array(),
+       );
 
        public static function init() {
                if ( ! self::$initiated ) {
@@ -91,11 +109,12 @@ class Akismet_Admin {
                        'post.php',
                        'settings_page_akismet-key-config',
                        'jetpack_page_akismet-key-config',
+                       'plugins.php',
                ) ) ) {
-                       wp_register_style( 'akismet.css', AKISMET__PLUGIN_URL . '_inc/akismet.css', array(), AKISMET_VERSION );
+                       wp_register_style( 'akismet.css', plugin_dir_url( __FILE__ ) . '_inc/akismet.css', array(), AKISMET_VERSION );
                        wp_enqueue_style( 'akismet.css');
 
-                       wp_register_script( 'akismet.js', AKISMET__PLUGIN_URL . '_inc/akismet.js', array('jquery','postbox'), AKISMET_VERSION );
+                       wp_register_script( 'akismet.js', plugin_dir_url( __FILE__ ) . '_inc/akismet.js', array('jquery','postbox'), AKISMET_VERSION );
                        wp_enqueue_script( 'akismet.js' );
                        wp_localize_script( 'akismet.js', 'WPAkismet', array(
                                'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' ),
@@ -257,8 +276,10 @@ class Akismet_Admin {
                                if ( in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) ) )
                                        update_option( 'wordpress_api_key', $api_key );
                                
-                               if (  $akismet_user->status == 'active' )
+                               if ( $akismet_user->status == 'active' )
                                        self::$notices['status'] = 'new-key-valid';
+                               elseif ( $akismet_user->status == 'notice' )
+                                       self::$notices['status'] = $akismet_user;
                                else
                                        self::$notices['status'] = $akismet_user->status;
                        }
@@ -345,6 +366,12 @@ class Akismet_Admin {
                }
                $moderation = $wpdb->get_results( "SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0'{$paginate}", ARRAY_A );
 
+               $result_counts = array(
+                       'spam' => 0,
+                       'ham' => 0,
+                       'error' => 0,
+               );
+
                foreach ( (array) $moderation as $c ) {
                        $c['user_ip']      = $c['comment_author_IP'];
                        $c['user_agent']   = $c['comment_agent'];
@@ -371,14 +398,15 @@ class Akismet_Admin {
                                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['spam'];
                        } elseif ( 'false' == $response[1] ) {
                                update_comment_meta( $c['comment_ID'], 'akismet_result', 'false' );
                                delete_comment_meta( $c['comment_ID'], 'akismet_error' );
                                delete_comment_meta( $c['comment_ID'], 'akismet_delayed_moderation_email' );
                                Akismet::update_comment_history( $c['comment_ID'], '', 'recheck-ham' );
-                       // abnormal result: error
+                               ++$result_counts['ham'];
                        } else {
+                               // abnormal result: error
                                update_comment_meta( $c['comment_ID'], 'akismet_result', 'error' );
                                Akismet::update_comment_history(
                                        $c['comment_ID'],
@@ -386,6 +414,7 @@ class Akismet_Admin {
                                        'recheck-error',
                                        array( 'response' => substr( $response[1], 0, 50 ) )
                                );
+                               ++$result_counts['error'];
                        }
 
                        delete_comment_meta( $c['comment_ID'], 'akismet_rechecking' );
@@ -393,6 +422,7 @@ class Akismet_Admin {
                if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
                        wp_send_json( array(
                                'processed' => count((array) $moderation),
+                               'counts' => $result_counts,
                        ));
                }
                else {
@@ -584,7 +614,7 @@ class Akismet_Admin {
        }
 
        public static function plugin_action_links( $links, $file ) {
-               if ( $file == plugin_basename( AKISMET__PLUGIN_URL . '/akismet.php' ) ) {
+               if ( $file == plugin_basename( plugin_dir_url( __FILE__ ) . '/akismet.php' ) ) {
                        $links[] = '<a href="' . esc_url( self::get_page_url() ) . '">'.esc_html__( 'Settings' , 'akismet').'</a>';
                }
 
@@ -867,11 +897,11 @@ class Akismet_Admin {
                                        $cleaning_up      = __( 'Cleaning up spam takes time.' , 'akismet');
 
                                        if ( $total_in_days > 1 )
-                                               $time_saved = $cleaning_up . ' ' . sprintf( __( '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( __( '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( __( '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 ) );
@@ -918,8 +948,24 @@ class Akismet_Admin {
                if ( !empty( $type ) )
                        Akismet::view( 'notice', compact( 'type' ) );
                elseif ( !empty( self::$notices ) ) {
-                       foreach ( self::$notices as $type )
-                               Akismet::view( 'notice', compact( 'type' ) );
+                       foreach ( self::$notices as $type ) {
+                               if ( is_object( $type ) ) {
+                                       $notice_header = $notice_text = '';
+                                       
+                                       if ( property_exists( $type, 'notice_header' ) )
+                                               $notice_header = wp_kses( $type->notice_header, self::$allowed );
+                               
+                                       if ( property_exists( $type, 'notice_text' ) )
+                                               $notice_text = wp_kses( $type->notice_text, self::$allowed );
+                                       
+                                       if ( property_exists( $type, 'status' ) ) {
+                                               $type = wp_kses( $type->status, self::$allowed );
+                                               Akismet::view( 'notice', compact( 'type', 'notice_header', 'notice_text' ) );
+                                       }
+                               }
+                               else
+                                       Akismet::view( 'notice', compact( 'type' ) );
+                       }                               
                }
        }