<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[15644] trunk/wp-admin: Theme searching.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15644">15644</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-09-22 15:28:03 +0000 (Wed, 22 Sep 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Theme searching. First pass. see <a href="http://trac.wordpress.org/ticket/14936">#14936</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesdefaultlisttablesphp">trunk/wp-admin/includes/default-list-tables.php</a></li>
<li><a href="#trunkwpadminthemesphp">trunk/wp-admin/themes.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesdefaultlisttablesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/default-list-tables.php (15643 => 15644)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/default-list-tables.php        2010-09-22 15:26:16 UTC (rev 15643)
+++ trunk/wp-admin/includes/default-list-tables.php        2010-09-22 15:28:03 UTC (rev 15644)
</span><span class="lines">@@ -3857,6 +3857,9 @@
</span><span class="cx"> 
</span><span class="cx"> class WP_Themes_Table extends WP_List_Table {
</span><span class="cx"> 
</span><ins>+        var $search = array();
+        var $features = array();
+
</ins><span class="cx">         function WP_Themes_Table() {
</span><span class="cx">                 parent::__construct( array(
</span><span class="cx">                         'screen' =&gt; 'themes',
</span><span class="lines">@@ -3874,6 +3877,18 @@
</span><span class="cx">                 $ct = current_theme_info();
</span><span class="cx"> 
</span><span class="cx">                 $themes = get_allowed_themes();
</span><ins>+
+                $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
+
+                if ( '' !== $this-&gt;search ) {
+                        $this-&gt;search = array_merge( $this-&gt;search, array_filter( array_map( 'trim', explode( ',', $search ) ) ) );
+                        $this-&gt;search = array_unique( $this-&gt;search );
+                        foreach ( $themes as $key =&gt; $theme ) {
+                                if ( !$this-&gt;search_theme( $theme ) )
+                                        unset( $themes[ $key ] );
+                        }
+                }
+
</ins><span class="cx">                 unset( $themes[$ct-&gt;name] );
</span><span class="cx">                 uksort( $themes, &quot;strnatcasecmp&quot; );
</span><span class="cx"> 
</span><span class="lines">@@ -4002,6 +4017,42 @@
</span><span class="cx"> &lt;/tr&gt;
</span><span class="cx"> &lt;?php } // end foreach $table
</span><span class="cx">         }
</span><ins>+
+        function search_theme( $theme ) {
+                $matched = 0;
+
+                // Match all phrases
+                if ( count( $this-&gt;search ) &gt; 0 ) {
+                        foreach ( $this-&gt;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-&gt;features ) &gt; 0 ) {
+                        foreach ( $this-&gt;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;
+        }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> class WP_Theme_Install_Table extends WP_List_Table {
</span></span></pre></div>
<a id="trunkwpadminthemesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/themes.php (15643 => 15644)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/themes.php        2010-09-22 15:26:16 UTC (rev 15643)
+++ trunk/wp-admin/themes.php        2010-09-22 15:28:03 UTC (rev 15644)
</span><span class="lines">@@ -103,6 +103,15 @@
</span><span class="cx"> ?&gt;
</span><span class="cx"> &lt;h3&gt;&lt;?php _e('Available Themes'); ?&gt;&lt;/h3&gt;
</span><span class="cx"> 
</span><ins>+&lt;form class=&quot;search-form&quot; action=&quot;&quot; method=&quot;get&quot;&gt;
+&lt;p class=&quot;search-box&quot;&gt;
+        &lt;label class=&quot;screen-reader-text&quot; for=&quot;theme-search-input&quot;&gt;&lt;?php _e('Search Themes'); ?&gt;:&lt;/label&gt;
+        &lt;input type=&quot;text&quot; id=&quot;tag-search-input&quot; name=&quot;s&quot; value=&quot;&lt;?php _admin_search_query(); ?&gt;&quot; /&gt;
+        &lt;input type=&quot;submit&quot; value=&quot;&lt;?php esc_attr_e('Search Themes');  ?&gt;&quot; class=&quot;button&quot; /&gt;
+&lt;/p&gt;
+&lt;/form&gt;
+&lt;br class=&quot;clear&quot; /&gt;
+
</ins><span class="cx"> &lt;?php $wp_list_table-&gt;display(); ?&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;br class=&quot;clear&quot; /&gt;
</span></span></pre>
</div>
</div>

</body>
</html>