Akismet Anti-Spam - Version 2.5.7

Version Description

  • FireFox Stats iframe preview bug
  • Fix mshots preview when using https
  • Add .htaccess to block direct access to files
  • Prevent some PHP notices
  • Fix Check For Spam return location when referrer is empty
  • Fix Settings links for network admins
  • Fix prepare() warnings in WP 3.5
Download this release

Release Info

Developer tellyworth
Plugin Icon 128x128 Akismet Anti-Spam
Version 2.5.7
Comparing to
See all releases

Code changes from version 2.4.1 to 2.5.7

Files changed (9) hide show
  1. .htaccess +6 -0
  2. admin.php +833 -0
  3. akismet.css +12 -0
  4. akismet.js +114 -0
  5. akismet.php +421 -697
  6. index.php +2 -0
  7. legacy.php +6 -7
  8. readme.txt +90 -11
  9. widget.php +108 -0
.htaccess ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ Order Deny,Allow
2
+ Deny from all
3
+
4
+ <FilesMatch "^akismet\.(css|js)$">
5
+ Allow from all
6
+ </FilesMatch>
admin.php ADDED
@@ -0,0 +1,833 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ add_action( 'admin_menu', 'akismet_admin_menu' );
3
+
4
+ akismet_admin_warnings();
5
+
6
+ function akismet_admin_init() {
7
+ global $wp_version;
8
+
9
+ // all admin functions are disabled in old versions
10
+ if ( !function_exists('is_multisite') && version_compare( $wp_version, '3.0', '<' ) ) {
11
+
12
+ function akismet_version_warning() {
13
+ echo "
14
+ <div id='akismet-warning' class='updated fade'><p><strong>".sprintf(__('Akismet %s requires WordPress 3.0 or higher.'), AKISMET_VERSION) ."</strong> ".sprintf(__('Please <a href="%s">upgrade WordPress</a> to a current version, or <a href="%s">downgrade to version 2.4 of the Akismet plugin</a>.'), 'http://codex.wordpress.org/Upgrading_WordPress', 'http://wordpress.org/extend/plugins/akismet/download/'). "</p></div>
15
+ ";
16
+ }
17
+ add_action('admin_notices', 'akismet_version_warning');
18
+
19
+ return;
20
+ }
21
+
22
+ if ( function_exists( 'get_plugin_page_hook' ) )
23
+ $hook = get_plugin_page_hook( 'akismet-stats-display', 'index.php' );
24
+ else
25
+ $hook = 'dashboard_page_akismet-stats-display';
26
+ add_meta_box('akismet-status', __('Comment History'), 'akismet_comment_status_meta_box', 'comment', 'normal');
27
+ }
28
+ add_action('admin_init', 'akismet_admin_init');
29
+
30
+ add_action( 'admin_enqueue_scripts', 'akismet_load_js_and_css' );
31
+ function akismet_load_js_and_css() {
32
+ global $hook_suffix;
33
+
34
+ if (
35
+ $hook_suffix == 'index.php' # dashboard
36
+ || $hook_suffix == 'edit-comments.php'
37
+ || $hook_suffix == 'comment.php'
38
+ || $hook_suffix == 'post.php'
39
+ || $hook_suffix == 'plugins_page_akismet-key-config'
40
+ ) {
41
+ wp_register_style( 'akismet.css', AKISMET_PLUGIN_URL . 'akismet.css', array(), '2.5.4.4' );
42
+ wp_enqueue_style( 'akismet.css');
43
+
44
+ wp_register_script( 'akismet.js', AKISMET_PLUGIN_URL . 'akismet.js', array('jquery'), '2.5.4.6' );
45
+ wp_enqueue_script( 'akismet.js' );
46
+ wp_localize_script( 'akismet.js', 'WPAkismet', array(
47
+ 'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' )
48
+ ) );
49
+ }
50
+ }
51
+
52
+
53
+ function akismet_nonce_field($action = -1) { return wp_nonce_field($action); }
54
+ $akismet_nonce = 'akismet-update-key';
55
+
56
+ function akismet_plugin_action_links( $links, $file ) {
57
+ if ( $file == plugin_basename( dirname(__FILE__).'/akismet.php' ) ) {
58
+ $links[] = '<a href="' . admin_url( 'admin.php?page=akismet-key-config' ) . '">'.__( 'Settings' ).'</a>';
59
+ }
60
+
61
+ return $links;
62
+ }
63
+
64
+ add_filter( 'plugin_action_links', 'akismet_plugin_action_links', 10, 2 );
65
+
66
+ function akismet_conf() {
67
+ global $akismet_nonce, $wpcom_api_key;
68
+
69
+ if ( isset($_POST['submit']) ) {
70
+ if ( function_exists('current_user_can') && !current_user_can('manage_options') )
71
+ die(__('Cheatin&#8217; uh?'));
72
+
73
+ check_admin_referer( $akismet_nonce );
74
+ $key = preg_replace( '/[^a-h0-9]/i', '', $_POST['key'] );
75
+ $home_url = parse_url( get_bloginfo('url') );
76
+
77
+ if ( empty($key) ) {
78
+ $key_status = 'empty';
79
+ $ms[] = 'new_key_empty';
80
+ delete_option('wordpress_api_key');
81
+ } elseif ( empty($home_url['host']) ) {
82
+ $key_status = 'empty';
83
+ $ms[] = 'bad_home_url';
84
+ } else {
85
+ $key_status = akismet_verify_key( $key );
86
+ }
87
+
88
+ if ( $key_status == 'valid' ) {
89
+ update_option('wordpress_api_key', $key);
90
+ $ms[] = 'new_key_valid';
91
+ } else if ( $key_status == 'invalid' ) {
92
+ $ms[] = 'new_key_invalid';
93
+ } else if ( $key_status == 'failed' ) {
94
+ $ms[] = 'new_key_failed';
95
+ }
96
+
97
+ if ( isset( $_POST['akismet_discard_month'] ) )
98
+ update_option( 'akismet_discard_month', 'true' );
99
+ else
100
+ update_option( 'akismet_discard_month', 'false' );
101
+
102
+ if ( isset( $_POST['akismet_show_user_comments_approved'] ) )
103
+ update_option( 'akismet_show_user_comments_approved', 'true' );
104
+ else
105
+ update_option( 'akismet_show_user_comments_approved', 'false' );
106
+
107
+ } elseif ( isset($_POST['check']) ) {
108
+ akismet_get_server_connectivity(0);
109
+ }
110
+
111
+ if ( empty( $key_status) || $key_status != 'valid' ) {
112
+ $key = get_option('wordpress_api_key');
113
+ if ( empty( $key ) ) {
114
+ if ( empty( $key_status ) || $key_status != 'failed' ) {
115
+ if ( akismet_verify_key( '1234567890ab' ) == 'failed' )
116
+ $ms[] = 'no_connection';
117
+ else
118
+ $ms[] = 'key_empty';
119
+ }
120
+ $key_status = 'empty';
121
+ } else {
122
+ $key_status = akismet_verify_key( $key );
123
+ }
124
+ if ( $key_status == 'valid' ) {
125
+ $ms[] = 'key_valid';
126
+ } else if ( $key_status == 'invalid' ) {
127
+ $ms[] = 'key_invalid';
128
+ } else if ( !empty($key) && $key_status == 'failed' ) {
129
+ $ms[] = 'key_failed';
130
+ }
131
+ }
132
+
133
+ $messages = array(
134
+ 'new_key_empty' => array('color' => 'aa0', 'text' => __('Your key has been cleared.')),
135
+ 'new_key_valid' => array('color' => '4AB915', 'text' => __('Your key has been verified. Happy blogging!')),
136
+ 'new_key_invalid' => array('color' => '888', 'text' => __('The key you entered is invalid. Please double-check it.')),
137
+ '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.')),
138
+ 'no_connection' => array('color' => '888', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')),
139
+ 'key_empty' => array('color' => 'aa0', 'text' => sprintf(__('Please enter an API key. (<a href="%s" style="color:#fff">Get your key.</a>)'), 'http://akismet.com/get/?return=true')),
140
+ 'key_valid' => array('color' => '4AB915', 'text' => __('This key is valid.')),
141
+ 'key_invalid' => array('color' => '888', 'text' => __('This key is invalid.')),
142
+ '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.')),
143
+ 'bad_home_url' => array('color' => '888', 'text' => sprintf( __('Your WordPress home URL %s is invalid. Please fix the <a href="%s">home option</a>.'), esc_html( get_bloginfo('url') ), admin_url('options.php#home') ) ),
144
+ );
145
+ ?>
146
+ <?php if ( !empty($_POST['submit'] ) ) : ?>
147
+ <div id="message" class="updated fade"><p><strong><?php _e('Options saved.') ?></strong></p></div>
148
+ <?php endif; ?>
149
+ <div class="wrap">
150
+ <h2><?php _e('Akismet Configuration'); ?></h2>
151
+ <?php if (isset($_GET['message']) && $_GET['message'] == 'success') { ?>
152
+ <div class="updated below-h2" id="message"><p><?php _e( '<strong>Sign up success!</strong> Please check your email for your Akismet API Key and enter it below.' ); ?></p></div>
153
+ <?php } ?>
154
+ <div class="narrow">
155
+ <form action="" method="post" id="akismet-conf" style="margin: auto; width: 400px; ">
156
+ <?php if ( !$wpcom_api_key ) { ?>
157
+ <p><?php printf(__('For many people, <a href="%1$s">Akismet</a> will greatly reduce or even completely eliminate the comment and trackback spam you get on your site. If one does happen to get through, simply mark it as "spam" on the moderation screen and Akismet will learn from the mistakes. If you don\'t have an API key yet, you can get one at <a href="%2$s">Akismet.com</a>.'), 'http://akismet.com/?return=true', 'http://akismet.com/get/?return=true'); ?></p>
158
+
159
+ <h3><label for="key"><?php _e('Akismet API Key'); ?></label></h3>
160
+ <?php foreach ( $ms as $m ) : ?>
161
+ <p style="padding: .5em; background-color: #<?php echo $messages[$m]['color']; ?>; color: #fff; font-weight: bold;"><?php echo $messages[$m]['text']; ?></p>
162
+ <?php endforeach; ?>
163
+ <p><input id="key" name="key" type="text" size="15" maxlength="12" value="<?php echo get_option('wordpress_api_key'); ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;" /> (<?php _e('<a href="http://akismet.com/get/?return=true">What is this?</a>'); ?>)</p>
164
+ <?php if ( isset( $invalid_key) && $invalid_key ) { ?>
165
+ <h3><?php _e('Why might my key be invalid?'); ?></h3>
166
+ <p><?php _e('This can mean one of two things, either you copied the key wrong or that the plugin is unable to reach the Akismet servers, which is most often caused by an issue with your web host around firewalls or similar.'); ?></p>
167
+ <?php } ?>
168
+ <?php } ?>
169
+ <?php akismet_nonce_field($akismet_nonce) ?>
170
+ <p><label><input name="akismet_discard_month" id="akismet_discard_month" value="true" type="checkbox" <?php if ( get_option('akismet_discard_month') == 'true' ) echo ' checked="checked" '; ?> /> <?php _e('Auto-delete spam submitted on posts more than a month old.'); ?></label></p>
171
+ <p><label><input name="akismet_show_user_comments_approved" id="akismet_show_user_comments_approved" value="true" type="checkbox" <?php if ( get_option('akismet_show_user_comments_approved') == 'true' ) echo ' checked="checked" '; ?> /> <?php _e('Show the number of comments you\'ve approved beside each comment author.'); ?></label></p>
172
+ <p class="submit"><input type="submit" name="submit" value="<?php _e('Update options &raquo;'); ?>" /></p>
173
+ </form>
174
+
175
+ <form action="" method="post" id="akismet-connectivity" style="margin: auto; width: 400px; ">
176
+
177
+ <h3><?php _e('Server Connectivity'); ?></h3>
178
+ <?php
179
+ if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') ) {
180
+ ?>
181
+ <p style="padding: .5em; background-color: #888; color: #fff; font-weight:bold;"><?php _e('Network functions are disabled.'); ?></p>
182
+ <p><?php echo sprintf( __('Your web host or server administrator has disabled PHP\'s <code>fsockopen</code> or <code>gethostbynamel</code> functions. <strong>Akismet cannot work correctly until this is fixed.</strong> Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet\'s system requirements</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
183
+ <?php
184
+ } else {
185
+ $servers = akismet_get_server_connectivity();
186
+ $fail_count = count($servers) - count( array_filter($servers) );
187
+ if ( is_array($servers) && count($servers) > 0 ) {
188
+ // some connections work, some fail
189
+ if ( $fail_count > 0 && $fail_count < count($servers) ) { ?>
190
+ <p style="padding: .5em; background-color: #aa0; color: #fff; font-weight:bold;"><?php _e('Unable to reach some Akismet servers.'); ?></p>
191
+ <p><?php echo sprintf( __('A network problem or firewall is blocking some connections from your web server to Akismet.com. Akismet is working but this may cause problems during times of network congestion. Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
192
+ <?php
193
+ // all connections fail
194
+ } elseif ( $fail_count > 0 ) { ?>
195
+ <p style="padding: .5em; background-color: #888; color: #fff; font-weight:bold;"><?php _e('Unable to reach any Akismet servers.'); ?></p>
196
+ <p><?php echo sprintf( __('A network problem or firewall is blocking all connections from your web server to Akismet.com. <strong>Akismet cannot work correctly until this is fixed.</strong> Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
197
+ <?php
198
+ // all connections work
199
+ } else { ?>
200
+ <p style="padding: .5em; background-color: #4AB915; color: #fff; font-weight:bold;"><?php _e('All Akismet servers are available.'); ?></p>
201
+ <p><?php _e('Akismet is working correctly. All servers are accessible.'); ?></p>
202
+ <?php
203
+ }
204
+ } else {
205
+ ?>
206
+ <p style="padding: .5em; background-color: #888; color: #fff; font-weight:bold;"><?php _e('Unable to find Akismet servers.'); ?></p>
207
+ <p><?php echo sprintf( __('A DNS problem or firewall is preventing all access from your web server to Akismet.com. <strong>Akismet cannot work correctly until this is fixed.</strong> Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
208
+ <?php
209
+ }
210
+ }
211
+
212
+ if ( !empty($servers) ) {
213
+ ?>
214
+ <table style="width: 100%;">
215
+ <thead><th><?php _e('Akismet server'); ?></th><th><?php _e('Network Status'); ?></th></thead>
216
+ <tbody>
217
+ <?php
218
+ asort($servers);
219
+ foreach ( $servers as $ip => $status ) {
220
+ $color = ( $status ? '#4AB915' : '#888');
221
+ ?>
222
+ <tr>
223
+ <td><?php echo htmlspecialchars($ip); ?></td>
224
+ <td style="padding: 0 .5em; font-weight:bold; color: #fff; background-color: <?php echo $color; ?>"><?php echo ($status ? __('Accessible') : __('Re-trying') ); ?></td>
225
+
226
+ <?php
227
+ }
228
+ }
229
+ ?>
230
+ </tbody>
231
+ </table>
232
+ <p><?php if ( get_option('akismet_connectivity_time') ) echo sprintf( __('Last checked %s ago.'), human_time_diff( get_option('akismet_connectivity_time') ) ); ?></p>
233
+ <p class="submit"><input type="submit" name="check" value="<?php _e('Check network status &raquo;'); ?>" /></p>
234
+ <p><?php printf( __('<a href="%s" target="_blank">Click here</a> to confirm that <a href="%s" target="_blank">Akismet.com is up</a>.'), 'http://status.automattic.com/9931/136079/Akismet-API', 'http://status.automattic.com/9931/136079/Akismet-API' ); ?></p>
235
+ </form>
236
+
237
+ </div>
238
+ </div>
239
+ <?php
240
+ }
241
+
242
+ function akismet_stats_display() {
243
+ global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
244
+ $blog = urlencode( get_bloginfo('url') );
245
+
246
+ $url = 'http://';
247
+ if ( is_ssl() )
248
+ $url = 'https://';
249
+
250
+ $url .= 'akismet.com/web/1.0/user-stats.php';
251
+ $url .= "?blog={$blog}&api_key=" . akismet_get_key();
252
+ ?>
253
+ <div class="wrap">
254
+ <iframe src="<?php echo $url; ?>" width="100%" height="2500px" frameborder="0" id="akismet-stats-frame"></iframe>
255
+ </div>
256
+ <?php
257
+ }
258
+
259
+ function akismet_stats() {
260
+ if ( !function_exists('did_action') || did_action( 'rightnow_end' ) ) // We already displayed this info in the "Right Now" section
261
+ return;
262
+ if ( !$count = get_option('akismet_spam_count') )
263
+ return;
264
+ $path = plugin_basename(__FILE__);
265
+ echo '<h3>' . _x( 'Spam', 'comments' ) . '</h3>';
266
+ global $submenu;
267
+ if ( isset( $submenu['edit-comments.php'] ) )
268
+ $link = 'edit-comments.php';
269
+ else
270
+ $link = 'edit.php';
271
+ echo '<p>'.sprintf( _n( '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.', '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.', $count ), 'http://akismet.com/?return=true', clean_url("$link?page=akismet-admin"), number_format_i18n($count) ).'</p>';
272
+ }
273
+ add_action('activity_box_end', 'akismet_stats');
274
+
275
+ function akismet_admin_warnings() {
276
+ global $wpcom_api_key, $pagenow;
277
+
278
+ if (
279
+ $pagenow == 'edit-comments.php'
280
+ || ( !empty( $_GET['page'] ) && $_GET['page'] == 'akismet-key-config' )
281
+ || ( !empty( $_GET['page'] ) && $_GET['page'] == 'akismet-stats-display' )
282
+ ) {
283
+ if ( get_option( 'akismet_alert_code' ) ) {
284
+ function akismet_alert() {
285
+ $alert = array(
286
+ 'code' => (int) get_option( 'akismet_alert_code' ),
287
+ 'msg' => get_option( 'akismet_alert_msg' )
288
+ );
289
+ ?>
290
+ <div class='error'>
291
+ <p><strong>Akismet Error Code: <?php echo $alert['code']; ?></strong></p>
292
+ <p><?php esc_html_e( $alert['msg'] ); ?></p>
293
+ <p>More information is available at <a href="https://akismet.com/errors/<?php echo $alert['code']; ?>">https://akismet.com/errors/<?php echo $alert['code']; ?></a></p>
294
+ </div>
295
+ <?php
296
+ }
297
+
298
+ add_action( 'admin_notices', 'akismet_alert' );
299
+ }
300
+ }
301
+
302
+ if ( !get_option('wordpress_api_key') && !$wpcom_api_key && !isset($_POST['submit']) ) {
303
+ function akismet_warning() {
304
+ echo "
305
+ <div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet is almost ready.')."</strong> ".sprintf(__('You must <a href="%1$s">enter your Akismet API key</a> for it to work.'), "admin.php?page=akismet-key-config")."</p></div>
306
+ ";
307
+ }
308
+ add_action('admin_notices', 'akismet_warning');
309
+ return;
310
+ } elseif ( ( empty($_SERVER['SCRIPT_FILENAME']) || basename($_SERVER['SCRIPT_FILENAME']) == 'edit-comments.php' ) && wp_next_scheduled('akismet_schedule_cron_recheck') ) {
311
+ function akismet_warning() {
312
+ global $wpdb;
313
+ akismet_fix_scheduled_recheck();
314
+ $waiting = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" );
315
+ $next_check = wp_next_scheduled('akismet_schedule_cron_recheck');
316
+ if ( $waiting > 0 && $next_check > time() )
317
+ echo "
318
+ <div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet has detected a problem.')."</strong> ".sprintf(__('Some comments have not yet been checked for spam by Akismet. They have been temporarily held for moderation. Please check your <a href="%s">Akismet configuration</a> and contact your web host if problems persist.'), 'admin.php?page=akismet-key-config')."</p></div>
319
+ ";
320
+ }
321
+ add_action('admin_notices', 'akismet_warning');
322
+ return;
323
+ }
324
+ }
325
+
326
+ // FIXME placeholder
327
+
328
+ function akismet_comment_row_action( $a, $comment ) {
329
+
330
+ // failsafe for old WP versions
331
+ if ( !function_exists('add_comment_meta') )
332
+ return $a;
333
+
334
+ $akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
335
+ $akismet_error = get_comment_meta( $comment->comment_ID, 'akismet_error', true );
336
+ $user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
337
+ $comment_status = wp_get_comment_status( $comment->comment_ID );
338
+ $desc = null;
339
+ if ( $akismet_error ) {
340
+ $desc = __( 'Awaiting spam check' );
341
+ } elseif ( !$user_result || $user_result == $akismet_result ) {
342
+ // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
343
+ if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' )
344
+ $desc = __( 'Flagged as spam by Akismet' );
345
+ elseif ( $akismet_result == 'false' && $comment_status == 'spam' )
346
+ $desc = __( 'Cleared by Akismet' );
347
+ } else {
348
+ $who = get_comment_meta( $comment->comment_ID, 'akismet_user', true );
349
+ if ( $user_result == 'true' )
350
+ $desc = sprintf( __('Flagged as spam by %s'), $who );
351
+ else
352
+ $desc = sprintf( __('Un-spammed by %s'), $who );
353
+ }
354
+
355
+ // add a History item to the hover links, just after Edit
356
+ if ( $akismet_result ) {
357
+ $b = array();
358
+ foreach ( $a as $k => $item ) {
359
+ $b[ $k ] = $item;
360
+ if (
361
+ $k == 'edit'
362
+ || ( $k == 'unspam' && $GLOBALS['wp_version'] >= 3.4 )
363
+ ) {
364
+ $b['history'] = '<a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="'. esc_attr__( 'View comment history' ) . '"> '. __('History') . '</a>';
365
+ }
366
+ }
367
+
368
+ $a = $b;
369
+ }
370
+
371
+ if ( $desc )
372
+ 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' ) . '">'.htmlspecialchars($desc).'</a></span>';
373
+
374
+ if ( apply_filters( 'akismet_show_user_comments_approved', get_option('akismet_show_user_comments_approved') ) == 'true' ) {
375
+ $comment_count = akismet_get_user_comments_approved( $comment->user_id, $comment->comment_author_email, $comment->comment_author, $comment->comment_author_url );
376
+ $comment_count = intval( $comment_count );
377
+ echo '<span class="akismet-user-comment-count" commentid="'.$comment->comment_ID.'" style="display:none;"><br><span class="akismet-user-comment-counts">'.sprintf( _n( '%s approved', '%s approved', $comment_count ), number_format_i18n( $comment_count ) ) . '</span></span>';
378
+ }
379
+
380
+ return $a;
381
+ }
382
+
383
+ add_filter( 'comment_row_actions', 'akismet_comment_row_action', 10, 2 );
384
+
385
+ function akismet_comment_status_meta_box($comment) {
386
+ $history = akismet_get_comment_history( $comment->comment_ID );
387
+
388
+ if ( $history ) {
389
+ echo '<div class="akismet-history" style="margin: 13px;">';
390
+ foreach ( $history as $row ) {
391
+ $time = date( 'D d M Y @ h:i:m a', $row['time'] ) . ' GMT';
392
+ echo '<div style="margin-bottom: 13px;"><span style="color: #999;" alt="' . $time . '" title="' . $time . '">' . sprintf( __('%s ago'), human_time_diff( $row['time'] ) ) . '</span> - ';
393
+ echo htmlspecialchars( $row['message'] ) . '</div>';
394
+ }
395
+
396
+ echo '</div>';
397
+
398
+ }
399
+ }
400
+
401
+
402
+ // add an extra column header to the comments screen
403
+ function akismet_comments_columns( $columns ) {
404
+ $columns[ 'akismet' ] = __( 'Akismet' );
405
+ return $columns;
406
+ }
407
+
408
+ #add_filter( 'manage_edit-comments_columns', 'akismet_comments_columns' );
409
+
410
+ // Show stuff in the extra column
411
+ function akismet_comment_column_row( $column, $comment_id ) {
412
+ if ( $column != 'akismet' )
413
+ return;
414
+
415
+ $history = akismet_get_comment_history( $comment_id );
416
+
417
+ if ( $history ) {
418
+ echo '<dl class="akismet-history">';
419
+ foreach ( $history as $row ) {
420
+ echo '<dt>' . sprintf( __('%s ago'), human_time_diff( $row['time'] ) ) . '</dt>';
421
+ echo '<dd>' . htmlspecialchars( $row['message'] ) . '</dd>';
422
+ }
423
+
424
+ echo '</dl>';
425
+ }
426
+ }
427
+
428
+ #add_action( 'manage_comments_custom_column', 'akismet_comment_column_row', 10, 2 );
429
+
430
+ // END FIXME
431
+
432
+ // call out URLS in comments
433
+ function akismet_text_add_link_callback( $m ) {
434
+
435
+ // bare link?
436
+ if ( $m[4] == $m[2] )
437
+ return '<a '.$m[1].' href="'.$m[2].'" '.$m[3].' class="comment-link">'.$m[4].'</a>';
438
+ else
439
+ return '<span title="'.$m[2].'" class="comment-link"><a '.$m[1].' href="'.$m[2].'" '.$m[3].' class="comment-link">'.$m[4].'</a></span>';
440
+ }
441
+
442
+ function akismet_text_add_link_class( $comment_text ) {
443
+
444
+ return preg_replace_callback( '#<a ([^>]*)href="([^"]+)"([^>]*)>(.*?)</a>#i', 'akismet_text_add_link_callback', $comment_text );
445
+ }
446
+
447
+ add_filter('comment_text', 'akismet_text_add_link_class');
448
+
449
+
450
+ // WP 2.5+
451
+ function akismet_rightnow() {
452
+ global $submenu, $wp_db_version;
453
+
454
+ if ( 8645 < $wp_db_version ) // 2.7
455
+ $link = 'edit-comments.php?comment_status=spam';
456
+ elseif ( isset( $submenu['edit-comments.php'] ) )
457
+ $link = 'edit-comments.php?page=akismet-admin';
458
+ else
459
+ $link = 'edit.php?page=akismet-admin';
460
+
461
+ if ( $count = get_option('akismet_spam_count') ) {
462
+ $intro = sprintf( _n(
463
+ '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comment already. ',
464
+ '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comments already. ',
465
+ $count
466
+ ), 'http://akismet.com/?return=true', number_format_i18n( $count ) );
467
+ } else {
468
+ $intro = sprintf( __('<a href="%1$s">Akismet</a> blocks spam from getting to your blog. '), 'http://akismet.com/?return=true' );
469
+ }
470
+
471
+ $link = function_exists( 'esc_url' ) ? esc_url( $link ) : clean_url( $link );
472
+ if ( $queue_count = akismet_spam_count() ) {
473
+ $queue_text = sprintf( _n(
474
+ 'There\'s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
475
+ 'There are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
476
+ $queue_count
477
+ ), number_format_i18n( $queue_count ), $link );
478
+ } else {
479
+ $queue_text = sprintf( __( "There's nothing in your <a href='%1\$s'>spam queue</a> at the moment." ), $link );
480
+ }
481
+
482
+ $text = $intro . '<br />' . $queue_text;
483
+ echo "<p class='akismet-right-now'>$text</p>\n";
484
+ }
485
+
486
+ add_action('rightnow_end', 'akismet_rightnow');
487
+
488
+
489
+ // For WP >= 2.5
490
+ function akismet_check_for_spam_button($comment_status) {
491
+ if ( 'approved' == $comment_status )
492
+ return;
493
+ if ( function_exists('plugins_url') )
494
+ $link = 'admin.php?action=akismet_recheck_queue';
495
+ else
496
+ $link = 'edit-comments.php?page=akismet-admin&amp;recheckqueue=true&amp;noheader=true';
497
+ echo "</div><div class='alignleft'><a class='button-secondary checkforspam' href='$link'>" . __('Check for Spam') . "</a>";
498
+ }
499
+ add_action('manage_comments_nav', 'akismet_check_for_spam_button');
500
+
501
+ function akismet_submit_nonspam_comment ( $comment_id ) {
502
+ global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
503
+ $comment_id = (int) $comment_id;
504
+
505
+ $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
506
+ if ( !$comment ) // it was deleted
507
+ return;
508
+
509
+ // use the original version stored in comment_meta if available
510
+ $as_submitted = get_comment_meta( $comment_id, 'akismet_as_submitted', true);
511
+ if ( $as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content']) ) {
512
+ $comment = (object) array_merge( (array)$comment, $as_submitted );
513
+ }
514
+
515
+ $comment->blog = get_bloginfo('url');
516
+ $comment->blog_lang = get_locale();
517
+ $comment->blog_charset = get_option('blog_charset');
518
+ $comment->permalink = get_permalink($comment->comment_post_ID);
519
+ $comment->reporter_ip = $_SERVER['REMOTE_ADDR'];
520
+ if ( is_object($current_user) ) {
521
+ $comment->reporter = $current_user->user_login;
522
+ }
523
+ if ( is_object($current_site) ) {
524
+ $comment->site_domain = $current_site->domain;
525
+ }
526
+
527
+ $comment->user_role = '';
528
+ if ( isset( $comment->user_ID ) )
529
+ $comment->user_role = akismet_get_user_roles($comment->user_ID);
530
+
531
+ if ( akismet_test_mode() )
532
+ $comment->is_test = 'true';
533
+
534
+ $post = get_post( $comment->comment_post_ID );
535
+ $comment->comment_post_modified_gmt = $post->post_modified_gmt;
536
+
537
+ $query_string = '';
538
+ foreach ( $comment as $key => $data )
539
+ $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
540
+
541
+ $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-ham", $akismet_api_port);
542
+ if ( $comment->reporter ) {
543
+ akismet_update_comment_history( $comment_id, sprintf( __('%s reported this comment as not spam'), $comment->reporter ), 'report-ham' );
544
+ update_comment_meta( $comment_id, 'akismet_user_result', 'false' );
545
+ update_comment_meta( $comment_id, 'akismet_user', $comment->reporter );
546
+ }
547
+
548
+ do_action('akismet_submit_nonspam_comment', $comment_id, $response[1]);
549
+ }
550
+
551
+ function akismet_submit_spam_comment ( $comment_id ) {
552
+ global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
553
+ $comment_id = (int) $comment_id;
554
+
555
+ $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
556
+ if ( !$comment ) // it was deleted
557
+ return;
558
+ if ( 'spam' != $comment->comment_approved )
559
+ return;
560
+
561
+ // use the original version stored in comment_meta if available
562
+ $as_submitted = get_comment_meta( $comment_id, 'akismet_as_submitted', true);
563
+ if ( $as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content']) ) {
564
+ $comment = (object) array_merge( (array)$comment, $as_submitted );
565
+ }
566
+
567
+ $comment->blog = get_bloginfo('url');
568
+ $comment->blog_lang = get_locale();
569
+ $comment->blog_charset = get_option('blog_charset');
570
+ $comment->permalink = get_permalink($comment->comment_post_ID);
571
+ $comment->reporter_ip = $_SERVER['REMOTE_ADDR'];
572
+ if ( is_object($current_user) ) {
573
+ $comment->reporter = $current_user->user_login;
574
+ }
575
+ if ( is_object($current_site) ) {
576
+ $comment->site_domain = $current_site->domain;
577
+ }
578
+
579
+ $comment->user_role = '';
580
+ if ( isset( $comment->user_ID ) )
581
+ $comment->user_role = akismet_get_user_roles($comment->user_ID);
582
+
583
+ if ( akismet_test_mode() )
584
+ $comment->is_test = 'true';
585
+
586
+ $post = get_post( $comment->comment_post_ID );
587
+ $comment->comment_post_modified_gmt = $post->post_modified_gmt;
588
+
589
+ $query_string = '';
590
+ foreach ( $comment as $key => $data )
591
+ $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
592
+
593
+ $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-spam", $akismet_api_port);
594
+ if ( $comment->reporter ) {
595
+ akismet_update_comment_history( $comment_id, sprintf( __('%s reported this comment as spam'), $comment->reporter ), 'report-spam' );
596
+ update_comment_meta( $comment_id, 'akismet_user_result', 'true' );
597
+ update_comment_meta( $comment_id, 'akismet_user', $comment->reporter );
598
+ }
599
+ do_action('akismet_submit_spam_comment', $comment_id, $response[1]);
600
+ }
601
+
602
+ // For WP 2.7+
603
+ function akismet_transition_comment_status( $new_status, $old_status, $comment ) {
604
+ if ( $new_status == $old_status )
605
+ return;
606
+
607
+ # we don't need to record a history item for deleted comments
608
+ if ( $new_status == 'delete' )
609
+ return;
610
+
611
+ if ( !is_admin() )
612
+ return;
613
+
614
+ if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) && !current_user_can( 'moderate_comments' ) )
615
+ return;
616
+
617
+ if ( defined('WP_IMPORTING') && WP_IMPORTING == true )
618
+ return;
619
+
620
+ // if this is present, it means the status has been changed by a re-check, not an explicit user action
621
+ if ( get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) )
622
+ return;
623
+
624
+ global $current_user;
625
+ $reporter = '';
626
+ if ( is_object( $current_user ) )
627
+ $reporter = $current_user->user_login;
628
+
629
+ // Assumption alert:
630
+ // We want to submit comments to Akismet only when a moderator explicitly spams or approves it - not if the status
631
+ // is changed automatically by another plugin. Unfortunately WordPress doesn't provide an unambiguous way to
632
+ // determine why the transition_comment_status action was triggered. And there are several different ways by which
633
+ // to spam and unspam comments: bulk actions, ajax, links in moderation emails, the dashboard, and perhaps others.
634
+ // We'll assume that this is an explicit user action if POST or GET has an 'action' key.
635
+ if ( isset($_POST['action']) || isset($_GET['action']) ) {
636
+ if ( $new_status == 'spam' && ( $old_status == 'approved' || $old_status == 'unapproved' || !$old_status ) ) {
637
+ return akismet_submit_spam_comment( $comment->comment_ID );
638
+ } elseif ( $old_status == 'spam' && ( $new_status == 'approved' || $new_status == 'unapproved' ) ) {
639
+ return akismet_submit_nonspam_comment( $comment->comment_ID );
640
+ }
641
+ }
642
+
643
+ akismet_update_comment_history( $comment->comment_ID, sprintf( __('%s changed the comment status to %s'), $reporter, $new_status ), 'status-' . $new_status );
644
+ }
645
+
646
+ add_action( 'transition_comment_status', 'akismet_transition_comment_status', 10, 3 );
647
+
648
+ // Total spam in queue
649
+ // get_option( 'akismet_spam_count' ) is the total caught ever
650
+ function akismet_spam_count( $type = false ) {
651
+ global $wpdb;
652
+
653
+ if ( !$type ) { // total
654
+ $count = wp_cache_get( 'akismet_spam_count', 'widget' );
655
+ if ( false === $count ) {
656
+ if ( function_exists('wp_count_comments') ) {
657
+ $count = wp_count_comments();
658
+ $count = $count->spam;
659
+ } else {
660
+ $count = (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam'");
661
+ }
662
+ wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 );
663
+ }
664
+ return $count;
665
+ } elseif ( 'comments' == $type || 'comment' == $type ) { // comments
666
+ $type = '';
667
+ } else { // pingback, trackback, ...
668
+ $type = $wpdb->escape( $type );
669
+ }
670
+
671
+ return (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam' AND comment_type='$type'");
672
+ }
673
+
674
+
675
+ function akismet_recheck_queue() {
676
+ global $wpdb, $akismet_api_host, $akismet_api_port;
677
+
678
+ akismet_fix_scheduled_recheck();
679
+
680
+ if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) )
681
+ return;
682
+
683
+ $moderation = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0'", ARRAY_A );
684
+ foreach ( (array) $moderation as $c ) {
685
+ $c['user_ip'] = $c['comment_author_IP'];
686
+ $c['user_agent'] = $c['comment_agent'];
687
+ $c['referrer'] = '';
688
+ $c['blog'] = get_bloginfo('url');
689
+ $c['blog_lang'] = get_locale();
690
+ $c['blog_charset'] = get_option('blog_charset');
691
+ $c['permalink'] = get_permalink($c['comment_post_ID']);
692
+
693
+ $c['user_role'] = '';
694
+ if ( isset( $c['user_ID'] ) )
695
+ $c['user_role'] = akismet_get_user_roles($c['user_ID']);
696
+
697
+ if ( akismet_test_mode() )
698
+ $c['is_test'] = 'true';
699
+
700
+ $id = (int) $c['comment_ID'];
701
+
702
+ $query_string = '';
703
+ foreach ( $c as $key => $data )
704
+ $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
705
+
706
+ add_comment_meta( $c['comment_ID'], 'akismet_rechecking', true );
707
+ $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
708
+ if ( 'true' == $response[1] ) {
709
+ wp_set_comment_status($c['comment_ID'], 'spam');
710
+ update_comment_meta( $c['comment_ID'], 'akismet_result', 'true' );
711
+ delete_comment_meta( $c['comment_ID'], 'akismet_error' );
712
+ akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and caught this comment as spam'), 'check-spam' );
713
+
714
+ } elseif ( 'false' == $response[1] ) {
715
+ update_comment_meta( $c['comment_ID'], 'akismet_result', 'false' );
716
+ delete_comment_meta( $c['comment_ID'], 'akismet_error' );
717
+ akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and cleared this comment'), 'check-ham' );
718
+ // abnormal result: error
719
+ } else {
720
+ update_comment_meta( $c['comment_ID'], 'akismet_result', 'error' );
721
+ akismet_update_comment_history( $c['comment_ID'], sprintf( __('Akismet was unable to re-check this comment (response: %s)'), substr($response[1], 0, 50)), 'check-error' );
722
+ }
723
+
724
+ delete_comment_meta( $c['comment_ID'], 'akismet_rechecking' );
725
+ }
726
+ $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : admin_url( 'edit-comments.php' );
727
+ wp_safe_redirect( $redirect_to );
728
+ exit;
729
+ }
730
+
731
+ add_action('admin_action_akismet_recheck_queue', 'akismet_recheck_queue');
732
+
733
+ // Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link
734
+ function akismet_remove_comment_author_url() {
735
+ if ( !empty($_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
736
+ global $wpdb;
737
+ $comment = get_comment( intval($_POST['id']), ARRAY_A );
738
+ if (current_user_can('edit_comment', $comment['comment_ID'])) {
739
+ $comment['comment_author_url'] = '';
740
+ do_action( 'comment_remove_author_url' );
741
+ print(wp_update_comment( $comment ));
742
+ die();
743
+ }
744
+ }
745
+ }
746
+
747
+ add_action('wp_ajax_comment_author_deurl', 'akismet_remove_comment_author_url');
748
+
749
+ function akismet_add_comment_author_url() {
750
+ if ( !empty( $_POST['id'] ) && !empty( $_POST['url'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
751
+ global $wpdb;
752
+ $comment = get_comment( intval($_POST['id']), ARRAY_A );
753
+ if (current_user_can('edit_comment', $comment['comment_ID'])) {
754
+ $comment['comment_author_url'] = esc_url($_POST['url']);
755
+ do_action( 'comment_add_author_url' );
756
+ print(wp_update_comment( $comment ));
757
+ die();
758
+ }
759
+ }
760
+ }
761
+
762
+ add_action('wp_ajax_comment_author_reurl', 'akismet_add_comment_author_url');
763
+
764
+ // Check connectivity between the WordPress blog and Akismet's servers.
765
+ // 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).
766
+ function akismet_check_server_connectivity() {
767
+ global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
768
+
769
+ $test_host = 'rest.akismet.com';
770
+
771
+ // Some web hosts may disable one or both functions
772
+ if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') )
773
+ return array();
774
+
775
+ $ips = gethostbynamel($test_host);
776
+ if ( !$ips || !is_array($ips) || !count($ips) )
777
+ return array();
778
+
779
+ $servers = array();
780
+ foreach ( $ips as $ip ) {
781
+ $response = akismet_verify_key( akismet_get_key(), $ip );
782
+ // even if the key is invalid, at least we know we have connectivity
783
+ if ( $response == 'valid' || $response == 'invalid' )
784
+ $servers[$ip] = true;
785
+ else
786
+ $servers[$ip] = false;
787
+ }
788
+
789
+ return $servers;
790
+ }
791
+
792
+ // Check the server connectivity and store the results in an option.
793
+ // Cached results will be used if not older than the specified timeout in seconds; use $cache_timeout = 0 to force an update.
794
+ // Returns the same associative array as akismet_check_server_connectivity()
795
+ function akismet_get_server_connectivity( $cache_timeout = 86400 ) {
796
+ $servers = get_option('akismet_available_servers');
797
+ if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false )
798
+ return $servers;
799
+
800
+ // There's a race condition here but the effect is harmless.
801
+ $servers = akismet_check_server_connectivity();
802
+ update_option('akismet_available_servers', $servers);
803
+ update_option('akismet_connectivity_time', time());
804
+ return $servers;
805
+ }
806
+
807
+ // Returns true if server connectivity was OK at the last check, false if there was a problem that needs to be fixed.
808
+ function akismet_server_connectivity_ok() {
809
+ // skip the check on WPMU because the status page is hidden
810
+ global $wpcom_api_key;
811
+ if ( $wpcom_api_key )
812
+ return true;
813
+ $servers = akismet_get_server_connectivity();
814
+ return !( empty($servers) || !count($servers) || count( array_filter($servers) ) < count($servers) );
815
+ }
816
+
817
+ function akismet_admin_menu() {
818
+ if ( class_exists( 'Jetpack' ) ) {
819
+ add_action( 'jetpack_admin_menu', 'akismet_load_menu' );
820
+ } else {
821
+ akismet_load_menu();
822
+ }
823
+ }
824
+
825
+ function akismet_load_menu() {
826
+ if ( class_exists( 'Jetpack' ) ) {
827
+ add_submenu_page( 'jetpack', __( 'Akismet Configuration' ), __( 'Akismet Configuration' ), 'manage_options', 'akismet-key-config', 'akismet_conf' );
828
+ add_submenu_page( 'jetpack', __( 'Akismet Stats' ), __( 'Akismet Stats' ), 'manage_options', 'akismet-stats-display', 'akismet_stats_display' );
829
+ } else {
830
+ add_submenu_page('plugins.php', __('Akismet Configuration'), __('Akismet Configuration'), 'manage_options', 'akismet-key-config', 'akismet_conf');
831
+ add_submenu_page('index.php', __('Akismet Stats'), __('Akismet Stats'), 'manage_options', 'akismet-stats-display', 'akismet_stats_display');
832
+ }
833
+ }
akismet.css ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #submitted-on { position: relative; }
2
+ #the-comment-list .author .akismet-user-comment-count { display: inline; }
3
+ #the-comment-list .author a span { text-decoration: none; color: #999; }
4
+ #the-comment-list .remove_url { margin-left: 3px; color: #999; padding: 2px 3px 2px 0; }
5
+ #the-comment-list .remove_url:hover { color: #A7301F; font-weight: bold; padding: 2px 2px 2px 0; }
6
+ #dashboard_recent_comments .akismet-status { display: none; } /* never show the flagged by text on the dashboard */
7
+ .akismet-status { float: right; }
8
+ .akismet-status a { color: #AAA; font-style: italic; }
9
+ span.comment-link a { text-decoration: underline; }
10
+ span.comment-link:after { content: " " attr(title) " "; color: #aaa; text-decoration: none; }
11
+ .mshot-arrow { width: 0; height: 0; border-top: 10px solid transparent; border-bottom: 10px solid transparent; border-right:10px solid #5C5C5C; position: absolute; left: -6px; top: 91px; }
12
+ .mshot-container { background: #5C5C5C; position: absolute; top: -94px; padding: 7px; width: 450px; height: 338px; z-index: 20000; -moz-border-radius:6px; border-radius:6px; -webkit-border-radius:6px; }
akismet.js ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function () {
2
+ jQuery('.akismet-status').each(function () {
3
+ var thisId = jQuery(this).attr('commentid');
4
+ jQuery(this).prependTo('#comment-' + thisId + ' .column-comment div:first-child');
5
+ });
6
+ jQuery('.akismet-user-comment-count').each(function () {
7
+ var thisId = jQuery(this).attr('commentid');
8
+ jQuery(this).insertAfter('#comment-' + thisId + ' .author strong:first').show();
9
+ });
10
+ jQuery('#the-comment-list tr.comment .column-author a[title ^= "http://"]').each(function () {
11
+ var thisTitle = jQuery(this).attr('title');
12
+ thisCommentId = jQuery(this).parents('tr:first').attr('id').split("-");
13
+
14
+ jQuery(this).attr("id", "author_comment_url_"+ thisCommentId[1]);
15
+
16
+ if (thisTitle) {
17
+ jQuery(this).after(' <a href="#" class="remove_url" commentid="'+ thisCommentId[1] +'" title="Remove this URL">x</a>');
18
+ }
19
+ });
20
+ jQuery('.remove_url').live('click', function () {
21
+ var thisId = jQuery(this).attr('commentid');
22
+ var data = {
23
+ action: 'comment_author_deurl',
24
+ _wpnonce: WPAkismet.comment_author_url_nonce,
25
+ id: thisId
26
+ };
27
+ jQuery.ajax({
28
+ url: ajaxurl,
29
+ type: 'POST',
30
+ data: data,
31
+ beforeSend: function () {
32
+ // Removes "x" link
33
+ jQuery("a[commentid='"+ thisId +"']").hide();
34
+ // Show temp status
35
+ jQuery("#author_comment_url_"+ thisId).html('<span>Removing...</span>');
36
+ },
37
+ success: function (response) {
38
+ if (response) {
39
+ // Show status/undo link
40
+ jQuery("#author_comment_url_"+ thisId).attr('cid', thisId).addClass('akismet_undo_link_removal').html('<span>URL removed (</span>undo<span>)</span>');
41
+ }
42
+ }
43
+ });
44
+
45
+ return false;
46
+ });
47
+ jQuery('.akismet_undo_link_removal').live('click', function () {
48
+ var thisId = jQuery(this).attr('cid');
49
+ var thisUrl = jQuery(this).attr('href').replace("http://www.", "").replace("http://", "");
50
+ var data = {
51
+ action: 'comment_author_reurl',
52
+ _wpnonce: WPAkismet.comment_author_url_nonce,
53
+ id: thisId,
54
+ url: thisUrl
55
+ };
56
+ jQuery.ajax({
57
+ url: ajaxurl,
58
+ type: 'POST',
59
+ data: data,
60
+ beforeSend: function () {
61
+ // Show temp status
62
+ jQuery("#author_comment_url_"+ thisId).html('<span>Re-adding…</span>');
63
+ },
64
+ success: function (response) {
65
+ if (response) {
66
+ // Add "x" link
67
+ jQuery("a[commentid='"+ thisId +"']").show();
68
+ // Show link
69
+ jQuery("#author_comment_url_"+ thisId).removeClass('akismet_undo_link_removal').html(thisUrl);
70
+ }
71
+ }
72
+ });
73
+
74
+ return false;
75
+ });
76
+ jQuery('a[id^="author_comment_url"]').mouseover(function () {
77
+ var wpcomProtocol = ( 'https:' === location.protocol ) ? 'https://' : 'http://';
78
+ // Need to determine size of author column
79
+ var thisParentWidth = jQuery(this).parent().width();
80
+ // It changes based on if there is a gravatar present
81
+ thisParentWidth = (jQuery(this).parent().find('.grav-hijack').length) ? thisParentWidth - 42 + 'px' : thisParentWidth + 'px';
82
+ if (jQuery(this).find('.mShot').length == 0 && !jQuery(this).hasClass('akismet_undo_link_removal')) {
83
+ var thisId = jQuery(this).attr('id').replace('author_comment_url_', '');
84
+ jQuery('.widefat td').css('overflow', 'visible');
85
+ jQuery(this).css('position', 'relative');
86
+ var thisHref = jQuery.URLEncode(jQuery(this).attr('href'));
87
+ jQuery(this).append('<div class="mShot mshot-container" style="left: '+thisParentWidth+'"><div class="mshot-arrow"></div><img src="'+wpcomProtocol+'s0.wordpress.com/mshots/v1/'+thisHref+'?w=450" width="450" class="mshot-image_'+thisId+'" style="margin: 0;" /></div>');
88
+ setTimeout(function () {
89
+ jQuery('.mshot-image_'+thisId).attr('src', wpcomProtocol+'s0.wordpress.com/mshots/v1/'+thisHref+'?w=450&r=2');
90
+ }, 6000);
91
+ setTimeout(function () {
92
+ jQuery('.mshot-image_'+thisId).attr('src', wpcomProtocol+'s0.wordpress.com/mshots/v1/'+thisHref+'?w=450&r=3');
93
+ }, 12000);
94
+ } else {
95
+ jQuery(this).find('.mShot').css('left', thisParentWidth).show();
96
+ }
97
+ }).mouseout(function () {
98
+ jQuery(this).find('.mShot').hide();
99
+ });
100
+ });
101
+ // URL encode plugin
102
+ jQuery.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
103
+ while(x<c.length){var m=r.exec(c.substr(x));
104
+ if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
105
+ }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
106
+ o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;}
107
+ });
108
+ // Preload mshot images after everything else has loaded
109
+ jQuery(window).load(function() {
110
+ var wpcomProtocol = ( 'https:' === location.protocol ) ? 'https://' : 'http://';
111
+ jQuery('a[id^="author_comment_url"]').each(function () {
112
+ jQuery.get(wpcomProtocol+'s0.wordpress.com/mshots/v1/'+jQuery.URLEncode(jQuery(this).attr('href'))+'?w=450');
113
+ });
114
+ });
akismet.php CHANGED
@@ -4,30 +4,38 @@
4
  */
5
  /*
6
  Plugin Name: Akismet
7
- Plugin URI: http://akismet.com/
8
- Description: Akismet checks your comments against the Akismet web service to see if they look like spam or not. You need an <a href="http://akismet.com/get/">API key</a> to use it. You can review the spam it catches under "Comments." To show off your Akismet stats just put <code>&lt;?php akismet_counter(); ?&gt;</code> in your template. See also: <a href="http://wordpress.org/extend/plugins/stats/">WP Stats plugin</a>.
9
- Version: 2.4.1
10
  Author: Automattic
11
  Author URI: http://automattic.com/wordpress-plugins/
12
- License: GPLv2
13
  */
14
 
15
  /*
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License as published by
18
- the Free Software Foundation; version 2 of the License.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
28
  */
29
 
30
- define('AKISMET_VERSION', '2.4.1');
 
 
 
 
 
 
 
31
 
32
  /** If you hardcode a WP.com API key here, all key config screens will be hidden */
33
  if ( defined('WPCOM_API_KEY') )
@@ -35,14 +43,13 @@ if ( defined('WPCOM_API_KEY') )
35
  else
36
  $wpcom_api_key = '';
37
 
38
- // Make sure we don't expose any info if called directly
39
- if ( !function_exists( 'add_action' ) ) {
40
- echo "Hi there! I'm just a plugin, not much I can do when called directly.";
41
- exit;
42
- }
43
 
44
- if ( $wp_db_version <= 9872 )
45
- include_once( dirname(__FILE__) . '/legacy.php' );
46
 
47
  function akismet_init() {
48
  global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
@@ -53,251 +60,9 @@ function akismet_init() {
53
  $akismet_api_host = get_option('wordpress_api_key') . '.rest.akismet.com';
54
 
55
  $akismet_api_port = 80;
56
- add_action('admin_menu', 'akismet_config_page');
57
- add_action('admin_menu', 'akismet_stats_page');
58
- akismet_admin_warnings();
59
  }
60
  add_action('init', 'akismet_init');
61
 
62
- function akismet_admin_init() {
63
- if ( function_exists( 'get_plugin_page_hook' ) )
64
- $hook = get_plugin_page_hook( 'akismet-stats-display', 'index.php' );
65
- else
66
- $hook = 'dashboard_page_akismet-stats-display';
67
- add_action('admin_head-'.$hook, 'akismet_stats_script');
68
- }
69
- add_action('admin_init', 'akismet_admin_init');
70
-
71
- if ( !function_exists('wp_nonce_field') ) {
72
- function akismet_nonce_field($action = -1) { return; }
73
- $akismet_nonce = -1;
74
- } else {
75
- function akismet_nonce_field($action = -1) { return wp_nonce_field($action); }
76
- $akismet_nonce = 'akismet-update-key';
77
- }
78
-
79
- if ( !function_exists('number_format_i18n') ) {
80
- function number_format_i18n( $number, $decimals = null ) { return number_format( $number, $decimals ); }
81
- }
82
-
83
- function akismet_config_page() {
84
- if ( function_exists('add_submenu_page') )
85
- add_submenu_page('plugins.php', __('Akismet Configuration'), __('Akismet Configuration'), 'manage_options', 'akismet-key-config', 'akismet_conf');
86
-
87
- }
88
-
89
- function akismet_conf() {
90
- global $akismet_nonce, $wpcom_api_key;
91
-
92
- if ( isset($_POST['submit']) ) {
93
- if ( function_exists('current_user_can') && !current_user_can('manage_options') )
94
- die(__('Cheatin&#8217; uh?'));
95
-
96
- check_admin_referer( $akismet_nonce );
97
- $key = preg_replace( '/[^a-h0-9]/i', '', $_POST['key'] );
98
-
99
- if ( empty($key) ) {
100
- $key_status = 'empty';
101
- $ms[] = 'new_key_empty';
102
- delete_option('wordpress_api_key');
103
- } else {
104
- $key_status = akismet_verify_key( $key );
105
- }
106
-
107
- if ( $key_status == 'valid' ) {
108
- update_option('wordpress_api_key', $key);
109
- $ms[] = 'new_key_valid';
110
- } else if ( $key_status == 'invalid' ) {
111
- $ms[] = 'new_key_invalid';
112
- } else if ( $key_status == 'failed' ) {
113
- $ms[] = 'new_key_failed';
114
- }
115
-
116
- if ( isset( $_POST['akismet_discard_month'] ) )
117
- update_option( 'akismet_discard_month', 'true' );
118
- else
119
- update_option( 'akismet_discard_month', 'false' );
120
- } elseif ( isset($_POST['check']) ) {
121
- akismet_get_server_connectivity(0);
122
- }
123
-
124
- if ( empty( $key_status) || $key_status != 'valid' ) {
125
- $key = get_option('wordpress_api_key');
126
- if ( empty( $key ) ) {
127
- if ( empty( $key_status ) || $key_status != 'failed' ) {
128
- if ( akismet_verify_key( '1234567890ab' ) == 'failed' )
129
- $ms[] = 'no_connection';
130
- else
131
- $ms[] = 'key_empty';
132
- }
133
- $key_status = 'empty';
134
- } else {
135
- $key_status = akismet_verify_key( $key );
136
- }
137
- if ( $key_status == 'valid' ) {
138
- $ms[] = 'key_valid';
139
- } else if ( $key_status == 'invalid' ) {
140
- delete_option('wordpress_api_key');
141
- $ms[] = 'key_empty';
142
- } else if ( !empty($key) && $key_status == 'failed' ) {
143
- $ms[] = 'key_failed';
144
- }
145
- }
146
-
147
- $messages = array(
148
- 'new_key_empty' => array('color' => 'aa0', 'text' => __('Your key has been cleared.')),
149
- 'new_key_valid' => array('color' => '2d2', 'text' => __('Your key has been verified. Happy blogging!')),
150
- 'new_key_invalid' => array('color' => 'd22', 'text' => __('The key you entered is invalid. Please double-check it.')),
151
- '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.')),
152
- 'no_connection' => array('color' => 'd22', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')),
153
- 'key_empty' => array('color' => 'aa0', 'text' => sprintf(__('Please enter an API key. (<a href="%s" style="color:#fff">Get your key.</a>)'), 'http://akismet.com/get/')),
154
- 'key_valid' => array('color' => '2d2', 'text' => __('This key is valid.')),
155
- '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.')));
156
- ?>
157
- <?php if ( !empty($_POST['submit'] ) ) : ?>
158
- <div id="message" class="updated fade"><p><strong><?php _e('Options saved.') ?></strong></p></div>
159
- <?php endif; ?>
160
- <div class="wrap">
161
- <h2><?php _e('Akismet Configuration'); ?></h2>
162
- <div class="narrow">
163
- <form action="" method="post" id="akismet-conf" style="margin: auto; width: 400px; ">
164
- <?php if ( !$wpcom_api_key ) { ?>
165
- <p><?php printf(__('For many people, <a href="%1$s">Akismet</a> will greatly reduce or even completely eliminate the comment and trackback spam you get on your site. If one does happen to get through, simply mark it as "spam" on the moderation screen and Akismet will learn from the mistakes. If you don\'t have an API key yet, you can get one at <a href="%2$s">Akismet.com</a>.'), 'http://akismet.com/', 'http://akismet.com/get/'); ?></p>
166
-
167
- <h3><label for="key"><?php _e('Akismet API Key'); ?></label></h3>
168
- <?php foreach ( $ms as $m ) : ?>
169
- <p style="padding: .5em; background-color: #<?php echo $messages[$m]['color']; ?>; color: #fff; font-weight: bold;"><?php echo $messages[$m]['text']; ?></p>
170
- <?php endforeach; ?>
171
- <p><input id="key" name="key" type="text" size="15" maxlength="12" value="<?php echo get_option('wordpress_api_key'); ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;" /> (<?php _e('<a href="http://akismet.com/get/">What is this?</a>'); ?>)</p>
172
- <?php if ( isset( $invalid_key) && $invalid_key ) { ?>
173
- <h3><?php _e('Why might my key be invalid?'); ?></h3>
174
- <p><?php _e('This can mean one of two things, either you copied the key wrong or that the plugin is unable to reach the Akismet servers, which is most often caused by an issue with your web host around firewalls or similar.'); ?></p>
175
- <?php } ?>
176
- <?php } ?>
177
- <?php akismet_nonce_field($akismet_nonce) ?>
178
- <p><label><input name="akismet_discard_month" id="akismet_discard_month" value="true" type="checkbox" <?php if ( get_option('akismet_discard_month') == 'true' ) echo ' checked="checked" '; ?> /> <?php _e('Automatically discard spam comments on posts older than a month.'); ?></label></p>
179
- <p class="submit"><input type="submit" name="submit" value="<?php _e('Update options &raquo;'); ?>" /></p>
180
- </form>
181
-
182
- <form action="" method="post" id="akismet-connectivity" style="margin: auto; width: 400px; ">
183
-
184
- <h3><?php _e('Server Connectivity'); ?></h3>
185
- <?php
186
- if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') ) {
187
- ?>
188
- <p style="padding: .5em; background-color: #d22; color: #fff; font-weight:bold;"><?php _e('Network functions are disabled.'); ?></p>
189
- <p><?php echo sprintf( __('Your web host or server administrator has disabled PHP\'s <code>fsockopen</code> or <code>gethostbynamel</code> functions. <strong>Akismet cannot work correctly until this is fixed.</strong> Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet\'s system requirements</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
190
- <?php
191
- } else {
192
- $servers = akismet_get_server_connectivity();
193
- $fail_count = count($servers) - count( array_filter($servers) );
194
- if ( is_array($servers) && count($servers) > 0 ) {
195
- // some connections work, some fail
196
- if ( $fail_count > 0 && $fail_count < count($servers) ) { ?>
197
- <p style="padding: .5em; background-color: #aa0; color: #fff; font-weight:bold;"><?php _e('Unable to reach some Akismet servers.'); ?></p>
198
- <p><?php echo sprintf( __('A network problem or firewall is blocking some connections from your web server to Akismet.com. Akismet is working but this may cause problems during times of network congestion. Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
199
- <?php
200
- // all connections fail
201
- } elseif ( $fail_count > 0 ) { ?>
202
- <p style="padding: .5em; background-color: #d22; color: #fff; font-weight:bold;"><?php _e('Unable to reach any Akismet servers.'); ?></p>
203
- <p><?php echo sprintf( __('A network problem or firewall is blocking all connections from your web server to Akismet.com. <strong>Akismet cannot work correctly until this is fixed.</strong> Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
204
- <?php
205
- // all connections work
206
- } else { ?>
207
- <p style="padding: .5em; background-color: #2d2; color: #fff; font-weight:bold;"><?php _e('All Akismet servers are available.'); ?></p>
208
- <p><?php _e('Akismet is working correctly. All servers are accessible.'); ?></p>
209
- <?php
210
- }
211
- } else {
212
- ?>
213
- <p style="padding: .5em; background-color: #d22; color: #fff; font-weight:bold;"><?php _e('Unable to find Akismet servers.'); ?></p>
214
- <p><?php echo sprintf( __('A DNS problem or firewall is preventing all access from your web server to Akismet.com. <strong>Akismet cannot work correctly until this is fixed.</strong> Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
215
- <?php
216
- }
217
- }
218
-
219
- if ( !empty($servers) ) {
220
- ?>
221
- <table style="width: 100%;">
222
- <thead><th><?php _e('Akismet server'); ?></th><th><?php _e('Network Status'); ?></th></thead>
223
- <tbody>
224
- <?php
225
- asort($servers);
226
- foreach ( $servers as $ip => $status ) {
227
- $color = ( $status ? '#2d2' : '#d22');
228
- ?>
229
- <tr>
230
- <td><?php echo htmlspecialchars($ip); ?></td>
231
- <td style="padding: 0 .5em; font-weight:bold; color: #fff; background-color: <?php echo $color; ?>"><?php echo ($status ? __('No problems') : __('Obstructed') ); ?></td>
232
-
233
- <?php
234
- }
235
- }
236
- ?>
237
- </tbody>
238
- </table>
239
- <p><?php if ( get_option('akismet_connectivity_time') ) echo sprintf( __('Last checked %s ago.'), human_time_diff( get_option('akismet_connectivity_time') ) ); ?></p>
240
- <p class="submit"><input type="submit" name="check" value="<?php _e('Check network status &raquo;'); ?>" /></p>
241
- </form>
242
-
243
- </div>
244
- </div>
245
- <?php
246
- }
247
-
248
- function akismet_stats_page() {
249
- if ( function_exists('add_submenu_page') )
250
- add_submenu_page('index.php', __('Akismet Stats'), __('Akismet Stats'), 'manage_options', 'akismet-stats-display', 'akismet_stats_display');
251
-
252
- }
253
-
254
- function akismet_stats_script() {
255
- ?>
256
- <script type="text/javascript">
257
- function resizeIframe() {
258
- var height = document.documentElement.clientHeight;
259
- height -= document.getElementById('akismet-stats-frame').offsetTop;
260
- height += 100; // magic padding
261
-
262
- document.getElementById('akismet-stats-frame').style.height = height +"px";
263
-
264
- };
265
- function resizeIframeInit() {
266
- document.getElementById('akismet-stats-frame').onload = resizeIframe;
267
- window.onresize = resizeIframe;
268
- }
269
- addLoadEvent(resizeIframeInit);
270
- </script><?php
271
- }
272
-
273
-
274
- function akismet_stats_display() {
275
- global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
276
- $blog = urlencode( get_option('home') );
277
- $url = "http://".akismet_get_key().".web.akismet.com/1.0/user-stats.php?blog={$blog}";
278
- ?>
279
- <div class="wrap">
280
- <iframe src="<?php echo $url; ?>" width="100%" height="100%" frameborder="0" id="akismet-stats-frame"></iframe>
281
- </div>
282
- <?php
283
- }
284
-
285
- function akismet_stats() {
286
- if ( !function_exists('did_action') || did_action( 'rightnow_end' ) ) // We already displayed this info in the "Right Now" section
287
- return;
288
- if ( !$count = get_option('akismet_spam_count') )
289
- return;
290
- $path = plugin_basename(__FILE__);
291
- echo '<h3>'.__('Spam').'</h3>';
292
- global $submenu;
293
- if ( isset( $submenu['edit-comments.php'] ) )
294
- $link = 'edit-comments.php';
295
- else
296
- $link = 'edit.php';
297
- echo '<p>'.sprintf(__('<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.'), 'http://akismet.com/', clean_url("$link?page=akismet-admin"), number_format_i18n($count) ).'</p>';
298
- }
299
- add_action('activity_box_end', 'akismet_stats');
300
-
301
  function akismet_get_key() {
302
  global $wpcom_api_key;
303
  if ( !empty($wpcom_api_key) )
@@ -305,119 +70,47 @@ function akismet_get_key() {
305
  return get_option('wordpress_api_key');
306
  }
307
 
308
- function akismet_verify_key( $key, $ip = null ) {
309
  global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
310
  $blog = urlencode( get_option('home') );
311
  if ( $wpcom_api_key )
312
  $key = $wpcom_api_key;
313
  $response = akismet_http_post("key=$key&blog=$blog", 'rest.akismet.com', '/1.1/verify-key', $akismet_api_port, $ip);
314
- if ( !is_array($response) || !isset($response[1]) || $response[1] != 'valid' && $response[1] != 'invalid' )
315
- return 'failed';
316
- return $response[1];
317
  }
318
 
319
- // Check connectivity between the WordPress blog and Akismet's servers.
320
- // 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).
321
- function akismet_check_server_connectivity() {
322
- global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
323
-
324
- $test_host = 'rest.akismet.com';
325
-
326
- // Some web hosts may disable one or both functions
327
- if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') )
328
- return array();
329
 
330
- $ips = gethostbynamel($test_host);
331
- if ( !$ips || !is_array($ips) || !count($ips) )
332
- return array();
333
-
334
- $servers = array();
335
- foreach ( $ips as $ip ) {
336
- $response = akismet_verify_key( akismet_get_key(), $ip );
337
- // even if the key is invalid, at least we know we have connectivity
338
- if ( $response == 'valid' || $response == 'invalid' )
339
- $servers[$ip] = true;
340
- else
341
- $servers[$ip] = false;
342
  }
343
-
344
- return $servers;
345
  }
346
 
347
- // Check the server connectivity and store the results in an option.
348
- // Cached results will be used if not older than the specified timeout in seconds; use $cache_timeout = 0 to force an update.
349
- // Returns the same associative array as akismet_check_server_connectivity()
350
- function akismet_get_server_connectivity( $cache_timeout = 86400 ) {
351
- $servers = get_option('akismet_available_servers');
352
- if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false )
353
- return $servers;
354
-
355
- // There's a race condition here but the effect is harmless.
356
- $servers = akismet_check_server_connectivity();
357
- update_option('akismet_available_servers', $servers);
358
- update_option('akismet_connectivity_time', time());
359
- return $servers;
360
  }
361
 
362
- // Returns true if server connectivity was OK at the last check, false if there was a problem that needs to be fixed.
363
- function akismet_server_connectivity_ok() {
364
- // skip the check on WPMU because the status page is hidden
365
- global $wpcom_api_key;
366
- if ( $wpcom_api_key )
367
  return true;
368
- $servers = akismet_get_server_connectivity();
369
- return !( empty($servers) || !count($servers) || count( array_filter($servers) ) < count($servers) );
370
- }
371
-
372
- function akismet_admin_warnings() {
373
- global $wpcom_api_key;
374
- if ( !get_option('wordpress_api_key') && !$wpcom_api_key && !isset($_POST['submit']) ) {
375
- function akismet_warning() {
376
- echo "
377
- <div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet is almost ready.')."</strong> ".sprintf(__('You must <a href="%1$s">enter your Akismet API key</a> for it to work.'), "plugins.php?page=akismet-key-config")."</p></div>
378
- ";
379
- }
380
- add_action('admin_notices', 'akismet_warning');
381
- return;
382
- } elseif ( get_option('akismet_connectivity_time') && empty($_POST) && is_admin() && !akismet_server_connectivity_ok() ) {
383
- function akismet_warning() {
384
- echo "
385
- <div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet has detected a problem.')."</strong> ".sprintf(__('A server or network problem is preventing Akismet from working correctly. <a href="%1$s">Click here for more information</a> about how to fix the problem.'), "plugins.php?page=akismet-key-config")."</p></div>
386
- ";
387
- }
388
- add_action('admin_notices', 'akismet_warning');
389
- return;
390
- }
391
- }
392
-
393
- function akismet_get_host($host) {
394
- // if all servers are accessible, just return the host name.
395
- // if not, return an IP that was known to be accessible at the last check.
396
- if ( akismet_server_connectivity_ok() ) {
397
- return $host;
398
- } else {
399
- $ips = akismet_get_server_connectivity();
400
- // a firewall may be blocking access to some Akismet IPs
401
- if ( count($ips) > 0 && count(array_filter($ips)) < count($ips) ) {
402
- // use DNS to get current IPs, but exclude any known to be unreachable
403
- $dns = (array)gethostbynamel( rtrim($host, '.') . '.' );
404
- $dns = array_filter($dns);
405
- foreach ( $dns as $ip ) {
406
- if ( array_key_exists( $ip, $ips ) && empty( $ips[$ip] ) )
407
- unset($dns[$ip]);
408
- }
409
- // return a random IP from those available
410
- if ( count($dns) )
411
- return $dns[ array_rand($dns) ];
412
-
413
- }
414
- }
415
- // if all else fails try the host name
416
- return $host;
417
  }
418
 
419
  // return a comma-separated list of role names for the given user
420
- function akismet_get_user_roles($user_id ) {
421
  $roles = false;
422
 
423
  if ( !class_exists('WP_User') )
@@ -428,42 +121,78 @@ function akismet_get_user_roles($user_id ) {
428
  if ( isset($comment_user->roles) )
429
  $roles = join(',', $comment_user->roles);
430
  }
431
-
 
 
 
 
 
 
 
 
 
432
  return $roles;
433
  }
434
 
435
  // Returns array with headers in $response[0] and body in $response[1]
436
  function akismet_http_post($request, $host, $path, $port = 80, $ip=null) {
437
  global $wp_version;
438
-
439
- $akismet_version = constant('AKISMET_VERSION');
440
-
441
- $http_request = "POST $path HTTP/1.0\r\n";
442
- $http_request .= "Host: $host\r\n";
443
- $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";
444
- $http_request .= "Content-Length: " . strlen($request) . "\r\n";
445
- $http_request .= "User-Agent: WordPress/$wp_version | Akismet/$akismet_version\r\n";
446
- $http_request .= "\r\n";
447
- $http_request .= $request;
448
-
449
  $http_host = $host;
450
- // use a specific IP if provided - needed by akismet_check_server_connectivity()
451
- if ( $ip && long2ip(ip2long($ip)) ) {
 
452
  $http_host = $ip;
453
  } else {
454
- $http_host = akismet_get_host($host);
455
  }
456
-
457
- $response = '';
458
- if( false != ( $fs = @fsockopen($http_host, $port, $errno, $errstr, 10) ) ) {
459
- fwrite($fs, $http_request);
460
-
461
- while ( !feof($fs) )
462
- $response .= fgets($fs, 1160); // One TCP-IP packet
463
- fclose($fs);
464
- $response = explode("\r\n\r\n", $response, 2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
  }
466
- return $response;
467
  }
468
 
469
  // filter handler used to return a spam result to pre_comment_approved
@@ -471,36 +200,181 @@ function akismet_result_spam( $approved ) {
471
  // bump the counter here instead of when the filter is added to reduce the possibility of overcounting
472
  if ( $incr = apply_filters('akismet_spam_count_incr', 1) )
473
  update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );
 
 
474
  return 'spam';
475
  }
476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
  function akismet_auto_check_comment( $commentdata ) {
478
- global $akismet_api_host, $akismet_api_port;
479
 
480
  $comment = $commentdata;
481
  $comment['user_ip'] = $_SERVER['REMOTE_ADDR'];
482
- $comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
483
- $comment['referrer'] = $_SERVER['HTTP_REFERER'];
484
  $comment['blog'] = get_option('home');
485
  $comment['blog_lang'] = get_locale();
486
  $comment['blog_charset'] = get_option('blog_charset');
487
  $comment['permalink'] = get_permalink($comment['comment_post_ID']);
488
 
489
- $comment['user_role'] = akismet_get_user_roles($comment['user_ID']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
490
 
491
  $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
492
 
493
- foreach ( $_SERVER as $key => $value )
494
  if ( !in_array( $key, $ignore ) && is_string($value) )
495
  $comment["$key"] = $value;
496
  else
497
  $comment["$key"] = '';
 
 
 
 
498
 
499
  $query_string = '';
500
  foreach ( $comment as $key => $data )
501
  $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
 
 
502
 
503
  $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
 
 
504
  $commentdata['akismet_result'] = $response[1];
505
  if ( 'true' == $response[1] ) {
506
  // akismet_spam_count will be incremented later by akismet_result_spam()
@@ -508,7 +382,6 @@ function akismet_auto_check_comment( $commentdata ) {
508
 
509
  do_action( 'akismet_spam_caught' );
510
 
511
- $post = get_post( $comment['comment_post_ID'] );
512
  $last_updated = strtotime( $post->post_modified_gmt );
513
  $diff = time() - $last_updated;
514
  $diff = $diff / 86400;
@@ -517,7 +390,19 @@ function akismet_auto_check_comment( $commentdata ) {
517
  // akismet_result_spam() won't be called so bump the counter here
518
  if ( $incr = apply_filters('akismet_spam_count_incr', 1) )
519
  update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );
520
- die;
 
 
 
 
 
 
 
 
 
 
 
 
521
  }
522
  }
523
 
@@ -529,361 +414,200 @@ function akismet_auto_check_comment( $commentdata ) {
529
  // WP 2.0: run this one time in ten
530
  akismet_delete_old();
531
  }
 
 
 
532
  return $commentdata;
533
  }
534
 
 
 
535
  function akismet_delete_old() {
536
  global $wpdb;
537
  $now_gmt = current_time('mysql', 1);
538
  $comment_ids = $wpdb->get_col("SELECT comment_id FROM $wpdb->comments WHERE DATE_SUB('$now_gmt', INTERVAL 15 DAY) > comment_date_gmt AND comment_approved = 'spam'");
539
  if ( empty( $comment_ids ) )
540
  return;
 
 
541
 
542
  do_action( 'delete_comment', $comment_ids );
543
- $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_id IN ( " . implode( ', ', $comment_ids ) . " )");
 
 
544
  $n = mt_rand(1, 5000);
545
  if ( apply_filters('akismet_optimize_table', ($n == 11)) ) // lucky number
546
  $wpdb->query("OPTIMIZE TABLE $wpdb->comments");
547
 
548
  }
549
 
550
- add_action('akismet_scheduled_delete', 'akismet_delete_old');
 
551
 
552
- function akismet_submit_nonspam_comment ( $comment_id ) {
553
- global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
554
- $comment_id = (int) $comment_id;
555
 
556
- $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
557
- if ( !$comment ) // it was deleted
 
558
  return;
559
- $comment->blog = get_option('home');
560
- $comment->blog_lang = get_locale();
561
- $comment->blog_charset = get_option('blog_charset');
562
- $comment->permalink = get_permalink($comment->comment_post_ID);
563
- if ( is_object($current_user) ) {
564
- $comment->reporter = $current_user->user_login;
565
  }
566
- if ( is_object($current_site) ) {
567
- $comment->site_domain = $current_site->domain;
568
- }
569
-
570
- $comment->user_role = '';
571
- if ( isset( $comment->user_ID ) )
572
- $comment->user_role = akismet_get_user_roles($comment->user_ID);
573
-
574
- $query_string = '';
575
- foreach ( $comment as $key => $data )
576
- $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
577
 
578
- $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-ham", $akismet_api_port);
579
- do_action('akismet_submit_nonspam_comment', $comment_id, $response[1]);
580
- }
 
581
 
582
- function akismet_submit_spam_comment ( $comment_id ) {
583
- global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
584
- $comment_id = (int) $comment_id;
585
 
586
- $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
587
- if ( !$comment ) // it was deleted
588
- return;
589
- if ( 'spam' != $comment->comment_approved )
590
- return;
591
- $comment->blog = get_option('home');
592
- $comment->blog_lang = get_locale();
593
- $comment->blog_charset = get_option('blog_charset');
594
- $comment->permalink = get_permalink($comment->comment_post_ID);
595
- if ( is_object($current_user) ) {
596
- $comment->reporter = $current_user->user_login;
597
  }
598
- if ( is_object($current_site) ) {
599
- $comment->site_domain = $current_site->domain;
 
 
 
600
  }
 
 
601
 
602
- $comment->user_role = '';
603
- if ( !isset( $comment->user_id ) )
604
- $comment->user_role = akismet_get_user_roles($comment->user_ID);
605
 
606
- $query_string = '';
607
- foreach ( $comment as $key => $data )
608
- $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
609
 
610
- $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-spam", $akismet_api_port);
611
- do_action('akismet_submit_spam_comment', $comment_id, $response[1]);
612
- }
 
613
 
614
- add_action('preprocess_comment', 'akismet_auto_check_comment', 1);
 
 
 
 
 
 
 
 
 
 
615
 
616
- // For old versions of WP only
617
- function akismet_set_comment_status( $comment_id, $status ) {
618
- if ( $status == 'spam' ) {
619
- akismet_submit_spam_comment( $comment_id );
620
- } elseif ( $status == 'approve' ) {
621
- akismet_submit_nonspam_comment( $comment_id );
622
- }
623
- }
624
 
625
- // For WP 2.7+
626
- function akismet_transition_comment_status( $new_status, $old_status, $comment ) {
627
- if ( $new_status == $old_status )
628
- return;
629
-
630
- if ( $new_status == 'spam' ) {
631
- akismet_submit_spam_comment( $comment->comment_ID );
632
- } elseif ( $old_status == 'spam' && ( $new_status == 'approved' || $new_status == 'unapproved' ) ) {
633
- akismet_submit_nonspam_comment( $comment->comment_ID );
634
- }
635
  }
636
 
637
- function akismet_spamtoham( $comment ) { akismet_submit_nonspam_comment( $comment->comment_ID ); }
638
-
639
- if ( function_exists( 'wp_transition_comment_status' ) ) {
640
- add_action( 'transition_comment_status', 'akismet_transition_comment_status', 10, 3 );
641
- } else {
642
- add_action('wp_set_comment_status', 'akismet_set_comment_status', 10, 2);
643
- add_action('edit_comment', 'akismet_submit_spam_comment');
644
- add_filter( 'comment_spam_to_approved', 'akismet_spamtoham' );
645
- add_filter( 'comment_spam_to_unapproved', 'akismet_spamtoham' );
646
- }
647
- // Total spam in queue
648
- // get_option( 'akismet_spam_count' ) is the total caught ever
649
- function akismet_spam_count( $type = false ) {
650
  global $wpdb;
651
 
652
- if ( !$type ) { // total
653
- $count = wp_cache_get( 'akismet_spam_count', 'widget' );
654
- if ( false === $count ) {
655
- if ( function_exists('wp_count_comments') ) {
656
- $count = wp_count_comments();
657
- $count = $count->spam;
658
- } else {
659
- $count = (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam'");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660
  }
661
- wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 );
 
 
 
662
  }
663
- return $count;
664
- } elseif ( 'comments' == $type || 'comment' == $type ) { // comments
665
- $type = '';
666
- } else { // pingback, trackback, ...
667
- $type = $wpdb->escape( $type );
668
- }
669
-
670
- return (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam' AND comment_type='$type'");
671
- }
672
-
673
-
674
- // WP 2.5+
675
- function akismet_rightnow() {
676
- global $submenu, $wp_db_version;
677
-
678
- // clean_url was deprecated in WP 3.0
679
- $esc_url = 'clean_url';
680
- if ( function_exists( 'esc_url' ) )
681
- $esc_url = 'esc_url';
682
-
683
- if ( 8645 < $wp_db_version ) // 2.7
684
- $link = 'edit-comments.php?comment_status=spam';
685
- elseif ( isset( $submenu['edit-comments.php'] ) )
686
- $link = 'edit-comments.php?page=akismet-admin';
687
- else
688
- $link = 'edit.php?page=akismet-admin';
689
-
690
- if ( $count = get_option('akismet_spam_count') ) {
691
- $intro = sprintf( __ngettext(
692
- '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comment already,',
693
- '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comments already,',
694
- $count
695
- ), 'http://akismet.com/', number_format_i18n( $count ) );
696
- } else {
697
- $intro = sprintf( __('<a href="%1$s">Akismet</a> blocks spam from getting to your blog,'), 'http://akismet.com/' );
698
  }
699
-
700
- if ( $queue_count = akismet_spam_count() ) {
701
- $queue_text = sprintf( __ngettext(
702
- 'and there\'s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
703
- 'and there are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
704
- $queue_count
705
- ), number_format_i18n( $queue_count ), clean_url($link) );
706
- } else {
707
- $queue_text = sprintf( __( "but there's nothing in your <a href='%1\$s'>spam queue</a> at the moment." ), $esc_url($link) );
708
  }
709
-
710
- // _c was deprecated in WP 2.9.0
711
- if ( function_exists( '_x' ) )
712
- $text = sprintf( _x( '%1$s %2$s', 'akismet_rightnow' ), $intro, $queue_text );
713
- else
714
- $text = sprintf( _c( '%1$s %2$s|akismet_rightnow' ), $intro, $queue_text );
715
-
716
- echo "<p class='akismet-right-now'>$text</p>\n";
717
  }
718
-
719
- add_action('rightnow_end', 'akismet_rightnow');
720
-
721
 
722
- // For WP >= 2.5
723
- function akismet_check_for_spam_button($comment_status) {
724
- if ( 'approved' == $comment_status )
725
- return;
726
- if ( function_exists('plugins_url') )
727
- $link = 'admin.php?action=akismet_recheck_queue';
728
- else
729
- $link = 'edit-comments.php?page=akismet-admin&amp;recheckqueue=true&amp;noheader=true';
730
- echo "</div><div class='alignleft'><a class='button-secondary checkforspam' href='$link'>" . __('Check for Spam') . "</a>";
731
  }
732
- add_action('manage_comments_nav', 'akismet_check_for_spam_button');
733
 
734
- function akismet_recheck_queue() {
735
- global $wpdb, $akismet_api_host, $akismet_api_port;
736
 
737
- if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) )
738
- return;
739
-
740
- $moderation = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0'", ARRAY_A );
741
- foreach ( (array) $moderation as $c ) {
742
- $c['user_ip'] = $c['comment_author_IP'];
743
- $c['user_agent'] = $c['comment_agent'];
744
- $c['referrer'] = '';
745
- $c['blog'] = get_option('home');
746
- $c['blog_lang'] = get_locale();
747
- $c['blog_charset'] = get_option('blog_charset');
748
- $c['permalink'] = get_permalink($c['comment_post_ID']);
749
-
750
- $c['user_role'] = '';
751
- if ( isset( $c['user_ID'] ) )
752
- $c['user_role'] = akismet_get_user_roles($c['user_ID']);
753
-
754
- $id = (int) $c['comment_ID'];
755
 
756
- $query_string = '';
757
- foreach ( $c as $key => $data )
758
- $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
759
-
760
- $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
761
- if ( 'true' == $response[1] ) {
762
- if ( function_exists('wp_set_comment_status') )
763
- wp_set_comment_status($id, 'spam');
764
- else
765
- $wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'spam' WHERE comment_ID = $id");
766
-
767
- }
768
- }
769
- wp_redirect( 'edit-comments.php' );
770
- exit;
771
  }
772
 
773
- add_action('admin_action_akismet_recheck_queue', 'akismet_recheck_queue');
774
-
775
- function akismet_check_db_comment( $id ) {
776
- global $wpdb, $akismet_api_host, $akismet_api_port;
777
-
778
- $id = (int) $id;
779
- $c = $wpdb->get_row( "SELECT * FROM $wpdb->comments WHERE comment_ID = '$id'", ARRAY_A );
780
- if ( !$c )
781
  return;
782
-
783
- $c['user_ip'] = $c['comment_author_IP'];
784
- $c['user_agent'] = $c['comment_agent'];
785
- $c['referrer'] = '';
786
- $c['blog'] = get_option('home');
787
- $c['blog_lang'] = get_locale();
788
- $c['blog_charset'] = get_option('blog_charset');
789
- $c['permalink'] = get_permalink($c['comment_post_ID']);
790
- $id = $c['comment_ID'];
791
-
792
- $query_string = '';
793
- foreach ( $c as $key => $data )
794
- $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
795
-
796
- $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
797
- return $response[1];
798
- }
799
-
800
- // Widget stuff
801
- function widget_akismet_register() {
802
- if ( function_exists('register_sidebar_widget') ) :
803
- function widget_akismet($args) {
804
- extract($args);
805
- $options = get_option('widget_akismet');
806
- $count = number_format_i18n(get_option('akismet_spam_count'));
807
- ?>
808
- <?php echo $before_widget; ?>
809
- <?php echo $before_title . $options['title'] . $after_title; ?>
810
- <div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><?php printf( __( '%1$s %2$sspam comments%3$s %4$sblocked by%5$s<br />%6$sAkismet%7$s' ), '<span id="akismet1"><span id="akismetcount">' . $count . '</span>', '<span id="akismetsc">', '</span></span>', '<span id="akismet2"><span id="akismetbb">', '</span>', '<span id="akismeta">', '</span></span>' ); ?></a></div></div>
811
- <?php echo $after_widget; ?>
812
- <?php
813
  }
814
 
815
- function widget_akismet_style() {
816
- $plugin_dir = '/wp-content/plugins';
817
- if ( defined( 'PLUGINDIR' ) )
818
- $plugin_dir = '/' . PLUGINDIR;
819
-
820
- ?>
821
- <style type="text/css">
822
- #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
823
- #aka:hover{border:none;text-decoration:none}
824
- #aka:hover #akismet1{display:none}
825
- #aka:hover #akismet2,#akismet1{display:block}
826
- #akismet2{display:none;padding-top:2px}
827
- #akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
828
- #akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
829
- #akismetwrap #akismetstats{background:url(<?php echo get_option('siteurl'), $plugin_dir; ?>/akismet/akismet.gif) no-repeat top left;border:none;color:#fff;font:11px 'Trebuchet MS','Myriad Pro',sans-serif;height:40px;line-height:100%;overflow:hidden;padding:8px 0 0;text-align:center;width:120px}
830
- </style>
831
- <?php
832
- }
833
-
834
- function widget_akismet_control() {
835
- $options = $newoptions = get_option('widget_akismet');
836
- if ( isset( $_POST['akismet-submit'] ) && $_POST["akismet-submit"] ) {
837
- $newoptions['title'] = strip_tags(stripslashes($_POST["akismet-title"]));
838
- if ( empty($newoptions['title']) ) $newoptions['title'] = __('Spam Blocked');
839
- }
840
- if ( $options != $newoptions ) {
841
- $options = $newoptions;
842
- update_option('widget_akismet', $options);
843
- }
844
- $title = htmlspecialchars($options['title'], ENT_QUOTES);
845
- ?>
846
- <p><label for="akismet-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="akismet-title" name="akismet-title" type="text" value="<?php echo $title; ?>" /></label></p>
847
- <input type="hidden" id="akismet-submit" name="akismet-submit" value="1" />
848
- <?php
849
  }
850
 
851
- if ( function_exists( 'wp_register_sidebar_widget' ) ) {
852
- wp_register_sidebar_widget( 'akismet', 'Akismet', 'widget_akismet', null, 'akismet');
853
- wp_register_widget_control( 'akismet', 'Akismet', 'widget_akismet_control', null, 75, 'akismet');
854
- } else {
855
- register_sidebar_widget('Akismet', 'widget_akismet', null, 'akismet');
856
- register_widget_control('Akismet', 'widget_akismet_control', null, 75, 'akismet');
857
  }
858
- if ( is_active_widget('widget_akismet') )
859
- add_action('wp_head', 'widget_akismet_style');
860
- endif;
861
  }
862
-
863
- add_action('init', 'widget_akismet_register');
864
-
865
- // Counter for non-widget users
866
- function akismet_counter() {
867
- $plugin_dir = '/wp-content/plugins';
868
- if ( defined( 'PLUGINDIR' ) )
869
- $plugin_dir = '/' . PLUGINDIR;
870
-
871
- ?>
872
- <style type="text/css">
873
- #akismetwrap #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
874
- #aka:hover{border:none;text-decoration:none}
875
- #aka:hover #akismet1{display:none}
876
- #aka:hover #akismet2,#akismet1{display:block}
877
- #akismet2{display:none;padding-top:2px}
878
- #akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
879
- #akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
880
- #akismetwrap #akismetstats{background:url(<?php echo get_option('siteurl'), $plugin_dir; ?>/akismet/akismet.gif) no-repeat top left;border:none;color:#fff;font:11px 'Trebuchet MS','Myriad Pro',sans-serif;height:40px;line-height:100%;overflow:hidden;padding:8px 0 0;text-align:center;width:120px}
881
- </style>
882
- <?php
883
- $count = number_format_i18n(get_option('akismet_spam_count'));
884
- ?>
885
- <div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><div id="akismet1"><span id="akismetcount"><?php echo $count; ?></span> <span id="akismetsc"><?php _e('spam comments') ?></span></div> <div id="akismet2"><span id="akismetbb"><?php _e('blocked by') ?></span><br /><span id="akismeta">Akismet</span></div></a></div></div>
886
- <?php
887
- }
888
-
889
- ?>
4
  */
5
  /*
6
  Plugin Name: Akismet
7
+ Plugin URI: http://akismet.com/?return=true
8
+ Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from comment and trackback spam</strong>. It keeps your site protected from spam even while you sleep. To get started: 1) Click the "Activate" link to the left of this description, 2) <a href="http://akismet.com/get/?return=true">Sign up for an Akismet API key</a>, and 3) Go to your Akismet configuration page, and save your API key.
9
+ Version: 2.5.7
10
  Author: Automattic
11
  Author URI: http://automattic.com/wordpress-plugins/
12
+ License: GPLv2 or later
13
  */
14
 
15
  /*
16
+ This program is free software; you can redistribute it and/or
17
+ modify it under the terms of the GNU General Public License
18
+ as published by the Free Software Foundation; either version 2
19
+ of the License, or (at your option) any later version.
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29
  */
30
 
31
+ // Make sure we don't expose any info if called directly
32
+ if ( !function_exists( 'add_action' ) ) {
33
+ echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
34
+ exit;
35
+ }
36
+
37
+ define('AKISMET_VERSION', '2.5.7');
38
+ define('AKISMET_PLUGIN_URL', plugin_dir_url( __FILE__ ));
39
 
40
  /** If you hardcode a WP.com API key here, all key config screens will be hidden */
41
  if ( defined('WPCOM_API_KEY') )
43
  else
44
  $wpcom_api_key = '';
45
 
46
+ if ( isset($wp_db_version) && $wp_db_version <= 9872 )
47
+ include_once dirname( __FILE__ ) . '/legacy.php';
48
+
49
+ include_once dirname( __FILE__ ) . '/widget.php';
 
50
 
51
+ if ( is_admin() )
52
+ require_once dirname( __FILE__ ) . '/admin.php';
53
 
54
  function akismet_init() {
55
  global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
60
  $akismet_api_host = get_option('wordpress_api_key') . '.rest.akismet.com';
61
 
62
  $akismet_api_port = 80;
 
 
 
63
  }
64
  add_action('init', 'akismet_init');
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  function akismet_get_key() {
67
  global $wpcom_api_key;
68
  if ( !empty($wpcom_api_key) )
70
  return get_option('wordpress_api_key');
71
  }
72
 
73
+ function akismet_check_key_status( $key, $ip = null ) {
74
  global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
75
  $blog = urlencode( get_option('home') );
76
  if ( $wpcom_api_key )
77
  $key = $wpcom_api_key;
78
  $response = akismet_http_post("key=$key&blog=$blog", 'rest.akismet.com', '/1.1/verify-key', $akismet_api_port, $ip);
79
+ return $response;
 
 
80
  }
81
 
82
+ // given a response from an API call like akismet_check_key_status(), update the alert code options if an alert is present.
83
+ function akismet_update_alert( $response ) {
84
+ $code = $msg = null;
85
+ if ( isset($response[0]['x-akismet-alert-code']) ) {
86
+ $code = $response[0]['x-akismet-alert-code'];
87
+ $msg = $response[0]['x-akismet-alert-msg'];
88
+ }
 
 
 
89
 
90
+ // only call update_option() if the value has changed
91
+ if ( $code != get_option( 'akismet_alert_code' ) ) {
92
+ update_option( 'akismet_alert_code', $code );
93
+ update_option( 'akismet_alert_msg', $msg );
 
 
 
 
 
 
 
 
94
  }
 
 
95
  }
96
 
97
+ function akismet_verify_key( $key, $ip = null ) {
98
+ $response = akismet_check_key_status( $key, $ip );
99
+ akismet_update_alert( $response );
100
+ if ( !is_array($response) || !isset($response[1]) || $response[1] != 'valid' && $response[1] != 'invalid' )
101
+ return 'failed';
102
+ return $response[1];
 
 
 
 
 
 
 
103
  }
104
 
105
+ // if we're in debug or test modes, use a reduced service level so as not to polute training or stats data
106
+ function akismet_test_mode() {
107
+ if ( defined('AKISMET_TEST_MODE') && AKISMET_TEST_MODE )
 
 
108
  return true;
109
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  }
111
 
112
  // return a comma-separated list of role names for the given user
113
+ function akismet_get_user_roles( $user_id ) {
114
  $roles = false;
115
 
116
  if ( !class_exists('WP_User') )
121
  if ( isset($comment_user->roles) )
122
  $roles = join(',', $comment_user->roles);
123
  }
124
+
125
+ if ( is_multisite() && is_super_admin( $user_id ) ) {
126
+ if ( empty( $roles ) ) {
127
+ $roles = 'super_admin';
128
+ } else {
129
+ $comment_user->roles[] = 'super_admin';
130
+ $roles = join( ',', $comment_user->roles );
131
+ }
132
+ }
133
+
134
  return $roles;
135
  }
136
 
137
  // Returns array with headers in $response[0] and body in $response[1]
138
  function akismet_http_post($request, $host, $path, $port = 80, $ip=null) {
139
  global $wp_version;
140
+
141
+ $akismet_ua = "WordPress/{$wp_version} | ";
142
+ $akismet_ua .= 'Akismet/' . constant( 'AKISMET_VERSION' );
143
+
144
+ $akismet_ua = apply_filters( 'akismet_ua', $akismet_ua );
145
+
146
+ $content_length = strlen( $request );
147
+
 
 
 
148
  $http_host = $host;
149
+ // use a specific IP if provided
150
+ // needed by akismet_check_server_connectivity()
151
+ if ( $ip && long2ip( ip2long( $ip ) ) ) {
152
  $http_host = $ip;
153
  } else {
154
+ $http_host = $host;
155
  }
156
+
157
+ // use the WP HTTP class if it is available
158
+ if ( function_exists( 'wp_remote_post' ) ) {
159
+ $http_args = array(
160
+ 'body' => $request,
161
+ 'headers' => array(
162
+ 'Content-Type' => 'application/x-www-form-urlencoded; ' .
163
+ 'charset=' . get_option( 'blog_charset' ),
164
+ 'Host' => $host,
165
+ 'User-Agent' => $akismet_ua
166
+ ),
167
+ 'httpversion' => '1.0',
168
+ 'timeout' => 15
169
+ );
170
+ $akismet_url = "http://{$http_host}{$path}";
171
+ $response = wp_remote_post( $akismet_url, $http_args );
172
+ if ( is_wp_error( $response ) )
173
+ return '';
174
+
175
+ return array( $response['headers'], $response['body'] );
176
+ } else {
177
+ $http_request = "POST $path HTTP/1.0\r\n";
178
+ $http_request .= "Host: $host\r\n";
179
+ $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n";
180
+ $http_request .= "Content-Length: {$content_length}\r\n";
181
+ $http_request .= "User-Agent: {$akismet_ua}\r\n";
182
+ $http_request .= "\r\n";
183
+ $http_request .= $request;
184
+
185
+ $response = '';
186
+ if( false != ( $fs = @fsockopen( $http_host, $port, $errno, $errstr, 10 ) ) ) {
187
+ fwrite( $fs, $http_request );
188
+
189
+ while ( !feof( $fs ) )
190
+ $response .= fgets( $fs, 1160 ); // One TCP-IP packet
191
+ fclose( $fs );
192
+ $response = explode( "\r\n\r\n", $response, 2 );
193
+ }
194
+ return $response;
195
  }
 
196
  }
197
 
198
  // filter handler used to return a spam result to pre_comment_approved
200
  // bump the counter here instead of when the filter is added to reduce the possibility of overcounting
201
  if ( $incr = apply_filters('akismet_spam_count_incr', 1) )
202
  update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );
203
+ // this is a one-shot deal
204
+ remove_filter( 'pre_comment_approved', 'akismet_result_spam' );
205
  return 'spam';
206
  }
207
 
208
+ function akismet_result_hold( $approved ) {
209
+ // once only
210
+ remove_filter( 'pre_comment_approved', 'akismet_result_hold' );
211
+ return '0';
212
+ }
213
+
214
+ // how many approved comments does this author have?
215
+ function akismet_get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url ) {
216
+ global $wpdb;
217
+
218
+ if ( !empty($user_id) )
219
+ return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE user_id = %d AND comment_approved = 1", $user_id ) );
220
+
221
+ if ( !empty($comment_author_email) )
222
+ return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_author_email = %s AND comment_author = %s AND comment_author_url = %s AND comment_approved = 1", $comment_author_email, $comment_author, $comment_author_url ) );
223
+
224
+ return 0;
225
+ }
226
+
227
+ function akismet_microtime() {
228
+ $mtime = explode( ' ', microtime() );
229
+ return $mtime[1] + $mtime[0];
230
+ }
231
+
232
+ // log an event for a given comment, storing it in comment_meta
233
+ function akismet_update_comment_history( $comment_id, $message, $event=null ) {
234
+ global $current_user;
235
+
236
+ // failsafe for old WP versions
237
+ if ( !function_exists('add_comment_meta') )
238
+ return false;
239
+
240
+ $user = '';
241
+ if ( is_object($current_user) && isset($current_user->user_login) )
242
+ $user = $current_user->user_login;
243
+
244
+ $event = array(
245
+ 'time' => akismet_microtime(),
246
+ 'message' => $message,
247
+ 'event' => $event,
248
+ 'user' => $user,
249
+ );
250
+
251
+ // $unique = false so as to allow multiple values per comment
252
+ $r = add_comment_meta( $comment_id, 'akismet_history', $event, false );
253
+ }
254
+
255
+ // get the full comment history for a given comment, as an array in reverse chronological order
256
+ function akismet_get_comment_history( $comment_id ) {
257
+
258
+ // failsafe for old WP versions
259
+ if ( !function_exists('add_comment_meta') )
260
+ return false;
261
+
262
+ $history = get_comment_meta( $comment_id, 'akismet_history', false );
263
+ usort( $history, 'akismet_cmp_time' );
264
+ return $history;
265
+ }
266
+
267
+ function akismet_cmp_time( $a, $b ) {
268
+ return $a['time'] > $b['time'] ? -1 : 1;
269
+ }
270
+
271
+ // this fires on wp_insert_comment. we can't update comment_meta when akismet_auto_check_comment() runs
272
+ // because we don't know the comment ID at that point.
273
+ function akismet_auto_check_update_meta( $id, $comment ) {
274
+ global $akismet_last_comment;
275
+
276
+ // failsafe for old WP versions
277
+ if ( !function_exists('add_comment_meta') )
278
+ return false;
279
+
280
+ if ( !isset( $akismet_last_comment['comment_author_email'] ) )
281
+ $akismet_last_comment['comment_author_email'] = '';
282
+
283
+ // wp_insert_comment() might be called in other contexts, so make sure this is the same comment
284
+ // as was checked by akismet_auto_check_comment
285
+ if ( is_object($comment) && !empty($akismet_last_comment) && is_array($akismet_last_comment) ) {
286
+ if ( isset($akismet_last_comment['comment_post_ID']) && intval($akismet_last_comment['comment_post_ID']) == intval($comment->comment_post_ID)
287
+ && $akismet_last_comment['comment_author'] == $comment->comment_author
288
+ && $akismet_last_comment['comment_author_email'] == $comment->comment_author_email ) {
289
+ // normal result: true or false
290
+ if ( $akismet_last_comment['akismet_result'] == 'true' ) {
291
+ update_comment_meta( $comment->comment_ID, 'akismet_result', 'true' );
292
+ akismet_update_comment_history( $comment->comment_ID, __('Akismet caught this comment as spam'), 'check-spam' );
293
+ if ( $comment->comment_approved != 'spam' )
294
+ akismet_update_comment_history( $comment->comment_ID, sprintf( __('Comment status was changed to %s'), $comment->comment_approved), 'status-changed'.$comment->comment_approved );
295
+ } elseif ( $akismet_last_comment['akismet_result'] == 'false' ) {
296
+ update_comment_meta( $comment->comment_ID, 'akismet_result', 'false' );
297
+ akismet_update_comment_history( $comment->comment_ID, __('Akismet cleared this comment'), 'check-ham' );
298
+ if ( $comment->comment_approved == 'spam' ) {
299
+ if ( wp_blacklist_check($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent) )
300
+ akismet_update_comment_history( $comment->comment_ID, __('Comment was caught by wp_blacklist_check'), 'wp-blacklisted' );
301
+ else
302
+ akismet_update_comment_history( $comment->comment_ID, sprintf( __('Comment status was changed to %s'), $comment->comment_approved), 'status-changed-'.$comment->comment_approved );
303
+ }
304
+ // abnormal result: error
305
+ } else {
306
+ update_comment_meta( $comment->comment_ID, 'akismet_error', time() );
307
+ akismet_update_comment_history( $comment->comment_ID, sprintf( __('Akismet was unable to check this comment (response: %s), will automatically retry again later.'), substr($akismet_last_comment['akismet_result'], 0, 50)), 'check-error' );
308
+ }
309
+
310
+ // record the complete original data as submitted for checking
311
+ if ( isset($akismet_last_comment['comment_as_submitted']) )
312
+ update_comment_meta( $comment->comment_ID, 'akismet_as_submitted', $akismet_last_comment['comment_as_submitted'] );
313
+ }
314
+ }
315
+ }
316
+
317
+ add_action( 'wp_insert_comment', 'akismet_auto_check_update_meta', 10, 2 );
318
+
319
+
320
  function akismet_auto_check_comment( $commentdata ) {
321
+ global $akismet_api_host, $akismet_api_port, $akismet_last_comment;
322
 
323
  $comment = $commentdata;
324
  $comment['user_ip'] = $_SERVER['REMOTE_ADDR'];
325
+ $comment['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
326
+ $comment['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
327
  $comment['blog'] = get_option('home');
328
  $comment['blog_lang'] = get_locale();
329
  $comment['blog_charset'] = get_option('blog_charset');
330
  $comment['permalink'] = get_permalink($comment['comment_post_ID']);
331
 
332
+ if ( !empty( $comment['user_ID'] ) ) {
333
+ $comment['user_role'] = akismet_get_user_roles( $comment['user_ID'] );
334
+ }
335
+
336
+ $akismet_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
337
+ $comment['akismet_comment_nonce'] = 'inactive';
338
+ if ( $akismet_nonce_option == 'true' || $akismet_nonce_option == '' ) {
339
+ $comment['akismet_comment_nonce'] = 'failed';
340
+ if ( isset( $_POST['akismet_comment_nonce'] ) && wp_verify_nonce( $_POST['akismet_comment_nonce'], 'akismet_comment_nonce_' . $comment['comment_post_ID'] ) )
341
+ $comment['akismet_comment_nonce'] = 'passed';
342
+
343
+ // comment reply in wp-admin
344
+ if ( isset( $_POST['_ajax_nonce-replyto-comment'] ) && check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ) )
345
+ $comment['akismet_comment_nonce'] = 'passed';
346
+
347
+ }
348
+
349
+ if ( akismet_test_mode() )
350
+ $comment['is_test'] = 'true';
351
+
352
+ foreach ($_POST as $key => $value ) {
353
+ if ( is_string($value) )
354
+ $comment["POST_{$key}"] = $value;
355
+ }
356
 
357
  $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
358
 
359
+ foreach ( $_SERVER as $key => $value ) {
360
  if ( !in_array( $key, $ignore ) && is_string($value) )
361
  $comment["$key"] = $value;
362
  else
363
  $comment["$key"] = '';
364
+ }
365
+
366
+ $post = get_post( $comment['comment_post_ID'] );
367
+ $comment[ 'comment_post_modified_gmt' ] = $post->post_modified_gmt;
368
 
369
  $query_string = '';
370
  foreach ( $comment as $key => $data )
371
  $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
372
+
373
+ $commentdata['comment_as_submitted'] = $comment;
374
 
375
  $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
376
+ do_action( 'akismet_comment_check_response', $response );
377
+ akismet_update_alert( $response );
378
  $commentdata['akismet_result'] = $response[1];
379
  if ( 'true' == $response[1] ) {
380
  // akismet_spam_count will be incremented later by akismet_result_spam()
382
 
383
  do_action( 'akismet_spam_caught' );
384
 
 
385
  $last_updated = strtotime( $post->post_modified_gmt );
386
  $diff = time() - $last_updated;
387
  $diff = $diff / 86400;
390
  // akismet_result_spam() won't be called so bump the counter here
391
  if ( $incr = apply_filters('akismet_spam_count_incr', 1) )
392
  update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );
393
+ $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : get_permalink( $post );
394
+ wp_safe_redirect( $redirect_to );
395
+ die();
396
+ }
397
+ }
398
+
399
+ // if the response is neither true nor false, hold the comment for moderation and schedule a recheck
400
+ if ( 'true' != $response[1] && 'false' != $response[1] ) {
401
+ if ( !current_user_can('moderate_comments') ) {
402
+ add_filter('pre_comment_approved', 'akismet_result_hold');
403
+ }
404
+ if ( !wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) {
405
+ wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
406
  }
407
  }
408
 
414
  // WP 2.0: run this one time in ten
415
  akismet_delete_old();
416
  }
417
+ $akismet_last_comment = $commentdata;
418
+
419
+ akismet_fix_scheduled_recheck();
420
  return $commentdata;
421
  }
422
 
423
+ add_action('preprocess_comment', 'akismet_auto_check_comment', 1);
424
+
425
  function akismet_delete_old() {
426
  global $wpdb;
427
  $now_gmt = current_time('mysql', 1);
428
  $comment_ids = $wpdb->get_col("SELECT comment_id FROM $wpdb->comments WHERE DATE_SUB('$now_gmt', INTERVAL 15 DAY) > comment_date_gmt AND comment_approved = 'spam'");
429
  if ( empty( $comment_ids ) )
430
  return;
431
+
432
+ $comma_comment_ids = implode( ', ', array_map('intval', $comment_ids) );
433
 
434
  do_action( 'delete_comment', $comment_ids );
435
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_id IN ( $comma_comment_ids )");
436
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id IN ( $comma_comment_ids )");
437
+ clean_comment_cache( $comment_ids );
438
  $n = mt_rand(1, 5000);
439
  if ( apply_filters('akismet_optimize_table', ($n == 11)) ) // lucky number
440
  $wpdb->query("OPTIMIZE TABLE $wpdb->comments");
441
 
442
  }
443
 
444
+ function akismet_delete_old_metadata() {
445
+ global $wpdb;
446
 
447
+ $now_gmt = current_time( 'mysql', 1 );
448
+ $interval = apply_filters( 'akismet_delete_commentmeta_interval', 15 );
 
449
 
450
+ # enfore a minimum of 1 day
451
+ $interval = absint( $interval );
452
+ if ( $interval < 1 ) {
453
  return;
 
 
 
 
 
 
454
  }
 
 
 
 
 
 
 
 
 
 
 
455
 
456
+ // akismet_as_submitted meta values are large, so expire them
457
+ // after $interval days regardless of the comment status
458
+ while ( TRUE ) {
459
+ $comment_ids = $wpdb->get_col( "SELECT $wpdb->comments.comment_id FROM $wpdb->commentmeta INNER JOIN $wpdb->comments USING(comment_id) WHERE meta_key = 'akismet_as_submitted' AND DATE_SUB('$now_gmt', INTERVAL {$interval} DAY) > comment_date_gmt LIMIT 10000" );
460
 
461
+ if ( empty( $comment_ids ) ) {
462
+ return;
463
+ }
464
 
465
+ foreach ( $comment_ids as $comment_id ) {
466
+ delete_comment_meta( $comment_id, 'akismet_as_submitted' );
467
+ }
 
 
 
 
 
 
 
 
468
  }
469
+
470
+ /*
471
+ $n = mt_rand( 1, 5000 );
472
+ if ( apply_filters( 'akismet_optimize_table', ( $n == 11 ), 'commentmeta' ) ) { // lucky number
473
+ $wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );
474
  }
475
+ */
476
+ }
477
 
478
+ add_action('akismet_scheduled_delete', 'akismet_delete_old');
479
+ add_action('akismet_scheduled_delete', 'akismet_delete_old_metadata');
 
480
 
481
+ function akismet_check_db_comment( $id, $recheck_reason = 'recheck_queue' ) {
482
+ global $wpdb, $akismet_api_host, $akismet_api_port;
 
483
 
484
+ $id = (int) $id;
485
+ $c = $wpdb->get_row( "SELECT * FROM $wpdb->comments WHERE comment_ID = '$id'", ARRAY_A );
486
+ if ( !$c )
487
+ return;
488
 
489
+ $c['user_ip'] = $c['comment_author_IP'];
490
+ $c['user_agent'] = $c['comment_agent'];
491
+ $c['referrer'] = '';
492
+ $c['blog'] = get_option('home');
493
+ $c['blog_lang'] = get_locale();
494
+ $c['blog_charset'] = get_option('blog_charset');
495
+ $c['permalink'] = get_permalink($c['comment_post_ID']);
496
+ $id = $c['comment_ID'];
497
+ if ( akismet_test_mode() )
498
+ $c['is_test'] = 'true';
499
+ $c['recheck_reason'] = $recheck_reason;
500
 
501
+ $query_string = '';
502
+ foreach ( $c as $key => $data )
503
+ $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
 
 
 
 
 
504
 
505
+ $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
506
+ return ( is_array( $response ) && isset( $response[1] ) ) ? $response[1] : false;
 
 
 
 
 
 
 
 
507
  }
508
 
509
+ function akismet_cron_recheck() {
 
 
 
 
 
 
 
 
 
 
 
 
510
  global $wpdb;
511
 
512
+ $status = akismet_verify_key( akismet_get_key() );
513
+ if ( get_option( 'akismet_alert_code' ) || $status == 'invalid' ) {
514
+ // since there is currently a problem with the key, reschedule a check for 6 hours hence
515
+ wp_schedule_single_event( time() + 21600, 'akismet_schedule_cron_recheck' );
516
+ return false;
517
+ }
518
+
519
+ delete_option('akismet_available_servers');
520
+
521
+ $comment_errors = $wpdb->get_col( "
522
+ SELECT comment_id
523
+ FROM {$wpdb->prefix}commentmeta
524
+ WHERE meta_key = 'akismet_error'
525
+ LIMIT 100
526
+ " );
527
+
528
+ foreach ( (array) $comment_errors as $comment_id ) {
529
+ // if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
530
+ $comment = get_comment( $comment_id );
531
+ if ( !$comment || strtotime( $comment->comment_date_gmt ) < strtotime( "-15 days" ) ) {
532
+ delete_comment_meta( $comment_id, 'akismet_error' );
533
+ continue;
534
+ }
535
+
536
+ add_comment_meta( $comment_id, 'akismet_rechecking', true );
537
+ $status = akismet_check_db_comment( $comment_id, 'retry' );
538
+
539
+ $msg = '';
540
+ if ( $status == 'true' ) {
541
+ $msg = __( 'Akismet caught this comment as spam during an automatic retry.' );
542
+ } elseif ( $status == 'false' ) {
543
+ $msg = __( 'Akismet cleared this comment during an automatic retry.' );
544
+ }
545
+
546
+ // If we got back a legit response then update the comment history
547
+ // other wise just bail now and try again later. No point in
548
+ // re-trying all the comments once we hit one failure.
549
+ if ( !empty( $msg ) ) {
550
+ delete_comment_meta( $comment_id, 'akismet_error' );
551
+ akismet_update_comment_history( $comment_id, $msg, 'cron-retry' );
552
+ update_comment_meta( $comment_id, 'akismet_result', $status );
553
+ // make sure the comment status is still pending. if it isn't, that means the user has already moved it elsewhere.
554
+ $comment = get_comment( $comment_id );
555
+ if ( $comment && 'unapproved' == wp_get_comment_status( $comment_id ) ) {
556
+ if ( $status == 'true' ) {
557
+ wp_spam_comment( $comment_id );
558
+ } elseif ( $status == 'false' ) {
559
+ // comment is good, but it's still in the pending queue. depending on the moderation settings
560
+ // we may need to change it to approved.
561
+ if ( check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type) )
562
+ wp_set_comment_status( $comment_id, 1 );
563
+ }
564
  }
565
+ } else {
566
+ delete_comment_meta( $comment_id, 'akismet_rechecking' );
567
+ wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
568
+ return;
569
  }
570
+ delete_comment_meta( $comment_id, 'akismet_rechecking' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
571
  }
572
+
573
+ $remaining = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" );
574
+ if ( $remaining && !wp_next_scheduled('akismet_schedule_cron_recheck') ) {
575
+ wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
 
 
 
 
 
576
  }
 
 
 
 
 
 
 
 
577
  }
578
+ add_action( 'akismet_schedule_cron_recheck', 'akismet_cron_recheck' );
 
 
579
 
580
+ function akismet_add_comment_nonce( $post_id ) {
581
+ echo '<p style="display: none;">';
582
+ wp_nonce_field( 'akismet_comment_nonce_' . $post_id, 'akismet_comment_nonce', FALSE );
583
+ echo '</p>';
 
 
 
 
 
584
  }
 
585
 
586
+ $akismet_comment_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
 
587
 
588
+ if ( $akismet_comment_nonce_option == 'true' || $akismet_comment_nonce_option == '' )
589
+ add_action( 'comment_form', 'akismet_add_comment_nonce' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
590
 
591
+ global $wp_version;
592
+ if ( '3.0.5' == $wp_version ) {
593
+ remove_filter( 'comment_text', 'wp_kses_data' );
594
+ if ( is_admin() )
595
+ add_filter( 'comment_text', 'wp_kses_post' );
 
 
 
 
 
 
 
 
 
 
596
  }
597
 
598
+ function akismet_fix_scheduled_recheck() {
599
+ $future_check = wp_next_scheduled( 'akismet_schedule_cron_recheck' );
600
+ if ( !$future_check ) {
 
 
 
 
 
601
  return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602
  }
603
 
604
+ if ( get_option( 'akismet_alert_code' ) > 0 ) {
605
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
606
  }
607
 
608
+ $check_range = time() + 1200;
609
+ if ( $future_check > $check_range ) {
610
+ wp_clear_scheduled_hook( 'akismet_schedule_cron_recheck' );
611
+ wp_schedule_single_event( time() + 300, 'akismet_schedule_cron_recheck' );
 
 
612
  }
 
 
 
613
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ # Silence is golden.
legacy.php CHANGED
@@ -52,10 +52,9 @@ function akismet_manage_page() {
52
  }
53
 
54
  function akismet_caught() {
55
- global $wpdb, $comment, $akismet_caught, $akismet_nonce, $submenu;
56
 
57
  akismet_recheck_queue();
58
- $akismet_page = isset( $submenu['edit-comments.php'] ) ? 'edit-comments.php' : 'edit.php';
59
  if (isset($_POST['submit']) && 'recover' == $_POST['action'] && ! empty($_POST['not_spam'])) {
60
  check_admin_referer( $akismet_nonce );
61
  if ( function_exists('current_user_can') && !current_user_can('moderate_comments') )
@@ -71,8 +70,8 @@ function akismet_caught() {
71
  akismet_submit_nonspam_comment($comment);
72
  ++$i;
73
  endforeach;
74
- $to = add_query_arg( 'recovered', $i, "{$akismet_page}?page=akismet-admin" );
75
- wp_redirect( $to );
76
  exit;
77
  }
78
  if ('delete' == $_POST['action']) {
@@ -87,8 +86,8 @@ function akismet_caught() {
87
  $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_id IN ( " . implode( ', ', $comment_ids ) . " )");
88
  wp_cache_delete( 'akismet_spam_count', 'widget' );
89
  }
90
- $to = add_query_arg( 'deleted', 'all', "{$akismet_page}?page=akismet-admin" );
91
- wp_redirect( $to );
92
  exit;
93
  }
94
 
@@ -367,7 +366,7 @@ function redirect_old_akismet_urls( ) {
367
  // 2.7 redirect for people who might have bookmarked the old page
368
  if ( 8204 < $wp_db_version && ( 'edit-comments.php' == $script_name || 'edit.php' == $script_name ) && 'akismet-admin' == $page ) {
369
  $new_url = esc_url( 'edit-comments.php?comment_status=spam' );
370
- wp_redirect( $new_url, 301 );
371
  exit;
372
  }
373
  }
52
  }
53
 
54
  function akismet_caught() {
55
+ global $wpdb, $comment, $akismet_caught, $akismet_nonce;
56
 
57
  akismet_recheck_queue();
 
58
  if (isset($_POST['submit']) && 'recover' == $_POST['action'] && ! empty($_POST['not_spam'])) {
59
  check_admin_referer( $akismet_nonce );
60
  if ( function_exists('current_user_can') && !current_user_can('moderate_comments') )
70
  akismet_submit_nonspam_comment($comment);
71
  ++$i;
72
  endforeach;
73
+ $to = add_query_arg( 'recovered', $i, $_SERVER['HTTP_REFERER'] );
74
+ wp_safe_redirect( $to );
75
  exit;
76
  }
77
  if ('delete' == $_POST['action']) {
86
  $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_id IN ( " . implode( ', ', $comment_ids ) . " )");
87
  wp_cache_delete( 'akismet_spam_count', 'widget' );
88
  }
89
+ $to = add_query_arg( 'deleted', 'all', $_SERVER['HTTP_REFERER'] );
90
+ wp_safe_redirect( $to );
91
  exit;
92
  }
93
 
366
  // 2.7 redirect for people who might have bookmarked the old page
367
  if ( 8204 < $wp_db_version && ( 'edit-comments.php' == $script_name || 'edit.php' == $script_name ) && 'akismet-admin' == $page ) {
368
  $new_url = esc_url( 'edit-comments.php?comment_status=spam' );
369
+ wp_safe_redirect( $new_url, 301 );
370
  exit;
371
  }
372
  }
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Akismet ===
2
- Contributors: matt, ryan, andy, mdawaffe, tellyworth, automattic
3
  Tags: akismet, comments, spam
4
- Requires at least: 2.0
5
- Tested up to: 3.0
6
- Stable tag: 2.4.1
7
- License: GPLv2
8
 
9
  Akismet checks your comments against the Akismet web service to see if they look like spam or not.
10
 
@@ -13,11 +13,15 @@ Akismet checks your comments against the Akismet web service to see if they look
13
  Akismet checks your comments against the Akismet web service to see if they look like spam or not and lets you
14
  review the spam it catches under your blog's "Comments" admin screen.
15
 
16
- Want to show off how much spam Akismet has caught for you? Just put `<?php akismet_counter(); ?>` in your template.
17
 
18
- See also: [WP Stats plugin](http://wordpress.org/extend/plugins/stats/).
 
 
 
 
19
 
20
- PS: You'll need an [Akismet.com API key](http://akismet.com/get/) to use it.
21
 
22
  == Installation ==
23
 
@@ -27,9 +31,84 @@ Upload the Akismet plugin to your blog, Activate it, then enter your [Akismet.co
27
 
28
  == Changelog ==
29
 
30
- = 2.4.1 =
31
-
32
- * Security fix for wp_redirect() calls (thanks xknown)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  = 2.4.0 =
35
 
1
  === Akismet ===
2
+ Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, automattic
3
  Tags: akismet, comments, spam
4
+ Requires at least: 3.0
5
+ Tested up to: 3.5
6
+ Stable tag: 2.5.7
7
+ License: GPLv2 or later
8
 
9
  Akismet checks your comments against the Akismet web service to see if they look like spam or not.
10
 
13
  Akismet checks your comments against the Akismet web service to see if they look like spam or not and lets you
14
  review the spam it catches under your blog's "Comments" admin screen.
15
 
16
+ Major new features in Akismet 2.5 include:
17
 
18
+ * A comment status history, so you can easily see which comments were caught or cleared by Akismet, and which were spammed or unspammed by a moderator
19
+ * Links are highlighted in the comment body, to reveal hidden or misleading links
20
+ * If your web host is unable to reach Akismet's servers, the plugin will automatically retry when your connection is back up
21
+ * Moderators can see the number of approved comments for each user
22
+ * Spam and Unspam reports now include more information, to help improve accuracy
23
 
24
+ PS: You'll need an [Akismet.com API key](http://akismet.com/get/) to use it. Keys are free for personal blogs, with paid subscriptions available for businesses and commercial sites.
25
 
26
  == Installation ==
27
 
31
 
32
  == Changelog ==
33
 
34
+ = 2.5.7 =
35
+ * FireFox Stats iframe preview bug
36
+ * Fix mshots preview when using https
37
+ * Add .htaccess to block direct access to files
38
+ * Prevent some PHP notices
39
+ * Fix Check For Spam return location when referrer is empty
40
+ * Fix Settings links for network admins
41
+ * Fix prepare() warnings in WP 3.5
42
+
43
+ = 2.5.6 =
44
+ * Prevent retry scheduling problems on sites where wp_cron is misbehaving
45
+ * Preload mshot previews
46
+ * Modernize the widget code
47
+ * Fix a bug where comments were not held for moderation during an error condition
48
+ * Improve the UX and display when comments are temporarily held due to an error
49
+ * Make the Check For Spam button force a retry when comments are held due to an error
50
+ * Handle errors caused by an invalid key
51
+ * Don't retry comments that are too old
52
+ * Improve error messages when verifying an API key
53
+
54
+ = 2.5.5 =
55
+ * Add nonce check for comment author URL remove action
56
+ * Fix the settings link
57
+
58
+ = 2.5.4 =
59
+ * Limit Akismet CSS and Javascript loading in wp-admin to just the pages that need it
60
+ * Added author URL quick removal functionality
61
+ * Added mShot preview on Author URL hover
62
+ * Added empty index.php to prevent directory listing
63
+ * Move wp-admin menu items under Jetpack, if it is installed
64
+ * Purge old Akismet comment meta data, default of 15 days
65
+
66
+ = 2.5.3 =
67
+ * Specify the license is GPL v2 or later
68
+ * Fix a bug that could result in orphaned commentmeta entries
69
+ * Include hotfix for WordPress 3.0.5 filter issue
70
+
71
+ = 2.5.2 =
72
+
73
+ * Properly format the comment count for author counts
74
+ * Look for super admins on multisite installs when looking up user roles
75
+ * Increase the HTTP request timeout
76
+ * Removed padding for author approved count
77
+ * Fix typo in function name
78
+ * Set Akismet stats iframe height to fixed 2500px. Better to have one tall scroll bar than two side by side.
79
+
80
+ = 2.5.1 =
81
+
82
+ * Fix a bug that caused the "Auto delete" option to fail to discard comments correctly
83
+ * Remove the comment nonce form field from the 'Akismet Configuration' page in favor of using a filter, akismet_comment_nonce
84
+ * Fixed padding bug in "author" column of posts screen
85
+ * Added margin-top to "cleared by ..." badges on dashboard
86
+ * Fix possible error when calling akismet_cron_recheck()
87
+ * Fix more PHP warnings
88
+ * Clean up XHTML warnings for comment nonce
89
+ * Fix for possible condition where scheduled comment re-checks could get stuck
90
+ * Clean up the comment meta details after deleting a comment
91
+ * Only show the status badge if the comment status has been changed by someone/something other than Akismet
92
+ * Show a 'History' link in the row-actions
93
+ * Translation fixes
94
+ * Reduced font-size on author name
95
+ * Moved "flagged by..." notification to top right corner of comment container and removed heavy styling
96
+ * Hid "flagged by..." notification while on dashboard
97
+
98
+ = 2.5.0 =
99
+
100
+ * Track comment actions under 'Akismet Status' on the edit comment screen
101
+ * Fix a few remaining deprecated function calls ( props Mike Glendinning )
102
+ * Use HTTPS for the stats IFRAME when wp-admin is using HTTPS
103
+ * Use the WordPress HTTP class if available
104
+ * Move the admin UI code to a separate file, only loaded when needed
105
+ * Add cron retry feature, to replace the old connectivity check
106
+ * Display Akismet status badge beside each comment
107
+ * Record history for each comment, and display it on the edit page
108
+ * Record the complete comment as originally submitted in comment_meta, to use when reporting spam and ham
109
+ * Highlight links in comment content
110
+ * New option, "Show the number of comments you've approved beside each comment author."
111
+ * New option, "Use a nonce on the comment form."
112
 
113
  = 2.4.0 =
114
 
widget.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Akismet
4
+ */
5
+ class Akismet_Widget extends WP_Widget {
6
+
7
+ function __construct() {
8
+ parent::__construct(
9
+ 'akismet_widget',
10
+ __( 'Akismet Widget' ),
11
+ array( 'description' => __( 'Display the number of spam comments Akismet has caught' ) )
12
+ );
13
+
14
+ if ( is_active_widget( false, false, $this->id_base ) ) {
15
+ add_action( 'wp_head', array( $this, 'css' ) );
16
+ }
17
+ }
18
+
19
+ function css() {
20
+ ?>
21
+
22
+ <style type="text/css">
23
+ .a-stats {
24
+ width: auto;
25
+ }
26
+ .a-stats a {
27
+ background: #7CA821;
28
+ background-image:-moz-linear-gradient(0% 100% 90deg,#5F8E14,#7CA821);
29
+ background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#7CA821),to(#5F8E14));
30
+ border: 1px solid #5F8E14;
31
+ border-radius:3px;
32
+ color: #CFEA93;
33
+ cursor: pointer;
34
+ display: block;
35
+ font-weight: normal;
36
+ height: 100%;
37
+ -moz-border-radius:3px;
38
+ padding: 7px 0 8px;
39
+ text-align: center;
40
+ text-decoration: none;
41
+ -webkit-border-radius:3px;
42
+ width: 100%;
43
+ }
44
+ .a-stats a:hover {
45
+ text-decoration: none;
46
+ background-image:-moz-linear-gradient(0% 100% 90deg,#6F9C1B,#659417);
47
+ background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#659417),to(#6F9C1B));
48
+ }
49
+ .a-stats .count {
50
+ color: #FFF;
51
+ display: block;
52
+ font-size: 15px;
53
+ line-height: 16px;
54
+ padding: 0 13px;
55
+ white-space: nowrap;
56
+ }
57
+ </style>
58
+
59
+ <?php
60
+ }
61
+
62
+ function form( $instance ) {
63
+ if ( $instance ) {
64
+ $title = esc_attr( $instance['title'] );
65
+ }
66
+ else {
67
+ $title = __( 'Spam Blocked' );
68
+ }
69
+ ?>
70
+
71
+ <p>
72
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
73
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
74
+ </p>
75
+
76
+ <?php
77
+ }
78
+
79
+ function update( $new_instance, $old_instance ) {
80
+ $instance['title'] = strip_tags( $new_instance['title'] );
81
+ return $instance;
82
+ }
83
+
84
+ function widget( $args, $instance ) {
85
+ $count = get_option( 'akismet_spam_count' );
86
+
87
+ echo $args['before_widget'];
88
+ if ( ! empty( $instance['title'] ) ) {
89
+ echo $args['before_title'];
90
+ echo esc_html( $instance['title'] );
91
+ echo $args['after_title'];
92
+ }
93
+ ?>
94
+
95
+ <div class="a-stats">
96
+ <a href="http://akismet.com" target="_blank" title=""><?php printf( _n( '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>', '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>', $count ), number_format_i18n( $count ) ); ?></a>
97
+ </div>
98
+
99
+ <?php
100
+ echo $args['after_widget'];
101
+ }
102
+ }
103
+
104
+ function akismet_register_widgets() {
105
+ register_widget( 'Akismet_Widget' );
106
+ }
107
+
108
+ add_action( 'widgets_init', 'akismet_register_widgets' );