From 4cd99b0f04ee753fea9768cbbf9159aecef7e60f Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Sun, 19 Apr 2009 18:50:22 +0000 Subject: [PATCH] Plugin search and paging. Props DD32. see #9527 git-svn-id: https://develop.svn.wordpress.org/trunk@11003 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/plugins.php | 92 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 7 deletions(-) diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index 92fa54c0a0..9f70eb7403 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -211,10 +211,11 @@ if ( !empty($invalid) ) $plugin_data) { //Translate, Apply Markup, Sanitize HTML $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, true, true); + $all_plugins[ $plugin_file ] = $plugin_data; //Filter into individual sections if ( is_plugin_active($plugin_file) ) { @@ -245,18 +247,62 @@ foreach ( (array)$all_plugins as $plugin_file => $plugin_data) { $upgrade_plugins[ $plugin_file ] = $plugin_data; } -$total_plugins = count($all_plugins); +$total_all_plugins = count($all_plugins); $total_inactive_plugins = count($inactive_plugins); $total_active_plugins = count($active_plugins); $total_recent_plugins = count($recent_plugins); $total_upgrade_plugins = count($upgrade_plugins); -$status = ( isset($_GET['plugin_status']) ) ? $_GET['plugin_status'] : 'all'; -if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade')) ) +//Searching. +if ( isset($_GET['s']) ) { + function _search_plugins_filter_callback($plugin) { + static $term; + if ( is_null($term) ) + $term = stripslashes($_GET['s']); + if ( stripos($plugin['Name'], $term) !== false || + stripos($plugin['Description'], $term) !== false || + stripos($plugin['Author'], $term) !== false || + stripos($plugin['PluginURI'], $term) !== false || + stripos($plugin['AuthorURI'], $term) !== false || + stripos($plugin['Version'], $term) !== false ) + return true; + else + return false; + } + $_GET['plugin_status'] = 'search'; + $search_plugins = array_filter($all_plugins, '_search_plugins_filter_callback'); + $total_search_plugins = count($search_plugins); +} + +$status = isset($_GET['plugin_status']) ? $_GET['plugin_status'] : 'all'; +if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'search')) ) $status = 'all'; $plugin_array_name = "${status}_plugins"; $plugins = &$$plugin_array_name; +//Paging. +$page = isset($_GET['paged']) ? $_GET['paged'] : 1; +$total_this_page = "total_{$status}_plugins"; +$total_this_page = $$total_this_page; +$plugins_per_page = apply_filters('plugins_per_page', 20, $status); + +$start = ($page - 1) * $plugins_per_page; + +$page_links = paginate_links( array( + 'base' => add_query_arg( 'paged', '%#%' ), + 'format' => '', + 'prev_text' => __('«'), + 'next_text' => __('»'), + 'total' => ceil($total_this_page / $plugins_per_page), + 'current' => $page +)); +$page_links_text = sprintf( '' . __( 'Displaying %s–%s of %s' ) . '%s', + number_format_i18n( $start + 1 ), + number_format_i18n( min( $page * $plugins_per_page, $total_this_page ) ), + '' . number_format_i18n( $total_this_page ) . '', + $page_links +); + /** * @ignore * @@ -362,6 +408,14 @@ function print_plugin_actions($context) { } ?> +
+ +
+
@@ -369,7 +423,7 @@ function print_plugin_actions($context) { " . sprintf( _n( 'All (%s)', 'All (%s)', $total_plugins ), number_format_i18n( $total_plugins ) ) . ''; +$status_links[] = "
  • " . sprintf( _n( 'All (%s)', 'All (%s)', $total_all_plugins ), number_format_i18n( $total_all_plugins ) ) . ''; if ( ! empty($active_plugins) ) { $class = ( 'active' == $status ) ? ' class="current"' : ''; $status_links[] = "
  • " . sprintf( _n( 'Active (%s)', 'Active (%s)', $total_active_plugins ), number_format_i18n( $total_active_plugins ) ) . ''; @@ -386,16 +440,40 @@ if ( ! empty($upgrade_plugins) ) { $class = ( 'upgrade' == $status ) ? ' class="current"' : ''; $status_links[] = "
  • " . sprintf( _n( 'Upgrade Available (%s)', 'Upgrade Available (%s)', $total_upgrade_plugins ), number_format_i18n( $total_upgrade_plugins ) ) . ''; } +if ( ! empty($search_plugins) ) { + $class = ( 'search' == $status ) ? ' class="current"' : ''; + $term = isset($_REQUEST['s']) ? urlencode(stripslashes($_REQUEST['s'])) : ''; + $status_links[] = "
  • " . sprintf( _n( 'Search Results (%s)', 'Search Results (%s)', $total_search_plugins ), number_format_i18n( $total_search_plugins ) ) . ''; +} echo implode( " |
  • \n", $status_links ) . ''; unset( $status_links ); ?>
    - +', $page_links_text, '
    '; + +print_plugin_actions($status); +?>
    - + $plugins_per_page ) + $plugins = array_slice($plugins, $start, $plugins_per_page); + + print_plugins_table($plugins, $status); +?> +
    +$page_links_text
    "; +?> +
    + +
    +