]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/edit-comments.php
Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-admin / edit-comments.php
1 <?php
2 require_once('admin.php');
3
4 $title = __('Edit Comments');
5 $parent_file = 'edit-comments.php';
6 wp_enqueue_script( 'admin-comments' );
7 wp_enqueue_script('admin-forms');
8
9 if ( !empty( $_REQUEST['delete_comments'] ) ) {
10         check_admin_referer('bulk-comments');
11
12         $comments_deleted = $comments_approved = $comments_unapproved = $comments_spammed = 0;
13         foreach ($_REQUEST['delete_comments'] as $comment) : // Check the permissions on each
14                 $comment = (int) $comment;
15                 $post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment) );
16                 if ( !current_user_can('edit_post', $post_id) )
17                         continue;
18                 if ( !empty( $_REQUEST['spamit'] ) ) {
19                         wp_set_comment_status($comment, 'spam');
20                         $comments_spammed++;
21                 } elseif ( !empty( $_REQUEST['deleteit'] ) ) {
22                         wp_set_comment_status($comment, 'delete');
23                         $comments_deleted++;
24                 } elseif ( !empty( $_REQUEST['approveit'] ) ) {
25                         wp_set_comment_status($comment, 'approve');
26                         $comments_approved++;
27                 } elseif ( !empty( $_REQUEST['unapproveit'] ) ) {
28                         wp_set_comment_status($comment, 'hold');
29                         $comments_unapproved++;
30                 }
31         endforeach;
32         $redirect_to = basename( __FILE__ ) . '?deleted=' . $comments_deleted . '&approved=' . $comments_approved . '&spam=' . $comments_spammed . '&unapproved=' . $comments_unapproved;
33         if ( isset($_REQUEST['apage']) )
34                 $redirect_to = add_query_arg( 'apage', absint($_REQUEST['apage']), $redirect_to );
35         if ( !empty($_REQUEST['mode']) )
36                 $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
37         if ( !empty($_REQUEST['comment_status']) )
38                 $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
39         if ( !empty($_REQUEST['s']) )
40                 $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
41         wp_redirect( $redirect_to );
42 } elseif ( !empty($_GET['_wp_http_referer']) ) {
43          wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
44          exit;
45 }
46
47 require_once('admin-header.php');
48
49 if ( empty($_GET['mode']) )
50         $mode = 'detail';
51 else
52         $mode = attribute_escape($_GET['mode']);
53
54 if ( isset($_GET['comment_status']) )
55         $comment_status = attribute_escape($_GET['comment_status']);
56 else
57         $comment_status = '';
58
59 if ( isset($_GET['s']) )
60         $search_dirty = $_GET['s'];
61 else
62         $search_dirty = '';
63 $search = attribute_escape( $search_dirty );
64 ?>
65 <?php
66 if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) {
67         $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
68         $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
69         $spam = isset( $_GET['spam'] ) ? (int) $_GET['spam'] : 0;
70
71         if ( $approved > 0 || $deleted > 0 || $spam > 0 ) {
72                 echo '<div id="moderated" class="updated fade"><p>';
73
74                 if ( $approved > 0 ) {
75                         printf( __ngettext( '%s comment approved', '%s comments approved', $approved ), $approved );
76                         echo '<br />';
77                 }
78
79                 if ( $deleted > 0 ) {
80                         printf( __ngettext( '%s comment deleted', '%s comments deleted', $deleted ), $deleted );
81                         echo '<br />';
82                 }
83
84                 if ( $spam > 0 ) {
85                         printf( __ngettext( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
86                         echo '<br />';
87                 }
88
89                 echo '</p></div>';
90         }
91 }
92 ?>
93 <div class="wrap">
94 <form id="posts-filter" action="" method="get">
95 <h2><?php _e('Manage Comments'); ?></h2>
96
97 <ul class="subsubsub">
98 <?php
99 $status_links = array();
100 $num_comments = wp_count_comments();
101 $stati = array('moderated' => sprintf(__ngettext('Awaiting Moderation (%s)', 'Awaiting Moderation (%s)', number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"), 'approved' => _c('Approved|plural'));
102 $class = ( '' === $comment_status ) ? ' class="current"' : '';
103 $status_links[] = "<li><a href=\"edit-comments.php\"$class>".__('Show All Comments')."</a>";
104 foreach ( $stati as $status => $label ) {
105         $class = '';
106
107         if ( $status == $comment_status )
108                 $class = ' class="current"';
109
110         $status_links[] = "<li><a href=\"edit-comments.php?comment_status=$status\"$class>" . $label . '</a>';
111 }
112
113 $status_links = apply_filters( 'comment_status_links', $status_links );
114
115 echo implode(' | </li>', $status_links) . '</li>';
116 unset($status_links);
117 ?>
118 </ul>
119
120 <p id="post-search">
121         <label class="hidden" for="post-search-input"><?php _e( 'Search Comments' ); ?>:</label>
122         <input type="text" id="post-search-input" name="s" value="<?php echo $search; ?>" />
123         <input type="submit" value="<?php _e( 'Search Comments' ); ?>" class="button" />
124 </p>
125
126 <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
127 <input type="hidden" name="comment_status" value="<?php echo $comment_status; ?>" />
128 </form>
129
130 <ul class="view-switch">
131         <li <?php if ( 'detail' == $mode ) echo "class='current'" ?>><a href="<?php echo clean_url(add_query_arg('mode', 'detail', $_SERVER['REQUEST_URI'])) ?>"><?php _e('Detail View') ?></a></li>
132         <li <?php if ( 'list' == $mode ) echo "class='current'" ?>><a href="<?php echo clean_url(add_query_arg('mode', 'list', $_SERVER['REQUEST_URI'])) ?>"><?php _e('List View') ?></a></li>
133 </ul>
134
135 <?php
136
137 $comments_per_page = apply_filters('comments_per_page', 20, $comment_status);
138
139 if ( isset( $_GET['apage'] ) )
140         $page = abs( (int) $_GET['apage'] );
141 else
142         $page = 1;
143
144 $start = $offset = ( $page - 1 ) * $comments_per_page;
145
146 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 5 ); // Grab a few extra
147
148 $comments = array_slice($_comments, 0, $comments_per_page);
149 $extra_comments = array_slice($_comments, $comments_per_page);
150
151 $page_links = paginate_links( array(
152         'base' => add_query_arg( 'apage', '%#%' ),
153         'format' => '',
154         'total' => ceil($total / $comments_per_page),
155         'current' => $page
156 ));
157
158 ?>
159
160 <form id="comments-form" action="" method="post">
161
162 <div class="tablenav">
163
164 <?php
165 if ( $page_links )
166         echo "<div class='tablenav-pages'>$page_links</div>";
167 ?>
168
169 <div class="alignleft">
170 <?php if ( 'approved' != $comment_status ): ?>
171 <input type="submit" value="<?php _e('Approve'); ?>" name="approveit" class="button-secondary" />
172 <?php endif; ?>
173 <input type="submit" value="<?php _e('Mark as Spam'); ?>" name="spamit" class="button-secondary" />
174 <?php if ( 'moderated' != $comment_status ): ?>
175 <input type="submit" value="<?php _e('Unapprove'); ?>" name="unapproveit" class="button-secondary" />
176 <?php endif; ?>
177 <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
178 <?php do_action('manage_comments_nav', $comment_status); ?>
179 <?php wp_nonce_field('bulk-comments'); ?>
180 <?php if ( isset($_GET['apage']) ) { ?>
181         <input type="hidden" name="apage" value="<?php echo absint( $_GET['apage'] ); ?>" />
182 <?php } ?>
183 </div>
184
185 <br class="clear" />
186
187 </div>
188
189 <br class="clear" />
190 <?php
191 if ($comments) {
192 ?>
193 <table class="widefat">
194 <thead>
195   <tr>
196     <th scope="col" class="check-column"><input type="checkbox" /></th>
197     <th scope="col"><?php _e('Comment') ?></th>
198     <th scope="col"><?php _e('Date') ?></th>
199     <th scope="col" class="action-links"><?php _e('Actions') ?></th>
200   </tr>
201 </thead>
202 <tbody id="the-comment-list" class="list:comment">
203 <?php
204         foreach ($comments as $comment)
205                 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
206 ?>
207 </tbody>
208 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
209 <?php
210         foreach ($extra_comments as $comment)
211                 _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
212 ?>
213 </tbody>
214 </table>
215
216 </form>
217
218 <form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
219         <input type="hidden" name="s" value="<?php echo $search; ?>" />
220         <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
221         <input type="hidden" name="comment_status" value="<?php echo $comment_status; ?>" />
222         <input type="hidden" name="page" value="<?php echo isset($_REQUEST['page']) ? absint( $_REQUEST['page'] ) : 1; ?>" />
223         <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
224 </form>
225
226 <div id="ajax-response"></div>
227 <?php
228 } elseif ( 'moderated' == $_GET['comment_status'] ) {
229 ?>
230 <p>
231 <?php _e('No comments awaiting moderation&hellip; yet.') ?>
232 </p>
233 <?php
234 } else  {
235 ?>
236 <p>
237 <?php _e('No results found.') ?>
238 </p>
239 <?php
240 }
241 ?>
242 <div class="tablenav">
243 <?php
244 if ( $page_links )
245         echo "<div class='tablenav-pages'>$page_links</div>";
246 ?>
247 <br class="clear" />
248 </div>
249
250 </div>
251
252 <?php include('admin-footer.php'); ?>