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