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