]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/comment.php
b2c69cb75298a2c3bf3dc2025dc479579e7240f0
[autoinstalls/wordpress.git] / wp-admin / comment.php
1 <?php
2 /**
3  * Comment Management Screen
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** Load WordPress Bootstrap */
10 require_once('./admin.php');
11
12 $parent_file = 'edit-comments.php';
13 $submenu_file = 'edit-comments.php';
14
15 wp_reset_vars( array('action') );
16
17 if ( isset( $_POST['deletecomment'] ) )
18         $action = 'deletecomment';
19
20 if ( 'cdc' == $action )
21         $action = 'delete';
22 elseif ( 'mac' == $action )
23         $action = 'approve';
24
25 if ( isset( $_GET['dt'] ) ) {
26         if ( 'spam' == $_GET['dt'] )
27                 $action = 'spam';
28         elseif ( 'trash' == $_GET['dt'] )
29                 $action = 'trash';
30 }
31
32 /**
33  * Display error message at bottom of comments.
34  *
35  * @param string $msg Error Message. Assumed to contain HTML and be sanitized.
36  */
37 function comment_footer_die( $msg ) {
38         echo "<div class='wrap'><p>$msg</p></div>";
39         include('./admin-footer.php');
40         die;
41 }
42
43 switch( $action ) {
44
45 case 'editcomment' :
46         $title = __('Edit Comment');
47
48         get_current_screen()->add_help_tab( array(
49                 'id'      => 'overview',
50                 'title'   => __('Overview'),
51                 'content' =>
52                         '<p>' . __( 'You can edit the information left in a comment if needed. This is often useful when you notice that a commenter has made a typographical error.' ) . '</p>' .
53                         '<p>' . __( 'You can also moderate the comment from this screen using the Status box, where you can also change the timestamp of the comment.' ) . '</p>'
54         ) );
55
56         get_current_screen()->set_help_sidebar(
57         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
58         '<p>' . __( '<a href="http://codex.wordpress.org/Administration_Screens#Comments" target="_blank">Documentation on Comments</a>' ) . '</p>' .
59         '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
60         );
61
62         wp_enqueue_script('comment');
63         require_once('./admin-header.php');
64
65         $comment_id = absint( $_GET['c'] );
66
67         if ( !$comment = get_comment( $comment_id ) )
68                 comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'javascript:history.go(-1)') );
69
70         if ( !current_user_can( 'edit_comment', $comment_id ) )
71                 comment_footer_die( __('You are not allowed to edit this comment.') );
72
73         if ( 'trash' == $comment->comment_approved )
74                 comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') );
75
76         if ( 'spam' == $comment->comment_approved )
77                 comment_footer_die( __('This comment is marked as Spam. Please mark it as Not Spam if you want to edit it.') );
78
79         $comment = get_comment_to_edit( $comment_id );
80
81         include('./edit-form-comment.php');
82
83         break;
84
85 case 'delete'  :
86 case 'approve' :
87 case 'trash'   :
88 case 'spam'    :
89
90         $title = __('Moderate Comment');
91
92         $comment_id = absint( $_GET['c'] );
93
94         if ( !$comment = get_comment_to_edit( $comment_id ) ) {
95                 wp_redirect( admin_url('edit-comments.php?error=1') );
96                 die();
97         }
98
99         if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) {
100                 wp_redirect( admin_url('edit-comments.php?error=2') );
101                 die();
102         }
103
104         // No need to re-approve/re-trash/re-spam a comment.
105         if ( $action == str_replace( '1', 'approve', $comment->comment_approved ) ) {
106                 wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) );
107                 die();
108         }
109
110         require_once('./admin-header.php');
111
112         $formaction    = $action . 'comment';
113         $nonce_action  = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
114         $nonce_action .= $comment_id;
115
116 ?>
117 <div class='wrap'>
118
119 <div class="narrow">
120
121 <?php screen_icon(); ?>
122 <h2><?php echo esc_html( $title ); ?></h2>
123
124 <?php
125 switch ( $action ) {
126         case 'spam' :
127                 $caution_msg = __('You are about to mark the following comment as spam:');
128                 $button      = __('Spam Comment');
129                 break;
130         case 'trash' :
131                 $caution_msg = __('You are about to move the following comment to the Trash:');
132                 $button      = __('Trash Comment');
133                 break;
134         case 'delete' :
135                 $caution_msg = __('You are about to delete the following comment:');
136                 $button      = __('Permanently Delete Comment');
137                 break;
138         default :
139                 $caution_msg = __('You are about to approve the following comment:');
140                 $button      = __('Approve Comment');
141                 break;
142 }
143
144 if ( $comment->comment_approved != '0' ) { // if not unapproved
145         $message = '';
146         switch ( $comment->comment_approved ) {
147                 case '1' :
148                         $message = __('This comment is currently approved.');
149                         break;
150                 case 'spam' :
151                         $message  = __('This comment is currently marked as spam.');
152                         break;
153                 case 'trash' :
154                         $message  = __('This comment is currently in the Trash.');
155                         break;
156         }
157         if ( $message )
158                 echo '<div class="updated"><p>' . $message . '</p></div>';
159 }
160 ?>
161 <p><strong><?php _e('Caution:'); ?></strong> <?php echo $caution_msg; ?></p>
162
163 <table class="form-table comment-ays">
164 <tr class="alt">
165 <th scope="row"><?php _e('Author'); ?></th>
166 <td><?php echo $comment->comment_author; ?></td>
167 </tr>
168 <?php if ( $comment->comment_author_email ) { ?>
169 <tr>
170 <th scope="row"><?php _e('E-mail'); ?></th>
171 <td><?php echo $comment->comment_author_email; ?></td>
172 </tr>
173 <?php } ?>
174 <?php if ( $comment->comment_author_url ) { ?>
175 <tr>
176 <th scope="row"><?php _e('URL'); ?></th>
177 <td><a href="<?php echo $comment->comment_author_url; ?>"><?php echo $comment->comment_author_url; ?></a></td>
178 </tr>
179 <?php } ?>
180 <tr>
181 <th scope="row" valign="top"><?php /* translators: field name in comment form */ _ex('Comment', 'noun'); ?></th>
182 <td><?php echo $comment->comment_content; ?></td>
183 </tr>
184 </table>
185
186 <p><?php _e('Are you sure you want to do this?'); ?></p>
187
188 <form action='comment.php' method='get'>
189
190 <table width="100%">
191 <tr>
192 <td><a class="button" href="<?php echo admin_url('edit-comments.php'); ?>"><?php esc_attr_e('No'); ?></a></td>
193 <td class="textright"><?php submit_button( $button, 'button' ); ?></td>
194 </tr>
195 </table>
196
197 <?php wp_nonce_field( $nonce_action ); ?>
198 <input type='hidden' name='action' value='<?php echo esc_attr($formaction); ?>' />
199 <input type='hidden' name='c' value='<?php echo esc_attr($comment->comment_ID); ?>' />
200 <input type='hidden' name='noredir' value='1' />
201 </form>
202
203 </div>
204 </div>
205 <?php
206         break;
207
208 case 'deletecomment'    :
209 case 'trashcomment'     :
210 case 'untrashcomment'   :
211 case 'spamcomment'      :
212 case 'unspamcomment'    :
213 case 'approvecomment'   :
214 case 'unapprovecomment' :
215         $comment_id = absint( $_REQUEST['c'] );
216
217         if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
218                 check_admin_referer( 'approve-comment_' . $comment_id );
219         else
220                 check_admin_referer( 'delete-comment_' . $comment_id );
221
222         $noredir = isset($_REQUEST['noredir']);
223
224         if ( !$comment = get_comment($comment_id) )
225                 comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'edit-comments.php') );
226         if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
227                 comment_footer_die( __('You are not allowed to edit comments on this post.') );
228
229         if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
230                 $redir = wp_get_referer();
231         elseif ( '' != wp_get_original_referer() && ! $noredir )
232                 $redir = wp_get_original_referer();
233         elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
234                 $redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
235         else
236                 $redir = admin_url('edit-comments.php');
237
238         $redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir );
239
240         switch ( $action ) {
241                 case 'deletecomment' :
242                         wp_delete_comment( $comment_id );
243                         $redir = add_query_arg( array('deleted' => '1'), $redir );
244                         break;
245                 case 'trashcomment' :
246                         wp_trash_comment($comment_id);
247                         $redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir );
248                         break;
249                 case 'untrashcomment' :
250                         wp_untrash_comment($comment_id);
251                         $redir = add_query_arg( array('untrashed' => '1'), $redir );
252                         break;
253                 case 'spamcomment' :
254                         wp_spam_comment($comment_id);
255                         $redir = add_query_arg( array('spammed' => '1', 'ids' => $comment_id), $redir );
256                         break;
257                 case 'unspamcomment' :
258                         wp_unspam_comment($comment_id);
259                         $redir = add_query_arg( array('unspammed' => '1'), $redir );
260                         break;
261                 case 'approvecomment' :
262                         wp_set_comment_status( $comment_id, 'approve' );
263                         $redir = add_query_arg( array( 'approved' => 1 ), $redir );
264                         break;
265                 case 'unapprovecomment' :
266                         wp_set_comment_status( $comment_id, 'hold' );
267                         $redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
268                         break;
269         }
270
271         wp_redirect( $redir );
272         die;
273         break;
274
275 case 'editedcomment' :
276
277         $comment_id = absint( $_POST['comment_ID'] );
278         $comment_post_id = absint( $_POST['comment_post_ID'] );
279
280         check_admin_referer( 'update-comment_' . $comment_id );
281
282         edit_comment();
283
284         $location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
285         $location = apply_filters( 'comment_edit_redirect', $location, $comment_id );
286         wp_redirect( $location );
287
288         exit();
289         break;
290
291 default:
292         wp_die( __('Unknown action.') );
293         break;
294
295 } // end switch
296
297 include('./admin-footer.php');
298
299 ?>