root/tags/1_0-rc2/wp-admin/edit-comments.php

Revision 626, 10.0 kB (checked in by donncha, 3 years ago)

WP Merge

  • Property svn:eol-style set to native
Line 
1 <?php
2 require_once('admin.php');
3
4 $title = __('Edit Comments');
5 $parent_file = 'edit.php';
6 wp_enqueue_script( 'admin-comments' );
7
8 require_once('admin-header.php');
9 if (empty($_GET['mode'])) $mode = 'view';
10 else $mode = wp_specialchars($_GET['mode'], 1);
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 wp_specialchars($_GET['s'], 1); ?>" 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, URI, 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 = $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(__('%s comments marked as spam.'), $i);
72     else
73         printf(__('%s comments deleted.'), $i);
74     echo '</p></div>';
75 endif;
76
77 if (isset($_GET['s'])) {
78     $s = $wpdb->escape($_GET['s']);
79     $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments  WHERE
80         (comment_author LIKE '%$s%' OR
81         comment_author_email LIKE '%$s%' OR
82         comment_author_url LIKE ('%$s%') OR
83         comment_author_IP LIKE ('%$s%') OR
84         comment_content LIKE ('%$s%') ) AND
85         comment_approved != 'spam'
86         ORDER BY comment_date DESC");
87 } else {
88     if ( isset($_GET['offset']) )
89         $offset = (int) $_GET['offset'] * 20;
90     else
91         $offset = 0;
92
93     $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $offset,20");
94 }
95 if ('view' == $mode) {
96     if ($comments) {
97         if ($offset)
98             $start = " start='$offset'";
99         else
100             $start = '';
101
102         echo "<ol id='the-comment-list' class='commentlist' $start>";
103         $i = 0;
104         foreach ($comments as $comment) {
105         ++$i; $class = '';
106         $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
107             $comment_status = wp_get_comment_status($comment->comment_ID);
108             if ('unapproved' == $comment_status)
109                 $class .= ' unapproved';
110             if ($i % 2)
111                 $class .= ' alternate';
112             echo "<li id='comment-$comment->comment_ID' class='$class'>";
113 ?>
114 <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>
115
116 <?php comment_text() ?>
117
118 <p><?php comment_date('M j, g:i A');  ?> &#8212; [
119 <?php
120 if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
121     echo " <a href='comment.php?action=editcomment&amp;comment=".$comment->comment_ID."'>" __('Edit') . '</a>';
122     echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;comment=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . sprintf(__("You are about to delete this comment by &quot;%s&quot;.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete."), js_escape($comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
123     if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
124         echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;comment=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
125         echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;comment=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
126     }
127     echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;delete_type=spam&amp;p=" . $comment->comment_post_ID . "&amp;comment=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . sprintf(__("You are about to mark as spam this comment by &quot;%s&quot;.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to mark as spam."), js_escape( $comment->comment_author))  . "', theCommentList );\">" . __('Spam') . "</a> ";
128 }
129 $post = get_post($comment->comment_post_ID);
130 $post_title = wp_specialchars( $post->post_title, 'double' );
131 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
132 ?>
133  | <a href="<?php echo get_permalink($comment->comment_post_ID); ?>" title="<?php echo $post_title; ?>"><?php _e('View Post') ?></a> ]</p>
134         </li>
135
136 <?php } // end foreach($comment) ?>
137 </ol>
138
139 <div id="ajax-response"></div>
140
141 <?php
142     } else { //no comments to show
143
144         ?>
145         <p>
146         <strong><?php _e('No comments found.') ?></strong></p>
147
148         <?php
149     } // end if ($comments)
150 } elseif ('edit' == $mode) {
151
152     if ($comments) {
153         echo '<form name="deletecomments" id="deletecomments" action="" method="post"> ';
154         wp_nonce_field('bulk-comments');
155         echo '<table class="widefat">
156 <thead>
157   <tr>
158     <th scope="col"><input type="checkbox" onclick="checkAll(document.getElementById(\'deletecomments\'));" /></th>
159     <th scope="col" style="text-align: left">' __('Name') . '</th>
160     <th scope="col" style="text-align: left">' __('E-mail') . '</th>
161     <th scope="col" style="text-align: left">' . __('IP') . '</th>
162     <th scope="col" style="text-align: left">' . __('Comment Excerpt') . '</th>
163     <th scope="col" colspan="3">' __('Actions') . '</th>
164   </tr>
165 </thead>';
166         foreach ($comments as $comment) {
167         $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
168         $comment_status = wp_get_comment_status($comment->comment_ID);
169         $class = ('alternate' == $class) ? '' : 'alternate';
170         $class .= ('unapproved' == $comment_status) ? ' unapproved' : '';
171 ?>
172   <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
173     <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>
174     <td><?php comment_author_link() ?></td>
175     <td><?php comment_author_email_link() ?></td>
176     <td><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></td>
177     <td><?php comment_excerpt(); ?></td>
178     <td>
179         <?php if ('unapproved' == $comment_status) { ?>
180             (Unapproved)
181         <?php } else { ?>
182             <a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a>
183         <?php } ?>
184     </td>
185     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
186     echo "<a href='comment.php?action=editcomment&amp;comment=$comment->comment_ID' class='edit'>" __('Edit') . "</a>"; } ?></td>
187     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
188         echo "<a href=\"comment.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return deleteSomething( 'comment', $comment->comment_ID, '" . sprintf(__("You are about to delete this comment by &quot;%s&quot;.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete."), js_escape( $comment->comment_author ))  . "', theCommentList );\" class='delete'>" . __('Delete') . "</a> ";
189         } ?></td>
190   </tr>
191         <?php
192         } // end foreach
193     ?></table>
194 <p class="submit"><input type="submit" name="delete_button" value="<?php _e('Delete Checked Comments &raquo;') ?>" onclick="var numchecked = getNumChecked(document.getElementById('deletecomments')); if(numchecked < 1) { alert('<?php _e("Please select some comments to delete"); ?>'); return false } return confirm('<?php printf(__("You are about to delete %s comments permanently \\n  \'Cancel\' to stop, \'OK\' to delete."), "' + numchecked + '"); ?>')" />
195             <input type="submit" name="spam_button" value="<?php _e('Mark Checked Comments as Spam &raquo;') ?>" onclick="return confirm('<?php _e("You are about to mark these comments as spam \\n  \'Cancel\' to stop, \'OK\' to mark as spam.") ?>')" /></p>
196   </form>
197 <div id="ajax-response"></div>
198 <?php
199     } else {
200 ?>
201 <p>
202 <strong><?php _e('No results found.') ?></strong>
203 </p>
204 <?php
205     } // end if ($comments)
206 }
207     ?>
208
209 </div>
210
211 <?php include('admin-footer.php'); ?>
212
Note: See TracBrowser for help on using the browser.