]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/media-upload.php
Wordpress 3.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 if ( ! isset( $_GET['inline'] ) )
13         define( 'IFRAME_REQUEST' , true );
14
15 /** Load WordPress Administration Bootstrap */
16 require_once('./admin.php');
17
18 if (!current_user_can('upload_files'))
19         wp_die(__('You do not have permission to upload files.'));
20
21 wp_enqueue_script('swfupload-all');
22 wp_enqueue_script('swfupload-handlers');
23 wp_enqueue_script('image-edit');
24 wp_enqueue_script('set-post-thumbnail' );
25 wp_enqueue_style('imgareaselect');
26
27 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
28
29 // IDs should be integers
30 $ID = isset($ID) ? (int) $ID : 0;
31 $post_id = isset($post_id)? (int) $post_id : 0;
32
33 // Require an ID for the edit screen
34 if ( isset($action) && $action == 'edit' && !$ID )
35         wp_die(__("You are not allowed to be here"));
36
37 if ( isset($_GET['inline']) ) {
38         $errors = array();
39
40         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
41                 // Upload File button was clicked
42                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
43                 unset($_FILES);
44                 if ( is_wp_error($id) ) {
45                         $errors['upload_error'] = $id;
46                         $id = false;
47                 }
48         }
49
50         if ( isset($_GET['upload-page-form']) ) {
51                 $errors = array_merge($errors, (array) media_upload_form_handler());
52
53                 $location = 'upload.php';
54                 if ( $errors )
55                         $location .= '?message=3';
56
57                 wp_redirect( admin_url($location) );
58                 exit;
59         }
60
61         $title = __('Upload New Media');
62         $parent_file = 'upload.php';
63
64         add_contextual_help( $current_screen,
65 '<p>' . __('You can upload media files here without creating a post first. This allows you to upload files to use with posts and pages later and/or to get a web link for a particular file that you can share.') . '</p>' .
66                 '<p>' . __('There are two options for uploading files: <em>Select Files</em> will open the Flash-based uploader (multiple file upload allowed), or you can use the <em>Browser Uploader</em>. Clicking <em>Select Files</em> opens a navigation window showing you files in your operating system. Selecting <em>Open</em> after clicking on the file you want activates a progress bar on the uploader screen. Basic image editing is available after upload is complete. Make sure you click <em>Save</em> before leaving this screen.') . '</p>' .
67                 '<p><strong>' . __('For more information:') . '</strong></p>' .
68                 '<p>' . __('<a href="http://codex.wordpress.org/Media_Add_New_SubPanel" target="_blank">Documentation on Uploading Media Files</a>') . '</p>' .
69                 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
70         );
71
72         require_once('./admin-header.php'); ?>
73         <div class="wrap">
74         <?php screen_icon(); ?>
75         <h2><?php echo esc_html( $title ); ?></h2>
76
77         <form enctype="multipart/form-data" method="post" action="<?php echo admin_url('media-upload.php?inline=&amp;upload-page-form='); ?>" class="media-upload-form type-form validate" id="file-form">
78
79         <?php media_upload_form(); ?>
80
81         <script type="text/javascript">
82         jQuery(function($){
83                 var preloaded = $(".media-item.preloaded");
84                 if ( preloaded.length > 0 ) {
85                         preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
86                 }
87                 updateMediaForm();
88                 post_id = 0;
89                 shortform = 1;
90         });
91         </script>
92         <input type="hidden" name="post_id" id="post_id" value="0" />
93         <?php wp_nonce_field('media-form'); ?>
94         <div id="media-items" class="hide-if-no-js"> </div>
95         <?php submit_button( __( 'Save all changes' ), 'button savebutton hide-if-no-js', 'save' ); ?>
96         </form>
97         </div>
98
99 <?php
100         include('./admin-footer.php');
101
102 } else {
103
104         // upload type: image, video, file, ..?
105         if ( isset($_GET['type']) )
106                 $type = strval($_GET['type']);
107         else
108                 $type = apply_filters('media_upload_default_type', 'file');
109
110         // tab: gallery, library, or type-specific
111         if ( isset($_GET['tab']) )
112                 $tab = strval($_GET['tab']);
113         else
114                 $tab = apply_filters('media_upload_default_tab', 'type');
115
116         $body_id = 'media-upload';
117
118         // let the action code decide how to handle the request
119         if ( $tab == 'type' || $tab == 'type_url' )
120                 do_action("media_upload_$type");
121         else
122                 do_action("media_upload_$tab");
123 }
124 ?>