]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-theme-install-list-table.php
Wordpress 3.3.1
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-theme-install-list-table.php
1 <?php
2 /**
3  * Theme Installer List Table class.
4  *
5  * @package WordPress
6  * @subpackage List_Table
7  * @since 3.1.0
8  * @access private
9  */
10 class WP_Theme_Install_List_Table extends WP_List_Table {
11
12         function ajax_user_can() {
13                 return current_user_can('install_themes');
14         }
15
16         function prepare_items() {
17                 include( ABSPATH . 'wp-admin/includes/theme-install.php' );
18
19                 global $tabs, $tab, $paged, $type, $term, $theme_field_defaults;
20
21                 wp_reset_vars( array( 'tab' ) );
22
23                 $paged = $this->get_pagenum();
24
25                 $per_page = 36;
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','Theme Installer' );
34                 //$tabs['popular']  = _x( 'Popular','Theme Installer' );
35                 $tabs['new']      = _x( 'Newest','Theme Installer' );
36                 $tabs['updated']  = _x( 'Recently Updated','Theme Installer' );
37
38                 $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
39
40                 $tabs = apply_filters( 'install_themes_tabs', $tabs );
41                 $nonmenu_tabs = apply_filters( 'install_themes_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, 'fields' => $theme_field_defaults );
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                                                 $terms = explode( ',', $term );
57                                                 $terms = array_map( 'trim', $terms );
58                                                 $terms = array_map( 'sanitize_title_with_dashes', $terms );
59                                                 $args['tag'] = $terms;
60                                                 break;
61                                         case 'term':
62                                                 $args['search'] = $term;
63                                                 break;
64                                         case 'author':
65                                                 $args['author'] = $term;
66                                                 break;
67                                 }
68
69                                 if ( !empty( $_POST['features'] ) ) {
70                                         $terms = $_POST['features'];
71                                         $terms = array_map( 'trim', $terms );
72                                         $terms = array_map( 'sanitize_title_with_dashes', $terms );
73                                         $args['tag'] = $terms;
74                                         $_REQUEST['s'] = implode( ',', $terms );
75                                         $_REQUEST['type'] = 'tag';
76                                 }
77
78                                 add_action( 'install_themes_table_header', 'install_theme_search_form' );
79                                 break;
80
81                         case 'featured':
82                         //case 'popular':
83                         case 'new':
84                         case 'updated':
85                                 $args['browse'] = $tab;
86                                 break;
87
88                         default:
89                                 $args = false;
90                 }
91
92                 if ( !$args )
93                         return;
94
95                 $api = themes_api( 'query_themes', $args );
96
97                 if ( is_wp_error( $api ) )
98                         wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
99
100                 $this->items = $api->themes;
101
102                 $this->set_pagination_args( array(
103                         'total_items' => $api->info['results'],
104                         'per_page' => $per_page,
105                 ) );
106         }
107
108         function no_items() {
109                 _e( 'No themes match your request.' );
110         }
111
112         function get_views() {
113                 global $tabs, $tab;
114
115                 $display_tabs = array();
116                 foreach ( (array) $tabs as $action => $text ) {
117                         $class = ( $action == $tab ) ? ' class="current"' : '';
118                         $href = self_admin_url('theme-install.php?tab=' . $action);
119                         $display_tabs['theme-install-'.$action] = "<a href='$href'$class>$text</a>";
120                 }
121
122                 return $display_tabs;
123         }
124
125         function get_columns() {
126                 return array();
127         }
128
129         function display() {
130
131                 // wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
132 ?>
133                 <div class="tablenav top themes">
134                         <div class="alignleft actions">
135                                 <?php do_action( 'install_themes_table_header' ); ?>
136                         </div>
137                         <?php $this->pagination( 'top' ); ?>
138                         <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
139                         <br class="clear" />
140                 </div>
141
142                 <div id="availablethemes">
143                         <?php $this->display_rows_or_placeholder(); ?>
144                 </div>
145
146                 <div class="tablenav bottom themes">
147                         <?php $this->pagination( 'bottom' ); ?>
148                         <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
149                         <br class="clear" />
150                 </div>
151 <?php
152         }
153
154         function display_rows() {
155                 $themes = $this->items;
156                 $theme_names = array_keys( $themes );
157
158                 foreach ( $theme_names as $theme_name ) {
159                                 $class = array( 'available-theme' );
160                                 ?>
161                                 <div class="<?php echo join( ' ', $class ); ?>"><?php
162                                         if ( isset( $themes[$theme_name] ) )
163                                                 display_theme( $themes[$theme_name] );
164                                 ?></div>
165                 <?php } // end foreach $theme_names
166         }
167 }
168
169 ?>