Changeset 10204 for trunk/wp-admin/admin-ajax.php
- Timestamp:
- 12/14/2008 12:13:30 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/admin-ajax.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r10150 r10204 64 64 endif; 65 65 66 /** 67 * Sends back current comment total and new page links if they need to be updated. 68 * 69 * Contrary to normal success AJAX response ("1"), die with time() on success. 70 * 71 * @since 2.7 72 * 73 * @param int $comment_id 74 * @return die 75 */ 76 function _wp_ajax_delete_comment_response( $comment_id ) { 77 $total = (int) @$_POST['_total']; 78 $per_page = (int) @$_POST['_per_page']; 79 $page = (int) @$_POST['_page']; 80 $url = clean_url( @$_POST['_url'], null, 'url' ); 81 // JS didn't send us everything we need to know. Just die with success message 82 if ( !$total || !$per_page || !$page || !$url ) 83 die( (string) time() ); 84 85 if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one) 86 $total = 0; 87 88 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 89 die( (string) time() ); 90 91 $status = 'total_comments'; // What type of comment count are we looking for? 92 $parsed = parse_url( $url ); 93 if ( isset( $parsed['query'] ) ) { 94 parse_str( $parsed['query'], $query_vars ); 95 if ( !empty( $query_vars['comment_status'] ) ) 96 $status = $query_vars['comment_status']; 97 } 98 99 $comment_count = wp_count_comments(); 100 $time = time(); // The time since the last comment count 101 102 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count 103 $total = $comment_count->$status; 104 // else use the decremented value from above 105 106 $page_links = paginate_links( array( 107 'base' => add_query_arg( 'apage', '%#%', $url ), 108 'format' => '', 109 'prev_text' => __('«'), 110 'next_text' => __('»'), 111 'total' => ceil($total / $per_page), 112 'current' => $page 113 ) ); 114 $x = new WP_Ajax_Response( array( 115 'what' => 'comment', 116 'id' => $comment_id, // here for completeness - not used 117 'supplemental' => array( 118 'pageLinks' => $page_links, 119 'total' => $total, 120 'time' => $time 121 ) 122 ) ); 123 $x->send(); 124 } 125 66 126 $id = isset($_POST['id'])? (int) $_POST['id'] : 0; 67 127 switch ( $action = $_POST['action'] ) : 68 case 'delete-comment' : 128 case 'delete-comment' : // On success, die with time() instead of 1 69 129 check_ajax_referer( "delete-comment_$id" ); 70 130 if ( !$comment = get_comment( $id ) ) 71 die( '1');131 die( (string) time() ); 72 132 if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) 73 133 die('-1'); … … 75 135 if ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { 76 136 if ( 'spam' == wp_get_comment_status( $comment->comment_ID ) ) 77 die( '1');137 die( (string) time() ); 78 138 $r = wp_set_comment_status( $comment->comment_ID, 'spam' ); 79 139 } else { 80 140 $r = wp_delete_comment( $comment->comment_ID ); 81 141 } 82 83 die( $r ? '1' : '0' ); 142 if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts 143 _wp_ajax_delete_comment_response( $comment->comment_ID ); 144 die( '0' ); 84 145 break; 85 146 case 'delete-cat' : … … 196 257 die('0'); 197 258 break; 198 case 'dim-comment' : 259 case 'dim-comment' : // On success, die with time() instead of 1 199 260 if ( !$comment = get_comment( $id ) ) 200 261 die('0'); … … 207 268 $current = wp_get_comment_status( $comment->comment_ID ); 208 269 if ( $_POST['new'] == $current ) 209 die('1'); 210 270 die( (string) time() ); 271 272 $r = 0; 211 273 if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) { 212 274 check_ajax_referer( "approve-comment_$id" ); 213 275 if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) ) 214 die('1');276 $r = 1; 215 277 } else { 216 278 check_ajax_referer( "unapprove-comment_$id" ); 217 279 if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) ) 218 die('1'); 219 } 220 die('0'); 280 $r = 1; 281 } 282 if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts 283 _wp_ajax_delete_comment_response( $comment->comment_ID ); 284 die( '0' ); 221 285 break; 222 286 case 'add-category' : // On the Fly
Note: See TracChangeset
for help on using the changeset viewer.