Make WordPress Core


Ignore:
Timestamp:
08/11/2010 09:54:51 PM (15 years ago)
Author:
scribu
Message:

Ajaxify list-type screens in the admin. See #14579

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/theme-install.php

    r14818 r15491  
    8989}
    9090
    91 add_action('install_themes_search', 'install_theme_search', 10, 1);
    92 /**
    93  * Display theme search results
    94  *
    95  * @since 2.8.0
    96  *
    97  * @param string $page
    98  */
    99 function install_theme_search($page) {
    100     global $theme_field_defaults;
    101 
    102     $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
    103     $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
    104 
    105     $args = array();
    106 
    107     switch( $type ){
    108         case 'tag':
    109             $terms = explode(',', $term);
    110             $terms = array_map('trim', $terms);
    111             $terms = array_map('sanitize_title_with_dashes', $terms);
    112             $args['tag'] = $terms;
    113             break;
    114         case 'term':
    115             $args['search'] = $term;
    116             break;
    117         case 'author':
    118             $args['author'] = $term;
    119             break;
    120     }
    121 
    122     $args['page'] = $page;
    123     $args['fields'] = $theme_field_defaults;
    124 
    125     if ( !empty( $_POST['features'] ) ) {
    126         $terms = $_POST['features'];
    127         $terms = array_map( 'trim', $terms );
    128         $terms = array_map( 'sanitize_title_with_dashes', $terms );
    129         $args['tag'] = $terms;
    130         $_REQUEST['s'] = implode( ',', $terms );
    131         $_REQUEST['type'] = 'tag';
    132     }
    133 
    134     $api = themes_api('query_themes', $args);
    135 
    136     if ( is_wp_error($api) )
    137         wp_die($api);
    138 
    139     add_action('install_themes_table_header', 'install_theme_search_form');
    140 
    141     display_themes($api->themes, $api->info['page'], $api->info['pages']);
    142 }
    143 
    14491/**
    14592 * Display search form for searching themes.
     
    153100<p class="install-help"><?php _e('Search for themes by keyword, author, or tag.') ?></p>
    154101
    155 <form id="search-themes" method="post" action="<?php echo admin_url( 'theme-install.php?tab=search' ); ?>">
     102<form id="search-themes" method="get" action="">
     103    <input type="hidden" name="tab" value="search" />
    156104    <select name="type" id="typeselector">
    157105    <option value="term" <?php selected('term', $type) ?>><?php _e('Term'); ?></option>
     
    165113}
    166114
    167 add_action('install_themes_dashboard', 'install_themes_dashboard');
    168115/**
    169116 * Display tags filter for themes.
     
    223170<?php
    224171}
    225 
    226 add_action('install_themes_featured', 'install_themes_featured', 10, 1);
    227 /**
    228  * Display featured themes.
    229  *
    230  * @since 2.8.0
    231  *
    232  * @param string $page
    233  */
    234 function install_themes_featured($page = 1) {
    235     global $theme_field_defaults;
    236     $args = array('browse' => 'featured', 'page' => $page, 'fields' => $theme_field_defaults);
    237     $api = themes_api('query_themes', $args);
    238     if ( is_wp_error($api) )
    239         wp_die($api);
    240     display_themes($api->themes, $api->info['page'], $api->info['pages']);
    241 }
    242 
    243 add_action('install_themes_new', 'install_themes_new', 10, 1);
    244 /**
    245  * Display new themes/
    246  *
    247  * @since 2.8.0
    248  *
    249  * @param string $page
    250  */
    251 function install_themes_new($page = 1) {
    252     global $theme_field_defaults;
    253     $args = array('browse' => 'new', 'page' => $page, 'fields' => $theme_field_defaults);
    254     $api = themes_api('query_themes', $args);
    255     if ( is_wp_error($api) )
    256         wp_die($api);
    257     display_themes($api->themes, $api->info['page'], $api->info['pages']);
    258 }
    259 
    260 add_action('install_themes_updated', 'install_themes_updated', 10, 1);
    261 /**
    262  * Display recently updated themes.
    263  *
    264  * @since 2.8.0
    265  *
    266  * @param string $page
    267  */
    268 function install_themes_updated($page = 1) {
    269     global $theme_field_defaults;
    270     $args = array('browse' => 'updated', 'page' => $page, 'fields' => $theme_field_defaults);
    271     $api = themes_api('query_themes', $args);
    272     display_themes($api->themes, $api->info['page'], $api->info['pages']);
    273 }
    274 
    275 add_action('install_themes_upload', 'install_themes_upload', 10, 1);
     172add_action('install_themes_dashboard', 'install_themes_dashboard');
     173
    276174function install_themes_upload($page = 1) {
    277175?>
     
    286184    <?php
    287185}
     186add_action('install_themes_upload', 'install_themes_upload', 10, 1);
    288187
    289188function display_theme($theme, $actions = null, $show_details = true) {
     
    361260 *
    362261 * @since 2.8.0
    363  *
    364  * @param array $themes List of themes.
    365  * @param string $page
    366  * @param int $totalpages Number of pages.
    367  */
    368 function display_themes($themes, $page = 1, $totalpages = 1) {
    369     $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
    370     $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
    371     ?>
    372 <div class="tablenav">
    373 <div class="alignleft actions"><?php do_action('install_themes_table_header'); ?></div>
    374     <?php
    375     $url = esc_url($_SERVER['REQUEST_URI']);
    376     if ( ! empty($term) )
    377         $url = add_query_arg('s', $term, $url);
    378     if ( ! empty($type) )
    379         $url = add_query_arg('type', $type, $url);
    380 
    381     $page_links = paginate_links( array(
    382             'base' => add_query_arg('paged', '%#%', $url),
    383             'format' => '',
    384             'prev_text' => __('&laquo;'),
    385             'next_text' => __('&raquo;'),
    386             'total' => $totalpages,
    387             'current' => $page
    388     ));
    389 
    390     if ( $page_links )
    391         echo "\t\t<div class='tablenav-pages'>$page_links</div>";
    392     ?>
    393 </div>
    394 <br class="clear" />
    395 <?php
    396     if ( empty($themes) ) {
    397         _e('No themes found');
    398         return;
    399     }
    400 ?>
    401 <table id="availablethemes" cellspacing="0" cellpadding="0">
    402 <?php
    403     $rows = ceil(count($themes) / 3);
    404     $table = array();
    405     $theme_keys = array_keys($themes);
    406     for ( $row = 1; $row <= $rows; $row++ )
    407         for ( $col = 1; $col <= 3; $col++ )
    408             $table[$row][$col] = array_shift($theme_keys);
    409 
    410     foreach ( $table as $row => $cols ) {
    411     ?>
    412     <tr>
    413     <?php
    414 
    415     foreach ( $cols as $col => $theme_index ) {
    416         $class = array('available-theme');
    417         if ( $row == 1 ) $class[] = 'top';
    418         if ( $col == 1 ) $class[] = 'left';
    419         if ( $row == $rows ) $class[] = 'bottom';
    420         if ( $col == 3 ) $class[] = 'right';
    421         ?>
    422         <td class="<?php echo join(' ', $class); ?>"><?php
    423             if ( isset($themes[$theme_index]) )
    424                 display_theme($themes[$theme_index]);
    425         ?></td>
    426         <?php } // end foreach $cols ?>
    427     </tr>
    428     <?php } // end foreach $table ?>
    429 </table>
    430 
    431 <div class="tablenav"><?php if ( $page_links )
    432 echo "\t\t<div class='tablenav-pages'>$page_links</div>"; ?> <br
    433     class="clear" />
    434 </div>
    435 
    436 <?php
    437 }
    438 
    439 add_action('install_themes_pre_theme-information', 'install_theme_information');
     262 */
     263function display_themes() {
     264    global $table;
     265
     266    $table->display();
     267}
     268add_action('install_themes_search', 'display_themes');
     269add_action('install_themes_featured', 'display_themes');
     270add_action('install_themes_new', 'display_themes');
     271add_action('install_themes_updated', 'display_themes');
    440272
    441273/**
     
    547379    exit;
    548380}
     381add_action('install_themes_pre_theme-information', 'install_theme_information');
     382
Note: See TracChangeset for help on using the changeset viewer.