PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/akismet/legacy.php

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