Make WordPress Core

Ticket #25387: 25387.3.diff

File 25387.3.diff, 5.1 KB (added by wonderboymusic, 10 years ago)
  • src/wp-includes/class-wp-embed.php

     
    291291         * @return string Potentially modified $content.
    292292         */
    293293        public function autoembed( $content ) {
    294                 return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content );
     294                return preg_replace_callback( '|(?<!")(?<!"\s)(https?:\/\/[^\s"\[<]+)|im', array( $this, 'autoembed_callback' ), $content );
    295295        }
    296296
    297297        /**
  • tests/phpunit/tests/media.php

     
    437437                $this->assertTrue( has_image_size( 'test-size' ) );
    438438        }
    439439
     440    /**
     441     * @ticket 25387
     442     * Testing variants of Autoembeds within paragraphs and surrounded by other text/markup
     443     */
     444    function test_autoembed_inline_paragraph() {
     445
     446        $embed = new WP_Embed();
     447        $url1 = '<p>
     448http://www.youtube.com/watch?v=ZJrP9irrLZk
     449</p>';
     450        $embed_oembed1 = <<<VIDEOWITHPTAG
     451<p>http://www.youtube.com/watch?v=ZJrP9irrLZk</p>
     452VIDEOWITHPTAG;
     453
     454        $url2 = '<p>test
     455
     456http://www.youtube.com/watch?v=ZJrP9irrLZk
     457
     458test</p>';
     459        $embed_oembed2 = <<<VIDEOWITHPTAGANDTEXT
     460<p>test
     461http://www.youtube.com/watch?v=ZJrP9irrLZk
     462test</p>
     463VIDEOWITHPTAGANDTEXT;
     464
     465        $url3 = 'http://www.youtube.com/watch?v=ZJrP9irrLZk';
     466        $embed_oembed3 = <<<VIDEONOEMBED
     467http://www.youtube.com/watch?v=ZJrP9irrLZk
     468VIDEONOEMBED;
     469
     470        $embed_oembed4 = <<<VIDEOEMBEDWITHSPACE
     471[embed] http://vimeo.com/85107599[/embed]
     472VIDEOEMBEDWITHSPACE;
     473        $url4 = 'http://vimeo.com/85107599';
     474
     475        $embed_oembed5 = <<<LINKWITHSPACE
     476<a href=" http://www.youtube.com/watch?v=ZJrP9irrLZk">Video link not embedded because of space within href attribute</a>
     477LINKWITHSPACE;
     478        $url5 = '<a href=" http://www.youtube.com/watch?v=ZJrP9irrLZk">Video link not embedded because of space within href attribute</a>';
     479
     480        $embed_oembed6 = <<<URLSWHITESPACE
     481So, YouTube video firsthttp://www.youtube.com/watch?v=ZJrP9irrLZk Now, after YouTube comes Vimeo video secondhttp://vimeo.com/85107599 and after Vimeo
     482URLSWHITESPACE;
     483        $url6 = 'So, YouTube video first
     484http://www.youtube.com/watch?v=ZJrP9irrLZk
     485 Now, after YouTube comes Vimeo video second
     486http://vimeo.com/85107599
     487 and after Vimeo';
     488
     489        $embed_oembed7 = <<<STANDARDANCHORLINK
     490<a href="http://www.youtube.com/watch?v=ZJrP9irrLZk">Sample this should be a link</a>
     491STANDARDANCHORLINK;
     492        $url7 = '<a href="http://www.youtube.com/watch?v=ZJrP9irrLZk">Sample this should be a link</a>';
     493
     494        $embed_oembed8 = <<<URLWITHMARKUP
     495Video url surrounded by span styled with border and background
     496<span style="border: 5px solid gray; background: #0000cc;">http://www.youtube.com/watch?v=ZJrP9irrLZk</span>
     497URLWITHMARKUP;
     498        $url8 = 'Video url surrounded by span styled with border and background
     499<span style="border: 5px solid gray; background: #0000cc;">
     500http://www.youtube.com/watch?v=ZJrP9irrLZk
     501</span>';
     502
     503        $embed_oembed9 = <<<EMBEDVIDEOPRESS
     504VideoPress wrapped in [ e m b e d ] tags
     505[embed]http://videos.videopress.com/EsBeI509/video-4f0ea27927_dvd.mp4[/embed]
     506EMBEDVIDEOPRESS;
     507        $url9 = 'VideoPress wrapped in [ e m b e d ] tags
     508[embed]
     509http://videos.videopress.com/EsBeI509/video-4f0ea27927_dvd.mp4
     510[/embed]';
     511
     512        $embed_oembed10 = <<<FLICKRFULLURL
     513<p>http://www.flickr.com/photos/seanhayes/270924038/</p>
     514FLICKRFULLURL;
     515        $url10 = '<p>
     516http://www.flickr.com/photos/seanhayes/270924038/
     517</p>';
     518
     519        $embed_oembed11 = <<<DAILYMOTIONFULLURL
     520<p>http://www.flickr.com/photos/seanhayes/270924038/</p>
     521DAILYMOTIONFULLURL;
     522        $url11 = '<p>http://www.dailymotion.com/video/x1gl4rz_the-rolling-stones-rock-shanghai_news</p>';
     523
     524        $content1 = $embed->autoembed( $embed_oembed1 );
     525        $this->assertContains( $url1, $content1 );
     526
     527        $content2 = $embed->autoembed( $embed_oembed2 );
     528        $this->assertContains( $url2, $content2 );
     529
     530        $content3 = $embed->autoembed( $embed_oembed3 );
     531        $this->assertContains( $url3, $content3 );
     532
     533        $content4 = $embed->autoembed( $embed_oembed4 );
     534        $this->assertContains( $url4, $content4 );
     535
     536        $content5 = $embed->autoembed( $embed_oembed5 );
     537        $this->assertEquals( $url5, $content5 );
     538
     539        $content6 = $embed->autoembed( $embed_oembed6 );
     540        $this->assertContains( $url6, $content6 );
     541
     542        $content7 = $embed->autoembed( $embed_oembed7 );
     543        $this->assertEquals( $url7, $content7 );
     544
     545        $content8 = $embed->autoembed( $embed_oembed8 );
     546        $this->assertEquals( $url8, $content8 );
     547
     548        $content9 = $embed->autoembed( $embed_oembed9 );
     549        $this->assertContains( $url9, $content9 );
     550
     551        $content10 = $embed->autoembed( $embed_oembed10 );
     552        $this->assertEquals( $url10, $content10 );
     553
     554        $content11 = $embed->autoembed( $embed_oembed11 );
     555        $this->assertEquals( $url11, $content11 );
     556    }
    440557}