Changeset 20094
- Timestamp:
- 03/02/2012 10:09:26 PM (13 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-list-table.php
r19819 r20094 485 485 return; 486 486 487 extract( $this->_pagination_args );487 extract( $this->_pagination_args, EXTR_SKIP ); 488 488 489 489 $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>'; … … 544 544 ); 545 545 546 $output .= "\n<span class='pagination-links'>" . join( "\n", $page_links ) . '</span>'; 546 $pagination_links_class = 'pagination-links'; 547 if ( ! empty( $infinite_scroll ) ) 548 $pagination_links_class = ' hide-if-js'; 549 $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>'; 547 550 548 551 if ( $total_pages ) … … 873 876 874 877 extract( $this->_args ); 875 extract( $this->_pagination_args );878 extract( $this->_pagination_args, EXTR_SKIP ); 876 879 877 880 ob_start(); -
trunk/wp-admin/includes/class-wp-theme-install-list-table.php
r19887 r20094 8 8 * @access private 9 9 */ 10 class WP_Theme_Install_List_Table extends WP_ List_Table {10 class WP_Theme_Install_List_Table extends WP_Themes_List_Table { 11 11 12 function __construct() { 13 parent::__construct( array( 14 'ajax' => true, 15 ) ); 16 } 12 var $features = array(); 17 13 18 14 function ajax_user_can() { 19 return current_user_can( 'install_themes');15 return current_user_can( 'install_themes' ); 20 16 } 21 17 … … 23 19 include( ABSPATH . 'wp-admin/includes/theme-install.php' ); 24 20 25 global $tabs, $tab, $paged, $type, $term, $theme_field_defaults; 21 global $tabs, $tab, $paged, $type, $theme_field_defaults; 22 wp_reset_vars( array( 'tab' ) ); 26 23 27 wp_reset_vars( array( 'tab' ) ); 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']; 28 33 29 34 $paged = $this->get_pagenum(); … … 56 61 case 'search': 57 62 $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : ''; 58 $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';59 60 63 switch ( $type ) { 61 64 case 'tag': 62 $terms = explode( ',', $term ); 63 $terms = array_map( 'trim', $terms ); 64 $terms = array_map( 'sanitize_title_with_dashes', $terms ); 65 $args['tag'] = $terms; 65 $args['tag'] = array_map( 'sanitize_title_with_dashes', $search_terms ); 66 66 break; 67 67 case 'term': 68 $args['search'] = $ term;68 $args['search'] = $search_string; 69 69 break; 70 70 case 'author': 71 $args['author'] = $ term;71 $args['author'] = $search_string; 72 72 break; 73 73 } 74 74 75 if ( !empty( $_REQUEST['features'] ) ) { 76 $terms = $_REQUEST['features']; 77 $terms = array_map( 'trim', $terms ); 78 $terms = array_map( 'sanitize_title_with_dashes', $terms ); 79 $args['tag'] = $terms; 80 $_REQUEST['s'] = implode( ',', $terms ); 75 if ( ! empty( $this->features ) ) { 76 $args['tag'] = $this->features; 77 $_REQUEST['s'] = implode( ',', $this->features ); 81 78 $_REQUEST['type'] = 'tag'; 82 79 } … … 96 93 } 97 94 98 if ( ! $args )95 if ( ! $args ) 99 96 return; 100 97 … … 109 106 'total_items' => $api->info['results'], 110 107 'per_page' => $per_page, 108 'infinite_scroll' => true, 111 109 ) ); 112 110 } … … 129 127 } 130 128 131 function get_columns() {132 return array();133 }134 135 129 function display() { 136 137 130 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); 138 131 ?> … … 150 143 </div> 151 144 152 <div class="tablenav bottom themes"> 153 <?php $this->pagination( 'bottom' ); ?> 154 <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading list-ajax-loading" alt="" /> 155 <br class="clear" /> 156 </div> 157 <?php 145 <?php 146 parent::tablenav( 'bottom' ); 158 147 } 159 148 … … 171 160 <?php } // end foreach $theme_names 172 161 } 162 163 /** 164 * Send required variables to JavaScript land 165 * 166 * @since 3.4 167 * @access private 168 * 169 * @uses $tab Global; current tab within Themes->Install screen 170 * @uses $type Global; type of search. 171 */ 172 function _js_vars() { 173 global $tab, $type; 174 parent::_js_vars( compact( $tab, $type ) ); 175 } 173 176 } -
trunk/wp-admin/includes/class-wp-themes-list-table.php
r20068 r20094 21 21 function ajax_user_can() { 22 22 // Do not check edit_theme_options here. AJAX calls for available themes require switch_themes. 23 return current_user_can( 'switch_themes');23 return current_user_can( 'switch_themes' ); 24 24 } 25 25 … … 53 53 'total_items' => count( $themes ), 54 54 'per_page' => $per_page, 55 'infinite_scroll' => true, 55 56 ) ); 56 57 } … … 203 204 return true; 204 205 } 206 207 /** 208 * Send required variables to JavaScript land 209 * 210 * @since 3.4 211 * @access private 212 * 213 * @uses $this->features Array of all feature search terms. 214 * @uses get_pagenum() 215 * @uses _pagination_args['total_pages'] 216 */ 217 function _js_vars( $extra_args = array() ) { 218 $search_string = isset( $_REQUEST['s'] ) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : ''; 219 220 $total_pages = 1; 221 if ( ! empty( $this->_pagination_args['total_pages'] ) ) 222 $total_pages = $this->_pagination_args['total_pages']; 223 224 $args = array( 225 'search' => $search_string, 226 'features' => $this->features, 227 'paged' => $this->get_pagenum(), 228 'total_pages' => $total_pages, 229 ); 230 231 if ( is_array( $extra_args ) ) 232 $args = array_merge( $args, $extra_args ); 233 234 printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", json_encode( $args ) ); 235 parent::_js_vars(); 236 } 205 237 } -
trunk/wp-admin/includes/list-table.php
r19712 r20094 29 29 'WP_Plugin_Install_List_Table' => 'plugin-install', 30 30 'WP_Themes_List_Table' => 'themes', 31 'WP_Theme_Install_List_Table' => 'theme-install',31 'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ), 32 32 'WP_Plugins_List_Table' => 'plugins', 33 33 // Network Admin … … 38 38 39 39 if ( isset( $core_classes[ $class ] ) ) { 40 require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $core_classes[ $class ] . '-list-table.php' ); 40 foreach ( (array) $core_classes[ $class ] as $required ) 41 require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' ); 41 42 return new $class; 42 43 } -
trunk/wp-admin/js/theme.dev.js
r20000 r20094 55 55 }); 56 56 57 58 /** 59 * Class that provides infinite scroll for Themes admin screens 60 * 61 * @since 3.4 62 * 63 * @uses ajaxurl 64 * @uses list_args 65 * @uses theme_list_args 66 * @uses $('#_ajax_fetch_list_nonce').val() 67 * */ 57 68 var ThemeScroller; 58 59 69 (function($){ 60 70 ThemeScroller = { 61 // Inputs62 71 nonce: '', 63 search: '', 64 tab: '', 65 type: '', 66 nextPage: 2, 67 features: {}, 68 69 // Preferences 72 nextPage: 2, // By default, assume we're on the first page. 73 querying: false, 70 74 scrollPollingDelay: 500, 71 75 failedRetryDelay: 4000, 72 76 outListBottomThreshold: 300, 73 77 74 // Flags 75 scrolling: false, 76 querying: false, 77 78 /** 79 * Initializer 80 * 81 * @since 3.4 82 * @access private 83 */ 78 84 init: function() { 79 85 var self = this, 80 startPage ,81 queryArray = {}, 82 queryString = window.location.search;83 84 // We're using infinite scrolling, so hide all pagination.85 $('.pagination-links').hide();86 87 // Parse GET query string88 queryArray = this.parseQuery( queryString.substring( 1 ) );86 startPage; 87 88 // Get out early if we don't have the required arguments. 89 if ( typeof ajaxurl === 'undefined' || 90 typeof list_args === 'undefined' || 91 typeof theme_list_args === 'undefined' ) { 92 $('.pagination-links').show(); 93 return; 94 } 89 95 90 96 // Handle inputs 91 97 this.nonce = $('#_ajax_fetch_list_nonce').val(); 92 this.search = queryArray['s']; 93 this.features = queryArray['features']; 94 this.tab = queryArray['tab']; 95 this.type = queryArray['type']; 96 97 startPage = parseInt( queryArray['paged'], 10 ); 98 if ( ! isNaN( startPage ) ) 98 99 startPage = theme_list_args.paged; 100 if ( startPage !== undefined ) 99 101 this.nextPage = ( startPage + 1 ); 100 102 … … 105 107 this.$document = $(document); 106 108 107 if ( $('.tablenav-pages').length ) 109 /** 110 * If there are more pages to query, then start polling to track 111 * when user hits the bottom of the current page 112 */ 113 if ( theme_list_args.total_pages !== undefined && 114 theme_list_args.total_pages >= this.nextPage ) 108 115 this.pollInterval = 109 116 setInterval( function() { … … 111 118 }, this.scrollPollingDelay ); 112 119 }, 120 121 /** 122 * Checks to see if user has scrolled to bottom of page. 123 * If so, requests another page of content from self.ajax(). 124 * 125 * @since 3.4 126 * @access private 127 */ 113 128 poll: function() { 114 129 var bottom = this.$document.scrollTop() + this.$window.innerHeight(); … … 120 135 this.ajax(); 121 136 }, 137 138 /** 139 * Applies results passed from this.ajax() to $outList 140 * 141 * @since 3.4 142 * @access private 143 * 144 * @param results Array with results from this.ajax() query. 145 */ 122 146 process: function( results ) { 123 147 if ( ( results === undefined ) || 124 ( results.rows.indexOf( 'no-items' ) != -1 ) ) { 148 ( results.rows === undefined ) || 149 ( results.rows.indexOf( 'no-items' ) != -1 ) ) { 125 150 clearInterval( this.pollInterval ); 126 151 return; 127 152 } 128 153 129 var totalPages = parseInt( results.total_pages, 10 ); 130 if ( this.nextPage > totalPages ) 154 if ( this.nextPage > theme_list_args.total_pages ) 131 155 clearInterval( this.pollInterval ); 132 156 133 if ( this.nextPage <= ( t otalPages + 1 ) )157 if ( this.nextPage <= ( theme_list_args.total_pages + 1 ) ) 134 158 this.$outList.append( results.rows ); 135 159 }, 160 161 /** 162 * Queries next page of themes 163 * 164 * @since 3.4 165 * @access private 166 */ 136 167 ajax: function() { 137 168 var self = this; 169 138 170 this.querying = true; 139 171 140 172 var query = { 141 173 action: 'fetch-list', 142 tab: this.tab,143 174 paged: this.nextPage, 144 s: this.search, 145 type: this.type, 175 s: theme_list_args.search, 176 tab: theme_list_args.tab, 177 type: theme_list_args.type, 146 178 _ajax_fetch_list_nonce: this.nonce, 147 'features[]': th is.features,179 'features[]': theme_list_args.features, 148 180 'list_args': list_args 149 181 }; … … 160 192 self.$spinner.css( 'visibility', 'hidden' ); 161 193 self.querying = false; 162 setTimeout( function() { self.ajax(); }, self.failedRetryDelay ) 194 setTimeout( function() { self.ajax(); }, self.failedRetryDelay ); 163 195 }); 164 },165 parseQuery: function( query ) {166 var params = {};167 if ( ! query )168 return params;169 170 var pairs = query.split( /[;&]/ );171 for ( var i = 0; i < pairs.length; i++ ) {172 var keyVal = pairs[i].split( '=' );173 174 if ( ! keyVal || keyVal.length != 2 )175 continue;176 177 var key = unescape( keyVal[0] );178 var val = unescape( keyVal[1] );179 val = val.replace( /\+/g, ' ' );180 key = key.replace( /\[.*\]$/g, '' );181 182 if ( params[key] === undefined ) {183 params[key] = val;184 } else {185 var oldVal = params[key];186 if ( ! $.isArray( params[key] ) )187 params[key] = new Array( oldVal, val );188 else189 params[key].push( val );190 }191 }192 return params;193 196 } 194 197 } 195 198 196 $(document).ready( function( $ ) { ThemeScroller.init(); }); 199 $(document).ready( function($) { 200 ThemeScroller.init(); 201 }); 197 202 198 203 })(jQuery);
Note: See TracChangeset
for help on using the changeset viewer.