web/wp-admin/media-upload.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     7  *
     7  *
     8  * @package WordPress
     8  * @package WordPress
     9  * @subpackage Administration
     9  * @subpackage Administration
    10  */
    10  */
    11 
    11 
       
    12 if ( ! isset( $_GET['inline'] ) )
       
    13 	define( 'IFRAME_REQUEST' , true );
       
    14 
    12 /** Load WordPress Administration Bootstrap */
    15 /** Load WordPress Administration Bootstrap */
    13 require_once('admin.php');
    16 require_once('./admin.php');
    14 
    17 
    15 if (!current_user_can('upload_files'))
    18 if (!current_user_can('upload_files'))
    16 	wp_die(__('You do not have permission to upload files.'));
    19 	wp_die(__('You do not have permission to upload files.'));
    17 
    20 
    18 wp_enqueue_script('swfupload-all');
    21 wp_enqueue_script('plupload-handlers');
    19 wp_enqueue_script('swfupload-handlers');
       
    20 wp_enqueue_script('image-edit');
    22 wp_enqueue_script('image-edit');
    21 wp_enqueue_script('set-post-thumbnail' );
    23 wp_enqueue_script('set-post-thumbnail' );
    22 wp_enqueue_style('imgareaselect');
    24 wp_enqueue_style('imgareaselect');
       
    25 wp_enqueue_script( 'media-gallery' );
    23 
    26 
    24 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
    27 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
    25 
    28 
    26 // IDs should be integers
    29 // IDs should be integers
    27 $ID = isset($ID) ? (int) $ID : 0;
    30 $ID = isset($ID) ? (int) $ID : 0;
    28 $post_id = isset($post_id)? (int) $post_id : 0;
    31 $post_id = isset($post_id)? (int) $post_id : 0;
    29 
    32 
    30 // Require an ID for the edit screen
    33 // Require an ID for the edit screen
    31 if ( isset($action) && $action == 'edit' && !$ID )
    34 if ( isset($action) && $action == 'edit' && !$ID )
    32 	wp_die(__("You are not allowed to be here"));
    35 	wp_die( __( 'Cheatin’ uh?' ) );
    33 
    36 
    34 if ( isset($_GET['inline']) ) {
    37 if ( isset($_GET['inline']) ) {
    35 	$errors = array();
    38 	$errors = array();
    36 
    39 
       
    40 	if ( ! empty( $_REQUEST['post_id'] ) && ! current_user_can( 'edit_post' , $_REQUEST['post_id'] ) )
       
    41 		wp_die( __( 'Cheatin’ uh?' ) );
       
    42 
    37 	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
    43 	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
       
    44 		check_admin_referer('media-form');
    38 		// Upload File button was clicked
    45 		// Upload File button was clicked
    39 		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
    46 		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
    40 		unset($_FILES);
    47 		unset($_FILES);
    41 		if ( is_wp_error($id) ) {
    48 		if ( is_wp_error($id) ) {
    42 			$errors['upload_error'] = $id;
    49 			$errors['upload_error'] = $id;
    50 		$location = 'upload.php';
    57 		$location = 'upload.php';
    51 		if ( $errors )
    58 		if ( $errors )
    52 			$location .= '?message=3';
    59 			$location .= '?message=3';
    53 
    60 
    54 		wp_redirect( admin_url($location) );
    61 		wp_redirect( admin_url($location) );
       
    62 		exit;
    55 	}
    63 	}
       
    64 
       
    65 	if ( isset( $_REQUEST['post_id'] ) )
       
    66 		wp_die( __( 'Cheatin’ uh?' ) );
    56 
    67 
    57 	$title = __('Upload New Media');
    68 	$title = __('Upload New Media');
    58 	$parent_file = 'upload.php';
    69 	$parent_file = 'upload.php';
    59 	require_once('admin-header.php'); ?>
    70 	get_current_screen()->add_help_tab( array(
       
    71 	'id'		=> 'overview',
       
    72 	'title'		=> __('Overview'),
       
    73 	'content'	=>
       
    74 		'<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. There are three options for uploading files:') . '</p>' .
       
    75 		'<ul>' .
       
    76 			'<li>' . __('<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.') . '</li>' .
       
    77 			'<li>' . __('Clicking <strong>Select Files</strong> opens a navigation window showing you files in your operating system. Selecting <strong>Open</strong> after clicking on the file you want activates a progress bar on the uploader screen.') . '</li>' .
       
    78 			'<li>' . __('Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.') . '</li>' .
       
    79 		'</ul>' .
       
    80 		'<p>' . __('Basic image editing is available after upload is complete. Make sure you click Save before leaving this screen.') . '</p>'
       
    81 	) );
       
    82 	get_current_screen()->set_help_sidebar(
       
    83 		'<p><strong>' . __('For more information:') . '</strong></p>' .
       
    84 		'<p>' . __('<a href="http://codex.wordpress.org/Media_Add_New_Screen" target="_blank">Documentation on Uploading Media Files</a>') . '</p>' .
       
    85 		'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
       
    86 	);
       
    87 
       
    88 	require_once('./admin-header.php');
       
    89 
       
    90 	$form_class = 'media-upload-form type-form validate';
       
    91 
       
    92 	if ( get_user_setting('uploader') )
       
    93 		$form_class .= ' html-uploader';
       
    94 	?>
    60 	<div class="wrap">
    95 	<div class="wrap">
    61 	<?php screen_icon(); ?>
    96 	<?php screen_icon(); ?>
    62 	<h2><?php echo esc_html( $title ); ?></h2>
    97 	<h2><?php echo esc_html( $title ); ?></h2>
    63 
    98 
    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">
    99 	<form enctype="multipart/form-data" method="post" action="<?php echo admin_url('media-upload.php?inline=&amp;upload-page-form='); ?>" class="<?php echo $form_class; ?>" id="file-form">
    65 
   100 
    66 	<?php media_upload_form(); ?>
   101 	<?php media_upload_form(); ?>
    67 
   102 
    68 	<script type="text/javascript">
   103 	<script type="text/javascript">
    69 	jQuery(function($){
   104 	jQuery(function($){
    76 		shortform = 1;
   111 		shortform = 1;
    77 	});
   112 	});
    78 	</script>
   113 	</script>
    79 	<input type="hidden" name="post_id" id="post_id" value="0" />
   114 	<input type="hidden" name="post_id" id="post_id" value="0" />
    80 	<?php wp_nonce_field('media-form'); ?>
   115 	<?php wp_nonce_field('media-form'); ?>
    81 	<div id="media-items"> </div>
   116 	<div id="media-items" class="hide-if-no-js"></div>
    82 	<p>
   117 	<?php submit_button( __( 'Save all changes' ), 'button savebutton hidden', 'save' ); ?>
    83 	<input type="submit" class="button savebutton" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
       
    84 	</p>
       
    85 	</form>
   118 	</form>
    86 	</div>
   119 	</div>
    87 
   120 
    88 <?php
   121 <?php
    89 	include('admin-footer.php');
   122 	include('./admin-footer.php');
    90 
   123 
    91 } else {
   124 } else {
       
   125 	if ( ! empty( $_REQUEST['post_id'] ) && ! current_user_can( 'edit_post' , $_REQUEST['post_id'] ) )
       
   126 		wp_die( __( 'Cheatin&#8217; uh?' ) );
    92 
   127 
    93 	// upload type: image, video, file, ..?
   128 	// upload type: image, video, file, ..?
    94 	if ( isset($_GET['type']) )
   129 	if ( isset($_GET['type']) )
    95 		$type = strval($_GET['type']);
   130 		$type = strval($_GET['type']);
    96 	else
   131 	else
   103 		$tab = apply_filters('media_upload_default_tab', 'type');
   138 		$tab = apply_filters('media_upload_default_tab', 'type');
   104 
   139 
   105 	$body_id = 'media-upload';
   140 	$body_id = 'media-upload';
   106 
   141 
   107 	// let the action code decide how to handle the request
   142 	// let the action code decide how to handle the request
   108 	if ( $tab == 'type' || $tab == 'type_url' )
   143 	if ( $tab == 'type' || $tab == 'type_url' || ! array_key_exists( $tab , media_upload_tabs() ) )
   109 		do_action("media_upload_$type");
   144 		do_action("media_upload_$type");
   110 	else
   145 	else
   111 		do_action("media_upload_$tab");
   146 		do_action("media_upload_$tab");
   112 }
   147 }
   113 ?>