Make WordPress Core

Ticket #34462: 34462.2.diff

File 34462.2.diff, 5.5 KB (added by pento, 8 years ago)
  • src/wp-includes/embed-functions.php

     
    465465
    466466        $embed_url = get_post_embed_url( $post );
    467467
    468         $output = "<script type='text/javascript'>\n";
     468        $output = '<blockquote><a href="' . get_permalink( $post ) . '">' . get_the_title( $post ) . "</a></blockquote>\n";
     469
     470        $output .= "<script type='text/javascript'>\n";
    469471        $output .= "<!--//--><![CDATA[//><!--\n";
    470472        if ( SCRIPT_DEBUG ) {
    471473                $output .= file_get_contents( ABSPATH . WPINC . '/js/wp-embed.js' );
     
    710712        }
    711713
    712714        $allowed_html = array(
    713                 'iframe' => array(
     715                'a'          => array(
     716                                'href' => true,
     717                ),
     718                'blockquote' => array(),
     719                'iframe'     => array(
    714720                        'src'          => true,
    715721                        'width'        => true,
    716722                        'height'       => true,
     
    724730        );
    725731
    726732        $html = wp_kses( $result, $allowed_html );
    727         preg_match( '|^.*(<iframe.*?></iframe>).*$|m', $html, $iframes );
    728733
    729         if ( empty( $iframes ) ) {
     734        preg_match( '|(<blockquote>.*?</blockquote>)?.*(<iframe.*?></iframe>)|ms', $html, $content );
     735        // We require at least the iframe to exist.
     736        if ( empty( $content[2] ) ) {
    730737                return false;
    731738        }
     739        $html = $content[1] . $content[2];
    732740
    733         $html = str_replace( '<iframe', '<iframe sandbox="allow-scripts" security="restricted"', $iframes[1] );
     741        if ( ! empty( $content[1] ) ) {
     742                // We have a blockquote to fall back on. Hide the iframe by default.
     743                $html = str_replace( '<iframe', '<iframe style="display:none;"', $html );
     744        }
    734745
     746        $html = str_replace( '<iframe', '<iframe sandbox="allow-scripts" security="restricted"', $html );
     747
    735748        preg_match( '/ src=[\'"]([^\'"]*)[\'"]/', $html, $results );
    736749
    737750        if ( ! empty( $results ) ) {
     
    740753                $url = esc_url( "{$results[1]}#?secret=$secret" );
    741754
    742755                $html = str_replace( $results[0], " src=\"$url\" data-secret=\"$secret\"", $html );
     756                $html = str_replace( '<blockquote', "<blockquote data-secret=\"$secret\"", $html );
    743757        }
    744758
    745759        return $html;
  • src/wp-includes/js/wp-embed.js

     
    1313                        return;
    1414                }
    1515
    16                 var iframes = document.querySelectorAll( '.wp-embedded-content[data-secret="' + data.secret + '"]' );
     16                var iframes = document.querySelectorAll( 'iframe[data-secret="' + data.secret + '"]' ),
     17                        blockquotes = document.querySelectorAll( 'blockquote[data-secret="' + data.secret + '"]' ),
     18                        i, source, height, sourceURL, targetURL;
    1719
    18                 for ( var i = 0; i < iframes.length; i++ ) {
    19                         var source = iframes[ i ];
     20                for ( i = 0; i < blockquotes.length; i++ ) {
     21                        blockquotes[ i ].style.display = 'none';
     22                }
    2023
     24                for ( i = 0; i < iframes.length; i++ ) {
     25                        source = iframes[ i ];
     26
     27                        source.style.display = '';
     28
    2129                        /* Resize the iframe on request. */
    2230                        if ( 'height' === data.message ) {
    23                                 var height = data.value;
     31                                height = data.value;
    2432                                if ( height > 1000 ) {
    2533                                        height = 1000;
    2634                                } else if ( height < 200 ) {
     
    3240
    3341                        /* Link to a specific URL on request. */
    3442                        if ( 'link' === data.message ) {
    35                                 var sourceURL = document.createElement( 'a' ), targetURL = document.createElement( 'a' );
     43                                sourceURL = document.createElement( 'a' );
     44                                targetURL = document.createElement( 'a' );
     45
    3646                                sourceURL.href = source.getAttribute( 'src' );
    3747                                targetURL.href = data.value;
    3848
     
    4858
    4959        function onLoad() {
    5060                var isIE10 = -1 !== navigator.appVersion.indexOf( 'MSIE 10' ),
    51                         isIE11 = !!navigator.userAgent.match( /Trident.*rv\:11\./ );
     61                        isIE11 = !!navigator.userAgent.match( /Trident.*rv\:11\./ ),
     62                        iframes, iframeClone, i;
    5263
    5364                /* Remove security attribute from iframes in IE10 and IE11. */
    5465                if ( isIE10 || isIE11 ) {
    55                         var iframes = document.querySelectorAll( '.wp-embedded-content[security]' ), iframeClone;
     66                        iframes = document.querySelectorAll( '.wp-embedded-content[security]' );
    5667
    57                         for ( var i = 0; i < iframes.length; i++ ) {
     68                        for ( i = 0; i < iframes.length; i++ ) {
    5869                                iframeClone = iframes[ i ].cloneNode( true );
    5970                                iframeClone.removeAttribute( 'security' );
    6071                                iframes[ i ].parentNode.insertBefore( iframeClone, iframes[ i ].nextSibling );
  • tests/phpunit/tests/oembed/filterResult.php

     
    7878                $this->assertFalse( wp_filter_oembed_result( false, (object) array( 'type' => 'rich' ), '' ) );
    7979                $this->assertFalse( wp_filter_oembed_result( '', (object) array( 'type' => 'rich' ), '' ) );
    8080        }
     81
     82        function test_filter_oembed_result_blockquote_adds_style_to_iframe() {
     83                $html   = '<blockquote></blockquote><iframe></iframe>';
     84                $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
     85
     86                $this->assertEquals( '<blockquote></blockquote><iframe sandbox="allow-scripts" security="restricted" style="display:none;"></iframe>', $actual );
     87        }
     88
     89        function test_filter_oembed_result_allowed_html() {
     90                $html   = '<blockquote><strong><a href="" target=""></a></strong></blockquote><iframe></iframe>';
     91                $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
     92
     93                $this->assertEquals( '<blockquote><a href=""></a></blockquote><iframe sandbox="allow-scripts" security="restricted" style="display:none;"></iframe>', $actual );
     94        }
    8195}