X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/d3b1ea255664edd2deef17f900a655613d20820d..refs/tags/wordpress-2.9:/wp-admin/admin-ajax.php diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 1fd0df53..5778a12e 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -37,8 +37,8 @@ if ( ! is_user_logged_in() ) { $x->send(); } - if ( !empty( $_POST['action']) ) - do_action( 'wp_ajax_nopriv_' . $_POST['action'] ); + if ( !empty( $_REQUEST['action']) ) + do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] ); die('-1'); } @@ -91,6 +91,8 @@ case 'wp-compression-test' : echo $test_str; die; } elseif ( 2 == $_GET['test'] ) { + if ( !isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) + die('-1'); if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) { header('Content-Encoding: deflate'); $out = gzdeflate( $test_str, 1 ); @@ -111,6 +113,23 @@ case 'wp-compression-test' : die('0'); break; +case 'imgedit-preview' : + $post_id = intval($_GET['postid']); + if ( empty($post_id) || !current_user_can('edit_post', $post_id) ) + die('-1'); + + check_ajax_referer( "image_editor-$post_id" ); + + include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); + if ( !stream_preview_image($post_id) ) + die('-1'); + + die(); + break; +case 'oembed-cache' : + $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0'; + die( $return ); + break; default : do_action( 'wp_ajax_' . $_GET['action'] ); die('0'); @@ -143,15 +162,18 @@ function _wp_ajax_delete_comment_response( $comment_id ) { 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 die( (string) time() ); + $post_id = 0; $status = 'total_comments'; // What type of comment count are we looking for? $parsed = parse_url( $url ); if ( isset( $parsed['query'] ) ) { parse_str( $parsed['query'], $query_vars ); if ( !empty( $query_vars['comment_status'] ) ) $status = $query_vars['comment_status']; + if ( !empty( $query_vars['p'] ) ) + $post_id = (int) $query_vars['p']; } - $comment_count = wp_count_comments(); + $comment_count = wp_count_comments($post_id); $time = time(); // The time since the last comment count if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count @@ -181,19 +203,36 @@ function _wp_ajax_delete_comment_response( $comment_id ) { $id = isset($_POST['id'])? (int) $_POST['id'] : 0; switch ( $action = $_POST['action'] ) : case 'delete-comment' : // On success, die with time() instead of 1 - check_ajax_referer( "delete-comment_$id" ); if ( !$comment = get_comment( $id ) ) die( (string) time() ); if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) die('-1'); - if ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { - if ( 'spam' == wp_get_comment_status( $comment->comment_ID ) ) + check_ajax_referer( "delete-comment_$id" ); + $status = wp_get_comment_status( $comment->comment_ID ); + + if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { + if ( 'trash' == $status ) die( (string) time() ); - $r = wp_set_comment_status( $comment->comment_ID, 'spam' ); - } else { + $r = wp_trash_comment( $comment->comment_ID ); + } elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) { + if ( 'trash' != $status ) + die( (string) time() ); + $r = wp_untrash_comment( $comment->comment_ID ); + } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { + if ( 'spam' == $status ) + die( (string) time() ); + $r = wp_spam_comment( $comment->comment_ID ); + } elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) { + if ( 'spam' != $status ) + die( (string) time() ); + $r = wp_unspam_comment( $comment->comment_ID ); + } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) { $r = wp_delete_comment( $comment->comment_ID ); + } else { + die('-1'); } + if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts _wp_ajax_delete_comment_response( $comment->comment_ID ); die( '0' ); @@ -213,20 +252,18 @@ case 'delete-cat' : die('0'); break; case 'delete-tag' : - check_ajax_referer( "delete-tag_$id" ); + $tag_id = (int) $_POST['tag_ID']; + check_ajax_referer( "delete-tag_$tag_id" ); if ( !current_user_can( 'manage_categories' ) ) die('-1'); - if ( !empty($_POST['taxonomy']) ) - $taxonomy = $_POST['taxonomy']; - else - $taxonomy = 'post_tag'; + $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; - $tag = get_term( $id, $taxonomy ); + $tag = get_term( $tag_id, $taxonomy ); if ( !$tag || is_wp_error( $tag ) ) die('1'); - if ( wp_delete_term($id, $taxonomy)) + if ( wp_delete_term($tag_id, $taxonomy)) die('1'); else die('0'); @@ -305,6 +342,25 @@ case 'delete-post' : else die('0'); break; +case 'trash-post' : +case 'untrash-post' : + check_ajax_referer( "{$action}_$id" ); + if ( !current_user_can( 'delete_post', $id ) ) + die('-1'); + + if ( !get_post( $id ) ) + die('1'); + + if ( 'trash-post' == $action ) + $done = wp_trash_post( $id ); + else + $done = wp_untrash_post( $id ); + + if ( $done ) + die('1'); + + die('0'); + break; case 'delete-page' : check_ajax_referer( "{$action}_$id" ); if ( !current_user_can( 'delete_page', $id ) ) @@ -328,23 +384,19 @@ case 'dim-comment' : // On success, die with time() instead of 1 $x->send(); } - if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) - die('-1'); - if ( !current_user_can( 'moderate_comments' ) ) + if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) && !current_user_can( 'moderate_comments' ) ) die('-1'); $current = wp_get_comment_status( $comment->comment_ID ); if ( $_POST['new'] == $current ) die( (string) time() ); - $r = 0; - if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) { - check_ajax_referer( "approve-comment_$id" ); + check_ajax_referer( "approve-comment_$id" ); + if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) $result = wp_set_comment_status( $comment->comment_ID, 'approve', true ); - } else { - check_ajax_referer( "unapprove-comment_$id" ); + else $result = wp_set_comment_status( $comment->comment_ID, 'hold', true ); - } + if ( is_wp_error($result) ) { $x = new WP_Ajax_Response( array( 'what' => 'comment', @@ -366,11 +418,8 @@ case 'add-category' : // On the Fly $parent = 0; $post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array(); $checked_categories = array_map( 'absint', (array) $post_category ); - $popular_ids = isset( $_POST['popular_ids'] ) ? - array_map( 'absint', explode( ',', $_POST['popular_ids'] ) ) : - false; + $popular_ids = wp_popular_terms_checklist('category', 0, 10, false); - $x = new WP_Ajax_Response(); foreach ( $names as $cat_name ) { $cat_name = trim($cat_name); $category_nicename = sanitize_title($cat_name); @@ -385,28 +434,43 @@ case 'add-category' : // On the Fly wp_category_checklist( 0, $cat_id, $checked_categories, $popular_ids ); $data = ob_get_contents(); ob_end_clean(); - $x->add( array( + $add = array( 'what' => 'category', 'id' => $cat_id, - 'data' => $data, + 'data' => str_replace( array("\n", "\t"), '', $data), 'position' => -1 - ) ); + ); } if ( $parent ) { // Foncy - replace the parent and all its children $parent = get_category( $parent ); + $term_id = $parent->term_id; + + while ( $parent->parent ) { // get the top parent + $parent = &get_category( $parent->parent ); + if ( is_wp_error( $parent ) ) + break; + $term_id = $parent->term_id; + } + ob_start(); - dropdown_categories( 0, $parent ); + wp_category_checklist( 0, $term_id, $checked_categories, $popular_ids, null, false ); $data = ob_get_contents(); ob_end_clean(); - $x->add( array( + $add = array( 'what' => 'category', - 'id' => $parent->term_id, - 'old_id' => $parent->term_id, - 'data' => $data, + 'id' => $term_id, + 'data' => str_replace( array("\n", "\t"), '', $data), 'position' => -1 - ) ); - + ); } + + ob_start(); + wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category') ) ); + $sup = ob_get_contents(); + ob_end_clean(); + $add['supplemental'] = array( 'newcat_parent' => $sup ); + + $x = new WP_Ajax_Response( $add ); $x->send(); break; case 'add-link-category' : // On the Fly @@ -527,43 +591,16 @@ case 'add-tag' : // From Manage->Tags if ( !current_user_can( 'manage_categories' ) ) die('-1'); - if ( '' === trim($_POST['name']) ) { - $x = new WP_Ajax_Response( array( - 'what' => 'tag', - 'id' => new WP_Error( 'name', __('You did not enter a tag name.') ) - ) ); - $x->send(); - } - - if ( !empty($_POST['taxonomy']) ) - $taxonomy = $_POST['taxonomy']; - else - $taxonomy = 'post_tag'; - - $tag = wp_insert_term($_POST['name'], $taxonomy, $_POST ); + $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; + $tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST ); - if ( is_wp_error($tag) ) { - $x = new WP_Ajax_Response( array( - 'what' => 'tag', - 'id' => $tag - ) ); - $x->send(); + if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) { + echo '
' . __('An error has occured. Please reload the page and try again.') . '
'.__('Title').' | '.__('Time').' | '.__('Status').' |
---|
'.__('Title').' | '.__('Date').' | '.__('Status').' |
---|