X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/d954c87a1e3f0e671855614661da9e5825279134..refs/tags/wordpress-3.5.1:/wp-content/plugins/akismet/admin.php diff --git a/wp-content/plugins/akismet/admin.php b/wp-content/plugins/akismet/admin.php index a1954039..9d7673f5 100644 --- a/wp-content/plugins/akismet/admin.php +++ b/wp-content/plugins/akismet/admin.php @@ -1,17 +1,17 @@
".sprintf(__('Akismet %s required WordPress 3.0 or higher.'), AKISMET_VERSION) ." ".sprintf(__('Please upgrade WordPress to a current version, or downgrade to version 2.4 of the Akismet plugin.'), 'http://codex.wordpress.org/Upgrading_WordPress', 'http://wordpress.org/extend/plugins/akismet/download/'). "
+ "; } add_action('admin_notices', 'akismet_version_warning'); @@ -23,20 +23,46 @@ function akismet_admin_init() { $hook = get_plugin_page_hook( 'akismet-stats-display', 'index.php' ); else $hook = 'dashboard_page_akismet-stats-display'; - add_action('admin_head-'.$hook, 'akismet_stats_script'); - add_meta_box('akismet-status', __('Akismet Status'), 'akismet_comment_status_meta_box', 'comment', 'normal'); + add_meta_box('akismet-status', __('Comment History'), 'akismet_comment_status_meta_box', 'comment', 'normal'); } add_action('admin_init', 'akismet_admin_init'); +add_action( 'admin_enqueue_scripts', 'akismet_load_js_and_css' ); +function akismet_load_js_and_css() { + global $hook_suffix; + + if ( + $hook_suffix == 'index.php' # dashboard + || $hook_suffix == 'edit-comments.php' + || $hook_suffix == 'comment.php' + || $hook_suffix == 'post.php' + || $hook_suffix == 'plugins_page_akismet-key-config' + ) { + wp_register_style( 'akismet.css', AKISMET_PLUGIN_URL . 'akismet.css', array(), '2.5.4.4' ); + wp_enqueue_style( 'akismet.css'); + + wp_register_script( 'akismet.js', AKISMET_PLUGIN_URL . 'akismet.js', array('jquery'), '2.5.4.6' ); + wp_enqueue_script( 'akismet.js' ); + wp_localize_script( 'akismet.js', 'WPAkismet', array( + 'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' ) + ) ); + } +} + + function akismet_nonce_field($action = -1) { return wp_nonce_field($action); } $akismet_nonce = 'akismet-update-key'; -function akismet_config_page() { - if ( function_exists('add_submenu_page') ) - add_submenu_page('plugins.php', __('Akismet Configuration'), __('Akismet Configuration'), 'manage_options', 'akismet-key-config', 'akismet_conf'); +function akismet_plugin_action_links( $links, $file ) { + if ( $file == plugin_basename( dirname(__FILE__).'/akismet.php' ) ) { + $links[] = ''.__( 'Settings' ).''; + } + return $links; } +add_filter( 'plugin_action_links', 'akismet_plugin_action_links', 10, 2 ); + function akismet_conf() { global $akismet_nonce, $wpcom_api_key; @@ -46,11 +72,15 @@ function akismet_conf() { check_admin_referer( $akismet_nonce ); $key = preg_replace( '/[^a-h0-9]/i', '', $_POST['key'] ); + $home_url = parse_url( get_bloginfo('url') ); if ( empty($key) ) { $key_status = 'empty'; $ms[] = 'new_key_empty'; delete_option('wordpress_api_key'); + } elseif ( empty($home_url['host']) ) { + $key_status = 'empty'; + $ms[] = 'bad_home_url'; } else { $key_status = akismet_verify_key( $key ); } @@ -68,6 +98,12 @@ function akismet_conf() { update_option( 'akismet_discard_month', 'true' ); else update_option( 'akismet_discard_month', 'false' ); + + if ( isset( $_POST['akismet_show_user_comments_approved'] ) ) + update_option( 'akismet_show_user_comments_approved', 'true' ); + else + update_option( 'akismet_show_user_comments_approved', 'false' ); + } elseif ( isset($_POST['check']) ) { akismet_get_server_connectivity(0); } @@ -88,8 +124,7 @@ function akismet_conf() { if ( $key_status == 'valid' ) { $ms[] = 'key_valid'; } else if ( $key_status == 'invalid' ) { - delete_option('wordpress_api_key'); - $ms[] = 'key_empty'; + $ms[] = 'key_invalid'; } else if ( !empty($key) && $key_status == 'failed' ) { $ms[] = 'key_failed'; } @@ -97,36 +132,43 @@ function akismet_conf() { $messages = array( 'new_key_empty' => array('color' => 'aa0', 'text' => __('Your key has been cleared.')), - 'new_key_valid' => array('color' => '2d2', 'text' => __('Your key has been verified. Happy blogging!')), - 'new_key_invalid' => array('color' => 'd22', 'text' => __('The key you entered is invalid. Please double-check it.')), - 'new_key_failed' => array('color' => 'd22', 'text' => __('The key you entered could not be verified because a connection to akismet.com could not be established. Please check your server configuration.')), - 'no_connection' => array('color' => 'd22', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')), - 'key_empty' => array('color' => 'aa0', 'text' => sprintf(__('Please enter an API key. (Get your key.)'), 'http://akismet.com/get/')), - 'key_valid' => array('color' => '2d2', 'text' => __('This key is valid.')), - 'key_failed' => array('color' => 'aa0', 'text' => __('The key below was previously validated but a connection to akismet.com can not be established at this time. Please check your server configuration.'))); + 'new_key_valid' => array('color' => '4AB915', 'text' => __('Your key has been verified. Happy blogging!')), + 'new_key_invalid' => array('color' => '888', 'text' => __('The key you entered is invalid. Please double-check it.')), + 'new_key_failed' => array('color' => '888', 'text' => __('The key you entered could not be verified because a connection to akismet.com could not be established. Please check your server configuration.')), + 'no_connection' => array('color' => '888', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')), + 'key_empty' => array('color' => 'aa0', 'text' => sprintf(__('Please enter an API key. (Get your key.)'), 'http://akismet.com/get/?return=true')), + 'key_valid' => array('color' => '4AB915', 'text' => __('This key is valid.')), + 'key_invalid' => array('color' => '888', 'text' => __('This key is invalid.')), + 'key_failed' => array('color' => 'aa0', 'text' => __('The key below was previously validated but a connection to akismet.com can not be established at this time. Please check your server configuration.')), + 'bad_home_url' => array('color' => '888', 'text' => sprintf( __('Your WordPress home URL %s is invalid. Please fix the home option.'), esc_html( get_bloginfo('url') ), admin_url('options.php#home') ) ), + ); ?>Sign up success! Please check your email for your Akismet API Key and enter it below.' ); ?>
fsockopen or gethostbynamel
functions. Akismet cannot work correctly until this is fixed. Please contact your web host or firewall administrator and give them this information about Akismet\'s system requirements.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?>
Akismet cannot work correctly until this is fixed. Please contact your web host or firewall administrator and give them this information about Akismet and firewalls.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?>
- + - +Akismet cannot work correctly until this is fixed. Please contact your web host or firewall administrator and give them this information about Akismet and firewalls.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?>
$status ) { - $color = ( $status ? '#2d2' : '#d22'); + $color = ( $status ? '#4AB915' : '#888'); ?>Click here to confirm that Akismet.com is up.'), 'http://status.automattic.com/9931/136079/Akismet-API', 'http://status.automattic.com/9931/136079/Akismet-API' ); ?>
@@ -196,35 +239,9 @@ function akismet_conf() { -'.sprintf(__('Akismet has protected your site from %3$s spam comments.'), 'http://akismet.com/', clean_url("$link?page=akismet-admin"), number_format_i18n($count) ).'
'; + echo ''.sprintf( _n( 'Akismet has protected your site from %3$s spam comments.', 'Akismet has protected your site from %3$s spam comments.', $count ), 'http://akismet.com/?return=true', clean_url("$link?page=akismet-admin"), number_format_i18n($count) ).'
'; } add_action('activity_box_end', 'akismet_stats'); function akismet_admin_warnings() { - global $wpcom_api_key; + global $wpcom_api_key, $pagenow; + + if ( + $pagenow == 'edit-comments.php' + || ( !empty( $_GET['page'] ) && $_GET['page'] == 'akismet-key-config' ) + || ( !empty( $_GET['page'] ) && $_GET['page'] == 'akismet-stats-display' ) + ) { + if ( get_option( 'akismet_alert_code' ) ) { + function akismet_alert() { + $alert = array( + 'code' => (int) get_option( 'akismet_alert_code' ), + 'msg' => get_option( 'akismet_alert_msg' ) + ); + ?> +Akismet Error Code:
+ +More information is available at https://akismet.com/errors/
+".__('Akismet is almost ready.')." ".sprintf(__('You must enter your Akismet API key for it to work.'), "plugins.php?page=akismet-key-config")."
+ "; } add_action('admin_notices', 'akismet_warning'); return; - } elseif ( get_option('akismet_connectivity_time') && empty($_POST) && is_admin() && !akismet_server_connectivity_ok() ) { + } elseif ( ( empty($_SERVER['SCRIPT_FILENAME']) || basename($_SERVER['SCRIPT_FILENAME']) == 'edit-comments.php' ) && wp_next_scheduled('akismet_schedule_cron_recheck') ) { function akismet_warning() { - echo " - + global $wpdb; + akismet_fix_scheduled_recheck(); + $waiting = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ); + $next_check = wp_next_scheduled('akismet_schedule_cron_recheck'); + if ( $waiting > 0 && $next_check > time() ) + echo " + "; } add_action('admin_notices', 'akismet_warning'); @@ -279,17 +326,24 @@ function akismet_admin_warnings() { // FIXME placeholder function akismet_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); + $comment_status = wp_get_comment_status( $comment->comment_ID ); $desc = null; - if ( !$user_result || $user_result == $akismet_result ) { + if ( $akismet_error ) { + $desc = __( 'Awaiting spam check' ); + } elseif ( !$user_result || $user_result == $akismet_result ) { // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same - if ( $akismet_result == 'true' ) - $desc = 'Flagged as spam by Akismet'; - elseif ( $akismet_result == 'false' ) - $desc = 'Cleared by Akismet'; + if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' ) + $desc = __( 'Flagged as spam by Akismet' ); + elseif ( $akismet_result == 'false' && $comment_status == 'spam' ) + $desc = __( 'Cleared by Akismet' ); } else { $who = get_comment_meta( $comment->comment_ID, 'akismet_user', true ); if ( $user_result == 'true' ) @@ -297,16 +351,37 @@ function akismet_comment_row_action( $a, $comment ) { else $desc = sprintf( __('Un-spammed by %s'), $who ); } - + + // add a History item to the hover links, just after Edit + if ( $akismet_result ) { + $b = array(); + foreach ( $a as $k => $item ) { + $b[ $k ] = $item; + if ( + $k == 'edit' + || ( $k == 'unspam' && $GLOBALS['wp_version'] >= 3.4 ) + ) { + $b['history'] = ' '. __('History') . ''; + } + } + + $a = $b; + } + if ( $desc ) - echo ''.htmlspecialchars($desc).''; + echo ' '; + + if ( apply_filters( 'akismet_show_user_comments_approved', get_option('akismet_show_user_comments_approved') ) == 'true' ) { + $comment_count = akismet_get_user_comments_approved( $comment->user_id, $comment->comment_author_email, $comment->comment_author, $comment->comment_author_url ); + $comment_count = intval( $comment_count ); + echo ' '; + } return $a; } add_filter( 'comment_row_actions', 'akismet_comment_row_action', 10, 2 ); - function akismet_comment_status_meta_box($comment) { $history = akismet_get_comment_history( $comment->comment_ID ); @@ -354,19 +429,28 @@ function akismet_comment_column_row( $column, $comment_id ) { // END FIXME +// call out URLS in comments +function akismet_text_add_link_callback( $m ) { + + // bare link? + if ( $m[4] == $m[2] ) + return ''.$m[4].''; + else + return ''.$m[4].''; +} + +function akismet_text_add_link_class( $comment_text ) { + + return preg_replace_callback( '#]*)href="([^"]+)"([^>]*)>(.*?)#i', 'akismet_text_add_link_callback', $comment_text ); +} + +add_filter('comment_text', 'akismet_text_add_link_class'); + + // WP 2.5+ function akismet_rightnow() { global $submenu, $wp_db_version; - $plural_func = '__ngettext'; - if ( function_exists( '_n' ) ) - $plural_func = '_n'; - - // clean_url was deprecated in WP 3.0 - $esc_url = 'clean_url'; - if ( function_exists( 'esc_url' ) ) - $esc_url = 'esc_url'; - if ( 8645 < $wp_db_version ) // 2.7 $link = 'edit-comments.php?comment_status=spam'; elseif ( isset( $submenu['edit-comments.php'] ) ) @@ -375,31 +459,27 @@ function akismet_rightnow() { $link = 'edit.php?page=akismet-admin'; if ( $count = get_option('akismet_spam_count') ) { - $intro = sprintf( $plural_func( - 'Akismet has protected your site from %2$s spam comment already,', - 'Akismet has protected your site from %2$s spam comments already,', + $intro = sprintf( _n( + 'Akismet has protected your site from %2$s spam comment already. ', + 'Akismet has protected your site from %2$s spam comments already. ', $count - ), 'http://akismet.com/', number_format_i18n( $count ) ); + ), 'http://akismet.com/?return=true', number_format_i18n( $count ) ); } else { - $intro = sprintf( __('Akismet blocks spam from getting to your blog,'), 'http://akismet.com/' ); + $intro = sprintf( __('Akismet blocks spam from getting to your blog. '), 'http://akismet.com/?return=true' ); } + $link = function_exists( 'esc_url' ) ? esc_url( $link ) : clean_url( $link ); if ( $queue_count = akismet_spam_count() ) { - $queue_text = sprintf( $plural_func( - 'and there\'s %1$s comment in your spam queue right now.', - 'and there are %1$s comments in your spam queue right now.', + $queue_text = sprintf( _n( + 'There\'s %1$s comment in your spam queue right now.', + 'There are %1$s comments in your spam queue right now.', $queue_count - ), number_format_i18n( $queue_count ), $esc_url($link) ); + ), number_format_i18n( $queue_count ), $link ); } else { - $queue_text = sprintf( __( " but there's nothing in your spam queue at the moment." ), $esc_url($link) ); + $queue_text = sprintf( __( "There's nothing in your spam queue at the moment." ), $link ); } - // _c was deprecated in WP 2.9.0 - if ( function_exists( '_x' ) ) - $text = sprintf( _x( '%1$s%2$s', 'akismet_rightnow' ), $intro, $queue_text ); - else - $text = sprintf( _c( '%1$s%2$s|akismet_rightnow' ), $intro, $queue_text ); - + $text = $intro . '