root/tags/2.0/wp-admin/edit-comments.php

Revision 3036, 7.6 kB (checked in by ryan, 3 years ago)

Remove redundant lines. Props johnjosephbachir. fixes #1774

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