PHP Cross Reference of WordPress Subversion HEAD

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

title

Body

[close]

/wp-admin/ -> edit-comments.php (source)

   1  <?php
   2  require_once ('admin.php');
   3  
   4  $title = __('Edit Comments');
   5  $parent_file = 'edit-comments.php';
   6  wp_enqueue_script( 'admin-comments' );
   7  
   8  require_once ('admin-header.php');
   9  if (empty($_GET['mode'])) $mode = 'view';
  10  else $mode = attribute_escape($_GET['mode']);
  11  ?>
  12  
  13  <script type="text/javascript">
  14  <!--
  15  function checkAll(form)
  16  {
  17      for (i = 0, n = form.elements.length; i < n; i++) {
  18          if(form.elements[i].type == "checkbox") {
  19              if(form.elements[i].checked == true)
  20                  form.elements[i].checked = false;
  21              else
  22                  form.elements[i].checked = true;
  23          }
  24      }
  25  }
  26  
  27  function getNumChecked(form)
  28  {
  29      var num = 0;
  30      for (i = 0, n = form.elements.length; i < n; i++) {
  31          if(form.elements[i].type == "checkbox") {
  32              if(form.elements[i].checked == true)
  33                  num++;
  34          }
  35      }
  36      return num;
  37  }
  38  //-->
  39  </script>
  40  <div class="wrap">
  41  <h2><?php _e('Comments'); ?></h2>
  42  <form name="searchform" action="" method="get" id="editcomments">
  43    <fieldset>
  44    <legend><?php _e('Show Comments That Contain...') ?></legend>
  45    <input type="text" name="s" value="<?php if (isset($_GET['s'])) echo attribute_escape($_GET['s']); ?>" size="17" />
  46    <input type="submit" name="submit" value="<?php _e('Search') ?>"  />
  47    <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
  48    <?php _e('(Searches within comment text, e-mail, URL, and IP address.)') ?>
  49    </fieldset>
  50  </form>
  51  <p><a href="?mode=view"><?php _e('View Mode') ?></a> | <a href="?mode=edit"><?php _e('Mass Edit Mode') ?></a></p>
  52  <?php
  53  if ( !empty( $_POST['delete_comments'] ) ) :
  54      check_admin_referer('bulk-comments');
  55  
  56      $i = 0;
  57      foreach ($_POST['delete_comments'] as $comment) : // Check the permissions on each
  58          $comment = (int) $comment;
  59          $post_id = (int) $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment");
  60          // $authordata = get_userdata( $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id") );
  61          if ( current_user_can('edit_post', $post_id) ) {
  62              if ( !empty( $_POST['spam_button'] ) )
  63                  wp_set_comment_status($comment, 'spam');
  64              else
  65                  wp_set_comment_status($comment, 'delete');
  66              ++$i;
  67          }
  68      endforeach;
  69      echo '<div style="background-color: rgb(207, 235, 247);" id="message" class="updated fade"><p>';
  70      if ( !empty( $_POST['spam_button'] ) ) {
  71          printf(__ngettext('%s comment marked as spam', '%s comments marked as spam.', $i), $i);
  72      } else {
  73          printf(__ngettext('%s comment deleted.', '%s comments deleted.', $i), $i);
  74      }
  75      echo '</p></div>';
  76  endif;
  77  
  78  if ( isset( $_GET['apage'] ) )
  79      $page = abs( (int) $_GET['apage'] );
  80  else
  81      $page = 1;
  82  
  83  $start = $offset = ( $page - 1 ) * 20;
  84  
  85  list($_comments, $total) = _wp_get_comment_list( isset($_GET['s']) ? $_GET['s'] : false, $start, 25 ); // Grab a few extra
  86  
  87  $comments = array_slice($_comments, 0, 20);
  88  $extra_comments = array_slice($_comments, 20);
  89  
  90  $page_links = paginate_links( array(
  91      'base' => add_query_arg( 'apage', '%#%' ),
  92      'format' => '',
  93      'total' => ceil($total / 20),
  94      'current' => $page
  95  ));
  96  
  97  if ( $page_links )
  98      echo "<p class='pagenav'>$page_links</p>";
  99  
 100  if ('view' == $mode) {
 101      if ($comments) {
 102          $offset = $offset + 1;
 103          $start = " start='$offset'";
 104  
 105          echo "<ol id='the-comment-list' class='list:comment commentlist' $start>\n";
 106          $i = 0;
 107          foreach ( $comments as $comment ) {
 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  <ol id="the-extra-comment-list" class="list:comment commentlist" style="color:red">
 115  <?php
 116      foreach ( $extra_comments as $comment ) {
 117          get_comment( $comment ); // Cache it
 118          _wp_comment_list_item( $comment->comment_ID, 0 );
 119      }
 120  ?>
 121  </ol>
 122  <form action="" method="get" id="get-extra-comments" class="add:the-extra-comment-list:">
 123  <input type="hidden" name="page" value="<?php echo $page; ?>" />
 124  <input type="hidden" name="s" value="<?php echo attribute_escape(@$_GET['s']); ?>" />
 125  <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
 126  </div>
 127  <?php endif; // $extra_comments ?>
 128  
 129  <div id="ajax-response"></div>
 130  
 131  <?php
 132      } else { //no comments to show
 133  
 134          ?>
 135          <p>
 136              <strong><?php _e('No comments found.') ?></strong></p>
 137  
 138          <?php
 139      } // end if ($comments)
 140  } elseif ('edit' == $mode) {
 141  
 142      if ($comments) {
 143          echo '<form name="deletecomments" id="deletecomments" action="" method="post"> ';
 144          wp_nonce_field('bulk-comments');
 145          echo '<table class="widefat">
 146  <thead>
 147    <tr>
 148      <th scope="col" style="text-align: center"><input type="checkbox" onclick="checkAll(document.getElementById(\'deletecomments\'));" /></th>
 149      <th scope="col">' .  __('Name') . '</th>
 150      <th scope="col">' .  __('E-mail') . '</th>
 151      <th scope="col">' . __('IP') . '</th>
 152      <th scope="col">' . __('Comment Excerpt') . '</th>
 153      <th scope="col" colspan="3" style="text-align: center">' .  __('Actions') . '</th>
 154    </tr>
 155  </thead>
 156  <tbody id="the-comment-list" class="list:comment">';
 157          foreach ($comments as $comment) {
 158          $post = get_post($comment->comment_post_ID);
 159          $authordata = get_userdata($post->post_author);
 160          $comment_status = wp_get_comment_status($comment->comment_ID);
 161          $class = ('alternate' == $class) ? '' : 'alternate';
 162          $class .= ('unapproved' == $comment_status) ? ' unapproved' : '';
 163  ?>
 164    <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
 165      <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>
 166      <td class="comment-author"><?php comment_author_link() ?></td>
 167      <td><?php comment_author_email_link() ?></td>
 168      <td><a href="edit-comments.php?s=<?php comment_author_IP() ?>&amp;mode=edit"><?php comment_author_IP() ?></a></td>
 169      <td><?php comment_excerpt(); ?></td>
 170      <td>
 171          <?php if ('unapproved' == $comment_status) {
 172              _e('Unapproved');
 173          } else { ?>
 174              <a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a>
 175          <?php } ?>
 176      </td>
 177      <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
 178      echo "<a href='comment.php?action=editcomment&amp;c=$comment->comment_ID' class='edit'>" .  __('Edit') . "</a>"; } ?></td>
 179      <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
 180          $url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
 181          echo "<a href='$url' class='delete:the-comment-list:comment-$comment->comment_ID delete'>" . __('Delete') . "</a> ";
 182          } ?></td>
 183    </tr>
 184          <?php
 185          } // end foreach
 186      ?></tbody>
 187  </table>
 188  <p class="submit"><input type="submit" name="delete_button" class="delete" value="<?php _e('Delete Checked Comments &raquo;') ?>" 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 + '"); ?>')" />
 189              <input type="submit" name="spam_button" value="<?php _e('Mark Checked Comments as Spam &raquo;') ?>" 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>
 190    </form>
 191  <div id="ajax-response"></div>
 192  <?php
 193      } else {
 194  ?>
 195  <p>
 196  <strong><?php _e('No results found.') ?></strong>
 197  </p>
 198  <?php
 199      } // end if ($comments)
 200  }
 201  
 202  if ( $page_links )
 203      echo "<p class='pagenav'>$page_links</p>";
 204  
 205  ?>
 206  
 207  </div>
 208  
 209  <?php include ('admin-footer.php'); ?>


Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs Cross-referenced by PHPXref 0.6 and RedAlt