From b7959c1d28b55a19cb5935158739f156bec4d60e Mon Sep 17 00:00:00 2001 From: azaozz Date: Fri, 17 Oct 2008 09:44:22 +0000 Subject: [PATCH] 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 --- wp-admin/admin-ajax.php | 30 +++++++++++++++++ wp-admin/edit-form-advanced.php | 16 +++------ wp-admin/js/edit-comments.js | 2 +- wp-admin/js/post.js | 58 ++++++++++++++++++++++++++++++--- wp-admin/wp-admin.css | 8 ++++- wp-includes/script-loader.php | 2 ++ 6 files changed, 98 insertions(+), 18 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 57ae7fea7..6eb2cd977 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -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 ); diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index a7feb8e85..647968954 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -341,17 +341,13 @@ function post_comment_status_meta_box($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 ); ?> - +
@@ -360,13 +356,9 @@ function post_comment_status_meta_box($post) { - - +

'+wpAjax.broken+''); + } + ); + + return false; + } + } + +})(jQuery); + diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css index b995cddf7..2f5fe2a8c 100644 --- a/wp-admin/wp-admin.css +++ b/wp-admin/wp-admin.css @@ -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; } diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 0073ad083..2d1eabb74 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -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(