WordPress.org

Make WordPress Core

Ticket #5911: 5911-9.diff

File 5911-9.diff, 9.1 KB (added by andy, 10 years ago)

first pass at Media Library uploader tab

  • wp-admin/includes/media.php

     
    2929        $tabs = media_upload_tabs();
    3030
    3131        if ( !empty($tabs) ) {
    32                 echo "<ul id='media-upload-tabs'>\n";
     32                echo "<ul id='sidemenu'>\n";
    3333                if ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
    3434                        $current = $_GET['tab'];
    3535                else
    3636                        $current = array_shift(array_keys($tabs));
    3737                foreach ( $tabs as $callback => $text ) {
    38                         if ( ++$i == count($tabs) )
    39                                 $class = ' class="last"';
    40                         $href = add_query_arg('tab', $callback);
    41                         if ( $callback == $current )
    42                                 $link = $text;
    43                         else
    44                                 $link = "<a href='$href'>$text</a>";
    45                         echo "\t<li id='tab-$callback'$class>$link</li>\n";
     38                        $class = '';
     39                        if ( $current == $callback )
     40                                $class = " class='current'";
     41                        $href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false));
     42                        $link = "<a href='$href'$class>$text</a>";
     43                        echo "\t<li id='tab-$callback'>$link</li>\n";
    4644                }
    4745                echo "</ul>\n";
    4846        }
     
    261259}
    262260
    263261function media_upload_library() {
    264         if ( empty($_POST) )
    265                 wp_iframe( 'media_upload_library_form', $errors );
     262        if ( !empty($_POST) ) {
     263                $return = media_upload_form_handler();
     264       
     265                if ( is_string($return) )
     266                        return $return;
     267                if ( is_array($return) )
     268                        $errors = $return;
     269        }
     270
     271        return wp_iframe( 'media_upload_library_form', $errors );
    266272}
    267273
    268274function get_media_items( $post_id, $errors ) {
    269         if ( $post_id )
     275        if ( $post_id ) {
    270276                $attachments = get_children("post_parent=$post_id&post_type=attachment&orderby=menu_order ASC, ID&order=DESC");
    271         else
    272                 $attachments = get_paged_attachments();
     277        } else {
     278                if ( is_array($GLOBALS['wp_the_query']->posts) )
     279                        foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
     280                                $attachments[$attachment->ID] = $attachment;
     281        }
    273282
    274283        if ( empty($attachments) )
    275284                return '';
     
    707716}
    708717
    709718function media_upload_library_form($errors) {
     719        global $wpdb, $wp_query, $wp_locale;
     720
    710721        media_upload_header();
     722
     723        $post_id = intval($_REQUEST['post_id']);
     724
     725        $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=media&tab=library&post_id=$post_id";
     726
     727        $_GET['paged'] = intval($_GET['paged']);
     728        if ( $_GET['paged'] < 1 )
     729                $_GET['paged'] = 1;
     730        $start = ( $_GET['paged'] - 1 ) * 10;
     731        if ( $start < 1 )
     732                $start = 0;
     733        add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
     734
     735        list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
     736
     737?>
     738
     739<form id="filter" action="" method="get">
     740<input type="hidden" name="type" value="media" />
     741<input type="hidden" name="tab" value="library" />
     742<input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
     743<input type="hidden" name="post_mime_type" value="<?php echo $_GET['post_mime_type']; ?>" />
     744
     745<div id="search-filter">
     746        <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" />
     747        <input type="submit" value="<?php _e( 'Search Media' ); ?>" class="button" />
     748</div>
     749
     750<p>
     751<ul class="subsubsub">
     752<?php
     753$type_links = array();
     754$_num_posts = (array) wp_count_attachments();
     755$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
     756foreach ( $matches as $type => $reals )
     757        foreach ( $reals as $real )
     758                $num_posts[$type] += $_num_posts[$real];
     759foreach ( $post_mime_types as $mime_type => $label ) {
     760        $class = '';
     761
     762        if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
     763                continue;
     764
     765        if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
     766                $class = ' class="current"';
     767
     768        $type_links[] = "<li><a href='" . add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false)) . "'$class>" . sprintf($label[2], $num_posts[$mime_type]) . '</a>';
    711769}
     770$class = empty($_GET['post_mime_type']) ? ' class="current"' : '';
     771$type_links[] = "<li><a href='" . remove_query_arg(array('post_mime_type', 'paged', 'm')) . "'$class>".__('All Types')."</a>";
     772echo implode(' | </li>', $type_links) . '</li>';
     773unset($type_links);
     774?>
     775</ul>
     776</p>
    712777
     778<div class="tablenav">
     779
     780<?php
     781$page_links = paginate_links( array(
     782        'base' => add_query_arg( 'paged', '%#%' ),
     783        'format' => '',
     784        'total' => ceil($wp_query->found_posts / 10),
     785        'current' => $_GET['paged']
     786));
     787
     788if ( $page_links )
     789        echo "<div class='tablenav-pages'>$page_links</div>";
     790?>
     791
     792<div style="float: left">
     793<?php
     794
     795$arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC";
     796
     797$arc_result = $wpdb->get_results( $arc_query );
     798
     799$month_count = count($arc_result);
     800
     801if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
     802<select name='m'>
     803<option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
     804<?php
     805foreach ($arc_result as $arc_row) {
     806        if ( $arc_row->yyear == 0 )
     807                continue;
     808        $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
     809       
     810        if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
     811                $default = ' selected="selected"';
     812        else
     813                $default = '';
     814       
     815        echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>";
     816        echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
     817        echo "</option>\n";
     818}
     819?>
     820</select>
     821<?php } ?>
     822
     823<input type="submit" id="post-query-submit" value="<?php _e('Filter &#187;'); ?>" class="button-secondary" />
     824
     825</div>
     826
     827<br style="clear:both;" />
     828</div>
     829</form>
     830
     831<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="attachments-form">
     832
     833<script type="text/javascript">
     834<!--
     835jQuery(function($){
     836        var preloaded = $(".media-item.preloaded");
     837        if ( preloaded.length > 0 ) {
     838                preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
     839                updateMediaForm();
     840        }
     841});
     842-->
     843</script>
     844
     845<?php wp_nonce_field('media-form'); ?>
     846<?php //media_upload_form( $errors ); ?>
     847
     848<div id="media-items">
     849<?php echo get_media_items(null, $errors); ?>
     850</div>
     851<input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
     852</form>
     853<?php
     854}
     855
    713856add_filter('async_upload_media', 'get_media_item', 10, 2);
    714857
    715858add_filter('media_upload_computer', 'media_upload_computer');
  • wp-admin/upload.php

     
    3737
    3838require_once('admin-header.php');
    3939
    40 add_filter( 'post_limits', $limit_filter = create_function( '$a', 'if ( empty($_GET["paged"]) ) $_GET["paged"] = 1; $start = ( intval($_GET["paged"]) - 1 ) * 15; return "LIMIT $start, 20";' ) );
     40if ( isset($_GET['paged']) && $start = ( intval($_GET['paged']) - 1 ) * 15 )
     41        add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 15';" ) );
    4142list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
    4243$wp_query->max_num_pages = ceil( $wp_query->found_posts / 15 ); // We grab 20 but only show 15 ( 5 more for ajax extra )
    4344
     
    8182
    8283<ul class="subsubsub">
    8384<?php
    84 $status_links = array();
     85$type_links = array();
    8586$_num_posts = (array) wp_count_attachments();
    8687$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
    8788foreach ( $matches as $type => $reals )
     
    9697        if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
    9798                $class = ' class="current"';
    9899
    99         $status_links[] = "<li><a href=\"upload.php?post_mime_type=$mime_type\"$class>" .
     100        $type_links[] = "<li><a href=\"upload.php?post_mime_type=$mime_type\"$class>" .
    100101        sprintf($label[2], $num_posts[$mime_type]) . '</a>';
    101102}
    102103$class = empty($_GET['post_mime_type']) ? ' class="current"' : '';
    103 $status_links[] = "<li><a href=\"upload.php\"$class>".__('All Types')."</a>";
    104 echo implode(' |</li>', $status_links) . '</li>';
    105 unset($status_links);
     104$type_links[] = "<li><a href=\"upload.php\"$class>".__('All Types')."</a>";
     105echo implode(' | </li>', $type_links) . '</li>';
     106unset($type_links);
    106107?>
    107108</ul>
    108109
  • wp-admin/css/media.css

     
    11div#media-upload-header {
    2         background-color: #eaf3fa;
     2        background-color: #e4f2fd;
    33        margin: 0;
    4         padding: 1em 0.5em 0.5em 0.5em;
     4        padding: 1em 0.5em 0 0.5em;
    55        font-weight: bold;
     6        position: relative;
     7        border-bottom: 1px solid #c6d9e9;
    68}
    79
    8 ul#media-upload-tabs {
    9         display:inline;
     10ul#sidemenu {
     11        font-weight: normal;
     12        margin: 0 15px;
    1013        position: absolute;
    1114        right: 1em;
    12         top: 1em;
    13         font-size: 0.9em;
     15        bottom: -1px;
    1416}
    1517
    16 ul#media-upload-tabs li {
    17         display:inline;
    18 }
    19 
    20 ul#media-upload-tabs li:after {
    21         content: " | ";
    22 }
    23 
    24 ul#media-upload-tabs li.last:after {
    25         content: "";
    26 }
    27 
    28 
    29 
    3018div#media-upload-error {
    3119        margin: 1em;
    3220        font-weight: bold;
    3321        color: #f00;
    3422}
    3523
    36 form.media-upload-form {
     24form {
    3725        margin: 1em;
    3826}
    3927
     28#search-filter {
     29        text-align: right;
     30}
     31
    4032.media-upload-form label, .media-upload-form legend {
    4133        display:block;
    4234        font-weight: bold;