| [ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
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_Themes_List_Table { 11 12 var $features = array(); 13 14 function ajax_user_can() { 15 return current_user_can( 'install_themes' ); 16 } 17 18 function prepare_items() { 19 include ( ABSPATH . 'wp-admin/includes/theme-install.php' ); 20 21 global $tabs, $tab, $paged, $type, $theme_field_defaults; 22 wp_reset_vars( array( 'tab' ) ); 23 24 $search_terms = array(); 25 $search_string = ''; 26 if ( ! empty( $_REQUEST['s'] ) ){ 27 $search_string = strtolower( stripslashes( $_REQUEST['s'] ) ); 28 $search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) ); 29 } 30 31 if ( ! empty( $_REQUEST['features'] ) ) 32 $this->features = $_REQUEST['features']; 33 34 $paged = $this->get_pagenum(); 35 36 $per_page = 36; 37 38 // These are the tabs which are shown on the page, 39 $tabs = array(); 40 $tabs['dashboard'] = __( 'Search' ); 41 if ( 'search' == $tab ) 42 $tabs['search'] = __( 'Search Results' ); 43 $tabs['upload'] = __( 'Upload' ); 44 $tabs['featured'] = _x( 'Featured','Theme Installer' ); 45 //$tabs['popular'] = _x( 'Popular','Theme Installer' ); 46 $tabs['new'] = _x( 'Newest','Theme Installer' ); 47 $tabs['updated'] = _x( 'Recently Updated','Theme Installer' ); 48 49 $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item. 50 51 $tabs = apply_filters( 'install_themes_tabs', $tabs ); 52 $nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs ); 53 54 // If a non-valid menu tab has been selected, And its not a non-menu action. 55 if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) 56 $tab = key( $tabs ); 57 58 $args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults ); 59 60 switch ( $tab ) { 61 case 'search': 62 $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : 'term'; 63 switch ( $type ) { 64 case 'tag': 65 $args['tag'] = array_map( 'sanitize_key', $search_terms ); 66 break; 67 case 'term': 68 $args['search'] = $search_string; 69 break; 70 case 'author': 71 $args['author'] = $search_string; 72 break; 73 } 74 75 if ( ! empty( $this->features ) ) { 76 $args['tag'] = $this->features; 77 $_REQUEST['s'] = implode( ',', $this->features ); 78 $_REQUEST['type'] = 'tag'; 79 } 80 81 add_action( 'install_themes_table_header', 'install_theme_search_form', 10, 0 ); 82 break; 83 84 case 'featured': 85 //case 'popular': 86 case 'new': 87 case 'updated': 88 $args['browse'] = $tab; 89 break; 90 91 default: 92 $args = false; 93 } 94 95 if ( ! $args ) 96 return; 97 98 $api = themes_api( 'query_themes', $args ); 99 100 if ( is_wp_error( $api ) ) 101 wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' ); 102 103 $this->items = $api->themes; 104 105 $this->set_pagination_args( array( 106 'total_items' => $api->info['results'], 107 'per_page' => $per_page, 108 'infinite_scroll' => true, 109 ) ); 110 } 111 112 function no_items() { 113 _e( 'No themes match your request.' ); 114 } 115 116 function get_views() { 117 global $tabs, $tab; 118 119 $display_tabs = array(); 120 foreach ( (array) $tabs as $action => $text ) { 121 $class = ( $action == $tab ) ? ' class="current"' : ''; 122 $href = self_admin_url('theme-install.php?tab=' . $action); 123 $display_tabs['theme-install-'.$action] = "<a href='$href'$class>$text</a>"; 124 } 125 126 return $display_tabs; 127 } 128 129 function display() { 130 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); 131 ?> 132 <div class="tablenav top themes"> 133 <div class="alignleft actions"> 134 <?php do_action( 'install_themes_table_header' ); ?> 135 </div> 136 <?php $this->pagination( 'top' ); ?> 137 <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" /> 138 <br class="clear" /> 139 </div> 140 141 <div id="availablethemes"> 142 <?php $this->display_rows_or_placeholder(); ?> 143 </div> 144 145 <?php 146 parent::tablenav( 'bottom' ); 147 } 148 149 function display_rows() { 150 $themes = $this->items; 151 foreach ( $themes as $theme ) { 152 ?> 153 <div class="available-theme installable-theme"><?php 154 $this->single_row( $theme ); 155 ?></div> 156 <?php } // end foreach $theme_names 157 158 $this->theme_installer(); 159 } 160 161 /* 162 * Prints a theme from the WordPress.org API. 163 * 164 * @param object $theme An object that contains theme data returned by the WordPress.org API. 165 * 166 * Example theme data: 167 * object(stdClass)[59] 168 * public 'name' => string 'Magazine Basic' (length=14) 169 * public 'slug' => string 'magazine-basic' (length=14) 170 * public 'version' => string '1.1' (length=3) 171 * public 'author' => string 'tinkerpriest' (length=12) 172 * public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' (length=36) 173 * public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' (length=68) 174 * public 'rating' => float 80 175 * public 'num_ratings' => int 1 176 * public 'homepage' => string 'http://wordpress.org/extend/themes/magazine-basic' (length=49) 177 * public 'description' => string 'A basic magazine style layout with a fully customizable layout through a backend interface. Designed by <a href="http://bavotasan.com">c.bavota</a> of <a href="http://tinkerpriestmedia.com">Tinker Priest Media</a>.' (length=214) 178 * public 'download_link' => string 'http://wordpress.org/extend/themes/download/magazine-basic.1.1.zip' (length=66) 179 */ 180 function single_row( $theme ) { 181 global $themes_allowedtags; 182 183 if ( empty( $theme ) ) 184 return; 185 186 $name = wp_kses( $theme->name, $themes_allowedtags ); 187 $author = wp_kses( $theme->author, $themes_allowedtags ); 188 189 $preview_title = sprintf( __('Preview “%s”'), $name ); 190 $preview_url = add_query_arg( array( 191 'tab' => 'theme-information', 192 'theme' => $theme->slug, 193 ) ); 194 195 $actions = array(); 196 197 $install_url = add_query_arg( array( 198 'action' => 'install-theme', 199 'theme' => $theme->slug, 200 ), self_admin_url( 'update.php' ) ); 201 202 $update_url = add_query_arg( array( 203 'action' => 'upgrade-theme', 204 'theme' => $theme->slug, 205 ), self_admin_url( 'update.php' ) ); 206 207 $status = $this->_get_theme_status( $theme ); 208 209 switch ( $status ) { 210 default: 211 case 'install': 212 $actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>'; 213 break; 214 case 'update_available': 215 $actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>'; 216 break; 217 case 'newer_installed': 218 case 'latest_installed': 219 $actions[] = '<span class="install-now" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>'; 220 break; 221 } 222 223 $actions[] = '<a class="install-theme-preview" href="' . esc_url( $preview_url ) . '" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>'; 224 225 $actions = apply_filters( 'theme_install_actions', $actions, $theme ); 226 227 ?> 228 <a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>"> 229 <img src='<?php echo esc_url( $theme->screenshot_url ); ?>' width='150' /> 230 </a> 231 232 <h3><?php echo $name; ?></h3> 233 <div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div> 234 235 <div class="action-links"> 236 <ul> 237 <?php foreach ( $actions as $action ): ?> 238 <li><?php echo $action; ?></li> 239 <?php endforeach; ?> 240 <li class="hide-if-no-js"><a href="#" class="theme-detail" tabindex='4'><?php _e('Details') ?></a></li> 241 </ul> 242 </div> 243 244 <?php 245 $this->install_theme_info( $theme ); 246 } 247 248 /* 249 * Prints the wrapper for the theme installer. 250 */ 251 function theme_installer() { 252 ?> 253 <div id="theme-installer" class="wp-full-overlay"> 254 <a href="#" class="close-full-overlay"><?php printf( __( '← Return to %s' ), get_admin_page_title() ); ?></a> 255 <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>"> 256 <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span> 257 <span class="collapse-sidebar-arrow"></span> 258 </a> 259 <div class="wp-full-overlay-sidebar"> 260 <div class="wp-full-overlay-header"></div> 261 <div class="wp-full-overlay-sidebar-content"> 262 <div class="install-theme-info"></div> 263 </div> 264 <div class="wp-full-overlay-footer"></div> 265 </div> 266 <div class="wp-full-overlay-main"></div> 267 </div> 268 <?php 269 } 270 271 /* 272 * Prints the wrapper for the theme installer with a provided theme's data. 273 * Used to make the theme installer work for no-js. 274 * 275 * @param object $theme - A WordPress.org Theme API object. 276 */ 277 function theme_installer_single( $theme ) { 278 ?> 279 <div id="theme-installer" class="wp-full-overlay single-theme"> 280 <div class="wp-full-overlay-sidebar"> 281 <?php $this->install_theme_info( $theme ); ?> 282 </div> 283 <div class="wp-full-overlay-main"> 284 <iframe src="<?php echo esc_url( $theme->preview_url ); ?>"></iframe> 285 </div> 286 </div> 287 <?php 288 } 289 290 /* 291 * Prints the info for a theme (to be used in the theme installer modal). 292 * 293 * @param object $theme - A WordPress.org Theme API object. 294 */ 295 function install_theme_info( $theme ) { 296 global $themes_allowedtags; 297 298 if ( empty( $theme ) ) 299 return; 300 301 $name = wp_kses( $theme->name, $themes_allowedtags ); 302 $author = wp_kses( $theme->author, $themes_allowedtags ); 303 304 $num_ratings = sprintf( _n( '(based on %s rating)', '(based on %s ratings)', $theme->num_ratings ), number_format_i18n( $theme->num_ratings ) ); 305 306 $install_url = add_query_arg( array( 307 'action' => 'install-theme', 308 'theme' => $theme->slug, 309 ), self_admin_url( 'update.php' ) ); 310 311 $update_url = add_query_arg( array( 312 'action' => 'upgrade-theme', 313 'theme' => $theme->slug, 314 ), self_admin_url( 'update.php' ) ); 315 316 $status = $this->_get_theme_status( $theme ); 317 318 ?> 319 <div class="install-theme-info"><?php 320 switch ( $status ) { 321 default: 322 case 'install': 323 echo '<a class="theme-install button-primary" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '">' . __( 'Install' ) . '</a>'; 324 break; 325 case 'update_available': 326 echo '<a class="theme-install button-primary" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>'; 327 break; 328 case 'newer_installed': 329 case 'latest_installed': 330 echo '<span class="theme-install" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>'; 331 break; 332 } ?> 333 <h3 class="theme-name"><?php echo $name; ?></h3> 334 <span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span> 335 <?php if ( isset( $theme->screenshot_url ) ): ?> 336 <img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" /> 337 <?php endif; ?> 338 <div class="theme-details"> 339 <div class="star-holder" title="<?php echo esc_attr( $num_ratings ); ?>"> 340 <div class="star-rating" style="width:<?php echo esc_attr( intval( $theme->rating ) . 'px' ); ?>;"></div> 341 </div> 342 <div class="theme-version"> 343 <strong><?php _e('Version:') ?> </strong> 344 <?php echo wp_kses( $theme->version, $themes_allowedtags ); ?> 345 </div> 346 <div class="theme-description"> 347 <?php echo wp_kses( $theme->description, $themes_allowedtags ); ?> 348 </div> 349 </div> 350 <input class="theme-preview-url" type="hidden" value="<?php echo esc_url( $theme->preview_url ); ?>" /> 351 </div> 352 <?php 353 } 354 355 /** 356 * Send required variables to JavaScript land 357 * 358 * @since 3.4 359 * @access private 360 * 361 * @uses $tab Global; current tab within Themes->Install screen 362 * @uses $type Global; type of search. 363 */ 364 function _js_vars() { 365 global $tab, $type; 366 parent::_js_vars( compact( 'tab', 'type' ) ); 367 } 368 369 /** 370 * Check to see if the theme is already installed. 371 * 372 * @since 3.4 373 * @access private 374 * 375 * @param object $theme - A WordPress.org Theme API object. 376 * @return string Theme status. 377 */ 378 private function _get_theme_status( $theme ) { 379 $status = 'install'; 380 381 $installed_theme = wp_get_theme( $theme->slug ); 382 if ( $installed_theme->exists() ) { 383 if ( version_compare( $installed_theme->get('Version'), $theme->version, '=' ) ) 384 $status = 'latest_installed'; 385 elseif ( version_compare( $installed_theme->get('Version'), $theme->version, '>' ) ) 386 $status = 'newer_installed'; 387 else 388 $status = 'update_available'; 389 } 390 391 return $status; 392 } 393 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri May 25 03:56:23 2012 | Hosted by follow the white rabbit. |