Akismet Anti-Spam - Version 2.2.5

Version Description

Download this release

Release Info

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

Version 2.2.5

Files changed (3) hide show
  1. akismet.gif +0 -0
  2. akismet.php +1100 -0
  3. readme.txt +22 -0
akismet.gif ADDED
Binary file
akismet.php ADDED
@@ -0,0 +1,1100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Akismet
4
+ Plugin URI: http://akismet.com/
5
+ Description: Akismet checks your comments against the Akismet web service to see if they look like spam or not. You need a <a href="http://wordpress.com/api-keys/">WordPress.com 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>.
6
+ Version: 2.2.5
7
+ Author: Matt Mullenweg
8
+ Author URI: http://ma.tt/
9
+ */
10
+
11
+ // If you hardcode a WP.com API key here, all key config screens will be hidden
12
+ $wpcom_api_key = '';
13
+
14
+ function akismet_init() {
15
+ global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
16
+
17
+ if ( $wpcom_api_key )
18
+ $akismet_api_host = $wpcom_api_key . '.rest.akismet.com';
19
+ else
20
+ $akismet_api_host = get_option('wordpress_api_key') . '.rest.akismet.com';
21
+
22
+ $akismet_api_port = 80;
23
+ add_action('admin_menu', 'akismet_config_page');
24
+ add_action('admin_menu', 'akismet_stats_page');
25
+ akismet_admin_warnings();
26
+ }
27
+ add_action('init', 'akismet_init');
28
+
29
+ function akismet_admin_init() {
30
+ if ( function_exists( 'get_plugin_page_hook' ) )
31
+ $hook = get_plugin_page_hook( 'akismet-stats-display', 'index.php' );
32
+ else
33
+ $hook = 'dashboard_page_akismet-stats-display';
34
+ add_action('admin_head-'.$hook, 'akismet_stats_script');
35
+ }
36
+ add_action('admin_init', 'akismet_admin_init');
37
+
38
+ if ( !function_exists('wp_nonce_field') ) {
39
+ function akismet_nonce_field($action = -1) { return; }
40
+ $akismet_nonce = -1;
41
+ } else {
42
+ function akismet_nonce_field($action = -1) { return wp_nonce_field($action); }
43
+ $akismet_nonce = 'akismet-update-key';
44
+ }
45
+
46
+ if ( !function_exists('number_format_i18n') ) {
47
+ function number_format_i18n( $number, $decimals = null ) { return number_format( $number, $decimals ); }
48
+ }
49
+
50
+ function akismet_config_page() {
51
+ if ( function_exists('add_submenu_page') )
52
+ add_submenu_page('plugins.php', __('Akismet Configuration'), __('Akismet Configuration'), 'manage_options', 'akismet-key-config', 'akismet_conf');
53
+
54
+ }
55
+
56
+ function akismet_conf() {
57
+ global $akismet_nonce, $wpcom_api_key;
58
+
59
+ if ( isset($_POST['submit']) ) {
60
+ if ( function_exists('current_user_can') && !current_user_can('manage_options') )
61
+ die(__('Cheatin&#8217; uh?'));
62
+
63
+ check_admin_referer( $akismet_nonce );
64
+ $key = preg_replace( '/[^a-h0-9]/i', '', $_POST['key'] );
65
+
66
+ if ( empty($key) ) {
67
+ $key_status = 'empty';
68
+ $ms[] = 'new_key_empty';
69
+ delete_option('wordpress_api_key');
70
+ } else {
71
+ $key_status = akismet_verify_key( $key );
72
+ }
73
+
74
+ if ( $key_status == 'valid' ) {
75
+ update_option('wordpress_api_key', $key);
76
+ $ms[] = 'new_key_valid';
77
+ } else if ( $key_status == 'invalid' ) {
78
+ $ms[] = 'new_key_invalid';
79
+ } else if ( $key_status == 'failed' ) {
80
+ $ms[] = 'new_key_failed';
81
+ }
82
+
83
+ if ( isset( $_POST['akismet_discard_month'] ) )
84
+ update_option( 'akismet_discard_month', 'true' );
85
+ else
86
+ update_option( 'akismet_discard_month', 'false' );
87
+ } elseif ( isset($_POST['check']) ) {
88
+ akismet_get_server_connectivity(0);
89
+ }
90
+
91
+ if ( $key_status != 'valid' ) {
92
+ $key = get_option('wordpress_api_key');
93
+ if ( empty( $key ) ) {
94
+ if ( $key_status != 'failed' ) {
95
+ if ( akismet_verify_key( '1234567890ab' ) == 'failed' )
96
+ $ms[] = 'no_connection';
97
+ else
98
+ $ms[] = 'key_empty';
99
+ }
100
+ $key_status = 'empty';
101
+ } else {
102
+ $key_status = akismet_verify_key( $key );
103
+ }
104
+ if ( $key_status == 'valid' ) {
105
+ $ms[] = 'key_valid';
106
+ } else if ( $key_status == 'invalid' ) {
107
+ delete_option('wordpress_api_key');
108
+ $ms[] = 'key_empty';
109
+ } else if ( !empty($key) && $key_status == 'failed' ) {
110
+ $ms[] = 'key_failed';
111
+ }
112
+ }
113
+
114
+ $messages = array(
115
+ 'new_key_empty' => array('color' => 'aa0', 'text' => __('Your key has been cleared.')),
116
+ 'new_key_valid' => array('color' => '2d2', 'text' => __('Your key has been verified. Happy blogging!')),
117
+ 'new_key_invalid' => array('color' => 'd22', 'text' => __('The key you entered is invalid. Please double-check it.')),
118
+ '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.')),
119
+ 'no_connection' => array('color' => 'd22', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')),
120
+ 'key_empty' => array('color' => 'aa0', 'text' => sprintf(__('Please enter an API key. (<a href="%s" style="color:#fff">Get your key.</a>)'), 'http://wordpress.com/profile/')),
121
+ 'key_valid' => array('color' => '2d2', 'text' => __('This key is valid.')),
122
+ '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.')));
123
+ ?>
124
+ <?php if ( !empty($_POST['submit'] ) ) : ?>
125
+ <div id="message" class="updated fade"><p><strong><?php _e('Options saved.') ?></strong></p></div>
126
+ <?php endif; ?>
127
+ <div class="wrap">
128
+ <h2><?php _e('Akismet Configuration'); ?></h2>
129
+ <div class="narrow">
130
+ <form action="" method="post" id="akismet-conf" style="margin: auto; width: 400px; ">
131
+ <?php if ( !$wpcom_api_key ) { ?>
132
+ <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 a WordPress.com account yet, you can get one at <a href="%2$s">WordPress.com</a>.'), 'http://akismet.com/', 'http://wordpress.com/api-keys/'); ?></p>
133
+
134
+ <?php akismet_nonce_field($akismet_nonce) ?>
135
+ <h3><label for="key"><?php _e('WordPress.com API Key'); ?></label></h3>
136
+ <?php foreach ( $ms as $m ) : ?>
137
+ <p style="padding: .5em; background-color: #<?php echo $messages[$m]['color']; ?>; color: #fff; font-weight: bold;"><?php echo $messages[$m]['text']; ?></p>
138
+ <?php endforeach; ?>
139
+ <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://faq.wordpress.com/2005/10/19/api-key/">What is this?</a>'); ?>)</p>
140
+ <?php if ( $invalid_key ) { ?>
141
+ <h3><?php _e('Why might my key be invalid?'); ?></h3>
142
+ <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>
143
+ <?php } ?>
144
+ <?php } ?>
145
+ <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>
146
+ <p class="submit"><input type="submit" name="submit" value="<?php _e('Update options &raquo;'); ?>" /></p>
147
+ </form>
148
+
149
+ <form action="" method="post" id="akismet-connectivity" style="margin: auto; width: 400px; ">
150
+
151
+ <h3><?php _e('Server Connectivity'); ?></h3>
152
+ <?php
153
+ $servers = akismet_get_server_connectivity();
154
+ $fail_count = count($servers) - count( array_filter($servers) );
155
+ if ( is_array($servers) && count($servers) > 0 ) {
156
+ // some connections work, some fail
157
+ if ( $fail_count > 0 && $fail_count < count($servers) ) { ?>
158
+ <p style="padding: .5em; background-color: #aa0; color: #fff; font-weight:bold;"><?php _e('Unable to reach some Akismet servers.'); ?></p>
159
+ <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>
160
+ <?php
161
+ // all connections fail
162
+ } elseif ( $fail_count > 0 ) { ?>
163
+ <p style="padding: .5em; background-color: #d22; color: #fff; font-weight:bold;"><?php _e('Unable to reach any Akismet servers.'); ?></p>
164
+ <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>
165
+ <?php
166
+ // all connections work
167
+ } else { ?>
168
+ <p style="padding: .5em; background-color: #2d2; color: #fff; font-weight:bold;"><?php _e('All Akismet servers are available.'); ?></p>
169
+ <p><?php _e('Akismet is working correctly. All servers are accessible.'); ?></p>
170
+ <?php
171
+ }
172
+ } elseif ( !is_callable('fsockopen') ) {
173
+ ?>
174
+ <p style="padding: .5em; background-color: #d22; color: #fff; font-weight:bold;"><?php _e('Network functions are disabled.'); ?></p>
175
+ <p><?php echo sprintf( __('Your web host or server administrator has disabled PHP\'s <code>fsockopen</code> function. <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>
176
+ <?php
177
+ } else {
178
+ ?>
179
+ <p style="padding: .5em; background-color: #d22; color: #fff; font-weight:bold;"><?php _e('Unable to find Akismet servers.'); ?></p>
180
+ <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>
181
+ <?php
182
+ }
183
+
184
+ if ( !empty($servers) ) {
185
+ ?>
186
+ <table style="width: 100%;">
187
+ <thead><th><?php _e('Akismet server'); ?></th><th><?php _e('Network Status'); ?></th></thead>
188
+ <tbody>
189
+ <?php
190
+ asort($servers);
191
+ foreach ( $servers as $ip => $status ) {
192
+ $color = ( $status ? '#2d2' : '#d22');
193
+ ?>
194
+ <tr>
195
+ <td><?php echo htmlspecialchars($ip); ?></td>
196
+ <td style="padding: 0 .5em; font-weight:bold; color: #fff; background-color: <?php echo $color; ?>"><?php echo ($status ? __('No problems') : __('Obstructed') ); ?></td>
197
+
198
+ <?php
199
+ }
200
+ }
201
+ ?>
202
+ </tbody>
203
+ </table>
204
+ <p><?php if ( get_option('akismet_connectivity_time') ) echo sprintf( __('Last checked %s ago.'), human_time_diff( get_option('akismet_connectivity_time') ) ); ?></p>
205
+ <p class="submit"><input type="submit" name="check" value="<?php _e('Check network status &raquo;'); ?>" /></p>
206
+ </form>
207
+
208
+ </div>
209
+ </div>
210
+ <?php
211
+ }
212
+
213
+ function akismet_stats_page() {
214
+ if ( function_exists('add_submenu_page') )
215
+ add_submenu_page('index.php', __('Akismet Stats'), __('Akismet Stats'), 'manage_options', 'akismet-stats-display', 'akismet_stats_display');
216
+
217
+ }
218
+
219
+ function akismet_stats_script() {
220
+ ?>
221
+ <script type="text/javascript">
222
+ function resizeIframe() {
223
+ var height = document.documentElement.clientHeight;
224
+ height -= document.getElementById('akismet-stats-frame').offsetTop;
225
+ height += 100; // magic padding
226
+
227
+ document.getElementById('akismet-stats-frame').style.height = height +"px";
228
+
229
+ };
230
+ function resizeIframeInit() {
231
+ document.getElementById('akismet-stats-frame').onload = resizeIframe;
232
+ window.onresize = resizeIframe;
233
+ }
234
+ addLoadEvent(resizeIframeInit);
235
+ </script><?php
236
+ }
237
+
238
+
239
+ function akismet_stats_display() {
240
+ global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
241
+ $blog = urlencode( get_option('home') );
242
+ $url = "http://".akismet_get_key().".web.akismet.com/1.0/user-stats.php?blog={$blog}";
243
+ ?>
244
+ <div class="wrap">
245
+ <iframe src="<?php echo $url; ?>" width="100%" height="100%" frameborder="0" id="akismet-stats-frame"></iframe>
246
+ </div>
247
+ <?php
248
+ }
249
+
250
+ function akismet_get_key() {
251
+ global $wpcom_api_key;
252
+ if ( !empty($wpcom_api_key) )
253
+ return $wpcom_api_key;
254
+ return get_option('wordpress_api_key');
255
+ }
256
+
257
+ function akismet_verify_key( $key, $ip = null ) {
258
+ global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
259
+ $blog = urlencode( get_option('home') );
260
+ if ( $wpcom_api_key )
261
+ $key = $wpcom_api_key;
262
+ $response = akismet_http_post("key=$key&blog=$blog", 'rest.akismet.com', '/1.1/verify-key', $akismet_api_port, $ip);
263
+ if ( !is_array($response) || !isset($response[1]) || $response[1] != 'valid' && $response[1] != 'invalid' )
264
+ return 'failed';
265
+ return $response[1];
266
+ }
267
+
268
+ // Check connectivity between the WordPress blog and Akismet's servers.
269
+ // 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).
270
+ function akismet_check_server_connectivity() {
271
+ global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
272
+
273
+ $test_host = 'rest.akismet.com';
274
+
275
+ // Some web hosts may disable one or both functions
276
+ if ( !is_callable('fsockopen') || !is_callable('gethostbynamel') )
277
+ return array();
278
+
279
+ $ips = gethostbynamel($test_host);
280
+ if ( !$ips || !is_array($ips) || !count($ips) )
281
+ return array();
282
+
283
+ $servers = array();
284
+ foreach ( $ips as $ip ) {
285
+ $response = akismet_verify_key( akismet_get_key(), $ip );
286
+ // even if the key is invalid, at least we know we have connectivity
287
+ if ( $response == 'valid' || $response == 'invalid' )
288
+ $servers[$ip] = true;
289
+ else
290
+ $servers[$ip] = false;
291
+ }
292
+
293
+ return $servers;
294
+ }
295
+
296
+ // Check the server connectivity and store the results in an option.
297
+ // Cached results will be used if not older than the specified timeout in seconds; use $cache_timeout = 0 to force an update.
298
+ // Returns the same associative array as akismet_check_server_connectivity()
299
+ function akismet_get_server_connectivity( $cache_timeout = 86400 ) {
300
+ $servers = get_option('akismet_available_servers');
301
+ if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false )
302
+ return $servers;
303
+
304
+ // There's a race condition here but the effect is harmless.
305
+ $servers = akismet_check_server_connectivity();
306
+ update_option('akismet_available_servers', $servers);
307
+ update_option('akismet_connectivity_time', time());
308
+ return $servers;
309
+ }
310
+
311
+ // Returns true if server connectivity was OK at the last check, false if there was a problem that needs to be fixed.
312
+ function akismet_server_connectivity_ok() {
313
+ $servers = akismet_get_server_connectivity();
314
+ return !( empty($servers) || !count($servers) || count( array_filter($servers) ) < count($servers) );
315
+ }
316
+
317
+ function akismet_admin_warnings() {
318
+ if ( !get_option('wordpress_api_key') && !$wpcom_api_key && !isset($_POST['submit']) ) {
319
+ function akismet_warning() {
320
+ echo "
321
+ <div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet is almost ready.')."</strong> ".sprintf(__('You must <a href="%1$s">enter your WordPress.com API key</a> for it to work.'), "plugins.php?page=akismet-key-config")."</p></div>
322
+ ";
323
+ }
324
+ add_action('admin_notices', 'akismet_warning');
325
+ return;
326
+ } elseif ( get_option('akismet_connectivity_time') && empty($_POST) && is_admin() && !akismet_server_connectivity_ok() ) {
327
+ function akismet_warning() {
328
+ echo "
329
+ <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>
330
+ ";
331
+ }
332
+ add_action('admin_notices', 'akismet_warning');
333
+ return;
334
+ }
335
+ }
336
+
337
+ function akismet_get_host($host) {
338
+ // if all servers are accessible, just return the host name.
339
+ // if not, return an IP that was known to be accessible at the last check.
340
+ if ( akismet_server_connectivity_ok() ) {
341
+ return $host;
342
+ } else {
343
+ $ips = akismet_get_server_connectivity();
344
+ // a firewall may be blocking access to some Akismet IPs
345
+ if ( count($ips) > 0 && count(array_filter($ips)) < count($ips) ) {
346
+ // use DNS to get current IPs, but exclude any known to be unreachable
347
+ $dns = (array)gethostbynamel( rtrim($host, '.') . '.' );
348
+ $dns = array_filter($dns);
349
+ foreach ( $dns as $ip ) {
350
+ if ( array_key_exists( $ip, $ips ) && empty( $ips[$ip] ) )
351
+ unset($dns[$ip]);
352
+ }
353
+ // return a random IP from those available
354
+ if ( count($dns) )
355
+ return $dns[ array_rand($dns) ];
356
+
357
+ }
358
+ }
359
+ // if all else fails try the host name
360
+ return $host;
361
+ }
362
+
363
+ // Returns array with headers in $response[0] and body in $response[1]
364
+ function akismet_http_post($request, $host, $path, $port = 80, $ip=null) {
365
+ global $wp_version;
366
+
367
+ $http_request = "POST $path HTTP/1.0\r\n";
368
+ $http_request .= "Host: $host\r\n";
369
+ $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";
370
+ $http_request .= "Content-Length: " . strlen($request) . "\r\n";
371
+ $http_request .= "User-Agent: WordPress/$wp_version | Akismet/2.0\r\n";
372
+ $http_request .= "\r\n";
373
+ $http_request .= $request;
374
+
375
+ $http_host = $host;
376
+ // use a specific IP if provided - needed by akismet_check_server_connectivity()
377
+ if ( $ip && long2ip(ip2long($ip)) ) {
378
+ $http_host = $ip;
379
+ } else {
380
+ $http_host = akismet_get_host($host);
381
+ }
382
+
383
+ $response = '';
384
+ if( false != ( $fs = @fsockopen($http_host, $port, $errno, $errstr, 10) ) ) {
385
+ fwrite($fs, $http_request);
386
+
387
+ while ( !feof($fs) )
388
+ $response .= fgets($fs, 1160); // One TCP-IP packet
389
+ fclose($fs);
390
+ $response = explode("\r\n\r\n", $response, 2);
391
+ }
392
+ return $response;
393
+ }
394
+
395
+ function akismet_auto_check_comment( $comment ) {
396
+ global $akismet_api_host, $akismet_api_port;
397
+
398
+ $comment['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
399
+ $comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
400
+ $comment['referrer'] = $_SERVER['HTTP_REFERER'];
401
+ $comment['blog'] = get_option('home');
402
+ $comment['blog_lang'] = get_locale();
403
+ $comment['blog_charset'] = get_option('blog_charset');
404
+ $comment['permalink'] = get_permalink($comment['comment_post_ID']);
405
+
406
+ $ignore = array( 'HTTP_COOKIE' );
407
+
408
+ foreach ( $_SERVER as $key => $value )
409
+ if ( !in_array( $key, $ignore ) )
410
+ $comment["$key"] = $value;
411
+
412
+ $query_string = '';
413
+ foreach ( $comment as $key => $data )
414
+ $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
415
+
416
+ $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
417
+ if ( 'true' == $response[1] ) {
418
+ add_filter('pre_comment_approved', create_function('$a', 'return \'spam\';'));
419
+ update_option( 'akismet_spam_count', get_option('akismet_spam_count') + 1 );
420
+
421
+ do_action( 'akismet_spam_caught' );
422
+
423
+ $post = get_post( $comment['comment_post_ID'] );
424
+ $last_updated = strtotime( $post->post_modified_gmt );
425
+ $diff = time() - $last_updated;
426
+ $diff = $diff / 86400;
427
+
428
+ if ( $post->post_type == 'post' && $diff > 30 && get_option( 'akismet_discard_month' ) == 'true' )
429
+ die;
430
+ }
431
+ akismet_delete_old();
432
+ return $comment;
433
+ }
434
+
435
+ function akismet_delete_old() {
436
+ global $wpdb;
437
+ $now_gmt = current_time('mysql', 1);
438
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE DATE_SUB('$now_gmt', INTERVAL 15 DAY) > comment_date_gmt AND comment_approved = 'spam'");
439
+ $n = mt_rand(1, 5000);
440
+ if ( $n == 11 ) // lucky number
441
+ $wpdb->query("OPTIMIZE TABLE $wpdb->comments");
442
+ }
443
+
444
+ function akismet_submit_nonspam_comment ( $comment_id ) {
445
+ global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
446
+ $comment_id = (int) $comment_id;
447
+
448
+ $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
449
+ if ( !$comment ) // it was deleted
450
+ return;
451
+ $comment->blog = get_option('home');
452
+ $comment->blog_lang = get_locale();
453
+ $comment->blog_charset = get_option('blog_charset');
454
+ $comment->permalink = get_permalink($comment->comment_post_ID);
455
+ if ( is_object($current_user) ) {
456
+ $comment->reporter = $current_user->user_login;
457
+ }
458
+ if ( is_object($current_site) ) {
459
+ $comment->site_domain = $current_site->domain;
460
+ }
461
+ $query_string = '';
462
+ foreach ( $comment as $key => $data )
463
+ $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
464
+
465
+ $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-ham", $akismet_api_port);
466
+ }
467
+
468
+ function akismet_submit_spam_comment ( $comment_id ) {
469
+ global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
470
+ $comment_id = (int) $comment_id;
471
+
472
+ $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
473
+ if ( !$comment ) // it was deleted
474
+ return;
475
+ if ( 'spam' != $comment->comment_approved )
476
+ return;
477
+ $comment->blog = get_option('home');
478
+ $comment->blog_lang = get_locale();
479
+ $comment->blog_charset = get_option('blog_charset');
480
+ $comment->permalink = get_permalink($comment->comment_post_ID);
481
+ if ( is_object($current_user) ) {
482
+ $comment->reporter = $current_user->user_login;
483
+ }
484
+ if ( is_object($current_site) ) {
485
+ $comment->site_domain = $current_site->domain;
486
+ }
487
+ $query_string = '';
488
+ foreach ( $comment as $key => $data )
489
+ $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
490
+
491
+ $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-spam", $akismet_api_port);
492
+ }
493
+
494
+ add_action('wp_set_comment_status', 'akismet_submit_spam_comment');
495
+ add_action('edit_comment', 'akismet_submit_spam_comment');
496
+ add_action('preprocess_comment', 'akismet_auto_check_comment', 1);
497
+
498
+ function akismet_spamtoham( $comment ) { akismet_submit_nonspam_comment( $comment->comment_ID ); }
499
+ add_filter( 'comment_spam_to_approved', 'akismet_spamtoham' );
500
+
501
+ // Total spam in queue
502
+ // get_option( 'akismet_spam_count' ) is the total caught ever
503
+ function akismet_spam_count( $type = false ) {
504
+ global $wpdb;
505
+
506
+ if ( !$type ) { // total
507
+ $count = wp_cache_get( 'akismet_spam_count', 'widget' );
508
+ if ( false === $count ) {
509
+ if ( function_exists('wp_count_comments') ) {
510
+ $count = wp_count_comments();
511
+ $count = $count->spam;
512
+ } else {
513
+ $count = (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam'");
514
+ }
515
+ wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 );
516
+ }
517
+ return $count;
518
+ } elseif ( 'comments' == $type || 'comment' == $type ) { // comments
519
+ $type = '';
520
+ } else { // pingback, trackback, ...
521
+ $type = $wpdb->escape( $type );
522
+ }
523
+
524
+ return (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam' AND comment_type='$type'");
525
+ }
526
+
527
+ function akismet_spam_comments( $type = false, $page = 1, $per_page = 50 ) {
528
+ global $wpdb;
529
+
530
+ $page = (int) $page;
531
+ if ( $page < 2 )
532
+ $page = 1;
533
+
534
+ $per_page = (int) $per_page;
535
+ if ( $per_page < 1 )
536
+ $per_page = 50;
537
+
538
+ $start = ( $page - 1 ) * $per_page;
539
+ $end = $start + $per_page;
540
+
541
+ if ( $type ) {
542
+ if ( 'comments' == $type || 'comment' == $type )
543
+ $type = '';
544
+ else
545
+ $type = $wpdb->escape( $type );
546
+ return $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = 'spam' AND comment_type='$type' ORDER BY comment_date DESC LIMIT $start, $end");
547
+ }
548
+
549
+ // All
550
+ return $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = 'spam' ORDER BY comment_date DESC LIMIT $start, $end");
551
+ }
552
+
553
+ // Totals for each comment type
554
+ // returns array( type => count, ... )
555
+ function akismet_spam_totals() {
556
+ global $wpdb;
557
+ $totals = $wpdb->get_results( "SELECT comment_type, COUNT(*) AS cc FROM $wpdb->comments WHERE comment_approved = 'spam' GROUP BY comment_type" );
558
+ $return = array();
559
+ foreach ( $totals as $total )
560
+ $return[$total->comment_type ? $total->comment_type : 'comment'] = $total->cc;
561
+ return $return;
562
+ }
563
+
564
+ function akismet_manage_page() {
565
+ global $wpdb, $submenu, $wp_db_version;
566
+
567
+ // WP 2.7 has its own spam management page
568
+ if ( 8645 <= $wp_db_version )
569
+ return;
570
+
571
+ $count = sprintf(__('Akismet Spam (%s)'), akismet_spam_count());
572
+ if ( isset( $submenu['edit-comments.php'] ) )
573
+ add_submenu_page('edit-comments.php', __('Akismet Spam'), $count, 'moderate_comments', 'akismet-admin', 'akismet_caught' );
574
+ elseif ( function_exists('add_management_page') )
575
+ add_management_page(__('Akismet Spam'), $count, 'moderate_comments', 'akismet-admin', 'akismet_caught');
576
+ }
577
+
578
+ function akismet_caught() {
579
+ global $wpdb, $comment, $akismet_caught, $akismet_nonce;
580
+
581
+ akismet_recheck_queue();
582
+ if (isset($_POST['submit']) && 'recover' == $_POST['action'] && ! empty($_POST['not_spam'])) {
583
+ check_admin_referer( $akismet_nonce );
584
+ if ( function_exists('current_user_can') && !current_user_can('moderate_comments') )
585
+ die(__('You do not have sufficient permission to moderate comments.'));
586
+
587
+ $i = 0;
588
+ foreach ($_POST['not_spam'] as $comment):
589
+ $comment = (int) $comment;
590
+ if ( function_exists('wp_set_comment_status') )
591
+ wp_set_comment_status($comment, 'approve');
592
+ else
593
+ $wpdb->query("UPDATE $wpdb->comments SET comment_approved = '1' WHERE comment_ID = '$comment'");
594
+ akismet_submit_nonspam_comment($comment);
595
+ ++$i;
596
+ endforeach;
597
+ $to = add_query_arg( 'recovered', $i, $_SERVER['HTTP_REFERER'] );
598
+ wp_redirect( $to );
599
+ exit;
600
+ }
601
+ if ('delete' == $_POST['action']) {
602
+ check_admin_referer( $akismet_nonce );
603
+ if ( function_exists('current_user_can') && !current_user_can('moderate_comments') )
604
+ die(__('You do not have sufficient permission to moderate comments.'));
605
+
606
+ $delete_time = $wpdb->escape( $_POST['display_time'] );
607
+ $nuked = $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam' AND '$delete_time' > comment_date_gmt" );
608
+ wp_cache_delete( 'akismet_spam_count', 'widget' );
609
+ $to = add_query_arg( 'deleted', 'all', $_SERVER['HTTP_REFERER'] );
610
+ wp_redirect( $to );
611
+ exit;
612
+ }
613
+
614
+ if ( isset( $_GET['recovered'] ) ) {
615
+ $i = (int) $_GET['recovered'];
616
+ echo '<div class="updated"><p>' . sprintf(__('%1$s comments recovered.'), $i) . "</p></div>";
617
+ }
618
+
619
+ if (isset( $_GET['deleted'] ) )
620
+ echo '<div class="updated"><p>' . __('All spam deleted.') . '</p></div>';
621
+
622
+ if ( isset( $GLOBALS['submenu']['edit-comments.php'] ) )
623
+ $link = 'edit-comments.php';
624
+ else
625
+ $link = 'edit.php';
626
+ ?>
627
+ <style type="text/css">
628
+ .akismet-tabs {
629
+ list-style: none;
630
+ margin: 0;
631
+ padding: 0;
632
+ clear: both;
633
+ border-bottom: 1px solid #ccc;
634
+ height: 31px;
635
+ margin-bottom: 20px;
636
+ background: #ddd;
637
+ border-top: 1px solid #bdbdbd;
638
+ }
639
+ .akismet-tabs li {
640
+ float: left;
641
+ margin: 5px 0 0 20px;
642
+ }
643
+ .akismet-tabs a {
644
+ display: block;
645
+ padding: 4px .5em 3px;
646
+ border-bottom: none;
647
+ color: #036;
648
+ }
649
+ .akismet-tabs .active a {
650
+ background: #fff;
651
+ border: 1px solid #ccc;
652
+ border-bottom: none;
653
+ color: #000;
654
+ font-weight: bold;
655
+ padding-bottom: 4px;
656
+ }
657
+ #akismetsearch {
658
+ float: right;
659
+ margin-top: -.5em;
660
+ }
661
+
662
+ #akismetsearch p {
663
+ margin: 0;
664
+ padding: 0;
665
+ }
666
+ </style>
667
+ <div class="wrap">
668
+ <h2><?php _e('Caught Spam') ?></h2>
669
+ <?php
670
+ $count = get_option( 'akismet_spam_count' );
671
+ if ( $count ) {
672
+ ?>
673
+ <p><?php printf(__('Akismet has caught <strong>%1$s spam</strong> for you since you first installed it.'), number_format_i18n($count) ); ?></p>
674
+ <?php
675
+ }
676
+
677
+ $spam_count = akismet_spam_count();
678
+
679
+ if ( 0 == $spam_count ) {
680
+ echo '<p>'.__('You have no spam currently in the queue. Must be your lucky day. :)').'</p>';
681
+ echo '</div>';
682
+ } else {
683
+ echo '<p>'.__('You can delete all of the spam from your database with a single click. This operation cannot be undone, so you may wish to check to ensure that no legitimate comments got through first. Spam is automatically deleted after 15 days, so don&#8217;t sweat it.').'</p>';
684
+ ?>
685
+ <?php if ( !isset( $_POST['s'] ) ) { ?>
686
+ <form method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>">
687
+ <?php akismet_nonce_field($akismet_nonce) ?>
688
+ <input type="hidden" name="action" value="delete" />
689
+ <?php printf(__('There are currently %1$s comments identified as spam.'), $spam_count); ?>&nbsp; &nbsp; <input type="submit" class="button delete" name="Submit" value="<?php _e('Delete all'); ?>" />
690
+ <input type="hidden" name="display_time" value="<?php echo current_time('mysql', 1); ?>" />
691
+ </form>
692
+ <?php } ?>
693
+ </div>
694
+ <div class="wrap">
695
+ <?php if ( isset( $_POST['s'] ) ) { ?>
696
+ <h2><?php _e('Search'); ?></h2>
697
+ <?php } else { ?>
698
+ <?php echo '<p>'.__('These are the latest comments identified as spam by Akismet. If you see any mistakes, simply mark the comment as "not spam" and Akismet will learn from the submission. If you wish to recover a comment from spam, simply select the comment, and click Not Spam. After 15 days we clean out the junk for you.').'</p>'; ?>
699
+ <?php } ?>
700
+ <?php
701
+ if ( isset( $_POST['s'] ) ) {
702
+ $s = $wpdb->escape($_POST['s']);
703
+ $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE
704
+ (comment_author LIKE '%$s%' OR
705
+ comment_author_email LIKE '%$s%' OR
706
+ comment_author_url LIKE ('%$s%') OR
707
+ comment_author_IP LIKE ('%$s%') OR
708
+ comment_content LIKE ('%$s%') ) AND
709
+ comment_approved = 'spam'
710
+ ORDER BY comment_date DESC");
711
+ } else {
712
+ if ( isset( $_GET['apage'] ) )
713
+ $page = (int) $_GET['apage'];
714
+ else
715
+ $page = 1;
716
+
717
+ if ( $page < 2 )
718
+ $page = 1;
719
+
720
+ $current_type = false;
721
+ if ( isset( $_GET['ctype'] ) )
722
+ $current_type = preg_replace( '|[^a-z]|', '', $_GET['ctype'] );
723
+
724
+ $comments = akismet_spam_comments( $current_type, $page );
725
+ $total = akismet_spam_count( $current_type );
726
+ $totals = akismet_spam_totals();
727
+ ?>
728
+ <ul class="akismet-tabs">
729
+ <li <?php if ( !isset( $_GET['ctype'] ) ) echo ' class="active"'; ?>><a href="edit-comments.php?page=akismet-admin"><?php _e('All'); ?></a></li>
730
+ <?php
731
+ foreach ( $totals as $type => $type_count ) {
732
+ if ( 'comment' == $type ) {
733
+ $type = 'comments';
734
+ $show = __('Comments');
735
+ } else {
736
+ $show = ucwords( $type );
737
+ }
738
+ $type_count = number_format_i18n( $type_count );
739
+ $extra = $current_type === $type ? ' class="active"' : '';
740
+ echo "<li $extra><a href='edit-comments.php?page=akismet-admin&amp;ctype=$type'>$show ($type_count)</a></li>";
741
+ }
742
+ do_action( 'akismet_tabs' ); // so plugins can add more tabs easily
743
+ ?>
744
+ </ul>
745
+ <?php
746
+ }
747
+
748
+ if ($comments) {
749
+ ?>
750
+ <form method="post" action="<?php echo attribute_escape("$link?page=akismet-admin"); ?>" id="akismetsearch">
751
+ <p> <input type="text" name="s" value="<?php if (isset($_POST['s'])) echo attribute_escape($_POST['s']); ?>" size="17" />
752
+ <input type="submit" class="button" name="submit" value="<?php echo attribute_escape(__('Search Spam &raquo;')) ?>" /> </p>
753
+ </form>
754
+ <?php if ( $total > 50 ) {
755
+ $total_pages = ceil( $total / 50 );
756
+ $r = '';
757
+ if ( 1 < $page ) {
758
+ $args['apage'] = ( 1 == $page - 1 ) ? '' : $page - 1;
759
+ $r .= '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">'. __('&laquo; Previous Page') .'</a>' . "\n";
760
+ }
761
+ if ( ( $total_pages = ceil( $total / 50 ) ) > 1 ) {
762
+ for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
763
+ if ( $page == $page_num ) :
764
+ $r .= "<strong>$page_num</strong>\n";
765
+ else :
766
+ $p = false;
767
+ if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
768
+ $args['apage'] = ( 1 == $page_num ) ? '' : $page_num;
769
+ $r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
770
+ $in = true;
771
+ elseif ( $in == true ) :
772
+ $r .= "...\n";
773
+ $in = false;
774
+ endif;
775
+ endif;
776
+ endfor;
777
+ }
778
+ if ( ( $page ) * 50 < $total || -1 == $total ) {
779
+ $args['apage'] = $page + 1;
780
+ $r .= '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page &raquo;') .'</a>' . "\n";
781
+ }
782
+ echo "<p>$r</p>";
783
+ ?>
784
+
785
+ <?php } ?>
786
+ <form style="clear: both;" method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>">
787
+ <?php akismet_nonce_field($akismet_nonce) ?>
788
+ <input type="hidden" name="action" value="recover" />
789
+ <ul id="spam-list" class="commentlist" style="list-style: none; margin: 0; padding: 0;">
790
+ <?php
791
+ $i = 0;
792
+ foreach($comments as $comment) {
793
+ $i++;
794
+ $comment_date = mysql2date(get_option("date_format") . " @ " . get_option("time_format"), $comment->comment_date);
795
+ $post = get_post($comment->comment_post_ID);
796
+ $post_title = $post->post_title;
797
+ if ($i % 2) $class = 'class="alternate"';
798
+ else $class = '';
799
+ echo "\n\t<li id='comment-$comment->comment_ID' $class>";
800
+ ?>
801
+
802
+ <p><strong><?php comment_author() ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
803
+
804
+ <?php comment_text() ?>
805
+
806
+ <p><label for="spam-<?php echo $comment->comment_ID; ?>">
807
+ <input type="checkbox" id="spam-<?php echo $comment->comment_ID; ?>" name="not_spam[]" value="<?php echo $comment->comment_ID; ?>" />
808
+ <?php _e('Not Spam') ?></label> &#8212; <?php comment_date('M j, g:i A'); ?> &#8212; [
809
+ <?php
810
+ $post = get_post($comment->comment_post_ID);
811
+ $post_title = wp_specialchars( $post->post_title, 'double' );
812
+ $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
813
+ ?>
814
+ <a href="<?php echo get_permalink($comment->comment_post_ID); ?>" title="<?php echo $post_title; ?>"><?php _e('View Post') ?></a> ] </p>
815
+
816
+
817
+ <?php
818
+ }
819
+ ?>
820
+ </ul>
821
+ <?php if ( $total > 50 ) {
822
+ $total_pages = ceil( $total / 50 );
823
+ $r = '';
824
+ if ( 1 < $page ) {
825
+ $args['apage'] = ( 1 == $page - 1 ) ? '' : $page - 1;
826
+ $r .= '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">'. __('&laquo; Previous Page') .'</a>' . "\n";
827
+ }
828
+ if ( ( $total_pages = ceil( $total / 50 ) ) > 1 ) {
829
+ for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
830
+ if ( $page == $page_num ) :
831
+ $r .= "<strong>$page_num</strong>\n";
832
+ else :
833
+ $p = false;
834
+ if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
835
+ $args['apage'] = ( 1 == $page_num ) ? '' : $page_num;
836
+ $r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
837
+ $in = true;
838
+ elseif ( $in == true ) :
839
+ $r .= "...\n";
840
+ $in = false;
841
+ endif;
842
+ endif;
843
+ endfor;
844
+ }
845
+ if ( ( $page ) * 50 < $total || -1 == $total ) {
846
+ $args['apage'] = $page + 1;
847
+ $r .= '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page &raquo;') .'</a>' . "\n";
848
+ }
849
+ echo "<p>$r</p>";
850
+ }
851
+ ?>
852
+ <p class="submit">
853
+ <input type="submit" name="submit" value="<?php echo attribute_escape(__('De-spam marked comments &raquo;')); ?>" />
854
+ </p>
855
+ <p><?php _e('Comments you de-spam will be submitted to Akismet as mistakes so it can learn and get better.'); ?></p>
856
+ </form>
857
+ <?php
858
+ } else {
859
+ ?>
860
+ <p><?php _e('No results found.'); ?></p>
861
+ <?php } ?>
862
+
863
+ <?php if ( !isset( $_POST['s'] ) ) { ?>
864
+ <form method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>">
865
+ <?php akismet_nonce_field($akismet_nonce) ?>
866
+ <p><input type="hidden" name="action" value="delete" />
867
+ <?php printf(__('There are currently %1$s comments identified as spam.'), $spam_count); ?>&nbsp; &nbsp; <input type="submit" name="Submit" class="button" value="<?php echo attribute_escape(__('Delete all')); ?>" />
868
+ <input type="hidden" name="display_time" value="<?php echo current_time('mysql', 1); ?>" /></p>
869
+ </form>
870
+ <?php } ?>
871
+ </div>
872
+ <?php
873
+ }
874
+ }
875
+
876
+ add_action('admin_menu', 'akismet_manage_page');
877
+
878
+ // WP < 2.5
879
+ function akismet_stats() {
880
+ if ( !function_exists('did_action') || did_action( 'rightnow_end' ) ) // We already displayed this info in the "Right Now" section
881
+ return;
882
+ if ( !$count = get_option('akismet_spam_count') )
883
+ return;
884
+ $path = plugin_basename(__FILE__);
885
+ echo '<h3>'.__('Spam').'</h3>';
886
+ global $submenu;
887
+ if ( isset( $submenu['edit-comments.php'] ) )
888
+ $link = 'edit-comments.php';
889
+ else
890
+ $link = 'edit.php';
891
+ 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>';
892
+ }
893
+
894
+ add_action('activity_box_end', 'akismet_stats');
895
+
896
+ // WP 2.5+
897
+ function akismet_rightnow() {
898
+ global $submenu, $wp_db_version;
899
+
900
+ if ( 8645 < $wp_db_version ) // 2.7
901
+ $link = 'edit-comments.php?comment_status=spam';
902
+ elseif ( isset( $submenu['edit-comments.php'] ) )
903
+ $link = 'edit-comments.php?page=akismet-admin';
904
+ else
905
+ $link = 'edit.php?page=akismet-admin';
906
+
907
+ if ( $count = get_option('akismet_spam_count') ) {
908
+ $intro = sprintf( __ngettext(
909
+ '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comment already,',
910
+ '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comments already,',
911
+ $count
912
+ ), 'http://akismet.com/', number_format_i18n( $count ) );
913
+ } else {
914
+ $intro = sprintf( __('<a href="%1$s">Akismet</a> blocks spam from getting to your blog,'), 'http://akismet.com/' );
915
+ }
916
+
917
+ if ( $queue_count = akismet_spam_count() ) {
918
+ $queue_text = sprintf( __ngettext(
919
+ 'and there\'s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
920
+ 'and there are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
921
+ $queue_count
922
+ ), number_format_i18n( $queue_count ), clean_url($link) );
923
+ } else {
924
+ $queue_text = sprintf( __( "but there's nothing in your <a href='%1\$s'>spam queue</a> at the moment." ), clean_url($link) );
925
+ }
926
+
927
+ $text = sprintf( _c( '%1$s %2$s|akismet_rightnow' ), $intro, $queue_text );
928
+
929
+ echo "<p class='akismet-right-now'>$text</p>\n";
930
+ }
931
+
932
+ add_action('rightnow_end', 'akismet_rightnow');
933
+
934
+ // For WP <= 2.3.x
935
+ if ( 'moderation.php' == $pagenow ) {
936
+ function akismet_recheck_button( $page ) {
937
+ global $submenu;
938
+ if ( isset( $submenu['edit-comments.php'] ) )
939
+ $link = 'edit-comments.php';
940
+ else
941
+ $link = 'edit.php';
942
+ $button = "<a href='$link?page=akismet-admin&amp;recheckqueue=true&amp;noheader=true' style='display: block; width: 100px; position: absolute; right: 7%; padding: 5px; font-size: 14px; text-decoration: underline; background: #fff; border: 1px solid #ccc;'>" . __('Recheck Queue for Spam') . "</a>";
943
+ $page = str_replace( '<div class="wrap">', '<div class="wrap">' . $button, $page );
944
+ return $page;
945
+ }
946
+
947
+ if ( $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'" ) )
948
+ ob_start( 'akismet_recheck_button' );
949
+ }
950
+
951
+ // For WP >= 2.5
952
+ function akismet_check_for_spam_button($comment_status) {
953
+ if ( 'approved' == $comment_status )
954
+ return;
955
+ if ( function_exists('plugins_url') )
956
+ $link = 'admin.php?action=akismet_recheck_queue';
957
+ else
958
+ $link = 'edit-comments.php?page=akismet-admin&amp;recheckqueue=true&amp;noheader=true';
959
+ echo "</div><div class='alignleft'><a class='button-secondary checkforspam' href='$link'>" . __('Check for Spam') . "</a>";
960
+ }
961
+ add_action('manage_comments_nav', 'akismet_check_for_spam_button');
962
+
963
+ function akismet_recheck_queue() {
964
+ global $wpdb, $akismet_api_host, $akismet_api_port;
965
+
966
+ if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) )
967
+ return;
968
+
969
+ $moderation = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0'", ARRAY_A );
970
+ foreach ( (array) $moderation as $c ) {
971
+ $c['user_ip'] = $c['comment_author_IP'];
972
+ $c['user_agent'] = $c['comment_agent'];
973
+ $c['referrer'] = '';
974
+ $c['blog'] = get_option('home');
975
+ $c['blog_lang'] = get_locale();
976
+ $c['blog_charset'] = get_option('blog_charset');
977
+ $c['permalink'] = get_permalink($c['comment_post_ID']);
978
+ $id = (int) $c['comment_ID'];
979
+
980
+ $query_string = '';
981
+ foreach ( $c as $key => $data )
982
+ $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
983
+
984
+ $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
985
+ if ( 'true' == $response[1] ) {
986
+ $wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'spam' WHERE comment_ID = $id" );
987
+ }
988
+ }
989
+ wp_redirect( $_SERVER['HTTP_REFERER'] );
990
+ exit;
991
+ }
992
+
993
+ add_action('admin_action_akismet_recheck_queue', 'akismet_recheck_queue');
994
+
995
+ function akismet_check_db_comment( $id ) {
996
+ global $wpdb, $akismet_api_host, $akismet_api_port;
997
+
998
+ $id = (int) $id;
999
+ $c = $wpdb->get_row( "SELECT * FROM $wpdb->comments WHERE comment_ID = '$id'", ARRAY_A );
1000
+ if ( !$c )
1001
+ return;
1002
+
1003
+ $c['user_ip'] = $c['comment_author_IP'];
1004
+ $c['user_agent'] = $c['comment_agent'];
1005
+ $c['referrer'] = '';
1006
+ $c['blog'] = get_option('home');
1007
+ $c['blog_lang'] = get_locale();
1008
+ $c['blog_charset'] = get_option('blog_charset');
1009
+ $c['permalink'] = get_permalink($c['comment_post_ID']);
1010
+ $id = $c['comment_ID'];
1011
+
1012
+ $query_string = '';
1013
+ foreach ( $c as $key => $data )
1014
+ $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
1015
+
1016
+ $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
1017
+ return $response[1];
1018
+ }
1019
+
1020
+ // This option causes tons of FPs, was removed in 2.1
1021
+ function akismet_kill_proxy_check( $option ) { return 0; }
1022
+ add_filter('option_open_proxy_check', 'akismet_kill_proxy_check');
1023
+
1024
+ // Widget stuff
1025
+ function widget_akismet_register() {
1026
+ if ( function_exists('register_sidebar_widget') ) :
1027
+ function widget_akismet($args) {
1028
+ extract($args);
1029
+ $options = get_option('widget_akismet');
1030
+ $count = number_format_i18n(get_option('akismet_spam_count'));
1031
+ ?>
1032
+ <?php echo $before_widget; ?>
1033
+ <?php echo $before_title . $options['title'] . $after_title; ?>
1034
+ <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' ), '<div id="akismet1"><span id="akismetcount">' . $count . '</span>', '<span id="akismetsc">', '</span></div>', '<div id="akismet2"><span id="akismetbb">', '</span>', '<span id="akismeta">', '</span></div>' ); ?></a></div></div>
1035
+ <?php echo $after_widget; ?>
1036
+ <?php
1037
+ }
1038
+
1039
+ function widget_akismet_style() {
1040
+ ?>
1041
+ <style type="text/css">
1042
+ #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
1043
+ #aka:hover{border:none;text-decoration:none}
1044
+ #aka:hover #akismet1{display:none}
1045
+ #aka:hover #akismet2,#akismet1{display:block}
1046
+ #akismet2{display:none;padding-top:2px}
1047
+ #akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
1048
+ #akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
1049
+ #akismetwrap #akismetstats{background:url(<?php echo get_option('siteurl'); ?>/wp-content/plugins/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}
1050
+ </style>
1051
+ <?php
1052
+ }
1053
+
1054
+ function widget_akismet_control() {
1055
+ $options = $newoptions = get_option('widget_akismet');
1056
+ if ( $_POST["akismet-submit"] ) {
1057
+ $newoptions['title'] = strip_tags(stripslashes($_POST["akismet-title"]));
1058
+ if ( empty($newoptions['title']) ) $newoptions['title'] = 'Spam Blocked';
1059
+ }
1060
+ if ( $options != $newoptions ) {
1061
+ $options = $newoptions;
1062
+ update_option('widget_akismet', $options);
1063
+ }
1064
+ $title = htmlspecialchars($options['title'], ENT_QUOTES);
1065
+ ?>
1066
+ <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>
1067
+ <input type="hidden" id="akismet-submit" name="akismet-submit" value="1" />
1068
+ <?php
1069
+ }
1070
+
1071
+ register_sidebar_widget('Akismet', 'widget_akismet', null, 'akismet');
1072
+ register_widget_control('Akismet', 'widget_akismet_control', null, 75, 'akismet');
1073
+ if ( is_active_widget('widget_akismet') )
1074
+ add_action('wp_head', 'widget_akismet_style');
1075
+ endif;
1076
+ }
1077
+
1078
+ add_action('init', 'widget_akismet_register');
1079
+
1080
+ // Counter for non-widget users
1081
+ function akismet_counter() {
1082
+ ?>
1083
+ <style type="text/css">
1084
+ #akismetwrap #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
1085
+ #aka:hover{border:none;text-decoration:none}
1086
+ #aka:hover #akismet1{display:none}
1087
+ #aka:hover #akismet2,#akismet1{display:block}
1088
+ #akismet2{display:none;padding-top:2px}
1089
+ #akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
1090
+ #akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
1091
+ #akismetwrap #akismetstats{background:url(<?php echo get_option('siteurl'); ?>/wp-content/plugins/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}
1092
+ </style>
1093
+ <?php
1094
+ $count = number_format_i18n(get_option('akismet_spam_count'));
1095
+ ?>
1096
+ <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>
1097
+ <?php
1098
+ }
1099
+
1100
+ ?>
readme.txt ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Akismet ===
2
+ Contributors: matt, ryan, andy, mdawaffe
3
+ Tags: akismet, comments, spam
4
+
5
+ Akismet checks your comments against the Akismet web service to see if they look like spam or not.
6
+
7
+ == Description ==
8
+
9
+ Akismet checks your comments against the Akismet web service to see if they look like spam or not and lets you
10
+ review the spam it catches under your blog's "Comments" admin screen.
11
+
12
+ Want to show off how much spam Akismet has caught for you? Just put `<?php akismet_counter(); ?>` in your template.
13
+
14
+ See also: [WP Stats plugin](http://wordpress.org/extend/plugins/stats/).
15
+
16
+ PS: You'll need a [WordPress.com API key](http://wordpress.com/api-keys/) to use it.
17
+
18
+ == Installation ==
19
+
20
+ Upload the Akismet plugin to your blog, Activate it, then enter your [WordPress.com API key](http://wordpress.com/api-keys/).
21
+
22
+ 1, 2, 3: You're done!