Wordpress 2.0.2
[autoinstalls/wordpress.git] / wp-admin / moderation.php
1 <?php
2 require_once('admin.php');
3
4 $title = __('Moderate comments');
5 $parent_file = 'edit.php';
6 $list_js = true;
7
8 $wpvarstoreset = array('action', 'item_ignored', 'item_deleted', 'item_approved', 'item_spam', 'feelinglucky');
9 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
10         $wpvar = $wpvarstoreset[$i];
11         if (!isset($$wpvar)) {
12                 if (empty($_POST["$wpvar"])) {
13                         if (empty($_GET["$wpvar"])) {
14                                 $$wpvar = '';
15                         } else {
16                                 $$wpvar = $_GET["$wpvar"];
17                         }
18                 } else {
19                         $$wpvar = $_POST["$wpvar"];
20                 }
21         }
22 }
23
24 $comment = array();
25 if (isset($_POST["comment"])) {
26         foreach ($_POST["comment"] as $k => $v) {
27                 $comment[intval($k)] = $v;
28         }
29 }
30
31 switch($action) {
32
33 case 'update':
34
35         if ( ! current_user_can('moderate_comments') )
36         die('<p>'.__('Your level is not high enough to moderate comments.').'</p>');
37
38         $item_ignored = 0;
39         $item_deleted = 0;
40         $item_approved = 0;
41         $item_spam = 0;
42
43         foreach($comment as $key => $value) {
44         if ($feelinglucky && 'later' == $value)
45                 $value = 'delete';
46             switch($value) {
47                         case 'later':
48                                 // do nothing with that comment
49                                 // wp_set_comment_status($key, "hold");
50                                 ++$item_ignored;
51                                 break;
52                         case 'delete':
53                                 wp_set_comment_status($key, 'delete');
54                                 ++$item_deleted;
55                                 break;
56                         case 'spam':
57                                 wp_set_comment_status($key, 'spam');
58                                 ++$item_spam;
59                                 break;
60                         case 'approve':
61                                 wp_set_comment_status($key, 'approve');
62                                 if ( get_settings('comments_notify') == true ) {
63                                         wp_notify_postauthor($key);
64                                 }
65                                 ++$item_approved;
66                                 break;
67             }
68         }
69
70         $file = basename(__FILE__);
71         header("Location: $file?ignored=$item_ignored&deleted=$item_deleted&approved=$item_approved&spam=$item_spam");
72         exit();
73
74 break;
75
76 default:
77
78 require_once('admin-header.php');
79
80 if ( isset($_GET['deleted']) || isset($_GET['approved']) || isset($_GET['ignored']) ) {
81         echo "<div id='moderated' class='updated fade'>\n<p>";
82         $approved = (int) $_GET['approved'];
83         $deleted  = (int) $_GET['deleted'];
84         $ignored  = (int) $_GET['ignored'];
85         $spam     = (int) $_GET['spam'];
86         if ($approved) {
87                 if ('1' == $approved) {
88                         echo __("1 comment approved") . " <br/>\n";
89                 } else {
90                  echo sprintf(__("%s comments approved <br />"), $approved) . "\n";
91                 }
92         }
93         if ($deleted) {
94                 if ('1' == $deleted) {
95                         echo __("1 comment deleted") . " <br/>\n";
96                 } else {
97                         echo sprintf(__("%s comments deleted"), $deleted) . " <br/>\n";
98                 }
99         }
100         if ($spam) {
101                 if ('1' == $spam) {
102                         echo __("1 comment marked as spam") . " <br/>\n";
103                 } else {
104                         echo sprintf(__("%s comments marked as spam"), $spam) . " <br/>\n";
105                 }
106         }
107         if ($ignored) {
108                 if ('1' == $ignored) {
109                         echo __("1 comment unchanged") . " <br/>\n";
110                 } else {
111                         echo sprintf(__("%s comments unchanged"), $ignored) . " <br/>\n";
112                 }
113         }
114         echo "</p></div>\n";
115 }
116
117 ?>
118         
119 <div class="wrap">
120
121 <?php
122 if ( current_user_can('moderate_comments') )
123         $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0'");
124 else
125         $comments = '';
126
127 if ($comments) {
128     // list all comments that are waiting for approval
129     $file = basename(__FILE__);
130 ?>
131     <h2><?php _e('Moderation Queue') ?></h2>
132     <form name="approval" action="moderation.php" method="post">
133     <input type="hidden" name="action" value="update" />
134     <ol id="the-list" class="commentlist">
135 <?php
136 $i = 0;
137     foreach($comments as $comment) {
138         ++$i;
139         $comment_date = mysql2date(get_settings("date_format") . " @ " . get_settings("time_format"), $comment->comment_date);
140         $post_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID='$comment->comment_post_ID'");
141         if ($i % 2) $class = 'class="alternate"';
142         else $class = '';
143         echo "\n\t<li id='comment-$comment->comment_ID' $class>"; 
144         ?>
145         <p><strong><?php _e('Name:') ?></strong> <?php comment_author_link() ?> <?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> | <strong><?php _e('Date:') ?></strong> <?php comment_date(); ?></p>
146 <?php comment_text() ?>
147 <p><?php
148 echo '<a href="post.php?action=editcomment&amp;comment='.$comment->comment_ID.'">' . __('Edit') . '</a> | ';?>
149 <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php _e('View Post') ?></a> | 
150 <?php 
151 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 just this comment') . "</a> | "; ?>  <?php _e('Bulk action:') ?>
152         <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-approve" value="approve" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-approve"><?php _e('Approve') ?></label>
153         <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-spam" value="spam" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-spam"><?php _e('Spam') ?></label>
154         <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-delete" value="delete" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-delete"><?php _e('Delete') ?></label>
155         <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-nothing" value="later" checked="checked" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-nothing"><?php _e('Defer until later') ?></label>
156         </p>
157
158         </li>
159 <?php
160     }
161 ?>
162     </ol>
163
164 <div id="ajax-response"></div>
165
166     <p class="submit"><input type="submit" name="submit" value="<?php _e('Moderate Comments &raquo;') ?>" /></p>
167 <script type="text/javascript">
168 // <![CDATA[
169 function markAllForDelete() {
170         for (var i=0; i< document.approval.length; i++) {
171                 if (document.approval[i].value == "delete") {
172                         document.approval[i].checked = true;
173                 }
174         }
175 }
176 function markAllForApprove() {
177         for (var i=0; i< document.approval.length; i++) {
178                 if (document.approval[i].value == "approve") {
179                         document.approval[i].checked = true;
180                 }
181         }
182 }
183 function markAllForDefer() {
184         for (var i=0; i< document.approval.length; i++) {
185                 if (document.approval[i].value == "later") {
186                         document.approval[i].checked = true;
187                 }
188         }
189 }
190 function markAllAsSpam() {
191         for (var i=0; i< document.approval.length; i++) {
192                 if (document.approval[i].value == "spam") {
193                         document.approval[i].checked = true;
194                 }
195         }
196 }
197 document.write('<ul><li><a href="javascript:markAllForApprove()"><?php _e('Mark all for approval'); ?></a></li><li><a href="javascript:markAllAsSpam()"><?php _e('Mark all as spam'); ?></a></li><li><a href="javascript:markAllForDelete()"><?php _e('Mark all for deletion'); ?></a></li><li><a href="javascript:markAllForDefer()"><?php _e('Mark all for later'); ?></a></li></ul>');
198 // ]]>
199 </script>
200
201 <noscript>
202         <p>
203                 <input name="feelinglucky" type="checkbox" id="feelinglucky" value="true" /> <label for="feelinglucky"><?php _e('Delete every comment marked "defer." <strong>Warning: This can&#8217;t be undone.</strong>'); ?></label>
204         </p>
205 </noscript>
206     </form>
207 <?php
208 } else {
209     // nothing to approve
210         echo '<p>'.__("Currently there are no comments for you to moderate.") . "</p>\n";
211 }
212 ?>
213
214 </div>
215
216 <?php
217
218 break;
219 }
220
221
222 include('admin-footer.php') ?>