Ticket #19815: 19815.11.diff
File 19815.11.diff, 10.9 KB (added by , 12 years ago) |
---|
-
wp-admin/includes/class-wp-theme-install-list-table.php
9 9 */ 10 10 class WP_Theme_Install_List_Table extends WP_List_Table { 11 11 12 var $features = array(); 13 12 14 function __construct() { 13 15 parent::__construct( array( 14 16 'ajax' => true, … … 16 18 } 17 19 18 20 function ajax_user_can() { 19 return current_user_can( 'install_themes');21 return current_user_can( 'install_themes' ); 20 22 } 21 23 22 24 function prepare_items() { 23 25 include( ABSPATH . 'wp-admin/includes/theme-install.php' ); 24 26 25 global $tabs, $tab, $paged, $type, $term, $theme_field_defaults; 26 27 global $tabs, $tab, $paged, $type, $theme_field_defaults; 27 28 wp_reset_vars( array( 'tab' ) ); 28 29 30 $search = array(); 31 $sanitized_terms = ''; 32 if ( ! empty( $_REQUEST['s'] ) ) { 33 $sanitized_terms = strtolower( stripslashes( $_REQUEST['s'] ) ); 34 $search = array_merge( $search, array_filter( array_map( 'trim', explode( ',', $sanitized_terms ) ) ) ); 35 $search = array_unique( $search ); 36 } 37 38 if ( ! empty( $_REQUEST['features'] ) ) { 39 $this->features = $_REQUEST['features']; 40 $this->features = array_map( 'trim', $this->features ); 41 $this->features = array_map( 'sanitize_title_with_dashes', $this->features ); 42 $this->features = array_unique( $this->features ); 43 } 44 29 45 $paged = $this->get_pagenum(); 30 46 31 47 $per_page = 36; … … 55 71 switch ( $tab ) { 56 72 case 'search': 57 73 $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : ''; 58 $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';59 60 74 switch ( $type ) { 61 75 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; 76 $args['tag'] = array_map( 'sanitize_title_with_dashes', $search ); 66 77 break; 67 78 case 'term': 68 $args['search'] = $ term;79 $args['search'] = $sanitized_terms; 69 80 break; 70 81 case 'author': 71 $args['author'] = $ term;82 $args['author'] = $sanitized_terms; 72 83 break; 73 84 } 74 85 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 ); 86 if ( ! empty( $this->features ) ) { 87 $args['tag'] = $this->features; 88 $_REQUEST['s'] = implode( ',', $this->features ); 81 89 $_REQUEST['type'] = 'tag'; 82 90 } 83 91 … … 95 103 $args = false; 96 104 } 97 105 98 if ( ! $args )106 if ( ! $args ) 99 107 return; 100 108 101 109 $api = themes_api( 'query_themes', $args ); … … 170 178 ?></div> 171 179 <?php } // end foreach $theme_names 172 180 } 181 182 /** 183 * Send required variables to JavaScript land 184 * 185 * @since 3.4 186 * @access private 187 * 188 * @uses $tab Global; current tab within Themes->Install screen 189 * @uses $type Global; type of search. 190 * @uses $this->features Array of all feature search terms. 191 * @uses get_pagenum() 192 * @uses _pagination_args['total_pages'] 193 */ 194 function _js_vars() { 195 global $tab, $type; 196 $search_string = isset( $_REQUEST['s'] ) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : ''; 197 198 $total_pages = 0; 199 if ( ! empty( $this->_pagination_args['total_pages'] ) ) 200 $total_pages = $this->_pagination_args['total_pages']; 201 202 $args = array( 203 'search' => $search_string, 204 'features' => $this->features, 205 'paged' => $this->get_pagenum(), 206 'total_pages' => $total_pages, 207 208 // Send items specific to theme-install 209 'tab' => $tab, 210 'type' => $type, 211 ); 212 213 printf( "<script type='text/javascript'>theme_list_args = %s;</script>\n", json_encode( $args ) ); 214 parent::_js_vars(); 215 } 173 216 } -
wp-admin/includes/class-wp-themes-list-table.php
11 11 12 12 var $search = array(); 13 13 var $features = array(); 14 14 15 15 function __construct() { 16 16 parent::__construct( array( 17 17 'ajax' => true, … … 20 20 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 26 26 function prepare_items() { … … 32 32 $this->search = array_unique( $this->search ); 33 33 } 34 34 35 if ( ! empty( $_REQUEST['features'] ) ) {35 if ( ! empty( $_REQUEST['features'] ) ) { 36 36 $this->features = $_REQUEST['features']; 37 37 $this->features = array_map( 'trim', $this->features ); 38 38 $this->features = array_map( 'sanitize_title_with_dashes', $this->features ); … … 217 217 218 218 return true; 219 219 } 220 221 /** 222 * Send required variables to JavaScript land 223 * 224 * @since 3.4 225 * @access private 226 * 227 * @uses $this->features Array of all feature search terms. 228 * @uses get_pagenum() 229 * @uses _pagination_args['total_pages'] 230 */ 231 function _js_vars() { 232 $search_string = isset( $_REQUEST['s'] ) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : ''; 233 234 $total_pages = 1; 235 if ( ! empty( $this->_pagination_args['total_pages'] ) ) 236 $total_pages = $this->_pagination_args['total_pages']; 237 238 $args = array( 239 'search' => $search_string, 240 'features' => $this->features, 241 'paged' => $this->get_pagenum(), 242 'total_pages' => $total_pages, 243 ); 244 245 printf( "<script type='text/javascript'>theme_list_args = %s;</script>\n", json_encode( $args ) ); 246 parent::_js_vars(); 247 } 220 248 } -
wp-admin/js/theme.dev.js
54 54 theme_viewer.init(); 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; 86 startPage; 83 87 84 88 // We're using infinite scrolling, so hide all pagination. 85 89 $('.pagination-links').hide(); 86 90 87 // Parse GET query string 88 queryArray = this.parseQuery( queryString.substring( 1 ) ); 91 // Get out early if we don't have the required arguments. 92 if ( ajaxurl === undefined || 93 list_args === undefined || 94 theme_list_args === undefined ) 95 return; 89 96 90 97 // Handle inputs 91 98 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 99 97 startPage = parseInt( queryArray['paged'], 10 );98 if ( ! isNaN( startPage ))100 startPage = theme_list_args.paged; 101 if ( startPage !== undefined ) 99 102 this.nextPage = ( startPage + 1 ); 100 103 101 104 // Cache jQuery selectors … … 104 107 this.$window = $(window); 105 108 this.$document = $(document); 106 109 107 if ( $('.tablenav-pages').length ) 110 /** 111 * If there are more pages to query, then start polling to track 112 * when user hits the bottom of the current page 113 */ 114 if ( theme_list_args.total_pages !== undefined && 115 theme_list_args.total_pages >= this.nextPage ) 108 116 this.pollInterval = 109 117 setInterval( function() { 110 118 return self.poll(); 111 119 }, this.scrollPollingDelay ); 112 120 }, 121 122 /** 123 * Checks to see if user has scrolled to bottom of page. 124 * If so, requests another page of content from self.ajax(). 125 * 126 * @since 3.4 127 * @access private 128 */ 113 129 poll: function() { 114 130 var bottom = this.$document.scrollTop() + this.$window.innerHeight(); 115 131 … … 119 135 120 136 this.ajax(); 121 137 }, 138 139 /** 140 * Applies results passed from this.ajax() to $outList 141 * 142 * @since 3.4 143 * @access private 144 * 145 * @param results Array with results from this.ajax() query. 146 */ 122 147 process: function( results ) { 123 148 if ( ( results === undefined ) || 124 ( results.rows.indexOf( 'no-items' ) != -1 ) ) { 149 ( results.rows === undefined ) || 150 ( results.rows.indexOf( 'no-items' ) != -1 ) ) { 125 151 clearInterval( this.pollInterval ); 126 152 return; 127 153 } 128 154 129 var totalPages = parseInt( results.total_pages, 10 ); 130 if ( this.nextPage > totalPages ) 155 if ( this.nextPage > theme_list_args.total_pages ) 131 156 clearInterval( this.pollInterval ); 132 157 133 if ( this.nextPage <= ( t otalPages + 1 ) )158 if ( this.nextPage <= ( theme_list_args.total_pages + 1 ) ) 134 159 this.$outList.append( results.rows ); 135 160 }, 161 162 /** 163 * Queries next page of themes 164 * 165 * @since 3.4 166 * @access private 167 */ 136 168 ajax: function() { 137 169 var self = this; 170 138 171 this.querying = true; 139 172 140 173 var query = { 141 174 action: 'fetch-list', 142 tab: this.tab,143 175 paged: this.nextPage, 144 s: this.search, 145 type: this.type, 176 s: theme_list_args.search, 177 tab: theme_list_args.tab, 178 type: theme_list_args.type, 146 179 _ajax_fetch_list_nonce: this.nonce, 147 'features[]': th is.features,180 'features[]': theme_list_args.features, 148 181 'list_args': list_args 149 182 }; 150 183 … … 159 192 .fail( function() { 160 193 self.$spinner.css( 'visibility', 'hidden' ); 161 194 self.querying = false; 162 setTimeout( function() { self.ajax(); }, self.failedRetryDelay ) 195 setTimeout( function() { self.ajax(); }, self.failedRetryDelay ); 163 196 }); 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 197 } 194 198 } 195 199 196 $(document).ready( function( $ ) { ThemeScroller.init(); }); 200 $(document).ready( function($) { 201 ThemeScroller.init(); 202 }); 197 203 198 204 })(jQuery);