Ticket #19815: 19815.11.2.diff
File 19815.11.2.diff, 10.1 KB (added by , 13 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_terms = array(); 31 $search_string = ''; 32 if ( ! empty( $_REQUEST['s'] ) ){ 33 $search_string = strtolower( stripslashes( $_REQUEST['s'] ) ); 34 $search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) ); 35 } 36 37 if ( ! empty( $_REQUEST['features'] ) ) 38 $this->features = $_REQUEST['features']; 39 29 40 $paged = $this->get_pagenum(); 30 41 31 42 $per_page = 36; … … 55 66 switch ( $tab ) { 56 67 case 'search': 57 68 $type = isset( $_REQUEST['type'] ) ? stripslashes( $_REQUEST['type'] ) : ''; 58 $term = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';59 60 69 switch ( $type ) { 61 70 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; 71 $args['tag'] = array_map( 'sanitize_title_with_dashes', $search_terms ); 66 72 break; 67 73 case 'term': 68 $args['search'] = $ term;74 $args['search'] = $search_string; 69 75 break; 70 76 case 'author': 71 $args['author'] = $ term;77 $args['author'] = $search_string; 72 78 break; 73 79 } 74 80 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 ); 81 if ( ! empty( $this->features ) ) { 82 $args['tag'] = $this->features; 83 $_REQUEST['s'] = implode( ',', $this->features ); 81 84 $_REQUEST['type'] = 'tag'; 82 85 } 83 86 … … 95 98 $args = false; 96 99 } 97 100 98 if ( ! $args )101 if ( ! $args ) 99 102 return; 100 103 101 104 $api = themes_api( 'query_themes', $args ); … … 170 173 ?></div> 171 174 <?php } // end foreach $theme_names 172 175 } 176 177 /** 178 * Send required variables to JavaScript land 179 * 180 * @since 3.4 181 * @access private 182 * 183 * @uses $tab Global; current tab within Themes->Install screen 184 * @uses $type Global; type of search. 185 * @uses $this->features Array of all feature search terms. 186 * @uses get_pagenum() 187 * @uses _pagination_args['total_pages'] 188 */ 189 function _js_vars() { 190 global $tab, $type; 191 $search_string = isset( $_REQUEST['s'] ) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : ''; 192 193 $total_pages = 0; 194 if ( ! empty( $this->_pagination_args['total_pages'] ) ) 195 $total_pages = $this->_pagination_args['total_pages']; 196 197 $args = array( 198 'search' => $search_string, 199 'features' => $this->features, 200 'paged' => $this->get_pagenum(), 201 'total_pages' => $total_pages, 202 'tab' => $tab, 203 'type' => $type, 204 ); 205 206 printf( "<script type='text/javascript'>theme_list_args = %s;</script>\n", json_encode( $args ) ); 207 parent::_js_vars(); 208 } 173 209 } -
wp-admin/includes/class-wp-themes-list-table.php
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() { … … 202 202 203 203 return true; 204 204 } 205 206 /** 207 * Send required variables to JavaScript land 208 * 209 * @since 3.4 210 * @access private 211 * 212 * @uses $this->features Array of all feature search terms. 213 * @uses get_pagenum() 214 * @uses _pagination_args['total_pages'] 215 */ 216 function _js_vars() { 217 $search_string = isset( $_REQUEST['s'] ) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : ''; 218 219 $total_pages = 1; 220 if ( ! empty( $this->_pagination_args['total_pages'] ) ) 221 $total_pages = $this->_pagination_args['total_pages']; 222 223 $args = array( 224 'search' => $search_string, 225 'features' => $this->features, 226 'paged' => $this->get_pagenum(), 227 'total_pages' => $total_pages, 228 ); 229 230 printf( "<script type='text/javascript'>theme_list_args = %s;</script>\n", json_encode( $args ) ); 231 parent::_js_vars(); 232 } 205 233 } -
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);