[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Plugin Installer List Table class.
   4   *
   5   * @package WordPress
   6   * @subpackage List_Table
   7   * @since 3.1.0
   8   * @access private
   9   */
  10  class WP_Plugin_Install_List_Table extends WP_List_Table {
  11  
  12  	function ajax_user_can() {
  13          return current_user_can('install_plugins');
  14      }
  15  
  16  	function prepare_items() {
  17          include ( ABSPATH . 'wp-admin/includes/plugin-install.php' );
  18  
  19          global $tabs, $tab, $paged, $type, $term;
  20  
  21          wp_reset_vars( array( 'tab' ) );
  22  
  23          $paged = $this->get_pagenum();
  24  
  25          $per_page = 30;
  26  
  27          // These are the tabs which are shown on the page
  28          $tabs = array();
  29          $tabs['dashboard'] = __( 'Search' );
  30          if ( 'search' == $tab )
  31              $tabs['search']    = __( 'Search Results' );
  32          $tabs['upload'] = __( 'Upload' );
  33          $tabs['featured'] = _x( 'Featured','Plugin Installer' );
  34          $tabs['popular']  = _x( 'Popular','Plugin Installer' );
  35          $tabs['new']      = _x( 'Newest','Plugin Installer' );
  36  
  37          $nonmenu_tabs = array( 'plugin-information' ); //Valid actions to perform which do not have a Menu item.
  38  
  39          $tabs = apply_filters( 'install_plugins_tabs', $tabs );
  40          $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
  41  
  42          // If a non-valid menu tab has been selected, And its not a non-menu action.
  43          if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
  44              $tab = key( $tabs );
  45  
  46          $args = array( 'page' => $paged, 'per_page' => $per_page );
  47  
  48          switch ( $tab ) {
  49              case 'search':
  50                  $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : 'term';
  51                  $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
  52  
  53                  switch ( $type ) {
  54                      case 'tag':
  55                          $args['tag'] = sanitize_title_with_dashes( $term );
  56                          break;
  57                      case 'term':
  58                          $args['search'] = $term;
  59                          break;
  60                      case 'author':
  61                          $args['author'] = $term;
  62                          break;
  63                  }
  64  
  65                  add_action( 'install_plugins_table_header', 'install_search_form', 10, 0 );
  66                  break;
  67  
  68              case 'featured':
  69              case 'popular':
  70              case 'new':
  71                  $args['browse'] = $tab;
  72                  break;
  73  
  74              default:
  75                  $args = false;
  76          }
  77  
  78          if ( !$args )
  79              return;
  80  
  81          $api = plugins_api( 'query_plugins', $args );
  82  
  83          if ( is_wp_error( $api ) )
  84              wp_die( $api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
  85  
  86          $this->items = $api->plugins;
  87  
  88          $this->set_pagination_args( array(
  89              'total_items' => $api->info['results'],
  90              'per_page' => $per_page,
  91          ) );
  92      }
  93  
  94  	function no_items() {
  95          _e( 'No plugins match your request.' );
  96      }
  97  
  98  	function get_views() {
  99          global $tabs, $tab;
 100  
 101          $display_tabs = array();
 102          foreach ( (array) $tabs as $action => $text ) {
 103              $class = ( $action == $tab ) ? ' class="current"' : '';
 104              $href = self_admin_url('plugin-install.php?tab=' . $action);
 105              $display_tabs['plugin-install-'.$action] = "<a href='$href'$class>$text</a>";
 106          }
 107  
 108          return $display_tabs;
 109      }
 110  
 111  	function display_tablenav( $which ) {
 112          if ( 'top' ==  $which ) { ?>
 113              <div class="tablenav top">
 114                  <div class="alignleft actions">
 115                      <?php do_action( 'install_plugins_table_header' ); ?>
 116                  </div>
 117                  <?php $this->pagination( $which ); ?>
 118                  <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
 119                  <br class="clear" />
 120              </div>
 121          <?php } else { ?>
 122              <div class="tablenav bottom">
 123                  <?php $this->pagination( $which ); ?>
 124                  <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
 125                  <br class="clear" />
 126              </div>
 127          <?php
 128          }
 129      }
 130  
 131  	function get_table_classes() {
 132          extract( $this->_args );
 133  
 134          return array( 'widefat', $plural );
 135      }
 136  
 137  	function get_columns() {
 138          return array(
 139              'name'        => _x( 'Name', 'plugin name' ),
 140              'version'     => __( 'Version' ),
 141              'rating'      => __( 'Rating' ),
 142              'description' => __( 'Description' ),
 143          );
 144      }
 145  
 146  	function display_rows() {
 147          $plugins_allowedtags = array(
 148              'a' => array( 'href' => array(),'title' => array(), 'target' => array() ),
 149              'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ),
 150              'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
 151              'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
 152          );
 153  
 154          list( $columns, $hidden ) = $this->get_column_info();
 155  
 156          $style = array();
 157          foreach ( $columns as $column_name => $column_display_name ) {
 158              $style[ $column_name ] = in_array( $column_name, $hidden ) ? 'style="display:none;"' : '';
 159          }
 160  
 161          foreach ( (array) $this->items as $plugin ) {
 162              if ( is_object( $plugin ) )
 163                  $plugin = (array) $plugin;
 164  
 165              $title = wp_kses( $plugin['name'], $plugins_allowedtags );
 166              //Limit description to 400char, and remove any HTML.
 167              $description = strip_tags( $plugin['description'] );
 168              if ( strlen( $description ) > 400 )
 169                  $description = mb_substr( $description, 0, 400 ) . '&#8230;';
 170              //remove any trailing entities
 171              $description = preg_replace( '/&[^;\s]{0,6}$/', '', $description );
 172              //strip leading/trailing & multiple consecutive lines
 173              $description = trim( $description );
 174              $description = preg_replace( "|(\r?\n)+|", "\n", $description );
 175              //\n => <br>
 176              $description = nl2br( $description );
 177              $version = wp_kses( $plugin['version'], $plugins_allowedtags );
 178  
 179              $name = strip_tags( $title . ' ' . $version );
 180  
 181              $author = $plugin['author'];
 182              if ( ! empty( $plugin['author'] ) )
 183                  $author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '.</cite>';
 184  
 185              $author = wp_kses( $author, $plugins_allowedtags );
 186  
 187              $action_links = array();
 188              $action_links[] = '<a href="' . self_admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
 189                                  '&amp;TB_iframe=true&amp;width=600&amp;height=550' ) . '" class="thickbox" title="' .
 190                                  esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
 191  
 192              if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
 193                  $status = install_plugin_install_status( $plugin );
 194  
 195                  switch ( $status['status'] ) {
 196                      case 'install':
 197                          if ( $status['url'] )
 198                              $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
 199                          break;
 200                      case 'update_available':
 201                          if ( $status['url'] )
 202                              $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $status['version'] ) ) . '">' . sprintf( __( 'Update Now' ), $status['version'] ) . '</a>';
 203                          break;
 204                      case 'latest_installed':
 205                      case 'newer_installed':
 206                          $action_links[] = '<span title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . _x( 'Installed', 'plugin' ) . '</span>';
 207                          break;
 208                  }
 209              }
 210  
 211              $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
 212          ?>
 213          <tr>
 214              <td class="name column-name"<?php echo $style['name']; ?>><strong><?php echo $title; ?></strong>
 215                  <div class="action-links"><?php if ( !empty( $action_links ) ) echo implode( ' | ', $action_links ); ?></div>
 216              </td>
 217              <td class="vers column-version"<?php echo $style['version']; ?>><?php echo $version; ?></td>
 218              <td class="vers column-rating"<?php echo $style['rating']; ?>>
 219                  <div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin['num_ratings'] ), number_format_i18n( $plugin['num_ratings'] ) ) ?>">
 220                      <div class="star star-rating" style="width: <?php echo esc_attr( str_replace( ',', '.', $plugin['rating'] ) ); ?>px"></div>
 221                  </div>
 222              </td>
 223              <td class="desc column-description"<?php echo $style['description']; ?>><?php echo $description, $author; ?></td>
 224          </tr>
 225          <?php
 226          }
 227      }
 228  }


Generated: Fri May 25 03:56:23 2012 Hosted by follow the white rabbit.