Make WordPress Core

Changeset 9225


Ignore:
Timestamp:
10/17/2008 09:44:22 AM (18 years ago)
Author:
azaozz
Message:

Comments post-box: show comments on the currently edited post with ajax, 20 at a time

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r9216 r9225  
    441441                ) );
    442442        }
     443        $x->send();
     444        break;
     445case 'get-comments' :
     446        check_ajax_referer( $action );
     447
     448        $post_ID = (int) $_POST['post_ID'];
     449        if ( !current_user_can( 'edit_post', $post_ID ) )
     450                die('-1');
     451
     452        $start = isset($_POST['start']) ? intval($_POST['start']) : 0;
     453        $num = isset($_POST['num']) ? intval($_POST['num']) : 10;
     454
     455        list($comments, $total) = _wp_get_comment_list( false, false, $start, $num, $post_ID );
     456
     457        if ( !$comments )
     458                die('1');
     459
     460        $comment_list_item = '';
     461        $x = new WP_Ajax_Response();
     462        foreach ( (array) $comments as $comment ) {
     463                get_comment( $comment );
     464                ob_start();
     465                        _wp_comment_row( $comment->comment_ID, 'single', false, false );
     466                        $comment_list_item .= ob_get_contents();
     467                ob_end_clean();
     468        }
     469        $x->add( array(
     470                'what' => 'comments',
     471                'data' => $comment_list_item
     472        ) );
    443473        $x->send();
    444474        break;
  • trunk/wp-admin/edit-form-advanced.php

    r9221 r9225  
    342342<?php
    343343
    344         if ( !$post_ID || $post_ID < 0 )
     344        if ( !$post_ID || $post_ID < 0 || 0 == $post->comment_count )
    345345                return;
    346346
    347         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) ) )
    348                 return;
    349 
    350         // Make sure comments, post, and post_author are cached
    351 //      update_comment_cache($comments);
    352 ?>
    353 
    354 <table class="widefat">
     347wp_nonce_field( 'get-comments', 'add_comment_nonce', false );
     348?>
     349
     350<table class="widefat comments-box" style="display:none;">
    355351<thead>
    356352        <tr>
     
    361357</thead>
    362358<tbody id="the-comment-list" class="list:comment">
    363 <?php
    364         foreach ($comments as $comment)
    365                 _wp_comment_row( $comment, 'single', false, false );
    366 ?>
    367359</tbody>
    368360</table>
    369 
     361<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>
    370362<?php
    371363}
  • trunk/wp-admin/js/edit-comments.js

    r9219 r9225  
    154154                t.o = '#comment-'+id;
    155155
    156                 $('#replyrow td').attr('colspan', $('.widefat tfoot th:visible').length);
     156                $('#replyrow td').attr('colspan', $('.widefat thead th:visible').length);
    157157                var editRow = $('#replyrow'), rowData = $('#inline-'+id);
    158158                var act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
  • trunk/wp-admin/js/post.js

    r8988 r9225  
    203203        }
    204204        });
    205        
     205
    206206        $('.edit-post-status').click(function() {
    207207                if ($('#post-status-select').is(":hidden")) {
     
    217217                $('#post-status-display').html($('#post_status :selected').text());
    218218                $('.edit-post-status').show();
    219                
    220                 return false;
    221         });
    222        
     219
     220                return false;
     221        });
     222
    223223        $('.cancel-post-status').click(function() {
    224224                $('#post-status-select').slideUp("normal");
     
    226226                $('#post-status-display').html($('#post_status :selected').text());
    227227                $('.edit-post-status').show();
    228                
     228
    229229                return false;
    230230        });
    231231});
     232
     233(function($){
     234        commentsBox = {
     235                st : 0,
     236
     237                get : function(id, nonce) {
     238                        var st = this.st;
     239                        this.st += 20;
     240
     241                        $('.waiting').show();
     242
     243                        var data = {
     244                                'action' : 'get-comments',
     245                                'mode' : 'single',
     246                                '_ajax_nonce' : $('#add_comment_nonce').val(),
     247                                'post_ID' : $('#post_ID').val(),
     248                                'start' : st,
     249                                'num' : '20'
     250                        };
     251
     252                        $.post('admin-ajax.php', data,
     253                                function(r) {
     254                                        var r = wpAjax.parseAjaxResponse(r);
     255                                        $('#commentstatusdiv .widefat').show();
     256                                        $('.waiting').hide();
     257
     258                                        if ( 'object' == typeof r && r.responses[0] ) {
     259                                                $('#the-comment-list').append( r.responses[0].data );
     260                                                $('#the-comment-list .hide-if-no-js').removeClass('hide-if-no-js');
     261
     262                                                theList = theExtraList = null;
     263                                                $("a[className*=':']").unbind();
     264                                                setCommentsList();
     265                                                $('#show-comments').html(postL10n.showcomm);
     266                                                return;
     267                                        } else if ( 1 == r ) {
     268                                                $('#show-comments').parent().html(postL10n.endcomm);
     269                                                return;
     270                                        }
     271
     272                                        $('#the-comment-list').append('<tr><td colspan="5">'+wpAjax.broken+'</td></tr>');
     273                                }
     274                        );
     275
     276                        return false;
     277                }
     278        }
     279
     280})(jQuery);
     281
  • trunk/wp-admin/wp-admin.css

    r9224 r9225  
    10821082.stuffbox .insidebox {
    10831083        margin: 11px 0;
     1084}
     1085
     1086#side-sortables .comments-box,
     1087#side-sortables #show-comments {
     1088        display: none;
    10841089}
    10851090
     
    19761981
    19771982#replysubmit img.waiting,
    1978 .quick-edit-save img.waiting {
     1983.quick-edit-save img.waiting,
     1984#commentstatusdiv img.waiting {
    19791985        padding: 0 10px;
    19801986        vertical-align: top;
  • trunk/wp-includes/script-loader.php

    r9220 r9225  
    184184                        'cancel' => __('Cancel'),
    185185                        'edit' => __('Edit'),
     186                        'showcomm' => __('Show more comments'),
     187                        'endcomm' => __('No more comments found.')
    186188                ) );
    187189                $scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox', 'settings-box'), '20080925' );
Note: See TracChangeset for help on using the changeset viewer.