[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-admin/includes/ -> class-wp-media-list-table.php (source)

   1  <?php
   2  /**
   3   * Media Library List Table class.
   4   *
   5   * @package WordPress
   6   * @subpackage List_Table
   7   * @since 3.1.0
   8   * @access private
   9   */
  10  class WP_Media_List_Table extends WP_List_Table {
  11  
  12  	function __construct() {
  13          $this->detached = isset( $_REQUEST['detached'] ) || isset( $_REQUEST['find_detached'] );
  14  
  15          parent::__construct( array(
  16              'plural' => 'media'
  17          ) );
  18      }
  19  
  20  	function ajax_user_can() {
  21          return current_user_can('upload_files');
  22      }
  23  
  24  	function prepare_items() {
  25          global $lost, $wpdb, $wp_query, $post_mime_types, $avail_post_mime_types;
  26  
  27          $q = $_REQUEST;
  28  
  29          if ( !empty( $lost ) )
  30              $q['post__in'] = implode( ',', $lost );
  31  
  32          list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $q );
  33  
  34           $this->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status'];
  35  
  36          $this->set_pagination_args( array(
  37              'total_items' => $wp_query->found_posts,
  38              'total_pages' => $wp_query->max_num_pages,
  39              'per_page' => $wp_query->query_vars['posts_per_page'],
  40          ) );
  41      }
  42  
  43  	function get_views() {
  44          global $wpdb, $post_mime_types, $avail_post_mime_types;
  45  
  46          $type_links = array();
  47          $_num_posts = (array) wp_count_attachments();
  48          $_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
  49          if ( !isset( $total_orphans ) )
  50                  $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" );
  51          $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
  52          foreach ( $matches as $type => $reals )
  53              foreach ( $reals as $real )
  54                  $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
  55  
  56          $class = ( empty($_GET['post_mime_type']) && !$this->detached && !isset($_GET['status']) ) ? ' class="current"' : '';
  57          $type_links['all'] = "<a href='upload.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</a>';
  58          foreach ( $post_mime_types as $mime_type => $label ) {
  59              $class = '';
  60  
  61              if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
  62                  continue;
  63  
  64              if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
  65                  $class = ' class="current"';
  66              if ( !empty( $num_posts[$mime_type] ) )
  67                  $type_links[$mime_type] = "<a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>';
  68          }
  69          $type_links['detached'] = '<a href="upload.php?detached=1"' . ( $this->detached ? ' class="current"' : '' ) . '>' . sprintf( _nx( 'Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</a>';
  70  
  71          if ( !empty($_num_posts['trash']) )
  72              $type_links['trash'] = '<a href="upload.php?status=trash"' . ( (isset($_GET['status']) && $_GET['status'] == 'trash' ) ? ' class="current"' : '') . '>' . sprintf( _nx( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</a>';
  73  
  74          return $type_links;
  75      }
  76  
  77  	function get_bulk_actions() {
  78          $actions = array();
  79          $actions['delete'] = __( 'Delete Permanently' );
  80          if ( $this->detached )
  81              $actions['attach'] = __( 'Attach to a post' );
  82  
  83          return $actions;
  84      }
  85  
  86  	function extra_tablenav( $which ) {
  87          global $post_type;
  88          $post_type_obj = get_post_type_object( $post_type );
  89  ?>
  90          <div class="alignleft actions">
  91  <?php
  92          if ( 'top' == $which && !is_singular() && !$this->detached && !$this->is_trash ) {
  93              $this->months_dropdown( $post_type );
  94  
  95              do_action( 'restrict_manage_posts' );
  96              submit_button( __( 'Filter' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) );
  97          }
  98  
  99          if ( $this->detached ) {
 100              submit_button( __( 'Scan for lost attachments' ), 'secondary', 'find_detached', false );
 101          } elseif ( $this->is_trash && current_user_can( 'edit_others_posts' ) ) {
 102              submit_button( __( 'Empty Trash' ), 'button-secondary apply', 'delete_all', false );
 103          } ?>
 104          </div>
 105  <?php
 106      }
 107  
 108  	function current_action() {
 109          if ( isset( $_REQUEST['find_detached'] ) )
 110              return 'find_detached';
 111  
 112          if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
 113              return 'attach';
 114  
 115          if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
 116              return 'delete_all';
 117  
 118          return parent::current_action();
 119      }
 120  
 121  	function has_items() {
 122          return have_posts();
 123      }
 124  
 125  	function no_items() {
 126          _e( 'No media attachments found.' );
 127      }
 128  
 129  	function get_columns() {
 130          $posts_columns = array();
 131          $posts_columns['cb'] = '<input type="checkbox" />';
 132          $posts_columns['icon'] = '';
 133          /* translators: column name */
 134          $posts_columns['title'] = _x( 'File', 'column name' );
 135          $posts_columns['author'] = __( 'Author' );
 136          //$posts_columns['tags'] = _x( 'Tags', 'column name' );
 137          /* translators: column name */
 138          if ( !$this->detached ) {
 139              $posts_columns['parent'] = _x( 'Attached to', 'column name' );
 140              $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>';
 141          }
 142          /* translators: column name */
 143          $posts_columns['date'] = _x( 'Date', 'column name' );
 144          $posts_columns = apply_filters( 'manage_media_columns', $posts_columns, $this->detached );
 145  
 146          return $posts_columns;
 147      }
 148  
 149  	function get_sortable_columns() {
 150          return array(
 151              'title'    => 'title',
 152              'author'   => 'author',
 153              'parent'   => 'parent',
 154              'comments' => 'comment_count',
 155              'date'     => array( 'date', true ),
 156          );
 157      }
 158  
 159  	function display_rows() {
 160          global $post, $id;
 161  
 162          add_filter( 'the_title','esc_html' );
 163          $alt = '';
 164  
 165          while ( have_posts() ) : the_post();
 166  
 167              if ( $this->is_trash && $post->post_status != 'trash'
 168              ||  !$this->is_trash && $post->post_status == 'trash' )
 169                  continue;
 170  
 171              $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
 172              $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other';
 173              $att_title = _draft_or_post_title();
 174  ?>
 175      <tr id='post-<?php echo $id; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">
 176  <?php
 177  
 178  list( $columns, $hidden ) = $this->get_column_info();
 179  foreach ( $columns as $column_name => $column_display_name ) {
 180      $class = "class='$column_name column-$column_name'";
 181  
 182      $style = '';
 183      if ( in_array( $column_name, $hidden ) )
 184          $style = ' style="display:none;"';
 185  
 186      $attributes = $class . $style;
 187  
 188      switch ( $column_name ) {
 189  
 190      case 'cb':
 191  ?>
 192          <th scope="row" class="check-column"><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><input type="checkbox" name="media[]" value="<?php the_ID(); ?>" /><?php } ?></th>
 193  <?php
 194          break;
 195  
 196      case 'icon':
 197          $attributes = 'class="column-icon media-icon"' . $style;
 198  ?>
 199          <td <?php echo $attributes ?>><?php
 200              if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) {
 201                  if ( $this->is_trash ) {
 202                      echo $thumb;
 203                  } else {
 204  ?>
 205                  <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
 206                      <?php echo $thumb; ?>
 207                  </a>
 208  
 209  <?php            }
 210              }
 211  ?>
 212          </td>
 213  <?php
 214          break;
 215  
 216      case 'title':
 217  ?>
 218          <td <?php echo $attributes ?>><strong><?php if ( $this->is_trash ) echo $att_title; else { ?><a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>"><?php echo $att_title; ?></a><?php }; _media_states( $post ); ?></strong>
 219              <p>
 220  <?php
 221              if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
 222                  echo esc_html( strtoupper( $matches[1] ) );
 223              else
 224                  echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) );
 225  ?>
 226              </p>
 227  <?php
 228          echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
 229  ?>
 230          </td>
 231  <?php
 232          break;
 233  
 234      case 'author':
 235  ?>
 236          <td <?php echo $attributes ?>><?php the_author() ?></td>
 237  <?php
 238          break;
 239  
 240      case 'tags':
 241  ?>
 242          <td <?php echo $attributes ?>><?php
 243          $tags = get_the_tags();
 244          if ( !empty( $tags ) ) {
 245              $out = array();
 246              foreach ( $tags as $c )
 247                  $out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'post_tag', 'display' ) ) . "</a>";
 248              echo join( ', ', $out );
 249          } else {
 250              _e( 'No Tags' );
 251          }
 252  ?>
 253          </td>
 254  <?php
 255          break;
 256  
 257      case 'desc':
 258  ?>
 259          <td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td>
 260  <?php
 261          break;
 262  
 263      case 'date':
 264          if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
 265              $t_time = $h_time = __( 'Unpublished' );
 266          } else {
 267              $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
 268              $m_time = $post->post_date;
 269              $time = get_post_time( 'G', true, $post, false );
 270              if ( ( abs( $t_diff = time() - $time ) ) < 86400 ) {
 271                  if ( $t_diff < 0 )
 272                      $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) );
 273                  else
 274                      $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
 275              } else {
 276                  $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
 277              }
 278          }
 279  ?>
 280          <td <?php echo $attributes ?>><?php echo $h_time ?></td>
 281  <?php
 282          break;
 283  
 284      case 'parent':
 285          if ( $post->post_parent > 0 ) {
 286              if ( get_post( $post->post_parent ) ) {
 287                  $title =_draft_or_post_title( $post->post_parent );
 288              }
 289  ?>
 290              <td <?php echo $attributes ?>>
 291                  <strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>,
 292                  <?php echo get_the_time( __( 'Y/m/d' ) ); ?>
 293              </td>
 294  <?php
 295          } else {
 296  ?>
 297              <td <?php echo $attributes ?>><?php _e( '(Unattached)' ); ?><br />
 298              <a class="hide-if-no-js" onclick="findPosts.open( 'media[]','<?php echo $post->ID ?>' );return false;" href="#the-list"><?php _e( 'Attach' ); ?></a></td>
 299  <?php
 300          }
 301          break;
 302  
 303      case 'comments':
 304          $attributes = 'class="comments column-comments num"' . $style;
 305  ?>
 306          <td <?php echo $attributes ?>>
 307              <div class="post-com-count-wrapper">
 308  <?php
 309          $pending_comments = get_pending_comments_num( $post->ID );
 310  
 311          $this->comments_bubble( $post->ID, $pending_comments );
 312  ?>
 313              </div>
 314          </td>
 315  <?php
 316          break;
 317  
 318      default:
 319  ?>
 320          <td <?php echo $attributes ?>>
 321              <?php do_action( 'manage_media_custom_column', $column_name, $id ); ?>
 322          </td>
 323  <?php
 324          break;
 325      }
 326  }
 327  ?>
 328      </tr>
 329  <?php endwhile;
 330      }
 331  
 332  	function _get_row_actions( $post, $att_title ) {
 333          $actions = array();
 334  
 335          if ( $this->detached ) {
 336              if ( current_user_can( 'edit_post', $post->ID ) )
 337                  $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>';
 338              if ( current_user_can( 'delete_post', $post->ID ) )
 339                  if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
 340                      $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-attachment_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
 341                  } else {
 342                      $delete_ays = !MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
 343                      $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-attachment_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>";
 344                  }
 345              $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $att_title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
 346              if ( current_user_can( 'edit_post', $post->ID ) )
 347                  $actions['attach'] = '<a href="#the-list" onclick="findPosts.open( \'media[]\',\''.$post->ID.'\' );return false;" class="hide-if-no-js">'.__( 'Attach' ).'</a>';
 348          }
 349          else {
 350              if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash )
 351                  $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>';
 352              if ( current_user_can( 'delete_post', $post->ID ) ) {
 353                  if ( $this->is_trash )
 354                      $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$post->ID", 'untrash-attachment_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
 355                  elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH )
 356                      $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-attachment_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
 357                  if ( $this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH ) {
 358                      $delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
 359                      $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&amp;post=$post->ID", 'delete-attachment_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>";
 360                  }
 361              }
 362              if ( !$this->is_trash ) {
 363                  $title =_draft_or_post_title( $post->post_parent );
 364                  $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
 365              }
 366          }
 367  
 368          $actions = apply_filters( 'media_row_actions', $actions, $post, $this->detached );
 369  
 370          return $actions;
 371      }
 372  }
 373  
 374  ?>


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting