From ed134c40a519336c1ff04e09b1bdcbdf4afc5c3f Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 22 Sep 2010 15:28:03 +0000 Subject: [PATCH] Theme searching. First pass. see #14936 git-svn-id: http://svn.automattic.com/wordpress/trunk@15644 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/default-list-tables.php | 51 +++++++++++++++++++++++ wp-admin/themes.php | 9 ++++ 2 files changed, 60 insertions(+) diff --git a/wp-admin/includes/default-list-tables.php b/wp-admin/includes/default-list-tables.php index a31ea13ad2..8e8c88516d 100644 --- a/wp-admin/includes/default-list-tables.php +++ b/wp-admin/includes/default-list-tables.php @@ -3857,6 +3857,9 @@ class WP_Plugin_Install_Table extends WP_List_Table { class WP_Themes_Table extends WP_List_Table { + var $search = array(); + var $features = array(); + function WP_Themes_Table() { parent::__construct( array( 'screen' => 'themes', @@ -3874,6 +3877,18 @@ class WP_Themes_Table extends WP_List_Table { $ct = current_theme_info(); $themes = get_allowed_themes(); + + $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : ''; + + if ( '' !== $this->search ) { + $this->search = array_merge( $this->search, array_filter( array_map( 'trim', explode( ',', $search ) ) ) ); + $this->search = array_unique( $this->search ); + foreach ( $themes as $key => $theme ) { + if ( !$this->search_theme( $theme ) ) + unset( $themes[ $key ] ); + } + } + unset( $themes[$ct->name] ); uksort( $themes, "strnatcasecmp" ); @@ -4002,6 +4017,42 @@ foreach ( $cols as $col => $theme_name ) { search ) > 0 ) { + foreach ( $this->search as $word ) { + $matched = 0; + + // In a tag? + if ( in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) ) + $matched = 1; + + // In one of the fields? + foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) AS $field ) { + if ( stripos( $theme[$field], $word ) !== false ) + $matched++; + } + + if ( $matched == 0 ) + return false; + } + } + + // Now search the features + if ( count( $this->features ) > 0 ) { + foreach ( $this->features as $word ) { + // In a tag? + if ( !in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) ) + return false; + } + } + + // Only get here if each word exists in the tags or one of the fields + return true; + } } class WP_Theme_Install_Table extends WP_List_Table { diff --git a/wp-admin/themes.php b/wp-admin/themes.php index 0df3582323..d43b98bd40 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -103,6 +103,15 @@ if ( ! current_user_can( 'switch_themes' ) ) { ?>

+
+ +
+
+ display(); ?>