]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/comment.php
7131a0c7f309edb47451b051781d004bc1559a3d
[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( dirname( __FILE__ ) . '/admin.php' );
11
12 $parent_file = 'edit-comments.php';
13 $submenu_file = 'edit-comments.php';
14
15 /**
16  * @global string $action
17  */
18 global $action;
19 wp_reset_vars( array('action') );
20
21 if ( isset( $_POST['deletecomment'] ) )
22         $action = 'deletecomment';
23
24 if ( 'cdc' == $action )
25         $action = 'delete';
26 elseif ( 'mac' == $action )
27         $action = 'approve';
28
29 if ( isset( $_GET['dt'] ) ) {
30         if ( 'spam' == $_GET['dt'] )
31                 $action = 'spam';
32         elseif ( 'trash' == $_GET['dt'] )
33                 $action = 'trash';
34 }
35
36 /**
37  * Display error message at bottom of comments.
38  *
39  * @param string $msg Error Message. Assumed to contain HTML and be sanitized.
40  */
41 function comment_footer_die( $msg ) {
42         echo "<div class='wrap'><p>$msg</p></div>";
43         include( ABSPATH . 'wp-admin/admin-footer.php' );
44         die;
45 }
46
47 switch( $action ) {
48
49 case 'editcomment' :
50         $title = __('Edit Comment');
51
52         get_current_screen()->add_help_tab( array(
53                 'id'      => 'overview',
54                 'title'   => __('Overview'),
55                 'content' =>
56                         '<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>' .
57                         '<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>'
58         ) );
59
60         get_current_screen()->set_help_sidebar(
61         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
62         '<p>' . __( '<a href="https://codex.wordpress.org/Administration_Screens#Comments" target="_blank">Documentation on Comments</a>' ) . '</p>' .
63         '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
64         );
65
66         wp_enqueue_script('comment');
67         require_once( ABSPATH . 'wp-admin/admin-header.php' );
68
69         $comment_id = absint( $_GET['c'] );
70
71         if ( !$comment = get_comment( $comment_id ) )
72                 comment_footer_die( __( 'Invalid comment ID.' ) . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'javascript:history.go(-1)') );
73
74         if ( !current_user_can( 'edit_comment', $comment_id ) )
75                 comment_footer_die( __('You are not allowed to edit this comment.') );
76
77         if ( 'trash' == $comment->comment_approved )
78                 comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') );
79
80         $comment = get_comment_to_edit( $comment_id );
81
82         include( ABSPATH . 'wp-admin/edit-form-comment.php' );
83
84         break;
85
86 case 'delete'  :
87 case 'approve' :
88 case 'trash'   :
89 case 'spam'    :
90
91         $title = __('Moderate Comment');
92
93         $comment_id = absint( $_GET['c'] );
94
95         if ( !$comment = get_comment_to_edit( $comment_id ) ) {
96                 wp_redirect( admin_url('edit-comments.php?error=1') );
97                 die();
98         }
99
100         if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) {
101                 wp_redirect( admin_url('edit-comments.php?error=2') );
102                 die();
103         }
104
105         // No need to re-approve/re-trash/re-spam a comment.
106         if ( $action == str_replace( '1', 'approve', $comment->comment_approved ) ) {
107                 wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) );
108                 die();
109         }
110
111         require_once( ABSPATH . 'wp-admin/admin-header.php' );
112
113         $formaction    = $action . 'comment';
114         $nonce_action  = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
115         $nonce_action .= $comment_id;
116
117 ?>
118 <div class="wrap">
119
120 <h1><?php echo esc_html( $title ); ?></h1>
121
122 <?php
123 switch ( $action ) {
124         case 'spam' :
125                 $caution_msg = __('You are about to mark the following comment as spam:');
126                 $button      = _x( 'Mark as Spam', 'comment' );
127                 break;
128         case 'trash' :
129                 $caution_msg = __('You are about to move the following comment to the Trash:');
130                 $button      = __('Move to Trash');
131                 break;
132         case 'delete' :
133                 $caution_msg = __('You are about to delete the following comment:');
134                 $button      = __('Permanently Delete Comment');
135                 break;
136         default :
137                 $caution_msg = __('You are about to approve the following comment:');
138                 $button      = __('Approve Comment');
139                 break;
140 }
141
142 if ( $comment->comment_approved != '0' ) { // if not unapproved
143         $message = '';
144         switch ( $comment->comment_approved ) {
145                 case '1' :
146                         $message = __('This comment is currently approved.');
147                         break;
148                 case 'spam' :
149                         $message  = __('This comment is currently marked as spam.');
150                         break;
151                 case 'trash' :
152                         $message  = __('This comment is currently in the Trash.');
153                         break;
154         }
155         if ( $message ) {
156                 echo '<div class="notice notice-info"><p>' . $message . '</p></div>';
157         }
158 }
159 ?>
160 <p><strong><?php _e('Caution:'); ?></strong> <?php echo $caution_msg; ?></p>
161
162 <table class="form-table comment-ays">
163 <tr>
164 <th scope="row"><?php _e('Author'); ?></th>
165 <td><?php echo $comment->comment_author; ?></td>
166 </tr>
167 <?php if ( $comment->comment_author_email ) { ?>
168 <tr>
169 <th scope="row"><?php _e('E-mail'); ?></th>
170 <td><?php echo $comment->comment_author_email; ?></td>
171 </tr>
172 <?php } ?>
173 <?php if ( $comment->comment_author_url ) { ?>
174 <tr>
175 <th scope="row"><?php _e('URL'); ?></th>
176 <td><a href="<?php echo $comment->comment_author_url; ?>"><?php echo $comment->comment_author_url; ?></a></td>
177 </tr>
178 <?php } ?>
179 <tr>
180         <th scope="row"><?php /* translators: column name or table row header */ _e( 'In Response To' ); ?></th>
181         <td>
182         <?php
183                 $post_id = $comment->comment_post_ID;
184                 if ( current_user_can( 'edit_post', $post_id ) ) {
185                         $post_link = "<a href='" . esc_url( get_edit_post_link( $post_id ) ) . "'>";
186                         $post_link .= esc_html( get_the_title( $post_id ) ) . '</a>';
187                 } else {
188                         $post_link = esc_html( get_the_title( $post_id ) );
189                 }
190                 echo $post_link;
191
192                 if ( $comment->comment_parent ) {
193                         $parent      = get_comment( $comment->comment_parent );
194                         $parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
195                         $name        = get_comment_author( $parent->comment_ID );
196                         printf( ' | ' . __( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
197                 }
198         ?>
199         </td>
200 </tr>
201 <tr>
202         <th scope="row"><?php _e( 'Submitted on' ); ?></th>
203         <td>
204         <?php
205                 /* translators: 2: comment date, 3: comment time */
206                 printf( __( '<a href="%1$s">%2$s at %3$s</a>' ),
207                         esc_url( get_comment_link( $comment->comment_ID ) ),
208                         /* translators: comment date format. See http://php.net/date */
209                         get_comment_date( __( 'Y/m/d' ) ),
210                         get_comment_date( get_option( 'time_format' ) )
211                 );
212         ?>
213         </td>
214 </tr>
215 <tr>
216 <th scope="row"><?php /* translators: field name in comment form */ _ex('Comment', 'noun'); ?></th>
217 <td><?php echo $comment->comment_content; ?></td>
218 </tr>
219 </table>
220
221 <form action="comment.php" method="get" class="comment-ays-submit">
222
223 <p>
224         <?php submit_button( $button, 'primary', 'submit', false ); ?>
225         <a href="<?php echo admin_url('edit-comments.php'); ?>" class="button-cancel"><?php esc_attr_e( 'Cancel' ); ?></a></td>
226 </p>
227
228 <?php wp_nonce_field( $nonce_action ); ?>
229 <input type="hidden" name="action" value="<?php echo esc_attr($formaction); ?>" />
230 <input type="hidden" name="c" value="<?php echo esc_attr($comment->comment_ID); ?>" />
231 <input type="hidden" name="noredir" value="1" />
232 </form>
233
234 </div>
235 <?php
236         break;
237
238 case 'deletecomment'    :
239 case 'trashcomment'     :
240 case 'untrashcomment'   :
241 case 'spamcomment'      :
242 case 'unspamcomment'    :
243 case 'approvecomment'   :
244 case 'unapprovecomment' :
245         $comment_id = absint( $_REQUEST['c'] );
246
247         if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
248                 check_admin_referer( 'approve-comment_' . $comment_id );
249         else
250                 check_admin_referer( 'delete-comment_' . $comment_id );
251
252         $noredir = isset($_REQUEST['noredir']);
253
254         if ( !$comment = get_comment($comment_id) )
255                 comment_footer_die( __( 'Invalid comment ID.' ) . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'edit-comments.php') );
256         if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
257                 comment_footer_die( __('You are not allowed to edit comments on this post.') );
258
259         if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
260                 $redir = wp_get_referer();
261         elseif ( '' != wp_get_original_referer() && ! $noredir )
262                 $redir = wp_get_original_referer();
263         elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
264                 $redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
265         else
266                 $redir = admin_url('edit-comments.php');
267
268         $redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir );
269
270         switch ( $action ) {
271                 case 'deletecomment' :
272                         wp_delete_comment( $comment_id );
273                         $redir = add_query_arg( array('deleted' => '1'), $redir );
274                         break;
275                 case 'trashcomment' :
276                         wp_trash_comment($comment_id);
277                         $redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir );
278                         break;
279                 case 'untrashcomment' :
280                         wp_untrash_comment($comment_id);
281                         $redir = add_query_arg( array('untrashed' => '1'), $redir );
282                         break;
283                 case 'spamcomment' :
284                         wp_spam_comment($comment_id);
285                         $redir = add_query_arg( array('spammed' => '1', 'ids' => $comment_id), $redir );
286                         break;
287                 case 'unspamcomment' :
288                         wp_unspam_comment($comment_id);
289                         $redir = add_query_arg( array('unspammed' => '1'), $redir );
290                         break;
291                 case 'approvecomment' :
292                         wp_set_comment_status( $comment_id, 'approve' );
293                         $redir = add_query_arg( array( 'approved' => 1 ), $redir );
294                         break;
295                 case 'unapprovecomment' :
296                         wp_set_comment_status( $comment_id, 'hold' );
297                         $redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
298                         break;
299         }
300
301         wp_redirect( $redir );
302         die;
303
304 case 'editedcomment' :
305
306         $comment_id = absint( $_POST['comment_ID'] );
307         $comment_post_id = absint( $_POST['comment_post_ID'] );
308
309         check_admin_referer( 'update-comment_' . $comment_id );
310
311         edit_comment();
312
313         $location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
314
315         /**
316          * Filter the URI the user is redirected to after editing a comment in the admin.
317          *
318          * @since 2.1.0
319          *
320          * @param string $location The URI the user will be redirected to.
321          * @param int $comment_id The ID of the comment being edited.
322          */
323         $location = apply_filters( 'comment_edit_redirect', $location, $comment_id );
324         wp_redirect( $location );
325
326         exit();
327
328 default:
329         wp_die( __('Unknown action.') );
330
331 } // end switch
332
333 include( ABSPATH . 'wp-admin/admin-footer.php' );