Wordpress 2.7.1-scripts
[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');
19 wp_enqueue_script('swfupload-swfobject');
20 wp_enqueue_script('swfupload-queue');
21 wp_enqueue_script('swfupload-handlers');
22
23 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
24
25 // IDs should be integers
26 $ID = isset($ID) ? (int) $ID : 0;
27 $post_id = isset($post_id)? (int) $post_id : 0;
28
29 // Require an ID for the edit screen
30 if ( isset($action) && $action == 'edit' && !$ID )
31         wp_die(__("You are not allowed to be here"));
32
33 if ( isset($_GET['inline']) ) {
34
35         if ( isset($_GET['upload-page-form']) ) {
36                 $errors = media_upload_form_handler();
37
38                 $location = 'upload.php';
39                 if ( $errors )
40                         $location .= '?message=3';
41
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         }
54
55         $title = __('Upload New Media');
56         $parent_file = 'upload.php';
57         require_once('admin-header.php'); ?>
58         <div class="wrap">
59         <?php screen_icon(); ?>
60         <h2><?php echo wp_specialchars( $title ); ?></h2>
61
62         <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">
63
64         <?php media_upload_form(); ?>
65
66         <script type="text/javascript">
67         jQuery(function($){
68                 var preloaded = $(".media-item.preloaded");
69                 if ( preloaded.length > 0 ) {
70                         preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
71                 }
72                 updateMediaForm();
73                 post_id = 0;
74                 shortform = 1;
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' || $tab == 'type_url' )
107                 do_action("media_upload_$type");
108         else
109                 do_action("media_upload_$tab");
110 }
111 ?>