Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-comments.php

    r5226 r4781  
    5757        foreach ($_POST['delete_comments'] as $comment) : // Check the permissions on each
    5858                $comment = (int) $comment;
    59                 $post_id = (int) $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment");
     59                $post_id = $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment");
    6060                // $authordata = get_userdata( $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id") );
    6161                if ( current_user_can('edit_post', $post_id) ) {
     
    7676endif;
    7777
    78 if ( isset( $_GET['apage'] ) )
    79         $page = (int) $_GET['apage'];
    80 else
    81         $page = 1;
    82 $start = $offset = ( $page - 1 ) * 20;
    83 
    84 list($_comments, $total) = _wp_get_comment_list( isset($_GET['s']) ? $_GET['s'] : false, $start, 25 ); // Grab a few extra
    85 
    86 $comments = array_slice($_comments, 0, 20);
    87 $extra_comments = array_slice($_comments, 20);
    88 
    89 $page_links = paginate_links( array(
    90         'base' => 'edit-comments.php?%_%',
    91         'format' => 'apage=%#%',
    92         'total' => ceil($total / 20),
    93         'current' => $page
    94 ));
    95 
    96 if ( $page_links )
    97         echo "<p class='pagenav'>$page_links</p>";
    98 
     78if (isset($_GET['s'])) {
     79        $s = $wpdb->escape($_GET['s']);
     80        $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments  WHERE
     81                (comment_author LIKE '%$s%' OR
     82                comment_author_email LIKE '%$s%' OR
     83                comment_author_url LIKE ('%$s%') OR
     84                comment_author_IP LIKE ('%$s%') OR
     85                comment_content LIKE ('%$s%') ) AND
     86                comment_approved != 'spam'
     87                ORDER BY comment_date DESC");
     88} else {
     89        if ( isset( $_GET['apage'] ) )
     90                $page = (int) $_GET['apage'];
     91        else
     92                $page = 1;
     93        $start = $offset = ( $page - 1 ) * 20;
     94
     95        $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, 20" );
     96        $total = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1'" );
     97}
     98?>
     99<?php if ( $total > 20 ) {
     100$total_pages = ceil( $total / 20 );
     101$r = '';
     102if ( 1 < $page ) {
     103        $args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
     104        $r .=  '<a class="prev" href="' . add_query_arg( $args ) . '">&laquo; '. __('Previous Page') .'</a>' . "\n";
     105}
     106if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) {
     107        for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
     108                if ( $page == $page_num ) :
     109                        $r .=  "<span>$page_num</span>\n";
     110                else :
     111                        $p = false;
     112                        if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
     113                                $args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num;
     114                                $r .= '<a class="page-numbers" href="' . add_query_arg($args) . '">' . ( $page_num ) . "</a>\n";
     115                                $in = true;
     116                        elseif ( $in == true ) :
     117                                $r .= "...\n";
     118                                $in = false;
     119                        endif;
     120                endif;
     121        endfor;
     122}
     123if ( ( $page ) * 20 < $total || -1 == $total ) {
     124        $args['apage'] = $page + 1;
     125        $r .=  '<a class="next" href="' . add_query_arg($args) . '">'. __('Next Page') .' &raquo;</a>' . "\n";
     126}
     127echo "<p class='pagenav'>$r</p>";
     128?>
     129
     130<?php } ?>
     131
     132<?php
    99133if ('view' == $mode) {
    100134        if ($comments) {
    101                 $offset = $offset + 1;
    102                 $start = " start='$offset'";
    103 
    104                 echo "<ol id='the-comment-list' class='commentlist' $start>\n";
     135?>
     136<?php
     137$offset = $offset + 1;
     138$start = " start='$offset'";
     139
     140                echo "<ol id='the-comment-list' class='commentlist' $start>";
    105141                $i = 0;
    106                 foreach ( $comments as $comment ) {
    107                         get_comment( $comment ); // Cache it
    108                         _wp_comment_list_item( $comment->comment_ID, ++$i );
    109                 }
    110                 echo "</ol>\n\n";
    111 
    112 if ( $extra_comments ) : ?>
    113 <div id="extra-comments" style="display:none">
    114 <ul id="the-extra-comment-list" class="commentlist">
    115 <?php
    116         foreach ( $extra_comments as $comment ) {
    117                 get_comment( $comment ); // Cache it
    118                 _wp_comment_list_item( $comment->comment_ID, ++$i );
    119         }
    120 ?>
    121 </ul>
    122 </div>
    123 <?php endif; // $extra_comments ?>
     142                foreach ($comments as $comment) {
     143                ++$i; $class = '';
     144                $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
     145                        $comment_status = wp_get_comment_status($comment->comment_ID);
     146                        if ('unapproved' == $comment_status)
     147                                $class .= ' unapproved';
     148                        if ($i % 2)
     149                                $class .= ' alternate';
     150                        echo "<li id='comment-$comment->comment_ID' class='$class'>";
     151?>
     152<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>
     153
     154<?php comment_text() ?>
     155
     156<p><?php comment_date('M j, g:i A');  ?> &#8212; [
     157<?php
     158if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
     159        echo " <a href='comment.php?action=editcomment&amp;c=".$comment->comment_ID."'>" .  __('Edit') . '</a>';
     160        echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;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> ';
     161        if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
     162                echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
     163                echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
     164        }
     165        echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;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> ";
     166}
     167$post = get_post($comment->comment_post_ID);
     168$post_title = wp_specialchars( $post->post_title, 'double' );
     169$post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
     170?>
     171 | <a href="<?php echo get_permalink($comment->comment_post_ID); ?>" title="<?php echo $post_title; ?>"><?php _e('View Post') ?></a> ]</p>
     172                </li>
     173
     174<?php } // end foreach($comment) ?>
     175</ol>
    124176
    125177<div id="ajax-response"></div>
     
    191243        } // end if ($comments)
    192244}
    193 
    194 if ( $page_links )
    195         echo "<p class='pagenav'>$page_links</p>";
    196 
    197 ?>
     245        ?>
     246<?php if ( $total > 20 ) {
     247$total_pages = ceil( $total / 20 );
     248$r = '';
     249if ( 1 < $page ) {
     250        $args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
     251        $r .=  '<a class="prev" href="' . add_query_arg( $args ) . '">&laquo; '. __('Previous Page') .'</a>' . "\n";
     252}
     253if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) {
     254        for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
     255                if ( $page == $page_num ) :
     256                        $r .=  "<span>$page_num</span>\n";
     257                else :
     258                        $p = false;
     259                        if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
     260                                $args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num;
     261                                $r .= '<a class="page-numbers" href="' . add_query_arg($args) . '">' . ( $page_num ) . "</a>\n";
     262                                $in = true;
     263                        elseif ( $in == true ) :
     264                                $r .= "...\n";
     265                                $in = false;
     266                        endif;
     267                endif;
     268        endfor;
     269}
     270if ( ( $page ) * 20 < $total || -1 == $total ) {
     271        $args['apage'] = $page + 1;
     272        $r .=  '<a class="next" href="' . add_query_arg($args) . '">'. __('Next Page') .' &raquo;</a>' . "\n";
     273}
     274echo "<p class='pagenav'>$r</p>";
     275?>
     276
     277<?php } ?>
    198278
    199279</div>
Note: See TracChangeset for help on using the changeset viewer.