Enforce video dimensions.
props wonderboymusic. see #23831. git-svn-id: https://develop.svn.wordpress.org/trunk@23969 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b340e0a6c8
commit
79c4e52ffa
|
@ -110,10 +110,21 @@ window.wp = window.wp || {};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mediaPreview = function (format, url, mime) {
|
mediaPreview = function (attachment) {
|
||||||
|
var dimensions = '', url = attachment.url,
|
||||||
|
mime = attachment.mime,
|
||||||
|
format = attachment.type;
|
||||||
|
|
||||||
|
if ( 'video' === format ) {
|
||||||
|
if ( attachment.width )
|
||||||
|
dimensions += ' width="' + attachment.width + '"';
|
||||||
|
if ( attachment.height )
|
||||||
|
dimensions += ' height="' + attachment.height + '"';
|
||||||
|
}
|
||||||
|
|
||||||
$('#' + format + '-preview').remove();
|
$('#' + format + '-preview').remove();
|
||||||
$holder.parent().prepend( '<div id="' + format + '-preview" class="wp-format-media-preview">' +
|
$holder.parent().prepend( '<div id="' + format + '-preview" class="wp-format-media-preview">' +
|
||||||
'<' + format + ' class="wp-' + format + '-shortcode" controls="controls" preload="none">' +
|
'<' + format + dimensions + ' class="wp-' + format + '-shortcode" controls="controls" preload="none">' +
|
||||||
'<source type="' + mime + '" src="' + url + '" />' +
|
'<source type="' + mime + '" src="' + url + '" />' +
|
||||||
'</' + format + '></div>' );
|
'</' + format + '></div>' );
|
||||||
$('.wp-' + format + '-shortcode').mediaelementplayer();
|
$('.wp-' + format + '-shortcode').mediaelementplayer();
|
||||||
|
@ -122,25 +133,25 @@ window.wp = window.wp || {};
|
||||||
// When an image is selected, run a callback.
|
// When an image is selected, run a callback.
|
||||||
mediaFrame.on( 'select', function () {
|
mediaFrame.on( 'select', function () {
|
||||||
// Grab the selected attachment.
|
// Grab the selected attachment.
|
||||||
var attachment = mediaFrame.state().get('selection').first(), mime, url, id;
|
var attachment = mediaFrame.state().get('selection').first().toJSON();
|
||||||
|
|
||||||
id = attachment.get('id');
|
if ( 0 === attachment.mime.indexOf('audio') ) {
|
||||||
url = attachment.get('url');
|
$field.val(attachment.url);
|
||||||
mime = attachment.get('mime');
|
|
||||||
|
|
||||||
if ( 0 === mime.indexOf('audio') ) {
|
|
||||||
$field.val(url);
|
|
||||||
// show one preview at a time
|
// show one preview at a time
|
||||||
mediaPreview('audio', url, mime);
|
mediaPreview(attachment);
|
||||||
} else if ( 0 === mime.indexOf('video') ) {
|
} else if ( 0 === attachment.mime.indexOf('video') ) {
|
||||||
$field.val(url);
|
attachment.src = attachment.url;
|
||||||
|
$field.val(wp.shortcode.string({
|
||||||
|
tag: 'video',
|
||||||
|
attrs: _.pick( attachment, 'src', 'width', 'height' )
|
||||||
|
}));
|
||||||
// show one preview at a time
|
// show one preview at a time
|
||||||
mediaPreview('video', url, mime);
|
mediaPreview(attachment);
|
||||||
} else {
|
} else {
|
||||||
// set the hidden input's value
|
// set the hidden input's value
|
||||||
$field.val(id);
|
$field.val(attachment.id);
|
||||||
// Show the image in the placeholder
|
// Show the image in the placeholder
|
||||||
$el.html('<img src="' + url + '" />');
|
$el.html('<img src="' + attachment.url + '" />');
|
||||||
$holder.removeClass('empty').show();
|
$holder.removeClass('empty').show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -144,6 +144,12 @@
|
||||||
|
|
||||||
shortcode = {};
|
shortcode = {};
|
||||||
|
|
||||||
|
if ( attachment.width )
|
||||||
|
shortcode.width = attachment.width;
|
||||||
|
|
||||||
|
if ( attachment.height )
|
||||||
|
shortcode.height = attachment.height;
|
||||||
|
|
||||||
if ( props.mime ) {
|
if ( props.mime ) {
|
||||||
switch ( props.mime ) {
|
switch ( props.mime ) {
|
||||||
case 'video/mp4':
|
case 'video/mp4':
|
||||||
|
|
|
@ -1638,6 +1638,11 @@ function wp_prepare_attachment_for_js( $attachment ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] );
|
$response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] );
|
||||||
|
} elseif ( $meta && 'video' === $type ) {
|
||||||
|
if ( isset( $meta['width'] ) )
|
||||||
|
$response['width'] = (int) $meta['width'];
|
||||||
|
if ( isset( $meta['height'] ) )
|
||||||
|
$response['height'] = (int) $meta['height'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( function_exists('get_compat_media_markup') )
|
if ( function_exists('get_compat_media_markup') )
|
||||||
|
@ -2014,6 +2019,15 @@ function wp_video_embed( $matches, $attr, $url, $rawattr ) {
|
||||||
if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) {
|
if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) {
|
||||||
$dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] );
|
$dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] );
|
||||||
$dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] );
|
$dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] );
|
||||||
|
} elseif ( strstr( $url, home_url() ) ) {
|
||||||
|
$id = attachment_url_to_postid( $url );
|
||||||
|
if ( ! empty( $id ) ) {
|
||||||
|
$meta = wp_get_attachment_metadata( $id );
|
||||||
|
if ( ! empty( $meta['width'] ) )
|
||||||
|
$dimensions .= sprintf( 'width="%d" ', (int) $meta['width'] );
|
||||||
|
if ( ! empty( $meta['height'] ) )
|
||||||
|
$dimensions .= sprintf( 'height="%d" ', (int) $meta['height'] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$video = do_shortcode( '[video ' . $dimensions . 'src="' . $url . '" /]' );
|
$video = do_shortcode( '[video ' . $dimensions . 'src="' . $url . '" /]' );
|
||||||
}
|
}
|
||||||
|
@ -2437,4 +2451,25 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
|
||||||
*/
|
*/
|
||||||
function the_post_format_image( $attached_size = 'full' ) {
|
function the_post_format_image( $attached_size = 'full' ) {
|
||||||
echo get_the_post_format_image( $attached_size );
|
echo get_the_post_format_image( $attached_size );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the post id for an attachment file URL
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
*
|
||||||
|
* @param string $url Permalink to check.
|
||||||
|
* @return int Post ID, or 0 on failure.
|
||||||
|
*/
|
||||||
|
function attachment_url_to_postid( $url ) {
|
||||||
|
global $wpdb;
|
||||||
|
if ( preg_match( '#\.[a-zA-Z0-9]+$#', $url ) ) {
|
||||||
|
$id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' " .
|
||||||
|
"AND guid = %s", $url ) );
|
||||||
|
|
||||||
|
if ( ! empty( $id ) )
|
||||||
|
return (int) $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue