PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/edit-comments.php

https://github.com/firebelly/Radio-Arte-Wordpress
PHP | 383 lines | 309 code | 60 blank | 14 comment | 79 complexity | 1c031faaa7db80fb0bdf16eeab84219b MD5 | raw file
  1. <?php
  2. /**
  3. * Edit Comments Administration Panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('admin.php');
  10. wp_enqueue_script('admin-comments');
  11. enqueue_comment_hotkeys_js();
  12. $post_id = isset($_REQUEST['p']) ? (int) $_REQUEST['p'] : 0;
  13. if ( ( isset( $_REQUEST['delete_all_spam'] ) || isset( $_REQUEST['delete_all_spam2'] ) ) && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
  14. check_admin_referer('bulk-spam-delete', '_spam_nonce');
  15. $delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] );
  16. if ( current_user_can('moderate_comments')) {
  17. $deleted_spam = $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam' AND '$delete_time' > comment_date_gmt" );
  18. } else {
  19. $deleted_spam = 0;
  20. }
  21. $redirect_to = 'edit-comments.php?comment_status=spam&deleted=' . (int) $deleted_spam;
  22. if ( $post_id )
  23. $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
  24. wp_redirect( $redirect_to );
  25. } elseif ( isset($_REQUEST['delete_comments']) && isset($_REQUEST['action']) && ( -1 != $_REQUEST['action'] || -1 != $_REQUEST['action2'] ) ) {
  26. check_admin_referer('bulk-comments');
  27. $doaction = ( -1 != $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2'];
  28. $deleted = $approved = $unapproved = $spammed = 0;
  29. foreach ( (array) $_REQUEST['delete_comments'] as $comment_id) : // Check the permissions on each
  30. $comment_id = (int) $comment_id;
  31. $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) );
  32. if ( !current_user_can('edit_post', $_post_id) )
  33. continue;
  34. switch( $doaction ) {
  35. case 'markspam' :
  36. wp_set_comment_status($comment_id, 'spam');
  37. $spammed++;
  38. break;
  39. case 'delete' :
  40. wp_set_comment_status($comment_id, 'delete');
  41. $deleted++;
  42. break;
  43. case 'approve' :
  44. wp_set_comment_status($comment_id, 'approve');
  45. $approved++;
  46. break;
  47. case 'unapprove' :
  48. wp_set_comment_status($comment_id, 'hold');
  49. $unapproved++;
  50. break;
  51. }
  52. endforeach;
  53. $redirect_to = 'edit-comments.php?deleted=' . $deleted . '&approved=' . $approved . '&spam=' . $spammed . '&unapproved=' . $unapproved;
  54. if ( $post_id )
  55. $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
  56. if ( isset($_REQUEST['apage']) )
  57. $redirect_to = add_query_arg( 'apage', absint($_REQUEST['apage']), $redirect_to );
  58. if ( !empty($_REQUEST['mode']) )
  59. $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
  60. if ( !empty($_REQUEST['comment_status']) )
  61. $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
  62. if ( !empty($_REQUEST['s']) )
  63. $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
  64. wp_redirect( $redirect_to );
  65. } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
  66. wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
  67. exit;
  68. }
  69. if ( $post_id )
  70. $title = sprintf(__('Edit Comments on &#8220;%s&#8221;'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
  71. else
  72. $title = __('Edit Comments');
  73. require_once('admin-header.php');
  74. $mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']);
  75. $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
  76. if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam')) )
  77. $comment_status = 'all';
  78. $comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : '';
  79. $search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
  80. $search = esc_attr( $search_dirty ); ?>
  81. <div class="wrap">
  82. <?php screen_icon(); ?>
  83. <h2><?php echo esc_html( $title );
  84. if ( isset($_GET['s']) && $_GET['s'] )
  85. printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( stripslashes( $_GET['s'] ) ), 50 ) ) . '</span>' ); ?>
  86. </h2>
  87. <?php
  88. if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) {
  89. $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
  90. $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
  91. $spam = isset( $_GET['spam'] ) ? (int) $_GET['spam'] : 0;
  92. if ( $approved > 0 || $deleted > 0 || $spam > 0 ) {
  93. echo '<div id="moderated" class="updated fade"><p>';
  94. if ( $approved > 0 ) {
  95. printf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
  96. echo '<br />';
  97. }
  98. if ( $deleted > 0 ) {
  99. printf( _n( '%s comment deleted', '%s comments deleted', $deleted ), $deleted );
  100. echo '<br />';
  101. }
  102. if ( $spam > 0 ) {
  103. printf( _n( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
  104. echo '<br />';
  105. }
  106. echo '</p></div>';
  107. }
  108. }
  109. ?>
  110. <form id="comments-form" action="" method="get">
  111. <ul class="subsubsub">
  112. <?php
  113. $status_links = array();
  114. $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
  115. //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
  116. //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
  117. $stati = array(
  118. 'all' => _n_noop('All', 'All'), // singular not used
  119. 'moderated' => _n_noop('Pending (<span class="pending-count">%s</span>)', 'Pending (<span class="pending-count">%s</span>)'),
  120. 'approved' => _n_noop('Approved', 'Approved'), // singular not used
  121. 'spam' => _n_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)')
  122. );
  123. $link = 'edit-comments.php';
  124. if ( !empty($comment_type) && 'all' != $comment_type )
  125. $link = add_query_arg( 'comment_type', $comment_type, $link );
  126. foreach ( $stati as $status => $label ) {
  127. $class = '';
  128. if ( $status == $comment_status )
  129. $class = ' class="current"';
  130. if ( !isset( $num_comments->$status ) )
  131. $num_comments->$status = 10;
  132. $link = add_query_arg( 'comment_status', $status, $link );
  133. if ( $post_id )
  134. $link = add_query_arg( 'p', absint( $post_id ), $link );
  135. /*
  136. // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
  137. if ( !empty( $_GET['s'] ) )
  138. $link = add_query_arg( 's', esc_attr( stripslashes( $_GET['s'] ) ), $link );
  139. */
  140. $status_links[] = "<li class='$status'><a href='$link'$class>" . sprintf(
  141. _n( $label[0], $label[1], $num_comments->$status ),
  142. number_format_i18n( $num_comments->$status )
  143. ) . '</a>';
  144. }
  145. $status_links = apply_filters( 'comment_status_links', $status_links );
  146. echo implode( " |</li>\n", $status_links) . '</li>';
  147. unset($status_links);
  148. ?>
  149. </ul>
  150. <p class="search-box">
  151. <label class="screen-reader-text" for="comment-search-input"><?php _e( 'Search Comments' ); ?>:</label>
  152. <input type="text" id="comment-search-input" name="s" value="<?php _admin_search_query(); ?>" />
  153. <input type="submit" value="<?php esc_attr_e( 'Search Comments' ); ?>" class="button" />
  154. </p>
  155. <?php
  156. $comments_per_page = get_user_option('edit_comments_per_page');
  157. if ( empty($comments_per_page) )
  158. $comments_per_page = 20;
  159. $comments_per_page = apply_filters('comments_per_page', $comments_per_page, $comment_status);
  160. if ( isset( $_GET['apage'] ) )
  161. $page = abs( (int) $_GET['apage'] );
  162. else
  163. $page = 1;
  164. $start = $offset = ( $page - 1 ) * $comments_per_page;
  165. list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 8, $post_id, $comment_type ); // Grab a few extra
  166. $_comment_post_ids = array();
  167. foreach ( $_comments as $_c ) {
  168. $_comment_post_ids[] = $_c->comment_post_ID;
  169. }
  170. $_comment_pending_count_temp = (array) get_pending_comments_num($_comment_post_ids);
  171. foreach ( (array) $_comment_post_ids as $_cpid )
  172. $_comment_pending_count[$_cpid] = isset( $_comment_pending_count_temp[$_cpid] ) ? $_comment_pending_count_temp[$_cpid] : 0;
  173. if ( empty($_comment_pending_count) )
  174. $_comment_pending_count = array();
  175. $comments = array_slice($_comments, 0, $comments_per_page);
  176. $extra_comments = array_slice($_comments, $comments_per_page);
  177. $page_links = paginate_links( array(
  178. 'base' => add_query_arg( 'apage', '%#%' ),
  179. 'format' => '',
  180. 'prev_text' => __('&laquo;'),
  181. 'next_text' => __('&raquo;'),
  182. 'total' => ceil($total / $comments_per_page),
  183. 'current' => $page
  184. ));
  185. ?>
  186. <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
  187. <?php if ( $post_id ) : ?>
  188. <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
  189. <?php endif; ?>
  190. <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
  191. <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
  192. <div class="tablenav">
  193. <?php if ( $page_links ) : ?>
  194. <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
  195. number_format_i18n( $start + 1 ),
  196. number_format_i18n( min( $page * $comments_per_page, $total ) ),
  197. '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
  198. $page_links
  199. ); echo $page_links_text; ?></div>
  200. <input type="hidden" name="_total" value="<?php echo esc_attr($total); ?>" />
  201. <input type="hidden" name="_per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
  202. <input type="hidden" name="_page" value="<?php echo esc_attr($page); ?>" />
  203. <?php endif; ?>
  204. <div class="alignleft actions">
  205. <select name="action">
  206. <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
  207. <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
  208. <option value="unapprove"><?php _e('Unapprove'); ?></option>
  209. <?php endif; ?>
  210. <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
  211. <option value="approve"><?php _e('Approve'); ?></option>
  212. <?php endif; ?>
  213. <?php if ( 'spam' != $comment_status ): ?>
  214. <option value="markspam"><?php _e('Mark as Spam'); ?></option>
  215. <?php endif; ?>
  216. <option value="delete"><?php _e('Delete'); ?></option>
  217. </select>
  218. <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
  219. <?php wp_nonce_field('bulk-comments'); ?>
  220. <select name="comment_type">
  221. <option value="all"><?php _e('Show all comment types'); ?></option>
  222. <?php
  223. $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
  224. 'comment' => __('Comments'),
  225. 'pings' => __('Pings'),
  226. ) );
  227. foreach ( $comment_types as $type => $label ) {
  228. echo " <option value='" . esc_attr($type) . "'";
  229. selected( $comment_type, $type );
  230. echo ">$label</option>\n";
  231. }
  232. ?>
  233. </select>
  234. <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
  235. <?php if ( isset($_GET['apage']) ) { ?>
  236. <input type="hidden" name="apage" value="<?php echo esc_attr( absint( $_GET['apage'] ) ); ?>" />
  237. <?php }
  238. if ( 'spam' == $comment_status ) {
  239. wp_nonce_field('bulk-spam-delete', '_spam_nonce');
  240. if ( current_user_can ('moderate_comments')) { ?>
  241. <input type="submit" name="delete_all_spam" value="<?php esc_attr_e('Delete All Spam'); ?>" class="button-secondary apply" />
  242. <?php }
  243. } ?>
  244. <?php do_action('manage_comments_nav', $comment_status); ?>
  245. </div>
  246. <br class="clear" />
  247. </div>
  248. <div class="clear"></div>
  249. <?php if ( $comments ) { ?>
  250. <table class="widefat comments fixed" cellspacing="0">
  251. <thead>
  252. <tr>
  253. <?php print_column_headers('edit-comments'); ?>
  254. </tr>
  255. </thead>
  256. <tfoot>
  257. <tr>
  258. <?php print_column_headers('edit-comments', false); ?>
  259. </tr>
  260. </tfoot>
  261. <tbody id="the-comment-list" class="list:comment">
  262. <?php
  263. foreach ($comments as $comment)
  264. _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
  265. ?>
  266. </tbody>
  267. <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
  268. <?php
  269. foreach ($extra_comments as $comment)
  270. _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
  271. ?>
  272. </tbody>
  273. </table>
  274. <div class="tablenav">
  275. <?php
  276. if ( $page_links )
  277. echo "<div class='tablenav-pages'>$page_links_text</div>";
  278. ?>
  279. <div class="alignleft actions">
  280. <select name="action2">
  281. <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
  282. <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
  283. <option value="unapprove"><?php _e('Unapprove'); ?></option>
  284. <?php endif; ?>
  285. <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
  286. <option value="approve"><?php _e('Approve'); ?></option>
  287. <?php endif; ?>
  288. <?php if ( 'spam' != $comment_status ): ?>
  289. <option value="markspam"><?php _e('Mark as Spam'); ?></option>
  290. <?php endif; ?>
  291. <option value="delete"><?php _e('Delete'); ?></option>
  292. </select>
  293. <input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
  294. <?php if ( 'spam' == $comment_status ) { ?>
  295. <input type="submit" name="delete_all_spam2" value="<?php esc_attr_e('Delete All Spam'); ?>" class="button-secondary apply" />
  296. <?php } ?>
  297. <?php do_action('manage_comments_nav', $comment_status); ?>
  298. </div>
  299. <br class="clear" />
  300. </div>
  301. </form>
  302. <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
  303. <input type="hidden" name="s" value="<?php echo esc_attr($search); ?>" />
  304. <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
  305. <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
  306. <input type="hidden" name="page" value="<?php echo esc_attr($page); ?>" />
  307. <input type="hidden" name="per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
  308. <input type="hidden" name="p" value="<?php echo esc_attr( $post_id ); ?>" />
  309. <input type="hidden" name="comment_type" value="<?php echo esc_attr( $comment_type ); ?>" />
  310. <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
  311. </form>
  312. <div id="ajax-response"></div>
  313. <?php } elseif ( 'moderated' == $comment_status ) { ?>
  314. <p><?php _e('No comments awaiting moderation&hellip; yet.') ?></p>
  315. </form>
  316. <?php } else { ?>
  317. <p><?php _e('No results found.') ?></p>
  318. </form>
  319. <?php } ?>
  320. </div>
  321. <?php
  322. wp_comment_reply('-1', true, 'detail');
  323. include('admin-footer.php'); ?>