+
+// Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link
+function akismet_remove_comment_author_url() {
+ if ( !empty($_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
+ global $wpdb;
+ $comment = get_comment( intval($_POST['id']), ARRAY_A );
+ if (current_user_can('edit_comment', $comment['comment_ID'])) {
+ $comment['comment_author_url'] = '';
+ do_action( 'comment_remove_author_url' );
+ print(wp_update_comment( $comment ));
+ die();
+ }
+ }
+}
+
+add_action('wp_ajax_comment_author_deurl', 'akismet_remove_comment_author_url');
+
+function akismet_add_comment_author_url() {
+ if ( !empty( $_POST['id'] ) && !empty( $_POST['url'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
+ global $wpdb;
+ $comment = get_comment( intval($_POST['id']), ARRAY_A );
+ if (current_user_can('edit_comment', $comment['comment_ID'])) {
+ $comment['comment_author_url'] = esc_url($_POST['url']);
+ do_action( 'comment_add_author_url' );
+ print(wp_update_comment( $comment ));
+ die();
+ }
+ }
+}
+
+add_action('wp_ajax_comment_author_reurl', 'akismet_add_comment_author_url');
+
+// Check connectivity between the WordPress blog and Akismet's servers.
+// 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).
+function akismet_check_server_connectivity() {
+ global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
+
+ $test_host = 'rest.akismet.com';
+
+ // Some web hosts may disable one or both functions
+ if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') )
+ return array();
+
+ $ips = gethostbynamel($test_host);
+ if ( !$ips || !is_array($ips) || !count($ips) )
+ return array();
+
+ $servers = array();
+ foreach ( $ips as $ip ) {
+ $response = akismet_verify_key( akismet_get_key(), $ip );
+ // even if the key is invalid, at least we know we have connectivity
+ if ( $response == 'valid' || $response == 'invalid' )
+ $servers[$ip] = true;
+ else
+ $servers[$ip] = false;
+ }
+
+ return $servers;
+}
+
+// Check the server connectivity and store the results in an option.
+// Cached results will be used if not older than the specified timeout in seconds; use $cache_timeout = 0 to force an update.
+// Returns the same associative array as akismet_check_server_connectivity()
+function akismet_get_server_connectivity( $cache_timeout = 86400 ) {
+ $servers = get_option('akismet_available_servers');
+ if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false )
+ return $servers;
+
+ // There's a race condition here but the effect is harmless.
+ $servers = akismet_check_server_connectivity();
+ update_option('akismet_available_servers', $servers);
+ update_option('akismet_connectivity_time', time());
+ return $servers;
+}
+
+// Returns true if server connectivity was OK at the last check, false if there was a problem that needs to be fixed.
+function akismet_server_connectivity_ok() {
+ // skip the check on WPMU because the status page is hidden
+ global $wpcom_api_key;
+ if ( $wpcom_api_key )
+ return true;
+ $servers = akismet_get_server_connectivity();
+ return !( empty($servers) || !count($servers) || count( array_filter($servers) ) < count($servers) );
+}
+
+function akismet_admin_menu() {
+ if ( class_exists( 'Jetpack' ) ) {
+ add_action( 'jetpack_admin_menu', 'akismet_load_menu' );
+ } else {
+ akismet_load_menu();
+ }
+}
+
+function akismet_load_menu() {
+ if ( class_exists( 'Jetpack' ) ) {
+ add_submenu_page( 'jetpack', __( 'Akismet Configuration' ), __( 'Akismet Configuration' ), 'manage_options', 'akismet-key-config', 'akismet_conf' );
+ add_submenu_page( 'jetpack', __( 'Akismet Stats' ), __( 'Akismet Stats' ), 'manage_options', 'akismet-stats-display', 'akismet_stats_display' );
+ } else {
+ add_submenu_page('plugins.php', __('Akismet Configuration'), __('Akismet Configuration'), 'manage_options', 'akismet-key-config', 'akismet_conf');
+ add_submenu_page('index.php', __('Akismet Stats'), __('Akismet Stats'), 'manage_options', 'akismet-stats-display', 'akismet_stats_display');
+ }
+}