diff --git wp-admin/js/post-formats.js wp-admin/js/post-formats.js
index 4ee97a4..10aab61 100644
|
|
window.wp = window.wp || {}; |
110 | 110 | } |
111 | 111 | }); |
112 | 112 | |
113 | | mediaPreview = function (format, url, mime) { |
| 113 | mediaPreview = function (attachment) { |
| 114 | var dimensions = '', url = attachment.url, |
| 115 | mime = attachment.mime, |
| 116 | format = attachment.type; |
| 117 | |
| 118 | if ( 'video' === format ) { |
| 119 | if ( attachment.width ) |
| 120 | dimensions += ' width="' + attachment.width + '"'; |
| 121 | if ( attachment.height ) |
| 122 | dimensions += ' height="' + attachment.height + '"'; |
| 123 | } |
| 124 | |
114 | 125 | $('#' + format + '-preview').remove(); |
115 | 126 | $holder.parent().prepend( '<div id="' + format + '-preview" class="wp-format-media-preview">' + |
116 | | '<' + format + ' class="wp-' + format + '-shortcode" controls="controls" preload="none">' + |
| 127 | '<' + format + dimensions + ' class="wp-' + format + '-shortcode" controls="controls" preload="none">' + |
117 | 128 | '<source type="' + mime + '" src="' + url + '" />' + |
118 | 129 | '</' + format + '></div>' ); |
119 | 130 | $('.wp-' + format + '-shortcode').mediaelementplayer(); |
… |
… |
window.wp = window.wp || {}; |
122 | 133 | // When an image is selected, run a callback. |
123 | 134 | mediaFrame.on( 'select', function () { |
124 | 135 | // Grab the selected attachment. |
125 | | var attachment = mediaFrame.state().get('selection').first(), mime, url, id; |
126 | | |
127 | | id = attachment.get('id'); |
128 | | url = attachment.get('url'); |
129 | | mime = attachment.get('mime'); |
| 136 | var attachment = mediaFrame.state().get('selection').first().toJSON(); |
130 | 137 | |
131 | | if ( 0 === mime.indexOf('audio') ) { |
132 | | $field.val(url); |
| 138 | if ( 0 === attachment.mime.indexOf('audio') ) { |
| 139 | $field.val(attachment.url); |
133 | 140 | // show one preview at a time |
134 | | mediaPreview('audio', url, mime); |
135 | | } else if ( 0 === mime.indexOf('video') ) { |
136 | | $field.val(url); |
| 141 | mediaPreview(attachment); |
| 142 | } else if ( 0 === attachment.mime.indexOf('video') ) { |
| 143 | attachment.src = attachment.url; |
| 144 | $field.val(wp.shortcode.string({ |
| 145 | tag: 'video', |
| 146 | attrs: _.pick( attachment, 'src', 'width', 'height' ) |
| 147 | })); |
137 | 148 | // show one preview at a time |
138 | | mediaPreview('video', url, mime); |
| 149 | mediaPreview(attachment); |
139 | 150 | } else { |
140 | 151 | // set the hidden input's value |
141 | | $field.val(id); |
| 152 | $field.val(attachment.id); |
142 | 153 | // Show the image in the placeholder |
143 | | $el.html('<img src="' + url + '" />'); |
| 154 | $el.html('<img src="' + attachment.url + '" />'); |
144 | 155 | $holder.removeClass('empty').show(); |
145 | 156 | } |
146 | 157 | }); |
diff --git wp-includes/js/media-editor.js wp-includes/js/media-editor.js
index 561171e..1fde563 100644
|
|
|
144 | 144 | |
145 | 145 | shortcode = {}; |
146 | 146 | |
| 147 | if ( attachment.width ) |
| 148 | shortcode.width = attachment.width; |
| 149 | |
| 150 | if ( attachment.height ) |
| 151 | shortcode.height = attachment.height; |
| 152 | |
147 | 153 | if ( props.mime ) { |
148 | 154 | switch ( props.mime ) { |
149 | 155 | case 'video/mp4': |
diff --git wp-includes/media.php wp-includes/media.php
index ab2cf3e..873139f 100644
|
|
function wp_prepare_attachment_for_js( $attachment ) { |
1638 | 1638 | } |
1639 | 1639 | |
1640 | 1640 | $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); |
| 1641 | } elseif ( $meta && 'video' === $type ) { |
| 1642 | if ( isset( $meta['width'] ) ) |
| 1643 | $response['width'] = (int) $meta['width']; |
| 1644 | if ( isset( $meta['height'] ) ) |
| 1645 | $response['height'] = (int) $meta['height']; |
1641 | 1646 | } |
1642 | 1647 | |
1643 | 1648 | if ( function_exists('get_compat_media_markup') ) |
… |
… |
function wp_video_embed( $matches, $attr, $url, $rawattr ) { |
2014 | 2019 | if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) { |
2015 | 2020 | $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] ); |
2016 | 2021 | $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] ); |
| 2022 | } elseif ( strstr( $url, home_url() ) ) { |
| 2023 | $id = attachment_url_to_postid( $url ); |
| 2024 | if ( ! empty( $id ) ) { |
| 2025 | $meta = wp_get_attachment_metadata( $id ); |
| 2026 | if ( ! empty( $meta['width'] ) ) |
| 2027 | $dimensions .= sprintf( 'width="%d" ', (int) $meta['width'] ); |
| 2028 | if ( ! empty( $meta['height'] ) ) |
| 2029 | $dimensions .= sprintf( 'height="%d" ', (int) $meta['height'] ); |
| 2030 | } |
2017 | 2031 | } |
2018 | 2032 | $video = do_shortcode( '[video ' . $dimensions . 'src="' . $url . '" /]' ); |
2019 | 2033 | } |
… |
… |
function get_the_image( $attached_size = 'full', &$post = null ) { |
2437 | 2451 | */ |
2438 | 2452 | function the_image( $attached_size = 'full' ) { |
2439 | 2453 | echo get_the_image( $attached_size ); |
| 2454 | } |
| 2455 | |
| 2456 | /** |
| 2457 | * Retrieve the post id for an attachment file URL |
| 2458 | * |
| 2459 | * @since 3.6.0 |
| 2460 | * |
| 2461 | * @param string $url Permalink to check. |
| 2462 | * @return int Post ID, or 0 on failure. |
| 2463 | */ |
| 2464 | function attachment_url_to_postid( $url ) { |
| 2465 | global $wpdb; |
| 2466 | if ( preg_match( '#\.[a-zA-Z0-9]+$#', $url ) ) { |
| 2467 | $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' " . |
| 2468 | "AND guid = %s", $url ) ); |
| 2469 | |
| 2470 | if ( ! empty( $id ) ) |
| 2471 | return (int) $id; |
| 2472 | } |
| 2473 | |
| 2474 | return 0; |
2440 | 2475 | } |
| 2476 | No newline at end of file |