web/wp-admin/includes/media.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     7  */
     7  */
     8 
     8 
     9 /**
     9 /**
    10  * {@internal Missing Short Description}}
    10  * {@internal Missing Short Description}}
    11  *
    11  *
    12  * @since unknown
    12  * @since 2.5.0
    13  *
    13  *
    14  * @return unknown
    14  * @return unknown
    15  */
    15  */
    16 function media_upload_tabs() {
    16 function media_upload_tabs() {
    17 	$_default_tabs = array(
    17 	$_default_tabs = array(
    25 }
    25 }
    26 
    26 
    27 /**
    27 /**
    28  * {@internal Missing Short Description}}
    28  * {@internal Missing Short Description}}
    29  *
    29  *
    30  * @since unknown
    30  * @since 2.5.0
    31  *
    31  *
    32  * @param unknown_type $tabs
    32  * @param unknown_type $tabs
    33  * @return unknown
    33  * @return unknown
    34  */
    34  */
    35 function update_gallery_tab($tabs) {
    35 function update_gallery_tab($tabs) {
    57 add_filter('media_upload_tabs', 'update_gallery_tab');
    57 add_filter('media_upload_tabs', 'update_gallery_tab');
    58 
    58 
    59 /**
    59 /**
    60  * {@internal Missing Short Description}}
    60  * {@internal Missing Short Description}}
    61  *
    61  *
    62  * @since unknown
    62  * @since 2.5.0
    63  */
    63  */
    64 function the_media_upload_tabs() {
    64 function the_media_upload_tabs() {
    65 	global $redir_tab;
    65 	global $redir_tab;
    66 	$tabs = media_upload_tabs();
    66 	$tabs = media_upload_tabs();
       
    67 	$default = 'type';
    67 
    68 
    68 	if ( !empty($tabs) ) {
    69 	if ( !empty($tabs) ) {
    69 		echo "<ul id='sidemenu'>\n";
    70 		echo "<ul id='sidemenu'>\n";
    70 		if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) )
    71 		if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) )
    71 			$current = $redir_tab;
    72 			$current = $redir_tab;
    72 		elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
    73 		elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
    73 			$current = $_GET['tab'];
    74 			$current = $_GET['tab'];
    74 		else
    75 		else
    75 			$current = apply_filters('media_upload_default_tab', 'type');
    76 			$current = apply_filters('media_upload_default_tab', $default);
    76 
    77 
    77 		foreach ( $tabs as $callback => $text ) {
    78 		foreach ( $tabs as $callback => $text ) {
    78 			$class = '';
    79 			$class = '';
       
    80 
    79 			if ( $current == $callback )
    81 			if ( $current == $callback )
    80 				$class = " class='current'";
    82 				$class = " class='current'";
    81 			$href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false));
    83 
       
    84 			$href = add_query_arg(array('tab' => $callback, 's' => false, 'paged' => false, 'post_mime_type' => false, 'm' => false));
    82 			$link = "<a href='" . esc_url($href) . "'$class>$text</a>";
    85 			$link = "<a href='" . esc_url($href) . "'$class>$text</a>";
    83 			echo "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n";
    86 			echo "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n";
    84 		}
    87 		}
    85 		echo "</ul>\n";
    88 		echo "</ul>\n";
    86 	}
    89 	}
    87 }
    90 }
    88 
    91 
    89 /**
    92 /**
    90  * {@internal Missing Short Description}}
    93  * {@internal Missing Short Description}}
    91  *
    94  *
    92  * @since unknown
    95  * @since 2.5.0
    93  *
    96  *
    94  * @param unknown_type $id
    97  * @param unknown_type $id
    95  * @param unknown_type $alt
    98  * @param unknown_type $alt
    96  * @param unknown_type $title
    99  * @param unknown_type $title
    97  * @param unknown_type $align
   100  * @param unknown_type $align
   115 }
   118 }
   116 
   119 
   117 /**
   120 /**
   118  * {@internal Missing Short Description}}
   121  * {@internal Missing Short Description}}
   119  *
   122  *
   120  * @since unknown
   123  * @since 2.6.0
   121  *
   124  *
   122  * @param unknown_type $html
   125  * @param unknown_type $html
   123  * @param unknown_type $id
   126  * @param unknown_type $id
   124  * @param unknown_type $alt
   127  * @param unknown_type $alt
   125  * @param unknown_type $title
   128  * @param unknown_type $title
   133 	if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
   136 	if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
   134 		return $html;
   137 		return $html;
   135 
   138 
   136 	$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
   139 	$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
   137 
   140 
   138 	if ( ! preg_match( '/width="([0-9]+)/', $html, $matches ) )
   141 	if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) )
   139 		return $html;
   142 		return $html;
   140 
   143 
   141 	$width = $matches[1];
   144 	$width = $matches[1];
       
   145 
       
   146 	$caption = str_replace( array("\r\n", "\r"), "\n", $caption);
       
   147 	$caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption );
       
   148 	// convert any remaining line breaks to <br>
       
   149 	$caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption );
   142 
   150 
   143 	$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
   151 	$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
   144 	if ( empty($align) )
   152 	if ( empty($align) )
   145 		$align = 'none';
   153 		$align = 'none';
   146 
   154 
   147 	$shcode = '[caption id="' . $id . '" align="align' . $align
   155 	$shcode = '[caption id="' . $id . '" align="align' . $align	. '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';
   148 	. '" width="' . $width . '" caption="' . addslashes($caption) . '"]' . $html . '[/caption]';
       
   149 
   156 
   150 	return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
   157 	return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
   151 }
   158 }
   152 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
   159 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
   153 
   160 
   154 /**
   161 /**
   155  * {@internal Missing Short Description}}
   162  * Private preg_replace callback used in image_add_caption()
   156  *
   163  *
   157  * @since unknown
   164  * @access private
       
   165  * @since 3.4.0
       
   166  */
       
   167 function _cleanup_image_add_caption( $matches ) {
       
   168 	// remove any line breaks from inside the tags
       
   169 	return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] );
       
   170 }
       
   171 
       
   172 /**
       
   173  * {@internal Missing Short Description}}
       
   174  *
       
   175  * @since 2.5.0
   158  *
   176  *
   159  * @param unknown_type $html
   177  * @param unknown_type $html
   160  */
   178  */
   161 function media_send_to_editor($html) {
   179 function media_send_to_editor($html) {
   162 ?>
   180 ?>
   173 /**
   191 /**
   174  * {@internal Missing Short Description}}
   192  * {@internal Missing Short Description}}
   175  *
   193  *
   176  * This handles the file upload POST itself, creating the attachment post.
   194  * This handles the file upload POST itself, creating the attachment post.
   177  *
   195  *
   178  * @since unknown
   196  * @since 2.5.0
   179  *
   197  *
   180  * @param unknown_type $file_id
   198  * @param string $file_id Index into the {@link $_FILES} array of the upload
   181  * @param unknown_type $post_id
   199  * @param int $post_id The post ID the media is associated with
   182  * @param unknown_type $post_data
   200  * @param array $post_data allows you to overwrite some of the attachment
   183  * @return unknown
   201  * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior
   184  */
   202  * @return int the ID of the attachment
   185 function media_handle_upload($file_id, $post_id, $post_data = array()) {
   203  */
   186 	$overrides = array('test_form'=>false);
   204 function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) {
   187 
   205 
   188 	$time = current_time('mysql');
   206 	$time = current_time('mysql');
   189 	if ( $post = get_post($post_id) ) {
   207 	if ( $post = get_post($post_id) ) {
   190 		if ( substr( $post->post_date, 0, 4 ) > 0 )
   208 		if ( substr( $post->post_date, 0, 4 ) > 0 )
   191 			$time = $post->post_date;
   209 			$time = $post->post_date;
   206 	$title = $name;
   224 	$title = $name;
   207 	$content = '';
   225 	$content = '';
   208 
   226 
   209 	// use image exif/iptc data for title and caption defaults if possible
   227 	// use image exif/iptc data for title and caption defaults if possible
   210 	if ( $image_meta = @wp_read_image_metadata($file) ) {
   228 	if ( $image_meta = @wp_read_image_metadata($file) ) {
   211 		if ( trim($image_meta['title']) )
   229 		if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
   212 			$title = $image_meta['title'];
   230 			$title = $image_meta['title'];
   213 		if ( trim($image_meta['caption']) )
   231 		if ( trim( $image_meta['caption'] ) )
   214 			$content = $image_meta['caption'];
   232 			$content = $image_meta['caption'];
   215 	}
   233 	}
   216 
   234 
   217 	// Construct the attachment array
   235 	// Construct the attachment array
   218 	$attachment = array_merge( array(
   236 	$attachment = array_merge( array(
   221 		'post_parent' => $post_id,
   239 		'post_parent' => $post_id,
   222 		'post_title' => $title,
   240 		'post_title' => $title,
   223 		'post_content' => $content,
   241 		'post_content' => $content,
   224 	), $post_data );
   242 	), $post_data );
   225 
   243 
       
   244 	// This should never be set as it would then overwrite an existing attachment.
       
   245 	if ( isset( $attachment['ID'] ) )
       
   246 		unset( $attachment['ID'] );
       
   247 
   226 	// Save the data
   248 	// Save the data
   227 	$id = wp_insert_attachment($attachment, $file, $post_id);
   249 	$id = wp_insert_attachment($attachment, $file, $post_id);
   228 	if ( !is_wp_error($id) ) {
   250 	if ( !is_wp_error($id) ) {
   229 		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
   251 		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
   230 	}
   252 	}
   232 	return $id;
   254 	return $id;
   233 
   255 
   234 }
   256 }
   235 
   257 
   236 /**
   258 /**
   237  * {@internal Missing Short Description}}
   259  * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()}
   238  *
   260  *
   239  * @since unknown
   261  * @since 2.6.0
   240  *
   262  *
   241  * @param unknown_type $file_array
   263  * @param array $file_array Array similar to a {@link $_FILES} upload array
   242  * @param unknown_type $post_id
   264  * @param int $post_id The post ID the media is associated with
   243  * @param unknown_type $desc
   265  * @param string $desc Description of the sideloaded file
   244  * @param unknown_type $post_data
   266  * @param array $post_data allows you to overwrite some of the attachment
   245  * @return unknown
   267  * @return int|object The ID of the attachment or a WP_Error on failure
   246  */
   268  */
   247 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()) {
   248 	$overrides = array('test_form'=>false);
   270 	$overrides = array('test_form'=>false);
   249 
   271 
   250 	$file = wp_handle_sideload($file_array, $overrides);
   272 	$file = wp_handle_sideload($file_array, $overrides);
   257 	$title = preg_replace('/\.[^.]+$/', '', basename($file));
   279 	$title = preg_replace('/\.[^.]+$/', '', basename($file));
   258 	$content = '';
   280 	$content = '';
   259 
   281 
   260 	// use image exif/iptc data for title and caption defaults if possible
   282 	// use image exif/iptc data for title and caption defaults if possible
   261 	if ( $image_meta = @wp_read_image_metadata($file) ) {
   283 	if ( $image_meta = @wp_read_image_metadata($file) ) {
   262 		if ( trim($image_meta['title']) )
   284 		if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
   263 			$title = $image_meta['title'];
   285 			$title = $image_meta['title'];
   264 		if ( trim($image_meta['caption']) )
   286 		if ( trim( $image_meta['caption'] ) )
   265 			$content = $image_meta['caption'];
   287 			$content = $image_meta['caption'];
   266 	}
   288 	}
   267 
   289 
   268 	$title = @$desc;
   290 	if ( isset( $desc ) )
       
   291 		$title = $desc;
   269 
   292 
   270 	// Construct the attachment array
   293 	// Construct the attachment array
   271 	$attachment = array_merge( array(
   294 	$attachment = array_merge( array(
   272 		'post_mime_type' => $type,
   295 		'post_mime_type' => $type,
   273 		'guid' => $url,
   296 		'guid' => $url,
   274 		'post_parent' => $post_id,
   297 		'post_parent' => $post_id,
   275 		'post_title' => $title,
   298 		'post_title' => $title,
   276 		'post_content' => $content,
   299 		'post_content' => $content,
   277 	), $post_data );
   300 	), $post_data );
   278 
   301 
       
   302 	// This should never be set as it would then overwrite an existing attachment.
       
   303 	if ( isset( $attachment['ID'] ) )
       
   304 		unset( $attachment['ID'] );
       
   305 
   279 	// Save the attachment metadata
   306 	// Save the attachment metadata
   280 	$id = wp_insert_attachment($attachment, $file, $post_id);
   307 	$id = wp_insert_attachment($attachment, $file, $post_id);
   281 	if ( !is_wp_error($id) ) {
   308 	if ( !is_wp_error($id) )
   282 		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
   309 		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
   283 		return $url;
   310 
   284 	}
       
   285 	return $id;
   311 	return $id;
   286 }
   312 }
   287 
   313 
   288 /**
   314 /**
   289  * {@internal Missing Short Description}}
   315  * {@internal Missing Short Description}}
   290  *
   316  *
   291  * Wrap iframe content (produced by $content_func) in a doctype, html head/body
   317  * Wrap iframe content (produced by $content_func) in a doctype, html head/body
   292  * etc any additional function args will be passed to content_func.
   318  * etc any additional function args will be passed to content_func.
   293  *
   319  *
   294  * @since unknown
   320  * @since 2.5.0
   295  *
   321  *
   296  * @param unknown_type $content_func
   322  * @param unknown_type $content_func
   297  */
   323  */
   298 function wp_iframe($content_func /* ... */) {
   324 function wp_iframe($content_func /* ... */) {
       
   325 	_wp_admin_html_begin();
   299 ?>
   326 ?>
   300 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
   301 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
       
   302 <head>
       
   303 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
       
   304 <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; <?php _e('WordPress'); ?></title>
   327 <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; <?php _e('WordPress'); ?></title>
   305 <?php
   328 <?php
   306 wp_enqueue_style( 'global' );
   329 
   307 wp_enqueue_style( 'wp-admin' );
       
   308 wp_enqueue_style( 'colors' );
   330 wp_enqueue_style( 'colors' );
   309 if ( 0 === strpos( $content_func, 'media' ) )
   331 // Check callback name for 'media'
       
   332 if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) )
       
   333 	|| ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) )
   310 	wp_enqueue_style( 'media' );
   334 	wp_enqueue_style( 'media' );
   311 wp_enqueue_style( 'ie' );
   335 wp_enqueue_style( 'ie' );
   312 ?>
   336 ?>
   313 <script type="text/javascript">
   337 <script type="text/javascript">
   314 //<![CDATA[
   338 //<![CDATA[
   315 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
   339 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
   316 var userSettings = {'url':'<?php echo SITECOOKIEPATH; ?>','uid':'<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>','time':'<?php echo time(); ?>'};
   340 var userSettings = {'url':'<?php echo SITECOOKIEPATH; ?>','uid':'<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>','time':'<?php echo time(); ?>'};
   317 var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup';
   341 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
       
   342 isRtl = <?php echo (int) is_rtl(); ?>;
   318 //]]>
   343 //]]>
   319 </script>
   344 </script>
   320 <?php
   345 <?php
   321 do_action('admin_enqueue_scripts', 'media-upload-popup');
   346 do_action('admin_enqueue_scripts', 'media-upload-popup');
   322 do_action('admin_print_styles-media-upload-popup');
   347 do_action('admin_print_styles-media-upload-popup');
   328 
   353 
   329 if ( is_string($content_func) )
   354 if ( is_string($content_func) )
   330 	do_action( "admin_head_{$content_func}" );
   355 	do_action( "admin_head_{$content_func}" );
   331 ?>
   356 ?>
   332 </head>
   357 </head>
   333 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
   358 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="no-js">
       
   359 <script type="text/javascript">
       
   360 document.body.className = document.body.className.replace('no-js', 'js');
       
   361 </script>
   334 <?php
   362 <?php
   335 	$args = func_get_args();
   363 	$args = func_get_args();
   336 	$args = array_slice($args, 1);
   364 	$args = array_slice($args, 1);
   337 	call_user_func_array($content_func, $args);
   365 	call_user_func_array($content_func, $args);
   338 
   366 
   345 }
   373 }
   346 
   374 
   347 /**
   375 /**
   348  * {@internal Missing Short Description}}
   376  * {@internal Missing Short Description}}
   349  *
   377  *
   350  * @since unknown
   378  * @since 2.5.0
   351  */
   379  */
   352 function media_buttons() {
   380 function media_buttons($editor_id = 'content') {
   353 	global $post_ID, $temp_ID;
       
   354 	$uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
       
   355 	$context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
   381 	$context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
   356 	$media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
   382 
   357 	$media_title = __('Add Media');
   383 	$img = '<img src="' . esc_url( admin_url( 'images/media-button.png?ver=20111005' ) ) . '" width="15" height="15" />';
   358 	$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&amp;type=image");
   384 
   359 	$image_title = __('Add an Image');
   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>';
   360 	$video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&amp;type=video");
       
   361 	$video_title = __('Add Video');
       
   362 	$audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&amp;type=audio");
       
   363 	$audio_title = __('Add Audio');
       
   364 	$out = <<<EOF
       
   365 
       
   366 	<a href="{$image_upload_iframe_src}&amp;TB_iframe=true" id="add_image" class="thickbox" title='$image_title' onclick="return false;"><img src='images/media-button-image.gif' alt='$image_title' /></a>
       
   367 	<a href="{$video_upload_iframe_src}&amp;TB_iframe=true" id="add_video" class="thickbox" title='$video_title' onclick="return false;"><img src='images/media-button-video.gif' alt='$video_title' /></a>
       
   368 	<a href="{$audio_upload_iframe_src}&amp;TB_iframe=true" id="add_audio" class="thickbox" title='$audio_title' onclick="return false;"><img src='images/media-button-music.gif' alt='$audio_title' /></a>
       
   369 	<a href="{$media_upload_iframe_src}&amp;TB_iframe=true" id="add_media" class="thickbox" title='$media_title' onclick="return false;"><img src='images/media-button-other.gif' alt='$media_title' /></a>
       
   370 
       
   371 EOF;
       
   372 	printf($context, $out);
       
   373 }
   386 }
   374 add_action( 'media_buttons', 'media_buttons' );
   387 add_action( 'media_buttons', 'media_buttons' );
   375 
   388 
   376 /**
   389 function _media_button($title, $icon, $type, $id) {
   377  * {@internal Missing Short Description}}
   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>";
   378  *
   391 }
   379  * @since unknown
   392 
       
   393 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
       
   394 	global $post_ID;
       
   395 
       
   396 	if ( empty( $post_id ) )
       
   397 		$post_id = $post_ID;
       
   398 
       
   399 	$upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url('media-upload.php') );
       
   400 
       
   401 	if ( $type && 'media' != $type )
       
   402 		$upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
       
   403 
       
   404 	if ( ! empty( $tab ) )
       
   405 		$upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src);
       
   406 
       
   407 	$upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
       
   408 
       
   409 	return add_query_arg('TB_iframe', true, $upload_iframe_src);
       
   410 }
       
   411 
       
   412 /**
       
   413  * {@internal Missing Short Description}}
       
   414  *
       
   415  * @since 2.5.0
   380  *
   416  *
   381  * @return unknown
   417  * @return unknown
   382  */
   418  */
   383 function media_upload_form_handler() {
   419 function media_upload_form_handler() {
   384 	check_admin_referer('media-form');
   420 	check_admin_referer('media-form');
   390 		$send_id = (int) array_shift($keys);
   426 		$send_id = (int) array_shift($keys);
   391 	}
   427 	}
   392 
   428 
   393 	if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
   429 	if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
   394 		$post = $_post = get_post($attachment_id, ARRAY_A);
   430 		$post = $_post = get_post($attachment_id, ARRAY_A);
       
   431 		$post_type_object = get_post_type_object( $post[ 'post_type' ] );
       
   432 
       
   433 		if ( !current_user_can( $post_type_object->cap->edit_post, $attachment_id ) )
       
   434 			continue;
       
   435 
   395 		if ( isset($attachment['post_content']) )
   436 		if ( isset($attachment['post_content']) )
   396 			$post['post_content'] = $attachment['post_content'];
   437 			$post['post_content'] = $attachment['post_content'];
   397 		if ( isset($attachment['post_title']) )
   438 		if ( isset($attachment['post_title']) )
   398 			$post['post_title'] = $attachment['post_title'];
   439 			$post['post_title'] = $attachment['post_title'];
   399 		if ( isset($attachment['post_excerpt']) )
   440 		if ( isset($attachment['post_excerpt']) )
   406 				$post['post_parent'] = $attachment['post_parent'];
   447 				$post['post_parent'] = $attachment['post_parent'];
   407 		}
   448 		}
   408 
   449 
   409 		$post = apply_filters('attachment_fields_to_save', $post, $attachment);
   450 		$post = apply_filters('attachment_fields_to_save', $post, $attachment);
   410 
   451 
   411 		if ( isset($attachment['image_alt']) && !empty($attachment['image_alt']) ) {
   452 		if ( isset($attachment['image_alt']) ) {
   412 			$image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
   453 			$image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
   413 			if ( $image_alt != stripslashes($attachment['image_alt']) ) {
   454 			if ( $image_alt != stripslashes($attachment['image_alt']) ) {
   414 				$image_alt = wp_strip_all_tags( stripslashes($attachment['image_alt']), true );
   455 				$image_alt = wp_strip_all_tags( stripslashes($attachment['image_alt']), true );
   415 				// update_meta expects slashed
   456 				// update_meta expects slashed
   416 				update_post_meta( $attachment_id, '_wp_attachment_image_alt', addslashes($image_alt) );
   457 				update_post_meta( $attachment_id, '_wp_attachment_image_alt', addslashes($image_alt) );
   443 	}
   484 	}
   444 
   485 
   445 	if ( isset($send_id) ) {
   486 	if ( isset($send_id) ) {
   446 		$attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
   487 		$attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
   447 
   488 
   448 		$html = $attachment['post_title'];
   489 		$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
   449 		if ( !empty($attachment['url']) ) {
   490 		if ( !empty($attachment['url']) ) {
   450 			if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
   491 			$rel = '';
   451 				$rel = " rel='attachment wp-att-" . esc_attr($send_id)."'";
   492 			if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] )
       
   493 				$rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'";
   452 			$html = "<a href='{$attachment['url']}'$rel>$html</a>";
   494 			$html = "<a href='{$attachment['url']}'$rel>$html</a>";
   453 		}
   495 		}
   454 
   496 
   455 		$html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
   497 		$html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
   456 		return media_send_to_editor($html);
   498 		return media_send_to_editor($html);
   460 }
   502 }
   461 
   503 
   462 /**
   504 /**
   463  * {@internal Missing Short Description}}
   505  * {@internal Missing Short Description}}
   464  *
   506  *
   465  * @since unknown
   507  * @since 2.5.0
   466  *
   508  *
   467  * @return unknown
   509  * @return unknown
   468  */
   510  */
   469 function media_upload_image() {
   511 function wp_media_upload_handler() {
   470 	$errors = array();
   512 	$errors = array();
   471 	$id = 0;
   513 	$id = 0;
   472 
   514 
   473 	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
   515 	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
       
   516 		check_admin_referer('media-form');
   474 		// Upload File button was clicked
   517 		// Upload File button was clicked
   475 		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
   518 		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
   476 		unset($_FILES);
   519 		unset($_FILES);
   477 		if ( is_wp_error($id) ) {
   520 		if ( is_wp_error($id) ) {
   478 			$errors['upload_error'] = $id;
   521 			$errors['upload_error'] = $id;
   479 			$id = false;
   522 			$id = false;
   480 		}
   523 		}
   481 	}
   524 	}
   482 
   525 
   483 	if ( !empty($_POST['insertonlybutton']) ) {
   526 	if ( !empty($_POST['insertonlybutton']) ) {
   484 		$alt = $align = '';
   527 		$src = $_POST['src'];
   485 
       
   486 		$src = $_POST['insertonly']['src'];
       
   487 		if ( !empty($src) && !strpos($src, '://') )
   528 		if ( !empty($src) && !strpos($src, '://') )
   488 			$src = "http://$src";
   529 			$src = "http://$src";
   489 		$alt = esc_attr($_POST['insertonly']['alt']);
   530 
   490 		if ( isset($_POST['insertonly']['align']) ) {
   531 		if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) {
   491 			$align = esc_attr($_POST['insertonly']['align']);
   532 			$title = esc_html( stripslashes( $_POST['title'] ) );
   492 			$class = " class='align$align'";
   533 			if ( empty( $title ) )
       
   534 				$title = esc_html( basename( $src ) );
       
   535 
       
   536 			if ( $title && $src )
       
   537 				$html = "<a href='" . esc_url($src) . "'>$title</a>";
       
   538 
       
   539 			$type = 'file';
       
   540 			if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) )
       
   541 				&& ( 'audio' == $ext_type || 'video' == $ext_type ) )
       
   542 					$type = $ext_type;
       
   543 
       
   544 			$html = apply_filters( $type . '_send_to_editor_url', $html, esc_url_raw( $src ), $title );
       
   545 		} else {
       
   546 			$align = '';
       
   547 			$alt = esc_attr( stripslashes( $_POST['alt'] ) );
       
   548 			if ( isset($_POST['align']) ) {
       
   549 				$align = esc_attr( stripslashes( $_POST['align'] ) );
       
   550 				$class = " class='align$align'";
       
   551 			}
       
   552 			if ( !empty($src) )
       
   553 				$html = "<img src='" . esc_url($src) . "' alt='$alt'$class />";
       
   554 
       
   555 			$html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align );
   493 		}
   556 		}
   494 		if ( !empty($src) )
   557 
   495 			$html = "<img src='" . esc_url($src) . "' alt='$alt'$class />";
       
   496 
       
   497 		$html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align);
       
   498 		return media_send_to_editor($html);
   558 		return media_send_to_editor($html);
   499 	}
   559 	}
   500 
   560 
   501 	if ( !empty($_POST) ) {
   561 	if ( !empty($_POST) ) {
   502 		$return = media_upload_form_handler();
   562 		$return = media_upload_form_handler();
   510 	if ( isset($_POST['save']) ) {
   570 	if ( isset($_POST['save']) ) {
   511 		$errors['upload_notice'] = __('Saved.');
   571 		$errors['upload_notice'] = __('Saved.');
   512 		return media_upload_gallery();
   572 		return media_upload_gallery();
   513 	}
   573 	}
   514 
   574 
   515 	if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
   575 	if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) {
   516 		return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
   576 		$type = 'image';
       
   577 		if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) )
       
   578 			$type = $_GET['type'];
       
   579 		return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id );
       
   580 	}
   517 
   581 
   518 	return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
   582 	return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
   519 }
   583 }
   520 
   584 
   521 /**
   585 /**
   522  * {@internal Missing Short Description}}
   586  * Download an image from the specified URL and attach it to a post.
   523  *
   587  *
   524  * @since unknown
   588  * @since 2.6.0
   525  *
   589  *
   526  * @param unknown_type $file
   590  * @param string $file The URL of the image to download
   527  * @param unknown_type $post_id
   591  * @param int $post_id The post ID the media is to be associated with
   528  * @param unknown_type $desc
   592  * @param string $desc Optional. Description of the image
   529  * @return unknown
   593  * @return string|WP_Error Populated HTML img tag on success
   530  */
   594  */
   531 function media_sideload_image($file, $post_id, $desc = null) {
   595 function media_sideload_image($file, $post_id, $desc = null) {
   532 	if (!empty($file) ) {
   596 	if ( ! empty($file) ) {
   533 		// Download file to temp location
   597 		// Download file to temp location
   534 		$tmp = download_url($file);
   598 		$tmp = download_url( $file );
   535 
   599 
   536 		// Set variables for storage
   600 		// Set variables for storage
   537 		// fix file filename for query strings
   601 		// fix file filename for query strings
   538 		preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
   602 		preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
   539 		$file_array['name'] = basename($matches[0]);
   603 		$file_array['name'] = basename($matches[0]);
   540 		$file_array['tmp_name'] = $tmp;
   604 		$file_array['tmp_name'] = $tmp;
   541 
   605 
   542 		// If error storing temporarily, unlink
   606 		// If error storing temporarily, unlink
   543 		if ( is_wp_error($tmp) ) {
   607 		if ( is_wp_error( $tmp ) ) {
   544 			@unlink($file_array['tmp_name']);
   608 			@unlink($file_array['tmp_name']);
   545 			$file_array['tmp_name'] = '';
   609 			$file_array['tmp_name'] = '';
   546 		}
   610 		}
   547 
   611 
   548 		// do the validation and storage stuff
   612 		// do the validation and storage stuff
   549 		$id = media_handle_sideload($file_array, $post_id, @$desc);
   613 		$id = media_handle_sideload( $file_array, $post_id, $desc );
   550 		$src = $id;
       
   551 
       
   552 		// If error storing permanently, unlink
   614 		// If error storing permanently, unlink
   553 		if ( is_wp_error($id) ) {
   615 		if ( is_wp_error($id) ) {
   554 			@unlink($file_array['tmp_name']);
   616 			@unlink($file_array['tmp_name']);
   555 			return $id;
   617 			return $id;
   556 		}
   618 		}
       
   619 
       
   620 		$src = wp_get_attachment_url( $id );
   557 	}
   621 	}
   558 
   622 
   559 	// Finally check to make sure the file has been saved, then return the html
   623 	// Finally check to make sure the file has been saved, then return the html
   560 	if ( !empty($src) ) {
   624 	if ( ! empty($src) ) {
   561 		$alt = @$desc;
   625 		$alt = isset($desc) ? esc_attr($desc) : '';
   562 		$html = "<img src='$src' alt='$alt' />";
   626 		$html = "<img src='$src' alt='$alt' />";
   563 		return $html;
   627 		return $html;
   564 	}
   628 	}
   565 }
   629 }
   566 
   630 
   567 /**
   631 /**
   568  * {@internal Missing Short Description}}
   632  * {@internal Missing Short Description}}
   569  *
   633  *
   570  * @since unknown
   634  * @since 2.5.0
   571  *
   635  *
   572  * @return unknown
   636  * @return unknown
   573  */
   637  */
   574 function media_upload_audio() {
   638 function media_upload_gallery() {
   575 	$errors = array();
   639 	$errors = array();
   576 	$id = 0;
       
   577 
       
   578 	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
       
   579 		// Upload File button was clicked
       
   580 		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
       
   581 		unset($_FILES);
       
   582 		if ( is_wp_error($id) ) {
       
   583 			$errors['upload_error'] = $id;
       
   584 			$id = false;
       
   585 		}
       
   586 	}
       
   587 
       
   588 	if ( !empty($_POST['insertonlybutton']) ) {
       
   589 		$href = $_POST['insertonly']['href'];
       
   590 		if ( !empty($href) && !strpos($href, '://') )
       
   591 			$href = "http://$href";
       
   592 
       
   593 		$title = esc_attr($_POST['insertonly']['title']);
       
   594 		if ( empty($title) )
       
   595             $title = esc_attr( basename($href) );
       
   596 
       
   597 		if ( !empty($title) && !empty($href) )
       
   598             $html = "<a href='" . esc_url($href) . "' >$title</a>";
       
   599 
       
   600 		$html = apply_filters('audio_send_to_editor_url', $html, $href, $title);
       
   601 
       
   602 		return media_send_to_editor($html);
       
   603 	}
       
   604 
   640 
   605 	if ( !empty($_POST) ) {
   641 	if ( !empty($_POST) ) {
   606 		$return = media_upload_form_handler();
   642 		$return = media_upload_form_handler();
   607 
   643 
   608 		if ( is_string($return) )
   644 		if ( is_string($return) )
   609 			return $return;
   645 			return $return;
   610 		if ( is_array($return) )
   646 		if ( is_array($return) )
   611 			$errors = $return;
   647 			$errors = $return;
   612 	}
   648 	}
   613 
   649 
   614 	if ( isset($_POST['save']) ) {
   650 	wp_enqueue_script('admin-gallery');
   615 		$errors['upload_notice'] = __('Saved.');
   651 	return wp_iframe( 'media_upload_gallery_form', $errors );
   616 		return media_upload_gallery();
   652 }
   617 	}
   653 
   618 
   654 /**
   619 	if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
   655  * {@internal Missing Short Description}}
   620 		return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );
   656  *
   621 
   657  * @since 2.5.0
   622 	return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
       
   623 }
       
   624 
       
   625 /**
       
   626  * {@internal Missing Short Description}}
       
   627  *
       
   628  * @since unknown
       
   629  *
   658  *
   630  * @return unknown
   659  * @return unknown
   631  */
   660  */
   632 function media_upload_video() {
   661 function media_upload_library() {
   633 	$errors = array();
   662 	$errors = array();
   634 	$id = 0;
       
   635 
       
   636 	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
       
   637 		// Upload File button was clicked
       
   638 		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
       
   639 		unset($_FILES);
       
   640 		if ( is_wp_error($id) ) {
       
   641 			$errors['upload_error'] = $id;
       
   642 			$id = false;
       
   643 		}
       
   644 	}
       
   645 
       
   646 	if ( !empty($_POST['insertonlybutton']) ) {
       
   647 		$href = $_POST['insertonly']['href'];
       
   648 		if ( !empty($href) && !strpos($href, '://') )
       
   649 			$href = "http://$href";
       
   650 
       
   651 		$title = esc_attr($_POST['insertonly']['title']);
       
   652         if ( empty($title) )
       
   653             $title = esc_attr( basename($href) );
       
   654 
       
   655 		if ( !empty($title) && !empty($href) )
       
   656             $html = "<a href='" . esc_url($href) . "' >$title</a>";
       
   657 
       
   658 		$html = apply_filters('video_send_to_editor_url', $html, $href, $title);
       
   659 
       
   660 		return media_send_to_editor($html);
       
   661 	}
       
   662 
       
   663 	if ( !empty($_POST) ) {
   663 	if ( !empty($_POST) ) {
   664 		$return = media_upload_form_handler();
   664 		$return = media_upload_form_handler();
   665 
   665 
   666 		if ( is_string($return) )
   666 		if ( is_string($return) )
   667 			return $return;
   667 			return $return;
   668 		if ( is_array($return) )
   668 		if ( is_array($return) )
   669 			$errors = $return;
   669 			$errors = $return;
   670 	}
   670 	}
   671 
   671 
   672 	if ( isset($_POST['save']) ) {
       
   673 		$errors['upload_notice'] = __('Saved.');
       
   674 		return media_upload_gallery();
       
   675 	}
       
   676 
       
   677 	if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
       
   678 		return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id );
       
   679 
       
   680 	return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
       
   681 }
       
   682 
       
   683 /**
       
   684  * {@internal Missing Short Description}}
       
   685  *
       
   686  * @since unknown
       
   687  *
       
   688  * @return unknown
       
   689  */
       
   690 function media_upload_file() {
       
   691 	$errors = array();
       
   692 	$id = 0;
       
   693 
       
   694 	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
       
   695 		// Upload File button was clicked
       
   696 		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
       
   697 		unset($_FILES);
       
   698 		if ( is_wp_error($id) ) {
       
   699 			$errors['upload_error'] = $id;
       
   700 			$id = false;
       
   701 		}
       
   702 	}
       
   703 
       
   704 	if ( !empty($_POST['insertonlybutton']) ) {
       
   705 		$href = $_POST['insertonly']['href'];
       
   706 		if ( !empty($href) && !strpos($href, '://') )
       
   707 			$href = "http://$href";
       
   708 
       
   709 		$title = esc_attr($_POST['insertonly']['title']);
       
   710 		if ( empty($title) )
       
   711 			$title = basename($href);
       
   712 		if ( !empty($title) && !empty($href) )
       
   713 			$html = "<a href='" . esc_url($href) . "' >$title</a>";
       
   714 		$html = apply_filters('file_send_to_editor_url', $html, esc_url_raw($href), $title);
       
   715 		return media_send_to_editor($html);
       
   716 	}
       
   717 
       
   718 	if ( !empty($_POST) ) {
       
   719 		$return = media_upload_form_handler();
       
   720 
       
   721 		if ( is_string($return) )
       
   722 			return $return;
       
   723 		if ( is_array($return) )
       
   724 			$errors = $return;
       
   725 	}
       
   726 
       
   727 	if ( isset($_POST['save']) ) {
       
   728 		$errors['upload_notice'] = __('Saved.');
       
   729 		return media_upload_gallery();
       
   730 	}
       
   731 
       
   732 	if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
       
   733 		return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );
       
   734 
       
   735 	return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
       
   736 }
       
   737 
       
   738 /**
       
   739  * {@internal Missing Short Description}}
       
   740  *
       
   741  * @since unknown
       
   742  *
       
   743  * @return unknown
       
   744  */
       
   745 function media_upload_gallery() {
       
   746 	$errors = array();
       
   747 
       
   748 	if ( !empty($_POST) ) {
       
   749 		$return = media_upload_form_handler();
       
   750 
       
   751 		if ( is_string($return) )
       
   752 			return $return;
       
   753 		if ( is_array($return) )
       
   754 			$errors = $return;
       
   755 	}
       
   756 
       
   757 	wp_enqueue_script('admin-gallery');
       
   758 	return wp_iframe( 'media_upload_gallery_form', $errors );
       
   759 }
       
   760 
       
   761 /**
       
   762  * {@internal Missing Short Description}}
       
   763  *
       
   764  * @since unknown
       
   765  *
       
   766  * @return unknown
       
   767  */
       
   768 function media_upload_library() {
       
   769 	$errors = array();
       
   770 	if ( !empty($_POST) ) {
       
   771 		$return = media_upload_form_handler();
       
   772 
       
   773 		if ( is_string($return) )
       
   774 			return $return;
       
   775 		if ( is_array($return) )
       
   776 			$errors = $return;
       
   777 	}
       
   778 
       
   779 	return wp_iframe( 'media_upload_library_form', $errors );
   672 	return wp_iframe( 'media_upload_library_form', $errors );
   780 }
   673 }
   781 
   674 
   782 /**
   675 /**
   783  * Retrieve HTML for the image alignment radio buttons with the specified one checked.
   676  * Retrieve HTML for the image alignment radio buttons with the specified one checked.
   784  *
   677  *
   785  * @since unknown
   678  * @since 2.7.0
   786  *
   679  *
   787  * @param unknown_type $post
   680  * @param unknown_type $post
   788  * @param unknown_type $checked
   681  * @param unknown_type $checked
   789  * @return unknown
   682  * @return unknown
   790  */
   683  */
   808 }
   701 }
   809 
   702 
   810 /**
   703 /**
   811  * Retrieve HTML for the size radio buttons with the specified one checked.
   704  * Retrieve HTML for the size radio buttons with the specified one checked.
   812  *
   705  *
   813  * @since unknown
   706  * @since 2.7.0
   814  *
   707  *
   815  * @param unknown_type $post
   708  * @param unknown_type $post
   816  * @param unknown_type $checked
   709  * @param unknown_type $check
   817  * @return unknown
   710  * @return unknown
   818  */
   711  */
   819 function image_size_input_fields( $post, $check = '' ) {
   712 function image_size_input_fields( $post, $check = '' ) {
   820 
   713 
   821 		// get a list of the actual pixel dimensions of each possible intermediate version of this image
   714 		// get a list of the actual pixel dimensions of each possible intermediate version of this image
   822 		$size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
   715 		$size_names = apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) );
   823 
   716 
   824 		if ( empty($check) )
   717 		if ( empty($check) )
   825 			$check = get_user_setting('imgsize', 'medium');
   718 			$check = get_user_setting('imgsize', 'medium');
   826 
   719 
   827 		foreach ( $size_names as $size => $label ) {
   720 		foreach ( $size_names as $size => $label ) {
   841 				// if $check is not enabled, default to the first available size that's bigger than a thumbnail
   734 				// if $check is not enabled, default to the first available size that's bigger than a thumbnail
   842 				$check = $size;
   735 				$check = $size;
   843 				$checked = " checked='checked'";
   736 				$checked = " checked='checked'";
   844 			}
   737 			}
   845 
   738 
   846 			$html = "<div class='image-size-item'><input type='radio' " . ( $enabled ? '' : "disabled='disabled' " ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
   739 			$html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
   847 
   740 
   848 			$html .= "<label for='{$css_id}'>$label</label>";
   741 			$html .= "<label for='{$css_id}'>$label</label>";
   849 			// only show the dimensions if that choice is available
   742 			// only show the dimensions if that choice is available
   850 			if ( $enabled )
   743 			if ( $enabled )
   851 				$html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d&nbsp;&times;&nbsp;%d)"), $downsize[1], $downsize[2] ). "</label>";
   744 				$html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d&nbsp;&times;&nbsp;%d)", $downsize[1], $downsize[2] ). "</label>";
   852 
   745 
   853 			$html .= '</div>';
   746 			$html .= '</div>';
   854 
   747 
   855 			$out[] = $html;
   748 			$out[] = $html;
   856 		}
   749 		}
   863 }
   756 }
   864 
   757 
   865 /**
   758 /**
   866  * Retrieve HTML for the Link URL buttons with the default link type as specified.
   759  * Retrieve HTML for the Link URL buttons with the default link type as specified.
   867  *
   760  *
   868  * @since unknown
   761  * @since 2.7.0
   869  *
   762  *
   870  * @param unknown_type $post
   763  * @param unknown_type $post
   871  * @param unknown_type $url_type
   764  * @param unknown_type $url_type
   872  * @return unknown
   765  * @return unknown
   873  */
   766  */
   885 	elseif ( $url_type == 'post' )
   778 	elseif ( $url_type == 'post' )
   886 		$url = $link;
   779 		$url = $link;
   887 
   780 
   888 	return "
   781 	return "
   889 	<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
   782 	<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
   890 	<button type='button' class='button urlnone' title=''>" . __('None') . "</button>
   783 	<button type='button' class='button urlnone' data-link-url=''>" . __('None') . "</button>
   891 	<button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button>
   784 	<button type='button' class='button urlfile' data-link-url='" . esc_attr($file) . "'>" . __('File URL') . "</button>
   892 	<button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button>
   785 	<button type='button' class='button urlpost' data-link-url='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button>
   893 ";
   786 ";
   894 }
   787 }
   895 
   788 
   896 /**
   789 function wp_caption_input_textarea($edit_post) {
   897  * {@internal Missing Short Description}}
   790 	// post data is already escaped
   898  *
   791 	$name = "attachments[{$edit_post->ID}][post_excerpt]";
   899  * @since unknown
   792 
       
   793 	return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>';
       
   794 }
       
   795 
       
   796 /**
       
   797  * {@internal Missing Short Description}}
       
   798  *
       
   799  * @since 2.5.0
   900  *
   800  *
   901  * @param unknown_type $form_fields
   801  * @param unknown_type $form_fields
   902  * @param unknown_type $post
   802  * @param unknown_type $post
   903  * @return unknown
   803  * @return unknown
   904  */
   804  */
   910 
   810 
   911 		$form_fields['post_title']['required'] = true;
   811 		$form_fields['post_title']['required'] = true;
   912 
   812 
   913 		$form_fields['image_alt'] = array(
   813 		$form_fields['image_alt'] = array(
   914 			'value' => $alt,
   814 			'value' => $alt,
   915 			'label' => __('Alternate text'),
   815 			'label' => __('Alternate Text'),
   916 			'helps' => __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;')
   816 			'helps' => __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;')
   917 		);
   817 		);
   918 
   818 
   919 		$form_fields['align'] = array(
   819 		$form_fields['align'] = array(
   920 			'label' => __('Alignment'),
   820 			'label' => __('Alignment'),
   933 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
   833 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
   934 
   834 
   935 /**
   835 /**
   936  * {@internal Missing Short Description}}
   836  * {@internal Missing Short Description}}
   937  *
   837  *
   938  * @since unknown
   838  * @since 2.5.0
   939  *
   839  *
   940  * @param unknown_type $form_fields
   840  * @param unknown_type $form_fields
   941  * @param unknown_type $post
   841  * @param unknown_type $post
   942  * @return unknown
   842  * @return unknown
   943  */
   843  */
   944 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
   844 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
   945 	unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
   845 	unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
   946 	return $form_fields;
   846 	return $form_fields;
   947 }
   847 }
   948 
   848 
       
   849 /**
       
   850  * {@internal Missing Short Description}}
       
   851  *
       
   852  * @since 2.8.0
       
   853  *
       
   854  * @param unknown_type $form_fields
       
   855  * @param unknown_type $post
       
   856  * @return unknown
       
   857  */
   949 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
   858 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
   950 	unset($form_fields['image_url']);
   859 	unset($form_fields['image_url']);
   951 	return $form_fields;
   860 	return $form_fields;
   952 }
   861 }
   953 
   862 
   954 /**
   863 /**
   955  * {@internal Missing Short Description}}
   864  * {@internal Missing Short Description}}
   956  *
   865  *
   957  * @since unknown
   866  * @since 2.5.0
   958  *
   867  *
   959  * @param unknown_type $post
   868  * @param unknown_type $post
   960  * @param unknown_type $attachment
   869  * @param unknown_type $attachment
   961  * @return unknown
   870  * @return unknown
   962  */
   871  */
   974 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
   883 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
   975 
   884 
   976 /**
   885 /**
   977  * {@internal Missing Short Description}}
   886  * {@internal Missing Short Description}}
   978  *
   887  *
   979  * @since unknown
   888  * @since 2.5.0
   980  *
   889  *
   981  * @param unknown_type $html
   890  * @param unknown_type $html
   982  * @param unknown_type $attachment_id
   891  * @param unknown_type $attachment_id
   983  * @param unknown_type $attachment
   892  * @param unknown_type $attachment
   984  * @return unknown
   893  * @return unknown
  1001 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
   910 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
  1002 
   911 
  1003 /**
   912 /**
  1004  * {@internal Missing Short Description}}
   913  * {@internal Missing Short Description}}
  1005  *
   914  *
  1006  * @since unknown
   915  * @since 2.5.0
  1007  *
   916  *
  1008  * @param unknown_type $post
   917  * @param unknown_type $post
  1009  * @param unknown_type $errors
   918  * @param unknown_type $errors
  1010  * @return unknown
   919  * @return unknown
  1011  */
   920  */
  1025 			'value'      => $edit_post->post_title
   934 			'value'      => $edit_post->post_title
  1026 		),
   935 		),
  1027 		'image_alt'   => array(),
   936 		'image_alt'   => array(),
  1028 		'post_excerpt' => array(
   937 		'post_excerpt' => array(
  1029 			'label'      => __('Caption'),
   938 			'label'      => __('Caption'),
  1030 			'value'      => $edit_post->post_excerpt
   939 			'input'      => 'html',
       
   940 			'html'       => wp_caption_input_textarea($edit_post)
  1031 		),
   941 		),
  1032 		'post_content' => array(
   942 		'post_content' => array(
  1033 			'label'      => __('Description'),
   943 			'label'      => __('Description'),
  1034 			'value'      => $edit_post->post_content,
   944 			'value'      => $edit_post->post_content,
  1035 			'input'      => 'textarea'
   945 			'input'      => 'textarea'
  1053 		)
   963 		)
  1054 	);
   964 	);
  1055 
   965 
  1056 	foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
   966 	foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
  1057 		$t = (array) get_taxonomy($taxonomy);
   967 		$t = (array) get_taxonomy($taxonomy);
       
   968 		if ( ! $t['public'] )
       
   969 			continue;
  1058 		if ( empty($t['label']) )
   970 		if ( empty($t['label']) )
  1059 			$t['label'] = $taxonomy;
   971 			$t['label'] = $taxonomy;
  1060 		if ( empty($t['args']) )
   972 		if ( empty($t['args']) )
  1061 			$t['args'] = array();
   973 			$t['args'] = array();
  1062 
   974 
  1087  *
   999  *
  1088  * The HTML markup retrieved will be created for the progress of SWF Upload
  1000  * The HTML markup retrieved will be created for the progress of SWF Upload
  1089  * component. Will also create link for showing and hiding the form to modify
  1001  * component. Will also create link for showing and hiding the form to modify
  1090  * the image attachment.
  1002  * the image attachment.
  1091  *
  1003  *
  1092  * @since unknown
  1004  * @since 2.5.0
  1093  *
  1005  *
  1094  * @param int $post_id Optional. Post ID.
  1006  * @param int $post_id Optional. Post ID.
  1095  * @param array $errors Errors for attachment, if any.
  1007  * @param array $errors Errors for attachment, if any.
  1096  * @return string
  1008  * @return string
  1097  */
  1009  */
  1098 function get_media_items( $post_id, $errors ) {
  1010 function get_media_items( $post_id, $errors ) {
       
  1011 	$attachments = array();
  1099 	if ( $post_id ) {
  1012 	if ( $post_id ) {
  1100 		$post = get_post($post_id);
  1013 		$post = get_post($post_id);
  1101 		if ( $post && $post->post_type == 'attachment' )
  1014 		if ( $post && $post->post_type == 'attachment' )
  1102 			$attachments = array($post->ID => $post);
  1015 			$attachments = array($post->ID => $post);
  1103 		else
  1016 		else
  1111 	$output = '';
  1024 	$output = '';
  1112 	foreach ( (array) $attachments as $id => $attachment ) {
  1025 	foreach ( (array) $attachments as $id => $attachment ) {
  1113 		if ( $attachment->post_status == 'trash' )
  1026 		if ( $attachment->post_status == 'trash' )
  1114 			continue;
  1027 			continue;
  1115 		if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
  1028 		if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
  1116 			$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div>$item\n</div>";
  1029 			$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-$id' class='hidden'></div><div class='filename hidden'></div>$item\n</div>";
  1117 	}
  1030 	}
  1118 
  1031 
  1119 	return $output;
  1032 	return $output;
  1120 }
  1033 }
  1121 
  1034 
  1122 /**
  1035 /**
  1123  * Retrieve HTML form for modifying the image attachment.
  1036  * Retrieve HTML form for modifying the image attachment.
  1124  *
  1037  *
  1125  * @since unknown
  1038  * @since 2.5.0
  1126  *
  1039  *
  1127  * @param int $attachment_id Attachment ID for modification.
  1040  * @param int $attachment_id Attachment ID for modification.
  1128  * @param string|array $args Optional. Override defaults.
  1041  * @param string|array $args Optional. Override defaults.
  1129  * @return string HTML form for attachment.
  1042  * @return string HTML form for attachment.
  1130  */
  1043  */
  1131 function get_media_item( $attachment_id, $args = null ) {
  1044 function get_media_item( $attachment_id, $args = null ) {
  1132 	global $redir_tab;
  1045 	global $redir_tab;
  1133 
  1046 
  1134 	if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
  1047 	if ( ( $attachment_id = intval( $attachment_id ) ) && $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) )
  1135 		$thumb_url = $thumb_url[0];
  1048 		$thumb_url = $thumb_url[0];
  1136 	else
  1049 	else
  1137 		return false;
  1050 		$thumb_url = false;
  1138 
  1051 
  1139 	$default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true );
  1052 	$post = get_post( $attachment_id );
       
  1053 	$current_post_id = !empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0;
       
  1054 
       
  1055 	$default_args = array( 'errors' => null, 'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true, 'delete' => true, 'toggle' => true, 'show_title' => true );
  1140 	$args = wp_parse_args( $args, $default_args );
  1056 	$args = wp_parse_args( $args, $default_args );
       
  1057 	$args = apply_filters( 'get_media_item_args', $args );
  1141 	extract( $args, EXTR_SKIP );
  1058 	extract( $args, EXTR_SKIP );
  1142 
  1059 
  1143 	$toggle_on = __('Show');
  1060 	$toggle_on  = __( 'Show' );
  1144 	$toggle_off = __('Hide');
  1061 	$toggle_off = __( 'Hide' );
  1145 
  1062 
  1146 	$post = get_post($attachment_id);
  1063 	$filename = esc_html( basename( $post->guid ) );
  1147 
  1064 	$title = esc_attr( $post->post_title );
  1148 	$filename = basename($post->guid);
  1065 
  1149 	$title = esc_attr($post->post_title);
  1066 	if ( $_tags = get_the_tags( $attachment_id ) ) {
  1150 
       
  1151 	if ( $_tags = get_the_tags($attachment_id) ) {
       
  1152 		foreach ( $_tags as $tag )
  1067 		foreach ( $_tags as $tag )
  1153 			$tags[] = $tag->name;
  1068 			$tags[] = $tag->name;
  1154 		$tags = esc_attr(join(', ', $tags));
  1069 		$tags = esc_attr( join( ', ', $tags ) );
  1155 	}
  1070 	}
  1156 
  1071 
  1157 	$post_mime_types = get_post_mime_types();
  1072 	$post_mime_types = get_post_mime_types();
  1158 	$keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
  1073 	$keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
  1159 	$type = array_shift($keys);
  1074 	$type = array_shift( $keys );
  1160 	$type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
  1075 	$type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
  1161 
  1076 
  1162 	$form_fields = get_attachment_fields_to_edit($post, $errors);
  1077 	$form_fields = get_attachment_fields_to_edit( $post, $errors );
  1163 
  1078 
  1164 	if ( $toggle ) {
  1079 	if ( $toggle ) {
  1165 		$class = empty($errors) ? 'startclosed' : 'startopen';
  1080 		$class = empty( $errors ) ? 'startclosed' : 'startopen';
  1166 		$toggle_links = "
  1081 		$toggle_links = "
  1167 	<a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
  1082 	<a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
  1168 	<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
  1083 	<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
  1169 	} else {
  1084 	} else {
  1170 		$class = 'form-table';
  1085 		$class = '';
  1171 		$toggle_links = '';
  1086 		$toggle_links = '';
  1172 	}
  1087 	}
  1173 
  1088 
  1174 	$display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
  1089 	$display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
  1175 	$display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt($display_title, 60) . "</span></div>" : '';
  1090 	$display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60 ) . "</span></div>" : '';
  1176 
  1091 
  1177 	$gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
  1092 	$gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
  1178 	$order = '';
  1093 	$order = '';
  1179 
  1094 
  1180 	foreach ( $form_fields as $key => $val ) {
  1095 	foreach ( $form_fields as $key => $val ) {
  1181 		if ( 'menu_order' == $key ) {
  1096 		if ( 'menu_order' == $key ) {
  1182 			if ( $gallery )
  1097 			if ( $gallery )
  1183 				$order = '<div class="menu_order"> <input class="menu_order_input" type="text" id="attachments['.$attachment_id.'][menu_order]" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" /></div>';
  1098 				$order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>";
  1184 			else
  1099 			else
  1185 				$order = '<input type="hidden" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" />';
  1100 				$order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
  1186 
  1101 
  1187 			unset($form_fields['menu_order']);
  1102 			unset( $form_fields['menu_order'] );
  1188 			break;
  1103 			break;
  1189 		}
  1104 		}
  1190 	}
  1105 	}
  1191 
  1106 
  1192 	$media_dims = '';
  1107 	$media_dims = '';
  1193 	$meta = wp_get_attachment_metadata($post->ID);
  1108 	$meta = wp_get_attachment_metadata( $post->ID );
  1194 	if ( is_array($meta) && array_key_exists('width', $meta) && array_key_exists('height', $meta) )
  1109 	if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
  1195 		$media_dims .= "<span id='media-dims-{$post->ID}'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
  1110 		$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
  1196 	$media_dims = apply_filters('media_meta', $media_dims, $post);
  1111 	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
  1197 
  1112 
  1198 	$image_edit_button = '';
  1113 	$image_edit_button = '';
  1199 	if ( gd_edit_image_support($post->post_mime_type) ) {
  1114 	if ( gd_edit_image_support( $post->post_mime_type ) ) {
  1200 		$nonce = wp_create_nonce("image_editor-$post->ID");
  1115 		$nonce = wp_create_nonce( "image_editor-$post->ID" );
  1201 		$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='images/wpspin_light.gif' class='imgedit-wait-spin' alt='' />";
  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='' />";
  1202 	}
  1117 	}
       
  1118 
       
  1119 	$attachment_url = get_permalink( $attachment_id );
  1203 
  1120 
  1204 	$item = "
  1121 	$item = "
  1205 	$type_html
  1122 	$type_html
  1206 	$toggle_links
  1123 	$toggle_links
  1207 	$order
  1124 	$order
  1208 	$display_title
  1125 	$display_title
  1209 	<table class='slidetoggle describe $class'>
  1126 	<table class='slidetoggle describe $class'>
  1210 		<thead class='media-item-info' id='media-head-$post->ID'>
  1127 		<thead class='media-item-info' id='media-head-$post->ID'>
  1211 		<tr>
  1128 		<tr valign='top'>
  1212 			<td class='A1B1' id='thumbnail-head-$post->ID' rowspan='5'><img class='thumbnail' src='$thumb_url' alt='' /></td>
  1129 			<td class='A1B1' id='thumbnail-head-$post->ID'>
  1213 			<td><strong>" . __('File name:') . "</strong> $filename</td>
  1130 			<p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p>
  1214 		</tr>
  1131 			<p>$image_edit_button</p>
  1215 		<tr><td><strong>" . __('File type:') . "</strong> $post->post_mime_type</td></tr>
  1132 			</td>
  1216 		<tr><td><strong>" . __('Upload date:') . "</strong> " . mysql2date( get_option('date_format'), $post->post_date ) . "</td></tr>\n";
  1133 			<td>
  1217 
  1134 			<p><strong>" . __('File name:') . "</strong> $filename</p>
  1218 	if ( !empty($media_dims) )
  1135 			<p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p>
  1219 		$item .= "<tr><td><strong>" . __('Dimensions:') . "</strong> $media_dims</td></tr>\n";
  1136 			<p><strong>" . __('Upload date:') . "</strong> " . mysql2date( get_option('date_format'), $post->post_date ). '</p>';
       
  1137 			if ( !empty( $media_dims ) )
       
  1138 				$item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n";
       
  1139 
       
  1140 			$item .= "</td></tr>\n";
  1220 
  1141 
  1221 	$item .= "
  1142 	$item .= "
  1222 		<tr><td class='A1B1'>$image_edit_button</td></tr>
       
  1223 		</thead>
  1143 		</thead>
  1224 		<tbody>
  1144 		<tbody>
  1225 		<tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>
  1145 		<tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>
  1226 		<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n";
  1146 		<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n";
  1227 
  1147 
  1231 		'value'      => '',
  1151 		'value'      => '',
  1232 		'extra_rows' => array(),
  1152 		'extra_rows' => array(),
  1233 	);
  1153 	);
  1234 
  1154 
  1235 	if ( $send )
  1155 	if ( $send )
  1236 		$send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . esc_attr__( 'Insert into Post' ) . "' />";
  1156 		$send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false );
  1237 	if ( $delete && current_user_can('delete_post', $attachment_id) ) {
  1157 	if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
  1238 		if ( !EMPTY_TRASH_DAYS ) {
  1158 		if ( !EMPTY_TRASH_DAYS ) {
  1239 			$delete = "<a href=\"" . wp_nonce_url("post.php?action=delete&amp;post=$attachment_id", 'delete-post_' . $attachment_id) . "\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Delete Permanently') . "</a>";
  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>';
  1240 		} elseif ( !MEDIA_TRASH ) {
  1160 		} elseif ( !MEDIA_TRASH ) {
  1241 			$delete = "<a href=\"#\" class=\"del-link\" onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __('Delete') . "</a> <div id=\"del_attachment_$attachment_id\" class=\"del-attachment\" style=\"display:none;\">" . sprintf(__("You are about to delete <strong>%s</strong>."), $filename) . " <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> <a href=\"#\" class=\"button\" onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a></div>";
  1161 			$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>
       
  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>
       
  1164 			 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a>
       
  1165 			 </div>";
  1242 		} else {
  1166 		} else {
  1243 			$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> <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>";
  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>
       
  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>";
  1244 		}
  1169 		}
  1245 	} else {
  1170 	} else {
  1246 		$delete = '';
  1171 		$delete = '';
  1247 	}
  1172 	}
  1248 
  1173 
  1249 	$thumbnail = '';
  1174 	$thumbnail = '';
  1250 	$calling_post_id = 0;
  1175 	$calling_post_id = 0;
  1251 	if ( isset( $_GET['post_id'] ) )
  1176 	if ( isset( $_GET['post_id'] ) )
  1252 		$calling_post_id = $_GET['post_id'];
  1177 		$calling_post_id = absint( $_GET['post_id'] );
  1253 	elseif ( isset( $_POST ) && count( $_POST ) ) // Like for async-upload where $_GET['post_id'] isn't set
  1178 	elseif ( isset( $_POST ) && count( $_POST ) ) // Like for async-upload where $_GET['post_id'] isn't set
  1254 		$calling_post_id = $post->post_parent;
  1179 		$calling_post_id = $post->post_parent;
  1255 	if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id )
  1180 	if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) )
  1256 		$thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\");return false;'>" . esc_html__( "Use as thumbnail" ) . "</a>";
  1181 		&& post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) {
  1257 
  1182 		$ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
  1258 	if ( ( $send || $thumbnail || $delete ) && !isset($form_fields['buttons']) )
  1183 		$thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>";
  1259 		$form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n");
  1184 	}
       
  1185 
       
  1186 	if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) )
       
  1187 		$form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n" );
  1260 
  1188 
  1261 	$hidden_fields = array();
  1189 	$hidden_fields = array();
  1262 
  1190 
  1263 	foreach ( $form_fields as $id => $field ) {
  1191 	foreach ( $form_fields as $id => $field ) {
  1264 		if ( $id{0} == '_' )
  1192 		if ( $id[0] == '_' )
  1265 			continue;
  1193 			continue;
  1266 
  1194 
  1267 		if ( !empty($field['tr']) ) {
  1195 		if ( !empty( $field['tr'] ) ) {
  1268 			$item .= $field['tr'];
  1196 			$item .= $field['tr'];
  1269 			continue;
  1197 			continue;
  1270 		}
  1198 		}
  1271 
  1199 
  1272 		$field = array_merge($defaults, $field);
  1200 		$field = array_merge( $defaults, $field );
  1273 		$name = "attachments[$attachment_id][$id]";
  1201 		$name = "attachments[$attachment_id][$id]";
  1274 
  1202 
  1275 		if ( $field['input'] == 'hidden' ) {
  1203 		if ( $field['input'] == 'hidden' ) {
  1276 			$hidden_fields[$name] = $field['value'];
  1204 			$hidden_fields[$name] = $field['value'];
  1277 			continue;
  1205 			continue;
  1278 		}
  1206 		}
  1279 
  1207 
  1280 		$required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
  1208 		$required      = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
  1281 		$aria_required = $field['required'] ? " aria-required='true' " : '';
  1209 		$aria_required = $field['required'] ? " aria-required='true' " : '';
  1282 		$class  = $id;
  1210 		$class  = $id;
  1283 		$class .= $field['required'] ? ' form-required' : '';
  1211 		$class .= $field['required'] ? ' form-required' : '';
  1284 
  1212 
  1285 		$item .= "\t\t<tr class='$class'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span><span class='alignright'>$required</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>";
  1213 		$item .= "\t\t<tr class='$class'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label></th>\n\t\t\t<td class='field'>";
  1286 		if ( !empty($field[$field['input']]) )
  1214 		if ( !empty( $field[ $field['input'] ] ) )
  1287 			$item .= $field[$field['input']];
  1215 			$item .= $field[ $field['input'] ];
  1288 		elseif ( $field['input'] == 'textarea' ) {
  1216 		elseif ( $field['input'] == 'textarea' ) {
  1289 			$item .= "<textarea type='text' id='$name' name='$name'" . $aria_required . ">" . esc_html( $field['value'] ) . "</textarea>";
  1217 			if ( 'post_content' == $id && user_can_richedit() ) {
       
  1218 				// sanitize_post() skips the post_content when user_can_richedit
       
  1219 				$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
       
  1220 			}
       
  1221 			// post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit()
       
  1222 			$item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>';
  1290 		} else {
  1223 		} else {
  1291 			$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'" . $aria_required . "/>";
  1224 			$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
  1292 		}
  1225 		}
  1293 		if ( !empty($field['helps']) )
  1226 		if ( !empty( $field['helps'] ) )
  1294 			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique((array) $field['helps']) ) . '</p>';
  1227 			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
  1295 		$item .= "</td>\n\t\t</tr>\n";
  1228 		$item .= "</td>\n\t\t</tr>\n";
  1296 
  1229 
  1297 		$extra_rows = array();
  1230 		$extra_rows = array();
  1298 
  1231 
  1299 		if ( !empty($field['errors']) )
  1232 		if ( !empty( $field['errors'] ) )
  1300 			foreach ( array_unique((array) $field['errors']) as $error )
  1233 			foreach ( array_unique( (array) $field['errors'] ) as $error )
  1301 				$extra_rows['error'][] = $error;
  1234 				$extra_rows['error'][] = $error;
  1302 
  1235 
  1303 		if ( !empty($field['extra_rows']) )
  1236 		if ( !empty( $field['extra_rows'] ) )
  1304 			foreach ( $field['extra_rows'] as $class => $rows )
  1237 			foreach ( $field['extra_rows'] as $class => $rows )
  1305 				foreach ( (array) $rows as $html )
  1238 				foreach ( (array) $rows as $html )
  1306 					$extra_rows[$class][] = $html;
  1239 					$extra_rows[$class][] = $html;
  1307 
  1240 
  1308 		foreach ( $extra_rows as $class => $rows )
  1241 		foreach ( $extra_rows as $class => $rows )
  1309 			foreach ( $rows as $html )
  1242 			foreach ( $rows as $html )
  1310 				$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
  1243 				$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
  1311 	}
  1244 	}
  1312 
  1245 
  1313 	if ( !empty($form_fields['_final']) )
  1246 	if ( !empty( $form_fields['_final'] ) )
  1314 		$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
  1247 		$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
  1315 	$item .= "\t</tbody>\n";
  1248 	$item .= "\t</tbody>\n";
  1316 	$item .= "\t</table>\n";
  1249 	$item .= "\t</table>\n";
  1317 
  1250 
  1318 	foreach ( $hidden_fields as $name => $value )
  1251 	foreach ( $hidden_fields as $name => $value )
  1319 		$item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
  1252 		$item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
  1320 
  1253 
  1321 	if ( $post->post_parent < 1 && isset($_REQUEST['post_id']) ) {
  1254 	if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) {
  1322 		$parent = (int) $_REQUEST['post_id'];
  1255 		$parent = (int) $_REQUEST['post_id'];
  1323 		$parent_name = "attachments[$attachment_id][post_parent]";
  1256 		$parent_name = "attachments[$attachment_id][post_parent]";
  1324 
  1257 		$item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n";
  1325 		$item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='" . $parent . "' />\n";
       
  1326 	}
  1258 	}
  1327 
  1259 
  1328 	return $item;
  1260 	return $item;
  1329 }
  1261 }
  1330 
  1262 
  1331 /**
  1263 /**
  1332  * {@internal Missing Short Description}}
  1264  * {@internal Missing Short Description}}
  1333  *
  1265  *
  1334  * @since unknown
  1266  * @since 2.5.0
  1335  */
  1267  */
  1336 function media_upload_header() {
  1268 function media_upload_header() {
  1337 	?>
  1269 	?>
  1338 	<script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
  1270 	<script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
  1339 	<div id="media-upload-header">
  1271 	<div id="media-upload-header">
  1343 }
  1275 }
  1344 
  1276 
  1345 /**
  1277 /**
  1346  * {@internal Missing Short Description}}
  1278  * {@internal Missing Short Description}}
  1347  *
  1279  *
  1348  * @since unknown
  1280  * @since 2.5.0
  1349  *
  1281  *
  1350  * @param unknown_type $errors
  1282  * @param unknown_type $errors
  1351  */
  1283  */
  1352 function media_upload_form( $errors = null ) {
  1284 function media_upload_form( $errors = null ) {
  1353 	global $type, $tab;
  1285 	global $type, $tab, $pagenow, $is_IE, $is_opera;
  1354 
  1286 
  1355 	$flash_action_url = admin_url('async-upload.php');
  1287 	if ( ! _device_can_upload() ) {
  1356 
  1288 		echo '<p>' . __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="http://wordpress.org/extend/mobile/">native app for your device</a> instead.') . '</p>';
  1357 	// If Mac and mod_security, no Flash. :(
  1289 		return;
  1358 	$flash = true;
  1290 	}
  1359 	if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') )
  1291 
  1360 		$flash = false;
  1292 	$upload_action_url = admin_url('async-upload.php');
  1361 
       
  1362 	$flash = apply_filters('flash_uploader', $flash);
       
  1363 	$post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
  1293 	$post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
  1364 
  1294 	$_type = isset($type) ? $type : '';
       
  1295 	$_tab = isset($tab) ? $tab : '';
       
  1296 
       
  1297 	$upload_size_unit = $max_upload_size = wp_max_upload_size();
       
  1298 	$sizes = array( 'KB', 'MB', 'GB' );
       
  1299 
       
  1300 	for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
       
  1301 		$upload_size_unit /= 1024;
       
  1302 	}
       
  1303 
       
  1304 	if ( $u < 0 ) {
       
  1305 		$upload_size_unit = 0;
       
  1306 		$u = 0;
       
  1307 	} else {
       
  1308 		$upload_size_unit = (int) $upload_size_unit;
       
  1309 	}
  1365 ?>
  1310 ?>
       
  1311 
       
  1312 <div id="media-upload-notice"><?php
       
  1313 
       
  1314 	if (isset($errors['upload_notice']) )
       
  1315 		echo $errors['upload_notice'];
       
  1316 
       
  1317 ?></div>
       
  1318 <div id="media-upload-error"><?php
       
  1319 
       
  1320 	if (isset($errors['upload_error']) && is_wp_error($errors['upload_error']))
       
  1321 		echo $errors['upload_error']->get_error_message();
       
  1322 
       
  1323 ?></div>
       
  1324 <?php
       
  1325 // Check quota for this blog if multisite
       
  1326 if ( is_multisite() && !is_upload_space_available() ) {
       
  1327 	echo '<p>' . sprintf( __( 'Sorry, you have filled your storage quota (%s MB).' ), get_space_allowed() ) . '</p>';
       
  1328 	return;
       
  1329 }
       
  1330 
       
  1331 do_action('pre-upload-ui');
       
  1332 
       
  1333 $post_params = array(
       
  1334 		"post_id" => $post_id,
       
  1335 		"_wpnonce" => wp_create_nonce('media-form'),
       
  1336 		"type" => $_type,
       
  1337 		"tab" => $_tab,
       
  1338 		"short" => "1",
       
  1339 );
       
  1340 
       
  1341 $post_params = apply_filters( 'upload_post_params', $post_params ); // hook change! old name: 'swfupload_post_params'
       
  1342 
       
  1343 $plupload_init = array(
       
  1344 	'runtimes' => 'html5,silverlight,flash,html4',
       
  1345 	'browse_button' => 'plupload-browse-button',
       
  1346 	'container' => 'plupload-upload-ui',
       
  1347 	'drop_element' => 'drag-drop-area',
       
  1348 	'file_data_name' => 'async-upload',
       
  1349 	'multiple_queues' => true,
       
  1350 	'max_file_size' => $max_upload_size . 'b',
       
  1351 	'url' => $upload_action_url,
       
  1352 	'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
       
  1353 	'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
       
  1354 	'filters' => array( array('title' => __( 'Allowed Files' ), 'extensions' => '*') ),
       
  1355 	'multipart' => true,
       
  1356 	'urlstream_upload' => true,
       
  1357 	'multipart_params' => $post_params
       
  1358 );
       
  1359 
       
  1360 $plupload_init = apply_filters( 'plupload_init', $plupload_init );
       
  1361 
       
  1362 ?>
       
  1363 
  1366 <script type="text/javascript">
  1364 <script type="text/javascript">
  1367 //<![CDATA[
  1365 <?php
  1368 var uploaderMode = 0;
  1366 // Verify size is an int. If not return default value.
  1369 jQuery(document).ready(function($){
  1367 $large_size_h = absint( get_option('large_size_h') );
  1370 	uploaderMode = getUserSetting('uploader');
  1368 if( !$large_size_h )
  1371 	$('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;});
  1369 	$large_size_h = 1024;
  1372 	$('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;});
  1370 $large_size_w = absint( get_option('large_size_w') );
  1373 });
  1371 if( !$large_size_w )
  1374 //]]>
  1372 	$large_size_w = 1024;
       
  1373 ?>
       
  1374 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>,
       
  1375 wpUploaderInit = <?php echo json_encode($plupload_init); ?>;
  1375 </script>
  1376 </script>
  1376 <div id="media-upload-notice">
  1377 
  1377 <?php if (isset($errors['upload_notice']) ) { ?>
  1378 <div id="plupload-upload-ui" class="hide-if-no-js">
  1378 	<?php echo $errors['upload_notice']; ?>
  1379 <?php do_action('pre-plupload-upload-ui'); // hook change, old name: 'pre-flash-upload-ui' ?>
  1379 <?php } ?>
  1380 <div id="drag-drop-area">
       
  1381 	<div class="drag-drop-inside">
       
  1382 	<p class="drag-drop-info"><?php _e('Drop files here'); ?></p>
       
  1383 	<p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p>
       
  1384 	<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p>
       
  1385 	</div>
  1380 </div>
  1386 </div>
  1381 <div id="media-upload-error">
  1387 <?php do_action('post-plupload-upload-ui'); // hook change, old name: 'post-flash-upload-ui' ?>
  1382 <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>
       
  1383 	<?php echo $errors['upload_error']->get_error_message(); ?>
       
  1384 <?php } ?>
       
  1385 </div>
  1388 </div>
  1386 
  1389 
  1387 <?php do_action('pre-upload-ui'); ?>
  1390 <div id="html-upload-ui" class="hide-if-js">
  1388 
       
  1389 <?php if ( $flash ) : ?>
       
  1390 <script type="text/javascript">
       
  1391 //<![CDATA[
       
  1392 var swfu;
       
  1393 SWFUpload.onload = function() {
       
  1394 	var settings = {
       
  1395 			button_text: '<span class="button"><?php _e('Select Files'); ?></span>',
       
  1396 			button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; }',
       
  1397 			button_height: "24",
       
  1398 			button_width: "132",
       
  1399 			button_text_top_padding: 2,
       
  1400 			button_image_url: '<?php echo includes_url('images/upload.png'); ?>',
       
  1401 			button_placeholder_id: "flash-browse-button",
       
  1402 			upload_url : "<?php echo esc_attr( $flash_action_url ); ?>",
       
  1403 			flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",
       
  1404 			file_post_name: "async-upload",
       
  1405 			file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
       
  1406 			post_params : {
       
  1407 				"post_id" : "<?php echo $post_id; ?>",
       
  1408 				"auth_cookie" : "<?php if ( is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>",
       
  1409 				"logged_in_cookie": "<?php echo $_COOKIE[LOGGED_IN_COOKIE]; ?>",
       
  1410 				"_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>",
       
  1411 				"type" : "<?php echo $type; ?>",
       
  1412 				"tab" : "<?php echo $tab; ?>",
       
  1413 				"short" : "1"
       
  1414 			},
       
  1415 			file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
       
  1416 			file_dialog_start_handler : fileDialogStart,
       
  1417 			file_queued_handler : fileQueued,
       
  1418 			upload_start_handler : uploadStart,
       
  1419 			upload_progress_handler : uploadProgress,
       
  1420 			upload_error_handler : uploadError,
       
  1421 			upload_success_handler : uploadSuccess,
       
  1422 			upload_complete_handler : uploadComplete,
       
  1423 			file_queue_error_handler : fileQueueError,
       
  1424 			file_dialog_complete_handler : fileDialogComplete,
       
  1425 			swfupload_pre_load_handler: swfuploadPreLoad,
       
  1426 			swfupload_load_failed_handler: swfuploadLoadFailed,
       
  1427 			custom_settings : {
       
  1428 				degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable
       
  1429 				swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available
       
  1430 			},
       
  1431 			debug: false
       
  1432 		};
       
  1433 		swfu = new SWFUpload(settings);
       
  1434 };
       
  1435 //]]>
       
  1436 </script>
       
  1437 
       
  1438 <div id="flash-upload-ui">
       
  1439 <?php do_action('pre-flash-upload-ui'); ?>
       
  1440 
       
  1441 	<div>
       
  1442 	<?php _e( 'Choose files to upload' ); ?>
       
  1443 	<div id="flash-browse-button"></div>
       
  1444 	<span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span>
       
  1445 	</div>
       
  1446 <?php do_action('post-flash-upload-ui'); ?>
       
  1447 	<p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
       
  1448 </div>
       
  1449 <?php endif; // $flash ?>
       
  1450 
       
  1451 <div id="html-upload-ui">
       
  1452 <?php do_action('pre-html-upload-ui'); ?>
  1391 <?php do_action('pre-html-upload-ui'); ?>
  1453 	<p id="async-upload-wrap">
  1392 	<p id="async-upload-wrap">
  1454 	<label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
  1393 		<label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
  1455 	<input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" name="html-upload" value="<?php esc_attr_e('Upload'); ?>" /> <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>
  1394 		<input type="file" name="async-upload" id="async-upload" />
       
  1395 		<?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?>
       
  1396 		<a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>
  1456 	</p>
  1397 	</p>
  1457 	<div class="clear"></div>
  1398 	<div class="clear"></div>
  1458 	<?php if ( is_lighttpd_before_150() ): ?>
  1399 <?php do_action('post-html-upload-ui'); ?>
  1459 	<p><?php _e('If you want to use all capabilities of the uploader, like uploading multiple files at once, please upgrade to lighttpd 1.5.'); ?></p>
       
  1460 	<?php endif;?>
       
  1461 <?php do_action('post-html-upload-ui', $flash); ?>
       
  1462 </div>
  1400 </div>
  1463 <?php do_action('post-upload-ui'); ?>
  1401 
       
  1402 <span class="max-upload-size"><?php printf( __( 'Maximum upload file size: %d%s.' ), esc_html($upload_size_unit), esc_html($sizes[$u]) ); ?></span>
  1464 <?php
  1403 <?php
  1465 }
  1404 if ( ($is_IE || $is_opera) && $max_upload_size > 100 * 1024 * 1024 ) { ?>
  1466 
  1405 	<span class="big-file-warning"><?php _e('Your browser has some limitations uploading large files with the multi-file uploader. Please use the browser uploader for files over 100MB.'); ?></span>
  1467 /**
  1406 <?php }
  1468  * {@internal Missing Short Description}}
  1407 
  1469  *
  1408 	do_action('post-upload-ui');
  1470  * @since unknown
  1409 }
       
  1410 
       
  1411 /**
       
  1412  * {@internal Missing Short Description}}
       
  1413  *
       
  1414  * @since 2.5.0
  1471  *
  1415  *
  1472  * @param unknown_type $type
  1416  * @param unknown_type $type
  1473  * @param unknown_type $errors
  1417  * @param unknown_type $errors
  1474  * @param unknown_type $id
  1418  * @param unknown_type $id
  1475  */
  1419  */
  1476 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
  1420 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
       
  1421 
  1477 	media_upload_header();
  1422 	media_upload_header();
  1478 
  1423 
  1479 	$post_id = intval($_REQUEST['post_id']);
  1424 	$post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0;
  1480 
  1425 
  1481 	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
  1426 	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
  1482 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1427 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
       
  1428 	$form_class = 'media-upload-form type-form validate';
       
  1429 
       
  1430 	if ( get_user_setting('uploader') )
       
  1431 		$form_class .= ' html-uploader';
  1483 ?>
  1432 ?>
  1484 
  1433 
  1485 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form">
  1434 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
  1486 <input type="submit" class="hidden" name="save" value="" />
  1435 <?php submit_button( '', 'hidden', 'save', false ); ?>
  1487 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1436 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1488 <?php wp_nonce_field('media-form'); ?>
  1437 <?php wp_nonce_field('media-form'); ?>
  1489 
  1438 
  1490 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
  1439 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
  1491 
  1440 
  1500 	}
  1449 	}
  1501 	updateMediaForm();
  1450 	updateMediaForm();
  1502 });
  1451 });
  1503 //]]>
  1452 //]]>
  1504 </script>
  1453 </script>
  1505 <div id="media-items">
  1454 <div id="media-items"><?php
  1506 <?php
  1455 
  1507 if ( $id ) {
  1456 if ( $id ) {
  1508 	if ( !is_wp_error($id) ) {
  1457 	if ( !is_wp_error($id) ) {
  1509 		add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
  1458 		add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
  1510 		echo get_media_items( $id, $errors );
  1459 		echo get_media_items( $id, $errors );
  1511 	} else {
  1460 	} else {
  1512 		echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div>';
  1461 		echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div></div>';
  1513 		exit;
  1462 		exit;
  1514 	}
  1463 	}
  1515 }
  1464 }
  1516 ?>
  1465 ?></div>
  1517 </div>
  1466 
  1518 <p class="savebutton ml-submit">
  1467 <p class="savebutton ml-submit">
  1519 <input type="submit" class="button" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
  1468 <?php submit_button( __( 'Save all changes' ), 'button', 'save', false ); ?>
  1520 </p>
  1469 </p>
       
  1470 </form>
  1521 <?php
  1471 <?php
  1522 }
  1472 }
  1523 
  1473 
  1524 /**
  1474 /**
  1525  * {@internal Missing Short Description}}
  1475  * {@internal Missing Short Description}}
  1526  *
  1476  *
  1527  * @since unknown
  1477  * @since 2.7.0
  1528  *
  1478  *
  1529  * @param unknown_type $type
  1479  * @param unknown_type $type
  1530  * @param unknown_type $errors
  1480  * @param unknown_type $errors
  1531  * @param unknown_type $id
  1481  * @param unknown_type $id
  1532  */
  1482  */
  1533 function media_upload_type_url_form($type = 'file', $errors = null, $id = null) {
  1483 function media_upload_type_url_form($type = null, $errors = null, $id = null) {
       
  1484 	if ( null === $type )
       
  1485 		$type = 'image';
       
  1486 
  1534 	media_upload_header();
  1487 	media_upload_header();
  1535 
  1488 
  1536 	$post_id = intval($_REQUEST['post_id']);
  1489 	$post_id = intval($_REQUEST['post_id']);
  1537 
  1490 
  1538 	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
  1491 	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
  1539 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1492 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1540 
  1493 	$form_class = 'media-upload-form type-form validate';
  1541 	$callback = "type_url_form_$type";
  1494 
       
  1495 	if ( get_user_setting('uploader') )
       
  1496 		$form_class .= ' html-uploader';
  1542 ?>
  1497 ?>
  1543 
  1498 
  1544 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form">
  1499 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
  1545 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1500 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1546 <?php wp_nonce_field('media-form'); ?>
  1501 <?php wp_nonce_field('media-form'); ?>
  1547 
  1502 
  1548 <?php if ( is_callable($callback) ) { ?>
  1503 <h3 class="media-title"><?php _e('Insert media from another website'); ?></h3>
  1549 
       
  1550 <h3 class="media-title"><?php _e('Add media file from URL'); ?></h3>
       
  1551 
  1504 
  1552 <script type="text/javascript">
  1505 <script type="text/javascript">
  1553 //<![CDATA[
  1506 //<![CDATA[
  1554 var addExtImage = {
  1507 var addExtImage = {
  1555 
  1508 
  1570 
  1523 
  1571 		if ( f.alt.value )
  1524 		if ( f.alt.value )
  1572 			alt = f.alt.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1525 			alt = f.alt.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1573 
  1526 
  1574 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
  1527 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
  1575 		if ( f.caption.value )
  1528 		if ( f.caption.value ) {
  1576 			caption = f.caption.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1529 			caption = f.caption.value.replace(/\r\n|\r/g, '\n');
       
  1530 			caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
       
  1531 				return a.replace(/[\r\n\t]+/, ' ');
       
  1532 			});
       
  1533 
       
  1534 			caption = caption.replace(/\s*\n\s*/g, '<br />');
       
  1535 		}
  1577 <?php } ?>
  1536 <?php } ?>
  1578 
  1537 
  1579 		cls = caption ? '' : ' class="'+t.align+'"';
  1538 		cls = caption ? '' : ' class="'+t.align+'"';
  1580 
  1539 
  1581 		html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
  1540 		html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
  1582 
  1541 
  1583 		if ( f.url.value )
  1542 		if ( f.url.value ) {
  1584 			html = '<a href="'+f.url.value+'">'+html+'</a>';
  1543 			url = f.url.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
       
  1544 			html = '<a href="'+url+'">'+html+'</a>';
       
  1545 		}
  1585 
  1546 
  1586 		if ( caption )
  1547 		if ( caption )
  1587 			html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
  1548 			html = '[caption id="" align="'+t.align+'" width="'+t.width+'"]'+html+caption+'[/caption]';
  1588 
  1549 
  1589 		var win = window.dialogArguments || opener || parent || top;
  1550 		var win = window.dialogArguments || opener || parent || top;
  1590 		win.send_to_editor(html);
  1551 		win.send_to_editor(html);
  1591 		return false;
  1552 		return false;
  1592 	},
  1553 	},
  1596 
  1557 
  1597 		t.width = t.height = '';
  1558 		t.width = t.height = '';
  1598 		document.getElementById('go_button').style.color = '#bbb';
  1559 		document.getElementById('go_button').style.color = '#bbb';
  1599 		if ( ! document.forms[0].src.value )
  1560 		if ( ! document.forms[0].src.value )
  1600 			document.getElementById('status_img').innerHTML = '*';
  1561 			document.getElementById('status_img').innerHTML = '*';
  1601 		else document.getElementById('status_img').innerHTML = '<img src="images/no.png" alt="" />';
  1562 		else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />';
  1602 	},
  1563 	},
  1603 
  1564 
  1604 	updateImageData : function() {
  1565 	updateImageData : function() {
  1605 		var t = addExtImage;
  1566 		var t = addExtImage;
  1606 
  1567 
  1607 		t.width = t.preloadImg.width;
  1568 		t.width = t.preloadImg.width;
  1608 		t.height = t.preloadImg.height;
  1569 		t.height = t.preloadImg.height;
  1609 		document.getElementById('go_button').style.color = '#333';
  1570 		document.getElementById('go_button').style.color = '#333';
  1610 		document.getElementById('status_img').innerHTML = '<img src="images/yes.png" alt="" />';
  1571 		document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />';
  1611 	},
  1572 	},
  1612 
  1573 
  1613 	getImageData : function() {
  1574 	getImageData : function() {
       
  1575 		if ( jQuery('table.describe').hasClass('not-image') )
       
  1576 			return;
       
  1577 
  1614 		var t = addExtImage, src = document.forms[0].src.value;
  1578 		var t = addExtImage, src = document.forms[0].src.value;
  1615 
  1579 
  1616 		if ( ! src ) {
  1580 		if ( ! src ) {
  1617 			t.resetImageData();
  1581 			t.resetImageData();
  1618 			return false;
  1582 			return false;
  1619 		}
  1583 		}
  1620 		document.getElementById('status_img').innerHTML = '<img src="images/wpspin_light.gif" alt="" />';
  1584 
       
  1585 		document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />';
  1621 		t.preloadImg = new Image();
  1586 		t.preloadImg = new Image();
  1622 		t.preloadImg.onload = t.updateImageData;
  1587 		t.preloadImg.onload = t.updateImageData;
  1623 		t.preloadImg.onerror = t.resetImageData;
  1588 		t.preloadImg.onerror = t.resetImageData;
  1624 		t.preloadImg.src = src;
  1589 		t.preloadImg.src = src;
  1625 	}
  1590 	}
  1626 }
  1591 }
       
  1592 
       
  1593 jQuery(document).ready( function($) {
       
  1594 	$('.media-types input').click( function() {
       
  1595 		$('table.describe').toggleClass('not-image', $('#not-image').prop('checked') );
       
  1596 	});
       
  1597 });
       
  1598 
  1627 //]]>
  1599 //]]>
  1628 </script>
  1600 </script>
  1629 
  1601 
  1630 <div id="media-items">
  1602 <div id="media-items">
  1631 <div class="media-item media-blank">
  1603 <div class="media-item media-blank">
  1632 <?php echo apply_filters($callback, call_user_func($callback)); ?>
  1604 <?php echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) ); ?>
  1633 </div>
  1605 </div>
  1634 </div>
  1606 </div>
  1635 </form>
  1607 </form>
  1636 <?php
  1608 <?php
  1637 	} else {
  1609 }
  1638 		wp_die( __('Unknown action.') );
  1610 
  1639 	}
  1611 /**
  1640 }
  1612  * {@internal Missing Short Description}}
  1641 
  1613  *
  1642 /**
  1614  * @since 2.5.0
  1643  * {@internal Missing Short Description}}
       
  1644  *
       
  1645  * @since unknown
       
  1646  *
  1615  *
  1647  * @param unknown_type $errors
  1616  * @param unknown_type $errors
  1648  */
  1617  */
  1649 function media_upload_gallery_form($errors) {
  1618 function media_upload_gallery_form($errors) {
  1650 	global $redir_tab, $type;
  1619 	global $redir_tab, $type;
  1653 	media_upload_header();
  1622 	media_upload_header();
  1654 
  1623 
  1655 	$post_id = intval($_REQUEST['post_id']);
  1624 	$post_id = intval($_REQUEST['post_id']);
  1656 	$form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id");
  1625 	$form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id");
  1657 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1626 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
       
  1627 	$form_class = 'media-upload-form validate';
       
  1628 
       
  1629 	if ( get_user_setting('uploader') )
       
  1630 		$form_class .= ' html-uploader';
  1658 ?>
  1631 ?>
  1659 
  1632 
  1660 <script type="text/javascript">
  1633 <script type="text/javascript">
  1661 <!--
  1634 <!--
  1662 jQuery(function($){
  1635 jQuery(function($){
  1675 <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a>
  1648 <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a>
  1676 </span>
  1649 </span>
  1677 <?php _e('Sort Order:'); ?>
  1650 <?php _e('Sort Order:'); ?>
  1678 <a href="#" id="asc"><?php _e('Ascending'); ?></a> |
  1651 <a href="#" id="asc"><?php _e('Ascending'); ?></a> |
  1679 <a href="#" id="desc"><?php _e('Descending'); ?></a> |
  1652 <a href="#" id="desc"><?php _e('Descending'); ?></a> |
  1680 <a href="#" id="clear"><?php echo _x('Clear', 'verb'); ?></a>
  1653 <a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a>
  1681 </div>
  1654 </div>
  1682 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
  1655 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
  1683 <?php wp_nonce_field('media-form'); ?>
  1656 <?php wp_nonce_field('media-form'); ?>
  1684 <?php //media_upload_form( $errors ); ?>
  1657 <?php //media_upload_form( $errors ); ?>
  1685 <table class="widefat" cellspacing="0">
  1658 <table class="widefat" cellspacing="0">
  1686 <thead><tr>
  1659 <thead><tr>
  1687 <th><?php _e('Media'); ?></th>
  1660 <th><?php _e('Media'); ?></th>
  1693 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
  1666 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
  1694 <?php echo get_media_items($post_id, $errors); ?>
  1667 <?php echo get_media_items($post_id, $errors); ?>
  1695 </div>
  1668 </div>
  1696 
  1669 
  1697 <p class="ml-submit">
  1670 <p class="ml-submit">
  1698 <input type="submit" class="button savebutton" style="display:none;" name="save" id="save-all" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
  1671 <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false, array( 'id' => 'save-all', 'style' => 'display: none;' ) ); ?>
  1699 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1672 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1700 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
  1673 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
  1701 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
  1674 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
  1702 </p>
  1675 </p>
  1703 
  1676 
  1727 	</th>
  1700 	</th>
  1728 	<td class="field">
  1701 	<td class="field">
  1729 		<select id="orderby" name="orderby">
  1702 		<select id="orderby" name="orderby">
  1730 			<option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
  1703 			<option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
  1731 			<option value="title"><?php _e('Title'); ?></option>
  1704 			<option value="title"><?php _e('Title'); ?></option>
  1732 			<option value="ID"><?php _e('Date/Time'); ?></option>
  1705 			<option value="post_date"><?php _e('Date/Time'); ?></option>
  1733 			<option value="rand"><?php _e('Random'); ?></option>
  1706 			<option value="rand"><?php _e('Random'); ?></option>
  1734 		</select>
  1707 		</select>
  1735 	</td>
  1708 	</td>
  1736 	</tr>
  1709 	</tr>
  1737 
  1710 
  1756 		<span class="alignleft"><?php _e('Gallery columns:'); ?></span>
  1729 		<span class="alignleft"><?php _e('Gallery columns:'); ?></span>
  1757 		</label>
  1730 		</label>
  1758 	</th>
  1731 	</th>
  1759 	<td class="field">
  1732 	<td class="field">
  1760 		<select id="columns" name="columns">
  1733 		<select id="columns" name="columns">
  1761 			<option value="2"><?php _e('2'); ?></option>
  1734 			<option value="1">1</option>
  1762 			<option value="3" selected="selected"><?php _e('3'); ?></option>
  1735 			<option value="2">2</option>
  1763 			<option value="4"><?php _e('4'); ?></option>
  1736 			<option value="3" selected="selected">3</option>
  1764 			<option value="5"><?php _e('5'); ?></option>
  1737 			<option value="4">4</option>
  1765 			<option value="6"><?php _e('6'); ?></option>
  1738 			<option value="5">5</option>
  1766 			<option value="7"><?php _e('7'); ?></option>
  1739 			<option value="6">6</option>
  1767 			<option value="8"><?php _e('8'); ?></option>
  1740 			<option value="7">7</option>
  1768 			<option value="9"><?php _e('9'); ?></option>
  1741 			<option value="8">8</option>
       
  1742 			<option value="9">9</option>
  1769 		</select>
  1743 		</select>
  1770 	</td>
  1744 	</td>
  1771 	</tr>
  1745 	</tr>
  1772 </tbody></table>
  1746 </tbody></table>
  1773 
  1747 
  1774 <p class="ml-submit">
  1748 <p class="ml-submit">
  1775 <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
  1749 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
  1776 <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" />
  1750 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" />
  1777 </p>
  1751 </p>
  1778 </div>
  1752 </div>
  1779 </form>
  1753 </form>
  1780 <?php
  1754 <?php
  1781 }
  1755 }
  1782 
  1756 
  1783 /**
  1757 /**
  1784  * {@internal Missing Short Description}}
  1758  * {@internal Missing Short Description}}
  1785  *
  1759  *
  1786  * @since unknown
  1760  * @since 2.5.0
  1787  *
  1761  *
  1788  * @param unknown_type $errors
  1762  * @param unknown_type $errors
  1789  */
  1763  */
  1790 function media_upload_library_form($errors) {
  1764 function media_upload_library_form($errors) {
  1791 	global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
  1765 	global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
  1794 
  1768 
  1795 	$post_id = intval($_REQUEST['post_id']);
  1769 	$post_id = intval($_REQUEST['post_id']);
  1796 
  1770 
  1797 	$form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");
  1771 	$form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");
  1798 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1772 	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
       
  1773 	$form_class = 'media-upload-form validate';
       
  1774 
       
  1775 	if ( get_user_setting('uploader') )
       
  1776 		$form_class .= ' html-uploader';
  1799 
  1777 
  1800 	$_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
  1778 	$_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
  1801 	if ( $_GET['paged'] < 1 )
  1779 	if ( $_GET['paged'] < 1 )
  1802 		$_GET['paged'] = 1;
  1780 		$_GET['paged'] = 1;
  1803 	$start = ( $_GET['paged'] - 1 ) * 10;
  1781 	$start = ( $_GET['paged'] - 1 ) * 10;
  1804 	if ( $start < 1 )
  1782 	if ( $start < 1 )
  1805 		$start = 0;
  1783 		$start = 0;
  1806 	add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
  1784 	add_filter( 'post_limits', create_function( '$a', "return 'LIMIT $start, 10';" ) );
  1807 
  1785 
  1808 	list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
  1786 	list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
  1809 
  1787 
  1810 ?>
  1788 ?>
  1811 
  1789 
  1812 <form id="filter" action="" method="get">
  1790 <form id="filter" action="" method="get">
  1813 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
  1791 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
  1814 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
  1792 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
  1815 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
  1793 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
  1816 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
  1794 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
       
  1795 <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" />
  1817 
  1796 
  1818 <p id="media-search" class="search-box">
  1797 <p id="media-search" class="search-box">
  1819 	<label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label>
  1798 	<label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label>
  1820 	<input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
  1799 	<input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
  1821 	<input type="submit" value="<?php esc_attr_e( 'Search Media' ); ?>" class="button" />
  1800 	<?php submit_button( __( 'Search Media' ), 'button', '', false ); ?>
  1822 </p>
  1801 </p>
  1823 
  1802 
  1824 <ul class="subsubsub">
  1803 <ul class="subsubsub">
  1825 <?php
  1804 <?php
  1826 $type_links = array();
  1805 $type_links = array();
  1849 		continue;
  1828 		continue;
  1850 
  1829 
  1851 	if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
  1830 	if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
  1852 		$class = ' class="current"';
  1831 		$class = ' class="current"';
  1853 
  1832 
  1854 	$type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf(_n($label[2][0], $label[2][1], $num_posts[$mime_type]), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>';
  1833 	$type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>';
  1855 }
  1834 }
  1856 echo implode(' | </li>', $type_links) . '</li>';
  1835 echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>';
  1857 unset($type_links);
  1836 unset($type_links);
  1858 ?>
  1837 ?>
  1859 </ul>
  1838 </ul>
  1860 
  1839 
  1861 <div class="tablenav">
  1840 <div class="tablenav">
  1903 }
  1882 }
  1904 ?>
  1883 ?>
  1905 </select>
  1884 </select>
  1906 <?php } ?>
  1885 <?php } ?>
  1907 
  1886 
  1908 <input type="submit" id="post-query-submit" value="<?php echo esc_attr( __( 'Filter &#187;' ) ); ?>" class="button-secondary" />
  1887 <?php submit_button( __( 'Filter &#187;' ), 'secondary', 'post-query-submit', false ); ?>
  1909 
  1888 
  1910 </div>
  1889 </div>
  1911 
  1890 
  1912 <br class="clear" />
  1891 <br class="clear" />
  1913 </div>
  1892 </div>
  1914 </form>
  1893 </form>
  1915 
  1894 
  1916 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="library-form">
  1895 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="library-form">
  1917 
  1896 
  1918 <?php wp_nonce_field('media-form'); ?>
  1897 <?php wp_nonce_field('media-form'); ?>
  1919 <?php //media_upload_form( $errors ); ?>
  1898 <?php //media_upload_form( $errors ); ?>
  1920 
  1899 
  1921 <script type="text/javascript">
  1900 <script type="text/javascript">
  1933 <div id="media-items">
  1912 <div id="media-items">
  1934 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
  1913 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
  1935 <?php echo get_media_items(null, $errors); ?>
  1914 <?php echo get_media_items(null, $errors); ?>
  1936 </div>
  1915 </div>
  1937 <p class="ml-submit">
  1916 <p class="ml-submit">
  1938 <input type="submit" class="button savebutton" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
  1917 <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false ); ?>
  1939 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1918 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1940 </p>
  1919 </p>
  1941 </form>
  1920 </form>
  1942 <?php
  1921 <?php
  1943 }
  1922 }
  1944 
  1923 
  1945 /**
  1924 /**
  1946  * {@internal Missing Short Description}}
  1925  * {@internal Missing Short Description}}
  1947  *
  1926  *
  1948  * @since unknown
  1927  * @since 2.7.0
  1949  *
  1928  *
  1950  * @return unknown
  1929  * @return unknown
  1951  */
  1930  */
  1952 function type_url_form_image() {
  1931 function wp_media_insert_url_form( $default_view = 'image' ) {
  1953 
       
  1954 	if ( !apply_filters( 'disable_captions', '' ) ) {
  1932 	if ( !apply_filters( 'disable_captions', '' ) ) {
  1955 		$caption = '
  1933 		$caption = '
  1956 		<tr>
  1934 		<tr class="image-only">
  1957 			<th valign="top" scope="row" class="label">
  1935 			<th valign="top" scope="row" class="label">
  1958 				<span class="alignleft"><label for="caption">' . __('Image Caption') . '</label></span>
  1936 				<span class="alignleft"><label for="caption">' . __('Image Caption') . '</label></span>
  1959 			</th>
  1937 			</th>
  1960 			<td class="field"><input id="caption" name="caption" value="" type="text" /></td>
  1938 			<td class="field"><textarea id="caption" name="caption"></textarea></td>
  1961 		</tr>
  1939 		</tr>
  1962 ';
  1940 ';
  1963 	} else {
  1941 	} else {
  1964 		$caption = '';
  1942 		$caption = '';
  1965 	}
  1943 	}
  1966 
  1944 
  1967 	$default_align = get_option('image_default_align');
  1945 	$default_align = get_option('image_default_align');
  1968 	if ( empty($default_align) )
  1946 	if ( empty($default_align) )
  1969 		$default_align = 'none';
  1947 		$default_align = 'none';
  1970 
  1948 
       
  1949 	if ( 'image' == $default_view ) {
       
  1950 		$view = 'image-only';
       
  1951 		$table_class = '';
       
  1952 	} else {
       
  1953 		$view = $table_class = 'not-image';
       
  1954 	}
       
  1955 
  1971 	return '
  1956 	return '
  1972 	<h4 class="media-sub-title">' . __('Insert an image from another web site') . '</h4>
  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>
  1973 	<table class="describe"><tbody>
  1958 	<table class="describe ' . $table_class . '"><tbody>
  1974 		<tr>
  1959 		<tr>
  1975 			<th valign="top" scope="row" class="label" style="width:130px;">
  1960 			<th valign="top" scope="row" class="label" style="width:130px;">
  1976 				<span class="alignleft"><label for="src">' . __('Image URL') . '</label></span>
  1961 				<span class="alignleft"><label for="src">' . __('URL') . '</label></span>
  1977 				<span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span>
  1962 				<span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span>
  1978 			</th>
  1963 			</th>
  1979 			<td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
  1964 			<td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
  1980 		</tr>
  1965 		</tr>
  1981 
  1966 
  1982 		<tr>
  1967 		<tr>
  1983 			<th valign="top" scope="row" class="label">
  1968 			<th valign="top" scope="row" class="label">
  1984 				<span class="alignleft"><label for="title">' . __('Image Title') . '</label></span>
  1969 				<span class="alignleft"><label for="title">' . __('Title') . '</label></span>
  1985 				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
  1970 				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
  1986 			</th>
  1971 			</th>
  1987 			<td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td>
  1972 			<td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td>
  1988 		</tr>
  1973 		</tr>
  1989 
  1974 
  1990 		<tr>
  1975 		<tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;') . '</p></td></tr>
       
  1976 
       
  1977 		<tr class="image-only">
  1991 			<th valign="top" scope="row" class="label">
  1978 			<th valign="top" scope="row" class="label">
  1992 				<span class="alignleft"><label for="alt">' . __('Alternate Text') . '</label></span>
  1979 				<span class="alignleft"><label for="alt">' . __('Alternate Text') . '</label></span>
  1993 			</th>
  1980 			</th>
  1994 			<td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
  1981 			<td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
  1995 			<p class="help">' . __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;') . '</p></td>
  1982 			<p class="help">' . __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;') . '</p></td>
  1996 		</tr>
  1983 		</tr>
  1997 		' . $caption . '
  1984 		' . $caption . '
  1998 		<tr class="align">
  1985 		<tr class="align image-only">
  1999 			<th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
  1986 			<th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
  2000 			<td class="field">
  1987 			<td class="field">
  2001 				<input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
  1988 				<input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
  2002 				<label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
  1989 				<label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
  2003 				<input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
  1990 				<input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
  2007 				<input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
  1994 				<input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
  2008 				<label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
  1995 				<label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
  2009 			</td>
  1996 			</td>
  2010 		</tr>
  1997 		</tr>
  2011 
  1998 
  2012 		<tr>
  1999 		<tr class="image-only">
  2013 			<th valign="top" scope="row" class="label">
  2000 			<th valign="top" scope="row" class="label">
  2014 				<span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
  2001 				<span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
  2015 			</th>
  2002 			</th>
  2016 			<td class="field"><input id="url" name="url" value="" type="text" /><br />
  2003 			<td class="field"><input id="url" name="url" value="" type="text" /><br />
  2017 
  2004 
  2018 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
  2005 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
  2019 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
  2006 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
  2020 			<p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
  2007 			<p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
  2021 		</tr>
  2008 		</tr>
  2022 
  2009 		<tr class="image-only">
       
  2010 			<td></td>
       
  2011 			<td>
       
  2012 				<input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
       
  2013 			</td>
       
  2014 		</tr>
       
  2015 		<tr class="not-image">
       
  2016 			<td></td>
       
  2017 			<td>
       
  2018 				' . get_submit_button( __( 'Insert into Post' ), 'button', 'insertonlybutton', false ) . '
       
  2019 			</td>
       
  2020 		</tr>
       
  2021 	</tbody></table>
       
  2022 ';
       
  2023 
       
  2024 }
       
  2025 
       
  2026 function _insert_into_post_button($type) {
       
  2027 	if ( !post_type_supports(get_post_type($_GET['post_id']), 'editor') )
       
  2028 		return '';
       
  2029 
       
  2030 	if ( 'image' == $type )
       
  2031 	return '
  2023 		<tr>
  2032 		<tr>
  2024 			<td></td>
  2033 			<td></td>
  2025 			<td>
  2034 			<td>
  2026 				<input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
  2035 				<input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
  2027 			</td>
  2036 			</td>
  2028 		</tr>
  2037 		</tr>
  2029 	</tbody></table>
  2038 	';
  2030 ';
  2039 
  2031 
       
  2032 }
       
  2033 
       
  2034 /**
       
  2035  * {@internal Missing Short Description}}
       
  2036  *
       
  2037  * @since unknown
       
  2038  *
       
  2039  * @return unknown
       
  2040  */
       
  2041 function type_url_form_audio() {
       
  2042 	return '
  2040 	return '
  2043 	<table class="describe"><tbody>
       
  2044 		<tr>
       
  2045 			<th valign="top" scope="row" class="label">
       
  2046 				<span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
       
  2047 				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
       
  2048 			</th>
       
  2049 			<td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
       
  2050 		</tr>
       
  2051 		<tr>
       
  2052 			<th valign="top" scope="row" class="label">
       
  2053 				<span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
       
  2054 				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
       
  2055 			</th>
       
  2056 			<td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
       
  2057 		</tr>
       
  2058 		<tr><td></td><td class="help">' . __('Link text, e.g. &#8220;Still Alive by Jonathan Coulton&#8221;') . '</td></tr>
       
  2059 		<tr>
  2041 		<tr>
  2060 			<td></td>
  2042 			<td></td>
  2061 			<td>
  2043 			<td>
  2062 				<input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
  2044 				' . get_submit_button( __( 'Insert into Post' ), 'button', 'insertonlybutton', false ) . '
  2063 			</td>
  2045 			</td>
  2064 		</tr>
  2046 		</tr>
  2065 	</tbody></table>
  2047 	';
  2066 ';
  2048 }
  2067 }
  2049 
  2068 
  2050 /**
  2069 /**
  2051  * {@internal Missing Short Description}}
  2070  * {@internal Missing Short Description}}
  2052  *
  2071  *
  2053  * @since 2.6.0
  2072  * @since unknown
       
  2073  *
       
  2074  * @return unknown
       
  2075  */
       
  2076 function type_url_form_video() {
       
  2077 	return '
       
  2078 	<table class="describe"><tbody>
       
  2079 		<tr>
       
  2080 			<th valign="top" scope="row" class="label">
       
  2081 				<span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
       
  2082 				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
       
  2083 			</th>
       
  2084 			<td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
       
  2085 		</tr>
       
  2086 		<tr>
       
  2087 			<th valign="top" scope="row" class="label">
       
  2088 				<span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
       
  2089 				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
       
  2090 			</th>
       
  2091 			<td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
       
  2092 		</tr>
       
  2093 		<tr><td></td><td class="help">' . __('Link text, e.g. &#8220;Lucy on YouTube&#8220;') . '</td></tr>
       
  2094 		<tr>
       
  2095 			<td></td>
       
  2096 			<td>
       
  2097 				<input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
       
  2098 			</td>
       
  2099 		</tr>
       
  2100 	</tbody></table>
       
  2101 ';
       
  2102 }
       
  2103 
       
  2104 /**
       
  2105  * {@internal Missing Short Description}}
       
  2106  *
       
  2107  * @since unknown
       
  2108  *
       
  2109  * @return unknown
       
  2110  */
       
  2111 function type_url_form_file() {
       
  2112 	return '
       
  2113 	<table class="describe"><tbody>
       
  2114 		<tr>
       
  2115 			<th valign="top" scope="row" class="label">
       
  2116 				<span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
       
  2117 				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
       
  2118 			</th>
       
  2119 			<td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
       
  2120 		</tr>
       
  2121 		<tr>
       
  2122 			<th valign="top" scope="row" class="label">
       
  2123 				<span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
       
  2124 				<span class="alignright"><abbr title="required" class="required">*</abbr></span>
       
  2125 			</th>
       
  2126 			<td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
       
  2127 		</tr>
       
  2128 		<tr><td></td><td class="help">' . __('Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;') . '</td></tr>
       
  2129 		<tr>
       
  2130 			<td></td>
       
  2131 			<td>
       
  2132 				<input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
       
  2133 			</td>
       
  2134 		</tr>
       
  2135 	</tbody></table>
       
  2136 ';
       
  2137 }
       
  2138 
       
  2139 /**
       
  2140  * {@internal Missing Short Description}}
       
  2141  *
       
  2142  * Support a GET parameter for disabling the flash uploader.
       
  2143  *
       
  2144  * @since unknown
       
  2145  *
       
  2146  * @param unknown_type $flash
       
  2147  * @return unknown
       
  2148  */
       
  2149 function media_upload_use_flash($flash) {
       
  2150 	if ( array_key_exists('flash', $_REQUEST) )
       
  2151 		$flash = !empty($_REQUEST['flash']);
       
  2152 	return $flash;
       
  2153 }
       
  2154 
       
  2155 add_filter('flash_uploader', 'media_upload_use_flash');
       
  2156 
       
  2157 /**
       
  2158  * {@internal Missing Short Description}}
       
  2159  *
       
  2160  * @since unknown
       
  2161  */
  2054  */
  2162 function media_upload_flash_bypass() {
  2055 function media_upload_flash_bypass() {
  2163 	echo '<p class="upload-flash-bypass">';
  2056 	?>
  2164 	printf( __('You are using the Flash uploader.  Problems?  Try the <a href="%s">Browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)) );
  2057 	<p class="upload-flash-bypass">
  2165 	echo '</p>';
  2058 	<?php _e('You are using the multi-file uploader. Problems? Try the <a href="#">browser uploader</a> instead.'); ?>
  2166 }
  2059 	</p>
  2167 
  2060 	<?php
  2168 /**
  2061 }
  2169  * {@internal Missing Short Description}}
  2062 add_action('post-plupload-upload-ui', 'media_upload_flash_bypass');
  2170  *
  2063 
  2171  * @since unknown
  2064 /**
  2172  */
  2065  * {@internal Missing Short Description}}
  2173 function media_upload_html_bypass($flash = true) {
  2066  *
  2174 	echo '<p class="upload-html-bypass">';
  2067  * @since 2.6.0
  2175 	_e('You are using the Browser uploader.');
  2068  */
  2176 	if ( $flash ) {
  2069 function media_upload_html_bypass() {
  2177 		// the user manually selected the browser uploader, so let them switch back to Flash
  2070 	?>
  2178 		echo ' ';
  2071 	<p class="upload-html-bypass hide-if-no-js">
  2179 		printf( __('Try the <a href="%s">Flash uploader</a> instead.'), esc_url(add_query_arg('flash', 1)) );
  2072        <?php _e('You are using the browser&#8217;s built-in file uploader. The WordPress uploader includes multiple file selection and drag and drop capability. <a href="#">Switch to the multi-file uploader</a>.'); ?>
  2180 	}
  2073 	</p>
  2181 	echo "</p>\n";
  2074 	<?php
  2182 }
  2075 }
  2183 
       
  2184 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
       
  2185 add_action('post-html-upload-ui', 'media_upload_html_bypass');
  2076 add_action('post-html-upload-ui', 'media_upload_html_bypass');
  2186 
  2077 
  2187 /**
  2078 function media_upload_text_after() {
  2188  * {@internal Missing Short Description}}
  2079 	?>
  2189  *
  2080 	<span class="after-file-upload"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></span>
  2190  * Make sure the GET parameter sticks when we submit a form.
  2081 	<?php
  2191  *
  2082 }
  2192  * @since unknown
  2083 add_action('post-upload-ui', 'media_upload_text_after', 5);
  2193  *
  2084 
  2194  * @param unknown_type $url
  2085 /**
  2195  * @return unknown
  2086  * {@internal Missing Short Description}}
  2196  */
  2087  *
  2197 function media_upload_bypass_url($url) {
  2088  * @since 2.6.0
  2198 	if ( array_key_exists('flash', $_REQUEST) )
  2089  */
  2199 		$url = add_query_arg('flash', intval($_REQUEST['flash']));
  2090 function media_upload_max_image_resize() {
  2200 	return $url;
  2091 	$checked = get_user_setting('upload_resize') ? ' checked="true"' : '';
  2201 }
  2092 	$a = $end = '';
  2202 
  2093 
  2203 add_filter('media_upload_form_url', 'media_upload_bypass_url');
  2094 	if ( current_user_can( 'manage_options' ) ) {
  2204 
  2095 		$a = '<a href="' . esc_url( admin_url( 'options-media.php' ) ) . '" target="_blank">';
  2205 add_filter('async_upload_image', 'get_media_item', 10, 2);
  2096 		$end = '</a>';
  2206 add_filter('async_upload_audio', 'get_media_item', 10, 2);
  2097 	}
  2207 add_filter('async_upload_video', 'get_media_item', 10, 2);
  2098 ?>
  2208 add_filter('async_upload_file', 'get_media_item', 10, 2);
  2099 <p class="hide-if-no-js"><label>
  2209 
  2100 <input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> />
  2210 add_action('media_upload_image', 'media_upload_image');
  2101 <?php
  2211 add_action('media_upload_audio', 'media_upload_audio');
  2102 	/* translators: %1$s is link start tag, %2$s is link end tag, %3$d is width, %4$d is height*/
  2212 add_action('media_upload_video', 'media_upload_video');
  2103 	printf( __( 'Scale images to match the large size selected in %1$simage options%2$s (%3$d &times; %4$d).' ), $a, $end, (int) get_option( 'large_size_w', '1024' ), (int) get_option( 'large_size_h', '1024' ) );
  2213 add_action('media_upload_file', 'media_upload_file');
  2104 ?>
  2214 
  2105 </label></p>
  2215 add_filter('media_upload_gallery', 'media_upload_gallery');
  2106 <?php
  2216 
  2107 }
  2217 add_filter('media_upload_library', 'media_upload_library');
  2108 
  2218 
  2109 add_filter( 'async_upload_image', 'get_media_item', 10, 2 );
       
  2110 add_filter( 'async_upload_audio', 'get_media_item', 10, 2 );
       
  2111 add_filter( 'async_upload_video', 'get_media_item', 10, 2 );
       
  2112 add_filter( 'async_upload_file',  'get_media_item', 10, 2 );
       
  2113 
       
  2114 add_action( 'media_upload_image', 'wp_media_upload_handler' );
       
  2115 add_action( 'media_upload_audio', 'wp_media_upload_handler' );
       
  2116 add_action( 'media_upload_video', 'wp_media_upload_handler' );
       
  2117 add_action( 'media_upload_file',  'wp_media_upload_handler' );
       
  2118 
       
  2119 add_filter( 'media_upload_gallery', 'media_upload_gallery' );
       
  2120 add_filter( 'media_upload_library', 'media_upload_library' );