]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/comment.php
Wordpress 3.0.5-scripts
[autoinstalls/wordpress.git] / wp-admin / comment.php
1 <?php
2 /**
3  * Comment Management Panel
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         add_contextual_help( $current_screen, '<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>' .
49         '<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>' .
50         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
51         '<p>' . __( '<a href="http://codex.wordpress.org/Administration_Panels#Comments" target="_blank">Comments Documentation</a>' ) . '</p>' .
52         '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank" >Support Forums</a>' ) . '</p>'
53         );
54
55         wp_enqueue_script('comment');
56         require_once('./admin-header.php');
57
58         $comment_id = absint( $_GET['c'] );
59
60         if ( !$comment = get_comment( $comment_id ) )
61                 comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'javascript:history.go(-1)') );
62
63         if ( !current_user_can('edit_post', $comment->comment_post_ID) )
64                 comment_footer_die( __('You are not allowed to edit comments on this post.') );
65
66         if ( 'trash' == $comment->comment_approved )
67                 comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') );
68
69         $comment = get_comment_to_edit( $comment_id );
70
71         include('./edit-form-comment.php');
72
73         break;
74
75 case 'delete'  :
76 case 'approve' :
77 case 'trash'   :
78 case 'spam'    :
79
80         $comment_id = absint( $_GET['c'] );
81
82         if ( !$comment = get_comment_to_edit( $comment_id ) ) {
83                 wp_redirect( admin_url('edit-comments.php?error=1') );
84                 die();
85         }
86
87         if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) {
88                 wp_redirect( admin_url('edit-comments.php?error=2') );
89                 die();
90         }
91
92         // No need to re-approve/re-trash/re-spam a comment.
93         if ( $action == str_replace( '1', 'approve', $comment->comment_approved ) ) {
94                 wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) );
95                 die();
96         }
97
98         require_once('./admin-header.php');
99
100         $formaction    = $action . 'comment';
101         $nonce_action  = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
102         $nonce_action .= $comment_id;
103
104 ?>
105 <div class='wrap'>
106
107 <div class="narrow">
108
109 <?php screen_icon(); ?>
110 <h2><?php esc_html_e( 'Moderate Comment' ); ?></h2>
111
112 <?php
113 switch ( $action ) {
114         case 'spam' :
115                 $caution_msg = __('You are about to mark the following comment as spam:');
116                 $button      = __('Spam Comment');
117                 break;
118         case 'trash' :
119                 $caution_msg = __('You are about to move the following comment to the Trash:');
120                 $button      = __('Trash Comment');
121                 break;
122         case 'delete' :
123                 $caution_msg = __('You are about to delete the following comment:');
124                 $button      = __('Permanently Delete Comment');
125                 break;
126         default :
127                 $caution_msg = __('You are about to approve the following comment:');
128                 $button      = __('Approve Comment');
129                 break;
130 }
131
132 if ( $comment->comment_approved != '0' ) { // if not unapproved
133         $message = '';
134         switch ( $comment->comment_approved ) {
135                 case '1' :
136                         $message = __('This comment is currently approved.');
137                         break;
138                 case 'spam' :
139                         $message  = __('This comment is currently marked as spam.');
140                         break;
141                 case 'trash' :
142                         $message  = __('This comment is currently in the Trash.');
143                         break;
144         }
145         if ( $message )
146                 echo '<div class="updated"><p>' . $message . '</p></div>';
147 }
148 ?>
149 <p><strong><?php _e('Caution:'); ?></strong> <?php echo $caution_msg; ?></p>
150
151 <table class="form-table comment-ays">
152 <tr class="alt">
153 <th scope="row"><?php _e('Author'); ?></th>
154 <td><?php echo $comment->comment_author; ?></td>
155 </tr>
156 <?php if ( $comment->comment_author_email ) { ?>
157 <tr>
158 <th scope="row"><?php _e('E-mail'); ?></th>
159 <td><?php echo $comment->comment_author_email; ?></td>
160 </tr>
161 <?php } ?>
162 <?php if ( $comment->comment_author_url ) { ?>
163 <tr>
164 <th scope="row"><?php _e('URL'); ?></th>
165 <td><a href="<?php echo $comment->comment_author_url; ?>"><?php echo $comment->comment_author_url; ?></a></td>
166 </tr>
167 <?php } ?>
168 <tr>
169 <th scope="row" valign="top"><?php /* translators: field name in comment form */ _ex('Comment', 'noun'); ?></th>
170 <td><?php echo $comment->comment_content; ?></td>
171 </tr>
172 </table>
173
174 <p><?php _e('Are you sure you want to do this?'); ?></p>
175
176 <form action='comment.php' method='get'>
177
178 <table width="100%">
179 <tr>
180 <td><a class="button" href="<?php echo admin_url('edit-comments.php'); ?>"><?php esc_attr_e('No'); ?></a></td>
181 <td class="textright"><input type='submit' class="button" value='<?php echo esc_attr($button); ?>' /></td>
182 </tr>
183 </table>
184
185 <?php wp_nonce_field( $nonce_action ); ?>
186 <input type='hidden' name='action' value='<?php echo esc_attr($formaction); ?>' />
187 <input type='hidden' name='p' value='<?php echo esc_attr($comment->comment_post_ID); ?>' />
188 <input type='hidden' name='c' value='<?php echo esc_attr($comment->comment_ID); ?>' />
189 <input type='hidden' name='noredir' value='1' />
190 </form>
191
192 </div>
193 </div>
194 <?php
195         break;
196
197 case 'deletecomment'    :
198 case 'trashcomment'     :
199 case 'untrashcomment'   :
200 case 'spamcomment'      :
201 case 'unspamcomment'    :
202 case 'approvecomment'   :
203 case 'unapprovecomment' :
204         $comment_id = absint( $_REQUEST['c'] );
205
206         if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
207                 check_admin_referer( 'approve-comment_' . $comment_id );
208         else
209                 check_admin_referer( 'delete-comment_' . $comment_id );
210
211         $noredir = isset($_REQUEST['noredir']);
212
213         if ( !$comment = get_comment($comment_id) )
214                 comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'edit-comments.php') );
215         if ( !current_user_can('edit_post', $comment->comment_post_ID ) )
216                 comment_footer_die( __('You are not allowed to edit comments on this post.') );
217
218         if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
219                 $redir = wp_get_referer();
220         elseif ( '' != wp_get_original_referer() && ! $noredir )
221                 $redir = wp_get_original_referer();
222         elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
223                 $redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
224         else
225                 $redir = admin_url('edit-comments.php');
226
227         $redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir );
228
229         switch ( $action ) {
230                 case 'deletecomment' :
231                         wp_delete_comment( $comment_id );
232                         $redir = add_query_arg( array('deleted' => '1'), $redir );
233                         break;
234                 case 'trashcomment' :
235                         wp_trash_comment($comment_id);
236                         $redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir );
237                         break;
238                 case 'untrashcomment' :
239                         wp_untrash_comment($comment_id);
240                         $redir = add_query_arg( array('untrashed' => '1'), $redir );
241                         break;
242                 case 'spamcomment' :
243                         wp_spam_comment($comment_id);
244                         $redir = add_query_arg( array('spammed' => '1', 'ids' => $comment_id), $redir );
245                         break;
246                 case 'unspamcomment' :
247                         wp_unspam_comment($comment_id);
248                         $redir = add_query_arg( array('unspammed' => '1'), $redir );
249                         break;
250                 case 'approvecomment' :
251                         wp_set_comment_status( $comment_id, 'approve' );
252                         $redir = add_query_arg( array( 'approved' => 1 ), $redir );
253                         break;
254                 case 'unapprovecomment' :
255                         wp_set_comment_status( $comment_id, 'hold' );
256                         $redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
257                         break;
258         }
259
260         wp_redirect( $redir );
261         die;
262         break;
263
264 case 'editedcomment' :
265
266         $comment_id = absint( $_POST['comment_ID'] );
267         $comment_post_id = absint( $_POST['comment_post_ID'] );
268
269         check_admin_referer( 'update-comment_' . $comment_id );
270
271         edit_comment();
272
273         $location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
274         $location = apply_filters( 'comment_edit_redirect', $location, $comment_id );
275         wp_redirect( $location );
276
277         exit();
278         break;
279
280 default:
281         wp_die( __('Unknown action.') );
282         break;
283
284 } // end switch
285
286 include('./admin-footer.php');
287
288 ?>