|
1 <?php |
|
2 |
|
3 function akismet_spam_comments( $type = false, $page = 1, $per_page = 50 ) { |
|
4 global $wpdb; |
|
5 |
|
6 $page = (int) $page; |
|
7 if ( $page < 2 ) |
|
8 $page = 1; |
|
9 |
|
10 $per_page = (int) $per_page; |
|
11 if ( $per_page < 1 ) |
|
12 $per_page = 50; |
|
13 |
|
14 $start = ( $page - 1 ) * $per_page; |
|
15 $end = $start + $per_page; |
|
16 |
|
17 if ( $type ) { |
|
18 if ( 'comments' == $type || 'comment' == $type ) |
|
19 $type = ''; |
|
20 else |
|
21 $type = $wpdb->escape( $type ); |
|
22 return $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = 'spam' AND comment_type='$type' ORDER BY comment_date DESC LIMIT $start, $end"); |
|
23 } |
|
24 |
|
25 // All |
|
26 return $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = 'spam' ORDER BY comment_date DESC LIMIT $start, $end"); |
|
27 } |
|
28 |
|
29 // Totals for each comment type |
|
30 // returns array( type => count, ... ) |
|
31 function akismet_spam_totals() { |
|
32 global $wpdb; |
|
33 $totals = $wpdb->get_results( "SELECT comment_type, COUNT(*) AS cc FROM $wpdb->comments WHERE comment_approved = 'spam' GROUP BY comment_type" ); |
|
34 $return = array(); |
|
35 foreach ( $totals as $total ) |
|
36 $return[$total->comment_type ? $total->comment_type : 'comment'] = $total->cc; |
|
37 return $return; |
|
38 } |
|
39 |
|
40 function akismet_manage_page() { |
|
41 global $wpdb, $submenu, $wp_db_version; |
|
42 |
|
43 // WP 2.7 has its own spam management page |
|
44 if ( 8645 <= $wp_db_version ) |
|
45 return; |
|
46 |
|
47 $count = sprintf(__('Akismet Spam (%s)'), akismet_spam_count()); |
|
48 if ( isset( $submenu['edit-comments.php'] ) ) |
|
49 add_submenu_page('edit-comments.php', __('Akismet Spam'), $count, 'moderate_comments', 'akismet-admin', 'akismet_caught' ); |
|
50 elseif ( function_exists('add_management_page') ) |
|
51 add_management_page(__('Akismet Spam'), $count, 'moderate_comments', 'akismet-admin', 'akismet_caught'); |
|
52 } |
|
53 |
|
54 function akismet_caught() { |
|
55 global $wpdb, $comment, $akismet_caught, $akismet_nonce; |
|
56 |
|
57 akismet_recheck_queue(); |
|
58 if (isset($_POST['submit']) && 'recover' == $_POST['action'] && ! empty($_POST['not_spam'])) { |
|
59 check_admin_referer( $akismet_nonce ); |
|
60 if ( function_exists('current_user_can') && !current_user_can('moderate_comments') ) |
|
61 die(__('You do not have sufficient permission to moderate comments.')); |
|
62 |
|
63 $i = 0; |
|
64 foreach ($_POST['not_spam'] as $comment): |
|
65 $comment = (int) $comment; |
|
66 if ( function_exists('wp_set_comment_status') ) |
|
67 wp_set_comment_status($comment, 'approve'); |
|
68 else |
|
69 $wpdb->query("UPDATE $wpdb->comments SET comment_approved = '1' WHERE comment_ID = '$comment'"); |
|
70 akismet_submit_nonspam_comment($comment); |
|
71 ++$i; |
|
72 endforeach; |
|
73 $to = add_query_arg( 'recovered', $i, $_SERVER['HTTP_REFERER'] ); |
|
74 wp_safe_redirect( $to ); |
|
75 exit; |
|
76 } |
|
77 if ('delete' == $_POST['action']) { |
|
78 check_admin_referer( $akismet_nonce ); |
|
79 if ( function_exists('current_user_can') && !current_user_can('moderate_comments') ) |
|
80 die(__('You do not have sufficient permission to moderate comments.')); |
|
81 |
|
82 $delete_time = $wpdb->escape( $_POST['display_time'] ); |
|
83 $comment_ids = $wpdb->get_col( "SELECT comment_id FROM $wpdb->comments WHERE comment_approved = 'spam' AND '$delete_time' > comment_date_gmt" ); |
|
84 if ( !empty( $comment_ids ) ) { |
|
85 do_action( 'delete_comment', $comment_ids ); |
|
86 $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_id IN ( " . implode( ', ', $comment_ids ) . " )"); |
|
87 wp_cache_delete( 'akismet_spam_count', 'widget' ); |
|
88 } |
|
89 $to = add_query_arg( 'deleted', 'all', $_SERVER['HTTP_REFERER'] ); |
|
90 wp_safe_redirect( $to ); |
|
91 exit; |
|
92 } |
|
93 |
|
94 if ( isset( $_GET['recovered'] ) ) { |
|
95 $i = (int) $_GET['recovered']; |
|
96 echo '<div class="updated"><p>' . sprintf(__('%1$s comments recovered.'), $i) . "</p></div>"; |
|
97 } |
|
98 |
|
99 if (isset( $_GET['deleted'] ) ) |
|
100 echo '<div class="updated"><p>' . __('All spam deleted.') . '</p></div>'; |
|
101 |
|
102 if ( isset( $GLOBALS['submenu']['edit-comments.php'] ) ) |
|
103 $link = 'edit-comments.php'; |
|
104 else |
|
105 $link = 'edit.php'; |
|
106 ?> |
|
107 <style type="text/css"> |
|
108 .akismet-tabs { |
|
109 list-style: none; |
|
110 margin: 0; |
|
111 padding: 0; |
|
112 clear: both; |
|
113 border-bottom: 1px solid #ccc; |
|
114 height: 31px; |
|
115 margin-bottom: 20px; |
|
116 background: #ddd; |
|
117 border-top: 1px solid #bdbdbd; |
|
118 } |
|
119 .akismet-tabs li { |
|
120 float: left; |
|
121 margin: 5px 0 0 20px; |
|
122 } |
|
123 .akismet-tabs a { |
|
124 display: block; |
|
125 padding: 4px .5em 3px; |
|
126 border-bottom: none; |
|
127 color: #036; |
|
128 } |
|
129 .akismet-tabs .active a { |
|
130 background: #fff; |
|
131 border: 1px solid #ccc; |
|
132 border-bottom: none; |
|
133 color: #000; |
|
134 font-weight: bold; |
|
135 padding-bottom: 4px; |
|
136 } |
|
137 #akismetsearch { |
|
138 float: right; |
|
139 margin-top: -.5em; |
|
140 } |
|
141 |
|
142 #akismetsearch p { |
|
143 margin: 0; |
|
144 padding: 0; |
|
145 } |
|
146 </style> |
|
147 <div class="wrap"> |
|
148 <h2><?php _e('Caught Spam') ?></h2> |
|
149 <?php |
|
150 $count = get_option( 'akismet_spam_count' ); |
|
151 if ( $count ) { |
|
152 ?> |
|
153 <p><?php printf(__('Akismet has caught <strong>%1$s spam</strong> for you since you first installed it.'), number_format_i18n($count) ); ?></p> |
|
154 <?php |
|
155 } |
|
156 |
|
157 $spam_count = akismet_spam_count(); |
|
158 |
|
159 if ( 0 == $spam_count ) { |
|
160 echo '<p>'.__('You have no spam currently in the queue. Must be your lucky day. :)').'</p>'; |
|
161 echo '</div>'; |
|
162 } else { |
|
163 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’t sweat it.').'</p>'; |
|
164 ?> |
|
165 <?php if ( !isset( $_POST['s'] ) ) { ?> |
|
166 <form method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>"> |
|
167 <?php akismet_nonce_field($akismet_nonce) ?> |
|
168 <input type="hidden" name="action" value="delete" /> |
|
169 <?php printf(__('There are currently %1$s comments identified as spam.'), $spam_count); ?> <input type="submit" class="button delete" name="Submit" value="<?php _e('Delete all'); ?>" /> |
|
170 <input type="hidden" name="display_time" value="<?php echo current_time('mysql', 1); ?>" /> |
|
171 </form> |
|
172 <?php } ?> |
|
173 </div> |
|
174 <div class="wrap"> |
|
175 <?php if ( isset( $_POST['s'] ) ) { ?> |
|
176 <h2><?php _e('Search'); ?></h2> |
|
177 <?php } else { ?> |
|
178 <?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>'; ?> |
|
179 <?php } ?> |
|
180 <?php |
|
181 if ( isset( $_POST['s'] ) ) { |
|
182 $s = $wpdb->escape($_POST['s']); |
|
183 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE |
|
184 (comment_author LIKE '%$s%' OR |
|
185 comment_author_email LIKE '%$s%' OR |
|
186 comment_author_url LIKE ('%$s%') OR |
|
187 comment_author_IP LIKE ('%$s%') OR |
|
188 comment_content LIKE ('%$s%') ) AND |
|
189 comment_approved = 'spam' |
|
190 ORDER BY comment_date DESC"); |
|
191 } else { |
|
192 if ( isset( $_GET['apage'] ) ) |
|
193 $page = (int) $_GET['apage']; |
|
194 else |
|
195 $page = 1; |
|
196 |
|
197 if ( $page < 2 ) |
|
198 $page = 1; |
|
199 |
|
200 $current_type = false; |
|
201 if ( isset( $_GET['ctype'] ) ) |
|
202 $current_type = preg_replace( '|[^a-z]|', '', $_GET['ctype'] ); |
|
203 |
|
204 $comments = akismet_spam_comments( $current_type, $page ); |
|
205 $total = akismet_spam_count( $current_type ); |
|
206 $totals = akismet_spam_totals(); |
|
207 ?> |
|
208 <ul class="akismet-tabs"> |
|
209 <li <?php if ( !isset( $_GET['ctype'] ) ) echo ' class="active"'; ?>><a href="edit-comments.php?page=akismet-admin"><?php _e('All'); ?></a></li> |
|
210 <?php |
|
211 foreach ( $totals as $type => $type_count ) { |
|
212 if ( 'comment' == $type ) { |
|
213 $type = 'comments'; |
|
214 $show = __('Comments'); |
|
215 } else { |
|
216 $show = ucwords( $type ); |
|
217 } |
|
218 $type_count = number_format_i18n( $type_count ); |
|
219 $extra = $current_type === $type ? ' class="active"' : ''; |
|
220 echo "<li $extra><a href='edit-comments.php?page=akismet-admin&ctype=$type'>$show ($type_count)</a></li>"; |
|
221 } |
|
222 do_action( 'akismet_tabs' ); // so plugins can add more tabs easily |
|
223 ?> |
|
224 </ul> |
|
225 <?php |
|
226 } |
|
227 |
|
228 if ($comments) { |
|
229 ?> |
|
230 <form method="post" action="<?php echo attribute_escape("$link?page=akismet-admin"); ?>" id="akismetsearch"> |
|
231 <p> <input type="text" name="s" value="<?php if (isset($_POST['s'])) echo attribute_escape($_POST['s']); ?>" size="17" /> |
|
232 <input type="submit" class="button" name="submit" value="<?php echo attribute_escape(__('Search Spam »')) ?>" /> </p> |
|
233 </form> |
|
234 <?php if ( $total > 50 ) { |
|
235 $total_pages = ceil( $total / 50 ); |
|
236 $r = ''; |
|
237 if ( 1 < $page ) { |
|
238 $args['apage'] = ( 1 == $page - 1 ) ? '' : $page - 1; |
|
239 $r .= '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">'. __('« Previous Page') .'</a>' . "\n"; |
|
240 } |
|
241 if ( ( $total_pages = ceil( $total / 50 ) ) > 1 ) { |
|
242 for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) : |
|
243 if ( $page == $page_num ) : |
|
244 $r .= "<strong>$page_num</strong>\n"; |
|
245 else : |
|
246 $p = false; |
|
247 if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) : |
|
248 $args['apage'] = ( 1 == $page_num ) ? '' : $page_num; |
|
249 $r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n"; |
|
250 $in = true; |
|
251 elseif ( $in == true ) : |
|
252 $r .= "...\n"; |
|
253 $in = false; |
|
254 endif; |
|
255 endif; |
|
256 endfor; |
|
257 } |
|
258 if ( ( $page ) * 50 < $total || -1 == $total ) { |
|
259 $args['apage'] = $page + 1; |
|
260 $r .= '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page »') .'</a>' . "\n"; |
|
261 } |
|
262 echo "<p>$r</p>"; |
|
263 ?> |
|
264 |
|
265 <?php } ?> |
|
266 <form style="clear: both;" method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>"> |
|
267 <?php akismet_nonce_field($akismet_nonce) ?> |
|
268 <input type="hidden" name="action" value="recover" /> |
|
269 <ul id="spam-list" class="commentlist" style="list-style: none; margin: 0; padding: 0;"> |
|
270 <?php |
|
271 $i = 0; |
|
272 foreach($comments as $comment) { |
|
273 $i++; |
|
274 $comment_date = mysql2date(get_option("date_format") . " @ " . get_option("time_format"), $comment->comment_date); |
|
275 $post = get_post($comment->comment_post_ID); |
|
276 $post_title = $post->post_title; |
|
277 if ($i % 2) $class = 'class="alternate"'; |
|
278 else $class = ''; |
|
279 echo "\n\t<li id='comment-$comment->comment_ID' $class>"; |
|
280 ?> |
|
281 |
|
282 <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> |
|
283 |
|
284 <?php comment_text() ?> |
|
285 |
|
286 <p><label for="spam-<?php echo $comment->comment_ID; ?>"> |
|
287 <input type="checkbox" id="spam-<?php echo $comment->comment_ID; ?>" name="not_spam[]" value="<?php echo $comment->comment_ID; ?>" /> |
|
288 <?php _e('Not Spam') ?></label> — <?php comment_date('M j, g:i A'); ?> — [ |
|
289 <?php |
|
290 $post = get_post($comment->comment_post_ID); |
|
291 $post_title = wp_specialchars( $post->post_title, 'double' ); |
|
292 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title; |
|
293 ?> |
|
294 <a href="<?php echo get_permalink($comment->comment_post_ID); ?>" title="<?php echo $post_title; ?>"><?php _e('View Post') ?></a> ] </p> |
|
295 |
|
296 |
|
297 <?php |
|
298 } |
|
299 ?> |
|
300 </ul> |
|
301 <?php if ( $total > 50 ) { |
|
302 $total_pages = ceil( $total / 50 ); |
|
303 $r = ''; |
|
304 if ( 1 < $page ) { |
|
305 $args['apage'] = ( 1 == $page - 1 ) ? '' : $page - 1; |
|
306 $r .= '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">'. __('« Previous Page') .'</a>' . "\n"; |
|
307 } |
|
308 if ( ( $total_pages = ceil( $total / 50 ) ) > 1 ) { |
|
309 for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) : |
|
310 if ( $page == $page_num ) : |
|
311 $r .= "<strong>$page_num</strong>\n"; |
|
312 else : |
|
313 $p = false; |
|
314 if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) : |
|
315 $args['apage'] = ( 1 == $page_num ) ? '' : $page_num; |
|
316 $r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n"; |
|
317 $in = true; |
|
318 elseif ( $in == true ) : |
|
319 $r .= "...\n"; |
|
320 $in = false; |
|
321 endif; |
|
322 endif; |
|
323 endfor; |
|
324 } |
|
325 if ( ( $page ) * 50 < $total || -1 == $total ) { |
|
326 $args['apage'] = $page + 1; |
|
327 $r .= '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page »') .'</a>' . "\n"; |
|
328 } |
|
329 echo "<p>$r</p>"; |
|
330 } |
|
331 ?> |
|
332 <p class="submit"> |
|
333 <input type="submit" name="submit" value="<?php echo attribute_escape(__('De-spam marked comments »')); ?>" /> |
|
334 </p> |
|
335 <p><?php _e('Comments you de-spam will be submitted to Akismet as mistakes so it can learn and get better.'); ?></p> |
|
336 </form> |
|
337 <?php |
|
338 } else { |
|
339 ?> |
|
340 <p><?php _e('No results found.'); ?></p> |
|
341 <?php } ?> |
|
342 |
|
343 <?php if ( !isset( $_POST['s'] ) ) { ?> |
|
344 <form method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>"> |
|
345 <?php akismet_nonce_field($akismet_nonce) ?> |
|
346 <p><input type="hidden" name="action" value="delete" /> |
|
347 <?php printf(__('There are currently %1$s comments identified as spam.'), $spam_count); ?> <input type="submit" name="Submit" class="button" value="<?php echo attribute_escape(__('Delete all')); ?>" /> |
|
348 <input type="hidden" name="display_time" value="<?php echo current_time('mysql', 1); ?>" /></p> |
|
349 </form> |
|
350 <?php } ?> |
|
351 </div> |
|
352 <?php |
|
353 } |
|
354 } |
|
355 |
|
356 add_action('admin_menu', 'akismet_manage_page'); |
|
357 |
|
358 function redirect_old_akismet_urls( ) { |
|
359 global $wp_db_version; |
|
360 $script_name = array_pop( split( '/', $_SERVER['PHP_SELF'] ) ); |
|
361 |
|
362 $page = ''; |
|
363 if ( !empty( $_GET['page'] ) ) |
|
364 $page = $_GET['page']; |
|
365 |
|
366 // 2.7 redirect for people who might have bookmarked the old page |
|
367 if ( 8204 < $wp_db_version && ( 'edit-comments.php' == $script_name || 'edit.php' == $script_name ) && 'akismet-admin' == $page ) { |
|
368 $new_url = esc_url( 'edit-comments.php?comment_status=spam' ); |
|
369 wp_safe_redirect( $new_url, 301 ); |
|
370 exit; |
|
371 } |
|
372 } |
|
373 add_action( 'admin_init', 'redirect_old_akismet_urls' ); |
|
374 |
|
375 // For WP <= 2.3.x |
|
376 global $pagenow; |
|
377 |
|
378 if ( 'moderation.php' == $pagenow ) { |
|
379 function akismet_recheck_button( $page ) { |
|
380 global $submenu; |
|
381 if ( isset( $submenu['edit-comments.php'] ) ) |
|
382 $link = 'edit-comments.php'; |
|
383 else |
|
384 $link = 'edit.php'; |
|
385 $button = "<a href='$link?page=akismet-admin&recheckqueue=true&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>"; |
|
386 $page = str_replace( '<div class="wrap">', '<div class="wrap">' . $button, $page ); |
|
387 return $page; |
|
388 } |
|
389 |
|
390 if ( $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'" ) ) |
|
391 ob_start( 'akismet_recheck_button' ); |
|
392 } |
|
393 |
|
394 // This option causes tons of FPs, was removed in 2.1 |
|
395 function akismet_kill_proxy_check( $option ) { return 0; } |
|
396 add_filter('option_open_proxy_check', 'akismet_kill_proxy_check'); |