PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/class-wp-theme-install-list-table.php

https://github.com/davidmh/WordPress
PHP | 176 lines | 122 code | 33 blank | 21 comment | 14 complexity | 890f86ae11fd86bcb1a0113dde13b0f9 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1
  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. var $features = array();
  12. function ajax_user_can() {
  13. return current_user_can( 'install_themes' );
  14. }
  15. function prepare_items() {
  16. include( ABSPATH . 'wp-admin/includes/theme-install.php' );
  17. global $tabs, $tab, $paged, $type, $theme_field_defaults;
  18. wp_reset_vars( array( 'tab' ) );
  19. $search_terms = array();
  20. $search_string = '';
  21. if ( ! empty( $_REQUEST['s'] ) ){
  22. $search_string = strtolower( stripslashes( $_REQUEST['s'] ) );
  23. $search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) );
  24. }
  25. if ( ! empty( $_REQUEST['features'] ) )
  26. $this->features = $_REQUEST['features'];
  27. $paged = $this->get_pagenum();
  28. $per_page = 36;
  29. // These are the tabs which are shown on the page,
  30. $tabs = array();
  31. $tabs['dashboard'] = __( 'Search' );
  32. if ( 'search' == $tab )
  33. $tabs['search'] = __( 'Search Results' );
  34. $tabs['upload'] = __( 'Upload' );
  35. $tabs['featured'] = _x( 'Featured','Theme Installer' );
  36. //$tabs['popular'] = _x( 'Popular','Theme Installer' );
  37. $tabs['new'] = _x( 'Newest','Theme Installer' );
  38. $tabs['updated'] = _x( 'Recently Updated','Theme Installer' );
  39. $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
  40. $tabs = apply_filters( 'install_themes_tabs', $tabs );
  41. $nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
  42. // If a non-valid menu tab has been selected, And its not a non-menu action.
  43. if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) )
  44. $tab = key( $tabs );
  45. $args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults );
  46. switch ( $tab ) {
  47. case 'search':
  48. $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : '';
  49. switch ( $type ) {
  50. case 'tag':
  51. $args['tag'] = array_map( 'sanitize_key', $search_terms );
  52. break;
  53. case 'term':
  54. $args['search'] = $search_string;
  55. break;
  56. case 'author':
  57. $args['author'] = $search_string;
  58. break;
  59. }
  60. if ( ! empty( $this->features ) ) {
  61. $args['tag'] = $this->features;
  62. $_REQUEST['s'] = implode( ',', $this->features );
  63. $_REQUEST['type'] = 'tag';
  64. }
  65. add_action( 'install_themes_table_header', 'install_theme_search_form' );
  66. break;
  67. case 'featured':
  68. //case 'popular':
  69. case 'new':
  70. case 'updated':
  71. $args['browse'] = $tab;
  72. break;
  73. default:
  74. $args = false;
  75. }
  76. if ( ! $args )
  77. return;
  78. $api = themes_api( 'query_themes', $args );
  79. if ( is_wp_error( $api ) )
  80. wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
  81. $this->items = $api->themes;
  82. $this->set_pagination_args( array(
  83. 'total_items' => $api->info['results'],
  84. 'per_page' => $per_page,
  85. 'infinite_scroll' => true,
  86. ) );
  87. }
  88. function no_items() {
  89. _e( 'No themes match your request.' );
  90. }
  91. function get_views() {
  92. global $tabs, $tab;
  93. $display_tabs = array();
  94. foreach ( (array) $tabs as $action => $text ) {
  95. $class = ( $action == $tab ) ? ' class="current"' : '';
  96. $href = self_admin_url('theme-install.php?tab=' . $action);
  97. $display_tabs['theme-install-'.$action] = "<a href='$href'$class>$text</a>";
  98. }
  99. return $display_tabs;
  100. }
  101. function display() {
  102. wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
  103. ?>
  104. <div class="tablenav top themes">
  105. <div class="alignleft actions">
  106. <?php do_action( 'install_themes_table_header' ); ?>
  107. </div>
  108. <?php $this->pagination( 'top' ); ?>
  109. <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" />
  110. <br class="clear" />
  111. </div>
  112. <div id="availablethemes">
  113. <?php $this->display_rows_or_placeholder(); ?>
  114. </div>
  115. <?php
  116. parent::tablenav( 'bottom' );
  117. }
  118. function display_rows() {
  119. $themes = $this->items;
  120. $theme_names = array_keys( $themes );
  121. foreach ( $theme_names as $theme_name ) {
  122. $class = array( 'available-theme' );
  123. ?>
  124. <div class="<?php echo join( ' ', $class ); ?>"><?php
  125. if ( isset( $themes[$theme_name] ) )
  126. display_theme( $themes[$theme_name] );
  127. ?></div>
  128. <?php } // end foreach $theme_names
  129. }
  130. /**
  131. * Send required variables to JavaScript land
  132. *
  133. * @since 3.4
  134. * @access private
  135. *
  136. * @uses $tab Global; current tab within Themes->Install screen
  137. * @uses $type Global; type of search.
  138. */
  139. function _js_vars() {
  140. global $tab, $type;
  141. parent::_js_vars( compact( 'tab', 'type' ) );
  142. }
  143. }