2010-10-24 22:57:43 -04:00
|
|
|
<?php
|
|
|
|
/**
|
2010-10-25 00:04:18 -04:00
|
|
|
* Theme Installer List Table class.
|
2010-10-24 22:57:43 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
2010-10-25 00:04:18 -04:00
|
|
|
* @subpackage List_Table
|
|
|
|
* @since 3.1.0
|
2011-01-16 16:47:24 -05:00
|
|
|
* @access private
|
2010-10-24 22:57:43 -04:00
|
|
|
*/
|
2012-03-02 17:09:26 -05:00
|
|
|
class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
|
2010-10-24 22:57:43 -04:00
|
|
|
|
2012-03-02 17:09:26 -05:00
|
|
|
var $features = array();
|
2012-02-09 12:20:26 -05:00
|
|
|
|
2010-12-16 04:18:28 -05:00
|
|
|
function ajax_user_can() {
|
2012-03-02 17:09:26 -05:00
|
|
|
return current_user_can( 'install_themes' );
|
2010-10-24 22:57:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function prepare_items() {
|
|
|
|
include( ABSPATH . 'wp-admin/includes/theme-install.php' );
|
|
|
|
|
2012-03-02 17:09:26 -05:00
|
|
|
global $tabs, $tab, $paged, $type, $theme_field_defaults;
|
2010-10-24 22:57:43 -04:00
|
|
|
wp_reset_vars( array( 'tab' ) );
|
|
|
|
|
2012-03-02 17:09:26 -05:00
|
|
|
$search_terms = array();
|
|
|
|
$search_string = '';
|
|
|
|
if ( ! empty( $_REQUEST['s'] ) ){
|
|
|
|
$search_string = strtolower( stripslashes( $_REQUEST['s'] ) );
|
|
|
|
$search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! empty( $_REQUEST['features'] ) )
|
|
|
|
$this->features = $_REQUEST['features'];
|
|
|
|
|
2010-10-24 22:57:43 -04:00
|
|
|
$paged = $this->get_pagenum();
|
|
|
|
|
2011-09-15 00:26:26 -04:00
|
|
|
$per_page = 36;
|
2010-10-24 22:57:43 -04:00
|
|
|
|
|
|
|
// These are the tabs which are shown on the page,
|
|
|
|
$tabs = array();
|
|
|
|
$tabs['dashboard'] = __( 'Search' );
|
|
|
|
if ( 'search' == $tab )
|
|
|
|
$tabs['search'] = __( 'Search Results' );
|
|
|
|
$tabs['upload'] = __( 'Upload' );
|
|
|
|
$tabs['featured'] = _x( 'Featured','Theme Installer' );
|
|
|
|
//$tabs['popular'] = _x( 'Popular','Theme Installer' );
|
|
|
|
$tabs['new'] = _x( 'Newest','Theme Installer' );
|
|
|
|
$tabs['updated'] = _x( 'Recently Updated','Theme Installer' );
|
|
|
|
|
|
|
|
$nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
|
|
|
|
|
|
|
|
$tabs = apply_filters( 'install_themes_tabs', $tabs );
|
|
|
|
$nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
|
|
|
|
|
|
|
|
// If a non-valid menu tab has been selected, And its not a non-menu action.
|
|
|
|
if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) )
|
|
|
|
$tab = key( $tabs );
|
|
|
|
|
|
|
|
$args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults );
|
|
|
|
|
|
|
|
switch ( $tab ) {
|
|
|
|
case 'search':
|
|
|
|
$type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
|
|
|
|
switch ( $type ) {
|
|
|
|
case 'tag':
|
2012-03-02 17:09:26 -05:00
|
|
|
$args['tag'] = array_map( 'sanitize_title_with_dashes', $search_terms );
|
2010-10-24 22:57:43 -04:00
|
|
|
break;
|
|
|
|
case 'term':
|
2012-03-02 17:09:26 -05:00
|
|
|
$args['search'] = $search_string;
|
2010-10-24 22:57:43 -04:00
|
|
|
break;
|
|
|
|
case 'author':
|
2012-03-02 17:09:26 -05:00
|
|
|
$args['author'] = $search_string;
|
2010-10-24 22:57:43 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-02 17:09:26 -05:00
|
|
|
if ( ! empty( $this->features ) ) {
|
|
|
|
$args['tag'] = $this->features;
|
|
|
|
$_REQUEST['s'] = implode( ',', $this->features );
|
2010-10-24 22:57:43 -04:00
|
|
|
$_REQUEST['type'] = 'tag';
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'install_themes_table_header', 'install_theme_search_form' );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'featured':
|
|
|
|
//case 'popular':
|
|
|
|
case 'new':
|
|
|
|
case 'updated':
|
|
|
|
$args['browse'] = $tab;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$args = false;
|
|
|
|
}
|
|
|
|
|
2012-03-02 17:09:26 -05:00
|
|
|
if ( ! $args )
|
2010-10-24 22:57:43 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
$api = themes_api( 'query_themes', $args );
|
|
|
|
|
|
|
|
if ( is_wp_error( $api ) )
|
2011-01-11 19:18:23 -05:00
|
|
|
wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
|
2010-10-24 22:57:43 -04:00
|
|
|
|
|
|
|
$this->items = $api->themes;
|
|
|
|
|
|
|
|
$this->set_pagination_args( array(
|
|
|
|
'total_items' => $api->info['results'],
|
|
|
|
'per_page' => $per_page,
|
2012-03-02 17:09:26 -05:00
|
|
|
'infinite_scroll' => true,
|
2010-10-24 22:57:43 -04:00
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
function no_items() {
|
|
|
|
_e( 'No themes match your request.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_views() {
|
|
|
|
global $tabs, $tab;
|
|
|
|
|
|
|
|
$display_tabs = array();
|
|
|
|
foreach ( (array) $tabs as $action => $text ) {
|
|
|
|
$class = ( $action == $tab ) ? ' class="current"' : '';
|
|
|
|
$href = self_admin_url('theme-install.php?tab=' . $action);
|
2010-12-03 13:51:24 -05:00
|
|
|
$display_tabs['theme-install-'.$action] = "<a href='$href'$class>$text</a>";
|
2010-10-24 22:57:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return $display_tabs;
|
|
|
|
}
|
|
|
|
|
2010-12-16 14:05:14 -05:00
|
|
|
function display() {
|
2012-02-09 12:20:26 -05:00
|
|
|
wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
|
2010-10-24 22:57:43 -04:00
|
|
|
?>
|
2011-09-15 00:26:26 -04:00
|
|
|
<div class="tablenav top themes">
|
2010-10-24 22:57:43 -04:00
|
|
|
<div class="alignleft actions">
|
|
|
|
<?php do_action( 'install_themes_table_header' ); ?>
|
|
|
|
</div>
|
|
|
|
<?php $this->pagination( 'top' ); ?>
|
2010-12-20 13:45:05 -05:00
|
|
|
<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
|
2010-10-24 22:57:43 -04:00
|
|
|
<br class="clear" />
|
|
|
|
</div>
|
|
|
|
|
2011-09-15 00:26:26 -04:00
|
|
|
<div id="availablethemes">
|
|
|
|
<?php $this->display_rows_or_placeholder(); ?>
|
|
|
|
</div>
|
2010-10-24 22:57:43 -04:00
|
|
|
|
2012-03-02 17:09:26 -05:00
|
|
|
<?php
|
|
|
|
parent::tablenav( 'bottom' );
|
2010-10-24 22:57:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function display_rows() {
|
|
|
|
$themes = $this->items;
|
2011-09-15 00:26:26 -04:00
|
|
|
$theme_names = array_keys( $themes );
|
2010-10-24 22:57:43 -04:00
|
|
|
|
2011-09-15 00:26:26 -04:00
|
|
|
foreach ( $theme_names as $theme_name ) {
|
2010-10-24 22:57:43 -04:00
|
|
|
$class = array( 'available-theme' );
|
|
|
|
?>
|
2011-09-15 00:26:26 -04:00
|
|
|
<div class="<?php echo join( ' ', $class ); ?>"><?php
|
|
|
|
if ( isset( $themes[$theme_name] ) )
|
|
|
|
display_theme( $themes[$theme_name] );
|
|
|
|
?></div>
|
|
|
|
<?php } // end foreach $theme_names
|
2010-10-24 22:57:43 -04:00
|
|
|
}
|
2012-03-02 17:09:26 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send required variables to JavaScript land
|
|
|
|
*
|
|
|
|
* @since 3.4
|
|
|
|
* @access private
|
|
|
|
*
|
|
|
|
* @uses $tab Global; current tab within Themes->Install screen
|
|
|
|
* @uses $type Global; type of search.
|
|
|
|
*/
|
|
|
|
function _js_vars() {
|
|
|
|
global $tab, $type;
|
|
|
|
parent::_js_vars( compact( $tab, $type ) );
|
|
|
|
}
|
2010-10-24 22:57:43 -04:00
|
|
|
}
|