+case 'closed-postboxes' :
+ check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
+ $closed = isset( $_POST['closed'] )? $_POST['closed'] : '';
+ $closed = explode( ',', $_POST['closed'] );
+ $hidden = isset( $_POST['hidden'] )? $_POST['hidden'] : '';
+ $hidden = explode( ',', $_POST['hidden'] );
+ $page = isset( $_POST['page'] )? $_POST['page'] : '';
+ if ( !preg_match( '/^[a-z-_]+$/', $page ) ) {
+ die(-1);
+ }
+ $current_user = wp_get_current_user();
+ if ( is_array($closed) )
+ update_usermeta($current_user->ID, 'closedpostboxes_'.$page, $closed);
+ if ( is_array($hidden) )
+ update_usermeta($current_user->ID, 'meta-box-hidden_'.$page, $hidden);
+break;
+case 'hidden-columns' :
+ check_ajax_referer( 'hiddencolumns', 'hiddencolumnsnonce' );
+ $hidden = isset( $_POST['hidden'] )? $_POST['hidden'] : '';
+ $hidden = explode( ',', $_POST['hidden'] );
+ $page = isset( $_POST['page'] )? $_POST['page'] : '';
+ if ( !preg_match( '/^[a-z-_]+$/', $page ) ) {
+ die(-1);
+ }
+ $current_user = wp_get_current_user();
+ if ( is_array($hidden) )
+ update_usermeta($current_user->ID, "manage-$page-columns-hidden", $hidden);
+break;
+case 'get-permalink':
+ check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
+ $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
+ die(add_query_arg(array('preview' => 'true'), get_permalink($post_id)));
+break;
+case 'sample-permalink':
+ check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
+ $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
+ $title = isset($_POST['new_title'])? $_POST['new_title'] : '';
+ $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : '';
+ die(get_sample_permalink_html($post_id, $title, $slug));
+break;
+case 'inline-save':
+ check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
+
+ if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) )
+ exit;
+
+ if ( 'page' == $_POST['post_type'] ) {
+ if ( ! current_user_can( 'edit_page', $post_ID ) )
+ die( __('You are not allowed to edit this page.') );
+ } else {
+ if ( ! current_user_can( 'edit_post', $post_ID ) )
+ die( __('You are not allowed to edit this post.') );
+ }
+
+ if ( $last = wp_check_post_lock( $post_ID ) ) {
+ $last_user = get_userdata( $last );
+ $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
+ printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ), wp_specialchars( $last_user_name ) );
+ exit;
+ }
+
+ $data = &$_POST;
+ $post = get_post( $post_ID, ARRAY_A );
+ $data['content'] = $post['post_content'];
+ $data['excerpt'] = $post['post_excerpt'];
+
+ // rename
+ $data['user_ID'] = $GLOBALS['user_ID'];
+
+ if ( isset($data['post_parent']) )
+ $data['parent_id'] = $data['post_parent'];
+
+ // status
+ if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
+ $data['post_status'] = 'private';
+ else
+ $data['post_status'] = $data['_status'];
+
+ if ( empty($data['comment_status']) )
+ $data['comment_status'] = 'closed';
+ if ( empty($data['ping_status']) )
+ $data['ping_status'] = 'closed';
+
+ // update the post
+ $_POST = $data;
+ edit_post();
+
+ $post = array();
+ if ( 'page' == $_POST['post_type'] ) {
+ $post[] = get_post($_POST['post_ID']);
+ page_rows($post);
+ } elseif ( 'post' == $_POST['post_type'] ) {
+ $mode = $_POST['post_view'];
+ $post[] = get_post($_POST['post_ID']);
+ post_rows($post);
+ }
+
+ exit;
+ break;
+case 'inline-save-tax':
+ check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
+
+ if ( ! current_user_can('manage_categories') )
+ die( __('Cheatin’ uh?') );
+
+ if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
+ die(-1);
+
+ switch ($_POST['tax_type']) {
+ case 'cat' :
+ $data = array();
+ $data['cat_ID'] = $id;
+ $data['cat_name'] = $_POST['name'];
+ $data['category_nicename'] = $_POST['slug'];
+ if ( isset($_POST['parent']) && (int) $_POST['parent'] > 0 )
+ $data['category_parent'] = $_POST['parent'];
+
+ $cat = get_category($id, ARRAY_A);
+ $data['category_description'] = $cat['category_description'];
+
+ $updated = wp_update_category($data);
+
+ if ( $updated && !is_wp_error($updated) )
+ echo _cat_row( $updated, 0 );
+ else
+ die( __('Category not updated.') );
+
+ break;
+ case 'link-cat' :
+ $updated = wp_update_term($id, 'link_category', $_POST);
+
+ if ( $updated && !is_wp_error($updated) )
+ echo link_cat_row($updated['term_id']);
+ else
+ die( __('Category not updated.') );
+
+ break;
+ case 'tag' :
+ $updated = wp_update_term($id, 'post_tag', $_POST);
+ if ( $updated && !is_wp_error($updated) ) {
+ $tag = get_term( $updated['term_id'], 'post_tag' );
+ if ( !$tag || is_wp_error( $tag ) )
+ die( __('Tag not updated.') );
+
+ echo _tag_row($tag);
+ } else {
+ die( __('Tag not updated.') );
+ }
+
+ break;
+ }
+
+ exit;
+ break;
+case 'meta-box-order':
+ check_ajax_referer( 'meta-box-order' );
+ update_user_option( $GLOBALS['current_user']->ID, "meta-box-order_$_POST[page]", $_POST['order'] );
+ die('1');
+ break;
+case 'find_posts':
+ check_ajax_referer( 'find-posts' );
+
+ if ( empty($_POST['ps']) )
+ exit;
+
+ $what = isset($_POST['pages']) ? 'page' : 'post';
+ $s = stripslashes($_POST['ps']);
+ preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
+ $search_terms = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
+
+ $searchand = $search = '';
+ foreach( (array) $search_terms as $term) {
+ $term = addslashes_gpc($term);
+ $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
+ $searchand = ' AND ';
+ }
+ $term = $wpdb->escape($s);
+ if ( count($search_terms) > 1 && $search_terms[0] != $s )
+ $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
+
+ $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" );
+
+ if ( ! $posts )
+ exit( __('No posts found.') );
+
+ $html = '<table class="widefat"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Time').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
+ foreach ( $posts as $post ) {
+
+ switch ( $post->post_status ) {
+ case 'publish' :
+ case 'private' :
+ $stat = __('Published');
+ break;
+ case 'future' :
+ $stat = __('Scheduled');
+ break;
+ case 'pending' :
+ $stat = __('Pending Review');
+ break;
+ case 'draft' :
+ $stat = __('Unpublished');
+ break;
+ }
+
+ if ( '0000-00-00 00:00:00' == $post->post_date ) {
+ $time = '';
+ } else {
+ $time = mysql2date(__('Y/m/d'), $post->post_date);
+ }
+
+ $html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="'.$post->ID.'"></td>';
+ $html .= '<td><label for="found-'.$post->ID.'">'.wp_specialchars($post->post_title, true).'</label></td><td>'.wp_specialchars($time, true).'</td><td>'.wp_specialchars($stat, true).'</td></tr>'."\n\n";
+ }
+ $html .= '</tbody></table>';
+
+ $x = new WP_Ajax_Response();
+ $x->add( array(
+ 'what' => $what,
+ 'data' => $html
+ ));
+ $x->send();
+
+ break;