Wordpress 2.8
[autoinstalls/wordpress.git] / wp-admin / media-upload.php
1 <?php
2 /**
3  * Manage media uploaded file.
4  *
5  * There are many filters in here for media. Plugins can extend functionality
6  * by hooking into the filters.
7  *
8  * @package WordPress
9  * @subpackage Administration
10  */
11
12 /** Load WordPress Administration Bootstrap */
13 require_once('admin.php');
14
15 if (!current_user_can('upload_files'))
16         wp_die(__('You do not have permission to upload files.'));
17
18 wp_enqueue_script('swfupload-all');
19 wp_enqueue_script('swfupload-handlers');
20
21 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
22
23 // IDs should be integers
24 $ID = isset($ID) ? (int) $ID : 0;
25 $post_id = isset($post_id)? (int) $post_id : 0;
26
27 // Require an ID for the edit screen
28 if ( isset($action) && $action == 'edit' && !$ID )
29         wp_die(__("You are not allowed to be here"));
30
31 if ( isset($_GET['inline']) ) {
32
33         if ( isset($_GET['upload-page-form']) ) {
34                 $errors = media_upload_form_handler();
35
36                 $location = 'upload.php';
37                 if ( $errors )
38                         $location .= '?message=3';
39
40                 wp_redirect( admin_url($location) );
41         }
42
43         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
44                 // Upload File button was clicked
45                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
46                 unset($_FILES);
47                 if ( is_wp_error($id) ) {
48                         $errors['upload_error'] = $id;
49                         $id = false;
50                 }
51         }
52
53         $title = __('Upload New Media');
54         $parent_file = 'upload.php';
55         require_once('admin-header.php'); ?>
56         <div class="wrap">
57         <?php screen_icon(); ?>
58         <h2><?php echo esc_html( $title ); ?></h2>
59
60         <form enctype="multipart/form-data" method="post" action="media-upload.php?inline=&amp;upload-page-form=" class="media-upload-form type-form validate" id="file-form">
61
62         <?php media_upload_form(); ?>
63
64         <script type="text/javascript">
65         jQuery(function($){
66                 var preloaded = $(".media-item.preloaded");
67                 if ( preloaded.length > 0 ) {
68                         preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
69                 }
70                 updateMediaForm();
71                 post_id = 0;
72                 shortform = 1;
73         });
74         </script>
75         <input type="hidden" name="post_id" id="post_id" value="0" />
76         <?php wp_nonce_field('media-form'); ?>
77         <div id="media-items"> </div>
78         <p>
79         <input type="submit" class="button savebutton" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
80         </p>
81         </form>
82         </div>
83
84 <?php
85         include('admin-footer.php');
86
87 } else {
88
89         // upload type: image, video, file, ..?
90         if ( isset($_GET['type']) )
91                 $type = strval($_GET['type']);
92         else
93                 $type = apply_filters('media_upload_default_type', 'file');
94
95         // tab: gallery, library, or type-specific
96         if ( isset($_GET['tab']) )
97                 $tab = strval($_GET['tab']);
98         else
99                 $tab = apply_filters('media_upload_default_tab', 'type');
100
101         $body_id = 'media-upload';
102
103         // let the action code decide how to handle the request
104         if ( $tab == 'type' || $tab == 'type_url' )
105                 do_action("media_upload_$type");
106         else
107                 do_action("media_upload_$tab");
108 }
109 ?>