Wordpress 2.0.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.php';
6 $list_js = true;
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 </script>
28 <div class="wrap">
29 <h2><?php _e('Comments'); ?></h2>
30 <form name="searchform" action="" method="get"> 
31   <fieldset> 
32   <legend><?php _e('Show Comments That Contain...') ?></legend> 
33   <input type="text" name="s" value="<?php if (isset($_GET['s'])) echo wp_specialchars($_GET['s'], 1); ?>" size="17" /> 
34   <input type="submit" name="submit" value="<?php _e('Search') ?>"  />  
35   <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
36   <?php _e('(Searches within comment text, e-mail, URI, and IP address.)') ?>
37   </fieldset> 
38 </form>
39 <p><a href="?mode=view"><?php _e('View Mode') ?></a> | <a href="?mode=edit"><?php _e('Mass Edit Mode') ?></a></p>
40 <?php
41 if ( !empty( $_POST['delete_comments'] ) ) :
42         $i = 0;
43         foreach ($_POST['delete_comments'] as $comment) : // Check the permissions on each
44                 $comment = (int) $comment;
45                 $post_id = $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment");
46                 $authordata = get_userdata( $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id") );
47                 if ( current_user_can('edit_post', $post_id) ) :
48                         wp_set_comment_status($comment, "delete");
49                         ++$i;
50                 endif;
51         endforeach;
52         echo "<div class='wrap'><p>" . sprintf(__('%s comments deleted.'), $i) . "</p></div>";
53 endif;
54
55 if (isset($_GET['s'])) {
56         $s = $wpdb->escape($_GET['s']);
57         $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments  WHERE
58                 (comment_author LIKE '%$s%' OR
59                 comment_author_email LIKE '%$s%' OR
60                 comment_author_url LIKE ('%$s%') OR
61                 comment_author_IP LIKE ('%$s%') OR
62                 comment_content LIKE ('%$s%') ) AND
63                 comment_approved != 'spam'
64                 ORDER BY comment_date DESC");
65 } else {
66         if ( isset($_GET['offset']) )
67                 $offset = (int) $_GET['offset'] * 20;
68         else
69                 $offset = 0;
70
71         $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $offset,20");
72 }
73 if ('view' == $mode) {
74         if ($comments) {
75                 if ($offset)
76                         $start = " start='$offset'";
77                 else
78                         $start = '';
79
80                 echo "<ol id='the-list' class='commentlist' $start>";
81                 $i = 0;
82                 foreach ($comments as $comment) {
83                 ++$i; $class = '';
84                 $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
85                         $comment_status = wp_get_comment_status($comment->comment_ID);
86                         if ('unapproved' == $comment_status) 
87                                 $class .= ' unapproved';
88                         if ($i % 2)
89                                 $class .= ' alternate';
90                         echo "<li id='comment-$comment->comment_ID' class='$class'>";
91 ?>              
92         <p><strong><?php _e('Name:') ?></strong> <?php comment_author() ?> <?php if ($comment->comment_author_email) { ?>| <strong><?php _e('E-mail:') ?></strong> <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url ) { ?> | <strong><?php _e('URI:') ?></strong> <?php comment_author_url_link() ?> <?php } ?>| <strong><?php _e('IP:') ?></strong> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
93                 
94                 <?php comment_text() ?>
95
96         <p><?php _e('Posted'); echo ' '; comment_date('M j, g:i A');  
97                         if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
98                                 echo " | <a href=\"post.php?action=editcomment&amp;comment=".$comment->comment_ID."\">" . __('Edit Comment') . "</a>";
99                                 echo " | <a href=\"post.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."), wp_specialchars( $comment->comment_author, 1 ))  . "' );\">" . __('Delete Comment') . "</a> &#8212; ";
100                         } // end if any comments to show
101                         // Get post title
102                         if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
103                                 $post_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID = $comment->comment_post_ID");
104                                 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
105                                 ?> <a href="post.php?action=edit&amp;post=<?php echo $comment->comment_post_ID; ?>"><?php printf(__('Edit Post &#8220;%s&#8221;'), stripslashes($post_title)); ?></a>
106                                 <?php } ?>
107                          | <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php _e('View Post') ?></a></p>
108                 </li>
109
110 <?php } // end foreach ?>
111 </ol>
112
113 <div id="ajax-response"></div>
114
115 <?php
116         } else {
117
118                 ?>
119                 <p>
120         <strong><?php _e('No comments found.') ?></strong></p>
121                 
122                 <?php
123         } // end if ($comments)
124 } elseif ('edit' == $mode) {
125
126         if ($comments) {
127                 echo '<form name="deletecomments" id="deletecomments" action="" method="post"> 
128                 <table width="100%" cellpadding="3" cellspacing="3">
129   <tr>
130     <th scope="col">*</th>
131     <th scope="col">' .  __('Name') . '</th>
132     <th scope="col">' .  __('E-mail') . '</th>
133     <th scope="col">' . __('IP') . '</th>
134     <th scope="col">' . __('Comment Excerpt') . '</th>
135         <th scope="col" colspan="3">' .  __('Actions') . '</th>
136   </tr>';
137                 foreach ($comments as $comment) {
138                 $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
139                 $class = ('alternate' == $class) ? '' : 'alternate';
140 ?>
141   <tr class='<?php echo $class; ?>'>
142     <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>
143     <td><?php comment_author_link() ?></td>
144     <td><?php comment_author_email_link() ?></td>
145     <td><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></td>
146     <td><?php comment_excerpt(); ?></td>
147     <td><a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a></td>
148     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
149         echo "<a href='post.php?action=editcomment&amp;comment=$comment->comment_ID' class='edit'>" .  __('Edit') . "</a>"; } ?></td>
150     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
151             echo "<a href=\"post.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return confirm('" . sprintf(__("You are about to delete this comment by \'%s\'\\n  \'Cancel\' to stop, \'OK\' to delete."), $comment->comment_author) . "')\"    class='delete'>" . __('Delete') . "</a>"; } ?></td>
152   </tr>
153                 <?php 
154                 } // end foreach
155         ?></table>
156     <p><a href="javascript:;" onclick="checkAll(document.getElementById('deletecomments')); return false; "><?php _e('Invert Checkbox Selection') ?></a></p>
157             <p class="submit"><input type="submit" name="Submit" value="<?php _e('Delete Checked Comments') ?> &raquo;" onclick="return confirm('<?php _e("You are about to delete these comments permanently \\n  \'Cancel\' to stop, \'OK\' to delete.") ?>')" />     </p>
158   </form>
159 <?php
160         } else {
161 ?>
162 <p>
163 <strong><?php _e('No results found.') ?></strong>
164 </p>
165 <?php
166         } // end if ($comments)
167 }
168         ?>
169
170 </div>
171
172 <?php include('admin-footer.php'); ?>