Projects : mp-wp : mp-wp_genesis

mp-wp/wp-admin/edit-comments.php

Dir - Raw

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