Akismet Anti-Spam - Version 2.4.1

Version Description

  • Security fix for wp_redirect() calls (thanks xknown)
Download this release

Release Info

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

Code changes from version 2.5.6 to 2.4.1

Files changed (8) hide show
  1. admin.php +0 -850
  2. akismet.css +0 -12
  3. akismet.js +0 -112
  4. akismet.php +689 -408
  5. index.php +0 -2
  6. legacy.php +7 -6
  7. readme.txt +11 -81
  8. widget.php +0 -108
admin.php DELETED
@@ -1,850 +0,0 @@
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_action('admin_head-'.$hook, 'akismet_stats_script');
27
- add_meta_box('akismet-status', __('Comment History'), 'akismet_comment_status_meta_box', 'comment', 'normal');
28
- }
29
- add_action('admin_init', 'akismet_admin_init');
30
-
31
- add_action( 'admin_enqueue_scripts', 'akismet_load_js_and_css' );
32
- function akismet_load_js_and_css() {
33
- global $hook_suffix;
34
-
35
- if (
36
- $hook_suffix == 'index.php' # dashboard
37
- || $hook_suffix == 'edit-comments.php'
38
- || $hook_suffix == 'comment.php'
39
- || $hook_suffix == 'post.php'
40
- || $hook_suffix == 'plugins_page_akismet-key-config'
41
- ) {
42
- wp_register_style( 'akismet.css', AKISMET_PLUGIN_URL . 'akismet.css', array(), '2.5.4.4' );
43
- wp_enqueue_style( 'akismet.css');
44
-
45
- wp_register_script( 'akismet.js', AKISMET_PLUGIN_URL . 'akismet.js', array('jquery'), '2.5.4.6' );
46
- wp_enqueue_script( 'akismet.js' );
47
- wp_localize_script( 'akismet.js', 'WPAkismet', array(
48
- 'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' )
49
- ) );
50
- }
51
- }
52
-
53
-
54
- function akismet_nonce_field($action = -1) { return wp_nonce_field($action); }
55
- $akismet_nonce = 'akismet-update-key';
56
-
57
- function akismet_plugin_action_links( $links, $file ) {
58
- if ( $file == plugin_basename( dirname(__FILE__).'/akismet.php' ) ) {
59
- $links[] = '<a href="admin.php?page=akismet-key-config">'.__('Settings').'</a>';
60
- }
61
-
62
- return $links;
63
- }
64
-
65
- add_filter( 'plugin_action_links', 'akismet_plugin_action_links', 10, 2 );
66
-
67
- function akismet_conf() {
68
- global $akismet_nonce, $wpcom_api_key;
69
-
70
- if ( isset($_POST['submit']) ) {
71
- if ( function_exists('current_user_can') && !current_user_can('manage_options') )
72
- die(__('Cheatin&#8217; uh?'));
73
-
74
- check_admin_referer( $akismet_nonce );
75
- $key = preg_replace( '/[^a-h0-9]/i', '', $_POST['key'] );
76
- $home_url = parse_url( get_bloginfo('url') );
77
-
78
- if ( empty($key) ) {
79
- $key_status = 'empty';
80
- $ms[] = 'new_key_empty';
81
- delete_option('wordpress_api_key');
82
- } elseif ( empty($home_url['host']) ) {
83
- $key_status = 'empty';
84
- $ms[] = 'bad_home_url';
85
- } else {
86
- $key_status = akismet_verify_key( $key );
87
- }
88
-
89
- if ( $key_status == 'valid' ) {
90
- update_option('wordpress_api_key', $key);
91
- $ms[] = 'new_key_valid';
92
- } else if ( $key_status == 'invalid' ) {
93
- $ms[] = 'new_key_invalid';
94
- } else if ( $key_status == 'failed' ) {
95
- $ms[] = 'new_key_failed';
96
- }
97
-
98
- if ( isset( $_POST['akismet_discard_month'] ) )
99
- update_option( 'akismet_discard_month', 'true' );
100
- else
101
- update_option( 'akismet_discard_month', 'false' );
102
-
103
- if ( isset( $_POST['akismet_show_user_comments_approved'] ) )
104
- update_option( 'akismet_show_user_comments_approved', 'true' );
105
- else
106
- update_option( 'akismet_show_user_comments_approved', 'false' );
107
-
108
- } elseif ( isset($_POST['check']) ) {
109
- akismet_get_server_connectivity(0);
110
- }
111
-
112
- if ( empty( $key_status) || $key_status != 'valid' ) {
113
- $key = get_option('wordpress_api_key');
114
- if ( empty( $key ) ) {
115
- if ( empty( $key_status ) || $key_status != 'failed' ) {
116
- if ( akismet_verify_key( '1234567890ab' ) == 'failed' )
117
- $ms[] = 'no_connection';
118
- else
119
- $ms[] = 'key_empty';
120
- }
121
- $key_status = 'empty';
122
- } else {
123
- $key_status = akismet_verify_key( $key );
124
- }
125
- if ( $key_status == 'valid' ) {
126
- $ms[] = 'key_valid';
127
- } else if ( $key_status == 'invalid' ) {
128
- $ms[] = 'key_invalid';
129
- } else if ( !empty($key) && $key_status == 'failed' ) {
130
- $ms[] = 'key_failed';
131
- }
132
- }
133
-
134
- $messages = array(
135
- 'new_key_empty' => array('color' => 'aa0', 'text' => __('Your key has been cleared.')),
136
- 'new_key_valid' => array('color' => '4AB915', 'text' => __('Your key has been verified. Happy blogging!')),
137
- 'new_key_invalid' => array('color' => '888', 'text' => __('The key you entered is invalid. Please double-check it.')),
138
- '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.')),
139
- 'no_connection' => array('color' => '888', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')),
140
- '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')),
141
- 'key_valid' => array('color' => '4AB915', 'text' => __('This key is valid.')),
142
- 'key_invalid' => array('color' => '888', 'text' => __('This key is invalid.')),
143
- '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.')),
144
- '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') ) ),
145
- );
146
- ?>
147
- <?php if ( !empty($_POST['submit'] ) ) : ?>
148
- <div id="message" class="updated fade"><p><strong><?php _e('Options saved.') ?></strong></p></div>
149
- <?php endif; ?>
150
- <div class="wrap">
151
- <h2><?php _e('Akismet Configuration'); ?></h2>
152
- <?php if (isset($_GET['message']) && $_GET['message'] == 'success') { ?>
153
- <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>
154
- <?php } ?>
155
- <div class="narrow">
156
- <form action="" method="post" id="akismet-conf" style="margin: auto; width: 400px; ">
157
- <?php if ( !$wpcom_api_key ) { ?>
158
- <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>
159
-
160
- <h3><label for="key"><?php _e('Akismet API Key'); ?></label></h3>
161
- <?php foreach ( $ms as $m ) : ?>
162
- <p style="padding: .5em; background-color: #<?php echo $messages[$m]['color']; ?>; color: #fff; font-weight: bold;"><?php echo $messages[$m]['text']; ?></p>
163
- <?php endforeach; ?>
164
- <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>
165
- <?php if ( isset( $invalid_key) && $invalid_key ) { ?>
166
- <h3><?php _e('Why might my key be invalid?'); ?></h3>
167
- <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>
168
- <?php } ?>
169
- <?php } ?>
170
- <?php akismet_nonce_field($akismet_nonce) ?>
171
- <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>
172
- <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>
173
- <p class="submit"><input type="submit" name="submit" value="<?php _e('Update options &raquo;'); ?>" /></p>
174
- </form>
175
-
176
- <form action="" method="post" id="akismet-connectivity" style="margin: auto; width: 400px; ">
177
-
178
- <h3><?php _e('Server Connectivity'); ?></h3>
179
- <?php
180
- if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') ) {
181
- ?>
182
- <p style="padding: .5em; background-color: #888; color: #fff; font-weight:bold;"><?php _e('Network functions are disabled.'); ?></p>
183
- <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>
184
- <?php
185
- } else {
186
- $servers = akismet_get_server_connectivity();
187
- $fail_count = count($servers) - count( array_filter($servers) );
188
- if ( is_array($servers) && count($servers) > 0 ) {
189
- // some connections work, some fail
190
- if ( $fail_count > 0 && $fail_count < count($servers) ) { ?>
191
- <p style="padding: .5em; background-color: #aa0; color: #fff; font-weight:bold;"><?php _e('Unable to reach some Akismet servers.'); ?></p>
192
- <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>
193
- <?php
194
- // all connections fail
195
- } elseif ( $fail_count > 0 ) { ?>
196
- <p style="padding: .5em; background-color: #888; color: #fff; font-weight:bold;"><?php _e('Unable to reach any Akismet servers.'); ?></p>
197
- <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>
198
- <?php
199
- // all connections work
200
- } else { ?>
201
- <p style="padding: .5em; background-color: #4AB915; color: #fff; font-weight:bold;"><?php _e('All Akismet servers are available.'); ?></p>
202
- <p><?php _e('Akismet is working correctly. All servers are accessible.'); ?></p>
203
- <?php
204
- }
205
- } else {
206
- ?>
207
- <p style="padding: .5em; background-color: #888; color: #fff; font-weight:bold;"><?php _e('Unable to find Akismet servers.'); ?></p>
208
- <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>
209
- <?php
210
- }
211
- }
212
-
213
- if ( !empty($servers) ) {
214
- ?>
215
- <table style="width: 100%;">
216
- <thead><th><?php _e('Akismet server'); ?></th><th><?php _e('Network Status'); ?></th></thead>
217
- <tbody>
218
- <?php
219
- asort($servers);
220
- foreach ( $servers as $ip => $status ) {
221
- $color = ( $status ? '#4AB915' : '#888');
222
- ?>
223
- <tr>
224
- <td><?php echo htmlspecialchars($ip); ?></td>
225
- <td style="padding: 0 .5em; font-weight:bold; color: #fff; background-color: <?php echo $color; ?>"><?php echo ($status ? __('Accessible') : __('Re-trying') ); ?></td>
226
-
227
- <?php
228
- }
229
- }
230
- ?>
231
- </tbody>
232
- </table>
233
- <p><?php if ( get_option('akismet_connectivity_time') ) echo sprintf( __('Last checked %s ago.'), human_time_diff( get_option('akismet_connectivity_time') ) ); ?></p>
234
- <p class="submit"><input type="submit" name="check" value="<?php _e('Check network status &raquo;'); ?>" /></p>
235
- <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>
236
- </form>
237
-
238
- </div>
239
- </div>
240
- <?php
241
- }
242
-
243
- function akismet_stats_script() {
244
- ?>
245
- <script type="text/javascript">
246
- function resizeIframe() {
247
-
248
- document.getElementById('akismet-stats-frame').style.height = "2500px";
249
-
250
- };
251
- function resizeIframeInit() {
252
- document.getElementById('akismet-stats-frame').onload = resizeIframe;
253
- window.onresize = resizeIframe;
254
- }
255
- addLoadEvent(resizeIframeInit);
256
- </script><?php
257
- }
258
-
259
-
260
- function akismet_stats_display() {
261
- global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
262
- $blog = urlencode( get_bloginfo('url') );
263
-
264
- $url = 'http://';
265
- if ( is_ssl() )
266
- $url = 'https://';
267
-
268
- $url .= 'akismet.com/web/1.0/user-stats.php';
269
- $url .= "?blog={$blog}&api_key=" . akismet_get_key();
270
- ?>
271
- <div class="wrap">
272
- <iframe src="<?php echo $url; ?>" width="100%" height="100%" frameborder="0" id="akismet-stats-frame"></iframe>
273
- </div>
274
- <?php
275
- }
276
-
277
- function akismet_stats() {
278
- if ( !function_exists('did_action') || did_action( 'rightnow_end' ) ) // We already displayed this info in the "Right Now" section
279
- return;
280
- if ( !$count = get_option('akismet_spam_count') )
281
- return;
282
- $path = plugin_basename(__FILE__);
283
- echo '<h3>' . _x( 'Spam', 'comments' ) . '</h3>';
284
- global $submenu;
285
- if ( isset( $submenu['edit-comments.php'] ) )
286
- $link = 'edit-comments.php';
287
- else
288
- $link = 'edit.php';
289
- 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>';
290
- }
291
- add_action('activity_box_end', 'akismet_stats');
292
-
293
- function akismet_admin_warnings() {
294
- global $wpcom_api_key, $pagenow;
295
-
296
- if (
297
- $pagenow == 'edit-comments.php'
298
- || ( !empty( $_GET['page'] ) && $_GET['page'] == 'akismet-key-config' )
299
- || ( !empty( $_GET['page'] ) && $_GET['page'] == 'akismet-stats-display' )
300
- ) {
301
- if ( get_option( 'akismet_alert_code' ) ) {
302
- function akismet_alert() {
303
- $alert = array(
304
- 'code' => (int) get_option( 'akismet_alert_code' ),
305
- 'msg' => get_option( 'akismet_alert_msg' )
306
- );
307
- ?>
308
- <div class='error'>
309
- <p><strong>Akismet Error Code: <?php echo $alert['code']; ?></strong></p>
310
- <p><?php esc_html_e( $alert['msg'] ); ?></p>
311
- <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>
312
- </div>
313
- <?php
314
- }
315
-
316
- add_action( 'admin_notices', 'akismet_alert' );
317
- }
318
- }
319
-
320
- if ( !get_option('wordpress_api_key') && !$wpcom_api_key && !isset($_POST['submit']) ) {
321
- function akismet_warning() {
322
- echo "
323
- <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>
324
- ";
325
- }
326
- add_action('admin_notices', 'akismet_warning');
327
- return;
328
- } elseif ( ( empty($_SERVER['SCRIPT_FILENAME']) || basename($_SERVER['SCRIPT_FILENAME']) == 'edit-comments.php' ) && wp_next_scheduled('akismet_schedule_cron_recheck') ) {
329
- function akismet_warning() {
330
- global $wpdb;
331
- akismet_fix_scheduled_recheck();
332
- $waiting = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ) );
333
- $next_check = wp_next_scheduled('akismet_schedule_cron_recheck');
334
- if ( $waiting > 0 && $next_check > time() )
335
- echo "
336
- <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>
337
- ";
338
- }
339
- add_action('admin_notices', 'akismet_warning');
340
- return;
341
- }
342
- }
343
-
344
- // FIXME placeholder
345
-
346
- function akismet_comment_row_action( $a, $comment ) {
347
-
348
- // failsafe for old WP versions
349
- if ( !function_exists('add_comment_meta') )
350
- return $a;
351
-
352
- $akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
353
- $akismet_error = get_comment_meta( $comment->comment_ID, 'akismet_error', true );
354
- $user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
355
- $comment_status = wp_get_comment_status( $comment->comment_ID );
356
- $desc = null;
357
- if ( $akismet_error ) {
358
- $desc = __( 'Awaiting spam check' );
359
- } elseif ( !$user_result || $user_result == $akismet_result ) {
360
- // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
361
- if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' )
362
- $desc = __( 'Flagged as spam by Akismet' );
363
- elseif ( $akismet_result == 'false' && $comment_status == 'spam' )
364
- $desc = __( 'Cleared by Akismet' );
365
- } else {
366
- $who = get_comment_meta( $comment->comment_ID, 'akismet_user', true );
367
- if ( $user_result == 'true' )
368
- $desc = sprintf( __('Flagged as spam by %s'), $who );
369
- else
370
- $desc = sprintf( __('Un-spammed by %s'), $who );
371
- }
372
-
373
- // add a History item to the hover links, just after Edit
374
- if ( $akismet_result ) {
375
- $b = array();
376
- foreach ( $a as $k => $item ) {
377
- $b[ $k ] = $item;
378
- if (
379
- $k == 'edit'
380
- || ( $k == 'unspam' && $GLOBALS['wp_version'] >= 3.4 )
381
- ) {
382
- $b['history'] = '<a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="'. esc_attr__( 'View comment history' ) . '"> '. __('History') . '</a>';
383
- }
384
- }
385
-
386
- $a = $b;
387
- }
388
-
389
- if ( $desc )
390
- 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>';
391
-
392
- if ( apply_filters( 'akismet_show_user_comments_approved', get_option('akismet_show_user_comments_approved') ) == 'true' ) {
393
- $comment_count = akismet_get_user_comments_approved( $comment->user_id, $comment->comment_author_email, $comment->comment_author, $comment->comment_author_url );
394
- $comment_count = intval( $comment_count );
395
- 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>';
396
- }
397
-
398
- return $a;
399
- }
400
-
401
- add_filter( 'comment_row_actions', 'akismet_comment_row_action', 10, 2 );
402
-
403
- function akismet_comment_status_meta_box($comment) {
404
- $history = akismet_get_comment_history( $comment->comment_ID );
405
-
406
- if ( $history ) {
407
- echo '<div class="akismet-history" style="margin: 13px;">';
408
- foreach ( $history as $row ) {
409
- $time = date( 'D d M Y @ h:i:m a', $row['time'] ) . ' GMT';
410
- echo '<div style="margin-bottom: 13px;"><span style="color: #999;" alt="' . $time . '" title="' . $time . '">' . sprintf( __('%s ago'), human_time_diff( $row['time'] ) ) . '</span> - ';
411
- echo htmlspecialchars( $row['message'] ) . '</div>';
412
- }
413
-
414
- echo '</div>';
415
-
416
- }
417
- }
418
-
419
-
420
- // add an extra column header to the comments screen
421
- function akismet_comments_columns( $columns ) {
422
- $columns[ 'akismet' ] = __( 'Akismet' );
423
- return $columns;
424
- }
425
-
426
- #add_filter( 'manage_edit-comments_columns', 'akismet_comments_columns' );
427
-
428
- // Show stuff in the extra column
429
- function akismet_comment_column_row( $column, $comment_id ) {
430
- if ( $column != 'akismet' )
431
- return;
432
-
433
- $history = akismet_get_comment_history( $comment_id );
434
-
435
- if ( $history ) {
436
- echo '<dl class="akismet-history">';
437
- foreach ( $history as $row ) {
438
- echo '<dt>' . sprintf( __('%s ago'), human_time_diff( $row['time'] ) ) . '</dt>';
439
- echo '<dd>' . htmlspecialchars( $row['message'] ) . '</dd>';
440
- }
441
-
442
- echo '</dl>';
443
- }
444
- }
445
-
446
- #add_action( 'manage_comments_custom_column', 'akismet_comment_column_row', 10, 2 );
447
-
448
- // END FIXME
449
-
450
- // call out URLS in comments
451
- function akismet_text_add_link_callback( $m ) {
452
-
453
- // bare link?
454
- if ( $m[4] == $m[2] )
455
- return '<a '.$m[1].' href="'.$m[2].'" '.$m[3].' class="comment-link">'.$m[4].'</a>';
456
- else
457
- return '<span title="'.$m[2].'" class="comment-link"><a '.$m[1].' href="'.$m[2].'" '.$m[3].' class="comment-link">'.$m[4].'</a></span>';
458
- }
459
-
460
- function akismet_text_add_link_class( $comment_text ) {
461
-
462
- return preg_replace_callback( '#<a ([^>]*)href="([^"]+)"([^>]*)>(.*?)</a>#i', 'akismet_text_add_link_callback', $comment_text );
463
- }
464
-
465
- add_filter('comment_text', 'akismet_text_add_link_class');
466
-
467
-
468
- // WP 2.5+
469
- function akismet_rightnow() {
470
- global $submenu, $wp_db_version;
471
-
472
- if ( 8645 < $wp_db_version ) // 2.7
473
- $link = 'edit-comments.php?comment_status=spam';
474
- elseif ( isset( $submenu['edit-comments.php'] ) )
475
- $link = 'edit-comments.php?page=akismet-admin';
476
- else
477
- $link = 'edit.php?page=akismet-admin';
478
-
479
- if ( $count = get_option('akismet_spam_count') ) {
480
- $intro = sprintf( _n(
481
- '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comment already. ',
482
- '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comments already. ',
483
- $count
484
- ), 'http://akismet.com/?return=true', number_format_i18n( $count ) );
485
- } else {
486
- $intro = sprintf( __('<a href="%1$s">Akismet</a> blocks spam from getting to your blog. '), 'http://akismet.com/?return=true' );
487
- }
488
-
489
- $link = function_exists( 'esc_url' ) ? esc_url( $link ) : clean_url( $link );
490
- if ( $queue_count = akismet_spam_count() ) {
491
- $queue_text = sprintf( _n(
492
- 'There\'s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
493
- 'There are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
494
- $queue_count
495
- ), number_format_i18n( $queue_count ), $link );
496
- } else {
497
- $queue_text = sprintf( __( "There's nothing in your <a href='%1\$s'>spam queue</a> at the moment." ), $link );
498
- }
499
-
500
- $text = $intro . '<br />' . $queue_text;
501
- echo "<p class='akismet-right-now'>$text</p>\n";
502
- }
503
-
504
- add_action('rightnow_end', 'akismet_rightnow');
505
-
506
-
507
- // For WP >= 2.5
508
- function akismet_check_for_spam_button($comment_status) {
509
- if ( 'approved' == $comment_status )
510
- return;
511
- if ( function_exists('plugins_url') )
512
- $link = 'admin.php?action=akismet_recheck_queue';
513
- else
514
- $link = 'edit-comments.php?page=akismet-admin&amp;recheckqueue=true&amp;noheader=true';
515
- echo "</div><div class='alignleft'><a class='button-secondary checkforspam' href='$link'>" . __('Check for Spam') . "</a>";
516
- }
517
- add_action('manage_comments_nav', 'akismet_check_for_spam_button');
518
-
519
- function akismet_submit_nonspam_comment ( $comment_id ) {
520
- global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
521
- $comment_id = (int) $comment_id;
522
-
523
- $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
524
- if ( !$comment ) // it was deleted
525
- return;
526
-
527
- // use the original version stored in comment_meta if available
528
- $as_submitted = get_comment_meta( $comment_id, 'akismet_as_submitted', true);
529
- if ( $as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content']) ) {
530
- $comment = (object) array_merge( (array)$comment, $as_submitted );
531
- }
532
-
533
- $comment->blog = get_bloginfo('url');
534
- $comment->blog_lang = get_locale();
535
- $comment->blog_charset = get_option('blog_charset');
536
- $comment->permalink = get_permalink($comment->comment_post_ID);
537
- $comment->reporter_ip = $_SERVER['REMOTE_ADDR'];
538
- if ( is_object($current_user) ) {
539
- $comment->reporter = $current_user->user_login;
540
- }
541
- if ( is_object($current_site) ) {
542
- $comment->site_domain = $current_site->domain;
543
- }
544
-
545
- $comment->user_role = '';
546
- if ( isset( $comment->user_ID ) )
547
- $comment->user_role = akismet_get_user_roles($comment->user_ID);
548
-
549
- if ( akismet_test_mode() )
550
- $comment->is_test = 'true';
551
-
552
- $post = get_post( $comment->comment_post_ID );
553
- $comment->comment_post_modified_gmt = $post->post_modified_gmt;
554
-
555
- $query_string = '';
556
- foreach ( $comment as $key => $data )
557
- $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
558
-
559
- $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-ham", $akismet_api_port);
560
- if ( $comment->reporter ) {
561
- akismet_update_comment_history( $comment_id, sprintf( __('%s reported this comment as not spam'), $comment->reporter ), 'report-ham' );
562
- update_comment_meta( $comment_id, 'akismet_user_result', 'false' );
563
- update_comment_meta( $comment_id, 'akismet_user', $comment->reporter );
564
- }
565
-
566
- do_action('akismet_submit_nonspam_comment', $comment_id, $response[1]);
567
- }
568
-
569
- function akismet_submit_spam_comment ( $comment_id ) {
570
- global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
571
- $comment_id = (int) $comment_id;
572
-
573
- $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
574
- if ( !$comment ) // it was deleted
575
- return;
576
- if ( 'spam' != $comment->comment_approved )
577
- return;
578
-
579
- // use the original version stored in comment_meta if available
580
- $as_submitted = get_comment_meta( $comment_id, 'akismet_as_submitted', true);
581
- if ( $as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content']) ) {
582
- $comment = (object) array_merge( (array)$comment, $as_submitted );
583
- }
584
-
585
- $comment->blog = get_bloginfo('url');
586
- $comment->blog_lang = get_locale();
587
- $comment->blog_charset = get_option('blog_charset');
588
- $comment->permalink = get_permalink($comment->comment_post_ID);
589
- $comment->reporter_ip = $_SERVER['REMOTE_ADDR'];
590
- if ( is_object($current_user) ) {
591
- $comment->reporter = $current_user->user_login;
592
- }
593
- if ( is_object($current_site) ) {
594
- $comment->site_domain = $current_site->domain;
595
- }
596
-
597
- $comment->user_role = '';
598
- if ( isset( $comment->user_ID ) )
599
- $comment->user_role = akismet_get_user_roles($comment->user_ID);
600
-
601
- if ( akismet_test_mode() )
602
- $comment->is_test = 'true';
603
-
604
- $post = get_post( $comment->comment_post_ID );
605
- $comment->comment_post_modified_gmt = $post->post_modified_gmt;
606
-
607
- $query_string = '';
608
- foreach ( $comment as $key => $data )
609
- $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
610
-
611
- $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-spam", $akismet_api_port);
612
- if ( $comment->reporter ) {
613
- akismet_update_comment_history( $comment_id, sprintf( __('%s reported this comment as spam'), $comment->reporter ), 'report-spam' );
614
- update_comment_meta( $comment_id, 'akismet_user_result', 'true' );
615
- update_comment_meta( $comment_id, 'akismet_user', $comment->reporter );
616
- }
617
- do_action('akismet_submit_spam_comment', $comment_id, $response[1]);
618
- }
619
-
620
- // For WP 2.7+
621
- function akismet_transition_comment_status( $new_status, $old_status, $comment ) {
622
- if ( $new_status == $old_status )
623
- return;
624
-
625
- # we don't need to record a history item for deleted comments
626
- if ( $new_status == 'delete' )
627
- return;
628
-
629
- if ( !is_admin() )
630
- return;
631
-
632
- if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) && !current_user_can( 'moderate_comments' ) )
633
- return;
634
-
635
- if ( defined('WP_IMPORTING') && WP_IMPORTING == true )
636
- return;
637
-
638
- // if this is present, it means the status has been changed by a re-check, not an explicit user action
639
- if ( get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) )
640
- return;
641
-
642
- global $current_user;
643
- $reporter = '';
644
- if ( is_object( $current_user ) )
645
- $reporter = $current_user->user_login;
646
-
647
- // Assumption alert:
648
- // We want to submit comments to Akismet only when a moderator explicitly spams or approves it - not if the status
649
- // is changed automatically by another plugin. Unfortunately WordPress doesn't provide an unambiguous way to
650
- // determine why the transition_comment_status action was triggered. And there are several different ways by which
651
- // to spam and unspam comments: bulk actions, ajax, links in moderation emails, the dashboard, and perhaps others.
652
- // We'll assume that this is an explicit user action if POST or GET has an 'action' key.
653
- if ( isset($_POST['action']) || isset($_GET['action']) ) {
654
- if ( $new_status == 'spam' && ( $old_status == 'approved' || $old_status == 'unapproved' || !$old_status ) ) {
655
- return akismet_submit_spam_comment( $comment->comment_ID );
656
- } elseif ( $old_status == 'spam' && ( $new_status == 'approved' || $new_status == 'unapproved' ) ) {
657
- return akismet_submit_nonspam_comment( $comment->comment_ID );
658
- }
659
- }
660
-
661
- akismet_update_comment_history( $comment->comment_ID, sprintf( __('%s changed the comment status to %s'), $reporter, $new_status ), 'status-' . $new_status );
662
- }
663
-
664
- add_action( 'transition_comment_status', 'akismet_transition_comment_status', 10, 3 );
665
-
666
- // Total spam in queue
667
- // get_option( 'akismet_spam_count' ) is the total caught ever
668
- function akismet_spam_count( $type = false ) {
669
- global $wpdb;
670
-
671
- if ( !$type ) { // total
672
- $count = wp_cache_get( 'akismet_spam_count', 'widget' );
673
- if ( false === $count ) {
674
- if ( function_exists('wp_count_comments') ) {
675
- $count = wp_count_comments();
676
- $count = $count->spam;
677
- } else {
678
- $count = (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam'");
679
- }
680
- wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 );
681
- }
682
- return $count;
683
- } elseif ( 'comments' == $type || 'comment' == $type ) { // comments
684
- $type = '';
685
- } else { // pingback, trackback, ...
686
- $type = $wpdb->escape( $type );
687
- }
688
-
689
- return (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam' AND comment_type='$type'");
690
- }
691
-
692
-
693
- function akismet_recheck_queue() {
694
- global $wpdb, $akismet_api_host, $akismet_api_port;
695
-
696
- akismet_fix_scheduled_recheck();
697
-
698
- if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) )
699
- return;
700
-
701
- $moderation = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0'", ARRAY_A );
702
- foreach ( (array) $moderation as $c ) {
703
- $c['user_ip'] = $c['comment_author_IP'];
704
- $c['user_agent'] = $c['comment_agent'];
705
- $c['referrer'] = '';
706
- $c['blog'] = get_bloginfo('url');
707
- $c['blog_lang'] = get_locale();
708
- $c['blog_charset'] = get_option('blog_charset');
709
- $c['permalink'] = get_permalink($c['comment_post_ID']);
710
-
711
- $c['user_role'] = '';
712
- if ( isset( $c['user_ID'] ) )
713
- $c['user_role'] = akismet_get_user_roles($c['user_ID']);
714
-
715
- if ( akismet_test_mode() )
716
- $c['is_test'] = 'true';
717
-
718
- $id = (int) $c['comment_ID'];
719
-
720
- $query_string = '';
721
- foreach ( $c as $key => $data )
722
- $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
723
-
724
- add_comment_meta( $c['comment_ID'], 'akismet_rechecking', true );
725
- $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
726
- if ( 'true' == $response[1] ) {
727
- wp_set_comment_status($c['comment_ID'], 'spam');
728
- update_comment_meta( $c['comment_ID'], 'akismet_result', 'true' );
729
- delete_comment_meta( $c['comment_ID'], 'akismet_error' );
730
- akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and caught this comment as spam'), 'check-spam' );
731
-
732
- } elseif ( 'false' == $response[1] ) {
733
- update_comment_meta( $c['comment_ID'], 'akismet_result', 'false' );
734
- delete_comment_meta( $c['comment_ID'], 'akismet_error' );
735
- akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and cleared this comment'), 'check-ham' );
736
- // abnormal result: error
737
- } else {
738
- update_comment_meta( $c['comment_ID'], 'akismet_result', 'error' );
739
- 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' );
740
- }
741
-
742
- delete_comment_meta( $c['comment_ID'], 'akismet_rechecking' );
743
- }
744
- wp_safe_redirect( $_SERVER['HTTP_REFERER'] );
745
- exit;
746
- }
747
-
748
- add_action('admin_action_akismet_recheck_queue', 'akismet_recheck_queue');
749
-
750
- // Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link
751
- function akismet_remove_comment_author_url() {
752
- if ( !empty($_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
753
- global $wpdb;
754
- $comment = get_comment( intval($_POST['id']), ARRAY_A );
755
- if (current_user_can('edit_comment', $comment['comment_ID'])) {
756
- $comment['comment_author_url'] = '';
757
- do_action( 'comment_remove_author_url' );
758
- print(wp_update_comment( $comment ));
759
- die();
760
- }
761
- }
762
- }
763
-
764
- add_action('wp_ajax_comment_author_deurl', 'akismet_remove_comment_author_url');
765
-
766
- function akismet_add_comment_author_url() {
767
- if ( !empty( $_POST['id'] ) && !empty( $_POST['url'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
768
- global $wpdb;
769
- $comment = get_comment( intval($_POST['id']), ARRAY_A );
770
- if (current_user_can('edit_comment', $comment['comment_ID'])) {
771
- $comment['comment_author_url'] = esc_url($_POST['url']);
772
- do_action( 'comment_add_author_url' );
773
- print(wp_update_comment( $comment ));
774
- die();
775
- }
776
- }
777
- }
778
-
779
- add_action('wp_ajax_comment_author_reurl', 'akismet_add_comment_author_url');
780
-
781
- // Check connectivity between the WordPress blog and Akismet's servers.
782
- // 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).
783
- function akismet_check_server_connectivity() {
784
- global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
785
-
786
- $test_host = 'rest.akismet.com';
787
-
788
- // Some web hosts may disable one or both functions
789
- if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') )
790
- return array();
791
-
792
- $ips = gethostbynamel($test_host);
793
- if ( !$ips || !is_array($ips) || !count($ips) )
794
- return array();
795
-
796
- $servers = array();
797
- foreach ( $ips as $ip ) {
798
- $response = akismet_verify_key( akismet_get_key(), $ip );
799
- // even if the key is invalid, at least we know we have connectivity
800
- if ( $response == 'valid' || $response == 'invalid' )
801
- $servers[$ip] = true;
802
- else
803
- $servers[$ip] = false;
804
- }
805
-
806
- return $servers;
807
- }
808
-
809
- // Check the server connectivity and store the results in an option.
810
- // Cached results will be used if not older than the specified timeout in seconds; use $cache_timeout = 0 to force an update.
811
- // Returns the same associative array as akismet_check_server_connectivity()
812
- function akismet_get_server_connectivity( $cache_timeout = 86400 ) {
813
- $servers = get_option('akismet_available_servers');
814
- if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false )
815
- return $servers;
816
-
817
- // There's a race condition here but the effect is harmless.
818
- $servers = akismet_check_server_connectivity();
819
- update_option('akismet_available_servers', $servers);
820
- update_option('akismet_connectivity_time', time());
821
- return $servers;
822
- }
823
-
824
- // Returns true if server connectivity was OK at the last check, false if there was a problem that needs to be fixed.
825
- function akismet_server_connectivity_ok() {
826
- // skip the check on WPMU because the status page is hidden
827
- global $wpcom_api_key;
828
- if ( $wpcom_api_key )
829
- return true;
830
- $servers = akismet_get_server_connectivity();
831
- return !( empty($servers) || !count($servers) || count( array_filter($servers) ) < count($servers) );
832
- }
833
-
834
- function akismet_admin_menu() {
835
- if ( class_exists( 'Jetpack' ) ) {
836
- add_action( 'jetpack_admin_menu', 'akismet_load_menu' );
837
- } else {
838
- akismet_load_menu();
839
- }
840
- }
841
-
842
- function akismet_load_menu() {
843
- if ( class_exists( 'Jetpack' ) ) {
844
- add_submenu_page( 'jetpack', __( 'Akismet Configuration' ), __( 'Akismet Configuration' ), 'manage_options', 'akismet-key-config', 'akismet_conf' );
845
- add_submenu_page( 'jetpack', __( 'Akismet Stats' ), __( 'Akismet Stats' ), 'manage_options', 'akismet-stats-display', 'akismet_stats_display' );
846
- } else {
847
- add_submenu_page('plugins.php', __('Akismet Configuration'), __('Akismet Configuration'), 'manage_options', 'akismet-key-config', 'akismet_conf');
848
- add_submenu_page('index.php', __('Akismet Stats'), __('Akismet Stats'), 'manage_options', 'akismet-stats-display', 'akismet_stats_display');
849
- }
850
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
akismet.css DELETED
@@ -1,12 +0,0 @@
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 DELETED
@@ -1,112 +0,0 @@
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
- // Need to determine size of author column
78
- var thisParentWidth = jQuery(this).parent().width();
79
- // It changes based on if there is a gravatar present
80
- thisParentWidth = (jQuery(this).parent().find('.grav-hijack').length) ? thisParentWidth - 42 + 'px' : thisParentWidth + 'px';
81
- if (jQuery(this).find('.mShot').length == 0 && !jQuery(this).hasClass('akismet_undo_link_removal')) {
82
- var thisId = jQuery(this).attr('id').replace('author_comment_url_', '');
83
- jQuery('.widefat td').css('overflow', 'visible');
84
- jQuery(this).css('position', 'relative');
85
- var thisHref = jQuery.URLEncode(jQuery(this).attr('href'));
86
- jQuery(this).append('<div class="mShot mshot-container" style="left: '+thisParentWidth+'"><div class="mshot-arrow"></div><img src="http://s.wordpress.com/mshots/v1/'+thisHref+'?w=450" width="450" class="mshot-image_'+thisId+'" style="margin: 0;" /></div>');
87
- setTimeout(function () {
88
- jQuery('.mshot-image_'+thisId).attr('src', 'http://s.wordpress.com/mshots/v1/'+thisHref+'?w=450&r=2');
89
- }, 6000);
90
- setTimeout(function () {
91
- jQuery('.mshot-image_'+thisId).attr('src', 'http://s.wordpress.com/mshots/v1/'+thisHref+'?w=450&r=3');
92
- }, 12000);
93
- } else {
94
- jQuery(this).find('.mShot').css('left', thisParentWidth).show();
95
- }
96
- }).mouseout(function () {
97
- jQuery(this).find('.mShot').hide();
98
- });
99
- });
100
- // URL encode plugin
101
- jQuery.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
102
- while(x<c.length){var m=r.exec(c.substr(x));
103
- if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
104
- }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
105
- o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;}
106
- });
107
- // Preload mshot images after everything else has loaded
108
- jQuery(window).load(function() {
109
- jQuery('a[id^="author_comment_url"]').each(function () {
110
- jQuery.get('http://s.wordpress.com/mshots/v1/'+jQuery.URLEncode(jQuery(this).attr('href'))+'?w=450');
111
- });
112
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
akismet.php CHANGED
@@ -4,32 +4,30 @@
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 <a href="admin.php?page=akismet-key-config">Akismet configuration</a> page, and save your API key.
9
- Version: 2.5.6
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
- define('AKISMET_VERSION', '2.5.6');
32
- define('AKISMET_PLUGIN_URL', plugin_dir_url( __FILE__ ));
33
 
34
  /** If you hardcode a WP.com API key here, all key config screens will be hidden */
35
  if ( defined('WPCOM_API_KEY') )
@@ -43,13 +41,8 @@ if ( !function_exists( 'add_action' ) ) {
43
  exit;
44
  }
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,9 +53,251 @@ function akismet_init() {
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,43 +305,115 @@ function akismet_get_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
@@ -121,78 +428,42 @@ function akismet_get_user_roles($user_id ) {
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,122 +471,11 @@ function akismet_result_spam( $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
- // wp_insert_comment() might be called in other contexts, so make sure this is the same comment
281
- // as was checked by akismet_auto_check_comment
282
- if ( is_object($comment) && !empty($akismet_last_comment) && is_array($akismet_last_comment) ) {
283
- if ( intval($akismet_last_comment['comment_post_ID']) == intval($comment->comment_post_ID)
284
- && $akismet_last_comment['comment_author'] == $comment->comment_author
285
- && $akismet_last_comment['comment_author_email'] == $comment->comment_author_email ) {
286
- // normal result: true or false
287
- if ( $akismet_last_comment['akismet_result'] == 'true' ) {
288
- update_comment_meta( $comment->comment_ID, 'akismet_result', 'true' );
289
- akismet_update_comment_history( $comment->comment_ID, __('Akismet caught this comment as spam'), 'check-spam' );
290
- if ( $comment->comment_approved != 'spam' )
291
- akismet_update_comment_history( $comment->comment_ID, sprintf( __('Comment status was changed to %s'), $comment->comment_approved), 'status-changed'.$comment->comment_approved );
292
- } elseif ( $akismet_last_comment['akismet_result'] == 'false' ) {
293
- update_comment_meta( $comment->comment_ID, 'akismet_result', 'false' );
294
- akismet_update_comment_history( $comment->comment_ID, __('Akismet cleared this comment'), 'check-ham' );
295
- if ( $comment->comment_approved == 'spam' ) {
296
- 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) )
297
- akismet_update_comment_history( $comment->comment_ID, __('Comment was caught by wp_blacklist_check'), 'wp-blacklisted' );
298
- else
299
- akismet_update_comment_history( $comment->comment_ID, sprintf( __('Comment status was changed to %s'), $comment->comment_approved), 'status-changed-'.$comment->comment_approved );
300
- }
301
- // abnormal result: error
302
- } else {
303
- update_comment_meta( $comment->comment_ID, 'akismet_error', time() );
304
- 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' );
305
- }
306
-
307
- // record the complete original data as submitted for checking
308
- if ( isset($akismet_last_comment['comment_as_submitted']) )
309
- update_comment_meta( $comment->comment_ID, 'akismet_as_submitted', $akismet_last_comment['comment_as_submitted'] );
310
- }
311
- }
312
- }
313
-
314
- add_action( 'wp_insert_comment', 'akismet_auto_check_update_meta', 10, 2 );
315
-
316
-
317
  function akismet_auto_check_comment( $commentdata ) {
318
- global $akismet_api_host, $akismet_api_port, $akismet_last_comment;
319
 
320
  $comment = $commentdata;
321
  $comment['user_ip'] = $_SERVER['REMOTE_ADDR'];
@@ -326,51 +486,21 @@ function akismet_auto_check_comment( $commentdata ) {
326
  $comment['blog_charset'] = get_option('blog_charset');
327
  $comment['permalink'] = get_permalink($comment['comment_post_ID']);
328
 
329
- if ( !empty( $comment['user_ID'] ) ) {
330
- $comment['user_role'] = akismet_get_user_roles($comment['user_ID']);
331
- }
332
-
333
- $akismet_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
334
- $comment['akismet_comment_nonce'] = 'inactive';
335
- if ( $akismet_nonce_option == 'true' || $akismet_nonce_option == '' ) {
336
- $comment['akismet_comment_nonce'] = 'failed';
337
- if ( isset( $_POST['akismet_comment_nonce'] ) && wp_verify_nonce( $_POST['akismet_comment_nonce'], 'akismet_comment_nonce_' . $comment['comment_post_ID'] ) )
338
- $comment['akismet_comment_nonce'] = 'passed';
339
-
340
- // comment reply in wp-admin
341
- if ( isset( $_POST['_ajax_nonce-replyto-comment'] ) && check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ) )
342
- $comment['akismet_comment_nonce'] = 'passed';
343
-
344
- }
345
-
346
- if ( akismet_test_mode() )
347
- $comment['is_test'] = 'true';
348
-
349
- foreach ($_POST as $key => $value ) {
350
- if ( is_string($value) )
351
- $comment["POST_{$key}"] = $value;
352
- }
353
 
354
  $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
355
 
356
- foreach ( $_SERVER as $key => $value ) {
357
  if ( !in_array( $key, $ignore ) && is_string($value) )
358
  $comment["$key"] = $value;
359
  else
360
  $comment["$key"] = '';
361
- }
362
-
363
- $post = get_post( $comment['comment_post_ID'] );
364
- $comment[ 'comment_post_modified_gmt' ] = $post->post_modified_gmt;
365
 
366
  $query_string = '';
367
  foreach ( $comment as $key => $data )
368
  $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
369
-
370
- $commentdata['comment_as_submitted'] = $comment;
371
 
372
  $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
373
- akismet_update_alert( $response );
374
  $commentdata['akismet_result'] = $response[1];
375
  if ( 'true' == $response[1] ) {
376
  // akismet_spam_count will be incremented later by akismet_result_spam()
@@ -378,6 +508,7 @@ function akismet_auto_check_comment( $commentdata ) {
378
 
379
  do_action( 'akismet_spam_caught' );
380
 
 
381
  $last_updated = strtotime( $post->post_modified_gmt );
382
  $diff = time() - $last_updated;
383
  $diff = $diff / 86400;
@@ -386,18 +517,7 @@ function akismet_auto_check_comment( $commentdata ) {
386
  // akismet_result_spam() won't be called so bump the counter here
387
  if ( $incr = apply_filters('akismet_spam_count_incr', 1) )
388
  update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );
389
- wp_safe_redirect( $_SERVER['HTTP_REFERER'] );
390
- die();
391
- }
392
- }
393
-
394
- // if the response is neither true nor false, hold the comment for moderation and schedule a recheck
395
- if ( 'true' != $response[1] && 'false' != $response[1] ) {
396
- if ( !current_user_can('moderate_comments') ) {
397
- add_filter('pre_comment_approved', 'akismet_result_hold');
398
- }
399
- if ( !wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) {
400
- wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
401
  }
402
  }
403
 
@@ -409,200 +529,361 @@ function akismet_auto_check_comment( $commentdata ) {
409
  // WP 2.0: run this one time in ten
410
  akismet_delete_old();
411
  }
412
- $akismet_last_comment = $commentdata;
413
-
414
- akismet_fix_scheduled_recheck();
415
  return $commentdata;
416
  }
417
 
418
- add_action('preprocess_comment', 'akismet_auto_check_comment', 1);
419
-
420
  function akismet_delete_old() {
421
  global $wpdb;
422
  $now_gmt = current_time('mysql', 1);
423
  $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'");
424
  if ( empty( $comment_ids ) )
425
  return;
426
-
427
- $comma_comment_ids = implode( ', ', array_map('intval', $comment_ids) );
428
 
429
  do_action( 'delete_comment', $comment_ids );
430
- $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_id IN ( $comma_comment_ids )");
431
- $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id IN ( $comma_comment_ids )");
432
- clean_comment_cache( $comment_ids );
433
  $n = mt_rand(1, 5000);
434
  if ( apply_filters('akismet_optimize_table', ($n == 11)) ) // lucky number
435
  $wpdb->query("OPTIMIZE TABLE $wpdb->comments");
436
 
437
  }
438
 
439
- function akismet_delete_old_metadata() {
440
- global $wpdb;
441
 
442
- $now_gmt = current_time( 'mysql', 1 );
443
- $interval = apply_filters( 'akismet_delete_commentmeta_interval', 15 );
 
444
 
445
- # enfore a minimum of 1 day
446
- $interval = absint( $interval );
447
- if ( $interval < 1 ) {
448
  return;
 
 
 
 
 
 
 
 
 
449
  }
450
 
451
- // akismet_as_submitted meta values are large, so expire them
452
- // after $interval days regardless of the comment status
453
- while ( TRUE ) {
454
- $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" );
455
 
456
- if ( empty( $comment_ids ) ) {
457
- return;
458
- }
459
 
460
- foreach ( $comment_ids as $comment_id ) {
461
- delete_comment_meta( $comment_id, 'akismet_as_submitted' );
462
- }
463
- }
 
 
 
464
 
465
- /*
466
- $n = mt_rand( 1, 5000 );
467
- if ( apply_filters( 'akismet_optimize_table', ( $n == 11 ), 'commentmeta' ) ) { // lucky number
468
- $wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );
 
 
 
 
 
 
 
 
 
 
469
  }
470
- */
471
- }
472
 
473
- add_action('akismet_scheduled_delete', 'akismet_delete_old');
474
- add_action('akismet_scheduled_delete', 'akismet_delete_old_metadata');
 
475
 
476
- function akismet_check_db_comment( $id, $recheck_reason = 'recheck_queue' ) {
477
- global $wpdb, $akismet_api_host, $akismet_api_port;
 
478
 
479
- $id = (int) $id;
480
- $c = $wpdb->get_row( "SELECT * FROM $wpdb->comments WHERE comment_ID = '$id'", ARRAY_A );
481
- if ( !$c )
482
- return;
483
 
484
- $c['user_ip'] = $c['comment_author_IP'];
485
- $c['user_agent'] = $c['comment_agent'];
486
- $c['referrer'] = '';
487
- $c['blog'] = get_option('home');
488
- $c['blog_lang'] = get_locale();
489
- $c['blog_charset'] = get_option('blog_charset');
490
- $c['permalink'] = get_permalink($c['comment_post_ID']);
491
- $id = $c['comment_ID'];
492
- if ( akismet_test_mode() )
493
- $c['is_test'] = 'true';
494
- $c['recheck_reason'] = $recheck_reason;
495
 
496
- $query_string = '';
497
- foreach ( $c as $key => $data )
498
- $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
 
 
 
 
 
 
 
 
 
 
499
 
500
- $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
501
- return $response[1];
 
 
 
502
  }
503
 
504
- function akismet_cron_recheck() {
 
 
 
 
 
 
 
 
 
 
 
 
505
  global $wpdb;
506
 
507
- $status = akismet_verify_key( akismet_get_key() );
508
- if ( get_option( 'akismet_alert_code' ) || $status == 'invalid' ) {
509
- // since there is currently a problem with the key, reschedule a check for 6 hours hence
510
- wp_schedule_single_event( time() + 21600, 'akismet_schedule_cron_recheck' );
511
- return false;
512
- }
513
-
514
- delete_option('akismet_available_servers');
515
-
516
- $comment_errors = $wpdb->get_col( "
517
- SELECT comment_id
518
- FROM {$wpdb->prefix}commentmeta
519
- WHERE meta_key = 'akismet_error'
520
- LIMIT 100
521
- " );
522
-
523
- foreach ( (array) $comment_errors as $comment_id ) {
524
- // if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
525
- $comment = get_comment( $comment_id );
526
- if ( !$comment || strtotime( $comment->comment_date_gmt ) < strtotime( "-15 days" ) ) {
527
- delete_comment_meta( $comment_id, 'akismet_error' );
528
- continue;
529
- }
530
-
531
- add_comment_meta( $comment_id, 'akismet_rechecking', true );
532
- $status = akismet_check_db_comment( $comment_id, 'retry' );
533
-
534
- $msg = '';
535
- if ( $status == 'true' ) {
536
- $msg = __( 'Akismet caught this comment as spam during an automatic retry.' );
537
- } elseif ( $status == 'false' ) {
538
- $msg = __( 'Akismet cleared this comment during an automatic retry.' );
539
- }
540
-
541
- // If we got back a legit response then update the comment history
542
- // other wise just bail now and try again later. No point in
543
- // re-trying all the comments once we hit one failure.
544
- if ( !empty( $msg ) ) {
545
- delete_comment_meta( $comment_id, 'akismet_error' );
546
- akismet_update_comment_history( $comment_id, $msg, 'cron-retry' );
547
- update_comment_meta( $comment_id, 'akismet_result', $status );
548
- // make sure the comment status is still pending. if it isn't, that means the user has already moved it elsewhere.
549
- $comment = get_comment( $comment_id );
550
- if ( $comment && 'unapproved' == wp_get_comment_status( $comment_id ) ) {
551
- if ( $status == 'true' ) {
552
- wp_spam_comment( $comment_id );
553
- } elseif ( $status == 'false' ) {
554
- // comment is good, but it's still in the pending queue. depending on the moderation settings
555
- // we may need to change it to approved.
556
- 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) )
557
- wp_set_comment_status( $comment_id, 1 );
558
- }
559
  }
560
- } else {
561
- delete_comment_meta( $comment_id, 'akismet_rechecking' );
562
- wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
563
- return;
564
  }
565
- delete_comment_meta( $comment_id, 'akismet_rechecking' );
 
 
 
 
566
  }
567
-
568
- $remaining = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ) );
569
- if ( $remaining && !wp_next_scheduled('akismet_schedule_cron_recheck') ) {
570
- wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
571
  }
 
 
 
 
 
 
 
 
572
  }
573
- add_action( 'akismet_schedule_cron_recheck', 'akismet_cron_recheck' );
 
 
574
 
575
- function akismet_add_comment_nonce( $post_id ) {
576
- echo '<p style="display: none;">';
577
- wp_nonce_field( 'akismet_comment_nonce_' . $post_id, 'akismet_comment_nonce', FALSE );
578
- echo '</p>';
 
 
 
 
 
579
  }
 
580
 
581
- $akismet_comment_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
 
582
 
583
- if ( $akismet_comment_nonce_option == 'true' || $akismet_comment_nonce_option == '' )
584
- add_action( 'comment_form', 'akismet_add_comment_nonce' );
585
 
586
- global $wp_version;
587
- if ( '3.0.5' == $wp_version ) {
588
- remove_filter( 'comment_text', 'wp_kses_data' );
589
- if ( is_admin() )
590
- add_filter( 'comment_text', 'wp_kses_post' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591
  }
592
 
593
- function akismet_fix_scheduled_recheck() {
594
- $future_check = wp_next_scheduled( 'akismet_schedule_cron_recheck' );
595
- if ( !$future_check ) {
 
 
 
 
 
596
  return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597
  }
598
 
599
- if ( get_option( 'akismet_alert_code' ) > 0 ) {
600
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
  }
602
 
603
- $check_range = time() + 1200;
604
- if ( $future_check > $check_range ) {
605
- wp_clear_scheduled_hook( 'akismet_schedule_cron_recheck' );
606
- wp_schedule_single_event( time() + 300, 'akismet_schedule_cron_recheck' );
 
 
 
 
 
 
 
 
 
 
 
607
  }
 
 
 
 
 
 
 
 
 
 
 
608
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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') )
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
  $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
  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
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
  // 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'];
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
 
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
  // 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
  // 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
+ ?>
index.php DELETED
@@ -1,2 +0,0 @@
1
- <?php
2
- # Silence is golden.
 
 
legacy.php CHANGED
@@ -52,9 +52,10 @@ function akismet_manage_page() {
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,8 +71,8 @@ function akismet_caught() {
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,8 +87,8 @@ function akismet_caught() {
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,7 +367,7 @@ function redirect_old_akismet_urls( ) {
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
  }
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
  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
  $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
  // 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
  }
readme.txt CHANGED
@@ -1,10 +1,10 @@
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.4
6
- Stable tag: 2.5.6
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,15 +13,11 @@ 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
- 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,75 +27,9 @@ Upload the Akismet plugin to your blog, Activate it, then enter your [Akismet.co
31
 
32
  == Changelog ==
33
 
34
- = 2.5.6 =
35
- * Prevent retry scheduling problems on sites where wp_cron is misbehaving
36
- * Preload mshot previews
37
- * Modernize the widget code
38
- * Fix a bug where comments were not held for moderation during an error condition
39
- * Improve the UX and display when comments are temporarily held due to an error
40
- * Make the Check For Spam button force a retry when comments are held due to an error
41
- * Handle errors caused by an invalid key
42
- * Don't retry comments that are too old
43
- * Improve error messages when verifying an API key
44
-
45
- = 2.5.5 =
46
- * Add nonce check for comment author URL remove action
47
- * Fix the settings link
48
-
49
- = 2.5.4 =
50
- * Limit Akismet CSS and Javascript loading in wp-admin to just the pages that need it
51
- * Added author URL quick removal functionality
52
- * Added mShot preview on Author URL hover
53
- * Added empty index.php to prevent directory listing
54
- * Move wp-admin menu items under Jetpack, if it is installed
55
- * Purge old Akismet comment meta data, default of 15 days
56
-
57
- = 2.5.3 =
58
- * Specify the license is GPL v2 or later
59
- * Fix a bug that could result in orphaned commentmeta entries
60
- * Include hotfix for WordPress 3.0.5 filter issue
61
-
62
- = 2.5.2 =
63
-
64
- * Properly format the comment count for author counts
65
- * Look for super admins on multisite installs when looking up user roles
66
- * Increase the HTTP request timeout
67
- * Removed padding for author approved count
68
- * Fix typo in function name
69
- * Set Akismet stats iframe height to fixed 2500px. Better to have one tall scroll bar than two side by side.
70
-
71
- = 2.5.1 =
72
-
73
- * Fix a bug that caused the "Auto delete" option to fail to discard comments correctly
74
- * Remove the comment nonce form field from the 'Akismet Configuration' page in favor of using a filter, akismet_comment_nonce
75
- * Fixed padding bug in "author" column of posts screen
76
- * Added margin-top to "cleared by ..." badges on dashboard
77
- * Fix possible error when calling akismet_cron_recheck()
78
- * Fix more PHP warnings
79
- * Clean up XHTML warnings for comment nonce
80
- * Fix for possible condition where scheduled comment re-checks could get stuck
81
- * Clean up the comment meta details after deleting a comment
82
- * Only show the status badge if the comment status has been changed by someone/something other than Akismet
83
- * Show a 'History' link in the row-actions
84
- * Translation fixes
85
- * Reduced font-size on author name
86
- * Moved "flagged by..." notification to top right corner of comment container and removed heavy styling
87
- * Hid "flagged by..." notification while on dashboard
88
-
89
- = 2.5.0 =
90
-
91
- * Track comment actions under 'Akismet Status' on the edit comment screen
92
- * Fix a few remaining deprecated function calls ( props Mike Glendinning )
93
- * Use HTTPS for the stats IFRAME when wp-admin is using HTTPS
94
- * Use the WordPress HTTP class if available
95
- * Move the admin UI code to a separate file, only loaded when needed
96
- * Add cron retry feature, to replace the old connectivity check
97
- * Display Akismet status badge beside each comment
98
- * Record history for each comment, and display it on the edit page
99
- * Record the complete comment as originally submitted in comment_meta, to use when reporting spam and ham
100
- * Highlight links in comment content
101
- * New option, "Show the number of comments you've approved beside each comment author."
102
- * New option, "Use a nonce on the comment form."
103
 
104
  = 2.4.0 =
105
 
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
  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
 
28
  == Changelog ==
29
 
30
+ = 2.4.1 =
31
+
32
+ * Security fix for wp_redirect() calls (thanks xknown)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  = 2.4.0 =
35
 
widget.php DELETED
@@ -1,108 +0,0 @@
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' );