WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/28/2008 09:29:51 PM (12 years ago)
Author:
ryan
Message:

Media library updates from andy. see #5911

File:
1 edited

Legend:

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

    r7067 r7092  
    33function media_upload_tabs() {
    44    $_default_tabs = array(
    5         'computer' => __('From Computer'), // handler action suffix => tab text
    6         'attachments' => __('Attachments'),
     5        'type' => __('Choose File'), // handler action suffix => tab text
     6        'gallery' => __('Gallery'),
    77        'library' => __('Media Library'),
    88    );
     
    1111}
    1212
    13 function update_attachments_tab($tabs) {
     13function update_gallery_tab($tabs) {
    1414    global $wpdb;
    1515    if ( !isset($_REQUEST['post_id']) ) {
    16         unset($tabs['attachments']);
     16        unset($tabs['gallery']);
    1717        return $tabs;
    1818    }
    1919    if ( intval($_REQUEST['post_id']) )
    20         $attachments = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id']));
    21 
    22     $tabs['attachments'] = sprintf(__('Attachments (%s)'), "<span id='attachments-count'>$attachments</span>");
     20        $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id'])));
     21
     22    $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
    2323
    2424    return $tabs;
    2525}
    26 add_filter('media_upload_tabs', 'update_attachments_tab');
     26add_filter('media_upload_tabs', 'update_gallery_tab');
    2727
    2828function the_media_upload_tabs() {
     
    5656    elseif ( $size == 'thumb' || $size == 'medium' )
    5757        $html = '<a href="'.get_attachment_link($id).'"'.$rel.'>'.$html.'</a>';
    58        
     58
    5959    $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url );
    6060
     
    155155    global $post_ID, $temp_ID;
    156156    $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
    157     $media_upload_iframe_src = "media-upload.php?type=media&amp;post_id=$uploading_iframe_ID";
    158     $media_upload_iframe_src = apply_filters('media_upload_iframe_src', $media_upload_iframe_src);
    159     echo "<a href='$media_upload_iframe_src&amp;TB_iframe=true&amp;height=500&amp;width=640' class='button-secondary thickbox'>" . __('Add media'). '</a>';
     157    $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
     158    $media_title = __('Add Media');
     159    $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&amp;type=image");
     160    $image_title = __('Add an Image');
     161    $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&amp;type=video");
     162    $video_title = __('Add Video');
     163    $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&amp;type=audio");
     164    $audio_title = __('Add Audio');
     165    $out = <<<EOF
     166
     167    <a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox" title='$image_title'><img src='images/media-button-image.gif' alt='$image_title' /></a>
     168    <a href="{$video_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox" title='$video_title'><img src='images/media-button-video.gif' alt='$video_title' /></a>
     169    <a href="{$audio_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox" title='$audio_title'><img src='images/media-button-music.gif' alt='$audio_title' /></a>
     170    <a href="{$media_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox" title='$media_title'><img src='images/media-button-other.gif' alt='$media_title' /></a>
     171
     172EOF;
     173    echo $out;
    160174}
    161175add_action( 'media_buttons', 'media_buttons' );
     
    192206        $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
    193207
    194         if ( is_wp_error($id) )
     208        if ( is_wp_error($id) ) {
    195209            $errors['upload_error'] = $id;
     210            $id = false;
     211        }
    196212    }
    197213
     
    233249}
    234250
    235 function media_upload_computer() {
     251function media_upload_image() {
     252    if ( !empty($_FILES) ) {
     253        // Upload File button was clicked
     254        $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
     255        unset($_FILES);
     256        if ( is_wp_error($id) ) {
     257            $errors['upload_error'] = $id;
     258            $id = false;
     259        }
     260    }
     261
     262    if ( !empty($_POST['insertonlybutton']) ) {
     263        $src = $_POST['insertonly']['src'];
     264        if ( !strpos($src, '://') )
     265            $src = "http://$src";
     266        $alt = attribute_escape($_POST['insertonly']['alt']);
     267        if ( isset($_POST['insertonly']['align']) ) {
     268            $align = attribute_escape($_POST['insertonly']['align']);
     269            $class = " class='align-$align'";
     270        }
     271        $html = "<img src='$src' alt='$alt'$class />";
     272        return media_send_to_editor($html);
     273    }
     274
     275    if ( !empty($_POST) ) {
     276        $return = media_upload_form_handler();
     277
     278        if ( is_string($return) )
     279            return $return;
     280        if ( is_array($return) )
     281            $errors = $return;
     282    }
     283
     284    return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
     285}
     286
     287function media_upload_audio() {
     288    if ( !empty($_FILES) ) {
     289        // Upload File button was clicked
     290        $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
     291        unset($_FILES);
     292        if ( is_wp_error($id) ) {
     293            $errors['upload_error'] = $id;
     294            $id = false;
     295        }
     296    }
     297
     298    if ( !empty($_POST['insertonlybutton']) ) {
     299        $href = $_POST['insertonly']['href'];
     300        if ( !strpos($href, '://') )
     301            $href = "http://$href";
     302        $title = attribute_escape($_POST['insertonly']['title']);
     303        $html = "<a href='$href' >$title</a>";
     304        return media_send_to_editor($html);
     305    }
     306
     307    if ( !empty($_POST) ) {
     308        $return = media_upload_form_handler();
     309
     310        if ( is_string($return) )
     311            return $return;
     312        if ( is_array($return) )
     313            $errors = $return;
     314    }
     315
     316    return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
     317}
     318
     319function media_upload_video() {
     320    if ( !empty($_FILES) ) {
     321        // Upload File button was clicked
     322        $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
     323        unset($_FILES);
     324        if ( is_wp_error($id) ) {
     325            $errors['upload_error'] = $id;
     326            $id = false;
     327        }
     328    }
     329
     330    if ( !empty($_POST['insertonlybutton']) ) {
     331        $href = $_POST['insertonly']['href'];
     332        if ( !strpos($href, '://') )
     333            $href = "http://$href";
     334        $title = attribute_escape($_POST['insertonly']['title']);
     335        $html = "<a href='$href' >$title</a>";
     336        return media_send_to_editor($html);
     337    }
     338
     339    if ( !empty($_POST) ) {
     340        $return = media_upload_form_handler();
     341
     342        if ( is_string($return) )
     343            return $return;
     344        if ( is_array($return) )
     345            $errors = $return;
     346    }
     347
     348    return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
     349}
     350
     351function media_upload_file() {
     352    if ( !empty($_FILES) ) {
     353        // Upload File button was clicked
     354        $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
     355        unset($_FILES);
     356        if ( is_wp_error($id) ) {
     357            $errors['upload_error'] = $id;
     358            $id = false;
     359        }
     360    }
     361
     362    if ( !empty($_POST['insertonlybutton']) ) {
     363        $href = $_POST['insertonly']['href'];
     364        if ( !strpos($href, '://') )
     365            $href = "http://$href";
     366        $title = attribute_escape($_POST['insertonly']['title']);
     367        $html = "<a href='$href' >$title</a>";
     368        return media_send_to_editor($html);
     369    }
     370
     371    if ( !empty($_POST) ) {
     372        $return = media_upload_form_handler();
     373
     374        if ( is_string($return) )
     375            return $return;
     376        if ( is_array($return) )
     377            $errors = $return;
     378    }
     379
     380    return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
     381}
     382
     383function media_upload_gallery() {
    236384    if ( !empty($_POST) ) {
    237385        $return = media_upload_form_handler();
     
    243391    }
    244392
    245     return wp_iframe( 'media_upload_computer_form', $errors );
    246 }
    247 
    248 function media_upload_attachments() {
    249     if ( !empty($_POST) ) {
    250         $return = media_upload_form_handler();
    251    
    252         if ( is_string($return) )
    253             return $return;
    254         if ( is_array($return) )
    255             $errors = $return;
    256     }
    257 
    258     return wp_iframe( 'media_upload_attachments_form', $errors );
     393    return wp_iframe( 'media_upload_gallery_form', $errors );
    259394}
    260395
     
    272407}
    273408
    274 function get_media_items( $post_id, $errors ) {
    275     if ( $post_id ) {
    276         $attachments = get_children("post_parent=$post_id&post_type=attachment&orderby=menu_order ASC, ID&order=DESC");
    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     }
    282 
    283     if ( empty($attachments) )
    284         return '';
    285 
    286     foreach ( $attachments as $id => $attachment )
    287         if ( $item = get_media_item($id, isset($errors[$id]) ? $errors[$id] : null) )
    288             $output .= "\n<div id='media-item-$id' class='media-item preloaded'><div id='media-upload-error-$id'></div><span class='filename'></span><div class='progress'><div class='bar'></div></div>$item<div class='progress clickmask'></div>\n</div>";
    289 
    290     return $output;
    291 }
    292 
    293409function get_attachment_taxonomies($attachment) {
    294410    if ( is_int( $attachment ) )
     
    332448        $thumb = wp_get_attachment_thumb_url();
    333449
    334         $form_fields['_send']['url'] = array(
    335             'label' => __('Link URL'),
    336             'input' => 'html',
    337             'html'  => '',
    338             'helps'  => __('If filled, this will override the default link URL.'),
    339         );
    340         $form_fields['_send']['align'] = array(
     450        $form_fields['align'] = array(
    341451            'label' => __('Alignment'),
    342452            'input' => 'html',
     
    351461                <label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n",
    352462        );
    353         $form_fields['_send']['image-size'] = array(
     463        $form_fields['image-size'] = array(
    354464            'label' => __('Size'),
    355465            'input' => 'html',
     
    384494    $post =& get_post($attachment_id);
    385495    if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
    386         if ( !empty($attachment['url']) )
    387             $url = $attachment['url'];
    388         elseif ( $rel = strlen(trim($post->post_content)) )
    389             $url = get_attachment_link($attachment_id);
    390         else
    391             $url = wp_get_attachment_url($attachment_id);
     496        $url = $attachment['url'];
    392497
    393498        if ( isset($attachment['align']) )
     
    416521
    417522    $edit_post = sanitize_post($post, 'edit');
     523    $file = wp_get_attachment_url($post->ID);
     524    $link = get_attachment_link($post->ID);
    418525
    419526    $form_fields = array(
     
    421528            'label'      => __('Title'),
    422529            'value'      => $edit_post->post_title,
     530            'helps'      => __(''),
    423531        ),
    424532        'post_excerpt' => array(
     
    430538            'value'      => $edit_post->post_content,
    431539            'input'      => 'textarea',
    432             'helps'      => array(__('If filled, the default link URL will be the attachment permalink.')),
     540        ),
     541        'url'          => array(
     542            'label'      => __('Link URL'),
     543            'input'      => 'html',
     544            'html'       => "
     545                <input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($file) . "' />
     546                <button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
     547                <button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
     548                <button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
     549                <script type='text/javascript'>
     550                jQuery('button.url-$post->ID').bind('click', function(){jQuery(this).siblings('input').val(this.value);});
     551                </script>\n",
     552            'helps'      => __('Enter a link URL or click above for presets.'),
    433553        ),
    434554    );
     
    463583}
    464584
    465 function get_media_item( $attachment_id, $errors = null, $send = true ) {
     585function get_media_items( $post_id, $errors ) {
     586    if ( $post_id && $post = get_post($post_id) ) {
     587        if ( $post->post_type == 'attachment' )
     588            $attachments = array($post->ID => $post);
     589        else
     590            $attachments = get_children("post_parent=$post_id&post_type=attachment&orderby=menu_order ASC, ID&order=DESC");
     591    } else {
     592        if ( is_array($GLOBALS['wp_the_query']->posts) )
     593            foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
     594                $attachments[$attachment->ID] = $attachment;
     595    }
     596
     597    if ( empty($attachments) )
     598        return '';
     599
     600    foreach ( $attachments as $id => $attachment )
     601        if ( $item = get_media_item($id, isset($errors[$id]) ? $errors[$id] : null) )
     602            $output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div id='media-upload-error-$id'></div><span class='filename'></span><div class='progress'><div class='bar'></div></div>$item<div class='progress clickmask'></div>\n</div>";
     603
     604    return $output;
     605}
     606
     607function get_media_item( $attachment_id, $errors = null, $send = true, $delete = true ) {
     608    global $post_mime_types;
    466609    if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
    467610        $thumb_url = $thumb_url[0];
     
    487630    }
    488631
     632    if ( isset($post_mime_types) ) {
     633        $type = array_shift(array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type)));
     634        $type = "<input type='hidden' id='type-of-$attachment_id' value='$type' />";
     635    }
     636
    489637    $form_fields = get_attachment_fields_to_edit($post, $errors);
    490638
    491639    $class = empty($errors) ? 'startclosed' : 'startopen';
    492640    $item = "
     641    $type
    493642    <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
    494643    <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>
     
    511660
    512661    $delete_href = wp_nonce_url("post.php?action=delete-post&amp;post=$attachment_id", 'delete-post_' . $attachment_id);
    513     $delete = __('Delete');
    514     $save = "<input type='submit' value='" . wp_specialchars(__('Save'), 1) . "' />";
    515     $send = "<input type='submit' value='" . wp_specialchars(__('Send to Editor'), 1) . "' id='send[$attachment_id]' name='send[$attachment_id]' />";
    516 
    517     if ( empty($form_fields['save']) && empty($form_fields['_send']) ) {
    518         $form_fields['save'] = array('tr' => "\t\t<tr class='submit'><td colspan='2' class='del'><a id='del[$attachment_id]' class='delete button' href='$delete_href'>$delete</a></td><td class='savesend'>$save$send</td></tr>\n");
    519     } elseif ( empty($form_fields['save']) ) {
    520         $form_fields['save'] = array('tr' => "\t\t<tr class='submit'><td></td><td></td><td class='savesend'>$save</td></tr>\n");
    521         foreach ( $form_fields['_send'] as $id => $field )
    522             $form_fields[$id] = $field;
    523         $form_fields['send'] = array('tr' => "\t\t<tr class='submit'><td colspan='2' class='del'><a id='del[$attachment_id]' class='delete button' href='$delete_href'>$delete</a></td><td class='savesend'>$send</td>");
    524     }
     662    if ( $send )
     663        $send = "<button type='submit' class='button' value='1' name='send[$attachment_id]'>" . __('Insert into Post') . '</button>';
     664    if ( $delete )
     665        $delete = "<a href='$delete_href' id='del[$attachment_id]' disabled='disabled' class='delete'>" . __('Delete') . "</button>";
     666    if ( ( $send || $delete ) && !isset($form_fields['buttons']) )
     667        $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td colspan='2'></td><td class='savesend'>$send $delete</td></tr>\n");
    525668
    526669    $hidden_fields = array();
     
    584727}
    585728
    586 function media_upload_header() {
     729function media_upload_header($title = false) {
     730    if ( empty($title) )
     731        $title = __('Choose a File');
    587732    ?>
     733    <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
    588734    <div id="media-upload-header">
    589     <h3><?php _e('Add Media'); ?></h3>
     735    <h3><?php echo $title ?></h3>
    590736    <?php the_media_upload_tabs(); ?>
    591737    </div>
     
    594740
    595741function media_upload_form( $errors = null ) {
    596     $flash_action_url = get_option('siteurl') . '/wp-admin/async-upload.php?type=media';
     742    global $type, $tab;
     743
     744    $flash_action_url = get_option('siteurl') . "/wp-admin/async-upload.php";
    597745
    598746    $post_id = intval($_REQUEST['post_id']);
    599747
    600748?>
     749<input type='hidden' name='post_id' value='<?php echo $post_id; ?>' />
    601750<div id="media-upload-error">
    602751<?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>
     
    615764                "post_id" : "<?php echo $post_id; ?>",
    616765                "auth_cookie" : "<?php echo $_COOKIE[AUTH_COOKIE]; ?>",
    617                 "type" : "media"
     766                "type" : "<?php echo $type; ?>",
     767                "tab" : "<?php echo $tab; ?>"
    618768            },
    619769            file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
     
    641791<div id="flash-upload-ui">
    642792    <p><input id="flash-browse-button" type="button" value="<?php _e('Choose files to upload'); ?>" class="button" /></p>
    643     <p><?php _e('After a file has been uploaded, you can add titles and descriptions below.'); ?></p>
     793    <p><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
    644794</div>
    645795
    646796<div id="html-upload-ui">
    647     <p><label for="async-upload"><?php _e('Choose image'); ?></label>
    648     <input type="file" name="async-upload" id="async-upload" />
    649     <label for="image-file" class="form-help"><?php _e('Only PNG, JPG, GIF'); ?></label>
    650     </p>
    651797    <p>
    652     <button id="upload-button" name="upload-button" value="1" class="button-ok"><?php _e('Add Image'); ?></button>
    653     <a href="#" onClick="return top.tb_remove();" id="image-cancel" class="button-cancel"><?php _e('Cancel'); ?></a>
     798    <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" value="<?php echo attribute_escape(__('Upload')); ?>" /> <a href="#" onClick="return top.tb_remove();"><?php _e('Cancel'); ?></a>
    654799    </p>
    655800    <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
     
    659804}
    660805
    661 function media_upload_computer_form( $errors = null ) {
     806function media_upload_type_form($type = 'file', $errors = null, $id = null) {
    662807    media_upload_header();
    663808
    664809    $post_id = intval($_REQUEST['post_id']);
    665810
    666     $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=media&tab=computer&post_id=$post_id";
    667 
     811    $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=$type&tab=type&post_id=$post_id";
     812
     813    $callback = "type_form_$type";
    668814?>
    669815
    670 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="computer-form">
     816<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form type-form" id="<?php echo $type; ?>-form">
     817<input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
    671818<?php wp_nonce_field('media-form'); ?>
     819<h3><?php _e('From Computer'); ?></h3>
    672820<?php media_upload_form( $errors ); ?>
    673821
    674 <div id="media-items"></div>
    675 <p class="submit">
    676     <input type="submit" class="submit insert-gallery" name="insert-media" value="<?php _e('Insert gallery into post'); ?>" />
    677 </p>
    678 </form>
    679 
    680 <?php
    681 }
    682 
    683 function media_upload_attachments_form($errors) {
    684     media_upload_header();
    685 
    686     $post_id = intval($_REQUEST['post_id']);
    687 
    688     $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=media&tab=attachments&post_id=$post_id";
    689 
    690 ?>
    691 
     822<?php if ( $id && !is_wp_error($id) ) : ?>
    692823<script type="text/javascript">
    693824<!--
     
    701832-->
    702833</script>
    703 
    704 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="attachments-form">
     834<div id="media-items">
     835<?php echo get_media_items( $id, $errors ); ?>
     836</div>
     837
     838<?php elseif ( is_callable($callback) ) : ?>
     839
     840<div class="media-blank">
     841<p style="text-align:center"><?php _e('&mdash; OR &mdash;'); ?></p>
     842<h3><?php _e('From URL'); ?></h3>
     843</div>
     844
     845<div id="media-items">
     846<div class="media-item media-blank">
     847<?php echo call_user_func($callback); ?>
     848</div>
     849</div>
     850<?php
     851    endif;
     852}
     853
     854function media_upload_gallery_form($errors) {
     855    media_upload_header(__('Browse attached files'));
     856
     857    $post_id = intval($_REQUEST['post_id']);
     858
     859    $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=media&tab=gallery&post_id=$post_id";
     860
     861?>
     862
     863<script type="text/javascript">
     864<!--
     865jQuery(function($){
     866    var preloaded = $(".media-item.preloaded");
     867    if ( preloaded.length > 0 ) {
     868        preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
     869        updateMediaForm();
     870    }
     871});
     872-->
     873</script>
     874
     875<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="gallery-form">
    705876<?php wp_nonce_field('media-form'); ?>
    706877<?php //media_upload_form( $errors ); ?>
     
    718889
    719890function media_upload_library_form($errors) {
    720     global $wpdb, $wp_query, $wp_locale;
    721 
    722     media_upload_header();
     891    global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
     892
     893    media_upload_header(__('Browse Media Library'));
    723894
    724895    $post_id = intval($_REQUEST['post_id']);
    725896
    726     $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=media&tab=library&post_id=$post_id";
     897    $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php";
    727898
    728899    $_GET['paged'] = intval($_GET['paged']);
     
    739910
    740911<form id="filter" action="" method="get">
    741 <input type="hidden" name="type" value="media" />
    742 <input type="hidden" name="tab" value="library" />
     912<input type="hidden" name="type" value="<?php echo $type; ?>" />
     913<input type="hidden" name="tab" value="<?php echo $tab; ?>" />
    743914<input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
    744 <input type="hidden" name="post_mime_type" value="<?php echo $_GET['post_mime_type']; ?>" />
     915<input type="hidden" name="post_mime_type" value="<?php echo wp_specialchars($_GET['post_mime_type'], true); ?>" />
    745916
    746917<div id="search-filter">
     
    767938        $class = ' class="current"';
    768939
    769     $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>';
     940    $type_links[] = "<li><a href='" . add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false)) . "'$class>" . sprintf($label[2], "<span id='$mime_type-counter'>{$num_posts[$mime_type]}</span>") . '</a>';
    770941}
    771942$class = empty($_GET['post_mime_type']) ? ' class="current"' : '';
     
    808979        continue;
    809980    $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
    810    
     981
    811982    if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
    812983        $default = ' selected="selected"';
    813984    else
    814985        $default = '';
    815    
     986
    816987    echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>";
    817988    echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
     
    8301001</form>
    8311002
    832 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="attachments-form">
     1003<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="library-form">
     1004
     1005<?php wp_nonce_field('media-form'); ?>
     1006<?php //media_upload_form( $errors ); ?>
    8331007
    8341008<script type="text/javascript">
     
    8441018</script>
    8451019
    846 <?php wp_nonce_field('media-form'); ?>
    847 <?php //media_upload_form( $errors ); ?>
    848 
    8491020<div id="media-items">
    8501021<?php echo get_media_items(null, $errors); ?>
     
    8551026}
    8561027
    857 add_filter('async_upload_media', 'get_media_item', 10, 2);
    858 
    859 add_filter('media_upload_computer', 'media_upload_computer');
    860 add_action('admin_head_media_upload_computer_form', 'media_admin_css');
    861 
    862 add_filter('media_upload_attachments', 'media_upload_attachments');
    863 add_action('admin_head_media_upload_attachments_form', 'media_admin_css');
     1028function type_form_image() {
     1029    return '
     1030    <table class="describe"><tbody>
     1031        <tr>
     1032            <td class="label"><label for="insertonly[src]">' . __('Image URL') . '</label></td>
     1033            <td class="required"><abbr title="required">*</abbr></td>
     1034            <td class="field"><input id="insertonly[src]" name="insertonly[src]" value="" type="text"></td>
     1035        </tr>
     1036        <tr>
     1037            <td class="label"><label for="insertonly[alt]">' . __('Description') . '</label></td>
     1038            <td class="required"><abbr title="required">*</abbr></td>
     1039            <td class="field"><input id="insertonly[alt]" name="insertonly[alt]" value="" type="text"></td>
     1040        </tr>
     1041        <tr><td colspan="2"></td><td class="help">' . __('Alternate text, e.g. "The Mona Lisa"') . '</td></tr>
     1042        <tr class="align">
     1043            <td class="label"><label for="insertonly[align]">' . __('Alignment') . '</label></td>
     1044            <td class="required"></td>
     1045            <td class="field">
     1046                <input name="insertonly[align]" id="image-align-none-0" value="none" type="radio">
     1047                <label for="image-align-none-0" class="align image-align-none-label">' . __('None') . '</label>
     1048                <input name="insertonly[align]" id="image-align-left-0" value="left" type="radio">
     1049                <label for="image-align-left-0" class="align image-align-left-label">' . __('Left') . '</label>
     1050                <input name="insertonly[align]" id="image-align-center-0" value="center" type="radio">
     1051                <label for="image-align-center-0" class="align image-align-center-label">' . __('Center') . '</label>
     1052                <input name="insertonly[align]" id="image-align-right-0" value="right" type="radio">
     1053                <label for="image-align-right-0" class="align image-align-right-label">' . __('Right') . '</label>
     1054            </td>
     1055        </tr>
     1056        <tr>
     1057            <td colspan="2"></td>
     1058            <td>
     1059                <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
     1060            </td>
     1061        </tr>
     1062    </tbody></table>
     1063';
     1064}
     1065
     1066function type_form_audio() {
     1067    return '
     1068    <table class="describe"><tbody>
     1069        <tr>
     1070            <td class="label"><label for="insertonly[href]">' . __('Audio File URL') . '</label></td>
     1071            <td class="required"><abbr title="required">*</abbr></td>
     1072            <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text"></td>
     1073        </tr>
     1074        <tr>
     1075            <td class="label"><label for="insertonly[title]">' . __('Title') . '</label></td>
     1076            <td class="required"><abbr title="required">*</abbr></td>
     1077            <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text"></td>
     1078        </tr>
     1079        <tr><td colspan="2"></td><td class="help">' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '</td></tr>
     1080        <tr>
     1081            <td colspan="2"></td>
     1082            <td>
     1083                <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
     1084            </td>
     1085        </tr>
     1086    </tbody></table>
     1087';
     1088}
     1089
     1090function type_form_video() {
     1091    return '
     1092    <table class="describe"><tbody>
     1093        <tr>
     1094            <td class="label"><label for="insertonly[href]">' . __('Video URL') . '</label></td>
     1095            <td class="required"><abbr title="required">*</abbr></td>
     1096            <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text"></td>
     1097        </tr>
     1098        <tr>
     1099            <td class="label"><label for="insertonly[title]">' . __('Title') . '</label></td>
     1100            <td class="required"><abbr title="required">*</abbr></td>
     1101            <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text"></td>
     1102        </tr>
     1103        <tr><td colspan="2"></td><td class="help">' . __('Link text, e.g. "Lucy on YouTube"') . '</td></tr>
     1104        <tr>
     1105            <td colspan="2"></td>
     1106            <td>
     1107                <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
     1108            </td>
     1109        </tr>
     1110    </tbody></table>
     1111';
     1112}
     1113
     1114function type_form_file() {
     1115    return '
     1116    <table class="describe"><tbody>
     1117        <tr>
     1118            <td class="label"><label for="insertonly[href]">' . __('URL') . '</label></td>
     1119            <td class="required"><abbr title="required">*</abbr></td>
     1120            <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text"></td>
     1121        </tr>
     1122        <tr>
     1123            <td class="label"><label for="insertonly[title]">' . __('Title') . '</label></td>
     1124            <td class="required"><abbr title="required">*</abbr></td>
     1125            <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text"></td>
     1126        </tr>
     1127        <tr><td colspan="2"></td><td class="help">' . __('Link text, e.g. "Ransom Demands (PDF)"') . '</td></tr>
     1128        <tr>
     1129            <td colspan="2"></td>
     1130            <td>
     1131                <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
     1132            </td>
     1133        </tr>
     1134    </tbody></table>
     1135';
     1136}
     1137
     1138add_filter('async_upload_image', 'get_media_item', 10, 2);
     1139add_filter('async_upload_audio', 'get_media_item', 10, 2);
     1140add_filter('async_upload_video', 'get_media_item', 10, 2);
     1141add_filter('async_upload_file', 'get_media_item', 10, 2);
     1142
     1143add_action('media_upload_image', 'media_upload_image');
     1144add_action('media_upload_audio', 'media_upload_audio');
     1145add_action('media_upload_video', 'media_upload_video');
     1146add_action('media_upload_file', 'media_upload_file');
     1147add_action('admin_head_media_upload_type_form', 'media_admin_css');
     1148
     1149add_filter('media_upload_gallery', 'media_upload_gallery');
     1150add_action('admin_head_media_upload_gallery_form', 'media_admin_css');
    8641151
    8651152add_filter('media_upload_library', 'media_upload_library');
Note: See TracChangeset for help on using the changeset viewer.