89 |
89 |
90 if ( 1 == $_GET['test'] ) { |
90 if ( 1 == $_GET['test'] ) { |
91 echo $test_str; |
91 echo $test_str; |
92 die; |
92 die; |
93 } elseif ( 2 == $_GET['test'] ) { |
93 } elseif ( 2 == $_GET['test'] ) { |
|
94 if ( !isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) |
|
95 die('-1'); |
94 if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) { |
96 if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) { |
95 header('Content-Encoding: deflate'); |
97 header('Content-Encoding: deflate'); |
96 $out = gzdeflate( $test_str, 1 ); |
98 $out = gzdeflate( $test_str, 1 ); |
97 } elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) { |
99 } elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) { |
98 header('Content-Encoding: gzip'); |
100 header('Content-Encoding: gzip'); |
108 update_site_option('can_compress_scripts', 1); |
110 update_site_option('can_compress_scripts', 1); |
109 } |
111 } |
110 } |
112 } |
111 |
113 |
112 die('0'); |
114 die('0'); |
|
115 break; |
|
116 case 'imgedit-preview' : |
|
117 $post_id = intval($_GET['postid']); |
|
118 if ( empty($post_id) || !current_user_can('edit_post', $post_id) ) |
|
119 die('-1'); |
|
120 |
|
121 check_ajax_referer( "image_editor-$post_id" ); |
|
122 |
|
123 include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); |
|
124 if ( !stream_preview_image($post_id) ) |
|
125 die('-1'); |
|
126 |
|
127 die(); |
|
128 break; |
|
129 case 'oembed-cache' : |
|
130 $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0'; |
|
131 die( $return ); |
113 break; |
132 break; |
114 default : |
133 default : |
115 do_action( 'wp_ajax_' . $_GET['action'] ); |
134 do_action( 'wp_ajax_' . $_GET['action'] ); |
116 die('0'); |
135 die('0'); |
117 break; |
136 break; |
141 $total = 0; |
160 $total = 0; |
142 |
161 |
143 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 |
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 die( (string) time() ); |
163 die( (string) time() ); |
145 |
164 |
|
165 $post_id = 0; |
146 $status = 'total_comments'; // What type of comment count are we looking for? |
166 $status = 'total_comments'; // What type of comment count are we looking for? |
147 $parsed = parse_url( $url ); |
167 $parsed = parse_url( $url ); |
148 if ( isset( $parsed['query'] ) ) { |
168 if ( isset( $parsed['query'] ) ) { |
149 parse_str( $parsed['query'], $query_vars ); |
169 parse_str( $parsed['query'], $query_vars ); |
150 if ( !empty( $query_vars['comment_status'] ) ) |
170 if ( !empty( $query_vars['comment_status'] ) ) |
151 $status = $query_vars['comment_status']; |
171 $status = $query_vars['comment_status']; |
152 } |
172 if ( !empty( $query_vars['p'] ) ) |
153 |
173 $post_id = (int) $query_vars['p']; |
154 $comment_count = wp_count_comments(); |
174 } |
|
175 |
|
176 $comment_count = wp_count_comments($post_id); |
155 $time = time(); // The time since the last comment count |
177 $time = time(); // The time since the last comment count |
156 |
178 |
157 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count |
179 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count |
158 $total = $comment_count->$status; |
180 $total = $comment_count->$status; |
159 // else use the decremented value from above |
181 // else use the decremented value from above |
179 } |
201 } |
180 |
202 |
181 $id = isset($_POST['id'])? (int) $_POST['id'] : 0; |
203 $id = isset($_POST['id'])? (int) $_POST['id'] : 0; |
182 switch ( $action = $_POST['action'] ) : |
204 switch ( $action = $_POST['action'] ) : |
183 case 'delete-comment' : // On success, die with time() instead of 1 |
205 case 'delete-comment' : // On success, die with time() instead of 1 |
184 check_ajax_referer( "delete-comment_$id" ); |
|
185 if ( !$comment = get_comment( $id ) ) |
206 if ( !$comment = get_comment( $id ) ) |
186 die( (string) time() ); |
207 die( (string) time() ); |
187 if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) |
208 if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) |
188 die('-1'); |
209 die('-1'); |
189 |
210 |
190 if ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { |
211 check_ajax_referer( "delete-comment_$id" ); |
191 if ( 'spam' == wp_get_comment_status( $comment->comment_ID ) ) |
212 $status = wp_get_comment_status( $comment->comment_ID ); |
|
213 |
|
214 if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { |
|
215 if ( 'trash' == $status ) |
192 die( (string) time() ); |
216 die( (string) time() ); |
193 $r = wp_set_comment_status( $comment->comment_ID, 'spam' ); |
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'] ) { |
|
231 $r = wp_delete_comment( $comment->comment_ID ); |
194 } else { |
232 } else { |
195 $r = wp_delete_comment( $comment->comment_ID ); |
233 die('-1'); |
196 } |
234 } |
|
235 |
197 if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts |
236 if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts |
198 _wp_ajax_delete_comment_response( $comment->comment_ID ); |
237 _wp_ajax_delete_comment_response( $comment->comment_ID ); |
199 die( '0' ); |
238 die( '0' ); |
200 break; |
239 break; |
201 case 'delete-cat' : |
240 case 'delete-cat' : |
211 die('1'); |
250 die('1'); |
212 else |
251 else |
213 die('0'); |
252 die('0'); |
214 break; |
253 break; |
215 case 'delete-tag' : |
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 if ( !current_user_can( 'manage_categories' ) ) |
257 if ( !current_user_can( 'manage_categories' ) ) |
218 die('-1'); |
258 die('-1'); |
219 |
259 |
220 if ( !empty($_POST['taxonomy']) ) |
260 $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; |
221 $taxonomy = $_POST['taxonomy']; |
261 |
222 else |
262 $tag = get_term( $tag_id, $taxonomy ); |
223 $taxonomy = 'post_tag'; |
|
224 |
|
225 $tag = get_term( $id, $taxonomy ); |
|
226 if ( !$tag || is_wp_error( $tag ) ) |
263 if ( !$tag || is_wp_error( $tag ) ) |
227 die('1'); |
264 die('1'); |
228 |
265 |
229 if ( wp_delete_term($id, $taxonomy)) |
266 if ( wp_delete_term($tag_id, $taxonomy)) |
230 die('1'); |
267 die('1'); |
231 else |
268 else |
232 die('0'); |
269 die('0'); |
233 break; |
270 break; |
234 case 'delete-link-cat' : |
271 case 'delete-link-cat' : |
303 if ( wp_delete_post( $id ) ) |
340 if ( wp_delete_post( $id ) ) |
304 die('1'); |
341 die('1'); |
305 else |
342 else |
306 die('0'); |
343 die('0'); |
307 break; |
344 break; |
|
345 case 'trash-post' : |
|
346 case 'untrash-post' : |
|
347 check_ajax_referer( "{$action}_$id" ); |
|
348 if ( !current_user_can( 'delete_post', $id ) ) |
|
349 die('-1'); |
|
350 |
|
351 if ( !get_post( $id ) ) |
|
352 die('1'); |
|
353 |
|
354 if ( 'trash-post' == $action ) |
|
355 $done = wp_trash_post( $id ); |
|
356 else |
|
357 $done = wp_untrash_post( $id ); |
|
358 |
|
359 if ( $done ) |
|
360 die('1'); |
|
361 |
|
362 die('0'); |
|
363 break; |
308 case 'delete-page' : |
364 case 'delete-page' : |
309 check_ajax_referer( "{$action}_$id" ); |
365 check_ajax_referer( "{$action}_$id" ); |
310 if ( !current_user_can( 'delete_page', $id ) ) |
366 if ( !current_user_can( 'delete_page', $id ) ) |
311 die('-1'); |
367 die('-1'); |
312 |
368 |
326 'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id)) |
382 'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id)) |
327 ) ); |
383 ) ); |
328 $x->send(); |
384 $x->send(); |
329 } |
385 } |
330 |
386 |
331 if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) |
387 if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) && !current_user_can( 'moderate_comments' ) ) |
332 die('-1'); |
|
333 if ( !current_user_can( 'moderate_comments' ) ) |
|
334 die('-1'); |
388 die('-1'); |
335 |
389 |
336 $current = wp_get_comment_status( $comment->comment_ID ); |
390 $current = wp_get_comment_status( $comment->comment_ID ); |
337 if ( $_POST['new'] == $current ) |
391 if ( $_POST['new'] == $current ) |
338 die( (string) time() ); |
392 die( (string) time() ); |
339 |
393 |
340 $r = 0; |
394 check_ajax_referer( "approve-comment_$id" ); |
341 if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) { |
395 if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) |
342 check_ajax_referer( "approve-comment_$id" ); |
|
343 $result = wp_set_comment_status( $comment->comment_ID, 'approve', true ); |
396 $result = wp_set_comment_status( $comment->comment_ID, 'approve', true ); |
344 } else { |
397 else |
345 check_ajax_referer( "unapprove-comment_$id" ); |
|
346 $result = wp_set_comment_status( $comment->comment_ID, 'hold', true ); |
398 $result = wp_set_comment_status( $comment->comment_ID, 'hold', true ); |
347 } |
399 |
348 if ( is_wp_error($result) ) { |
400 if ( is_wp_error($result) ) { |
349 $x = new WP_Ajax_Response( array( |
401 $x = new WP_Ajax_Response( array( |
350 'what' => 'comment', |
402 'what' => 'comment', |
351 'id' => $result |
403 'id' => $result |
352 ) ); |
404 ) ); |
364 $names = explode(',', $_POST['newcat']); |
416 $names = explode(',', $_POST['newcat']); |
365 if ( 0 > $parent = (int) $_POST['newcat_parent'] ) |
417 if ( 0 > $parent = (int) $_POST['newcat_parent'] ) |
366 $parent = 0; |
418 $parent = 0; |
367 $post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array(); |
419 $post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array(); |
368 $checked_categories = array_map( 'absint', (array) $post_category ); |
420 $checked_categories = array_map( 'absint', (array) $post_category ); |
369 $popular_ids = isset( $_POST['popular_ids'] ) ? |
421 $popular_ids = wp_popular_terms_checklist('category', 0, 10, false); |
370 array_map( 'absint', explode( ',', $_POST['popular_ids'] ) ) : |
422 |
371 false; |
|
372 |
|
373 $x = new WP_Ajax_Response(); |
|
374 foreach ( $names as $cat_name ) { |
423 foreach ( $names as $cat_name ) { |
375 $cat_name = trim($cat_name); |
424 $cat_name = trim($cat_name); |
376 $category_nicename = sanitize_title($cat_name); |
425 $category_nicename = sanitize_title($cat_name); |
377 if ( '' === $category_nicename ) |
426 if ( '' === $category_nicename ) |
378 continue; |
427 continue; |
383 $category = get_category( $cat_id ); |
432 $category = get_category( $cat_id ); |
384 ob_start(); |
433 ob_start(); |
385 wp_category_checklist( 0, $cat_id, $checked_categories, $popular_ids ); |
434 wp_category_checklist( 0, $cat_id, $checked_categories, $popular_ids ); |
386 $data = ob_get_contents(); |
435 $data = ob_get_contents(); |
387 ob_end_clean(); |
436 ob_end_clean(); |
388 $x->add( array( |
437 $add = array( |
389 'what' => 'category', |
438 'what' => 'category', |
390 'id' => $cat_id, |
439 'id' => $cat_id, |
391 'data' => $data, |
440 'data' => str_replace( array("\n", "\t"), '', $data), |
392 'position' => -1 |
441 'position' => -1 |
393 ) ); |
442 ); |
394 } |
443 } |
395 if ( $parent ) { // Foncy - replace the parent and all its children |
444 if ( $parent ) { // Foncy - replace the parent and all its children |
396 $parent = get_category( $parent ); |
445 $parent = get_category( $parent ); |
|
446 $term_id = $parent->term_id; |
|
447 |
|
448 while ( $parent->parent ) { // get the top parent |
|
449 $parent = &get_category( $parent->parent ); |
|
450 if ( is_wp_error( $parent ) ) |
|
451 break; |
|
452 $term_id = $parent->term_id; |
|
453 } |
|
454 |
397 ob_start(); |
455 ob_start(); |
398 dropdown_categories( 0, $parent ); |
456 wp_category_checklist( 0, $term_id, $checked_categories, $popular_ids, null, false ); |
399 $data = ob_get_contents(); |
457 $data = ob_get_contents(); |
400 ob_end_clean(); |
458 ob_end_clean(); |
401 $x->add( array( |
459 $add = array( |
402 'what' => 'category', |
460 'what' => 'category', |
403 'id' => $parent->term_id, |
461 'id' => $term_id, |
404 'old_id' => $parent->term_id, |
462 'data' => str_replace( array("\n", "\t"), '', $data), |
405 'data' => $data, |
|
406 'position' => -1 |
463 'position' => -1 |
407 ) ); |
464 ); |
408 |
465 } |
409 } |
466 |
|
467 ob_start(); |
|
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(); |
|
470 ob_end_clean(); |
|
471 $add['supplemental'] = array( 'newcat_parent' => $sup ); |
|
472 |
|
473 $x = new WP_Ajax_Response( $add ); |
410 $x->send(); |
474 $x->send(); |
411 break; |
475 break; |
412 case 'add-link-category' : // On the Fly |
476 case 'add-link-category' : // On the Fly |
413 check_ajax_referer( $action ); |
477 check_ajax_referer( $action ); |
414 if ( !current_user_can( 'manage_categories' ) ) |
478 if ( !current_user_can( 'manage_categories' ) ) |
525 case 'add-tag' : // From Manage->Tags |
589 case 'add-tag' : // From Manage->Tags |
526 check_ajax_referer( 'add-tag' ); |
590 check_ajax_referer( 'add-tag' ); |
527 if ( !current_user_can( 'manage_categories' ) ) |
591 if ( !current_user_can( 'manage_categories' ) ) |
528 die('-1'); |
592 die('-1'); |
529 |
593 |
530 if ( '' === trim($_POST['name']) ) { |
594 $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; |
531 $x = new WP_Ajax_Response( array( |
595 $tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST ); |
532 'what' => 'tag', |
596 |
533 'id' => new WP_Error( 'name', __('You did not enter a tag name.') ) |
597 if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) { |
534 ) ); |
598 echo '<div class="error"><p>' . __('An error has occured. Please reload the page and try again.') . '</p></div>'; |
535 $x->send(); |
599 exit; |
536 } |
600 } |
537 |
601 |
538 if ( !empty($_POST['taxonomy']) ) |
602 echo _tag_row( $tag, '', $taxonomy ); |
539 $taxonomy = $_POST['taxonomy']; |
603 exit; |
540 else |
|
541 $taxonomy = 'post_tag'; |
|
542 |
|
543 $tag = wp_insert_term($_POST['name'], $taxonomy, $_POST ); |
|
544 |
|
545 if ( is_wp_error($tag) ) { |
|
546 $x = new WP_Ajax_Response( array( |
|
547 'what' => 'tag', |
|
548 'id' => $tag |
|
549 ) ); |
|
550 $x->send(); |
|
551 } |
|
552 |
|
553 if ( !$tag || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) |
|
554 die('0'); |
|
555 |
|
556 $tag_full_name = $tag->name; |
|
557 $tag_full_name = esc_attr($tag_full_name); |
|
558 |
|
559 $x = new WP_Ajax_Response( array( |
|
560 'what' => 'tag', |
|
561 'id' => $tag->term_id, |
|
562 'position' => '-1', |
|
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)) |
|
565 ) ); |
|
566 $x->send(); |
|
567 break; |
604 break; |
568 case 'get-tagcloud' : |
605 case 'get-tagcloud' : |
569 if ( !current_user_can( 'edit_posts' ) ) |
606 if ( !current_user_can( 'edit_posts' ) ) |
570 die('-1'); |
607 die('-1'); |
571 |
608 |
597 |
634 |
598 exit; |
635 exit; |
599 break; |
636 break; |
600 case 'add-comment' : |
637 case 'add-comment' : |
601 check_ajax_referer( $action ); |
638 check_ajax_referer( $action ); |
602 if ( !current_user_can( 'edit_post', $id ) ) |
639 if ( !current_user_can( 'edit_posts' ) ) |
603 die('-1'); |
640 die('-1'); |
604 $search = isset($_POST['s']) ? $_POST['s'] : false; |
641 $search = isset($_POST['s']) ? $_POST['s'] : false; |
605 $status = isset($_POST['comment_status']) ? $_POST['comment_status'] : 'all'; |
642 $status = isset($_POST['comment_status']) ? $_POST['comment_status'] : 'all'; |
606 $per_page = isset($_POST['per_page']) ? (int) $_POST['per_page'] + 8 : 28; |
643 $per_page = isset($_POST['per_page']) ? (int) $_POST['per_page'] + 8 : 28; |
607 $start = isset($_POST['page']) ? ( intval($_POST['page']) * $per_page ) -1 : $per_page - 1; |
644 $start = isset($_POST['page']) ? ( intval($_POST['page']) * $per_page ) -1 : $per_page - 1; |
672 |
709 |
673 $status = $wpdb->get_var( $wpdb->prepare("SELECT post_status FROM $wpdb->posts WHERE ID = %d", $comment_post_ID) ); |
710 $status = $wpdb->get_var( $wpdb->prepare("SELECT post_status FROM $wpdb->posts WHERE ID = %d", $comment_post_ID) ); |
674 |
711 |
675 if ( empty($status) ) |
712 if ( empty($status) ) |
676 die('1'); |
713 die('1'); |
677 elseif ( in_array($status, array('draft', 'pending') ) ) |
714 elseif ( in_array($status, array('draft', 'pending', 'trash') ) ) |
678 die( __('Error: you are replying to a comment on a draft post.') ); |
715 die( __('Error: you are replying to a comment on a draft post.') ); |
679 |
716 |
680 $user = wp_get_current_user(); |
717 $user = wp_get_current_user(); |
681 if ( $user->ID ) { |
718 if ( $user->ID ) { |
682 $comment_author = $wpdb->escape($user->display_name); |
719 $comment_author = $wpdb->escape($user->display_name); |
883 /* translators: draft saved date format, see http://php.net/date */ |
920 /* translators: draft saved date format, see http://php.net/date */ |
884 $draft_saved_date_format = __('g:i:s a'); |
921 $draft_saved_date_format = __('g:i:s a'); |
885 $message = sprintf( __('Draft Saved at %s.'), date_i18n( $draft_saved_date_format ) ); |
922 $message = sprintf( __('Draft Saved at %s.'), date_i18n( $draft_saved_date_format ) ); |
886 |
923 |
887 $supplemental = array(); |
924 $supplemental = array(); |
|
925 if ( isset($login_grace_period) ) |
|
926 $supplemental['session_expired'] = add_query_arg( 'interim-login', 1, wp_login_url() ); |
888 |
927 |
889 $id = $revision_id = 0; |
928 $id = $revision_id = 0; |
890 if($_POST['post_ID'] < 0) { |
929 if($_POST['post_ID'] < 0) { |
891 $_POST['post_status'] = 'draft'; |
930 $_POST['post_status'] = 'draft'; |
892 $_POST['temp_ID'] = $_POST['post_ID']; |
931 $_POST['temp_ID'] = $_POST['post_ID']; |
962 $x->send(); |
1001 $x->send(); |
963 break; |
1002 break; |
964 case 'autosave-generate-nonces' : |
1003 case 'autosave-generate-nonces' : |
965 check_ajax_referer( 'autosave', 'autosavenonce' ); |
1004 check_ajax_referer( 'autosave', 'autosavenonce' ); |
966 $ID = (int) $_POST['post_ID']; |
1005 $ID = (int) $_POST['post_ID']; |
967 if($_POST['post_type'] == 'post') { |
1006 $post_type = ( 'page' == $_POST['post_type'] ) ? 'page' : 'post'; |
968 if(current_user_can('edit_post', $ID)) |
1007 if ( current_user_can( "edit_{$post_type}", $ID ) ) |
969 die(wp_create_nonce('update-post_' . $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}" ) ) ) ) ); |
970 } |
1009 do_action('autosave_generate_nonces'); |
971 if($_POST['post_type'] == 'page') { |
|
972 if(current_user_can('edit_page', $ID)) { |
|
973 die(wp_create_nonce('update-page_' . $ID)); |
|
974 } |
|
975 } |
|
976 die('0'); |
1010 die('0'); |
977 break; |
1011 break; |
978 case 'closed-postboxes' : |
1012 case 'closed-postboxes' : |
979 check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' ); |
1013 check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' ); |
980 $closed = isset( $_POST['closed'] ) ? $_POST['closed'] : ''; |
1014 $closed = isset( $_POST['closed'] ) ? $_POST['closed'] : ''; |
991 |
1025 |
992 if ( is_array($closed) ) |
1026 if ( is_array($closed) ) |
993 update_usermeta($user->ID, 'closedpostboxes_'.$page, $closed); |
1027 update_usermeta($user->ID, 'closedpostboxes_'.$page, $closed); |
994 |
1028 |
995 if ( is_array($hidden) ) { |
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 update_usermeta($user->ID, 'meta-box-hidden_'.$page, $hidden); |
1031 update_usermeta($user->ID, 'meta-box-hidden_'.$page, $hidden); |
998 } |
1032 } |
999 |
1033 |
1000 die('1'); |
1034 die('1'); |
1001 break; |
1035 break; |
1146 else |
1180 else |
1147 die( __('Category not updated.') ); |
1181 die( __('Category not updated.') ); |
1148 |
1182 |
1149 break; |
1183 break; |
1150 case 'tag' : |
1184 case 'tag' : |
1151 if ( !empty($_POST['taxonomy']) ) |
1185 $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; |
1152 $taxonomy = $_POST['taxonomy']; |
|
1153 else |
|
1154 $taxonomy = 'post_tag'; |
|
1155 |
1186 |
1156 $tag = get_term( $id, $taxonomy ); |
1187 $tag = get_term( $id, $taxonomy ); |
1157 $_POST['description'] = $tag->description; |
1188 $_POST['description'] = $tag->description; |
1158 |
1189 |
1159 $updated = wp_update_term($id, $taxonomy, $_POST); |
1190 $updated = wp_update_term($id, $taxonomy, $_POST); |
1160 if ( $updated && !is_wp_error($updated) ) { |
1191 if ( $updated && !is_wp_error($updated) ) { |
1161 $tag = get_term( $updated['term_id'], $taxonomy ); |
1192 $tag = get_term( $updated['term_id'], $taxonomy ); |
1162 if ( !$tag || is_wp_error( $tag ) ) |
1193 if ( !$tag || is_wp_error( $tag ) ) |
1163 die( __('Tag not updated.') ); |
1194 die( __('Tag not updated.') ); |
1164 |
1195 |
1165 echo _tag_row($tag); |
1196 echo _tag_row($tag, '', $taxonomy); |
1166 } else { |
1197 } else { |
1167 die( __('Tag not updated.') ); |
1198 die( __('Tag not updated.') ); |
1168 } |
1199 } |
1169 |
1200 |
1170 break; |
1201 break; |
1179 exit; |
1210 exit; |
1180 |
1211 |
1181 $what = isset($_POST['pages']) ? 'page' : 'post'; |
1212 $what = isset($_POST['pages']) ? 'page' : 'post'; |
1182 $s = stripslashes($_POST['ps']); |
1213 $s = stripslashes($_POST['ps']); |
1183 preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches); |
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]); |
1185 |
1216 |
1186 $searchand = $search = ''; |
1217 $searchand = $search = ''; |
1187 foreach( (array) $search_terms as $term) { |
1218 foreach ( (array) $search_terms as $term ) { |
1188 $term = addslashes_gpc($term); |
1219 $term = addslashes_gpc($term); |
1189 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))"; |
1220 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))"; |
1190 $searchand = ' AND '; |
1221 $searchand = ' AND '; |
1191 } |
1222 } |
1192 $term = $wpdb->escape($s); |
1223 $term = $wpdb->escape($s); |
1193 if ( count($search_terms) > 1 && $search_terms[0] != $s ) |
1224 if ( count($search_terms) > 1 && $search_terms[0] != $s ) |
1194 $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')"; |
1225 $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')"; |
1195 |
1226 |
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" ); |
1197 |
1228 |
1198 if ( ! $posts ) |
1229 if ( ! $posts ) |
1199 exit( __('No posts found.') ); |
1230 exit( __('No posts found.') ); |
1200 |
1231 |
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 foreach ( $posts as $post ) { |
1233 foreach ( $posts as $post ) { |
1203 |
1234 |
1204 switch ( $post->post_status ) { |
1235 switch ( $post->post_status ) { |
1205 case 'publish' : |
1236 case 'publish' : |
1206 case 'private' : |
1237 case 'private' : |
1346 if ( $form = $wp_registered_widget_controls[$widget_id] ) |
1377 if ( $form = $wp_registered_widget_controls[$widget_id] ) |
1347 call_user_func_array( $form['callback'], $form['params'] ); |
1378 call_user_func_array( $form['callback'], $form['params'] ); |
1348 |
1379 |
1349 die(); |
1380 die(); |
1350 break; |
1381 break; |
|
1382 case 'image-editor': |
|
1383 $attachment_id = intval($_POST['postid']); |
|
1384 if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) ) |
|
1385 die('-1'); |
|
1386 |
|
1387 check_ajax_referer( "image_editor-$attachment_id" ); |
|
1388 include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); |
|
1389 |
|
1390 $msg = false; |
|
1391 switch ( $_POST['do'] ) { |
|
1392 case 'save' : |
|
1393 $msg = wp_save_image($attachment_id); |
|
1394 $msg = json_encode($msg); |
|
1395 die($msg); |
|
1396 break; |
|
1397 case 'scale' : |
|
1398 $msg = wp_save_image($attachment_id); |
|
1399 break; |
|
1400 case 'restore' : |
|
1401 $msg = wp_restore_image($attachment_id); |
|
1402 break; |
|
1403 } |
|
1404 |
|
1405 wp_image_editor($attachment_id, $msg); |
|
1406 die(); |
|
1407 break; |
|
1408 case 'set-post-thumbnail': |
|
1409 $post_id = intval( $_POST['post_id'] ); |
|
1410 if ( !current_user_can( 'edit_post', $post_id ) ) |
|
1411 die( '-1' ); |
|
1412 $thumbnail_id = intval( $_POST['thumbnail_id'] ); |
|
1413 |
|
1414 if ( $thumbnail_id == '-1' ) { |
|
1415 delete_post_meta( $post_id, '_thumbnail_id' ); |
|
1416 die( _wp_post_thumbnail_html() ); |
|
1417 } |
|
1418 |
|
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 ) ); |
|
1424 } |
|
1425 } |
|
1426 die( '0' ); |
1351 default : |
1427 default : |
1352 do_action( 'wp_ajax_' . $_POST['action'] ); |
1428 do_action( 'wp_ajax_' . $_POST['action'] ); |
1353 die('0'); |
1429 die('0'); |
1354 break; |
1430 break; |
1355 endswitch; |
1431 endswitch; |