]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/edit-comments.php
Wordpress 2.3.3-scripts
[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
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['apage'] ) )
79         $page = abs( (int) $_GET['apage'] );
80 else
81         $page = 1;
82
83 $start = $offset = ( $page - 1 ) * 20;
84
85 list($_comments, $total) = _wp_get_comment_list( isset($_GET['s']) ? $_GET['s'] : false, $start, 25 ); // Grab a few extra
86
87 $comments = array_slice($_comments, 0, 20);
88 $extra_comments = array_slice($_comments, 20);
89
90 $page_links = paginate_links( array(
91         'base' => add_query_arg( 'apage', '%#%' ),
92         'format' => '',
93         'total' => ceil($total / 20),
94         'current' => $page
95 ));
96
97 if ( $page_links )
98         echo "<p class='pagenav'>$page_links</p>";
99
100 if ('view' == $mode) {
101         if ($comments) {
102                 $offset = $offset + 1;
103                 $start = " start='$offset'";
104
105                 echo "<ol id='the-comment-list' class='commentlist' $start>\n";
106                 $i = 0;
107                 foreach ( $comments as $comment ) {
108                         get_comment( $comment ); // Cache it
109                         _wp_comment_list_item( $comment->comment_ID, ++$i );
110                 }
111                 echo "</ol>\n\n";
112
113 if ( $extra_comments ) : ?>
114 <div id="extra-comments" style="display:none">
115 <ul id="the-extra-comment-list" class="commentlist">
116 <?php
117         foreach ( $extra_comments as $comment ) {
118                 get_comment( $comment ); // Cache it
119                 _wp_comment_list_item( $comment->comment_ID, ++$i );
120         }
121 ?>
122 </ul>
123 </div>
124 <?php endif; // $extra_comments ?>
125
126 <div id="ajax-response"></div>
127
128 <?php
129         } else { //no comments to show
130
131                 ?>
132                 <p>
133                         <strong><?php _e('No comments found.') ?></strong></p>
134
135                 <?php
136         } // end if ($comments)
137 } elseif ('edit' == $mode) {
138
139         if ($comments) {
140                 echo '<form name="deletecomments" id="deletecomments" action="" method="post"> ';
141                 wp_nonce_field('bulk-comments');
142                 echo '<table class="widefat">
143 <thead>
144   <tr>
145     <th scope="col" style="text-align: center"><input type="checkbox" onclick="checkAll(document.getElementById(\'deletecomments\'));" /></th>
146     <th scope="col">' .  __('Name') . '</th>
147     <th scope="col">' .  __('E-mail') . '</th>
148     <th scope="col">' . __('IP') . '</th>
149     <th scope="col">' . __('Comment Excerpt') . '</th>
150         <th scope="col" colspan="3" style="text-align: center">' .  __('Actions') . '</th>
151   </tr>
152 </thead>';
153                 foreach ($comments as $comment) {
154                 $post = get_post($comment->comment_post_ID);
155                 $authordata = get_userdata($post->post_author);
156                 $comment_status = wp_get_comment_status($comment->comment_ID);
157                 $class = ('alternate' == $class) ? '' : 'alternate';
158                 $class .= ('unapproved' == $comment_status) ? ' unapproved' : '';
159 ?>
160   <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
161     <td style="text-align: center"><?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>
162     <td><?php comment_author_link() ?></td>
163     <td><?php comment_author_email_link() ?></td>
164     <td><a href="edit-comments.php?s=<?php comment_author_IP() ?>&amp;mode=edit"><?php comment_author_IP() ?></a></td>
165     <td><?php comment_excerpt(); ?></td>
166     <td>
167         <?php if ('unapproved' == $comment_status) {
168                 _e('Unapproved');
169         } else { ?>
170                 <a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a>
171         <?php } ?>
172     </td>
173     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
174         echo "<a href='comment.php?action=editcomment&amp;c=$comment->comment_ID' class='edit'>" .  __('Edit') . "</a>"; } ?></td>
175     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
176                 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> ";
177                 } ?></td>
178   </tr>
179                 <?php
180                 } // end foreach
181         ?></table>
182 <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 + '"); ?>')" />
183                         <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>
184   </form>
185 <div id="ajax-response"></div>
186 <?php
187         } else {
188 ?>
189 <p>
190 <strong><?php _e('No results found.') ?></strong>
191 </p>
192 <?php
193         } // end if ($comments)
194 }
195
196 if ( $page_links )
197         echo "<p class='pagenav'>$page_links</p>";
198
199 ?>
200
201 </div>
202
203 <?php include('admin-footer.php'); ?>