Ticket #26628: 26628.diff
File 26628.diff, 8.1 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-editor.php
222 222 * the TinyMCE instance. 223 223 */ 224 224 $plugins = array_unique( apply_filters( 'tiny_mce_plugins', array( 225 'audiovideo', 225 226 'charmap', 226 227 'link', 227 228 'media', -
src/wp-includes/formatting.php
242 242 $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed 243 243 $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee); 244 244 } 245 if ( preg_match( '|[\[<]video|', $pee ) ) { 246 $pee = preg_replace( '#\s*<(track|source)([^>]*)>\s*#', '<$1$2>', $pee ); // no pee inside video tag/shortcode 247 } 245 248 $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates 246 249 // make paragraphs, including one at the end 247 250 $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY); … … 258 261 $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); 259 262 if ( $br ) { 260 263 $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee); 264 $pee = preg_replace_callback('/[\[<]video.*?[\[<]\/video[\]>]/s', '_autop_newline_preservation_helper', $pee); 261 265 $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks 262 266 $pee = str_replace('<WPPreserveNewline />', "\n", $pee); 263 267 } -
src/wp-includes/js/media-editor.js
480 480 } else if ( h.indexOf('[gallery') !== -1 ) { 481 481 if ( ed.plugins.wpgallery ) 482 482 h = ed.plugins.wpgallery._do_gallery(h); 483 } else if ( h.indexOf('[video') !== -1 || h.indexOf('[audio') !== -1 ) { 484 if ( ed.plugins.audiovideo ) 485 h = ed.plugins.audiovideo._do_media(h); 483 486 } else if ( h.indexOf('[embed') === 0 ) { 484 487 if ( ed.plugins.wordpress ) 485 488 h = ed.plugins.wordpress._setEmbed(h); -
src/wp-includes/js/tinymce/plugins/audiovideo/plugin.js
1 /* global tinymce */ 2 tinymce.PluginManager.add('audiovideo', function( editor ) { 3 4 function parseMedia( content ) { 5 return content 6 .replace( /(\[audio[^\]]*\][\s\S]*?\[\/audio\])/g, function( match, attr ) { 7 var data = tinymce.DOM.encode( attr ); 8 9 return '<img src="' + tinymce.Env.transparentSrc + '" class="wp-media-shortcode wp-audio-shortcode mceItem" ' + 10 'title="' + data + '" data-mce-resize="false" data-mce-placeholder="1" />'; 11 }) 12 .replace( /(\[video[^\]]*\][\s\S]*?\[\/video\])/g, function( match, attr ) { 13 var data = tinymce.DOM.encode( attr ); 14 15 return '<img src="' + tinymce.Env.transparentSrc + '" class="wp-media-shortcode wp-video-shortcode mceItem" ' + 16 'title="' + data + '" data-mce-resize="false" data-mce-placeholder="1" />'; 17 }); 18 } 19 20 function getMedia( content ) { 21 function getAttr( str, name ) { 22 name = new RegExp( name + '=\"([^\"]+)\"', 'g' ).exec( str ); 23 return name ? tinymce.DOM.decode( name[1] ) : ''; 24 } 25 26 return content.replace( /(?:<p[^>]*>)*(<img[^>]+>)(?:<\/p>)*/g, function( match, image ) { 27 var cls = getAttr( image, 'class' ); 28 29 if ( cls.indexOf('wp-audio-shortcode') !== -1 ) { 30 return tinymce.trim( getAttr( image, 'title' ) ); 31 } 32 33 if ( cls.indexOf('wp-video-shortcode') !== -1 ) { 34 return tinymce.trim( getAttr( image, 'title' ) ); 35 } 36 37 return match; 38 }); 39 } 40 41 // Display 'media' instead of img in element path 42 editor.on( 'ResolveName', function( e ) { 43 var dom = editor.dom, 44 target = e.target; 45 46 if ( target.nodeName === 'IMG' && dom.hasClass( target, 'wp-audio-shortcode' ) ) { 47 e.name = 'audio'; 48 } 49 50 if ( target.nodeName === 'IMG' && dom.hasClass( target, 'wp-video-shortcode' ) ) { 51 e.name = 'video'; 52 } 53 }); 54 55 editor.on( 'BeforeSetContent', function( e ) { 56 e.content = parseMedia( e.content ); 57 }); 58 59 editor.on( 'PostProcess', function( e ) { 60 if ( e.get ) { 61 e.content = getMedia( e.content ); 62 } 63 }); 64 65 return { 66 _do_media: parseMedia, 67 _get_media: getMedia 68 }; 69 }); -
src/wp-includes/js/tinymce/skins/wordpress/wp-content.css
122 122 border-style: solid; 123 123 } 124 124 125 .mce-content-body img.wp-media-shortcode { 126 border: 1px dashed #888; 127 background: #f2f2f2 url("images/embedded.png") no-repeat scroll center center; 128 width: 99%; 129 height: 250px; 130 outline: 0; 131 cursor: pointer; 132 } 133 134 .mce-content-body img.wp-audio-shortcode { 135 height: 100px; 136 } 137 138 .mce-content-body img.wp-media-shortcode:hover { 139 background-color: #ededed; 140 border-style: solid; 141 } 142 125 143 .mce-content-body img.wp-gallery.wp-gallery-selected { 126 144 background-color: #d8d8d8; 127 145 border-style: solid; -
src/wp-includes/media.php
1223 1223 $html .= sprintf( $source, $type['type'], esc_url( $$fallback ) ); 1224 1224 } 1225 1225 } 1226 1227 if ( ! empty( $content ) ) { 1228 if ( false !== strpos( $content, "\n" ) ) 1229 $content = str_replace( array( "\r\n", "\n", "\t" ), '', $content ); 1230 1231 $html .= trim( $content ); 1232 } 1233 1226 1234 if ( 'mediaelement' === $library ) 1227 1235 $html .= wp_mediaelement_fallback( $fileurl ); 1228 1236 $html .= '</video>'; -
tests/phpunit/tests/media.php
346 346 $matches = get_media_embedded_in_content( $content, $types ); 347 347 $this->assertEquals( $contents, $matches ); 348 348 } 349 350 function test_video_shortcode_body() { 351 $width = 640; 352 $height = 360; 353 354 $video =<<<VIDEO 355 [video width="640" height="360" mp4="http://wordpress-core-develop/wp-content/uploads/2013/12/XVMwB.mp4"] 356 <!-- WebM/VP8 for Firefox4, Opera, and Chrome --> 357 <source type="video/webm" src="myvideo.webm" /> 358 <!-- Ogg/Vorbis for older Firefox and Opera versions --> 359 <source type="video/ogg" src="myvideo.ogv" /> 360 <!-- Optional: Add subtitles for each language --> 361 <track kind="subtitles" src="subtitles.srt" srclang="en" /> 362 <!-- Optional: Add chapters --> 363 <track kind="chapters" src="chapters.srt" srclang="en" /> 364 [/video] 365 VIDEO; 366 367 $w = $GLOBALS['content_width']; 368 $h = ceil( ( $height * $w ) / $width ); 369 370 $content = apply_filters( 'the_content', $video ); 371 372 $expected = '<div style="width: ' . $w . 'px; max-width: 100%;" class="wp-video">' . 373 '<!--[if lt IE 9]><script>document.createElement(\'video\');</script><![endif]--> 374 <video class="wp-video-shortcode" id="video-0-1" width="' . $w . '" height="' . $h . '" preload="metadata" controls="controls">' . 375 '<source type="video/mp4" src="http://wordpress-core-develop/wp-content/uploads/2013/12/XVMwB.mp4" />' . 376 '<!-- WebM/VP8 for Firefox4, Opera, and Chrome --><source type="video/webm" src="myvideo.webm" />' . 377 '<!-- Ogg/Vorbis for older Firefox and Opera versions --><source type="video/ogg" src="myvideo.ogv" />' . 378 '<!-- Optional: Add subtitles for each language --><track kind="subtitles" src="subtitles.srt" srclang="en" />' . 379 '<!-- Optional: Add chapters --><track kind="chapters" src="chapters.srt" srclang="en" />' . 380 '<a href="http://wordpress-core-develop/wp-content/uploads/2013/12/XVMwB.mp4">' . 381 'http://wordpress-core-develop/wp-content/uploads/2013/12/XVMwB.mp4</a></video></div> 382 '; 383 384 $this->assertEquals( $expected, $content ); 385 } 349 386 }