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