root/branches/2.1/wp-admin/edit-comments.php

Revision 5092, 12.5 kB (checked in by ryan, 2 years ago)

Big int patch for 2.1

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
8 require_once('admin-header.php');
9 if (empty($_GET['mode'])) $mode = 'view';
10 else $mode = attribute_escape($_GET['mode']);
11 ?>
12
13 <script type="text/javascript">
14 <!--
15 function checkAll(form)
16 {
17     for (i = 0, n = form.elements.length; i < n; i++) {
18         if(form.elements[i].type == "checkbox") {
19             if(form.elements[i].checked == true)
20                 form.elements[i].checked = false;
21             else
22                 form.elements[i].checked = true;
23         }
24     }
25 }
26
27 function getNumChecked(form)
28 {
29     var num = 0;
30     for (i = 0, n = form.elements.length; i < n; i++) {
31         if(form.elements[i].type == "checkbox") {
32             if(form.elements[i].checked == true)
33                 num++;
34         }
35     }
36     return num;
37 }
38 //-->
39 </script>
40 <div class="wrap">
41 <h2><?php _e('Comments'); ?></h2>
42 <form name="searchform" action="" method="get" id="editcomments">
43   <fieldset>
44   <legend><?php _e('Show Comments That Contain...') ?></legend>
45   <input type="text" name="s" value="<?php if (isset($_GET['s'])) echo attribute_escape($_GET['s']); ?>" size="17" />
46   <input type="submit" name="submit" value="<?php _e('Search') ?>"  /> 
47   <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
48   <?php _e('(Searches within comment text, e-mail, URL, and IP address.)') ?>
49   </fieldset>
50 </form>
51 <p><a href="?mode=view"><?php _e('View Mode') ?></a> | <a href="?mode=edit"><?php _e('Mass Edit Mode') ?></a></p>
52 <?php
53 if ( !empty( $_POST['delete_comments'] ) ) :
54     check_admin_referer('bulk-comments');
55
56     $i = 0;
57     foreach ($_POST['delete_comments'] as $comment) : // Check the permissions on each
58         $comment = (int) $comment;
59         $post_id = (int) $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment");
60         // $authordata = get_userdata( $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id") );
61         if ( current_user_can('edit_post', $post_id) ) {
62             if ( !empty( $_POST['spam_button'] ) )
63                 wp_set_comment_status($comment, 'spam');
64             else
65                 wp_set_comment_status($comment, 'delete');
66             ++$i;
67         }
68     endforeach;
69     echo '<div style="background-color: rgb(207, 235, 247);" id="message" class="updated fade"><p>';
70     if ( !empty( $_POST['spam_button'] ) ) {
71         printf(__ngettext('%s comment marked as spam', '%s comments marked as spam.', $i), $i);
72     } else {
73         printf(__ngettext('%s comment deleted.', '%s comments deleted.', $i), $i);
74     }
75     echo '</p></div>';
76 endif;
77
78 if (isset($_GET['s'])) {
79     $s = $wpdb->escape($_GET['s']);
80     $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments  WHERE
81         (comment_author LIKE '%$s%' OR
82         comment_author_email LIKE '%$s%' OR
83         comment_author_url LIKE ('%$s%') OR
84         comment_author_IP LIKE ('%$s%') OR
85         comment_content LIKE ('%$s%') ) AND
86         comment_approved != 'spam'
87         ORDER BY comment_date DESC");
88 } else {
89     if ( isset( $_GET['apage'] ) )
90         $page = (int) $_GET['apage'];
91     else
92         $page = 1;
93     $start = $offset = ( $page - 1 ) * 20;
94
95     $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, 20" );
96     $total = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1'" );
97 }
98 ?>
99 <?php if ( $total > 20 ) {
100 $total_pages = ceil( $total / 20 );
101 $r = '';
102 if ( 1 < $page ) {
103     $args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
104     $r .=  '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">&laquo; '. __('Previous Page') .'</a>' . "\n";
105 }
106 if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) {
107     for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
108         if ( $page == $page_num ) :
109             $r .=  "<span>$page_num</span>\n";
110         else :
111             $p = false;
112             if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
113                 $args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num;
114                 $r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
115                 $in = true;
116             elseif ( $in == true ) :
117                 $r .= "...\n";
118                 $in = false;
119             endif;
120         endif;
121     endfor;
122 }
123 if ( ( $page ) * 20 < $total || -1 == $total ) {
124     $args['apage'] = $page + 1;
125     $r .=  '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page') .' &raquo;</a>' . "\n";
126 }
127 echo "<p class='pagenav'>$r</p>";
128 ?>
129
130 <?php } ?>
131
132 <?php
133 if ('view' == $mode) {
134     if ($comments) {
135 ?>
136 <?php
137 $offset = $offset + 1;
138 $start = " start='$offset'";
139
140         echo "<ol id='the-comment-list' class='commentlist' $start>";
141         $i = 0;
142         foreach ($comments as $comment) {
143         ++$i; $class = '';
144         $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
145             $comment_status = wp_get_comment_status($comment->comment_ID);
146             if ('unapproved' == $comment_status)
147                 $class .= ' unapproved';
148             if ($i % 2)
149                 $class .= ' alternate';
150             echo "<li id='comment-$comment->comment_ID' class='$class'>";
151 ?>
152 <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>
153
154 <?php comment_text() ?>
155
156 <p><?php comment_date('M j, g:i A');  ?> &#8212; [
157 <?php
158 if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
159     echo " <a href='comment.php?action=editcomment&amp;c=".$comment->comment_ID."'>" __('Edit') . '</a>';
160     echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
161     if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
162         echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
163         echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
164     }
165     echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author))  . "', theCommentList );\">" . __('Spam') . "</a> ";
166 }
167 $post = get_post($comment->comment_post_ID);
168 $post_title = wp_specialchars( $post->post_title, 'double' );
169 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
170 ?>
171  | <a href="<?php echo get_permalink($comment->comment_post_ID); ?>" title="<?php echo $post_title; ?>"><?php _e('View Post') ?></a> ]</p>
172         </li>
173
174 <?php } // end foreach($comment) ?>
175 </ol>
176
177 <div id="ajax-response"></div>
178
179 <?php
180     } else { //no comments to show
181
182         ?>
183         <p>
184             <strong><?php _e('No comments found.') ?></strong></p>
185
186         <?php
187     } // end if ($comments)
188 } elseif ('edit' == $mode) {
189
190     if ($comments) {
191         echo '<form name="deletecomments" id="deletecomments" action="" method="post"> ';
192         wp_nonce_field('bulk-comments');
193         echo '<table class="widefat">
194 <thead>
195   <tr>
196     <th scope="col" style="text-align: center"><input type="checkbox" onclick="checkAll(document.getElementById(\'deletecomments\'));" /></th>
197     <th scope="col">' __('Name') . '</th>
198     <th scope="col">' __('E-mail') . '</th>
199     <th scope="col">' . __('IP') . '</th>
200     <th scope="col">' . __('Comment Excerpt') . '</th>
201     <th scope="col" colspan="3" style="text-align: center">' __('Actions') . '</th>
202   </tr>
203 </thead>';
204         foreach ($comments as $comment) {
205         $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
206         $comment_status = wp_get_comment_status($comment->comment_ID);
207         $class = ('alternate' == $class) ? '' : 'alternate';
208         $class .= ('unapproved' == $comment_status) ? ' unapproved' : '';
209 ?>
210   <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
211     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { ?><input type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /><?php } ?></td>
212     <td><?php comment_author_link() ?></td>
213     <td><?php comment_author_email_link() ?></td>
214     <td><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></td>
215     <td><?php comment_excerpt(); ?></td>
216     <td>
217         <?php if ('unapproved' == $comment_status) { ?>
218             (Unapproved)
219         <?php } else { ?>
220             <a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a>
221         <?php } ?>
222     </td>
223     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
224     echo "<a href='comment.php?action=editcomment&amp;c=$comment->comment_ID' class='edit'>" __('Edit') . "</a>"; } ?></td>
225     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
226         echo "<a href=\"comment.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;c=".$comment->comment_ID."\" onclick=\"return deleteSomething( 'comment', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to delete this comment by '%s'. \n  'Cancel' to stop, 'OK' to delete."), $comment->comment_author ))  . "', theCommentList );\" class='delete'>" . __('Delete') . "</a> ";
227         } ?></td>
228   </tr>
229         <?php
230         } // end foreach
231     ?></table>
232 <p class="submit"><input type="submit" name="delete_button" class="delete" value="<?php _e('Delete Checked Comments &raquo;') ?>" onclick="var numchecked = getNumChecked(document.getElementById('deletecomments')); if(numchecked < 1) { alert('<?php echo js_escape(__("Please select some comments to delete")); ?>'); return false } return confirm('<?php echo sprintf(js_escape(__("You are about to delete %s comments permanently \n  'Cancel' to stop, 'OK' to delete.")), "' + numchecked + '"); ?>')" />
233             <input type="submit" name="spam_button" value="<?php _e('Mark Checked Comments as Spam &raquo;') ?>" onclick="var numchecked = getNumChecked(document.getElementById('deletecomments')); if(numchecked < 1) { alert('<?php echo js_escape(__("Please select some comments to mark as spam")); ?>'); return false } return confirm('<?php echo sprintf(js_escape(__("You are about to mark %s comments as spam \n  'Cancel' to stop, 'OK' to mark as spam.")), "' + numchecked + '"); ?>')" /></p>
234   </form>
235 <div id="ajax-response"></div>
236 <?php
237     } else {
238 ?>
239 <p>
240 <strong><?php _e('No results found.') ?></strong>
241 </p>
242 <?php
243     } // end if ($comments)
244 }
245     ?>
246 <?php if ( $total > 20 ) {
247 $total_pages = ceil( $total / 20 );
248 $r = '';
249 if ( 1 < $page ) {
250     $args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
251     $r .=  '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">&laquo; '. __('Previous Page') .'</a>' . "\n";
252 }
253 if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) {
254     for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
255         if ( $page == $page_num ) :
256             $r .=  "<span>$page_num</span>\n";
257         else :
258             $p = false;
259             if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
260                 $args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num;
261                 $r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
262                 $in = true;
263             elseif ( $in == true ) :
264                 $r .= "...\n";
265                 $in = false;
266             endif;
267         endif;
268     endfor;
269 }
270 if ( ( $page ) * 20 < $total || -1 == $total ) {
271     $args['apage'] = $page + 1;
272     $r .=  '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page') .' &raquo;</a>' . "\n";
273 }
274 echo "<p class='pagenav'>$r</p>";
275 ?>
276
277 <?php } ?>
278
279 </div>
280
281 <?php include('admin-footer.php'); ?>
282
Note: See TracBrowser for help on using the browser.