Changeset 10204
- Timestamp:
- 12/14/2008 12:13:30 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
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 -
trunk/wp-admin/edit-comments.php
r10162 r10204 228 228 number_format_i18n( $start + 1 ), 229 229 number_format_i18n( min( $page * $comments_per_page, $total ) ), 230 number_format_i18n( $total ),230 '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>', 231 231 $page_links 232 232 ); echo $page_links_text; ?></div> 233 <input type="hidden" name="_total" value="<?php echo $total; ?>" /> 234 <input type="hidden" name="_per_page" value="<?php echo $comments_per_page; ?>" /> 235 <input type="hidden" name="_page" value="<?php echo $page; ?>" /> 233 236 <?php endif; ?> 234 237 -
trunk/wp-admin/js/edit-comments.js
r10150 r10204 3 3 4 4 setCommentsList = function() { 5 var totalInput = $('#comments-form .tablenav :input[name="_total"]'); 6 var perPageInput = $('#comments-form .tablenav :input[name="_per_page"]'); 7 var pageInput = $('#comments-form .tablenav :input[name="_page"]'); 8 var lastConfidentTime = 0; 9 5 10 var dimAfter = function( r, settings ) { 6 11 var c = $('#' + settings.element); … … 26 31 }; 27 32 33 // Send current total, page, per_page and url 34 var delBefore = function( settings ) { 35 settings.data._total = totalInput.val(); 36 settings.data._per_page = perPageInput.val(); 37 settings.data._page = pageInput.val(); 38 settings.data._url = document.location.href; 39 return settings; 40 }; 41 42 /* Updates the current total (as displayed visibly) 43 */ 44 var updateTotalCount = function( total, time, setConfidentTime ) { 45 if ( time < lastConfidentTime ) { 46 return; 47 } 48 totalInput.val( total.toString() ); 49 if ( setConfidentTime ) { 50 lastConfidentTime = time; 51 } 52 $('span.total-type-count').each( function() { 53 var a = $(this); 54 var n = totalInput.val().toString(); 55 if ( n.length > 3 ) 56 n = n.substr(0, n.length-3)+' '+n.substr(-3); 57 a.html(n); 58 }); 59 60 }; 61 62 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success 28 63 var delAfter = function( r, settings ) { 29 64 $('span.pending-count').each( function() { … … 45 80 }); 46 81 47 $('span.spam-count' 82 $('span.spam-count').each( function() { 48 83 var a = $(this); 49 84 var n = a.html().replace(/[ ,.]+/g, ''); … … 62 97 }); 63 98 99 100 // XML response 101 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { 102 // Set the total to the known good value (even if this value is a little old, newer values should only be a few less, and so shouldn't mess up the page links) 103 updateTotalCount( settings.parsed.responses[0].supplemental.total, settings.parsed.responses[0].supplemental.time, true ); 104 if ( $.trim( settings.parsed.responses[0].supplemental.pageLinks ) ) { 105 $('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( settings.parsed.responses[0].supplemental.pageLinks ) ); 106 } else if ( 'undefined' != typeof settings.parsed.responses[0].supplemental.pageLinks ) { 107 $('.tablenav-pages').find( '.page-numbers' ).remove(); 108 } 109 } else { 110 // Decrement the total 111 var total = parseInt( totalInput.val(), 10 ); 112 if ( total-- < 0 ) 113 total = 0; 114 updateTotalCount( total, r, false ); 115 } 116 64 117 if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 ) { 65 118 return; … … 71 124 72 125 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); 73 theList = $('#the-comment-list').wpList( { alt: '', d imAfter: dimAfter, delAfter: delAfter, addColor: 'none' } );126 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ); 74 127 75 128 }; -
trunk/wp-includes/general-template.php
r10150 r10204 1170 1170 $the_date .= $after; 1171 1171 $previousday = $day; 1172 } 1172 1173 1173 $the_date = apply_filters('the_date', $the_date, $d, $before, $after); 1174 1174 if ( $echo ) … … 1176 1176 else 1177 1177 return $the_date; 1178 } 1178 1179 } 1179 1180 -
trunk/wp-includes/script-loader.php
r10170 r10204 162 162 'l10n_print_after' => 'try{convertEntities(pwsL10n);}catch(e){};' 163 163 ) ); 164 $scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '2008121 0' );164 $scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '20081211' ); 165 165 $scripts->localize( 'admin-comments', 'adminCommentsL10n', array( 166 166 'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
Note: See TracChangeset
for help on using the changeset viewer.