Make WordPress Core


Ignore:
Timestamp:
09/27/2008 08:17:55 AM (18 years ago)
Author:
azaozz
Message:

Upload media from the Media Library page.

File:
1 edited

Legend:

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

    r8645 r8998  
    1212/** Load WordPress Administration Bootstrap */
    1313require_once('admin.php');
     14
     15if (!current_user_can('upload_files'))
     16        wp_die(__('You do not have permission to upload files.'));
     17
    1418wp_enqueue_script('swfupload');
    1519wp_enqueue_script('swfupload-degrade');
     
    1822
    1923@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
    20 
    21 if (!current_user_can('upload_files'))
    22         wp_die(__('You do not have permission to upload files.'));
    2324
    2425// IDs should be integers
     
    3031        wp_die(__("You are not allowed to be here"));
    3132
    32 // upload type: image, video, file, ..?
    33 if ( isset($_GET['type']) )
    34         $type = strval($_GET['type']);
    35 else
    36         $type = apply_filters('media_upload_default_type', 'file');
     33if ( isset($_GET['inline']) ) {
     34       
     35        if ( isset($_GET['upload-page-form']) ) {
     36                $errors = media_upload_form_handler();
    3737
    38 // tab: gallery, library, or type-specific
    39 if ( isset($_GET['tab']) )
    40         $tab = strval($_GET['tab']);
    41 else
    42         $tab = apply_filters('media_upload_default_tab', 'type');
     38                $location = 'upload.php';
     39                if ( $errors )
     40                        $location .= '?message=3';
    4341
    44 $body_id = 'media-upload';
     42                wp_redirect( admin_url($location) );
     43        }
     44       
     45        if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
     46                // Upload File button was clicked
     47                $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
     48                unset($_FILES);
     49                if ( is_wp_error($id) ) {
     50                        $errors['upload_error'] = $id;
     51                        $id = false;
     52                }
     53        }
    4554
    46 // let the action code decide how to handle the request
    47 if ( $tab == 'type' )
    48         do_action("media_upload_$type");
    49 else
    50         do_action("media_upload_$tab");
     55        $title = __('Upload Media');
     56        $parent_file = 'edit.php';
     57        require_once('admin-header.php'); ?>
     58        <div class="wrap">
     59        <h2><?php _e('Upload Media') ?></h2>
    5160
     61        <form enctype="multipart/form-data" method="post" action="media-upload.php?inline=&upload-page-form=" class="media-upload-form type-form validate" id="file-form">
     62       
     63        <?php media_upload_form(); ?>
     64       
     65        <script type="text/javascript">
     66        jQuery(function($){
     67                var preloaded = $(".media-item.preloaded");
     68                if ( preloaded.length > 0 ) {
     69                        preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
     70                }
     71                updateMediaForm();
     72                post_id = 0;
     73                shortform = 1;
     74                $('body:last div:has(embed), body:last div:has(object)').css({'visibility':'hidden','marginTop':'-1px'});
     75        });
     76        </script>
     77        <input type="hidden" name="post_id" id="post_id" value="0" />
     78        <?php wp_nonce_field('media-form'); ?>
     79        <div id="media-items"> </div>
     80        <p>
     81        <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
     82        </p>
     83        </form>
     84        </div>
     85
     86<?php
     87        include('admin-footer.php');
     88
     89} else {
     90
     91        // upload type: image, video, file, ..?
     92        if ( isset($_GET['type']) )
     93                $type = strval($_GET['type']);
     94        else
     95                $type = apply_filters('media_upload_default_type', 'file');
     96       
     97        // tab: gallery, library, or type-specific
     98        if ( isset($_GET['tab']) )
     99                $tab = strval($_GET['tab']);
     100        else
     101                $tab = apply_filters('media_upload_default_tab', 'type');
     102       
     103        $body_id = 'media-upload';
     104       
     105        // let the action code decide how to handle the request
     106        if ( $tab == 'type' )
     107                do_action("media_upload_$type");
     108        else
     109                do_action("media_upload_$tab");
     110}
    52111?>
Note: See TracChangeset for help on using the changeset viewer.