source: trunk/www.guidonia.net/wp/wp-content/plugins/akismet/akismet.php@ 44

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