root/tags/1_0-rc1/wp-admin/moderation.php

Revision 599, 7.8 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 = __('Moderate comments');
5 $parent_file = 'edit.php';
6 wp_enqueue_script( 'admin-comments' );
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     check_admin_referer('moderate-comments');
36
37     if ( ! current_user_can('moderate_comments') )
38     die('<p>'.__('Your level is not high enough to moderate comments.').'</p>');
39
40     $item_ignored = 0;
41     $item_deleted = 0;
42     $item_approved = 0;
43     $item_spam = 0;
44
45     foreach($comment as $key => $value) {
46     if ($feelinglucky && 'later' == $value)
47         $value = 'delete';
48         switch($value) {
49             case 'later':
50                 // do nothing with that comment
51                 // wp_set_comment_status($key, "hold");
52                 ++$item_ignored;
53                 break;
54             case 'delete':
55                 wp_set_comment_status($key, 'delete');
56                 ++$item_deleted;
57                 break;
58              case 'spam':
59                  wp_set_comment_status($key, 'spam');
60                  ++$item_spam;
61                  break;
62             case 'approve':
63                 wp_set_comment_status($key, 'approve');
64                 if ( get_settings('comments_notify') == true ) {
65                     wp_notify_postauthor($key);
66                 }
67                 ++$item_approved;
68                 break;
69         }
70     }
71
72     $file = basename(__FILE__);
73     wp_redirect("$file?ignored=$item_ignored&deleted=$item_deleted&approved=$item_approved&spam=$item_spam");
74     exit();
75
76 break;
77
78 default:
79
80 require_once('admin-header.php');
81
82 if ( isset($_GET['deleted']) || isset($_GET['approved']) || isset($_GET['ignored']) ) {
83     echo "<div id='moderated' class='updated fade'>\n<p>";
84     $approved = (int) $_GET['approved'];
85     $deleted  = (int) $_GET['deleted'];
86     $ignored  = (int) $_GET['ignored'];
87     $spam     = (int) $_GET['spam'];
88     if ($approved) {
89         if ('1' == $approved) {
90             echo __("1 comment approved") . " <br/>\n";
91         } else {
92          echo sprintf(__("%s comments approved <br />"), $approved) . "\n";
93         }
94     }
95     if ($deleted) {
96         if ('1' == $deleted) {
97             echo __("1 comment deleted") . " <br/>\n";
98         } else {
99             echo sprintf(__("%s comments deleted"), $deleted) . " <br/>\n";
100         }
101     }
102      if ($spam) {
103          if ('1' == $spam) {
104             echo __("1 comment marked as spam") . " <br/>\n";
105          } else {
106              echo sprintf(__("%s comments marked as spam"), $spam) . " <br/>\n";
107          }
108      }
109     if ($ignored) {
110         if ('1' == $ignored) {
111             echo __("1 comment unchanged") . " <br/>\n";
112         } else {
113             echo sprintf(__("%s comments unchanged"), $ignored) . " <br/>\n";
114         }
115     }
116     echo "</p></div>\n";
117 }
118
119 ?>
120
121 <div class="wrap">
122
123 <?php
124 if ( current_user_can('moderate_comments') )
125     $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0'");
126 else
127     $comments = '';
128
129 if ($comments) {
130     // list all comments that are waiting for approval
131     $file = basename(__FILE__);
132 ?>
133     <h2><?php _e('Moderation Queue') ?></h2>
134     <form name="approval" action="moderation.php" method="post">
135     <?php wp_nonce_field('moderate-comments') ?>
136     <input type="hidden" name="action" value="update" />
137     <ol id="the-comment-list" class="commentlist">
138 <?php
139 $i = 0;
140     foreach($comments as $comment) {
141     ++$i;
142     $comment_date = mysql2date(get_settings("date_format") . " @ " . get_settings("time_format"), $comment->comment_date);
143     $post_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID='$comment->comment_post_ID'");
144     if ($i % 2) $class = 'js-unapproved alternate';
145     else $class = 'js-unapproved';
146     echo "\n\t<li id='comment-$comment->comment_ID' class='$class'>";
147     ?>
148     <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>
149 <?php comment_text() ?>
150 <p><?php comment_date('M j, g:i A'); ?> &#8212; [ <?php
151 echo '<a href="comment.php?action=editcomment&amp;comment='.$comment->comment_ID.'">' . __('Edit') . '</a> | ';
152 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."), js_escape($comment->comment_author)) . "', theCommentList );\">" . __('Delete ') . "</a> | "; ?>
153 <?php
154 $post = get_post($comment->comment_post_ID);
155 $post_title = wp_specialchars( $post->post_title, 'double' );
156 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
157 ?>
158 <a href="<?php echo get_permalink($comment->comment_post_ID); ?>" title="<?php echo $post_title; ?>"><?php _e('View Post') ?></a> ] &#8212;
159  <?php _e('Bulk action:') ?>
160     <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> &nbsp;
161     <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> &nbsp;
162     <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> &nbsp;
163     <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>
164     </p>
165
166     </li>
167 <?php
168     }
169 ?>
170     </ol>
171
172 <div id="ajax-response"></div>
173
174     <p class="submit"><input type="submit" name="submit" value="<?php _e('Bulk Moderate Comments &raquo;') ?>" /></p>
175 <script type="text/javascript">
176 // <![CDATA[
177 function markAllForDelete() {
178     for (var i=0; i< document.approval.length; i++) {
179         if (document.approval[i].value == "delete") {
180             document.approval[i].checked = true;
181         }
182     }
183 }
184 function markAllForApprove() {
185     for (var i=0; i< document.approval.length; i++) {
186         if (document.approval[i].value == "approve") {
187             document.approval[i].checked = true;
188         }
189     }
190 }
191 function markAllForDefer() {
192     for (var i=0; i< document.approval.length; i++) {
193         if (document.approval[i].value == "later") {
194             document.approval[i].checked = true;
195         }
196     }
197 }
198 function markAllAsSpam() {
199     for (var i=0; i< document.approval.length; i++) {
200         if (document.approval[i].value == "spam") {
201             document.approval[i].checked = true;
202         }
203     }
204 }
205 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>');
206 // ]]>
207 </script>
208
209 <noscript>
210     <p>
211         <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>
212     </p>
213 </noscript>
214     </form>
215 <?php
216 } else {
217     // nothing to approve
218     echo '<p>'.__("Currently there are no comments for you to moderate.") . "</p>\n";
219 }
220 ?>
221
222 </div>
223
224 <?php
225
226 break;
227 }
228
229
230 include('admin-footer.php');
231
232 ?>
233
Note: See TracBrowser for help on using the browser.