Make WordPress Core

Ticket #26628: 26628.diff

File 26628.diff, 8.1 KB (added by wonderboymusic, 9 years ago)
  • src/wp-includes/class-wp-editor.php

     
    222222                                         * the TinyMCE instance.
    223223                                         */
    224224                                        $plugins = array_unique( apply_filters( 'tiny_mce_plugins', array(
     225                                                'audiovideo',
    225226                                                'charmap',
    226227                                                'link',
    227228                                                'media',
  • src/wp-includes/formatting.php

     
    242242                $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed
    243243                $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
    244244        }
     245        if ( preg_match( '|[\[<]video|', $pee ) ) {
     246                $pee = preg_replace( '#\s*<(track|source)([^>]*)>\s*#', '<$1$2>', $pee ); // no pee inside video tag/shortcode
     247        }
    245248        $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
    246249        // make paragraphs, including one at the end
    247250        $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
     
    258261        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
    259262        if ( $br ) {
    260263                $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);
    261265                $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
    262266                $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    263267        }
  • src/wp-includes/js/media-editor.js

     
    480480                                } else if ( h.indexOf('[gallery') !== -1 ) {
    481481                                        if ( ed.plugins.wpgallery )
    482482                                                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);
    483486                                } else if ( h.indexOf('[embed') === 0 ) {
    484487                                        if ( ed.plugins.wordpress )
    485488                                                h = ed.plugins.wordpress._setEmbed(h);
  • src/wp-includes/js/tinymce/plugins/audiovideo/plugin.js

     
     1/* global tinymce */
     2tinymce.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

     
    122122        border-style: solid;
    123123}
    124124
     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
    125143.mce-content-body img.wp-gallery.wp-gallery-selected {
    126144        background-color: #d8d8d8;
    127145        border-style: solid;
  • src/wp-includes/media.php

     
    12231223                        $html .= sprintf( $source, $type['type'], esc_url( $$fallback ) );
    12241224                }
    12251225        }
     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
    12261234        if ( 'mediaelement' === $library )
    12271235                $html .= wp_mediaelement_fallback( $fileurl );
    12281236        $html .= '</video>';
  • tests/phpunit/tests/media.php

     
    346346                $matches = get_media_embedded_in_content( $content, $types );
    347347                $this->assertEquals( $contents, $matches );
    348348        }
     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]
     365VIDEO;
     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        }
    349386}