[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Plugins List Table class.
   4   *
   5   * @package WordPress
   6   * @subpackage List_Table
   7   * @since 3.1.0
   8   * @access private
   9   */
  10  class WP_Plugins_List_Table extends WP_List_Table {
  11  
  12  	function __construct() {
  13          global $status, $page;
  14  
  15          $default_status = get_user_option( 'plugins_last_view' );
  16          if ( empty( $default_status ) )
  17              $default_status = 'all';
  18          $status = isset( $_REQUEST['plugin_status'] ) ? $_REQUEST['plugin_status'] : $default_status;
  19          if ( !in_array( $status, array( 'all', 'active', 'inactive', 'recently_activated', 'upgrade', 'network', 'mustuse', 'dropins', 'search' ) ) )
  20              $status = 'all';
  21          if ( $status != $default_status && 'search' != $status )
  22              update_user_meta( get_current_user_id(), 'plugins_last_view', $status );
  23  
  24          $page = $this->get_pagenum();
  25  
  26          parent::__construct( array(
  27              'plural' => 'plugins',
  28          ) );
  29      }
  30      
  31  	function get_table_classes() {
  32          return array( 'widefat', $this->_args['plural'] );
  33      }
  34  
  35  	function ajax_user_can() {
  36          if ( is_multisite() ) {
  37              $menu_perms = get_site_option( 'menu_items', array() );
  38  
  39              if ( empty( $menu_perms['plugins'] ) && ! is_super_admin() )
  40                  return false;
  41          }
  42  
  43          return current_user_can('activate_plugins');
  44      }
  45  
  46  	function prepare_items() {
  47          global $status, $plugins, $totals, $page, $orderby, $order, $s;
  48  
  49          wp_reset_vars( array( 'orderby', 'order', 's' ) );
  50  
  51          $plugins = array(
  52              'all' => apply_filters( 'all_plugins', get_plugins() ),
  53              'search' => array(),
  54              'active' => array(),
  55              'inactive' => array(),
  56              'recently_activated' => array(),
  57              'upgrade' => array(),
  58              'mustuse' => array(),
  59              'dropins' => array()
  60          );
  61  
  62          $screen = get_current_screen();
  63  
  64          if ( ! is_multisite() || ( $screen->is_network && current_user_can('manage_network_plugins') ) ) {
  65              if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
  66                  $plugins['mustuse'] = get_mu_plugins();
  67              if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
  68                  $plugins['dropins'] = get_dropins();
  69  
  70              $current = get_site_transient( 'update_plugins' );
  71              foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
  72                  if ( isset( $current->response[ $plugin_file ] ) )
  73                      $plugins['upgrade'][ $plugin_file ] = $plugin_data;
  74              }
  75          }
  76  
  77          set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 );
  78  
  79          $recently_activated = get_option( 'recently_activated', array() );
  80  
  81          $one_week = 7*24*60*60;
  82          foreach ( $recently_activated as $key => $time )
  83              if ( $time + $one_week < time() )
  84                  unset( $recently_activated[$key] );
  85          update_option( 'recently_activated', $recently_activated );
  86  
  87          foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
  88              // Filter into individual sections
  89              if ( is_multisite() && is_network_only_plugin( $plugin_file ) && !$screen->is_network ) {
  90                  unset( $plugins['all'][ $plugin_file] );
  91              } elseif ( is_plugin_active_for_network($plugin_file) && !$screen->is_network ) {
  92                  unset( $plugins['all'][ $plugin_file ] );
  93              } elseif ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) {
  94                  $plugins['network'][ $plugin_file ] = $plugin_data;
  95              } elseif ( ( !$screen->is_network && is_plugin_active( $plugin_file ) )
  96                  || ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) {
  97                  $plugins['active'][ $plugin_file ] = $plugin_data;
  98              } else {
  99                  if ( !$screen->is_network && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
 100                      $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
 101                  $plugins['inactive'][ $plugin_file ] = $plugin_data;
 102              }
 103          }
 104  
 105          if ( !current_user_can( 'update_plugins' ) )
 106              $plugins['upgrade'] = array();
 107  
 108          if ( $s ) {
 109              $status = 'search';
 110              $plugins['search'] = array_filter( $plugins['all'], array( &$this, '_search_callback' ) );
 111          }
 112  
 113          $totals = array();
 114          foreach ( $plugins as $type => $list )
 115              $totals[ $type ] = count( $list );
 116  
 117          if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
 118              $status = 'all';
 119  
 120          $this->items = array();
 121          foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
 122              // Translate, Don't Apply Markup, Sanitize HTML
 123              $this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
 124          }
 125  
 126          $total_this_page = $totals[ $status ];
 127  
 128          if ( $orderby ) {
 129              $orderby = ucfirst( $orderby );
 130              $order = strtoupper( $order );
 131  
 132              uasort( $this->items, array( &$this, '_order_callback' ) );
 133          }
 134  
 135          $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ) );
 136  
 137          $start = ( $page - 1 ) * $plugins_per_page;
 138  
 139          if ( $total_this_page > $plugins_per_page )
 140              $this->items = array_slice( $this->items, $start, $plugins_per_page );
 141  
 142          $this->set_pagination_args( array(
 143              'total_items' => $total_this_page,
 144              'per_page' => $plugins_per_page,
 145          ) );
 146      }
 147  
 148  	function _search_callback( $plugin ) {
 149          static $term;
 150          if ( is_null( $term ) )
 151              $term = stripslashes( $_REQUEST['s'] );
 152  
 153          foreach ( $plugin as $value )
 154              if ( stripos( $value, $term ) !== false )
 155                  return true;
 156  
 157          return false;
 158      }
 159  
 160  	function _order_callback( $plugin_a, $plugin_b ) {
 161          global $orderby, $order;
 162  
 163          $a = $plugin_a[$orderby];
 164          $b = $plugin_b[$orderby];
 165  
 166          if ( $a == $b )
 167              return 0;
 168  
 169          if ( 'DESC' == $order )
 170              return ( $a < $b ) ? 1 : -1;
 171          else
 172              return ( $a < $b ) ? -1 : 1;
 173      }
 174  
 175  	function no_items() {
 176          global $plugins;
 177  
 178          if ( !empty( $plugins['all'] ) )
 179              _e( 'No plugins found.' );
 180          else
 181              _e( 'You do not appear to have any plugins available at this time.' );
 182      }
 183  
 184  	function get_columns() {
 185          global $status;
 186  
 187          return array(
 188              'cb'          => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
 189              'name'        => __( 'Plugin' ),
 190              'description' => __( 'Description' ),
 191          );
 192      }
 193  
 194  	function get_sortable_columns() {
 195          return array();
 196      }
 197  
 198  	function get_views() {
 199          global $totals, $status;
 200  
 201          $status_links = array();
 202          foreach ( $totals as $type => $count ) {
 203              if ( !$count )
 204                  continue;
 205  
 206              switch ( $type ) {
 207                  case 'all':
 208                      $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
 209                      break;
 210                  case 'active':
 211                      $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
 212                      break;
 213                  case 'recently_activated':
 214                      $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
 215                      break;
 216                  case 'inactive':
 217                      $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
 218                      break;
 219                  case 'network':
 220                      $text = _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $count );
 221                      break;
 222                  case 'mustuse':
 223                      $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
 224                      break;
 225                  case 'dropins':
 226                      $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
 227                      break;
 228                  case 'upgrade':
 229                      $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
 230                      break;
 231              }
 232  
 233              if ( 'search' != $type ) {
 234                  $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
 235                      add_query_arg('plugin_status', $type, 'plugins.php'),
 236                      ( $type == $status ) ? ' class="current"' : '',
 237                      sprintf( $text, number_format_i18n( $count ) )
 238                      );
 239              }
 240          }
 241  
 242          return $status_links;
 243      }
 244  
 245  	function get_bulk_actions() {
 246          global $status;
 247  
 248          $actions = array();
 249  
 250          $screen = get_current_screen();
 251  
 252          if ( 'active' != $status ) {
 253              $action = $screen->is_network ? 'network-activate-selected' : 'activate-selected';
 254              $actions[ $action ] = __( 'Activate' );
 255          }
 256  
 257          if ( 'inactive' != $status && 'recent' != $status )
 258              $actions['deactivate-selected'] = __( 'Deactivate' );
 259  
 260          if ( !is_multisite() || $screen->is_network ) {
 261              if ( current_user_can( 'update_plugins' ) )
 262                  $actions['update-selected'] = __( 'Update' );
 263              if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
 264                  $actions['delete-selected'] = __( 'Delete' );
 265          }
 266  
 267          return $actions;
 268      }
 269  
 270  	function bulk_actions( $which ) {
 271          global $status;
 272  
 273          if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
 274              return;
 275  
 276          parent::bulk_actions( $which );
 277      }
 278  
 279  	function extra_tablenav( $which ) {
 280          global $status;
 281  
 282          if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) )
 283              return;
 284  
 285          echo '<div class="alignleft actions">';
 286  
 287          if ( 'recently_activated' == $status )
 288              submit_button( __( 'Clear List' ), 'secondary', 'clear-recent-list', false );
 289          elseif ( 'top' == $which && 'mustuse' == $status )
 290              echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>';
 291          elseif ( 'top' == $which && 'dropins' == $status )
 292              echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the <code>%s</code> directory that replace WordPress functionality when present.' ), str_replace( ABSPATH, '', WP_CONTENT_DIR ) ) . '</p>';
 293  
 294          echo '</div>';
 295      }
 296  
 297  	function current_action() {
 298          if ( isset($_POST['clear-recent-list']) )
 299              return 'clear-recent-list';
 300  
 301          return parent::current_action();
 302      }
 303  
 304  	function display_rows() {
 305          global $status;
 306  
 307          $screen = get_current_screen();
 308  
 309          if ( is_multisite() && !$screen->is_network && in_array( $status, array( 'mustuse', 'dropins' ) ) )
 310              return;
 311  
 312          foreach ( $this->items as $plugin_file => $plugin_data )
 313              $this->single_row( $plugin_file, $plugin_data );
 314      }
 315  
 316  	function single_row( $plugin_file, $plugin_data ) {
 317          global $status, $page, $s;
 318  
 319          $context = $status;
 320  
 321          $screen = get_current_screen();
 322  
 323          // preorder
 324          $actions = array(
 325              'network_deactivate' => '', 'deactivate' => '',
 326              'network_only' => '', 'activate' => '',
 327              'network_activate' => '',
 328              'edit' => '',
 329              'delete' => '',
 330          );
 331  
 332          if ( 'mustuse' == $context ) {
 333              $is_active = true;
 334          } elseif ( 'dropins' == $context ) {
 335              $dropins = _get_dropins();
 336              $plugin_name = $plugin_file;
 337              if ( $plugin_file != $plugin_data['Name'] )
 338                  $plugin_name .= '<br/>' . $plugin_data['Name'];
 339              if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
 340                  $is_active = true;
 341                  $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
 342              } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
 343                  $is_active = true;
 344                  $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
 345              } else {
 346                  $is_active = false;
 347                  $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf( __( 'Requires <code>%s</code> in <code>wp-config.php</code>.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);" ) . '</p>';
 348              }
 349              if ( $plugin_data['Description'] )
 350                  $description .= '<p>' . $plugin_data['Description'] . '</p>';
 351          } else {
 352              $is_active_for_network = is_plugin_active_for_network($plugin_file);
 353              if ( $screen->is_network )
 354                  $is_active = $is_active_for_network;
 355              else
 356                  $is_active = is_plugin_active( $plugin_file );
 357  
 358              if ( $is_active_for_network && !is_super_admin() && !$screen->is_network )
 359                  return;
 360  
 361              if ( $screen->is_network ) {
 362                  if ( $is_active_for_network ) {
 363                      if ( current_user_can( 'manage_network_plugins' ) )
 364                          $actions['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
 365                  } else {
 366                      if ( current_user_can( 'manage_network_plugins' ) )
 367                          $actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
 368                      if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) )
 369                          $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
 370                  }
 371              } else {
 372                  if ( $is_active ) {
 373                      $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
 374                  } else {
 375                      $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
 376  
 377                      if ( ! is_multisite() && current_user_can('delete_plugins') )
 378                          $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
 379                  } // end if $is_active
 380               } // end if $screen->is_network
 381  
 382              if ( ( ! is_multisite() || $screen->is_network ) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
 383                  $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
 384          } // end if $context
 385  
 386          $prefix = $screen->is_network ? 'network_admin_' : '';
 387          $actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
 388          $actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
 389  
 390          $class = $is_active ? 'active' : 'inactive';
 391          $checkbox_id =  "checkbox_" . md5($plugin_data['Name']);
 392          $checkbox = in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $plugin_data['Name'] . "</label>";
 393          if ( 'dropins' != $context ) {
 394              $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;' ) . '</p>';
 395              $plugin_name = $plugin_data['Name'];
 396          }
 397  
 398          $id = sanitize_title( $plugin_name );
 399  
 400          echo "<tr id='$id' class='$class'>";
 401  
 402          list( $columns, $hidden ) = $this->get_column_info();
 403  
 404          foreach ( $columns as $column_name => $column_display_name ) {
 405              $style = '';
 406              if ( in_array( $column_name, $hidden ) )
 407                  $style = ' style="display:none;"';
 408  
 409              switch ( $column_name ) {
 410                  case 'cb':
 411                      echo "<th scope='row' class='check-column'>$checkbox</th>";
 412                      break;
 413                  case 'name':
 414                      echo "<td class='plugin-title'$style><strong>$plugin_name</strong>";
 415                      echo $this->row_actions( $actions, true );
 416                      echo "</td>";
 417                      break;
 418                  case 'description':
 419                      echo "<td class='column-description desc'$style>
 420                          <div class='plugin-description'>$description</div>
 421                          <div class='$class second plugin-version-author-uri'>";
 422  
 423                      $plugin_meta = array();
 424                      if ( !empty( $plugin_data['Version'] ) )
 425                          $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
 426                      if ( !empty( $plugin_data['Author'] ) ) {
 427                          $author = $plugin_data['Author'];
 428                          if ( !empty( $plugin_data['AuthorURI'] ) )
 429                              $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
 430                          $plugin_meta[] = sprintf( __( 'By %s' ), $author );
 431                      }
 432                      if ( ! empty( $plugin_data['PluginURI'] ) )
 433                          $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin site' ) . '">' . __( 'Visit plugin site' ) . '</a>';
 434  
 435                      $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
 436                      echo implode( ' | ', $plugin_meta );
 437  
 438                      echo "</div></td>";
 439                      break;
 440                  default:
 441                      echo "<td class='$column_name column-$column_name'$style>";
 442                      do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
 443                      echo "</td>";
 444              }
 445          }
 446  
 447          echo "</tr>";
 448  
 449          do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
 450          do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );
 451      }
 452  }
 453  
 454  ?>


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