WordPress.org

Make WordPress Core

Changeset 5574


Ignore:
Timestamp:
05/28/07 17:21:25 (7 years ago)
Author:
rob1n
Message:

Moderation cleaned up, add paging and various bug fixes. fixes #4317

File:
1 edited

Legend:

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

    r5472 r5574  
    11<?php 
    2 require_once('admin.php'); 
    3  
    4 $title = __('Moderate comments'); 
     2 
     3require_once './admin.php'; 
     4 
     5$title = __( 'Moderate Comments' ); 
    56$parent_file = 'edit-comments.php'; 
     7 
    68wp_enqueue_script( 'admin-comments' ); 
    79 
    8 wp_reset_vars(array('action', 'item_ignored', 'item_deleted', 'item_approved', 'item_spam', 'feelinglucky')); 
     10wp_reset_vars( array( 'action', 'item_ignored', 'item_deleted', 'item_approved', 'item_spam', 'feelinglucky' ) ); 
    911 
    1012$comment = array(); 
    11 if (isset($_POST["comment"])) { 
    12     foreach ($_POST["comment"] as $k => $v) { 
    13         $comment[intval($k)] = $v; 
    14     } 
    15 } 
    16  
    17 switch($action) { 
    18  
    19 case 'update': 
    20  
    21     check_admin_referer('moderate-comments'); 
    22  
    23     if ( !current_user_can('moderate_comments') ) 
    24         wp_die(__('Your level is not high enough to moderate comments.')); 
    25  
     13 
     14if ( isset( $_POST['comment'] ) && is_array( $_POST['comment'] ) ) { 
     15    foreach ( $_POST['comment'] as $k => $v ) { 
     16        $comment[intval( $k )] = $v; 
     17    } 
     18} 
     19 
     20if ( $action == 'update' ) { 
     21    check_admin_referer( 'moderate-comments' ); 
     22     
     23    if ( !current_user_can( 'moderate_comments' ) ) { 
     24        wp_die( __( 'Your level is not high enough to moderate comments.' ) ); 
     25    } 
     26     
    2627    $item_ignored = 0; 
    2728    $item_deleted = 0; 
    2829    $item_approved = 0; 
    2930    $item_spam = 0; 
    30  
    31     foreach($comment as $key => $value) { 
    32     if ($feelinglucky && 'later' == $value) 
    33         $value = 'delete'; 
    34         switch($value) { 
    35             case 'later': 
    36                 // do nothing with that comment 
    37                 // wp_set_comment_status($key, "hold"); 
    38                 ++$item_ignored; 
    39                 break; 
    40             case 'delete': 
    41                 wp_set_comment_status($key, 'delete'); 
    42                 ++$item_deleted; 
    43                 break; 
    44             case 'spam': 
    45                 wp_set_comment_status($key, 'spam'); 
    46                 ++$item_spam; 
    47                 break; 
    48             case 'approve': 
    49                 wp_set_comment_status($key, 'approve'); 
    50                 if ( get_option('comments_notify') == true ) { 
    51                     wp_notify_postauthor($key); 
     31     
     32    foreach ( $comment as $k => $v ) { 
     33        if ( $feelinglucky && $v == 'later' ) { 
     34            $v = 'delete'; 
     35        } 
     36         
     37        switch ( $v ) { 
     38            case 'later' : 
     39                $item_ignored++; 
     40            break; 
     41             
     42            case 'delete' : 
     43                wp_set_comment_status( $k, 'delete' ); 
     44                $item_deleted++; 
     45            break; 
     46             
     47            case 'spam' : 
     48                wp_set_comment_status( $k, 'spam' ); 
     49                $item_spam++; 
     50            break; 
     51             
     52            case 'approve' : 
     53                wp_set_comment_status( $k, 'approve' ); 
     54                 
     55                if ( get_option( 'comments_notify' ) == true ) { 
     56                    wp_notify_postauthor( $k ); 
    5257                } 
    53                 ++$item_approved; 
    54                 break; 
    55         } 
    56     } 
    57  
    58     $file = basename(__FILE__); 
    59     wp_redirect("$file?ignored=$item_ignored&deleted=$item_deleted&approved=$item_approved&spam=$item_spam"); 
    60     exit(); 
    61  
    62 break; 
    63  
    64 default: 
    65  
    66 require_once('admin-header.php'); 
    67  
    68 if ( isset($_GET['deleted']) || isset($_GET['approved']) || isset($_GET['ignored']) ) { 
    69     echo "<div id='moderated' class='updated fade'>\n<p>"; 
    70     $approved = (int) $_GET['approved']; 
    71     $deleted  = (int) $_GET['deleted']; 
    72     $ignored  = (int) $_GET['ignored']; 
    73     $spam     = (int) $_GET['spam']; 
    74     if ($approved) { 
    75         printf(__ngettext('%s comment approved', '%s comments approved', $approved), $approved); 
    76         echo "<br/>\n"; 
    77     } 
    78     if ($deleted) { 
    79         printf(__ngettext('%s comment deleted', '%s comments deleted', $deleted), $deleted); 
    80         echo "<br/>\n"; 
    81     } 
    82     if ($spam) { 
    83         printf(__ngettext('%s comment marked as spam', '%s comments marked as spam', $spam), $spam); 
    84         echo "<br/>\n"; 
    85     } 
    86     if ($ignored) { 
    87         printf(__ngettext('%s comment unchanged', '%s comments unchanged', $ignored), $ignored); 
    88         echo "<br/>\n"; 
    89     } 
    90     echo "</p></div>\n"; 
     58                 
     59                $item_approved++; 
     60            break; 
     61        } 
     62    } 
     63     
     64    wp_redirect( basename( __FILE__ ) . '?ignored=' . $item_ignored . '&deleted=' . $item_deleted . '&approved=' . $item_approved . '&spam=' . $item_spam ); 
     65    exit; 
     66} 
     67 
     68require_once './admin-header.php'; 
     69 
     70if ( !current_user_can( 'moderate_comments' ) ) { 
     71    echo '<div class="wrap"><p>' . __( 'Your level is not high enough to moderate comments.' ) . '</p></div>'; 
     72    include_once './admin-footer.php'; 
     73    exit; 
     74} 
     75 
     76if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) { 
     77    $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0; 
     78    $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0; 
     79    $spam = isset( $_GET['ignored'] ) ? (int) $_GET['spam'] : 0; 
     80     
     81    if ( $approved > 0 || $deleted > 0 || $spam > 0 ) { 
     82        echo '<div id="moderated" class="updated fade"><p>'; 
     83     
     84        if ( $approved > 0 ) { 
     85            printf( __ngettext( '%s comment approved.', '%s comments approved.', $approved ), $approved ); 
     86            echo '<br />'; 
     87        } 
     88     
     89        if ( $deleted > 0 ) { 
     90            printf( __ngettext( '%s comment deleted', '%s comments deleted.', $deleted ), $deleted ); 
     91            echo '<br />'; 
     92        } 
     93     
     94        if ( $spam > 0 ) { 
     95            printf( __ngettext( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam ); 
     96            echo '<br />'; 
     97        } 
     98     
     99        echo '</p></div>'; 
     100    } 
    91101} 
    92102 
    93103?> 
    94  
    95104<div class="wrap"> 
    96  
    97105<?php 
    98 if ( current_user_can('moderate_comments') ) 
    99     $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0'"); 
    100 else 
    101     $comments = ''; 
    102  
    103 if ($comments) { 
    104     // list all comments that are waiting for approval 
    105     $file = basename(__FILE__); 
     106 
     107$comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0'" ); 
     108 
     109if ( !$comments ) { 
     110    echo '<p>' . __( 'Currently there are no comments for you to moderate.' ) . '</p></div>'; 
     111    include_once './admin-footer.php'; 
     112    exit; 
     113} 
     114 
     115$total = count( $comments ); 
     116$per = 20; 
     117 
     118if ( isset( $_GET['paged'] ) ) { 
     119    $page = (int) $_GET['paged']; 
     120} else { 
     121    $page = 1; 
     122} 
     123 
     124$start = ( $page * $per ) - $per; 
     125$stop = $start + $per; 
     126 
     127$page_links = paginate_links( array(  
     128    'base' => add_query_arg( 'paged', '%#%' ),  
     129    'format' => '',  
     130    'total' => ceil( $total / $per ),  
     131    'current' => $page,  
     132    'prev_text' => '&laquo;',  
     133    'next_text' => '&raquo;' 
     134) ); 
     135 
     136$comments = array_slice( $comments, $start, $stop ); 
     137 
    106138?> 
    107     <h2><?php _e('Moderation Queue') ?></h2> 
    108     <form name="approval" action="moderation.php" method="post"> 
    109     <?php wp_nonce_field('moderate-comments') ?> 
    110     <input type="hidden" name="action" value="update" /> 
    111     <ol id="the-comment-list" class="commentlist"> 
    112 <?php 
    113 $i = 0; 
    114     foreach($comments as $comment) { 
    115     ++$i; 
    116     $comment_date = mysql2date(get_option("date_format") . " @ " . get_option("time_format"), $comment->comment_date); 
    117     $post_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID='$comment->comment_post_ID'"); 
    118     if ($i % 2) $class = 'js-unapproved alternate'; 
    119     else $class = 'js-unapproved'; 
    120     echo "\n\t<li id='comment-$comment->comment_ID' class='$class'>";  
     139    <h2><?php _e( 'Moderation Queue' ); ?></h2> 
     140     
     141    <?php 
     142        if ( $page_links ) { 
     143            echo '<p class="pagenav">' . $page_links . '</p>'; 
     144        } 
    121145    ?> 
    122     <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> 
    123 <?php comment_text() ?> 
    124 <p><?php comment_date(__('M j, g:i A')); ?> &#8212; [ <?php 
    125 echo '<a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'">' . __('Edit') . '</a> | '; 
    126 echo " <a href=\"post.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;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> "; ?> ] &#8212; 
    127 <?php 
    128 $post = get_post($comment->comment_post_ID); 
    129 $post_title = wp_specialchars( $post->post_title, 'double' ); 
    130 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title; 
    131 ?> 
    132 <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo $post_title; ?></a></p> 
    133 <p><?php _e('Bulk action:') ?> 
    134     <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment-<?php echo $comment->comment_ID; ?>-approve" value="approve" /> <label for="comment-<?php echo $comment->comment_ID; ?>-approve"><?php _e('Approve') ?></label> &nbsp; 
    135     <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment-<?php echo $comment->comment_ID; ?>-spam" value="spam" /> <label for="comment-<?php echo $comment->comment_ID; ?>-spam"><?php _e('Spam') ?></label> &nbsp; 
    136     <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment-<?php echo $comment->comment_ID; ?>-delete" value="delete" /> <label for="comment-<?php echo $comment->comment_ID; ?>-delete"><?php _e('Delete') ?></label> &nbsp; 
    137     <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment-<?php echo $comment->comment_ID; ?>-nothing" value="later" checked="checked" /> <label for="comment-<?php echo $comment->comment_ID; ?>-nothing"><?php _e('Defer until later') ?></label> 
    138     </p> 
    139  
    140     </li> 
    141 <?php 
    142     } 
    143 ?> 
    144     </ol> 
    145  
    146 <div id="ajax-response"></div> 
    147  
    148 <p class="submit"><input type="submit" name="submit" value="<?php _e('Bulk Moderate Comments &raquo;') ?>" /></p> 
    149 <script type="text/javascript"> 
    150 // <![CDATA[ 
    151 function markAllForDelete() { 
    152     for (var i=0; i< document.approval.length; i++) { 
    153         if (document.approval[i].value == "delete") { 
    154             document.approval[i].checked = true; 
    155         } 
    156     } 
    157 } 
    158 function markAllForApprove() { 
    159     for (var i=0; i< document.approval.length; i++) { 
    160         if (document.approval[i].value == "approve") { 
    161             document.approval[i].checked = true; 
    162         } 
    163     } 
    164 } 
    165 function markAllForDefer() { 
    166     for (var i=0; i< document.approval.length; i++) { 
    167         if (document.approval[i].value == "later") { 
    168             document.approval[i].checked = true; 
    169         } 
    170     } 
    171 } 
    172 function markAllAsSpam() { 
    173     for (var i=0; i< document.approval.length; i++) { 
    174         if (document.approval[i].value == "spam") { 
    175             document.approval[i].checked = true; 
    176         } 
    177     } 
    178 } 
    179 document.write('<ul><li><a href="javascript:markAllForApprove()"><?php _e('Mark all for approval'); ?></a></li><li><a href="javascript:markAllAsSpam()"><?php _e('Mark all as spam'); ?></a></li><li><a href="javascript:markAllForDelete()"><?php _e('Mark all for deletion'); ?></a></li><li><a href="javascript:markAllForDefer()"><?php _e('Mark all for later'); ?></a></li></ul>'); 
    180 // ]]> 
    181 </script> 
    182  
    183 <noscript> 
    184     <p> 
    185         <input name="feelinglucky" type="checkbox" id="feelinglucky" value="true" /> <label for="feelinglucky"><?php _e('Delete every comment marked &#8220;defer.&#8221; <strong>Warning: This can&#8217;t be undone.</strong>'); ?></label> 
    186     </p> 
    187 </noscript> 
    188 </form> 
    189 <?php 
    190 } else { 
    191     // nothing to approve 
    192     echo '<p>'.__("Currently there are no comments for you to moderate.") . "</p>\n"; 
    193 } 
    194 ?> 
    195  
     146     
     147    <form name="approval" id="approval" action="<?php echo basename( __FILE__ ); ?>" method="post"> 
     148        <?php wp_nonce_field( 'moderate-comments' ); ?> 
     149        <input type="hidden" name="action" value="update" /> 
     150        <ol id="the-comments-list" class="commentlist"> 
     151    <?php 
     152        $i = 0; 
     153         
     154        foreach ( $comments as $comment ) { 
     155            $class = 'js-unapproved'; 
     156             
     157            if ( $i++ % 2 ) { 
     158                $class .= ' alternate'; 
     159            } 
     160        ?> 
     161            <li id="comment-<?php comment_ID(); ?>" class="<?php echo $class; ?>"> 
     162                <p> 
     163                    <strong><?php comment_author(); ?></strong>  
     164                    <?php if ( !empty( $comment->comment_author_email ) ) { ?>| <?php comment_author_email_link(); ?> <?php } ?> 
     165                    <?php if ( !empty( $comment->comment_author_url ) && $comment->comment_author_url != 'http://' ) { ?>| <?php comment_author_url_link(); ?> <?php } ?> 
     166                    | <?php _e( 'IP:' ); ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP(); ?>"><?php comment_author_IP(); ?></a> 
     167                </p> 
     168                 
     169                <p><small> 
     170                    <?php comment_date( __( 'M j, g:i A' ) ); ?> &#8212;  
     171                    [ <a href="comment.php?action=editcomment&amp;c=<?php comment_ID(); ?>" title="<?php _e( 'Edit this comment' ); ?>"><?php _e( 'Edit' ); ?></a> |  
     172                    <a href="post.php?action=deletecomment&amp;p=<?php echo $comment->comment_post_ID; ?>" title="<?php _e( 'Delete this comment' ); ?>" onclick="return deleteSomething( 'comment', <?php comment_ID(); ?>, '<?php echo js_escape( sprintf( __( 'You are about to delete this comment by \'%s\'.\n\'OK\' to delete, \'Cancel\' to stop.' ), get_comment_author() ) ); ?>', theCommentList );"><?php _e( 'Delete' ); ?></a> ] &#8212;  
     173                    <a href="<?php echo get_permalink( $comment->comment_post_ID ); ?>" title="<?php _e( 'View the post' ); ?>"><?php printf( __( 'View post &#8220;%s&#8221;' ), get_the_title( $comment->comment_post_ID ) ); ?></a> 
     174                </small></p> 
     175                 
     176                <p> 
     177                    <?php comment_text(); ?> 
     178                </p> 
     179                 
     180                <p><small> 
     181                    <?php _e( 'Bulk action:' ); ?> 
     182                    <label for="comment-<?php comment_ID(); ?>-approve"><input type="radio" name="comment[<?php comment_ID(); ?>]" id="comment-<?php comment_ID(); ?>-approve" value="approve" /> <?php _e( 'Approve' ); ?></label> &nbsp; 
     183                    <label for="comment-<?php comment_ID(); ?>-spam"><input type="radio" name="comment[<?php comment_ID(); ?>]" id="comment-<?php comment_ID(); ?>-spam" value="spam" /> <?php _e( 'Spam' ); ?></label> &nbsp; 
     184                    <label for="comment-<?php comment_ID(); ?>-delete"><input type="radio" name="comment[<?php comment_ID(); ?>]" id="comment-<?php comment_ID(); ?>-delete" value="delete" /> <?php _e( 'Delete' ); ?></label> &nbsp; 
     185                    <label for="comment-<?php comment_ID(); ?>-nothing"><input type="radio" name="comment[<?php comment_ID(); ?>]" id="comment-<?php comment_ID(); ?>-nothing" value="later" checked="checked" /> <?php _e( 'No action' ); ?></label> 
     186                </small></p> 
     187            </li> 
     188        <?php 
     189        } 
     190    ?> 
     191        </ol> 
     192         
     193        <?php 
     194            if ( $page_links ) { 
     195                echo '<p class="pagenav">' . $page_links . '</p>'; 
     196            } 
     197        ?> 
     198         
     199        <div id="ajax-response"></div> 
     200         
     201        <noscript> 
     202            <p class="submit"> 
     203                <label for="feelinglucky"><input name="feelinglucky" id="feelinglucky" type="checkbox" value="true" /> <?php _e( 'Delete every comment marked &#8220;defer.&#8221; <strong>Warning: This can&#8217;t be undone.</strong>' ); ?></label> 
     204            </p> 
     205        </noscript> 
     206         
     207        <p class="submit"> 
     208            <input type="submit" id="submit" name="submit" value="<?php _e( 'Bulk Moderate Comments &raquo;' ); ?>" /> 
     209        </p> 
     210         
     211        <script type="text/javascript"> 
     212        // <![CDATA[ 
     213            function mark_all_as( what ) { 
     214                for ( var i = 0; i < document.approval.length; i++ ) { 
     215                    if ( document.approval[i].value == what ) { 
     216                        document.approval[i].checked = true; 
     217                    } 
     218                } 
     219            } 
     220         
     221            document.write( '<p style="text-align:center;"><strong><?php _e( 'Mark all:' ); ?></strong> <a href="javascript:mark_all_as(\'approve\')"><?php _e( 'Approved' ); ?></a> &ndash; <a href="javascript:mark_all_as(\'spam\')"><?php _e( 'Spam' ); ?></a> &ndash; <a href="javascript:mark_all_as(\'delete\')"><?php _e( 'Deleted' ); ?></a> &ndash; <a href="javascript:mark_all_as(\'later\')"><?php _e( 'Later' ); ?></a></p>' ); 
     222        // ]]> 
     223        </script> 
     224    </form> 
    196225</div> 
    197  
    198 <?php 
    199  
    200 break; 
    201 } 
    202  
    203  
    204 include('admin-footer.php'); 
    205  
    206 ?> 
     226<?php include_once './admin-footer.php'; ?> 
Note: See TracChangeset for help on using the changeset viewer.