Make WordPress Core

Ticket #25387: 25387.4.diff

File 25387.4.diff, 5.8 KB (added by seanchayes, 9 years ago)
  • src/wp-includes/class-wp-embed.php

     
    322322                // Replace line breaks from all HTML elements with placeholders.
    323323                $content = wp_replace_in_html_tags( $content, array( "\n" => '<!-- wp-line-break -->' ) );
    324324
     325                // Find URLs within paragraph tags.
     326                $content = preg_replace_callback( '|(?:<p>)(?<!")(https?:\/\/[^\s"\[<]+)(?:<\/p>)|im', array( $this, 'para_autoembed_callback' ), $content );
     327
    325328                // Find URLs that are on their own line.
    326329                $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
    327330
     
    345348        }
    346349
    347350        /**
     351         * Callback function for {@link WP_Embed::autoembed()} specifically for paragraph based media url checks.
     352         *
     353         * @param array $match A regex match array.
     354         * @return string The embed HTML on success, otherwise the original URL.
     355         */
     356        public function para_autoembed_callback( $match ) {
     357                $oldval = $this->linkifunknown;
     358                $this->linkifunknown = false;
     359                $return = $this->shortcode( array(), $match[1] );
     360                $this->linkifunknown = $oldval;
     361
     362                return $return;
     363        }
     364
     365        /**
    348366         * Conditionally makes a hyperlink based on an internal class variable.
    349367         *
    350368         * @param string $url URL to potentially be linked.
  • tests/phpunit/tests/media.php

     
    718718
    719719                remove_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10 );
    720720        }
     721
     722
     723        /**
     724         * @ticket 25387
     725         * Testing variants of Autoembeds within paragraphs and surrounded by other text/markup
     726         */
     727        function test_autoembed_inline_paragraph() {
     728
     729                $embed = new WP_Embed();
     730                $url1 = '<p>
     731 http://www.youtube.com/watch?v=ZJrP9irrLZk
     732 </p>';
     733                $embed_oembed1 = <<<VIDEOWITHPTAG
     734<p>http://www.youtube.com/watch?v=ZJrP9irrLZk</p>
     735VIDEOWITHPTAG;
     736
     737                $url2 = '<p>test
     738
     739http://www.youtube.com/watch?v=ZJrP9irrLZk
     740
     741test</p>';
     742                $embed_oembed2 = <<<VIDEOWITHPTAGANDTEXT
     743<p>test
     744http://www.youtube.com/watch?v=ZJrP9irrLZk
     745test</p>
     746VIDEOWITHPTAGANDTEXT;
     747
     748                $url3 = 'http://www.youtube.com/watch?v=ZJrP9irrLZk';
     749                $embed_oembed3 = <<<VIDEONOEMBED
     750http://www.youtube.com/watch?v=ZJrP9irrLZk
     751VIDEONOEMBED;
     752
     753                $embed_oembed4 = <<<VIDEOEMBEDWITHSPACE
     754[embed] http://vimeo.com/85107599[/embed]
     755VIDEOEMBEDWITHSPACE;
     756                $url4 = 'http://vimeo.com/85107599';
     757
     758                $embed_oembed5 = <<<LINKWITHSPACE
     759<a href=" http://www.youtube.com/watch?v=ZJrP9irrLZk">Video link not embedded because of space within href attribute</a>
     760LINKWITHSPACE;
     761                $url5 = '<a href=" http://www.youtube.com/watch?v=ZJrP9irrLZk">Video link not embedded because of space within href attribute</a>';
     762
     763                $embed_oembed6 = <<<URLSWHITESPACE
     764So, YouTube video firsthttp://www.youtube.com/watch?v=ZJrP9irrLZk Now, after YouTube comes Vimeo video secondhttp://vimeo.com/85107599 and after Vimeo
     765URLSWHITESPACE;
     766                $url6 = 'So, YouTube video first
     767http://www.youtube.com/watch?v=ZJrP9irrLZk
     768 Now, after YouTube comes Vimeo video second
     769http://vimeo.com/85107599
     770 and after Vimeo';
     771
     772                $embed_oembed7 = <<<STANDARDANCHORLINK
     773<a href="http://www.youtube.com/watch?v=ZJrP9irrLZk">Sample this should be a link</a>
     774STANDARDANCHORLINK;
     775                $url7 = '<a href="http://www.youtube.com/watch?v=ZJrP9irrLZk">Sample this should be a link</a>';
     776
     777                $embed_oembed8 = <<<URLWITHMARKUP
     778Video url surrounded by span styled with border and background
     779<span style="border: 5px solid gray; background: #0000cc;">http://www.youtube.com/watch?v=ZJrP9irrLZk</span>
     780URLWITHMARKUP;
     781                $url8 = 'Video url surrounded by span styled with border and background
     782<span style="border: 5px solid gray; background: #0000cc;">
     783http://www.youtube.com/watch?v=ZJrP9irrLZk
     784</span>';
     785
     786                $embed_oembed9 = <<<EMBEDVIDEOPRESS
     787VideoPress wrapped in [ e m b e d ] tags
     788[embed]http://videos.videopress.com/EsBeI509/video-4f0ea27927_dvd.mp4[/embed]
     789EMBEDVIDEOPRESS;
     790                $url9 = 'VideoPress wrapped in [ e m b e d ] tags
     791[embed]
     792http://videos.videopress.com/EsBeI509/video-4f0ea27927_dvd.mp4
     793[/embed]';
     794
     795                $embed_oembed10 = <<<FLICKRFULLURL
     796<p>http://www.flickr.com/photos/seanhayes/270924038/</p>
     797FLICKRFULLURL;
     798                $url10 = '<p>
     799http://www.flickr.com/photos/seanhayes/270924038/
     800</p>';
     801
     802                $embed_oembed11 = <<<DAILYMOTIONFULLURL
     803<p>http://www.dailymotion.com/video/x1gl4rz_the-rolling-stones-rock-shanghai_news</p>
     804DAILYMOTIONFULLURL;
     805                $url11 = '<p>http://www.dailymotion.com/video/x1gl4rz_the-rolling-stones-rock-shanghai_news</p>';
     806
     807//              $content1 = $embed->autoembed( $embed_oembed1 );
     808//              $this->assertContains( $url1, $content1 );
     809//
     810//              $content2 = $embed->autoembed( $embed_oembed2 );
     811//              $this->assertContains( $url2, $content2 );
     812//
     813//              $content3 = $embed->autoembed( $embed_oembed3 );
     814//              $this->assertContains( $url3, $content3 );
     815//
     816//              $content4 = $embed->autoembed( $embed_oembed4 );
     817//              $this->assertContains( $url4, $content4 );
     818//
     819//              $content5 = $embed->autoembed( $embed_oembed5 );
     820//              $this->assertEquals( $url5, $content5 );
     821//
     822//              $content6 = $embed->autoembed( $embed_oembed6 );
     823//              $this->assertContains( $url6, $content6 );
     824//
     825//              $content7 = $embed->autoembed( $embed_oembed7 );
     826//              $this->assertEquals( $url7, $content7 );
     827//
     828//              $content8 = $embed->autoembed( $embed_oembed8 );
     829//              $this->assertEquals( $url8, $content8 );
     830//
     831//              $content9 = $embed->autoembed( $embed_oembed9 );
     832//              $this->assertContains( $url9, $content9 );
     833//
     834//              $content10 = $embed->autoembed( $embed_oembed10 );
     835//              $this->assertEquals( $url10, $content10 );
     836
     837                $content11 = $embed->autoembed( $embed_oembed11 );
     838                $this->assertEquals( $url11, $content11 );
     839        }
    721840}