3 * Plugin Installer List Table class.
6 * @subpackage List_Table
10 class WP_Plugin_Install_List_Table extends WP_List_Table {
12 function ajax_user_can() {
13 return current_user_can('install_plugins');
16 function prepare_items() {
17 include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
19 global $tabs, $tab, $paged, $type, $term;
21 wp_reset_vars( array( 'tab' ) );
23 $paged = $this->get_pagenum();
27 // These are the tabs which are shown on the page
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' );
37 $nonmenu_tabs = array( 'plugin-information' ); //Valid actions to perform which do not have a Menu item.
39 $tabs = apply_filters( 'install_plugins_tabs', $tabs );
40 $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
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 ) ) )
46 $args = array( 'page' => $paged, 'per_page' => $per_page );
50 $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : 'term';
51 $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
55 $args['tag'] = sanitize_title_with_dashes( $term );
58 $args['search'] = $term;
61 $args['author'] = $term;
65 add_action( 'install_plugins_table_header', 'install_search_form', 10, 0 );
71 $args['browse'] = $tab;
81 $api = plugins_api( 'query_plugins', $args );
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>' );
86 $this->items = $api->plugins;
88 $this->set_pagination_args( array(
89 'total_items' => $api->info['results'],
90 'per_page' => $per_page,
95 _e( 'No plugins match your request.' );
98 function get_views() {
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>";
108 return $display_tabs;
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' ); ?>
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="" />
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="" />
131 function get_table_classes() {
132 extract( $this->_args );
134 return array( 'widefat', $plural );
137 function get_columns() {
139 'name' => _x( 'Name', 'plugin name' ),
140 'version' => __( 'Version' ),
141 'rating' => __( 'Rating' ),
142 'description' => __( 'Description' ),
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()
154 list( $columns, $hidden ) = $this->get_column_info();
157 foreach ( $columns as $column_name => $column_display_name ) {
158 $style[ $column_name ] = in_array( $column_name, $hidden ) ? 'style="display:none;"' : '';
161 foreach ( (array) $this->items as $plugin ) {
162 if ( is_object( $plugin ) )
163 $plugin = (array) $plugin;
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 ) . '…';
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 );
176 $description = nl2br( $description );
177 $version = wp_kses( $plugin['version'], $plugins_allowedtags );
179 $name = strip_tags( $title . ' ' . $version );
181 $author = $plugin['author'];
182 if ( ! empty( $plugin['author'] ) )
183 $author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '.</cite>';
185 $author = wp_kses( $author, $plugins_allowedtags );
187 $action_links = array();
188 $action_links[] = '<a href="' . self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin['slug'] .
189 '&TB_iframe=true&width=600&height=550' ) . '" class="thickbox" title="' .
190 esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '">' . __( 'Details' ) . '</a>';
192 if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
193 $status = install_plugin_install_status( $plugin );
195 switch ( $status['status'] ) {
197 if ( $status['url'] )
198 $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
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>';
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>';
211 $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
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>
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>
223 <td class="desc column-description"<?php echo $style['description']; ?>><?php echo $description, $author; ?></td>