Changeset 6993

Show
Ignore:
Timestamp:
02/23/08 08:01:51 (9 months ago)
Author:
ryan
Message:

Manage comments rework. WIP.

Files:

Legend:

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

    r6980 r6993  
    77wp_enqueue_script('admin-forms'); 
    88 
    9 require_once('admin-header.php'); 
    10 if (empty($_GET['mode'])) $mode = 'view'; 
    11 else $mode = attribute_escape($_GET['mode']); 
    12 ?> 
    13 <div class="wrap"> 
    14 <h2><?php _e('Comments'); ?></h2> 
    15 <form name="searchform" action="" method="get" id="editcomments"> 
    16   <fieldset> 
    17   <legend><?php _e('Show Comments That Contain...') ?></legend> 
    18   <input type="text" name="s" value="<?php if (isset($_GET['s'])) echo attribute_escape($_GET['s']); ?>" size="17" /> 
    19   <input type="submit" name="submit" value="<?php _e('Search') ?>" class="button" /> 
    20   <input type="hidden" name="mode" value="<?php echo $mode; ?>" /> 
    21   <?php _e('(Searches within comment text, e-mail, URL, and IP address.)') ?> 
    22   </fieldset> 
    23 </form> 
    24 <p><a href="?mode=view"><?php _e('View Mode') ?></a> | <a href="?mode=edit"><?php _e('Mass Edit Mode') ?></a></p> 
    25 <?php 
    269if ( !empty( $_POST['delete_comments'] ) ) : 
    2710    check_admin_referer('bulk-comments'); 
     
    4023        } 
    4124    endforeach; 
     25    /* 
    4226    echo '<div style="background-color: rgb(207, 235, 247);" id="message" class="updated fade"><p>'; 
    4327    if ( !empty( $_POST['spam_button'] ) ) { 
     
    4731    } 
    4832    echo '</p></div>'; 
     33    */ 
     34    // TODO redirect with message 
    4935endif; 
     36 
     37require_once('admin-header.php'); 
     38if (empty($_GET['mode'])) $mode = 'view'; 
     39else $mode = attribute_escape($_GET['mode']); 
     40?> 
     41 
     42<div class="wrap"> 
     43<form id="posts-filter" action="" method="get"> 
     44<h2><?php _e('Manage Comments'); ?></h2> 
     45 
     46<ul class="subsubsub"> 
     47<?php 
     48if ( isset($_GET['comment_status']) ) 
     49    $comment_status = $_GET['comment_status']; 
     50else 
     51    $comment_status = ''; 
     52$status_links = array(); 
     53$num_posts = wp_count_posts('post'); 
     54$stati = array('moderated' => __('Awaiting Moderation'), 'approved' => __('Approved')); 
     55foreach ( $stati as $status => $label ) { 
     56    $class = ''; 
     57 
     58    if ( $status == $comment_status ) 
     59        $class = ' class="current"'; 
     60 
     61    $status_links[] = "<li><a href=\"edit-comments.php?comment_status=$status\"$class>" . $label . '</a>'; 
     62} 
     63$class = ( '' === $comment_status ) ? ' class="current"' : ''; 
     64$status_links[] = "<li><a href=\"edit-comments.php\"$class>".__('All Comments')."</a>"; 
     65echo implode(' |</li>', $status_links) . '</li>'; 
     66unset($status_links); 
     67?> 
     68</ul> 
     69 
     70<p id="post-search"> 
     71    <input type="text" id="post-search-input" name="s" value="<?php if (isset($_GET['s'])) echo attribute_escape($_GET['s']); ?>" /> 
     72    <input type="submit" value="<?php _e( 'Search Comments' ); ?>" class="button" /> 
     73</p> 
     74 
     75<input type="hidden" name="mode" value="<?php echo $mode; ?>" /> 
     76 
     77<p><a href="?mode=view"><?php _e('View Mode') ?></a> | <a href="?mode=edit"><?php _e('Mass Edit Mode') ?></a></p> 
     78 
     79<?php 
    5080 
    5181if ( isset( $_GET['apage'] ) ) 
     
    5686$start = $offset = ( $page - 1 ) * 20; 
    5787 
    58 list($_comments, $total) = _wp_get_comment_list( isset($_GET['s']) ? $_GET['s'] : false, $start, 25 ); // Grab a few extra 
     88list($_comments, $total) = _wp_get_comment_list( $comment_status, isset($_GET['s']) ? $_GET['s'] : false, $start, 25 ); // Grab a few extra 
    5989 
    6090$comments = array_slice($_comments, 0, 20); 
     
    6898)); 
    6999 
    70 if ( $page_links ) 
    71     echo "<p class='pagenav'>$page_links</p>"; 
     100?> 
    72101 
    73 if ('view' == $mode) { 
    74     if ($comments) { 
    75         $offset = $offset + 1; 
    76         $start = " start='$offset'"; 
     102<br style="clear:both;" /> 
    77103 
    78         echo "<ol id='the-comment-list' class='list:comment commentlist' $start>\n"; 
    79         $i = 0; 
    80         foreach ( $comments as $comment ) { 
    81             _wp_comment_list_item( $comment->comment_ID, ++$i ); 
    82         } 
    83         echo "</ol>\n\n"; 
    84  
    85 if ( $extra_comments ) : ?> 
    86 <div id="extra-comments" style="display:none"> 
    87 <ol id="the-extra-comment-list" class="list:comment commentlist" style="color:red"> 
    88 <?php 
    89     foreach ( $extra_comments as $comment ) { 
    90         get_comment( $comment ); // Cache it 
    91         _wp_comment_list_item( $comment->comment_ID, 0 ); 
    92     } 
    93 ?> 
    94 </ol> 
    95 <form action="" method="get" id="get-extra-comments" class="add:the-extra-comment-list:"> 
    96 <input type="hidden" name="page" value="<?php echo $page; ?>" /> 
    97 <input type="hidden" name="s" value="<?php echo attribute_escape(@$_GET['s']); ?>" /> 
    98 <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?> 
    99 </form> 
    100 </div> 
    101 <?php endif; // $extra_comments ?> 
    102  
    103 <div id="ajax-response"></div> 
     104<div class="tablenav"> 
    104105 
    105106<?php 
    106     } else { //no comments to show 
     107if ( $page_links ) 
     108    echo "<div class='tablenav-pages'>$page_links</div>"; 
     109?> 
    107110 
    108         ?> 
    109         <p> 
    110             <strong><?php _e('No comments found.') ?></strong></p> 
     111<div style="float: left"> 
     112<input type="submit" value="<?php _e('Approve'); ?>" name="approveit" class="button-secondary" /> 
     113<input type="submit" value="<?php _e('Mark as Spam'); ?>" name="spamit" class="button-secondary" /> 
     114<input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary" /> 
     115<?php wp_nonce_field('bulk-comments'); ?> 
     116</div> 
    111117 
    112         <?php 
    113     } // end if ($comments) 
    114 } elseif ('edit' == $mode) { 
     118<br style="clear:both;" /> 
     119</div> 
    115120 
    116     if ($comments) { 
    117         echo '<form name="deletecomments" id="deletecomments" action="" method="post"> '; 
    118         wp_nonce_field('bulk-comments'); 
    119         echo '<table class="widefat"> 
     121<br style="clear:both;" /> 
     122<?php 
     123if ($comments) { 
     124?> 
     125<table class="widefat"> 
    120126<thead> 
    121127  <tr> 
    122     <th scope="col" style="text-align: center"><input type="checkbox" onclick="checkAll(document.getElementById(\'deletecomments\'));" /></th> 
    123     <th scope="col">' .  __('Name') . '</th> 
    124     <th scope="col">' .  __('E-mail') . '</th> 
    125     <th scope="col">' . __('IP') . '</th> 
    126     <th scope="col">' . __('Comment Excerpt') . '</th> 
    127     <th scope="col" colspan="3" style="text-align: center">' .  __('Actions') . '</th> 
     128    <th scope="col" style="text-align: center"><input type="checkbox" onclick="checkAll(document.getElementById('posts-filter'));" /></th> 
     129    <th scope="col"><?php _e('Comment') ?></th> 
     130    <th scope="col"><?php _e('Date') ?></th> 
     131    <th scope="col"><?php _e('Actions') ?></th> 
    128132  </tr> 
    129133</thead> 
    130 <tbody id="the-comment-list" class="list:comment">'; 
    131         foreach ($comments as $comment) { 
     134<tbody id="the-comment-list" class="list:comment"> 
     135<?php 
     136    foreach ($comments as $comment) { 
    132137        $post = get_post($comment->comment_post_ID); 
    133138        $authordata = get_userdata($post->post_author); 
     
    135140        $class = ('alternate' == $class) ? '' : 'alternate'; 
    136141        $class .= ('unapproved' == $comment_status) ? ' unapproved' : ''; 
     142        $post_link = '<a href="' . get_comment_link() . '">' . get_the_title($comment->comment_post_ID) . '</a>'; 
     143        $author_url = get_comment_author_url(); 
     144        if ( 'http://' == $author_url ) 
     145            $author_url = ''; 
    137146?> 
    138147  <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'> 
    139     <td style="text-align: center"><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { ?><input type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /><?php } ?></td> 
    140     <td class="comment-author"><?php comment_author_link() ?></td> 
    141     <td><?php comment_author_email_link() ?></td> 
    142     <td><a href="edit-comments.php?s=<?php comment_author_IP() ?>&amp;mode=edit"><?php comment_author_IP() ?></a></td> 
    143     <td><?php comment_excerpt(); ?></td> 
    144     <td> 
    145         <?php if ('unapproved' == $comment_status) { 
    146             _e('Unapproved'); 
    147         } else { ?> 
    148             <a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a> 
    149         <?php } ?> 
     148    <td style="text-align: center; vertical-align: text-top"><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { ?><input type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /><?php } ?></td> 
     149    <td style="vertical-align: text-top"> 
     150    <?php comment_author_link(); ?><br /> 
     151    <?php if ( !empty($author_url) ) : ?>  
     152    <a href="<?php echo $author_url ?>"><?php echo $author_url; ?></a> | 
     153    <?php endif; ?> 
     154    <?php if ( !empty($comment->comment_author_email) ): ?> 
     155    <?php comment_author_email_link() ?> | 
     156    <?php endif; ?> 
     157    <a href="edit-comments.php?s=<?php comment_author_IP() ?>&amp;mode=edit"><?php comment_author_IP() ?></a> 
     158    <p><?php comment_excerpt(); ?></p> 
     159    <?php printf(__('From %1$s, %2$s at %3$s'), $post_link, get_the_time(get_option('date_format')), get_the_time()) ?> 
    150160    </td> 
    151     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { 
    152     echo "<a href='comment.php?action=editcomment&amp;c=$comment->comment_ID' class='edit'>" .  __('Edit') . "</a>"; } ?></td> 
    153     <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { 
     161    <td style="vertical-align: text-top"><?php comment_date(); ?></td> 
     162    <td style="vertical-align: text-top"> 
     163    <?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { 
     164        echo "<a href='comment.php?action=editcomment&amp;c=$comment->comment_ID' class='edit'>" .  __('Edit') . "</a> | "; 
    154165        $url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) ); 
    155166        echo "<a href='$url' class='delete:the-comment-list:comment-$comment->comment_ID delete'>" . __('Delete') . "</a> "; 
    156         } ?></td> 
     167    } 
     168    ?> 
     169    </td> 
    157170  </tr> 
    158171        <?php 
     
    160173    ?></tbody> 
    161174</table> 
    162 <p class="submit"><input type="submit" name="delete_button" class="delete" value="<?php _e('Delete Checked Comments') ?>" onclick="var numchecked = getNumChecked(document.getElementById('deletecomments')); if(numchecked < 1) { alert('<?php echo js_escape(__("Please select some comments to delete")); ?>'); return false } return confirm('<?php echo sprintf(js_escape(__("You are about to delete %s comments permanently \n  'Cancel' to stop, 'OK' to delete.")), "' + numchecked + '"); ?>')" /> 
    163             <input type="submit" name="spam_button" value="<?php _e('Mark Checked Comments as Spam') ?>" onclick="var numchecked = getNumChecked(document.getElementById('deletecomments')); if(numchecked < 1) { alert('<?php echo js_escape(__("Please select some comments to mark as spam")); ?>'); return false } return confirm('<?php echo sprintf(js_escape(__("You are about to mark %s comments as spam \n  'Cancel' to stop, 'OK' to mark as spam.")), "' + numchecked + '"); ?>')" /></p> 
    164   </form> 
     175 
    165176<div id="ajax-response"></div> 
    166177<?php 
    167    } else { 
     178} else { 
    168179?> 
    169180<p> 
     
    171182</p> 
    172183<?php 
    173     } // end if ($comments) 
    174184} 
    175  
     185?> 
     186<div class="tablenav"> 
     187<?php 
    176188if ( $page_links ) 
    177     echo "<p class='pagenav'>$page_links</p>"; 
    178  
     189    echo "<div class='tablenav-pages'>$page_links</div>"; 
    179190?> 
    180  
     191<br style="clear:both;" /> 
    181192</div> 
    182193 
  • trunk/wp-admin/includes/template.php

    r6989 r6993  
    568568} 
    569569 
    570 function _wp_get_comment_list( $s = false, $start, $num ) { 
     570function _wp_get_comment_list( $status = '', $s = false, $start, $num ) { 
    571571    global $wpdb; 
    572572 
     
    574574    $num = (int) $num; 
    575575 
     576    if ( 'moderated' == $status ) 
     577        $approved = "comment_approved = '0'"; 
     578    elseif ( 'approved' == $status ) 
     579        $approved = "comment_approved = '1'"; 
     580    elseif ( 'spam' == $status ) 
     581        $approved = "comment_approved = 'spam'"; 
     582    else 
     583        $approved = "comment_approved != 'spam'"; 
     584     
    576585    if ( $s ) { 
    577586        $s = $wpdb->escape($s); 
     
    582591            comment_author_IP LIKE ('%$s%') OR 
    583592            comment_content LIKE ('%$s%') ) AND 
    584             comment_approved != 'spam' 
     593            $approved 
    585594            ORDER BY comment_date_gmt DESC LIMIT $start, $num"); 
    586595    } else { 
    587         $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments USE INDEX (comment_date_gmt) WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $start, $num" ); 
     596        $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments USE INDEX (comment_date_gmt) WHERE $approved ORDER BY comment_date_gmt DESC LIMIT $start, $num" ); 
    588597    } 
    589598