web/wp-admin/media-upload.php
changeset 136 bde1974c263b
child 194 32102edaa81b
equal deleted inserted replaced
135:53cff4b4a802 136:bde1974c263b
       
     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 		// Upload File button was clicked
       
    39 		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
       
    40 		unset($_FILES);
       
    41 		if ( is_wp_error($id) ) {
       
    42 			$errors['upload_error'] = $id;
       
    43 			$id = false;
       
    44 		}
       
    45 	}
       
    46 
       
    47 	if ( isset($_GET['upload-page-form']) ) {
       
    48 		$errors = array_merge($errors, (array) media_upload_form_handler());
       
    49 
       
    50 		$location = 'upload.php';
       
    51 		if ( $errors )
       
    52 			$location .= '?message=3';
       
    53 
       
    54 		wp_redirect( admin_url($location) );
       
    55 	}
       
    56 
       
    57 	$title = __('Upload New Media');
       
    58 	$parent_file = 'upload.php';
       
    59 	require_once('admin-header.php'); ?>
       
    60 	<div class="wrap">
       
    61 	<?php screen_icon(); ?>
       
    62 	<h2><?php echo esc_html( $title ); ?></h2>
       
    63 
       
    64 	<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">
       
    65 
       
    66 	<?php media_upload_form(); ?>
       
    67 
       
    68 	<script type="text/javascript">
       
    69 	jQuery(function($){
       
    70 		var preloaded = $(".media-item.preloaded");
       
    71 		if ( preloaded.length > 0 ) {
       
    72 			preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
       
    73 		}
       
    74 		updateMediaForm();
       
    75 		post_id = 0;
       
    76 		shortform = 1;
       
    77 	});
       
    78 	</script>
       
    79 	<input type="hidden" name="post_id" id="post_id" value="0" />
       
    80 	<?php wp_nonce_field('media-form'); ?>
       
    81 	<div id="media-items"> </div>
       
    82 	<p>
       
    83 	<input type="submit" class="button savebutton" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
       
    84 	</p>
       
    85 	</form>
       
    86 	</div>
       
    87 
       
    88 <?php
       
    89 	include('admin-footer.php');
       
    90 
       
    91 } else {
       
    92 
       
    93 	// upload type: image, video, file, ..?
       
    94 	if ( isset($_GET['type']) )
       
    95 		$type = strval($_GET['type']);
       
    96 	else
       
    97 		$type = apply_filters('media_upload_default_type', 'file');
       
    98 
       
    99 	// tab: gallery, library, or type-specific
       
   100 	if ( isset($_GET['tab']) )
       
   101 		$tab = strval($_GET['tab']);
       
   102 	else
       
   103 		$tab = apply_filters('media_upload_default_tab', 'type');
       
   104 
       
   105 	$body_id = 'media-upload';
       
   106 
       
   107 	// let the action code decide how to handle the request
       
   108 	if ( $tab == 'type' || $tab == 'type_url' )
       
   109 		do_action("media_upload_$type");
       
   110 	else
       
   111 		do_action("media_upload_$tab");
       
   112 }
       
   113 ?>