93
93
} elseif ( 2 == $_GET['test'] ) {
94
if ( !isset($_SERVER['HTTP_ACCEPT_ENCODING']) )
94
96
if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
95
97
header('Content-Encoding: deflate');
96
98
$out = gzdeflate( $test_str, 1 );
116
case 'imgedit-preview' :
117
$post_id = intval($_GET['postid']);
118
if ( empty($post_id) || !current_user_can('edit_post', $post_id) )
121
check_ajax_referer( "image_editor-$post_id" );
123
include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
124
if ( !stream_preview_image($post_id) )
129
case 'oembed-cache' :
130
$return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0';
115
134
do_action( 'wp_ajax_' . $_GET['action'] );
143
162
if ( 0 != $total % $per_page && 1 != mt_rand( 1, $per_page ) ) // Only do the expensive stuff on a page-break, and about 1 other time per page
144
163
die( (string) time() );
146
166
$status = 'total_comments'; // What type of comment count are we looking for?
147
167
$parsed = parse_url( $url );
148
168
if ( isset( $parsed['query'] ) ) {
149
169
parse_str( $parsed['query'], $query_vars );
150
170
if ( !empty( $query_vars['comment_status'] ) )
151
171
$status = $query_vars['comment_status'];
172
if ( !empty( $query_vars['p'] ) )
173
$post_id = (int) $query_vars['p'];
154
$comment_count = wp_count_comments();
176
$comment_count = wp_count_comments($post_id);
155
177
$time = time(); // The time since the last comment count
157
179
if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count
181
203
$id = isset($_POST['id'])? (int) $_POST['id'] : 0;
182
204
switch ( $action = $_POST['action'] ) :
183
205
case 'delete-comment' : // On success, die with time() instead of 1
206
if ( !$comment = get_comment( $id ) )
207
die( (string) time() );
208
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
184
211
check_ajax_referer( "delete-comment_$id" );
185
if ( !$comment = get_comment( $id ) )
186
die( (string) time() );
187
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
212
$status = wp_get_comment_status( $comment->comment_ID );
190
if ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
191
if ( 'spam' == wp_get_comment_status( $comment->comment_ID ) )
192
die( (string) time() );
193
$r = wp_set_comment_status( $comment->comment_ID, 'spam' );
214
if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
215
if ( 'trash' == $status )
216
die( (string) time() );
217
$r = wp_trash_comment( $comment->comment_ID );
218
} elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) {
219
if ( 'trash' != $status )
220
die( (string) time() );
221
$r = wp_untrash_comment( $comment->comment_ID );
222
} elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
223
if ( 'spam' == $status )
224
die( (string) time() );
225
$r = wp_spam_comment( $comment->comment_ID );
226
} elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) {
227
if ( 'spam' != $status )
228
die( (string) time() );
229
$r = wp_unspam_comment( $comment->comment_ID );
230
} elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
195
231
$r = wp_delete_comment( $comment->comment_ID );
197
236
if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
198
237
_wp_ajax_delete_comment_response( $comment->comment_ID );
215
254
case 'delete-tag' :
216
check_ajax_referer( "delete-tag_$id" );
255
$tag_id = (int) $_POST['tag_ID'];
256
check_ajax_referer( "delete-tag_$tag_id" );
217
257
if ( !current_user_can( 'manage_categories' ) )
220
if ( !empty($_POST['taxonomy']) )
221
$taxonomy = $_POST['taxonomy'];
223
$taxonomy = 'post_tag';
260
$taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
225
$tag = get_term( $id, $taxonomy );
262
$tag = get_term( $tag_id, $taxonomy );
226
263
if ( !$tag || is_wp_error( $tag ) )
229
if ( wp_delete_term($id, $taxonomy))
266
if ( wp_delete_term($tag_id, $taxonomy))
346
case 'untrash-post' :
347
check_ajax_referer( "{$action}_$id" );
348
if ( !current_user_can( 'delete_post', $id ) )
351
if ( !get_post( $id ) )
354
if ( 'trash-post' == $action )
355
$done = wp_trash_post( $id );
357
$done = wp_untrash_post( $id );
308
364
case 'delete-page' :
309
365
check_ajax_referer( "{$action}_$id" );
310
366
if ( !current_user_can( 'delete_page', $id ) )
331
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
333
if ( !current_user_can( 'moderate_comments' ) )
387
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) && !current_user_can( 'moderate_comments' ) )
336
390
$current = wp_get_comment_status( $comment->comment_ID );
337
391
if ( $_POST['new'] == $current )
338
392
die( (string) time() );
341
if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
342
check_ajax_referer( "approve-comment_$id" );
394
check_ajax_referer( "approve-comment_$id" );
395
if ( in_array( $current, array( 'unapproved', 'spam' ) ) )
343
396
$result = wp_set_comment_status( $comment->comment_ID, 'approve', true );
345
check_ajax_referer( "unapprove-comment_$id" );
346
398
$result = wp_set_comment_status( $comment->comment_ID, 'hold', true );
348
400
if ( is_wp_error($result) ) {
349
401
$x = new WP_Ajax_Response( array(
350
402
'what' => 'comment',
367
419
$post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array();
368
420
$checked_categories = array_map( 'absint', (array) $post_category );
369
$popular_ids = isset( $_POST['popular_ids'] ) ?
370
array_map( 'absint', explode( ',', $_POST['popular_ids'] ) ) :
421
$popular_ids = wp_popular_terms_checklist('category', 0, 10, false);
373
$x = new WP_Ajax_Response();
374
423
foreach ( $names as $cat_name ) {
375
424
$cat_name = trim($cat_name);
376
425
$category_nicename = sanitize_title($cat_name);
385
434
wp_category_checklist( 0, $cat_id, $checked_categories, $popular_ids );
386
435
$data = ob_get_contents();
389
438
'what' => 'category',
440
'data' => str_replace( array("\n", "\t"), '', $data),
395
444
if ( $parent ) { // Foncy - replace the parent and all its children
396
445
$parent = get_category( $parent );
446
$term_id = $parent->term_id;
448
while ( $parent->parent ) { // get the top parent
449
$parent = &get_category( $parent->parent );
450
if ( is_wp_error( $parent ) )
452
$term_id = $parent->term_id;
398
dropdown_categories( 0, $parent );
456
wp_category_checklist( 0, $term_id, $checked_categories, $popular_ids, null, false );
399
457
$data = ob_get_contents();
402
460
'what' => 'category',
403
'id' => $parent->term_id,
404
'old_id' => $parent->term_id,
462
'data' => str_replace( array("\n", "\t"), '', $data),
468
wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category') ) );
469
$sup = ob_get_contents();
471
$add['supplemental'] = array( 'newcat_parent' => $sup );
473
$x = new WP_Ajax_Response( $add );
412
476
case 'add-link-category' : // On the Fly
527
591
if ( !current_user_can( 'manage_categories' ) )
530
if ( '' === trim($_POST['name']) ) {
531
$x = new WP_Ajax_Response( array(
533
'id' => new WP_Error( 'name', __('You did not enter a tag name.') )
538
if ( !empty($_POST['taxonomy']) )
539
$taxonomy = $_POST['taxonomy'];
541
$taxonomy = 'post_tag';
543
$tag = wp_insert_term($_POST['name'], $taxonomy, $_POST );
545
if ( is_wp_error($tag) ) {
546
$x = new WP_Ajax_Response( array(
553
if ( !$tag || (!$tag = get_term( $tag['term_id'], $taxonomy )) )
556
$tag_full_name = $tag->name;
557
$tag_full_name = esc_attr($tag_full_name);
559
$x = new WP_Ajax_Response( array(
561
'id' => $tag->term_id,
563
'data' => _tag_row( $tag, '', $taxonomy ),
564
'supplemental' => array('name' => $tag_full_name, 'show-link' => sprintf(__( 'Tag <a href="#%s">%s</a> added' ), "tag-$tag->term_id", $tag_full_name))
594
$taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
595
$tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST );
597
if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) {
598
echo '<div class="error"><p>' . __('An error has occured. Please reload the page and try again.') . '</p></div>';
602
echo _tag_row( $tag, '', $taxonomy );
568
605
case 'get-tagcloud' :
569
606
if ( !current_user_can( 'edit_posts' ) )
600
637
case 'add-comment' :
601
638
check_ajax_referer( $action );
602
if ( !current_user_can( 'edit_post', $id ) )
639
if ( !current_user_can( 'edit_posts' ) )
604
641
$search = isset($_POST['s']) ? $_POST['s'] : false;
605
642
$status = isset($_POST['comment_status']) ? $_POST['comment_status'] : 'all';
675
712
if ( empty($status) )
677
elseif ( in_array($status, array('draft', 'pending') ) )
714
elseif ( in_array($status, array('draft', 'pending', 'trash') ) )
678
715
die( __('Error: you are replying to a comment on a draft post.') );
680
717
$user = wp_get_current_user();
885
922
$message = sprintf( __('Draft Saved at %s.'), date_i18n( $draft_saved_date_format ) );
887
924
$supplemental = array();
925
if ( isset($login_grace_period) )
926
$supplemental['session_expired'] = add_query_arg( 'interim-login', 1, wp_login_url() );
889
928
$id = $revision_id = 0;
890
929
if($_POST['post_ID'] < 0) {
964
1003
case 'autosave-generate-nonces' :
965
1004
check_ajax_referer( 'autosave', 'autosavenonce' );
966
1005
$ID = (int) $_POST['post_ID'];
967
if($_POST['post_type'] == 'post') {
968
if(current_user_can('edit_post', $ID))
969
die(wp_create_nonce('update-post_' . $ID));
971
if($_POST['post_type'] == 'page') {
972
if(current_user_can('edit_page', $ID)) {
973
die(wp_create_nonce('update-page_' . $ID));
1006
$post_type = ( 'page' == $_POST['post_type'] ) ? 'page' : 'post';
1007
if ( current_user_can( "edit_{$post_type}", $ID ) )
1008
die( json_encode( array( 'updateNonce' => wp_create_nonce( "update-{$post_type}_{$ID}" ), 'deleteURL' => str_replace( '&', '&', wp_nonce_url( admin_url( $post_type . '.php?action=trash&post=' . $ID ), "trash-{$post_type}_{$ID}" ) ) ) ) );
1009
do_action('autosave_generate_nonces');
978
1012
case 'closed-postboxes' :
993
1027
update_usermeta($user->ID, 'closedpostboxes_'.$page, $closed);
995
1029
if ( is_array($hidden) ) {
996
$hidden = array_diff( $hidden, array('submitdiv', 'pagesubmitdiv', 'linksubmitdiv') ); // postboxes that are always shown
1030
$hidden = array_diff( $hidden, array('submitdiv', 'linksubmitdiv') ); // postboxes that are always shown
997
1031
update_usermeta($user->ID, 'meta-box-hidden_'.$page, $hidden);
1151
if ( !empty($_POST['taxonomy']) )
1152
$taxonomy = $_POST['taxonomy'];
1154
$taxonomy = 'post_tag';
1185
$taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
1156
1187
$tag = get_term( $id, $taxonomy );
1157
1188
$_POST['description'] = $tag->description;
1162
1193
if ( !$tag || is_wp_error( $tag ) )
1163
1194
die( __('Tag not updated.') );
1165
echo _tag_row($tag);
1196
echo _tag_row($tag, '', $taxonomy);
1167
1198
die( __('Tag not updated.') );
1181
1212
$what = isset($_POST['pages']) ? 'page' : 'post';
1182
1213
$s = stripslashes($_POST['ps']);
1183
1214
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
1184
$search_terms = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
1215
$search_terms = array_map('_search_terms_tidy', $matches[0]);
1186
1217
$searchand = $search = '';
1187
foreach( (array) $search_terms as $term) {
1218
foreach ( (array) $search_terms as $term ) {
1188
1219
$term = addslashes_gpc($term);
1189
1220
$search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
1190
1221
$searchand = ' AND ';
1193
1224
if ( count($search_terms) > 1 && $search_terms[0] != $s )
1194
1225
$search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
1196
$posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND $search ORDER BY post_date_gmt DESC LIMIT 50" );
1227
$posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" );
1198
1229
if ( ! $posts )
1199
1230
exit( __('No posts found.') );
1201
$html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Time').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
1232
$html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Date').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
1202
1233
foreach ( $posts as $post ) {
1204
1235
switch ( $post->post_status ) {
1382
case 'image-editor':
1383
$attachment_id = intval($_POST['postid']);
1384
if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) )
1387
check_ajax_referer( "image_editor-$attachment_id" );
1388
include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
1391
switch ( $_POST['do'] ) {
1393
$msg = wp_save_image($attachment_id);
1394
$msg = json_encode($msg);
1398
$msg = wp_save_image($attachment_id);
1401
$msg = wp_restore_image($attachment_id);
1405
wp_image_editor($attachment_id, $msg);
1408
case 'set-post-thumbnail':
1409
$post_id = intval( $_POST['post_id'] );
1410
if ( !current_user_can( 'edit_post', $post_id ) )
1412
$thumbnail_id = intval( $_POST['thumbnail_id'] );
1414
if ( $thumbnail_id == '-1' ) {
1415
delete_post_meta( $post_id, '_thumbnail_id' );
1416
die( _wp_post_thumbnail_html() );
1419
if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
1420
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' );
1421
if ( !empty( $thumbnail_html ) ) {
1422
update_post_meta( $post_id, '_thumbnail_id', $thumbnail_id );
1423
die( _wp_post_thumbnail_html( $thumbnail_id ) );
1352
1428
do_action( 'wp_ajax_' . $_POST['action'] );