$title = $name;
$content = '';
+ if ( preg_match( '#^audio#', $type ) ) {
+ $meta = wp_read_audio_metadata( $file );
+
+ if ( ! empty( $meta['title'] ) )
+ $title = $meta['title'];
+
+ $content = '';
+
+ if ( ! empty( $title ) ) {
+
+ if ( ! empty( $meta['album'] ) && ! empty( $meta['artist'] ) ) {
+ /* translators: 1: audio track title, 2: album title, 3: artist name */
+ $content .= sprintf( __( '"%1$s" from %2$s by %3$s.' ), $title, $meta['album'], $meta['artist'] );
+ } else if ( ! empty( $meta['album'] ) ) {
+ /* translators: 1: audio track title, 2: album title */
+ $content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] );
+ } else if ( ! empty( $meta['artist'] ) ) {
+ /* translators: 1: audio track title, 2: artist name */
+ $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] );
+ } else {
+ $content .= sprintf( __( '"%s".' ), $title );
+ }
+
+ } else if ( ! empty( $meta['album'] ) ) {
+
+ if ( ! empty( $meta['artist'] ) ) {
+ /* translators: 1: audio album title, 2: artist name */
+ $content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] );
+ } else {
+ $content .= $meta['album'] . '.';
+ }
+
+ } else if ( ! empty( $meta['artist'] ) ) {
+
+ $content .= $meta['artist'] . '.';
+
+ }
+
+ if ( ! empty( $meta['year'] ) )
+ $content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] );
+
+ if ( ! empty( $meta['track_number'] ) ) {
+ $track_number = explode( '/', $meta['track_number'] );
+ if ( isset( $track_number[1] ) )
+ $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) );
+ else
+ $content .= ' ' . sprintf( __( 'Track %1$s.' ), number_format_i18n( $track_number[0] ) );
+ }
+
+ if ( ! empty( $meta['genre'] ) )
+ $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] );
+
// use image exif/iptc data for title and caption defaults if possible
- if ( $image_meta = @wp_read_image_metadata($file) ) {
+ } elseif ( $image_meta = @wp_read_image_metadata( $file ) ) {
if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
$title = $image_meta['title'];
if ( trim( $image_meta['caption'] ) )
<script type="text/javascript">
//<![CDATA[
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();}}};
-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(); ?>'};
var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
isRtl = <?php echo (int) is_rtl(); ?>;
//]]>
$img = '<span class="wp-media-buttons-icon"></span> ';
- echo '<a href="#" class="button insert-media add_media" data-editor="' . esc_attr( $editor_id ) . '" title="' . esc_attr__( 'Add Media' ) . '">' . $img . __( 'Add Media' ) . '</a>';
+ echo '<a href="#" id="insert-media-button" class="button insert-media add_media" data-editor="' . esc_attr( $editor_id ) . '" title="' . esc_attr__( 'Add Media' ) . '">' . $img . __( 'Add Media' ) . '</a>';
// Don't use this filter. Want to add a button? Use the media_buttons action.
$legacy_filter = apply_filters('media_buttons_context', ''); // deprecated
if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
$post = $_post = get_post($attachment_id, ARRAY_A);
- $post_type_object = get_post_type_object( $post[ 'post_type' ] );
- if ( !current_user_can( $post_type_object->cap->edit_post, $attachment_id ) )
+ if ( !current_user_can( 'edit_post', $attachment_id ) )
continue;
if ( isset($attachment['post_content']) )
$post = apply_filters('attachment_fields_to_save', $post, $attachment);
if ( isset($attachment['image_alt']) ) {
- $image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
- if ( $image_alt != stripslashes($attachment['image_alt']) ) {
- $image_alt = wp_strip_all_tags( stripslashes($attachment['image_alt']), true );
+ $image_alt = wp_unslash( $attachment['image_alt'] );
+ if ( $image_alt != get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ) {
+ $image_alt = wp_strip_all_tags( $image_alt, true );
// update_meta expects slashed
- update_post_meta( $attachment_id, '_wp_attachment_image_alt', addslashes($image_alt) );
+ update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
}
}
}
if ( isset($send_id) ) {
- $attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
+ $attachment = wp_unslash( $_POST['attachments'][$send_id] );
$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
if ( !empty($attachment['url']) ) {
$src = "http://$src";
if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) {
- $title = esc_html( stripslashes( $_POST['title'] ) );
+ $title = esc_html( wp_unslash( $_POST['title'] ) );
if ( empty( $title ) )
$title = esc_html( basename( $src ) );
$html = apply_filters( $type . '_send_to_editor_url', $html, esc_url_raw( $src ), $title );
} else {
$align = '';
- $alt = esc_attr( stripslashes( $_POST['alt'] ) );
+ $alt = esc_attr( wp_unslash( $_POST['alt'] ) );
if ( isset($_POST['align']) ) {
- $align = esc_attr( stripslashes( $_POST['align'] ) );
+ $align = esc_attr( wp_unslash( $_POST['align'] ) );
$class = " class='align$align'";
}
if ( !empty($src) )
}
$display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
- $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60 ) . "</span></div>" : '';
+ $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '…' ) . "</span></div>" : '';
$gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
$order = '';
$media_dims = '';
$meta = wp_get_attachment_metadata( $post->ID );
- if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
+ if ( isset( $meta['width'], $meta['height'] ) )
$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> ";
$media_dims = apply_filters( 'media_meta', $media_dims, $post );
$item .= '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n";
}
+ if ( $item )
+ $item = '<input type="hidden" name="attachments[' . $attachment_id . '][menu_order]" value="' . esc_attr( $post->menu_order ) . '" />' . $item;
+
return array(
'item' => $item,
'meta' => $media_meta,
global $type, $tab, $pagenow, $is_IE, $is_opera;
if ( ! _device_can_upload() ) {
- 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>';
+ echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'http://wordpress.org/mobile/' ) . '</p>';
return;
}
$form_class .= ' html-uploader';
?>
-<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">
+<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
<?php submit_button( '', 'hidden', 'save', false ); ?>
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
<?php wp_nonce_field('media-form'); ?>
$form_class .= ' html-uploader';
?>
-<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">
+<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
<?php wp_nonce_field('media-form'); ?>
<a href="#" id="desc"><?php _e('Descending'); ?></a> |
<a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a>
</div>
-<form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
+<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
<?php wp_nonce_field('media-form'); ?>
<?php //media_upload_form( $errors ); ?>
<table class="widefat" cellspacing="0">
</div>
</form>
-<form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="library-form">
+<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form">
<?php wp_nonce_field('media-form'); ?>
<?php //media_upload_form( $errors ); ?>
*
* @since 3.5.0
*/
-function edit_form_image_editor() {
- $post = get_post();
-
+function edit_form_image_editor( $post ) {
$open = isset( $_GET['image-editor'] );
if ( $open )
require_once ABSPATH . 'wp-admin/includes/image-edit.php';
$title = esc_attr( $post->post_title );
$alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
- $att_url = wp_get_attachment_url( $post->ID );
-
+ $att_url = wp_get_attachment_url( $post->ID ); ?>
+ <div class="wp_attachment_holder">
+ <?php
if ( wp_attachment_is_image( $post->ID ) ) :
$image_edit_button = '';
if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
}
?>
- <div class="wp_attachment_holder">
+
<div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>
<div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>">
<div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>">
<?php if ( $open ) wp_image_editor( $attachment_id ); ?>
</div>
- </div>
- <?php endif; ?>
+ <?php
+ elseif ( $attachment_id && 0 === strpos( $post->post_mime_type, 'audio/' ) ):
+
+ echo wp_audio_shortcode( array( 'src' => $att_url ) );
+
+ elseif ( $attachment_id && 0 === strpos( $post->post_mime_type, 'video/' ) ):
- <div class="wp_attachment_details">
+ $meta = wp_get_attachment_metadata( $attachment_id );
+ $w = ! empty( $meta['width'] ) ? min( $meta['width'], 600 ) : 0;
+ $h = 0;
+ if ( ! empty( $meta['height'] ) )
+ $h = $meta['height'];
+ if ( $h && $w < $meta['width'] )
+ $h = round( ( $meta['height'] * $w ) / $meta['width'] );
+
+ $attr = array( 'src' => $att_url );
+
+ if ( ! empty( $meta['width' ] ) )
+ $attr['width'] = $w;
+
+ if ( ! empty( $meta['height'] ) )
+ $attr['height'] = $h;
+
+ echo wp_video_shortcode( $attr );
+
+ endif; ?>
+ </div>
+ <div class="wp_attachment_details edit-form-section">
<p>
<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
<textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
<?php endif; ?>
<?php
- $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' );
+ $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
$editor_args = array(
'textarea_name' => 'content',
'textarea_rows' => 5,
function attachment_submitbox_metadata() {
$post = get_post();
- $filename = esc_html( basename( $post->guid ) );
+ $filename = esc_html( wp_basename( $post->guid ) );
$media_dims = '';
$meta = wp_get_attachment_metadata( $post->ID );
- if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
+ if ( isset( $meta['width'], $meta['height'] ) )
$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> ";
$media_dims = apply_filters( 'media_meta', $media_dims, $post );
?></strong>
</div>
-<?php if ( $media_dims ) : ?>
+<?php
+ if ( preg_match( '#^audio|video#', $post->post_mime_type ) ):
+
+ $fields = array(
+ 'mime_type' => __( 'Mime-type:' ),
+ 'year' => __( 'Year:' ),
+ 'genre' => __( 'Genre:' ),
+ 'length_formatted' => __( 'Length:' ),
+ );
+
+ foreach ( $fields as $key => $label ):
+ if ( ! empty( $meta[$key] ) ) : ?>
+ <div class="misc-pub-section">
+ <?php echo $label ?> <strong><?php echo esc_html( $meta[$key] ); ?></strong>
+ </div>
+ <?php
+ endif;
+ endforeach;
+
+ if ( ! empty( $meta['bitrate'] ) ) : ?>
+ <div class="misc-pub-section">
+ <?php _e( 'Bitrate:' ); ?> <strong><?php
+ echo round( $meta['bitrate'] / 1000 ), 'kb/s';
+
+ if ( ! empty( $meta['bitrate_mode'] ) )
+ echo ' ', strtoupper( $meta['bitrate_mode'] );
+
+ ?></strong>
+ </div>
+ <?php
+ endif;
+
+ $audio_fields = array(
+ 'dataformat' => __( 'Audio Format:' ),
+ 'codec' => __( 'Audio Codec:' )
+ );
+
+ foreach ( $audio_fields as $key => $label ):
+ if ( ! empty( $meta['audio'][$key] ) ) : ?>
+ <div class="misc-pub-section">
+ <?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][$key] ); ?></strong>
+ </div>
+ <?php
+ endif;
+ endforeach;
+
+ endif;
+
+ if ( $media_dims ) : ?>
<div class="misc-pub-section">
<?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong>
</div>
add_filter( 'media_upload_library', 'media_upload_library' );
add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' );
+
+/**
+ * Parse ID3v2, ID3v1, and getID3 comments to extract usable data
+ *
+ * @since 3.6.0
+ *
+ * @param array $metadata An existing array with data
+ * @param array $data Data supplied by ID3 tags
+ */
+function wp_add_id3_tag_data( &$metadata, $data ) {
+ foreach ( array( 'id3v2', 'id3v1' ) as $version ) {
+ if ( ! empty( $data[$version]['comments'] ) ) {
+ foreach ( $data[$version]['comments'] as $key => $list ) {
+ if ( ! empty( $list ) ) {
+ $metadata[$key] = reset( $list );
+ // fix bug in byte stream analysis
+ if ( 'terms_of_use' === $key && 0 === strpos( $metadata[$key], 'yright notice.' ) )
+ $metadata[$key] = 'Cop' . $metadata[$key];
+ }
+ }
+ break;
+ }
+ }
+
+ if ( ! empty( $data['id3v2']['APIC'] ) ) {
+ $image = reset( $data['id3v2']['APIC']);
+ if ( ! empty( $image['data'] ) ) {
+ $metadata['image'] = array(
+ 'data' => $image['data'],
+ 'mime' => $image['image_mime'],
+ 'width' => $image['image_width'],
+ 'height' => $image['image_height']
+ );
+ }
+ } elseif ( ! empty( $data['comments']['picture'] ) ) {
+ $image = reset( $data['comments']['picture'] );
+ if ( ! empty( $image['data'] ) ) {
+ $metadata['image'] = array(
+ 'data' => $image['data'],
+ 'mime' => $image['image_mime']
+ );
+ }
+ }
+}
+
+/**
+ * Retrieve metadata from a video file's ID3 tags
+ *
+ * @since 3.6.0
+ *
+ * @param string $file Path to file.
+ * @return array|boolean Returns array of metadata, if found.
+ */
+function wp_read_video_metadata( $file ) {
+ if ( ! file_exists( $file ) )
+ return false;
+
+ $metadata = array();
+
+ if ( ! class_exists( 'getID3' ) )
+ require( ABSPATH . WPINC . '/ID3/getid3.php' );
+ $id3 = new getID3();
+ $data = $id3->analyze( $file );
+
+ if ( isset( $data['video']['lossless'] ) )
+ $metadata['lossless'] = $data['video']['lossless'];
+ if ( ! empty( $data['video']['bitrate'] ) )
+ $metadata['bitrate'] = (int) $data['video']['bitrate'];
+ if ( ! empty( $data['video']['bitrate_mode'] ) )
+ $metadata['bitrate_mode'] = $data['video']['bitrate_mode'];
+ if ( ! empty( $data['filesize'] ) )
+ $metadata['filesize'] = (int) $data['filesize'];
+ if ( ! empty( $data['mime_type'] ) )
+ $metadata['mime_type'] = $data['mime_type'];
+ if ( ! empty( $data['playtime_seconds'] ) )
+ $metadata['length'] = (int) ceil( $data['playtime_seconds'] );
+ if ( ! empty( $data['playtime_string'] ) )
+ $metadata['length_formatted'] = $data['playtime_string'];
+ if ( ! empty( $data['video']['resolution_x'] ) )
+ $metadata['width'] = (int) $data['video']['resolution_x'];
+ if ( ! empty( $data['video']['resolution_y'] ) )
+ $metadata['height'] = (int) $data['video']['resolution_y'];
+ if ( ! empty( $data['fileformat'] ) )
+ $metadata['fileformat'] = $data['fileformat'];
+ if ( ! empty( $data['video']['dataformat'] ) )
+ $metadata['dataformat'] = $data['video']['dataformat'];
+ if ( ! empty( $data['video']['encoder'] ) )
+ $metadata['encoder'] = $data['video']['encoder'];
+ if ( ! empty( $data['video']['codec'] ) )
+ $metadata['codec'] = $data['video']['codec'];
+
+ if ( ! empty( $data['audio'] ) ) {
+ unset( $data['audio']['streams'] );
+ $metadata['audio'] = $data['audio'];
+ }
+
+ wp_add_id3_tag_data( $metadata, $data );
+
+ return $metadata;
+}
+
+/**
+ * Retrieve metadata from a audio file's ID3 tags
+ *
+ * @since 3.6.0
+ *
+ * @param string $file Path to file.
+ * @return array|boolean Returns array of metadata, if found.
+ */
+function wp_read_audio_metadata( $file ) {
+ if ( ! file_exists( $file ) )
+ return false;
+ $metadata = array();
+
+ if ( ! class_exists( 'getID3' ) )
+ require( ABSPATH . WPINC . '/ID3/getid3.php' );
+ $id3 = new getID3();
+ $data = $id3->analyze( $file );
+
+ if ( ! empty( $data['audio'] ) ) {
+ unset( $data['audio']['streams'] );
+ $metadata = $data['audio'];
+ }
+
+ if ( ! empty( $data['fileformat'] ) )
+ $metadata['fileformat'] = $data['fileformat'];
+ if ( ! empty( $data['filesize'] ) )
+ $metadata['filesize'] = (int) $data['filesize'];
+ if ( ! empty( $data['mime_type'] ) )
+ $metadata['mime_type'] = $data['mime_type'];
+ if ( ! empty( $data['playtime_seconds'] ) )
+ $metadata['length'] = (int) ceil( $data['playtime_seconds'] );
+ if ( ! empty( $data['playtime_string'] ) )
+ $metadata['length_formatted'] = $data['playtime_string'];
+
+ wp_add_id3_tag_data( $metadata, $data );
+
+ return $metadata;
+}