- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-themes-list-table.php
r18673 r21010 10 10 class WP_Themes_List_Table extends WP_List_Table { 11 11 12 var $search= array();12 protected $search_terms = array(); 13 13 var $features = array(); 14 15 function __construct() { 16 parent::__construct( array( 17 'ajax' => true, 18 ) ); 19 } 14 20 15 21 function ajax_user_can() { 16 22 // Do not check edit_theme_options here. AJAX calls for available themes require switch_themes. 17 return current_user_can( 'switch_themes');23 return current_user_can( 'switch_themes' ); 18 24 } 19 25 20 26 function prepare_items() { 21 global $ct; 22 23 $ct = current_theme_info(); 24 25 $themes = get_allowed_themes(); 26 27 if ( ! empty( $_REQUEST['s'] ) ) { 28 $search = strtolower( stripslashes( $_REQUEST['s'] ) ); 29 $this->search = array_merge( $this->search, array_filter( array_map( 'trim', explode( ',', $search ) ) ) ); 30 $this->search = array_unique( $this->search ); 31 } 32 33 if ( !empty( $_REQUEST['features'] ) ) { 27 $themes = wp_get_themes( array( 'allowed' => true ) ); 28 29 if ( ! empty( $_REQUEST['s'] ) ) 30 $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( stripslashes( $_REQUEST['s'] ) ) ) ) ) ); 31 32 if ( ! empty( $_REQUEST['features'] ) ) 34 33 $this->features = $_REQUEST['features']; 35 $this->features = array_map( 'trim', $this->features ); 36 $this->features = array_map( 'sanitize_title_with_dashes', $this->features ); 37 $this->features = array_unique( $this->features ); 38 } 39 40 if ( $this->search || $this->features ) { 34 35 if ( $this->search_terms || $this->features ) { 41 36 foreach ( $themes as $key => $theme ) { 42 if ( ! $this->search_theme( $theme ) )37 if ( ! $this->search_theme( $theme ) ) 43 38 unset( $themes[ $key ] ); 44 39 } 45 40 } 46 41 47 unset( $themes[ $ct->name] );48 uksort( $themes, "strnatcasecmp");49 50 $per_page = 24;42 unset( $themes[ get_option( 'stylesheet' ) ] ); 43 WP_Theme::sort_by_name( $themes ); 44 45 $per_page = 999; 51 46 $page = $this->get_pagenum(); 52 47 53 48 $start = ( $page - 1 ) * $per_page; 54 49 55 $this->items = array_slice( $themes, $start, $per_page );50 $this->items = array_slice( $themes, $start, $per_page, true ); 56 51 57 52 $this->set_pagination_args( array( 58 53 'total_items' => count( $themes ), 59 54 'per_page' => $per_page, 55 'infinite_scroll' => true, 60 56 ) ); 61 57 } 62 58 63 59 function no_items() { 64 if ( $this->search || $this->features ) {60 if ( $this->search_terms || $this->features ) { 65 61 _e( 'No items found.' ); 66 62 return; … … 102 98 103 99 function display() { 104 //wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );100 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); 105 101 ?> 106 102 <?php $this->tablenav( 'top' ); ?> … … 120 116 function display_rows() { 121 117 $themes = $this->items; 122 $theme_names = array_keys( $themes ); 123 natcasesort( $theme_names ); 124 125 foreach ( $theme_names as $theme_name ) { 126 $class = array( 'available-theme' ); 127 ?> 128 <div class="<?php echo join( ' ', $class ); ?>"> 129 <?php if ( !empty( $theme_name ) ) : 130 $template = $themes[$theme_name]['Template']; 131 $stylesheet = $themes[$theme_name]['Stylesheet']; 132 $title = $themes[$theme_name]['Title']; 133 $version = $themes[$theme_name]['Version']; 134 $description = $themes[$theme_name]['Description']; 135 $author = $themes[$theme_name]['Author']; 136 $screenshot = $themes[$theme_name]['Screenshot']; 137 $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir']; 138 $template_dir = $themes[$theme_name]['Template Dir']; 139 $parent_theme = $themes[$theme_name]['Parent Theme']; 140 $theme_root = $themes[$theme_name]['Theme Root']; 141 $theme_root_uri = $themes[$theme_name]['Theme Root URI']; 142 $preview_link = esc_url( get_option( 'home' ) . '/' ); 143 if ( is_ssl() ) 144 $preview_link = str_replace( 'http://', 'https://', $preview_link ); 145 $preview_link = htmlspecialchars( add_query_arg( array( 'preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => true, 'TB_iframe' => 'true' ), $preview_link ) ); 146 $preview_text = esc_attr( sprintf( __( 'Preview of “%s”' ), $title ) ); 147 $tags = $themes[$theme_name]['Tags']; 148 $thickbox_class = 'thickbox thickbox-preview'; 149 $activate_link = wp_nonce_url( "themes.php?action=activate&template=".urlencode( $template )."&stylesheet=".urlencode( $stylesheet ), 'switch-theme_' . $template ); 150 $activate_text = esc_attr( sprintf( __( 'Activate “%s”' ), $title ) ); 151 $actions = array(); 152 $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="' . $activate_text . '">' . __( 'Activate' ) . '</a>'; 153 $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr( sprintf( __( 'Preview “%s”' ), $theme_name ) ) . '">' . __( 'Preview' ) . '</a>'; 154 if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) 155 $actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url( "themes.php?action=delete&template=$stylesheet", 'delete-theme_' . $stylesheet ) . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $theme_name ) ) . "' );" . '">' . __( 'Delete' ) . '</a>'; 156 $actions = apply_filters( 'theme_action_links', $actions, $themes[$theme_name] ); 157 158 $actions = implode ( ' | ', $actions ); 159 ?> 160 <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot"> 161 <?php if ( $screenshot ) : ?> 162 <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" /> 163 <?php endif; ?> 164 </a> 165 <h3><?php 166 /* translators: 1: theme title, 2: theme version, 3: theme author */ 167 printf( __( '%1$s %2$s by %3$s' ), $title, $version, $author ) ; ?></h3> 168 <p class="description"><?php echo $description; ?></p> 169 <span class='action-links'><?php echo $actions ?></span> 170 <?php if ( current_user_can( 'edit_themes' ) && $parent_theme ) { 171 /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?> 172 <p><?php printf( __( 'The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ), $title, $parent_theme ); ?></p> 173 <?php } else { ?> 174 <p><?php printf( __( 'All of this theme’s files are located in <code>%2$s</code>.' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ) ); ?></p> 175 <?php } ?> 176 <?php if ( $tags ) : ?> 177 <p><?php _e( 'Tags:' ); ?> <?php echo join( ', ', $tags ); ?></p> 178 <?php endif; ?> 179 <?php theme_update_available( $themes[$theme_name] ); ?> 180 <?php endif; // end if not empty theme_name ?> 181 </div> 182 <?php } // end foreach $theme_names 118 119 foreach ( $themes as $theme ): 120 ?><div class="available-theme"><?php 121 122 $template = $theme->get_template(); 123 $stylesheet = $theme->get_stylesheet(); 124 $title = $theme->display('Name'); 125 $version = $theme->display('Version'); 126 $author = $theme->display('Author'); 127 128 $activate_link = wp_nonce_url( "themes.php?action=activate&template=" . urlencode( $template ) . "&stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet ); 129 130 $preview_link = esc_url( add_query_arg( 131 array( 'preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => true, 'TB_iframe' => 'true' ), 132 home_url( '/' ) ) ); 133 134 $actions = array(); 135 $actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' 136 . esc_attr( sprintf( __( 'Activate “%s”' ), $title ) ) . '">' . __( 'Activate' ) . '</a>'; 137 138 $actions['preview'] = '<a href="' . $preview_link . '" class="hide-if-customize" title="' 139 . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '">' . __( 'Preview' ) . '</a>'; 140 141 if ( current_user_can( 'edit_theme_options' ) ) 142 $actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="load-customize hide-if-no-customize">' 143 . __( 'Live Preview' ) . '</a>'; 144 145 if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) 146 $actions['delete'] = '<a class="submitdelete deletion" href="' . wp_nonce_url( "themes.php?action=delete&stylesheet=$stylesheet", 'delete-theme_' . $stylesheet ) 147 . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ) 148 . "' );" . '">' . __( 'Delete' ) . '</a>'; 149 150 $actions = apply_filters( 'theme_action_links', $actions, $theme ); 151 $delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : ''; 152 unset( $actions['delete'] ); 153 154 ?> 155 156 <a href="<?php echo $preview_link; ?>" class="screenshot hide-if-customize"> 157 <?php if ( $screenshot = $theme->get_screenshot() ) : ?> 158 <img src="<?php echo esc_url( $screenshot ); ?>" alt="" /> 159 <?php endif; ?> 160 </a> 161 <a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize"> 162 <?php if ( $screenshot = $theme->get_screenshot() ) : ?> 163 <img src="<?php echo esc_url( $screenshot ); ?>" alt="" /> 164 <?php endif; ?> 165 </a> 166 167 <h3><?php echo $title; ?></h3> 168 <div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div> 169 <div class="action-links"> 170 <ul> 171 <?php foreach ( $actions as $action ): ?> 172 <li><?php echo $action; ?></li> 173 <?php endforeach; ?> 174 <li class="hide-if-no-js"><a href="#" class="theme-detail" tabindex='4'><?php _e('Details') ?></a></li> 175 </ul> 176 <?php echo $delete_action; ?> 177 178 <?php theme_update_available( $theme ); ?> 179 </div> 180 181 <div class="themedetaildiv hide-if-js"> 182 <p><strong><?php _e('Version: '); ?></strong><?php echo $version; ?></p> 183 <p><?php echo $theme->display('Description'); ?></p> 184 <?php if ( current_user_can( 'edit_themes' ) && $theme->parent() ) : 185 /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?> 186 <p><?php printf( __( 'The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.' ), 187 $title, str_replace( WP_CONTENT_DIR, '', $theme->get_template_directory() ), str_replace( WP_CONTENT_DIR, '', $theme->get_stylesheet_directory() ), $title, $theme->parent()->display('Name') ); ?></p> 188 <?php else : 189 /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir */ ?> 190 <p><?php printf( __( 'All of this theme’s files are located in <code>%2$s</code>.' ), 191 $title, str_replace( WP_CONTENT_DIR, '', $theme->get_template_directory() ), str_replace( WP_CONTENT_DIR, '', $theme->get_stylesheet_directory() ) ); ?></p> 192 <?php endif; ?> 193 </div> 194 195 </div> 196 <?php 197 endforeach; 183 198 } 184 199 185 200 function search_theme( $theme ) { 186 $matched = 0; 201 // Search the features 202 foreach ( $this->features as $word ) { 203 if ( ! in_array( $word, $theme->get('Tags') ) ) 204 return false; 205 } 187 206 188 207 // Match all phrases 189 if ( count( $this->search ) > 0 ) { 190 foreach ( $this->search as $word ) { 191 $matched = 0; 192 193 // In a tag? 194 if ( in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) ) 195 $matched = 1; 196 197 // In one of the fields? 198 foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) AS $field ) { 199 if ( stripos( $theme[$field], $word ) !== false ) 200 $matched++; 201 } 202 203 if ( $matched == 0 ) 204 return false; 205 } 206 } 207 208 // Now search the features 209 if ( count( $this->features ) > 0 ) { 210 foreach ( $this->features as $word ) { 211 // In a tag? 212 if ( !in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) ) 213 return false; 214 } 215 } 216 217 // Only get here if each word exists in the tags or one of the fields 208 foreach ( $this->search_terms as $word ) { 209 if ( in_array( $word, $theme->get('Tags') ) ) 210 continue; 211 212 foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) { 213 // Don't mark up; Do translate. 214 if ( false !== stripos( $theme->display( $header, false, true ), $word ) ) 215 continue 2; 216 } 217 218 if ( false !== stripos( $theme->get_stylesheet(), $word ) ) 219 continue; 220 221 if ( false !== stripos( $theme->get_template(), $word ) ) 222 continue; 223 224 return false; 225 } 226 218 227 return true; 219 228 } 229 230 /** 231 * Send required variables to JavaScript land 232 * 233 * @since 3.4 234 * @access private 235 * 236 * @uses $this->features Array of all feature search terms. 237 * @uses get_pagenum() 238 * @uses _pagination_args['total_pages'] 239 */ 240 function _js_vars( $extra_args = array() ) { 241 $search_string = isset( $_REQUEST['s'] ) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : ''; 242 243 $args = array( 244 'search' => $search_string, 245 'features' => $this->features, 246 'paged' => $this->get_pagenum(), 247 'total_pages' => ! empty( $this->_pagination_args['total_pages'] ) ? $this->_pagination_args['total_pages'] : 1, 248 ); 249 250 if ( is_array( $extra_args ) ) 251 $args = array_merge( $args, $extra_args ); 252 253 printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", json_encode( $args ) ); 254 parent::_js_vars(); 255 } 220 256 } 221 222 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)