]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/moderation.php
Wordpress 2.3.2
[autoinstalls/wordpress.git] / wp-admin / moderation.php
1 <?php
2
3 require_once './admin.php';
4
5 $title = __( 'Moderate Comments' );
6 $parent_file = 'edit-comments.php';
7
8 wp_enqueue_script( 'admin-comments' );
9
10 wp_reset_vars( array( 'action', 'item_ignored', 'item_deleted', 'item_approved', 'item_spam', 'feelinglucky' ) );
11
12 $comment = array();
13
14 if ( isset( $_POST['comment'] ) && is_array( $_POST['comment'] ) ) {
15         foreach ( $_POST['comment'] as $k => $v ) {
16                 $comment[intval( $k )] = $v;
17         }
18 }
19
20 if ( $action == 'update' ) {
21         check_admin_referer( 'moderate-comments' );
22
23         if ( !current_user_can( 'moderate_comments' ) ) {
24                 wp_die( __( 'Your level is not high enough to moderate comments.' ) );
25         }
26
27         $item_ignored = 0;
28         $item_deleted = 0;
29         $item_approved = 0;
30         $item_spam = 0;
31
32         foreach ( $comment as $k => $v ) {
33                 if ( $feelinglucky && $v == 'later' ) {
34                         $v = 'delete';
35                 }
36
37                 switch ( $v ) {
38                         case 'later' :
39                                 $item_ignored++;
40                         break;
41
42                         case 'delete' :
43                                 wp_set_comment_status( $k, 'delete' );
44                                 $item_deleted++;
45                         break;
46
47                         case 'spam' :
48                                 wp_set_comment_status( $k, 'spam' );
49                                 $item_spam++;
50                         break;
51
52                         case 'approve' :
53                                 wp_set_comment_status( $k, 'approve' );
54
55                                 if ( get_option( 'comments_notify' ) == true ) {
56                                         wp_notify_postauthor( $k );
57                                 }
58
59                                 $item_approved++;
60                         break;
61                 }
62         }
63
64         wp_redirect( basename( __FILE__ ) . '?ignored=' . $item_ignored . '&deleted=' . $item_deleted . '&approved=' . $item_approved . '&spam=' . $item_spam );
65         exit;
66 }
67
68 require_once './admin-header.php';
69
70 if ( !current_user_can( 'moderate_comments' ) ) {
71         echo '<div class="wrap"><p>' . __( 'Your level is not high enough to moderate comments.' ) . '</p></div>';
72         include_once './admin-footer.php';
73         exit;
74 }
75
76 if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) {
77         $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
78         $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
79         $spam = isset( $_GET['ignored'] ) ? (int) $_GET['spam'] : 0;
80
81         if ( $approved > 0 || $deleted > 0 || $spam > 0 ) {
82                 echo '<div id="moderated" class="updated fade"><p>';
83
84                 if ( $approved > 0 ) {
85                         printf( __ngettext( '%s comment approved.', '%s comments approved.', $approved ), $approved );
86                         echo '<br />';
87                 }
88
89                 if ( $deleted > 0 ) {
90                         printf( __ngettext( '%s comment deleted', '%s comments deleted.', $deleted ), $deleted );
91                         echo '<br />';
92                 }
93
94                 if ( $spam > 0 ) {
95                         printf( __ngettext( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
96                         echo '<br />';
97                 }
98
99                 echo '</p></div>';
100         }
101 }
102
103 ?>
104 <div class="wrap">
105 <?php
106
107 $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0'" );
108
109 if ( !$comments ) {
110         echo '<p>' . __( 'Currently there are no comments for you to moderate.' ) . '</p></div>';
111         include_once './admin-footer.php';
112         exit;
113 }
114
115 $total = count( $comments );
116 $per = 100;
117
118 if ( isset( $_GET['paged'] ) ) {
119         $page = (int) $_GET['paged'];
120 } else {
121         $page = 1;
122 }
123
124 $start = ( $page * $per ) - $per;
125 $stop = $start + $per;
126
127 $page_links = paginate_links( array(
128         'base' => add_query_arg( 'paged', '%#%' ),
129         'format' => '',
130         'total' => ceil( $total / $per ),
131         'current' => $page,
132         'prev_text' => '&laquo;',
133         'next_text' => '&raquo;'
134 ) );
135
136 $comments = array_slice( $comments, $start, $stop );
137
138 ?>
139         <h2><?php _e( 'Moderation Queue' ); ?></h2>
140
141         <?php
142                 if ( $page_links ) {
143                         echo '<p class="pagenav">' . $page_links . '</p>';
144                 }
145         ?>
146
147         <form name="approval" id="approval" action="<?php echo basename( __FILE__ ); ?>" method="post">
148                 <?php wp_nonce_field( 'moderate-comments' ); ?>
149                 <input type="hidden" name="action" value="update" />
150                 <ol id="the-comments-list" class="commentlist">
151         <?php
152                 $i = 0;
153
154                 foreach ( $comments as $comment ) {
155                         $class = 'js-unapproved';
156
157                         if ( $i++ % 2 ) {
158                                 $class .= ' alternate';
159                         }
160                 ?>
161                         <li id="comment-<?php comment_ID(); ?>" class="<?php echo $class; ?>">
162                                 <p>
163                                         <strong><?php comment_author(); ?></strong>
164                                         <?php if ( !empty( $comment->comment_author_email ) ) { ?>| <?php comment_author_email_link(); ?> <?php } ?>
165                                         <?php if ( !empty( $comment->comment_author_url ) && $comment->comment_author_url != 'http://' ) { ?>| <?php comment_author_url_link(); ?> <?php } ?>
166                                         | <?php _e( 'IP:' ); ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP(); ?>"><?php comment_author_IP(); ?></a>
167                                 </p>
168
169                                 <p>
170                                         <?php comment_text(); ?>
171                                 </p>
172
173                                 <p><small>
174                                         <?php comment_date( __( 'M j, g:i A' ) ); ?> &#8212;
175                                         [ <a href="comment.php?action=editcomment&amp;c=<?php comment_ID(); ?>" title="<?php _e( 'Edit this comment' ); ?>"><?php _e( 'Edit' ); ?></a> |
176                                         <a href="post.php?action=deletecomment&amp;p=<?php echo $comment->comment_post_ID; ?>" title="<?php _e( 'Delete this comment' ); ?>" onclick="return deleteSomething( 'comment', <?php comment_ID(); ?>, '<?php echo js_escape( sprintf( __( "You are about to delete this comment by '%s'.\n'OK' to delete, 'Cancel' to stop." ), get_comment_author() ) ); ?>', theCommentList );"><?php _e( 'Delete' ); ?></a> ] &#8212;
177                                         <a href="<?php echo get_permalink( $comment->comment_post_ID ); ?>" title="<?php _e( 'View the post' ); ?>"><?php printf( __( 'View post &#8220;%s&#8221;' ), get_the_title( $comment->comment_post_ID ) ); ?></a>
178                                 </small></p>
179
180                                 <p><small>
181                                         <?php _e( 'Bulk action:' ); ?>
182                                         <label for="comment-<?php comment_ID(); ?>-approve"><input type="radio" name="comment[<?php comment_ID(); ?>]" id="comment-<?php comment_ID(); ?>-approve" value="approve" /> <?php _e( 'Approve' ); ?></label> &nbsp;
183                                         <label for="comment-<?php comment_ID(); ?>-spam"><input type="radio" name="comment[<?php comment_ID(); ?>]" id="comment-<?php comment_ID(); ?>-spam" value="spam" /> <?php _e( 'Spam' ); ?></label> &nbsp;
184                                         <label for="comment-<?php comment_ID(); ?>-delete"><input type="radio" name="comment[<?php comment_ID(); ?>]" id="comment-<?php comment_ID(); ?>-delete" value="delete" /> <?php _e( 'Delete' ); ?></label> &nbsp;
185                                         <label for="comment-<?php comment_ID(); ?>-nothing"><input type="radio" name="comment[<?php comment_ID(); ?>]" id="comment-<?php comment_ID(); ?>-nothing" value="later" checked="checked" /> <?php _e( 'No action' ); ?></label>
186                                 </small></p>
187                         </li>
188                 <?php
189                 }
190         ?>
191                 </ol>
192
193                 <?php
194                         if ( $page_links ) {
195                                 echo '<p class="pagenav">' . $page_links . '</p>';
196                         }
197                 ?>
198
199                 <div id="ajax-response"></div>
200
201                 <noscript>
202                         <p class="submit">
203                                 <label for="feelinglucky"><input name="feelinglucky" id="feelinglucky" type="checkbox" value="true" /> <?php _e( 'Delete every comment marked &#8220;defer.&#8221; <strong>Warning: This can&#8217;t be undone.</strong>' ); ?></label>
204                         </p>
205                 </noscript>
206
207                 <p class="submit">
208                         <input type="submit" id="submit" name="submit" value="<?php _e( 'Bulk Moderate Comments &raquo;' ); ?>" />
209                 </p>
210
211                 <script type="text/javascript">
212                 // <![CDATA[
213                         function mark_all_as( what ) {
214                                 for ( var i = 0; i < document.approval.length; i++ ) {
215                                         if ( document.approval[i].value == what ) {
216                                                 document.approval[i].checked = true;
217                                         }
218                                 }
219                         }
220
221                         document.write( '<p><strong><?php _e( 'Mark all:' ); ?></strong> <a href="javascript:mark_all_as(\'approve\')"><?php _e( 'Approved' ); ?></a> &ndash; <a href="javascript:mark_all_as(\'spam\')"><?php _e( 'Spam' ); ?></a> &ndash; <a href="javascript:mark_all_as(\'delete\')"><?php _e( 'Deleted' ); ?></a> &ndash; <a href="javascript:mark_all_as(\'later\')"><?php _e( 'Later' ); ?></a></p>' );
222                 // ]]>
223                 </script>
224         </form>
225 </div>
226 <?php include_once './admin-footer.php'; ?>