Make WordPress Core


Ignore:
Timestamp:
09/22/2010 03:28:03 PM (14 years ago)
Author:
ryan
Message:

Theme searching. First pass. see #14936

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/default-list-tables.php

    r15642 r15644  
    38583858class WP_Themes_Table extends WP_List_Table {
    38593859
     3860    var $search = array();
     3861    var $features = array();
     3862
    38603863    function WP_Themes_Table() {
    38613864        parent::__construct( array(
     
    38753878
    38763879        $themes = get_allowed_themes();
     3880
     3881        $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
     3882
     3883        if ( '' !== $this->search ) {
     3884            $this->search = array_merge( $this->search, array_filter( array_map( 'trim', explode( ',', $search ) ) ) );
     3885            $this->search = array_unique( $this->search );
     3886            foreach ( $themes as $key => $theme ) {
     3887                if ( !$this->search_theme( $theme ) )
     3888                    unset( $themes[ $key ] );
     3889            }
     3890        }
     3891
    38773892        unset( $themes[$ct->name] );
    38783893        uksort( $themes, "strnatcasecmp" );
     
    40034018<?php } // end foreach $table
    40044019    }
     4020
     4021    function search_theme( $theme ) {
     4022        $matched = 0;
     4023
     4024        // Match all phrases
     4025        if ( count( $this->search ) > 0 ) {
     4026            foreach ( $this->search as $word ) {
     4027                $matched = 0;
     4028
     4029                // In a tag?
     4030                if ( in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
     4031                    $matched = 1;
     4032
     4033                // In one of the fields?
     4034                foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) AS $field ) {
     4035                    if ( stripos( $theme[$field], $word ) !== false )
     4036                        $matched++;
     4037                }
     4038
     4039                if ( $matched == 0 )
     4040                    return false;
     4041            }
     4042        }
     4043
     4044        // Now search the features
     4045        if ( count( $this->features ) > 0 ) {
     4046            foreach ( $this->features as $word ) {
     4047                // In a tag?
     4048                if ( !in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
     4049                    return false;
     4050            }
     4051        }
     4052
     4053        // Only get here if each word exists in the tags or one of the fields
     4054        return true;
     4055    }
    40054056}
    40064057
Note: See TracChangeset for help on using the changeset viewer.