web/wp-admin/includes/media.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 /**
     9 /**
    10  * {@internal Missing Short Description}}
    10  * Defines the default media upload tabs
    11  *
    11  *
    12  * @since 2.5.0
    12  * @since 2.5.0
    13  *
    13  *
    14  * @return unknown
    14  * @return array default tabs
    15  */
    15  */
    16 function media_upload_tabs() {
    16 function media_upload_tabs() {
    17 	$_default_tabs = array(
    17 	$_default_tabs = array(
    18 		'type' => __('From Computer'), // handler action suffix => tab text
    18 		'type' => __('From Computer'), // handler action suffix => tab text
    19 		'type_url' => __('From URL'),
    19 		'type_url' => __('From URL'),
    23 
    23 
    24 	return apply_filters('media_upload_tabs', $_default_tabs);
    24 	return apply_filters('media_upload_tabs', $_default_tabs);
    25 }
    25 }
    26 
    26 
    27 /**
    27 /**
    28  * {@internal Missing Short Description}}
    28  * Adds the gallery tab back to the tabs array if post has image attachments
    29  *
    29  *
    30  * @since 2.5.0
    30  * @since 2.5.0
    31  *
    31  *
    32  * @param unknown_type $tabs
    32  * @param array $tabs
    33  * @return unknown
    33  * @return array $tabs with gallery if post has image attachment
    34  */
    34  */
    35 function update_gallery_tab($tabs) {
    35 function update_gallery_tab($tabs) {
    36 	global $wpdb;
    36 	global $wpdb;
    37 
    37 
    38 	if ( !isset($_REQUEST['post_id']) ) {
    38 	if ( !isset($_REQUEST['post_id']) ) {
    92 /**
    92 /**
    93  * {@internal Missing Short Description}}
    93  * {@internal Missing Short Description}}
    94  *
    94  *
    95  * @since 2.5.0
    95  * @since 2.5.0
    96  *
    96  *
    97  * @param unknown_type $id
    97  * @param integer $id image attachment id
    98  * @param unknown_type $alt
    98  * @param string $caption image caption
    99  * @param unknown_type $title
    99  * @param string $alt image alt attribute
   100  * @param unknown_type $align
   100  * @param string $title image title attribute
   101  * @param unknown_type $url
   101  * @param string $align image css alignment property
   102  * @param unknown_type $rel
   102  * @param string $url image src url
   103  * @param unknown_type $size
   103  * @param string|bool $rel image rel attribute
   104  * @return unknown
   104  * @param string $size image size (thumbnail, medium, large, full or added  with add_image_size() )
       
   105  * @return string the html to insert into editor
   105  */
   106  */
   106 function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') {
   107 function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') {
   107 
   108 
   108 	$html = get_image_tag($id, $alt, $title, $align, $size);
   109 	$html = get_image_tag($id, $alt, '', $align, $size);
   109 
   110 
   110 	$rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : '';
   111 	$rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : '';
   111 
   112 
   112 	if ( $url )
   113 	if ( $url )
   113 		$html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>";
   114 		$html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>";
   116 
   117 
   117 	return $html;
   118 	return $html;
   118 }
   119 }
   119 
   120 
   120 /**
   121 /**
   121  * {@internal Missing Short Description}}
   122  * Adds image shortcode with caption to editor
   122  *
   123  *
   123  * @since 2.6.0
   124  * @since 2.6.0
   124  *
   125  *
   125  * @param unknown_type $html
   126  * @param string $html
   126  * @param unknown_type $id
   127  * @param integer $id
   127  * @param unknown_type $alt
   128  * @param string $caption image caption
   128  * @param unknown_type $title
   129  * @param string $alt image alt attribute
   129  * @param unknown_type $align
   130  * @param string $title image title attribute
   130  * @param unknown_type $url
   131  * @param string $align image css alignment property
   131  * @param unknown_type $size
   132  * @param string $url image src url
   132  * @return unknown
   133  * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() )
       
   134  * @return string
   133  */
   135  */
   134 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
   136 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
   135 
   137 
   136 	if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
   138 	if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
   137 		return $html;
   139 		return $html;
   168 	// remove any line breaks from inside the tags
   170 	// remove any line breaks from inside the tags
   169 	return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] );
   171 	return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] );
   170 }
   172 }
   171 
   173 
   172 /**
   174 /**
   173  * {@internal Missing Short Description}}
   175  * Adds image html to editor
   174  *
   176  *
   175  * @since 2.5.0
   177  * @since 2.5.0
   176  *
   178  *
   177  * @param unknown_type $html
   179  * @param string $html
   178  */
   180  */
   179 function media_send_to_editor($html) {
   181 function media_send_to_editor($html) {
   180 ?>
   182 ?>
   181 <script type="text/javascript">
   183 <script type="text/javascript">
   182 /* <![CDATA[ */
   184 /* <![CDATA[ */
   187 <?php
   189 <?php
   188 	exit;
   190 	exit;
   189 }
   191 }
   190 
   192 
   191 /**
   193 /**
   192  * {@internal Missing Short Description}}
       
   193  *
       
   194  * This handles the file upload POST itself, creating the attachment post.
   194  * This handles the file upload POST itself, creating the attachment post.
   195  *
   195  *
   196  * @since 2.5.0
   196  * @since 2.5.0
   197  *
   197  *
   198  * @param string $file_id Index into the {@link $_FILES} array of the upload
   198  * @param string $file_id Index into the {@link $_FILES} array of the upload
   267  * @return int|object The ID of the attachment or a WP_Error on failure
   267  * @return int|object The ID of the attachment or a WP_Error on failure
   268  */
   268  */
   269 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
   269 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
   270 	$overrides = array('test_form'=>false);
   270 	$overrides = array('test_form'=>false);
   271 
   271 
   272 	$file = wp_handle_sideload($file_array, $overrides);
   272 	$time = current_time( 'mysql' );
       
   273 	if ( $post = get_post( $post_id ) ) {
       
   274 		if ( substr( $post->post_date, 0, 4 ) > 0 )
       
   275 			$time = $post->post_date;
       
   276 	}
       
   277 
       
   278 	$file = wp_handle_sideload( $file_array, $overrides, $time );
   273 	if ( isset($file['error']) )
   279 	if ( isset($file['error']) )
   274 		return new WP_Error( 'upload_error', $file['error'] );
   280 		return new WP_Error( 'upload_error', $file['error'] );
   275 
   281 
   276 	$url = $file['url'];
   282 	$url = $file['url'];
   277 	$type = $file['type'];
   283 	$type = $file['type'];
   310 
   316 
   311 	return $id;
   317 	return $id;
   312 }
   318 }
   313 
   319 
   314 /**
   320 /**
   315  * {@internal Missing Short Description}}
   321  * Adds the iframe to display content for the media upload page
   316  *
       
   317  * Wrap iframe content (produced by $content_func) in a doctype, html head/body
       
   318  * etc any additional function args will be passed to content_func.
       
   319  *
   322  *
   320  * @since 2.5.0
   323  * @since 2.5.0
   321  *
   324  *
   322  * @param unknown_type $content_func
   325  * @param array $content_func
   323  */
   326  */
   324 function wp_iframe($content_func /* ... */) {
   327 function wp_iframe($content_func /* ... */) {
   325 	_wp_admin_html_begin();
   328 	_wp_admin_html_begin();
   326 ?>
   329 ?>
   327 <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; <?php _e('WordPress'); ?></title>
   330 <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; <?php _e('WordPress'); ?></title>
   353 
   356 
   354 if ( is_string($content_func) )
   357 if ( is_string($content_func) )
   355 	do_action( "admin_head_{$content_func}" );
   358 	do_action( "admin_head_{$content_func}" );
   356 ?>
   359 ?>
   357 </head>
   360 </head>
   358 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="no-js">
   361 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-core-ui no-js">
   359 <script type="text/javascript">
   362 <script type="text/javascript">
   360 document.body.className = document.body.className.replace('no-js', 'js');
   363 document.body.className = document.body.className.replace('no-js', 'js');
   361 </script>
   364 </script>
   362 <?php
   365 <?php
   363 	$args = func_get_args();
   366 	$args = func_get_args();
   371 </html>
   374 </html>
   372 <?php
   375 <?php
   373 }
   376 }
   374 
   377 
   375 /**
   378 /**
   376  * {@internal Missing Short Description}}
   379  * Adds the media button to the editor
   377  *
   380  *
   378  * @since 2.5.0
   381  * @since 2.5.0
       
   382  *
       
   383  * @param string $editor_id
   379  */
   384  */
   380 function media_buttons($editor_id = 'content') {
   385 function media_buttons($editor_id = 'content') {
   381 	$context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
   386 	$post = get_post();
   382 
   387 	if ( ! $post && ! empty( $GLOBALS['post_ID'] ) )
   383 	$img = '<img src="' . esc_url( admin_url( 'images/media-button.png?ver=20111005' ) ) . '" width="15" height="15" />';
   388 		$post = $GLOBALS['post_ID'];
   384 
   389 
   385 	echo '<a href="' . esc_url( get_upload_iframe_src() ) . '" class="thickbox add_media" id="' . esc_attr( $editor_id ) . '-add_media" title="' . esc_attr__( 'Add Media' ) . '" onclick="return false;">' . sprintf( $context, $img ) . '</a>';
   390 	wp_enqueue_media( array(
       
   391 		'post' => $post
       
   392 	) );
       
   393 
       
   394 	$img = '<span class="wp-media-buttons-icon"></span> ';
       
   395 
       
   396 	echo '<a href="#" class="button insert-media add_media" data-editor="' . esc_attr( $editor_id ) . '" title="' . esc_attr__( 'Add Media' ) . '">' . $img . __( 'Add Media' ) . '</a>';
       
   397 
       
   398 	// Don't use this filter. Want to add a button? Use the media_buttons action.
       
   399 	$legacy_filter = apply_filters('media_buttons_context', ''); // deprecated
       
   400 
       
   401 	if ( $legacy_filter ) {
       
   402 		// #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
       
   403 		if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) )
       
   404 			$legacy_filter .= '</a>';
       
   405 		echo $legacy_filter;
       
   406 	}
   386 }
   407 }
   387 add_action( 'media_buttons', 'media_buttons' );
   408 add_action( 'media_buttons', 'media_buttons' );
   388 
       
   389 function _media_button($title, $icon, $type, $id) {
       
   390 	return "<a href='" . esc_url( get_upload_iframe_src($type) ) . "' id='{$id}-add_{$type}' class='thickbox add_$type' title='" . esc_attr( $title ) . "'><img src='" . esc_url( admin_url( $icon ) ) . "' alt='$title' onclick='return false;' /></a>";
       
   391 }
       
   392 
   409 
   393 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
   410 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
   394 	global $post_ID;
   411 	global $post_ID;
   395 
   412 
   396 	if ( empty( $post_id ) )
   413 	if ( empty( $post_id ) )
   412 /**
   429 /**
   413  * {@internal Missing Short Description}}
   430  * {@internal Missing Short Description}}
   414  *
   431  *
   415  * @since 2.5.0
   432  * @since 2.5.0
   416  *
   433  *
   417  * @return unknown
   434  * @return mixed void|object WP_Error on failure
   418  */
   435  */
   419 function media_upload_form_handler() {
   436 function media_upload_form_handler() {
   420 	check_admin_referer('media-form');
   437 	check_admin_referer('media-form');
   421 
   438 
   422 	$errors = null;
   439 	$errors = null;
   504 /**
   521 /**
   505  * {@internal Missing Short Description}}
   522  * {@internal Missing Short Description}}
   506  *
   523  *
   507  * @since 2.5.0
   524  * @since 2.5.0
   508  *
   525  *
   509  * @return unknown
   526  * @return mixed
   510  */
   527  */
   511 function wp_media_upload_handler() {
   528 function wp_media_upload_handler() {
   512 	$errors = array();
   529 	$errors = array();
   513 	$id = 0;
   530 	$id = 0;
   514 
   531 
   597 		// Download file to temp location
   614 		// Download file to temp location
   598 		$tmp = download_url( $file );
   615 		$tmp = download_url( $file );
   599 
   616 
   600 		// Set variables for storage
   617 		// Set variables for storage
   601 		// fix file filename for query strings
   618 		// fix file filename for query strings
   602 		preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
   619 		preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
   603 		$file_array['name'] = basename($matches[0]);
   620 		$file_array['name'] = basename($matches[0]);
   604 		$file_array['tmp_name'] = $tmp;
   621 		$file_array['tmp_name'] = $tmp;
   605 
   622 
   606 		// If error storing temporarily, unlink
   623 		// If error storing temporarily, unlink
   607 		if ( is_wp_error( $tmp ) ) {
   624 		if ( is_wp_error( $tmp ) ) {
   675 /**
   692 /**
   676  * Retrieve HTML for the image alignment radio buttons with the specified one checked.
   693  * Retrieve HTML for the image alignment radio buttons with the specified one checked.
   677  *
   694  *
   678  * @since 2.7.0
   695  * @since 2.7.0
   679  *
   696  *
   680  * @param unknown_type $post
   697  * @param object $post
   681  * @param unknown_type $checked
   698  * @param string $checked
   682  * @return unknown
   699  * @return string
   683  */
   700  */
   684 function image_align_input_fields( $post, $checked = '' ) {
   701 function image_align_input_fields( $post, $checked = '' ) {
   685 
   702 
   686 	if ( empty($checked) )
   703 	if ( empty($checked) )
   687 		$checked = get_user_setting('align', 'none');
   704 		$checked = get_user_setting('align', 'none');
   703 /**
   720 /**
   704  * Retrieve HTML for the size radio buttons with the specified one checked.
   721  * Retrieve HTML for the size radio buttons with the specified one checked.
   705  *
   722  *
   706  * @since 2.7.0
   723  * @since 2.7.0
   707  *
   724  *
   708  * @param unknown_type $post
   725  * @param object $post
   709  * @param unknown_type $check
   726  * @param bool|string $check
   710  * @return unknown
   727  * @return array
   711  */
   728  */
   712 function image_size_input_fields( $post, $check = '' ) {
   729 function image_size_input_fields( $post, $check = '' ) {
   713 
   730 
   714 		// get a list of the actual pixel dimensions of each possible intermediate version of this image
   731 		// get a list of the actual pixel dimensions of each possible intermediate version of this image
   715 		$size_names = apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) );
   732 		$size_names = apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) );
   758 /**
   775 /**
   759  * Retrieve HTML for the Link URL buttons with the default link type as specified.
   776  * Retrieve HTML for the Link URL buttons with the default link type as specified.
   760  *
   777  *
   761  * @since 2.7.0
   778  * @since 2.7.0
   762  *
   779  *
   763  * @param unknown_type $post
   780  * @param object $post
   764  * @param unknown_type $url_type
   781  * @param string $url_type
   765  * @return unknown
   782  * @return string
   766  */
   783  */
   767 function image_link_input_fields($post, $url_type = '') {
   784 function image_link_input_fields($post, $url_type = '') {
   768 
   785 
   769 	$file = wp_get_attachment_url($post->ID);
   786 	$file = wp_get_attachment_url($post->ID);
   770 	$link = get_attachment_link($post->ID);
   787 	$link = get_attachment_link($post->ID);
   796 /**
   813 /**
   797  * {@internal Missing Short Description}}
   814  * {@internal Missing Short Description}}
   798  *
   815  *
   799  * @since 2.5.0
   816  * @since 2.5.0
   800  *
   817  *
   801  * @param unknown_type $form_fields
   818  * @param array $form_fields
   802  * @param unknown_type $post
   819  * @param object $post
   803  * @return unknown
   820  * @return array
   804  */
   821  */
   805 function image_attachment_fields_to_edit($form_fields, $post) {
   822 function image_attachment_fields_to_edit($form_fields, $post) {
   806 	if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
       
   807 		$alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
       
   808 		if ( empty($alt) )
       
   809 			$alt = '';
       
   810 
       
   811 		$form_fields['post_title']['required'] = true;
       
   812 
       
   813 		$form_fields['image_alt'] = array(
       
   814 			'value' => $alt,
       
   815 			'label' => __('Alternate Text'),
       
   816 			'helps' => __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;')
       
   817 		);
       
   818 
       
   819 		$form_fields['align'] = array(
       
   820 			'label' => __('Alignment'),
       
   821 			'input' => 'html',
       
   822 			'html'  => image_align_input_fields($post, get_option('image_default_align')),
       
   823 		);
       
   824 
       
   825 		$form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') );
       
   826 
       
   827 	} else {
       
   828 		unset( $form_fields['image_alt'] );
       
   829 	}
       
   830 	return $form_fields;
   823 	return $form_fields;
   831 }
   824 }
   832 
   825 
   833 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
       
   834 
       
   835 /**
   826 /**
   836  * {@internal Missing Short Description}}
   827  * {@internal Missing Short Description}}
   837  *
   828  *
   838  * @since 2.5.0
   829  * @since 2.5.0
   839  *
   830  *
   840  * @param unknown_type $form_fields
   831  * @param array $form_fields
   841  * @param unknown_type $post
   832  * @param object $post {@internal $post not used}}
   842  * @return unknown
   833  * @return array
   843  */
   834  */
   844 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
   835 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
   845 	unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
   836 	unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
   846 	return $form_fields;
   837 	return $form_fields;
   847 }
   838 }
   849 /**
   840 /**
   850  * {@internal Missing Short Description}}
   841  * {@internal Missing Short Description}}
   851  *
   842  *
   852  * @since 2.8.0
   843  * @since 2.8.0
   853  *
   844  *
   854  * @param unknown_type $form_fields
   845  * @param array $form_fields
   855  * @param unknown_type $post
   846  * @param object $post {@internal $post not used}}
   856  * @return unknown
   847  * @return array
   857  */
   848  */
   858 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
   849 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
   859 	unset($form_fields['image_url']);
   850 	unset($form_fields['image_url']);
   860 	return $form_fields;
   851 	return $form_fields;
   861 }
   852 }
   862 
   853 
   863 /**
   854 /**
   864  * {@internal Missing Short Description}}
   855  * Filters input from media_upload_form_handler() and assigns a default
       
   856  * post_title from the file name if none supplied.
       
   857  *
       
   858  * Illustrates the use of the attachment_fields_to_save filter
       
   859  * which can be used to add default values to any field before saving to DB.
   865  *
   860  *
   866  * @since 2.5.0
   861  * @since 2.5.0
   867  *
   862  *
   868  * @param unknown_type $post
   863  * @param object $post
   869  * @param unknown_type $attachment
   864  * @param array $attachment {@internal $attachment not used}}
   870  * @return unknown
   865  * @return array
   871  */
   866  */
   872 function image_attachment_fields_to_save($post, $attachment) {
   867 function image_attachment_fields_to_save($post, $attachment) {
   873 	if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
   868 	if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
   874 		if ( strlen(trim($post['post_title'])) == 0 ) {
   869 		if ( strlen(trim($post['post_title'])) == 0 ) {
   875 			$post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
   870 			$post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
   885 /**
   880 /**
   886  * {@internal Missing Short Description}}
   881  * {@internal Missing Short Description}}
   887  *
   882  *
   888  * @since 2.5.0
   883  * @since 2.5.0
   889  *
   884  *
   890  * @param unknown_type $html
   885  * @param string $html
   891  * @param unknown_type $attachment_id
   886  * @param integer $attachment_id
   892  * @param unknown_type $attachment
   887  * @param array $attachment
   893  * @return unknown
   888  * @return array
   894  */
   889  */
   895 function image_media_send_to_editor($html, $attachment_id, $attachment) {
   890 function image_media_send_to_editor($html, $attachment_id, $attachment) {
   896 	$post =& get_post($attachment_id);
   891 	$post = get_post($attachment_id);
   897 	if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
   892 	if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
   898 		$url = $attachment['url'];
   893 		$url = $attachment['url'];
   899 		$align = !empty($attachment['align']) ? $attachment['align'] : 'none';
   894 		$align = !empty($attachment['align']) ? $attachment['align'] : 'none';
   900 		$size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
   895 		$size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
   901 		$alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
   896 		$alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
   912 /**
   907 /**
   913  * {@internal Missing Short Description}}
   908  * {@internal Missing Short Description}}
   914  *
   909  *
   915  * @since 2.5.0
   910  * @since 2.5.0
   916  *
   911  *
   917  * @param unknown_type $post
   912  * @param object $post
   918  * @param unknown_type $errors
   913  * @param array $errors
   919  * @return unknown
   914  * @return array
   920  */
   915  */
   921 function get_attachment_fields_to_edit($post, $errors = null) {
   916 function get_attachment_fields_to_edit($post, $errors = null) {
   922 	if ( is_int($post) )
   917 	if ( is_int($post) )
   923 		$post =& get_post($post);
   918 		$post = get_post($post);
   924 	if ( is_array($post) )
   919 	if ( is_array($post) )
   925 		$post = (object) $post;
   920 		$post = new WP_Post( (object) $post );
   926 
   921 
   927 	$image_url = wp_get_attachment_url($post->ID);
   922 	$image_url = wp_get_attachment_url($post->ID);
   928 
   923 
   929 	$edit_post = sanitize_post($post, 'edit');
   924 	$edit_post = sanitize_post($post, 'edit');
   930 
   925 
   963 		)
   958 		)
   964 	);
   959 	);
   965 
   960 
   966 	foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
   961 	foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
   967 		$t = (array) get_taxonomy($taxonomy);
   962 		$t = (array) get_taxonomy($taxonomy);
   968 		if ( ! $t['public'] )
   963 		if ( ! $t['public'] || ! $t['show_ui'] )
   969 			continue;
   964 			continue;
   970 		if ( empty($t['label']) )
   965 		if ( empty($t['label']) )
   971 			$t['label'] = $taxonomy;
   966 			$t['label'] = $taxonomy;
   972 		if ( empty($t['args']) )
   967 		if ( empty($t['args']) )
   973 			$t['args'] = array();
   968 			$t['args'] = array();
   974 
   969 
   975 		$terms = get_object_term_cache($post->ID, $taxonomy);
   970 		$terms = get_object_term_cache($post->ID, $taxonomy);
   976 		if ( empty($terms) )
   971 		if ( false === $terms )
   977 			$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
   972 			$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
   978 
   973 
   979 		$values = array();
   974 		$values = array();
   980 
   975 
   981 		foreach ( $terms as $term )
   976 		foreach ( $terms as $term )
   982 			$values[] = $term->name;
   977 			$values[] = $term->slug;
   983 		$t['value'] = join(', ', $values);
   978 		$t['value'] = join(', ', $values);
   984 
   979 
   985 		$form_fields[$taxonomy] = $t;
   980 		$form_fields[$taxonomy] = $t;
   986 	}
   981 	}
   987 
   982 
   988 	// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
   983 	// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
   989 	// The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
   984 	// The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
   990 	$form_fields = array_merge_recursive($form_fields, (array) $errors);
   985 	$form_fields = array_merge_recursive($form_fields, (array) $errors);
       
   986 
       
   987 	// This was formerly in image_attachment_fields_to_edit().
       
   988 	if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
       
   989 		$alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
       
   990 		if ( empty($alt) )
       
   991 			$alt = '';
       
   992 
       
   993 		$form_fields['post_title']['required'] = true;
       
   994 
       
   995 		$form_fields['image_alt'] = array(
       
   996 			'value' => $alt,
       
   997 			'label' => __('Alternative Text'),
       
   998 			'helps' => __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;')
       
   999 		);
       
  1000 
       
  1001 		$form_fields['align'] = array(
       
  1002 			'label' => __('Alignment'),
       
  1003 			'input' => 'html',
       
  1004 			'html'  => image_align_input_fields($post, get_option('image_default_align')),
       
  1005 		);
       
  1006 
       
  1007 		$form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') );
       
  1008 
       
  1009 	} else {
       
  1010 		unset( $form_fields['image_alt'] );
       
  1011 	}
   991 
  1012 
   992 	$form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
  1013 	$form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
   993 
  1014 
   994 	return $form_fields;
  1015 	return $form_fields;
   995 }
  1016 }
  1058 	extract( $args, EXTR_SKIP );
  1079 	extract( $args, EXTR_SKIP );
  1059 
  1080 
  1060 	$toggle_on  = __( 'Show' );
  1081 	$toggle_on  = __( 'Show' );
  1061 	$toggle_off = __( 'Hide' );
  1082 	$toggle_off = __( 'Hide' );
  1062 
  1083 
  1063 	$filename = esc_html( basename( $post->guid ) );
  1084 	$filename = esc_html( wp_basename( $post->guid ) );
  1064 	$title = esc_attr( $post->post_title );
  1085 	$title = esc_attr( $post->post_title );
  1065 
  1086 
  1066 	if ( $_tags = get_the_tags( $attachment_id ) ) {
  1087 	if ( $_tags = get_the_tags( $attachment_id ) ) {
  1067 		foreach ( $_tags as $tag )
  1088 		foreach ( $_tags as $tag )
  1068 			$tags[] = $tag->name;
  1089 			$tags[] = $tag->name;
  1109 	if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
  1130 	if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
  1110 		$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
  1131 		$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
  1111 	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
  1132 	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
  1112 
  1133 
  1113 	$image_edit_button = '';
  1134 	$image_edit_button = '';
  1114 	if ( gd_edit_image_support( $post->post_mime_type ) ) {
  1135 	if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
  1115 		$nonce = wp_create_nonce( "image_editor-$post->ID" );
  1136 		$nonce = wp_create_nonce( "image_editor-$post->ID" );
  1116 		$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <img src='" . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . "' class='imgedit-wait-spin' alt='' />";
  1137 		$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
  1117 	}
  1138 	}
  1118 
  1139 
  1119 	$attachment_url = get_permalink( $attachment_id );
  1140 	$attachment_url = get_permalink( $attachment_id );
  1120 
  1141 
  1121 	$item = "
  1142 	$item = "
  1154 
  1175 
  1155 	if ( $send )
  1176 	if ( $send )
  1156 		$send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false );
  1177 		$send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false );
  1157 	if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
  1178 	if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
  1158 		if ( !EMPTY_TRASH_DAYS ) {
  1179 		if ( !EMPTY_TRASH_DAYS ) {
  1159 			$delete = "<a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Delete Permanently' ) . '</a>';
  1180 			$delete = "<a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete-permanently'>" . __( 'Delete Permanently' ) . '</a>';
  1160 		} elseif ( !MEDIA_TRASH ) {
  1181 		} elseif ( !MEDIA_TRASH ) {
  1161 			$delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a>
  1182 			$delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a>
  1162 			 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'><p>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ), $filename ) . "</p>
  1183 			 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'><p>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ), $filename ) . "</p>
  1163 			 <a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a>
  1184 			 <a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a>
  1164 			 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a>
  1185 			 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a>
  1165 			 </div>";
  1186 			 </div>";
  1166 		} else {
  1187 		} else {
  1167 			$delete = "<a href='" . wp_nonce_url( "post.php?action=trash&amp;post=$attachment_id", 'trash-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a>
  1188 			$delete = "<a href='" . wp_nonce_url( "post.php?action=trash&amp;post=$attachment_id", 'trash-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a>
  1168 			<a href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$attachment_id", 'untrash-attachment_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . "</a>";
  1189 			<a href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$attachment_id", 'untrash-post_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . "</a>";
  1169 		}
  1190 		}
  1170 	} else {
  1191 	} else {
  1171 		$delete = '';
  1192 		$delete = '';
  1172 	}
  1193 	}
  1173 
  1194 
  1258 	}
  1279 	}
  1259 
  1280 
  1260 	return $item;
  1281 	return $item;
  1261 }
  1282 }
  1262 
  1283 
       
  1284 function get_compat_media_markup( $attachment_id, $args = null ) {
       
  1285 	$post = get_post( $attachment_id );
       
  1286 
       
  1287 	$default_args = array(
       
  1288 		'errors' => null,
       
  1289 		'in_modal' => false,
       
  1290 	);
       
  1291 
       
  1292 	$user_can_edit = current_user_can( 'edit_post', $attachment_id );
       
  1293 
       
  1294 	$args = wp_parse_args( $args, $default_args );
       
  1295 	$args = apply_filters( 'get_media_item_args', $args );
       
  1296 
       
  1297 	$form_fields = array();
       
  1298 
       
  1299 	if ( $args['in_modal'] ) {
       
  1300 		foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
       
  1301 			$t = (array) get_taxonomy($taxonomy);
       
  1302 			if ( ! $t['public'] || ! $t['show_ui'] )
       
  1303 				continue;
       
  1304 			if ( empty($t['label']) )
       
  1305 				$t['label'] = $taxonomy;
       
  1306 			if ( empty($t['args']) )
       
  1307 				$t['args'] = array();
       
  1308 
       
  1309 			$terms = get_object_term_cache($post->ID, $taxonomy);
       
  1310 			if ( false === $terms )
       
  1311 				$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
       
  1312 
       
  1313 			$values = array();
       
  1314 
       
  1315 			foreach ( $terms as $term )
       
  1316 				$values[] = $term->slug;
       
  1317 			$t['value'] = join(', ', $values);
       
  1318 			$t['taxonomy'] = true;
       
  1319 
       
  1320 			$form_fields[$taxonomy] = $t;
       
  1321 		}
       
  1322 	}
       
  1323 
       
  1324 	// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
       
  1325 	// The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
       
  1326 	$form_fields = array_merge_recursive($form_fields, (array) $args['errors'] );
       
  1327 
       
  1328 	$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
       
  1329 
       
  1330 	unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'],
       
  1331 		$form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'],
       
  1332 		$form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] );
       
  1333 
       
  1334 	$media_meta = apply_filters( 'media_meta', '', $post );
       
  1335 
       
  1336 	$defaults = array(
       
  1337 		'input'         => 'text',
       
  1338  		'required'      => false,
       
  1339  		'value'         => '',
       
  1340  		'extra_rows'    => array(),
       
  1341  		'show_in_edit'  => true,
       
  1342  		'show_in_modal' => true,
       
  1343 	);
       
  1344 
       
  1345 	$hidden_fields = array();
       
  1346 
       
  1347 	$item = '';
       
  1348 	foreach ( $form_fields as $id => $field ) {
       
  1349 		if ( $id[0] == '_' )
       
  1350 			continue;
       
  1351 
       
  1352 		$name = "attachments[$attachment_id][$id]";
       
  1353 		$id_attr = "attachments-$attachment_id-$id";
       
  1354 
       
  1355 		if ( !empty( $field['tr'] ) ) {
       
  1356 			$item .= $field['tr'];
       
  1357 			continue;
       
  1358 		}
       
  1359 
       
  1360 		$field = array_merge( $defaults, $field );
       
  1361 
       
  1362 		if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) )
       
  1363 			continue;
       
  1364 
       
  1365 		if ( $field['input'] == 'hidden' ) {
       
  1366 			$hidden_fields[$name] = $field['value'];
       
  1367 			continue;
       
  1368 		}
       
  1369 
       
  1370 		$readonly      = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : '';
       
  1371 		$required      = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
       
  1372 		$aria_required = $field['required'] ? " aria-required='true' " : '';
       
  1373 		$class  = 'compat-field-' . $id;
       
  1374 		$class .= $field['required'] ? ' form-required' : '';
       
  1375 
       
  1376 		$item .= "\t\t<tr class='$class'>";
       
  1377 		$item .= "\t\t\t<th valign='top' scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>";
       
  1378 		$item .= "</th>\n\t\t\t<td class='field'>";
       
  1379 
       
  1380 		if ( !empty( $field[ $field['input'] ] ) )
       
  1381 			$item .= $field[ $field['input'] ];
       
  1382 		elseif ( $field['input'] == 'textarea' ) {
       
  1383 			if ( 'post_content' == $id && user_can_richedit() ) {
       
  1384 				// sanitize_post() skips the post_content when user_can_richedit
       
  1385 				$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
       
  1386 			}
       
  1387 			$item .= "<textarea id='$id_attr' name='$name' $aria_required>" . $field['value'] . '</textarea>';
       
  1388 		} else {
       
  1389 			$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly $aria_required />";
       
  1390 		}
       
  1391 		if ( !empty( $field['helps'] ) )
       
  1392 			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
       
  1393 		$item .= "</td>\n\t\t</tr>\n";
       
  1394 
       
  1395 		$extra_rows = array();
       
  1396 
       
  1397 		if ( !empty( $field['errors'] ) )
       
  1398 			foreach ( array_unique( (array) $field['errors'] ) as $error )
       
  1399 				$extra_rows['error'][] = $error;
       
  1400 
       
  1401 		if ( !empty( $field['extra_rows'] ) )
       
  1402 			foreach ( $field['extra_rows'] as $class => $rows )
       
  1403 				foreach ( (array) $rows as $html )
       
  1404 					$extra_rows[$class][] = $html;
       
  1405 
       
  1406 		foreach ( $extra_rows as $class => $rows )
       
  1407 			foreach ( $rows as $html )
       
  1408 				$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
       
  1409 	}
       
  1410 
       
  1411 	if ( !empty( $form_fields['_final'] ) )
       
  1412 		$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
       
  1413 	if ( $item )
       
  1414 		$item = '<table class="compat-attachment-fields">' . $item . '</table>';
       
  1415 
       
  1416 	foreach ( $hidden_fields as $hidden_field => $value ) {
       
  1417 		$item .= '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n";
       
  1418 	}
       
  1419 
       
  1420 	return array(
       
  1421 		'item'   => $item,
       
  1422 		'meta'   => $media_meta,
       
  1423 	);
       
  1424 }
       
  1425 
  1263 /**
  1426 /**
  1264  * {@internal Missing Short Description}}
  1427  * {@internal Missing Short Description}}
  1265  *
  1428  *
  1266  * @since 2.5.0
  1429  * @since 2.5.0
  1267  */
  1430  */
  1268 function media_upload_header() {
  1431 function media_upload_header() {
  1269 	?>
  1432 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  1270 	<script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
  1433 	echo '<script type="text/javascript">post_id = ' . $post_id . ";</script>\n";
  1271 	<div id="media-upload-header">
  1434 	if ( empty( $_GET['chromeless'] ) ) {
  1272 	<?php the_media_upload_tabs(); ?>
  1435 		echo '<div id="media-upload-header">';
  1273 	</div>
  1436 		the_media_upload_tabs();
  1274 	<?php
  1437 		echo '</div>';
       
  1438 	}
  1275 }
  1439 }
  1276 
  1440 
  1277 /**
  1441 /**
  1278  * {@internal Missing Short Description}}
  1442  * {@internal Missing Short Description}}
  1279  *
  1443  *
  1320 	if (isset($errors['upload_error']) && is_wp_error($errors['upload_error']))
  1484 	if (isset($errors['upload_error']) && is_wp_error($errors['upload_error']))
  1321 		echo $errors['upload_error']->get_error_message();
  1485 		echo $errors['upload_error']->get_error_message();
  1322 
  1486 
  1323 ?></div>
  1487 ?></div>
  1324 <?php
  1488 <?php
  1325 // Check quota for this blog if multisite
       
  1326 if ( is_multisite() && !is_upload_space_available() ) {
  1489 if ( is_multisite() && !is_upload_space_available() ) {
  1327 	echo '<p>' . sprintf( __( 'Sorry, you have filled your storage quota (%s MB).' ), get_space_allowed() ) . '</p>';
  1490 	do_action( 'upload_ui_over_quota' );
  1328 	return;
  1491 	return;
  1329 }
  1492 }
  1330 
  1493 
  1331 do_action('pre-upload-ui');
  1494 do_action('pre-upload-ui');
  1332 
  1495 
  1355 	'multipart' => true,
  1518 	'multipart' => true,
  1356 	'urlstream_upload' => true,
  1519 	'urlstream_upload' => true,
  1357 	'multipart_params' => $post_params
  1520 	'multipart_params' => $post_params
  1358 );
  1521 );
  1359 
  1522 
       
  1523 // Multi-file uploading doesn't currently work in iOS Safari,
       
  1524 // single-file allows the built-in camera to be used as source for images
       
  1525 if ( wp_is_mobile() )
       
  1526 	$plupload_init['multi_selection'] = false;
       
  1527 
  1360 $plupload_init = apply_filters( 'plupload_init', $plupload_init );
  1528 $plupload_init = apply_filters( 'plupload_init', $plupload_init );
  1361 
  1529 
  1362 ?>
  1530 ?>
  1363 
  1531 
  1364 <script type="text/javascript">
  1532 <script type="text/javascript">
  1411 /**
  1579 /**
  1412  * {@internal Missing Short Description}}
  1580  * {@internal Missing Short Description}}
  1413  *
  1581  *
  1414  * @since 2.5.0
  1582  * @since 2.5.0
  1415  *
  1583  *
  1416  * @param unknown_type $type
  1584  * @param string $type
  1417  * @param unknown_type $errors
  1585  * @param object $errors
  1418  * @param unknown_type $id
  1586  * @param integer $id
  1419  */
  1587  */
  1420 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
  1588 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
  1421 
  1589 
  1422 	media_upload_header();
  1590 	media_upload_header();
  1423 
  1591 
  1474 /**
  1642 /**
  1475  * {@internal Missing Short Description}}
  1643  * {@internal Missing Short Description}}
  1476  *
  1644  *
  1477  * @since 2.7.0
  1645  * @since 2.7.0
  1478  *
  1646  *
  1479  * @param unknown_type $type
  1647  * @param string $type
  1480  * @param unknown_type $errors
  1648  * @param object $errors
  1481  * @param unknown_type $id
  1649  * @param integer $id
  1482  */
  1650  */
  1483 function media_upload_type_url_form($type = null, $errors = null, $id = null) {
  1651 function media_upload_type_url_form($type = null, $errors = null, $id = null) {
  1484 	if ( null === $type )
  1652 	if ( null === $type )
  1485 		$type = 'image';
  1653 		$type = 'image';
  1486 
  1654 
  1487 	media_upload_header();
  1655 	media_upload_header();
  1488 
  1656 
  1489 	$post_id = intval($_REQUEST['post_id']);
  1657 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  1490 
  1658 
  1491 	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
  1659 	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
  1492 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1660 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1493 	$form_class = 'media-upload-form type-form validate';
  1661 	$form_class = 'media-upload-form type-form validate';
  1494 
  1662 
  1513 	insert : function() {
  1681 	insert : function() {
  1514 		var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = '';
  1682 		var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = '';
  1515 
  1683 
  1516 		if ( '' == f.src.value || '' == t.width )
  1684 		if ( '' == f.src.value || '' == t.width )
  1517 			return false;
  1685 			return false;
  1518 
       
  1519 		if ( f.title.value ) {
       
  1520 			title = f.title.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
       
  1521 			title = ' title="'+title+'"';
       
  1522 		}
       
  1523 
  1686 
  1524 		if ( f.alt.value )
  1687 		if ( f.alt.value )
  1525 			alt = f.alt.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1688 			alt = f.alt.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1526 
  1689 
  1527 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
  1690 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
  1535 		}
  1698 		}
  1536 <?php } ?>
  1699 <?php } ?>
  1537 
  1700 
  1538 		cls = caption ? '' : ' class="'+t.align+'"';
  1701 		cls = caption ? '' : ' class="'+t.align+'"';
  1539 
  1702 
  1540 		html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
  1703 		html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />';
  1541 
  1704 
  1542 		if ( f.url.value ) {
  1705 		if ( f.url.value ) {
  1543 			url = f.url.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1706 			url = f.url.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1544 			html = '<a href="'+url+'">'+html+'</a>';
  1707 			html = '<a href="'+url+'">'+html+'</a>';
  1545 		}
  1708 		}
  1580 		if ( ! src ) {
  1743 		if ( ! src ) {
  1581 			t.resetImageData();
  1744 			t.resetImageData();
  1582 			return false;
  1745 			return false;
  1583 		}
  1746 		}
  1584 
  1747 
  1585 		document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />';
  1748 		document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" width="16" />';
  1586 		t.preloadImg = new Image();
  1749 		t.preloadImg = new Image();
  1587 		t.preloadImg.onload = t.updateImageData;
  1750 		t.preloadImg.onload = t.updateImageData;
  1588 		t.preloadImg.onerror = t.resetImageData;
  1751 		t.preloadImg.onerror = t.resetImageData;
  1589 		t.preloadImg.src = src;
  1752 		t.preloadImg.src = src;
  1590 	}
  1753 	}
  1607 </form>
  1770 </form>
  1608 <?php
  1771 <?php
  1609 }
  1772 }
  1610 
  1773 
  1611 /**
  1774 /**
  1612  * {@internal Missing Short Description}}
  1775  * Adds gallery form to upload iframe
  1613  *
  1776  *
  1614  * @since 2.5.0
  1777  * @since 2.5.0
  1615  *
  1778  *
  1616  * @param unknown_type $errors
  1779  * @param array $errors
  1617  */
  1780  */
  1618 function media_upload_gallery_form($errors) {
  1781 function media_upload_gallery_form($errors) {
  1619 	global $redir_tab, $type;
  1782 	global $redir_tab, $type;
  1620 
  1783 
  1621 	$redir_tab = 'gallery';
  1784 	$redir_tab = 'gallery';
  1757 /**
  1920 /**
  1758  * {@internal Missing Short Description}}
  1921  * {@internal Missing Short Description}}
  1759  *
  1922  *
  1760  * @since 2.5.0
  1923  * @since 2.5.0
  1761  *
  1924  *
  1762  * @param unknown_type $errors
  1925  * @param array $errors
  1763  */
  1926  */
  1764 function media_upload_library_form($errors) {
  1927 function media_upload_library_form($errors) {
  1765 	global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
  1928 	global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
  1766 
  1929 
  1767 	media_upload_header();
  1930 	media_upload_header();
  1768 
  1931 
  1769 	$post_id = intval($_REQUEST['post_id']);
  1932 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  1770 
  1933 
  1771 	$form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");
  1934 	$form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");
  1772 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1935 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1773 	$form_class = 'media-upload-form validate';
  1936 	$form_class = 'media-upload-form validate';
  1774 
  1937 
  1882 }
  2045 }
  1883 ?>
  2046 ?>
  1884 </select>
  2047 </select>
  1885 <?php } ?>
  2048 <?php } ?>
  1886 
  2049 
  1887 <?php submit_button( __( 'Filter &#187;' ), 'secondary', 'post-query-submit', false ); ?>
  2050 <?php submit_button( __( 'Filter &#187;' ), 'button', 'post-query-submit', false ); ?>
  1888 
  2051 
  1889 </div>
  2052 </div>
  1890 
  2053 
  1891 <br class="clear" />
  2054 <br class="clear" />
  1892 </div>
  2055 </div>
  1920 </form>
  2083 </form>
  1921 <?php
  2084 <?php
  1922 }
  2085 }
  1923 
  2086 
  1924 /**
  2087 /**
  1925  * {@internal Missing Short Description}}
  2088  * Creates the form for external url
  1926  *
  2089  *
  1927  * @since 2.7.0
  2090  * @since 2.7.0
  1928  *
  2091  *
  1929  * @return unknown
  2092  * @param string $default_view
       
  2093  * @return string the form html
  1930  */
  2094  */
  1931 function wp_media_insert_url_form( $default_view = 'image' ) {
  2095 function wp_media_insert_url_form( $default_view = 'image' ) {
  1932 	if ( !apply_filters( 'disable_captions', '' ) ) {
  2096 	if ( !apply_filters( 'disable_captions', '' ) ) {
  1933 		$caption = '
  2097 		$caption = '
  1934 		<tr class="image-only">
  2098 		<tr class="image-only">
  1935 			<th valign="top" scope="row" class="label">
  2099 			<th valign="top" scope="row" class="label">
  1936 				<span class="alignleft"><label for="caption">' . __('Image Caption') . '</label></span>
  2100 				<label for="caption"><span class="alignleft">' . __('Image Caption') . '</span></label>
  1937 			</th>
  2101 			</th>
  1938 			<td class="field"><textarea id="caption" name="caption"></textarea></td>
  2102 			<td class="field"><textarea id="caption" name="caption"></textarea></td>
  1939 		</tr>
  2103 		</tr>
  1940 ';
  2104 ';
  1941 	} else {
  2105 	} else {
  1956 	return '
  2120 	return '
  1957 	<p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> &nbsp; &nbsp; <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p>
  2121 	<p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> &nbsp; &nbsp; <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p>
  1958 	<table class="describe ' . $table_class . '"><tbody>
  2122 	<table class="describe ' . $table_class . '"><tbody>
  1959 		<tr>
  2123 		<tr>
  1960 			<th valign="top" scope="row" class="label" style="width:130px;">
  2124 			<th valign="top" scope="row" class="label" style="width:130px;">
  1961 				<span class="alignleft"><label for="src">' . __('URL') . '</label></span>
  2125 				<label for="src"><span class="alignleft">' . __('URL') . '</span></label>
  1962 				<span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span>
  2126 				<span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span>
  1963 			</th>
  2127 			</th>
  1964 			<td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
  2128 			<td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
  1965 		</tr>
  2129 		</tr>
  1966 
  2130 
  1967 		<tr>
  2131 		<tr>
  1968 			<th valign="top" scope="row" class="label">
  2132 			<th valign="top" scope="row" class="label">
  1969 				<span class="alignleft"><label for="title">' . __('Title') . '</label></span>
  2133 				<label for="title"><span class="alignleft">' . __('Title') . '</span></label>
  1970 				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
  2134 				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
  1971 			</th>
  2135 			</th>
  1972 			<td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td>
  2136 			<td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td>
  1973 		</tr>
  2137 		</tr>
  1974 
  2138 
  1975 		<tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;') . '</p></td></tr>
  2139 		<tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;') . '</p></td></tr>
  1976 
  2140 
  1977 		<tr class="image-only">
  2141 		<tr class="image-only">
  1978 			<th valign="top" scope="row" class="label">
  2142 			<th valign="top" scope="row" class="label">
  1979 				<span class="alignleft"><label for="alt">' . __('Alternate Text') . '</label></span>
  2143 				<label for="alt"><span class="alignleft">' . __('Alternative Text') . '</span></label>
  1980 			</th>
  2144 			</th>
  1981 			<td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
  2145 			<td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
  1982 			<p class="help">' . __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;') . '</p></td>
  2146 			<p class="help">' . __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;') . '</p></td>
  1983 		</tr>
  2147 		</tr>
  1984 		' . $caption . '
  2148 		' . $caption . '
  1996 			</td>
  2160 			</td>
  1997 		</tr>
  2161 		</tr>
  1998 
  2162 
  1999 		<tr class="image-only">
  2163 		<tr class="image-only">
  2000 			<th valign="top" scope="row" class="label">
  2164 			<th valign="top" scope="row" class="label">
  2001 				<span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
  2165 				<label for="url"><span class="alignleft">' . __('Link Image To:') . '</span></label>
  2002 			</th>
  2166 			</th>
  2003 			<td class="field"><input id="url" name="url" value="" type="text" /><br />
  2167 			<td class="field"><input id="url" name="url" value="" type="text" /><br />
  2004 
  2168 
  2005 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
  2169 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
  2006 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
  2170 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
  2021 	</tbody></table>
  2185 	</tbody></table>
  2022 ';
  2186 ';
  2023 
  2187 
  2024 }
  2188 }
  2025 
  2189 
  2026 function _insert_into_post_button($type) {
  2190 /**
  2027 	if ( !post_type_supports(get_post_type($_GET['post_id']), 'editor') )
  2191  * Displays the multi-file uploader message.
  2028 		return '';
       
  2029 
       
  2030 	if ( 'image' == $type )
       
  2031 	return '
       
  2032 		<tr>
       
  2033 			<td></td>
       
  2034 			<td>
       
  2035 				<input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
       
  2036 			</td>
       
  2037 		</tr>
       
  2038 	';
       
  2039 
       
  2040 	return '
       
  2041 		<tr>
       
  2042 			<td></td>
       
  2043 			<td>
       
  2044 				' . get_submit_button( __( 'Insert into Post' ), 'button', 'insertonlybutton', false ) . '
       
  2045 			</td>
       
  2046 		</tr>
       
  2047 	';
       
  2048 }
       
  2049 
       
  2050 /**
       
  2051  * {@internal Missing Short Description}}
       
  2052  *
  2192  *
  2053  * @since 2.6.0
  2193  * @since 2.6.0
  2054  */
  2194  */
  2055 function media_upload_flash_bypass() {
  2195 function media_upload_flash_bypass() {
       
  2196 	$browser_uploader = admin_url( 'media-new.php?browser-uploader' );
       
  2197 
       
  2198 	if ( $post = get_post() )
       
  2199 		$browser_uploader .= '&amp;post_id=' . intval( $post->ID );
       
  2200 	elseif ( ! empty( $GLOBALS['post_ID'] ) )
       
  2201 		$browser_uploader .= '&amp;post_id=' . intval( $GLOBALS['post_ID'] );
       
  2202 
  2056 	?>
  2203 	?>
  2057 	<p class="upload-flash-bypass">
  2204 	<p class="upload-flash-bypass">
  2058 	<?php _e('You are using the multi-file uploader. Problems? Try the <a href="#">browser uploader</a> instead.'); ?>
  2205 	<?php printf( __( 'You are using the multi-file uploader. Problems? Try the <a href="%1$s" target="%2$s">browser uploader</a> instead.' ), $browser_uploader, '_blank' ); ?>
  2059 	</p>
  2206 	</p>
  2060 	<?php
  2207 	<?php
  2061 }
  2208 }
  2062 add_action('post-plupload-upload-ui', 'media_upload_flash_bypass');
  2209 add_action('post-plupload-upload-ui', 'media_upload_flash_bypass');
  2063 
  2210 
  2064 /**
  2211 /**
  2065  * {@internal Missing Short Description}}
  2212  * Displays the browser's built-in uploader message.
  2066  *
  2213  *
  2067  * @since 2.6.0
  2214  * @since 2.6.0
  2068  */
  2215  */
  2069 function media_upload_html_bypass() {
  2216 function media_upload_html_bypass() {
  2070 	?>
  2217 	?>
  2073 	</p>
  2220 	</p>
  2074 	<?php
  2221 	<?php
  2075 }
  2222 }
  2076 add_action('post-html-upload-ui', 'media_upload_html_bypass');
  2223 add_action('post-html-upload-ui', 'media_upload_html_bypass');
  2077 
  2224 
  2078 function media_upload_text_after() {
  2225 /**
  2079 	?>
  2226  * Used to display a "After a file has been uploaded..." help message.
  2080 	<span class="after-file-upload"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></span>
  2227  *
  2081 	<?php
  2228  * @since 3.3.0
  2082 }
  2229  */
  2083 add_action('post-upload-ui', 'media_upload_text_after', 5);
  2230 function media_upload_text_after() {}
  2084 
  2231 
  2085 /**
  2232 /**
  2086  * {@internal Missing Short Description}}
  2233  * Displays the checkbox to scale images.
  2087  *
  2234  *
  2088  * @since 2.6.0
  2235  * @since 3.3.0
  2089  */
  2236  */
  2090 function media_upload_max_image_resize() {
  2237 function media_upload_max_image_resize() {
  2091 	$checked = get_user_setting('upload_resize') ? ' checked="true"' : '';
  2238 	$checked = get_user_setting('upload_resize') ? ' checked="true"' : '';
  2092 	$a = $end = '';
  2239 	$a = $end = '';
  2093 
  2240 
  2104 ?>
  2251 ?>
  2105 </label></p>
  2252 </label></p>
  2106 <?php
  2253 <?php
  2107 }
  2254 }
  2108 
  2255 
       
  2256 /**
       
  2257  * Displays the out of storage quota message in Multisite.
       
  2258  *
       
  2259  * @since 3.5.0
       
  2260  */
       
  2261 function multisite_over_quota_message() {
       
  2262 	echo '<p>' . sprintf( __( 'Sorry, you have used all of your storage quota of %s MB.' ), get_space_allowed() ) . '</p>';
       
  2263 }
       
  2264 
       
  2265 /**
       
  2266  * Displays the image and editor in the post editor
       
  2267  *
       
  2268  * @since 3.5.0
       
  2269  */
       
  2270 function edit_form_image_editor() {
       
  2271 	$post = get_post();
       
  2272 
       
  2273 	$open = isset( $_GET['image-editor'] );
       
  2274 	if ( $open )
       
  2275 		require_once ABSPATH . 'wp-admin/includes/image-edit.php';
       
  2276 
       
  2277 	$thumb_url = false;
       
  2278 	if ( $attachment_id = intval( $post->ID ) )
       
  2279 		$thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true );
       
  2280 
       
  2281 	$filename = esc_html( basename( $post->guid ) );
       
  2282 	$title = esc_attr( $post->post_title );
       
  2283 	$alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
       
  2284 
       
  2285 	$att_url = wp_get_attachment_url( $post->ID );
       
  2286 
       
  2287 	if ( wp_attachment_is_image( $post->ID ) ) :
       
  2288 		$image_edit_button = '';
       
  2289 		if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
       
  2290 			$nonce = wp_create_nonce( "image_editor-$post->ID" );
       
  2291 			$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
       
  2292 		}
       
  2293  	?>
       
  2294 	<div class="wp_attachment_holder">
       
  2295 		<div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>
       
  2296 
       
  2297 		<div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>">
       
  2298 			<p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p>
       
  2299 			<p><?php echo $image_edit_button; ?></p>
       
  2300 		</div>
       
  2301 		<div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>">
       
  2302 			<?php if ( $open ) wp_image_editor( $attachment_id ); ?>
       
  2303 		</div>
       
  2304 	</div>
       
  2305 	<?php endif; ?>
       
  2306 
       
  2307 	<div class="wp_attachment_details">
       
  2308 		<p>
       
  2309 			<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
       
  2310 			<textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
       
  2311 		</p>
       
  2312 
       
  2313 	<?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?>
       
  2314 		<p>
       
  2315 			<label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
       
  2316 			<input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" />
       
  2317 		</p>
       
  2318 	<?php endif; ?>
       
  2319 
       
  2320 	<?php
       
  2321 		$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' );
       
  2322 		$editor_args = array(
       
  2323 			'textarea_name' => 'content',
       
  2324 			'textarea_rows' => 5,
       
  2325 			'media_buttons' => false,
       
  2326 			'tinymce' => false,
       
  2327 			'quicktags' => $quicktags_settings,
       
  2328 		);
       
  2329 	?>
       
  2330 
       
  2331 	<label for="content"><strong><?php _e( 'Description' ); ?></strong></label>
       
  2332 	<?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
       
  2333 
       
  2334 	</div>
       
  2335 	<?php
       
  2336 	$extras = get_compat_media_markup( $post->ID );
       
  2337 	echo $extras['item'];
       
  2338 	echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n";
       
  2339 }
       
  2340 
       
  2341 /**
       
  2342  * Displays non-editable attachment metadata in the publish metabox
       
  2343  *
       
  2344  * @since 3.5.0
       
  2345  */
       
  2346 function attachment_submitbox_metadata() {
       
  2347 	$post = get_post();
       
  2348 
       
  2349 	$filename = esc_html( basename( $post->guid ) );
       
  2350 
       
  2351 	$media_dims = '';
       
  2352 	$meta = wp_get_attachment_metadata( $post->ID );
       
  2353 	if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
       
  2354 		$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
       
  2355 	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
       
  2356 
       
  2357 	$att_url = wp_get_attachment_url( $post->ID );
       
  2358 ?>
       
  2359 	<div class="misc-pub-section">
       
  2360 			<label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
       
  2361 			<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php echo esc_attr($att_url); ?>" />
       
  2362 	</div>
       
  2363 	<div class="misc-pub-section">
       
  2364 		<?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong>
       
  2365 	</div>
       
  2366 	<div class="misc-pub-section">
       
  2367 		<?php _e( 'File type:' ); ?> <strong><?php
       
  2368 			if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
       
  2369 				echo esc_html( strtoupper( $matches[1] ) );
       
  2370 			else
       
  2371 				echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) );
       
  2372 		?></strong>
       
  2373 	</div>
       
  2374 
       
  2375 <?php if ( $media_dims ) : ?>
       
  2376 	<div class="misc-pub-section">
       
  2377 		<?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong>
       
  2378 	</div>
       
  2379 <?php
       
  2380 	endif;
       
  2381 }
       
  2382 
  2109 add_filter( 'async_upload_image', 'get_media_item', 10, 2 );
  2383 add_filter( 'async_upload_image', 'get_media_item', 10, 2 );
  2110 add_filter( 'async_upload_audio', 'get_media_item', 10, 2 );
  2384 add_filter( 'async_upload_audio', 'get_media_item', 10, 2 );
  2111 add_filter( 'async_upload_video', 'get_media_item', 10, 2 );
  2385 add_filter( 'async_upload_video', 'get_media_item', 10, 2 );
  2112 add_filter( 'async_upload_file',  'get_media_item', 10, 2 );
  2386 add_filter( 'async_upload_file',  'get_media_item', 10, 2 );
  2113 
  2387 
  2116 add_action( 'media_upload_video', 'wp_media_upload_handler' );
  2390 add_action( 'media_upload_video', 'wp_media_upload_handler' );
  2117 add_action( 'media_upload_file',  'wp_media_upload_handler' );
  2391 add_action( 'media_upload_file',  'wp_media_upload_handler' );
  2118 
  2392 
  2119 add_filter( 'media_upload_gallery', 'media_upload_gallery' );
  2393 add_filter( 'media_upload_gallery', 'media_upload_gallery' );
  2120 add_filter( 'media_upload_library', 'media_upload_library' );
  2394 add_filter( 'media_upload_library', 'media_upload_library' );
       
  2395 
       
  2396 add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' );