| 1 | <?php |
|---|
| 2 | if (empty($_GET['mode'])) $mode = 'view'; |
|---|
| 3 | else $mode = attribute_escape($_GET['mode']); |
|---|
| 4 | ?> |
|---|
| 5 | |
|---|
| 6 | <script type="text/javascript"> |
|---|
| 7 | <!-- |
|---|
| 8 | function checkAll(form) |
|---|
| 9 | { |
|---|
| 10 | for (i = 0, n = form.elements.length; i < n; i++) { |
|---|
| 11 | if(form.elements[i].type == "checkbox") { |
|---|
| 12 | if(form.elements[i].checked == true) |
|---|
| 13 | form.elements[i].checked = false; |
|---|
| 14 | else |
|---|
| 15 | form.elements[i].checked = true; |
|---|
| 16 | } |
|---|
| 17 | } |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | function getNumChecked(form) |
|---|
| 21 | { |
|---|
| 22 | var num = 0; |
|---|
| 23 | for (i = 0, n = form.elements.length; i < n; i++) { |
|---|
| 24 | if(form.elements[i].type == "checkbox") { |
|---|
| 25 | if(form.elements[i].checked == true) |
|---|
| 26 | num++; |
|---|
| 27 | } |
|---|
| 28 | } |
|---|
| 29 | return num; |
|---|
| 30 | } |
|---|
| 31 | //--> |
|---|
| 32 | </script> |
|---|
| 33 | <?php |
|---|
| 34 | function process_delete_comments() { |
|---|
| 35 | global $wpdb; |
|---|
| 36 | |
|---|
| 37 | if ( !empty( $_POST['delete_comments'] ) ) { |
|---|
| 38 | check_admin_referer('bulk-comments'); |
|---|
| 39 | |
|---|
| 40 | $i = 0; |
|---|
| 41 | foreach ($_POST['delete_comments'] as $comment) { // Check the permissions on each |
|---|
| 42 | $comment = (int) $comment; |
|---|
| 43 | $post_id = $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment"); |
|---|
| 44 | // $authordata = get_userdata( $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id") ); |
|---|
| 45 | if ( current_user_can('edit_post', $post_id) ) { |
|---|
| 46 | if ( !empty( $_POST['spam_button'] ) ) { |
|---|
| 47 | wp_set_comment_status($comment, 'spam'); |
|---|
| 48 | } else { |
|---|
| 49 | wp_set_comment_status($comment, 'delete'); |
|---|
| 50 | } |
|---|
| 51 | ++$i; |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | echo '<div style="background-color: rgb(207, 235, 247);" id="message" class="updated fade"><p>'; |
|---|
| 55 | if ( !empty( $_POST['spam_button'] ) ) { |
|---|
| 56 | printf(__ngettext('%s comment marked as spam', '%s comments marked as spam.', $i), $i); |
|---|
| 57 | } else { |
|---|
| 58 | printf(__ngettext('%s comment deleted.', '%s comments deleted.', $i), $i); |
|---|
| 59 | } |
|---|
| 60 | echo '</p></div>'; |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | function show_comment_list($comments, $mode, $total = 0, $page = 1) { |
|---|
| 65 | global $wpdb, $comment; |
|---|
| 66 | |
|---|
| 67 | if (count($comments) > $total) { |
|---|
| 68 | $total = count($comments); |
|---|
| 69 | } |
|---|
| 70 | show_comment_page_nav($total, $page); |
|---|
| 71 | if ('view' == $mode) { |
|---|
| 72 | if ($comments) { |
|---|
| 73 | ?> |
|---|
| 74 | <?php |
|---|
| 75 | $offset = $offset + 1; |
|---|
| 76 | $start = " start='$offset'"; |
|---|
| 77 | |
|---|
| 78 | echo "<ol id='the-comment-list' class='commentlist' $start>"; |
|---|
| 79 | $i = 0; |
|---|
| 80 | foreach ($comments as $comment) { |
|---|
| 81 | ++$i; $class = ''; |
|---|
| 82 | $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID")); |
|---|
| 83 | $comment_status = wp_get_comment_status($comment->comment_ID); |
|---|
| 84 | if ('unapproved' == $comment_status) |
|---|
| 85 | $class .= ' unapproved'; |
|---|
| 86 | if ($i % 2) |
|---|
| 87 | $class .= ' alternate'; |
|---|
| 88 | echo "<li id='comment-$comment->comment_ID' class='$class'>"; |
|---|
| 89 | ?> |
|---|
| 90 | <p><strong><?php comment_author() ?></strong> <?php if ($comment->comment_author_email) { ?>| |
|---|
| 91 | <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> |
|---|
| 92 | | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a |
|---|
| 93 | href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p> |
|---|
| 94 | |
|---|
| 95 | <?php comment_text() ?> |
|---|
| 96 | |
|---|
| 97 | <p><?php comment_date('M j, g:i A'); ?> — [ <?php |
|---|
| 98 | if ( current_user_can('edit_post', $comment->comment_post_ID) ) { |
|---|
| 99 | echo " <a href='comment.php?action=editcomment&c=".$comment->comment_ID."'>" . __('Edit') . '</a>'; |
|---|
| 100 | 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> '; |
|---|
| 101 | if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) { |
|---|
| 102 | 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>'; |
|---|
| 103 | 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>'; |
|---|
| 104 | } |
|---|
| 105 | 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> "; |
|---|
| 106 | } |
|---|
| 107 | $post = get_post($comment->comment_post_ID); |
|---|
| 108 | $post_title = wp_specialchars( $post->post_title, 'double' ); |
|---|
| 109 | $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title; |
|---|
| 110 | ?> | <a href="<?php echo get_permalink($comment->comment_post_ID); ?>" |
|---|
| 111 | title="<?php echo $post_title; ?>"><?php _e('View Post') ?></a> ]</p> |
|---|
| 112 | </li> |
|---|
| 113 | |
|---|
| 114 | <?php } // end foreach($comment) ?> |
|---|
| 115 | </ol> |
|---|
| 116 | |
|---|
| 117 | <div id="ajax-response"></div> |
|---|
| 118 | |
|---|
| 119 | <?php |
|---|
| 120 | } else { //no comments to show |
|---|
| 121 | |
|---|
| 122 | ?> |
|---|
| 123 | <p><strong><?php _e('No comments found.') ?></strong></p> |
|---|
| 124 | |
|---|
| 125 | <?php |
|---|
| 126 | } // end if ($comments) |
|---|
| 127 | } elseif ('edit' == $mode) { |
|---|
| 128 | |
|---|
| 129 | if ($comments) { |
|---|
| 130 | echo '<form name="deletecomments" id="deletecomments" action="" method="post"> '; |
|---|
| 131 | wp_nonce_field('bulk-comments'); |
|---|
| 132 | echo '<table class="widefat"> |
|---|
| 133 | <thead> |
|---|
| 134 | <tr> |
|---|
| 135 | <th scope="col" style="text-align: center"><input type="checkbox" onclick="checkAll(document.getElementById(\'deletecomments\'));" /></th> |
|---|
| 136 | <th scope="col">' . __('Name') . '</th> |
|---|
| 137 | <th scope="col">' . __('E-mail') . '</th> |
|---|
| 138 | <th scope="col">' . __('IP') . '</th> |
|---|
| 139 | <th scope="col">' . __('Comment Excerpt') . '</th> |
|---|
| 140 | <th scope="col" colspan="3" style="text-align: center">' . __('Actions') . '</th> |
|---|
| 141 | </tr> |
|---|
| 142 | </thead>'; |
|---|
| 143 | foreach ($comments as $comment) { |
|---|
| 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 | $class = ('alternate' == $class) ? '' : 'alternate'; |
|---|
| 147 | $class .= ('unapproved' == $comment_status) ? ' unapproved' : ''; |
|---|
| 148 | ?> |
|---|
| 149 | <tr id="comment-<?php echo $comment->comment_ID; ?>" |
|---|
| 150 | class='<?php echo $class; ?>'> |
|---|
| 151 | <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { ?><input |
|---|
| 152 | type="checkbox" name="delete_comments[]" |
|---|
| 153 | value="<?php echo $comment->comment_ID; ?>" /><?php } ?></td> |
|---|
| 154 | <td><?php comment_author_link() ?></td> |
|---|
| 155 | <td><?php comment_author_email_link() ?></td> |
|---|
| 156 | <td><a |
|---|
| 157 | href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></td> |
|---|
| 158 | <td><?php comment_excerpt(); ?></td> |
|---|
| 159 | <td><?php if ('unapproved' == $comment_status) { ?> (Unapproved) <?php } else { ?> |
|---|
| 160 | <a |
|---|
| 161 | href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" |
|---|
| 162 | class="edit"><?php _e('View') ?></a> <?php } ?></td> |
|---|
| 163 | <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { |
|---|
| 164 | echo "<a href='comment.php?action=editcomment&c=$comment->comment_ID' class='edit'>" . __('Edit') . "</a>"; } ?></td> |
|---|
| 165 | <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { |
|---|
| 166 | echo "<a href=\"comment.php?action=deletecomment&p=".$comment->comment_post_ID."&c=".$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 );\" class='delete'>" . __('Delete') . "</a> "; |
|---|
| 167 | } ?></td> |
|---|
| 168 | </tr> |
|---|
| 169 | <?php |
|---|
| 170 | } // end foreach |
|---|
| 171 | ?> |
|---|
| 172 | </table> |
|---|
| 173 | <p class="submit"><input type="submit" name="delete_button" |
|---|
| 174 | class="delete" value="<?php _e('Delete Checked Comments »') ?>" |
|---|
| 175 | 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 + '"); ?>')" /> |
|---|
| 176 | <input type="submit" name="spam_button" |
|---|
| 177 | value="<?php _e('Mark Checked Comments as Spam »') ?>" |
|---|
| 178 | 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> |
|---|
| 179 | </form> |
|---|
| 180 | <div id="ajax-response"></div> |
|---|
| 181 | <?php |
|---|
| 182 | } else { |
|---|
| 183 | ?> |
|---|
| 184 | <p><strong><?php _e('No results found.') ?></strong></p> |
|---|
| 185 | <?php |
|---|
| 186 | } // end if ($comments) |
|---|
| 187 | show_comment_page_nav($total, $page); |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | function show_comment_page_nav($total, $page) { |
|---|
| 192 | |
|---|
| 193 | if ( $total > 20 ) { |
|---|
| 194 | $total_pages = ceil( $total / 20 ); |
|---|
| 195 | $r = ''; |
|---|
| 196 | if ( 1 < $page ) { |
|---|
| 197 | $args['apage'] = ( 1 == $page - 1 ) ? false : $page - 1; |
|---|
| 198 | $r .= '<a class="prev" href="' . add_query_arg( $args ) . '">« '. __('Previous Page') .'</a>' . "\n"; |
|---|
| 199 | } |
|---|
| 200 | if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) { |
|---|
| 201 | for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) { |
|---|
| 202 | if ( $page == $page_num ) { |
|---|
| 203 | $r .= "<span>$page_num</span>\n"; |
|---|
| 204 | } else { |
|---|
| 205 | $p = false; |
|---|
| 206 | if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) { |
|---|
| 207 | $args['apage'] = ( 1 == $page_num ) ? false : $page_num; |
|---|
| 208 | $r .= '<a class="page-numbers" href="' . add_query_arg($args) . '">' . ( $page_num ) . "</a>\n"; |
|---|
| 209 | $in = true; |
|---|
| 210 | } else if ( $in == true ) { |
|---|
| 211 | $r .= "...\n"; |
|---|
| 212 | $in = false; |
|---|
| 213 | } |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | } |
|---|
| 217 | if ( ( $page ) * 20 < $total || -1 == $total ) { |
|---|
| 218 | $args['apage'] = $page + 1; |
|---|
| 219 | $r .= '<a class="next" href="' . add_query_arg($args) . '">'. __('Next Page') .' »</a>' . "\n"; |
|---|
| 220 | } |
|---|
| 221 | echo "<p class='pagenav'>$r</p>"; |
|---|
| 222 | } |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | ?> |
|---|