Comments post-box: show comments on the currently edited post with ajax, 20 at a time
git-svn-id: http://svn.automattic.com/wordpress/trunk@9225 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d40277d4c0
commit
b7959c1d28
|
@ -442,6 +442,36 @@ case 'add-comment' :
|
|||
}
|
||||
$x->send();
|
||||
break;
|
||||
case 'get-comments' :
|
||||
check_ajax_referer( $action );
|
||||
|
||||
$post_ID = (int) $_POST['post_ID'];
|
||||
if ( !current_user_can( 'edit_post', $post_ID ) )
|
||||
die('-1');
|
||||
|
||||
$start = isset($_POST['start']) ? intval($_POST['start']) : 0;
|
||||
$num = isset($_POST['num']) ? intval($_POST['num']) : 10;
|
||||
|
||||
list($comments, $total) = _wp_get_comment_list( false, false, $start, $num, $post_ID );
|
||||
|
||||
if ( !$comments )
|
||||
die('1');
|
||||
|
||||
$comment_list_item = '';
|
||||
$x = new WP_Ajax_Response();
|
||||
foreach ( (array) $comments as $comment ) {
|
||||
get_comment( $comment );
|
||||
ob_start();
|
||||
_wp_comment_row( $comment->comment_ID, 'single', false, false );
|
||||
$comment_list_item .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
}
|
||||
$x->add( array(
|
||||
'what' => 'comments',
|
||||
'data' => $comment_list_item
|
||||
) );
|
||||
$x->send();
|
||||
break;
|
||||
case 'replyto-comment' :
|
||||
check_ajax_referer( $action );
|
||||
|
||||
|
|
|
@ -341,17 +341,13 @@ function post_comment_status_meta_box($post) {
|
|||
</p>
|
||||
<?php
|
||||
|
||||
if ( !$post_ID || $post_ID < 0 )
|
||||
if ( !$post_ID || $post_ID < 0 || 0 == $post->comment_count )
|
||||
return;
|
||||
|
||||
if ( !$comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved != 'spam' ORDER BY comment_date", $post_ID) ) )
|
||||
return;
|
||||
|
||||
// Make sure comments, post, and post_author are cached
|
||||
// update_comment_cache($comments);
|
||||
wp_nonce_field( 'get-comments', 'add_comment_nonce', false );
|
||||
?>
|
||||
|
||||
<table class="widefat">
|
||||
<table class="widefat comments-box" style="display:none;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e('Comments') ?></th>
|
||||
|
@ -360,13 +356,9 @@ function post_comment_status_meta_box($post) {
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody id="the-comment-list" class="list:comment">
|
||||
<?php
|
||||
foreach ($comments as $comment)
|
||||
_wp_comment_row( $comment, 'single', false, false );
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p class="hide-if-no-js"><a href="#commentstatusdiv" id="show-comments" onclick="commentsBox.get();return false;"><?php _e('Show comments'); ?></a> <img class="waiting" style="display:none;" src="images/loading.gif" alt="" /></p>
|
||||
<?php
|
||||
}
|
||||
add_meta_box('commentstatusdiv', __('Comments on this Post'), 'post_comment_status_meta_box', 'post', 'normal', 'core');
|
||||
|
|
|
@ -153,7 +153,7 @@ commentReply = {
|
|||
|
||||
t.o = '#comment-'+id;
|
||||
|
||||
$('#replyrow td').attr('colspan', $('.widefat tfoot th:visible').length);
|
||||
$('#replyrow td').attr('colspan', $('.widefat thead th:visible').length);
|
||||
var editRow = $('#replyrow'), rowData = $('#inline-'+id);
|
||||
var act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
|
||||
|
||||
|
|
|
@ -202,7 +202,7 @@ jQuery(document).ready( function($) {
|
|||
return s;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('.edit-post-status').click(function() {
|
||||
if ($('#post-status-select').is(":hidden")) {
|
||||
$('#post-status-select').slideDown("normal");
|
||||
|
@ -216,16 +216,66 @@ jQuery(document).ready( function($) {
|
|||
$('#post-status-select').slideUp("normal");
|
||||
$('#post-status-display').html($('#post_status :selected').text());
|
||||
$('.edit-post-status').show();
|
||||
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
$('.cancel-post-status').click(function() {
|
||||
$('#post-status-select').slideUp("normal");
|
||||
$('#post_status').val($('#hidden_post_status').val());
|
||||
$('#post-status-display').html($('#post_status :selected').text());
|
||||
$('.edit-post-status').show();
|
||||
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
(function($){
|
||||
commentsBox = {
|
||||
st : 0,
|
||||
|
||||
get : function(id, nonce) {
|
||||
var st = this.st;
|
||||
this.st += 20;
|
||||
|
||||
$('.waiting').show();
|
||||
|
||||
var data = {
|
||||
'action' : 'get-comments',
|
||||
'mode' : 'single',
|
||||
'_ajax_nonce' : $('#add_comment_nonce').val(),
|
||||
'post_ID' : $('#post_ID').val(),
|
||||
'start' : st,
|
||||
'num' : '20'
|
||||
};
|
||||
|
||||
$.post('admin-ajax.php', data,
|
||||
function(r) {
|
||||
var r = wpAjax.parseAjaxResponse(r);
|
||||
$('#commentstatusdiv .widefat').show();
|
||||
$('.waiting').hide();
|
||||
|
||||
if ( 'object' == typeof r && r.responses[0] ) {
|
||||
$('#the-comment-list').append( r.responses[0].data );
|
||||
$('#the-comment-list .hide-if-no-js').removeClass('hide-if-no-js');
|
||||
|
||||
theList = theExtraList = null;
|
||||
$("a[className*=':']").unbind();
|
||||
setCommentsList();
|
||||
$('#show-comments').html(postL10n.showcomm);
|
||||
return;
|
||||
} else if ( 1 == r ) {
|
||||
$('#show-comments').parent().html(postL10n.endcomm);
|
||||
return;
|
||||
}
|
||||
|
||||
$('#the-comment-list').append('<tr><td colspan="5">'+wpAjax.broken+'</td></tr>');
|
||||
}
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
|
||||
|
|
|
@ -1083,6 +1083,11 @@ table.form-table td .updated {
|
|||
margin: 11px 0;
|
||||
}
|
||||
|
||||
#side-sortables .comments-box,
|
||||
#side-sortables #show-comments {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#mediadiv img {
|
||||
float: left;
|
||||
margin-right: 1em;
|
||||
|
@ -1975,7 +1980,8 @@ a.togbox {
|
|||
}
|
||||
|
||||
#replysubmit img.waiting,
|
||||
.quick-edit-save img.waiting {
|
||||
.quick-edit-save img.waiting,
|
||||
#commentstatusdiv img.waiting {
|
||||
padding: 0 10px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
|
|
@ -183,6 +183,8 @@ function wp_default_scripts( &$scripts ) {
|
|||
'separate' => __('Separate tags with commas'),
|
||||
'cancel' => __('Cancel'),
|
||||
'edit' => __('Edit'),
|
||||
'showcomm' => __('Show more comments'),
|
||||
'endcomm' => __('No more comments found.')
|
||||
) );
|
||||
$scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox', 'settings-box'), '20080925' );
|
||||
$scripts->localize( 'page', 'postL10n', array(
|
||||
|
|
Loading…
Reference in New Issue