WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/27/2008 08:31:10 AM (12 years ago)
Author:
ryan
Message:

Add media library uploader tab. Props andy. see #5911

File:
1 edited

Legend:

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

    r7043 r7062  
    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'];
     
    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";
     
    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) )
     
    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>';
     769}
     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>
     777
     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
    711854}
    712855
Note: See TracChangeset for help on using the changeset viewer.