X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/11be8dc178e77d0b46189bbd8e33a216a9b90942..341dfbb66f24f5145174c373267f889c31615cc5:/wp-admin/includes/media.php diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 57e032ea..ff77e6c0 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -9,7 +9,7 @@ /** * {@internal Missing Short Description}} * - * @since unknown + * @since 2.5.0 * * @return unknown */ @@ -27,7 +27,7 @@ function media_upload_tabs() { /** * {@internal Missing Short Description}} * - * @since unknown + * @since 2.5.0 * * @param unknown_type $tabs * @return unknown @@ -40,8 +40,10 @@ function update_gallery_tab($tabs) { return $tabs; } - if ( intval($_REQUEST['post_id']) ) - $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id']))); + $post_id = intval($_REQUEST['post_id']); + + if ( $post_id ) + $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) ); if ( empty($attachments) ) { unset($tabs['gallery']); @@ -57,29 +59,37 @@ add_filter('media_upload_tabs', 'update_gallery_tab'); /** * {@internal Missing Short Description}} * - * @since unknown + * @since 2.5.0 */ function the_media_upload_tabs() { - global $redir_tab; + global $redir_tab, $is_iphone; $tabs = media_upload_tabs(); + if ( $is_iphone ) { + unset($tabs['type']); + $default = 'type_url'; + } else { + $default = 'type'; + } + if ( !empty($tabs) ) { echo "
\n"; } @@ -88,7 +98,7 @@ function the_media_upload_tabs() { /** * {@internal Missing Short Description}} * - * @since unknown + * @since 2.5.0 * * @param unknown_type $id * @param unknown_type $alt @@ -99,18 +109,16 @@ function the_media_upload_tabs() { * @param unknown_type $size * @return unknown */ -function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') { +function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') { - $htmlalt = ( empty($alt) ) ? $title : $alt; + $html = get_image_tag($id, $alt, $title, $align, $size); - $html = get_image_tag($id, $htmlalt, $title, $align, $size); - - $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : ''; + $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : ''; if ( $url ) - $html = '$html"; + $html = '$html"; - $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size ); + $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); return $html; } @@ -118,7 +126,7 @@ function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = fal /** * {@internal Missing Short Description}} * - * @since unknown + * @since 2.6.0 * * @param unknown_type $html * @param unknown_type $id @@ -129,31 +137,38 @@ function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = fal * @param unknown_type $size * @return unknown */ -function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) { +function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { + + if ( empty($caption) || apply_filters( 'disable_captions', '' ) ) + return $html; - if ( empty($alt) || apply_filters( 'disable_captions', '' ) ) return $html; $id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; - preg_match( '/width="([0-9]+)/', $html, $matches ); - if ( ! isset($matches[1]) ) return $html; + if ( ! preg_match( '/width="([0-9]+)/', $html, $matches ) ) + return $html; + $width = $matches[1]; - $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html ); - if ( empty($align) ) $align = 'none'; + $caption = str_replace( array( '>', '<', '"', "'" ), + array( '>', '<', '"', ''' ), + $caption + ); - $alt = ! empty($alt) ? addslashes($alt) : ''; + $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html ); + if ( empty($align) ) + $align = 'none'; $shcode = '[caption id="' . $id . '" align="align' . $align - . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]'; + . '" width="' . $width . '" caption="' . addslashes($caption) . '"]' . $html . '[/caption]'; return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); } -add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 ); +add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 ); /** * {@internal Missing Short Description}} * - * @since unknown + * @since 2.5.0 * * @param unknown_type $html */ @@ -165,7 +180,7 @@ var win = window.dialogArguments || opener || parent || top; win.send_to_editor(''); /* ]]> */ - '); * * This handles the file upload POST itself, creating the attachment post. * - * @since unknown + * @since 2.5.0 * - * @param unknown_type $file_id - * @param unknown_type $post_id - * @param unknown_type $post_data - * @return unknown + * @param string $file_id Index into the {@link $_FILES} array of the upload + * @param int $post_id The post ID the media is associated with + * @param array $post_data allows you to overwrite some of the attachment + * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior + * @return int the ID of the attachment */ -function media_handle_upload($file_id, $post_id, $post_data = array()) { - $overrides = array('test_form'=>false); +function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { $time = current_time('mysql'); if ( $post = get_post($post_id) ) { @@ -190,22 +205,26 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) { $time = $post->post_date; } + $name = $_FILES[$file_id]['name']; $file = wp_handle_upload($_FILES[$file_id], $overrides, $time); if ( isset($file['error']) ) return new WP_Error( 'upload_error', $file['error'] ); + $name_parts = pathinfo($name); + $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) ); + $url = $file['url']; $type = $file['type']; $file = $file['file']; - $title = preg_replace('/\.[^.]+$/', '', basename($file)); + $title = $name; $content = ''; // use image exif/iptc data for title and caption defaults if possible if ( $image_meta = @wp_read_image_metadata($file) ) { - if ( trim($image_meta['title']) ) + if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) $title = $image_meta['title']; - if ( trim($image_meta['caption']) ) + if ( trim( $image_meta['caption'] ) ) $content = $image_meta['caption']; } @@ -218,6 +237,10 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) { 'post_content' => $content, ), $post_data ); + // This should never be set as it would then overwrite an existing attachment. + if ( isset( $attachment['ID'] ) ) + unset( $attachment['ID'] ); + // Save the data $id = wp_insert_attachment($attachment, $file, $post_id); if ( !is_wp_error($id) ) { @@ -229,20 +252,20 @@ function media_handle_upload($file_id, $post_id, $post_data = array()) { } /** - * {@internal Missing Short Description}} + * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()} * - * @since unknown + * @since 2.6.0 * - * @param unknown_type $file_array - * @param unknown_type $post_id - * @param unknown_type $desc - * @param unknown_type $post_data - * @return unknown + * @param array $file_array Array similar to a {@link $_FILES} upload array + * @param int $post_id The post ID the media is associated with + * @param string $desc Description of the sideloaded file + * @param array $post_data allows you to overwrite some of the attachment + * @return int|object The ID of the attachment or a WP_Error on failure */ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { $overrides = array('test_form'=>false); - $file = wp_handle_sideload($file_array, $overrides); + $file = wp_handle_sideload($file_array, $overrides); if ( isset($file['error']) ) return new WP_Error( 'upload_error', $file['error'] ); @@ -254,13 +277,14 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = // use image exif/iptc data for title and caption defaults if possible if ( $image_meta = @wp_read_image_metadata($file) ) { - if ( trim($image_meta['title']) ) + if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) $title = $image_meta['title']; - if ( trim($image_meta['caption']) ) + if ( trim( $image_meta['caption'] ) ) $content = $image_meta['caption']; } - $title = @$desc; + if ( isset( $desc ) ) + $title = $desc; // Construct the attachment array $attachment = array_merge( array( @@ -271,12 +295,15 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = 'post_content' => $content, ), $post_data ); - // Save the data + // This should never be set as it would then overwrite an existing attachment. + if ( isset( $attachment['ID'] ) ) + unset( $attachment['ID'] ); + + // Save the attachment metadata $id = wp_insert_attachment($attachment, $file, $post_id); - if ( !is_wp_error($id) ) { + if ( !is_wp_error($id) ) wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); - return $url; - } + return $id; } @@ -286,44 +313,56 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = * Wrap iframe content (produced by $content_func) in a doctype, html head/body * etc any additional function args will be passed to content_func. * - * @since unknown + * @since 2.5.0 * * @param unknown_type $content_func */ function wp_iframe($content_func /* ... */) { + _wp_admin_html_begin(); ?> - - > - -- | $filename | -
$post->post_mime_type | |
" . mysql2date($post->post_date, get_option('time_format')) . " | |
" . apply_filters('media_meta', '', $post) . " | |
+
+ $image_edit_button + |
+
+ " . __('File name:') . " $filename +" . __('File type:') . " $post->post_mime_type +" . __('Upload date:') . " " . mysql2date( get_option('date_format'), $post->post_date ). ' '; + if ( !empty( $media_dims ) ) + $item .= "" . __('Dimensions:') . " $media_dims \n"; + + $item .= " |
$send $delete - | |
$send $thumbnail $delete | |
\n\t\t\t | "; - if ( !empty($field[$field['input']]) ) - $item .= $field[$field['input']]; + $item .= "\t\t |
---|---|
\n\t\t\t | ";
+ if ( !empty( $field[ $field['input'] ] ) )
+ $item .= $field[ $field['input'] ];
elseif ( $field['input'] == 'textarea' ) {
- $item .= "";
+ if ( user_can_richedit() ) { // textarea_escaped when user_can_richedit() = false
+ $field['value'] = esc_textarea( $field['value'] );
+ }
+ $item .= "';
} else {
- $item .= "";
+ $item .= "";
}
- if ( !empty($field['helps']) )
- $item .= " " . join( " \n", array_unique((array) $field['helps']) ) . ' '; + if ( !empty( $field['helps'] ) ) + $item .= "" . join( " \n", array_unique( (array) $field['helps'] ) ) . ' '; $item .= " | \n\t\t
$html | |
{$form_fields['_final']} |
- - + | + + * | |
---|---|---|
- + * | -+ | |
' . __('Link text, e.g. “Ransom Demands (PDF)”') . ' | ||
- + |
- ' . $alt_help . ' |
+ |
@@ -1839,7 +1981,7 @@ function type_url_form_image() { | ||
@@ -1849,204 +1991,115 @@ function type_url_form_image() { | ||
- + |
- - * - | -- |
---|---|
- - * - | -- |
' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . ' | |
- + ' . get_submit_button( __( 'Insert into Post' ), 'button', 'insertonlybutton', false ) . ' |
- - * - | -- |
---|---|
- - * - | -- |
' . __('Link text, e.g. "Lucy on YouTube"') . ' | |
- + |
- - * - | -- |
---|---|
- - * - | -- |
' . __('Link text, e.g. "Ransom Demands (PDF)"') . ' | |
- + ' . get_submit_button( __( 'Insert into Post' ), 'button', 'insertonlybutton', false ) . ' |
'; - printf( __('You are using the Flash uploader. Problems? Try the Browser uploader instead.'), clean_url(add_query_arg('flash', 0)) ); - echo '
'; + ?> ++ browser uploader instead.'); ?> +
+ '; - if ( array_key_exists('flash', $_REQUEST) ) - // the user manually selected the browser uploader, so let them switch back to Flash - printf( __('You are using the Browser uploader. Try the Flash uploader instead.'), clean_url(add_query_arg('flash', 1)) ); - else - // the user probably doesn't have Flash - printf( __('You are using the Browser uploader.') ); - - echo ''; + ?> + + + + '; + $end = ''; + } +?> + + +add_filter( 'media_upload_gallery', 'media_upload_gallery' ); +add_filter( 'media_upload_library', 'media_upload_library' );