WordPress.org

Make WordPress Core

Changeset 11003


Ignore:
Timestamp:
04/19/09 18:50:22 (6 years ago)
Author:
ryan
Message:

Plugin search and paging. Props DD32. see #9527

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/plugins.php

    r11002 r11003  
    212212 
    213213$all_plugins = get_plugins(); 
     214$search_plugins = array(); 
    214215$active_plugins = array(); 
    215216$inactive_plugins = array(); 
    216217$recent_plugins = array(); 
    217 $recently_activated = (array) get_option('recently_activated'); 
     218$recently_activated = get_option('recently_activated', array()); 
    218219$upgrade_plugins = array(); 
    219220 
     
    232233    //Translate, Apply Markup, Sanitize HTML 
    233234    $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, true, true); 
     235    $all_plugins[ $plugin_file ] = $plugin_data; 
    234236 
    235237    //Filter into individual sections 
     
    246248} 
    247249 
    248 $total_plugins = count($all_plugins); 
     250$total_all_plugins = count($all_plugins); 
    249251$total_inactive_plugins = count($inactive_plugins); 
    250252$total_active_plugins = count($active_plugins); 
     
    252254$total_upgrade_plugins = count($upgrade_plugins); 
    253255 
    254 $status = ( isset($_GET['plugin_status']) ) ? $_GET['plugin_status'] : 'all'; 
    255 if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade')) ) 
     256//Searching. 
     257if ( isset($_GET['s']) ) { 
     258    function _search_plugins_filter_callback($plugin) { 
     259        static $term; 
     260        if ( is_null($term) ) 
     261            $term = stripslashes($_GET['s']); 
     262        if (    stripos($plugin['Name'], $term) !== false || 
     263                stripos($plugin['Description'], $term) !== false || 
     264                stripos($plugin['Author'], $term) !== false || 
     265                stripos($plugin['PluginURI'], $term) !== false || 
     266                stripos($plugin['AuthorURI'], $term) !== false || 
     267                stripos($plugin['Version'], $term) !== false ) 
     268            return true; 
     269        else 
     270            return false; 
     271    } 
     272    $_GET['plugin_status'] = 'search'; 
     273    $search_plugins = array_filter($all_plugins, '_search_plugins_filter_callback'); 
     274    $total_search_plugins = count($search_plugins); 
     275} 
     276 
     277$status = isset($_GET['plugin_status']) ? $_GET['plugin_status'] : 'all'; 
     278if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'search')) ) 
    256279    $status = 'all'; 
    257280$plugin_array_name = "${status}_plugins"; 
    258281$plugins = &$$plugin_array_name; 
     282 
     283//Paging. 
     284$page = isset($_GET['paged']) ? $_GET['paged'] : 1; 
     285$total_this_page = "total_{$status}_plugins"; 
     286$total_this_page = $$total_this_page; 
     287$plugins_per_page = apply_filters('plugins_per_page', 20, $status); 
     288 
     289$start = ($page - 1) * $plugins_per_page; 
     290 
     291$page_links = paginate_links( array( 
     292    'base' => add_query_arg( 'paged', '%#%' ), 
     293    'format' => '', 
     294    'prev_text' => __('«'), 
     295    'next_text' => __('»'), 
     296    'total' => ceil($total_this_page / $plugins_per_page), 
     297    'current' => $page 
     298)); 
     299$page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s', 
     300    number_format_i18n( $start + 1 ), 
     301    number_format_i18n( min( $page * $plugins_per_page, $total_this_page ) ), 
     302    '<span class="total-type-count">' . number_format_i18n( $total_this_page ) . '</span>', 
     303    $page_links 
     304); 
    259305 
    260306/** 
     
    363409?> 
    364410 
     411<form method="get" action=""> 
     412<p class="search-box"> 
     413    <label class="hidden" for="plugin-search-input"><?php _e( 'Search Plugins' ); ?>:</label> 
     414    <input type="text" id="plugin-search-input" name="s" value="<?php _admin_search_query(); ?>" /> 
     415    <input type="submit" value="<?php _e( 'Search Plugins' ); ?>" class="button" /> 
     416</p> 
     417</form> 
     418 
    365419<form method="post" action="<?php echo admin_url('plugins.php') ?>"> 
    366420<?php wp_nonce_field('bulk-manage-plugins') ?> 
     
    370424$status_links = array(); 
    371425$class = ( 'all' == $status ) ? ' class="current"' : ''; 
    372 $status_links[] = "<li><a href='plugins.php' $class>" . sprintf( _n( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_plugins ), number_format_i18n( $total_plugins ) ) . '</a>'; 
     426$status_links[] = "<li><a href='plugins.php' $class>" . sprintf( _n( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_all_plugins ), number_format_i18n( $total_all_plugins ) ) . '</a>'; 
    373427if ( ! empty($active_plugins) ) { 
    374428    $class = ( 'active' == $status ) ? ' class="current"' : ''; 
     
    387441    $status_links[] = "<li><a href='plugins.php?plugin_status=upgrade' $class>" . sprintf( _n( 'Upgrade Available <span class="count">(%s)</span>', 'Upgrade Available <span class="count">(%s)</span>', $total_upgrade_plugins ), number_format_i18n( $total_upgrade_plugins ) ) . '</a>'; 
    388442} 
     443if ( ! empty($search_plugins) ) { 
     444    $class = ( 'search' == $status ) ? ' class="current"' : ''; 
     445    $term = isset($_REQUEST['s']) ? urlencode(stripslashes($_REQUEST['s'])) : ''; 
     446    $status_links[] = "<li><a href='plugins.php?s=$term' $class>" . sprintf( _n( 'Search Results <span class="count">(%s)</span>', 'Search Results <span class="count">(%s)</span>', $total_search_plugins ), number_format_i18n( $total_search_plugins ) ) . '</a>'; 
     447} 
    389448echo implode( " |</li>\n", $status_links ) . '</li>'; 
    390449unset( $status_links ); 
     
    393452 
    394453<div class="tablenav"> 
    395 <?php print_plugin_actions($status) ?> 
     454<?php 
     455if ( $page_links ) 
     456    echo '<div class="tablenav-pages">', $page_links_text, '</div>'; 
     457 
     458print_plugin_actions($status); 
     459?> 
    396460</div> 
    397461<div class="clear"></div> 
    398 <?php print_plugins_table($plugins, $status) ?> 
     462<?php 
     463    if ( $total_this_page > $plugins_per_page ) 
     464        $plugins = array_slice($plugins, $start, $plugins_per_page); 
     465     
     466    print_plugins_table($plugins, $status); 
     467?> 
     468<div class="tablenav"> 
     469<?php 
     470if ( $page_links ) 
     471    echo "<div class='tablenav-pages'>$page_links_text</div>"; 
     472?> 
     473<div class="alignleft actions"> 
     474<!-- TODO lower bulk actions. --> 
     475</div> 
     476</div> 
    399477</form> 
    400478 
Note: See TracChangeset for help on using the changeset viewer.