Dynamically refill comment list when a comment is deleted. Props mdawaffe. fixes #4038
git-svn-id: https://develop.svn.wordpress.org/trunk@5118 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0ba70bb459
commit
8a15ffc657
@ -151,6 +151,31 @@ case 'add-cat' : // From Manage->Categories
|
||||
) );
|
||||
$x->send();
|
||||
break;
|
||||
case 'add-comment' :
|
||||
if ( !current_user_can( 'edit_post', $id ) )
|
||||
die('-1');
|
||||
$search = isset($_POST['s']) ? $_POST['s'] : false;
|
||||
$start = isset($_POST['page']) ? intval($_POST['page']) * 25 : 25;
|
||||
|
||||
list($comments, $total) = _wp_get_comment_list( $search, $start, 1 );
|
||||
|
||||
if ( !$comments )
|
||||
die('1');
|
||||
$x = new WP_Ajax_Response();
|
||||
foreach ( (array) $comments as $comment ) {
|
||||
get_comment( $comment );
|
||||
ob_start();
|
||||
_wp_comment_list_item( $comment->comment_ID );
|
||||
$comment_list_item = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$x->add( array(
|
||||
'what' => 'comment',
|
||||
'id' => $comment->comment_ID,
|
||||
'data' => $comment_list_item
|
||||
) );
|
||||
}
|
||||
$x->send();
|
||||
break;
|
||||
case 'add-meta' :
|
||||
if ( !current_user_can( 'edit_post', $id ) )
|
||||
die('-1');
|
||||
|
@ -909,6 +909,68 @@ function user_row( $user_object, $style = '' ) {
|
||||
return $r;
|
||||
}
|
||||
|
||||
function _wp_get_comment_list( $s = false, $start, $num ) {
|
||||
global $wpdb;
|
||||
|
||||
$start = (int) $start;
|
||||
$num = (int) $num;
|
||||
|
||||
if ( $s ) {
|
||||
$s = $wpdb->escape($s);
|
||||
$comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
|
||||
(comment_author LIKE '%$s%' OR
|
||||
comment_author_email LIKE '%$s%' OR
|
||||
comment_author_url LIKE ('%$s%') OR
|
||||
comment_author_IP LIKE ('%$s%') OR
|
||||
comment_content LIKE ('%$s%') ) AND
|
||||
comment_approved != 'spam'
|
||||
ORDER BY comment_date DESC LIMIT $start, $num");
|
||||
} else {
|
||||
$comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $num" );
|
||||
}
|
||||
|
||||
$total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
|
||||
|
||||
return array($comments, $total);
|
||||
}
|
||||
|
||||
function _wp_comment_list_item( $id, $alt = 0 ) {
|
||||
global $authordata, $comment, $wpdb;
|
||||
$id = (int) $id;
|
||||
$comment =& get_comment( $id );
|
||||
$class = '';
|
||||
$authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
|
||||
$comment_status = wp_get_comment_status($comment->comment_ID);
|
||||
if ( 'unapproved' == $comment_status )
|
||||
$class .= ' unapproved';
|
||||
if ( $alt % 2 )
|
||||
$class .= ' alternate';
|
||||
echo "<li id='comment-$comment->comment_ID' class='$class'>";
|
||||
?>
|
||||
<p><strong><?php comment_author(); ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
|
||||
|
||||
<?php comment_text() ?>
|
||||
|
||||
<p><?php comment_date(__('M j, g:i A')); ?> — [
|
||||
<?php
|
||||
if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
|
||||
echo " <a href='comment.php?action=editcomment&c=".$comment->comment_ID."'>" . __('Edit') . '</a>';
|
||||
echo ' | <a href="' . wp_nonce_url('ocomment.php?action=deletecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
|
||||
if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
|
||||
echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
|
||||
echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
|
||||
}
|
||||
echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&dt=spam&p=" . $comment->comment_post_ID . "&c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . "</a> ";
|
||||
}
|
||||
$post = get_post($comment->comment_post_ID);
|
||||
$post_title = wp_specialchars( $post->post_title, 'double' );
|
||||
$post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
|
||||
?>
|
||||
] — <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo $post_title; ?></a></p>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
|
||||
global $wpdb;
|
||||
if (!$categories )
|
||||
|
@ -2,15 +2,50 @@ addLoadEvent(function() {
|
||||
theCommentList = new listMan('the-comment-list');
|
||||
if ( !theCommentList )
|
||||
return false;
|
||||
|
||||
theExtraCommentList = new listMan('the-extra-comment-list');
|
||||
if ( theExtraCommentList ) {
|
||||
theExtraCommentList.showLink = 0;
|
||||
theExtraCommentList.altOffset = 1;
|
||||
if ( theExtraCommentList.theList && theExtraCommentList.theList.childNodes )
|
||||
var commentNum = $A(theExtraCommentList.theList.childNodes).findAll( function(i) { return Element.visible(i) } ).length;
|
||||
else
|
||||
var commentNum = 0;
|
||||
var urlQ = document.location.href.split('?');
|
||||
var params = urlQ[1] ? urlQ[1].toQueryParams() : [];
|
||||
var search = params['s'] ? params['s'] : '';
|
||||
var page = params['apage'] ? params['apage'] : 1;
|
||||
}
|
||||
|
||||
theCommentList.dimComplete = function(what,id,dimClass) {
|
||||
var m = document.getElementById('awaitmod');
|
||||
if ( document.getElementById(what + '-' + id).className.match(dimClass) ) m.innerHTML = parseInt(m.innerHTML,10) + 1;
|
||||
else m.innerHTML = parseInt(m.innerHTML,10) - 1;
|
||||
if ( document.getElementById(what + '-' + id).className.match(dimClass) )
|
||||
m.innerHTML = parseInt(m.innerHTML,10) + 1;
|
||||
else
|
||||
m.innerHTML = parseInt(m.innerHTML,10) - 1;
|
||||
}
|
||||
|
||||
theCommentList.delComplete = function(what,id) {
|
||||
var m = document.getElementById('awaitmod');
|
||||
if ( document.getElementById(what + '-' + id).className.match('unapproved') ) m.innerHTML = parseInt(m.innerHTML,10) - 1;
|
||||
if ( document.getElementById(what + '-' + id).className.match('unapproved') )
|
||||
m.innerHTML = parseInt(m.innerHTML,10) - 1;
|
||||
if ( theExtraCommentList && commentNum ) {
|
||||
var theMover = theExtraCommentList.theList.childNodes[0];
|
||||
Element.removeClassName(theMover,'alternate');
|
||||
theCommentList.theList.appendChild(theMover);
|
||||
theExtraCommentList.inputData += '&page=' + page;
|
||||
if ( search )
|
||||
theExtraCommentList.inputData += '&s=' + search; // trust the URL not the search box
|
||||
theExtraCommentList.addComplete = function() {
|
||||
if ( theExtraCommentList.theList.childNodes )
|
||||
var commentNum = $A(theExtraCommentList.theList.childNodes).findAll( function(i) { return Element.visible(i) } ).length;
|
||||
else
|
||||
var commentNum = 0;
|
||||
}
|
||||
theExtraCommentList.ajaxAdder( 'comment', 'ajax-response' ); // Dummy Request
|
||||
}
|
||||
}
|
||||
|
||||
if ( theList ) // the post list: edit.php
|
||||
theList.delComplete = function() {
|
||||
var comments = document.getElementById('comments');
|
||||
|
@ -75,104 +75,52 @@ if ( !empty( $_POST['delete_comments'] ) ) :
|
||||
echo '</p></div>';
|
||||
endif;
|
||||
|
||||
if (isset($_GET['s'])) {
|
||||
$s = $wpdb->escape($_GET['s']);
|
||||
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE
|
||||
(comment_author LIKE '%$s%' OR
|
||||
comment_author_email LIKE '%$s%' OR
|
||||
comment_author_url LIKE ('%$s%') OR
|
||||
comment_author_IP LIKE ('%$s%') OR
|
||||
comment_content LIKE ('%$s%') ) AND
|
||||
comment_approved != 'spam'
|
||||
ORDER BY comment_date DESC");
|
||||
} else {
|
||||
if ( isset( $_GET['apage'] ) )
|
||||
$page = (int) $_GET['apage'];
|
||||
else
|
||||
$page = 1;
|
||||
$start = $offset = ( $page - 1 ) * 20;
|
||||
if ( isset( $_GET['apage'] ) )
|
||||
$page = (int) $_GET['apage'];
|
||||
else
|
||||
$page = 1;
|
||||
$start = $offset = ( $page - 1 ) * 20;
|
||||
|
||||
$comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, 20" );
|
||||
$total = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1'" );
|
||||
}
|
||||
?>
|
||||
<?php if ( $total > 20 ) {
|
||||
$total_pages = ceil( $total / 20 );
|
||||
$r = '';
|
||||
if ( 1 < $page ) {
|
||||
$args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
|
||||
$r .= '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">« '. __('Previous Page') .'</a>' . "\n";
|
||||
}
|
||||
if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) {
|
||||
for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
|
||||
if ( $page == $page_num ) :
|
||||
$r .= "<span>$page_num</span>\n";
|
||||
else :
|
||||
$p = false;
|
||||
if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
|
||||
$args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num;
|
||||
$r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
|
||||
$in = true;
|
||||
elseif ( $in == true ) :
|
||||
$r .= "...\n";
|
||||
$in = false;
|
||||
endif;
|
||||
endif;
|
||||
endfor;
|
||||
}
|
||||
if ( ( $page ) * 20 < $total || -1 == $total ) {
|
||||
$args['apage'] = $page + 1;
|
||||
$r .= '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page') .' »</a>' . "\n";
|
||||
}
|
||||
echo "<p class='pagenav'>$r</p>";
|
||||
?>
|
||||
list($_comments, $total) = _wp_get_comment_list( isset($_GET['s']) ? $_GET['s'] : false, $start, 25 ); // Grab a few extra
|
||||
|
||||
<?php } ?>
|
||||
$comments = array_slice($_comments, 0, 20);
|
||||
$extra_comments = array_slice($_comments, 20);
|
||||
|
||||
$page_links = paginate_links( array(
|
||||
'base' => clean_url( add_query_arg( 'apage', '%#%' ) ),
|
||||
'format' => '',
|
||||
'total' => ceil($total / 20),
|
||||
'current' => $page
|
||||
));
|
||||
|
||||
if ( $page_links )
|
||||
echo "<p class='pagenav'>$page_links</p>";
|
||||
|
||||
<?php
|
||||
if ('view' == $mode) {
|
||||
if ($comments) {
|
||||
?>
|
||||
<?php
|
||||
$offset = $offset + 1;
|
||||
$start = " start='$offset'";
|
||||
$offset = $offset + 1;
|
||||
$start = " start='$offset'";
|
||||
|
||||
echo "<ol id='the-comment-list' class='commentlist' $start>";
|
||||
echo "<ol id='the-comment-list' class='commentlist' $start>\n";
|
||||
$i = 0;
|
||||
foreach ($comments as $comment) {
|
||||
++$i; $class = '';
|
||||
$authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
|
||||
$comment_status = wp_get_comment_status($comment->comment_ID);
|
||||
if ('unapproved' == $comment_status)
|
||||
$class .= ' unapproved';
|
||||
if ($i % 2)
|
||||
$class .= ' alternate';
|
||||
echo "<li id='comment-$comment->comment_ID' class='$class'>";
|
||||
?>
|
||||
<p><strong><?php comment_author() ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
|
||||
foreach ( $comments as $comment ) {
|
||||
get_comment( $comment ); // Cache it
|
||||
_wp_comment_list_item( $comment->comment_ID, ++$i );
|
||||
}
|
||||
echo "</ol>\n\n";
|
||||
|
||||
<?php comment_text() ?>
|
||||
|
||||
<p><?php comment_date(__('M j, g:i A')); ?> — [
|
||||
if ( $extra_comments ) : ?>
|
||||
<div id="extra-comments" style="display:none">
|
||||
<ul id="the-extra-comment-list" class="commentlist">
|
||||
<?php
|
||||
if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
|
||||
echo " <a href='comment.php?action=editcomment&c=".$comment->comment_ID."'>" . __('Edit') . '</a>';
|
||||
echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
|
||||
if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
|
||||
echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
|
||||
echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
|
||||
foreach ( $extra_comments as $comment ) {
|
||||
get_comment( $comment ); // Cache it
|
||||
_wp_comment_list_item( $comment->comment_ID, ++$i );
|
||||
}
|
||||
echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&dt=spam&p=" . $comment->comment_post_ID . "&c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . "</a> ";
|
||||
}
|
||||
$post = get_post($comment->comment_post_ID);
|
||||
$post_title = wp_specialchars( $post->post_title, 'double' );
|
||||
$post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
|
||||
?>
|
||||
] — <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo $post_title; ?></a></p>
|
||||
</li>
|
||||
|
||||
<?php } // end foreach($comment) ?>
|
||||
</ol>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; // $extra_comments ?>
|
||||
|
||||
<div id="ajax-response"></div>
|
||||
|
||||
@ -242,39 +190,11 @@ $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
|
||||
<?php
|
||||
} // end if ($comments)
|
||||
}
|
||||
?>
|
||||
<?php if ( $total > 20 ) {
|
||||
$total_pages = ceil( $total / 20 );
|
||||
$r = '';
|
||||
if ( 1 < $page ) {
|
||||
$args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
|
||||
$r .= '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">« '. __('Previous Page') .'</a>' . "\n";
|
||||
}
|
||||
if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) {
|
||||
for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
|
||||
if ( $page == $page_num ) :
|
||||
$r .= "<span>$page_num</span>\n";
|
||||
else :
|
||||
$p = false;
|
||||
if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
|
||||
$args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num;
|
||||
$r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
|
||||
$in = true;
|
||||
elseif ( $in == true ) :
|
||||
$r .= "...\n";
|
||||
$in = false;
|
||||
endif;
|
||||
endif;
|
||||
endfor;
|
||||
}
|
||||
if ( ( $page ) * 20 < $total || -1 == $total ) {
|
||||
$args['apage'] = $page + 1;
|
||||
$r .= '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page') .' »</a>' . "\n";
|
||||
}
|
||||
echo "<p class='pagenav'>$r</p>";
|
||||
?>
|
||||
|
||||
<?php } ?>
|
||||
if ( $page_links )
|
||||
echo "<p class='pagenav'>$page_links</p>";
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -34,7 +34,7 @@ class WP_Scripts {
|
||||
'strangeText' => __("Something strange happened. Try refreshing the page."),
|
||||
'whoaText' => __("Slow down, I'm still sending your data!")
|
||||
) );
|
||||
$this->add( 'listman', '/wp-includes/js/list-manipulation.js', array('wp-ajax', 'fat'), '20070306');
|
||||
$this->add( 'listman', '/wp-includes/js/list-manipulation.js', array('wp-ajax', 'fat'), '20070306' );
|
||||
$this->localize( 'listman', 'listManL10n', array(
|
||||
'jumpText' => __('Jump to new item'),
|
||||
'delText' => __('Are you sure you want to delete this %thing%?')
|
||||
@ -84,7 +84,7 @@ class WP_Scripts {
|
||||
) );
|
||||
$this->add( 'admin-categories', '/wp-admin/categories.js', array('listman'), '3684' );
|
||||
$this->add( 'admin-custom-fields', '/wp-admin/custom-fields.js', array('listman'), '3733' );
|
||||
$this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '3847' );
|
||||
$this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '20070327' );
|
||||
$this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '4583' );
|
||||
$this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' );
|
||||
$this->add( 'upload', '/wp-admin/upload.js', array('prototype'), '20070306' );
|
||||
|
Loading…
Reference in New Issue
Block a user