]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/media-upload.php
Wordpress 3.0.6
[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 wp_enqueue_script('image-edit');
21 wp_enqueue_script('set-post-thumbnail' );
22 wp_enqueue_style('imgareaselect');
23
24 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
25
26 // IDs should be integers
27 $ID = isset($ID) ? (int) $ID : 0;
28 $post_id = isset($post_id)? (int) $post_id : 0;
29
30 // Require an ID for the edit screen
31 if ( isset($action) && $action == 'edit' && !$ID )
32         wp_die(__("You are not allowed to be here"));
33
34 if ( isset($_GET['inline']) ) {
35         $errors = array();
36
37         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
38                 check_admin_referer('media-form');
39                 // Upload File button was clicked
40                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
41                 unset($_FILES);
42                 if ( is_wp_error($id) ) {
43                         $errors['upload_error'] = $id;
44                         $id = false;
45                 }
46         }
47
48         if ( isset($_GET['upload-page-form']) ) {
49                 $errors = array_merge($errors, (array) media_upload_form_handler());
50
51                 $location = 'upload.php';
52                 if ( $errors )
53                         $location .= '?message=3';
54
55                 wp_redirect( admin_url($location) );
56         }
57
58         $title = __('Upload New Media');
59         $parent_file = 'upload.php';
60
61         add_contextual_help( $current_screen,
62 '<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>' .
63                 '<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>' .
64                 '<p><strong>' . __('For more information:') . '</strong></p>' .
65                 '<p>' . __('<a href="http://codex.wordpress.org/Media_Add_New_SubPanel" target="_blank">Documentation on Uploading Media Files</a>') . '</p>' .
66                 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
67         );
68
69         require_once('./admin-header.php'); ?>
70         <div class="wrap">
71         <?php screen_icon(); ?>
72         <h2><?php echo esc_html( $title ); ?></h2>
73
74         <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">
75
76         <?php media_upload_form(); ?>
77
78         <script type="text/javascript">
79         jQuery(function($){
80                 var preloaded = $(".media-item.preloaded");
81                 if ( preloaded.length > 0 ) {
82                         preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
83                 }
84                 updateMediaForm();
85                 post_id = 0;
86                 shortform = 1;
87         });
88         </script>
89         <input type="hidden" name="post_id" id="post_id" value="0" />
90         <?php wp_nonce_field('media-form'); ?>
91         <div id="media-items" class="hide-if-no-js"> </div>
92         <p>
93         <input type="submit" class="button savebutton hide-if-no-js" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
94         </p>
95         </form>
96         </div>
97
98 <?php
99         include('./admin-footer.php');
100
101 } else {
102
103         // upload type: image, video, file, ..?
104         if ( isset($_GET['type']) )
105                 $type = strval($_GET['type']);
106         else
107                 $type = apply_filters('media_upload_default_type', 'file');
108
109         // tab: gallery, library, or type-specific
110         if ( isset($_GET['tab']) )
111                 $tab = strval($_GET['tab']);
112         else
113                 $tab = apply_filters('media_upload_default_tab', 'type');
114
115         $body_id = 'media-upload';
116
117         // let the action code decide how to handle the request
118         if ( $tab == 'type' || $tab == 'type_url' )
119                 do_action("media_upload_$type");
120         else
121                 do_action("media_upload_$tab");
122 }
123 ?>