Make WordPress Core

Ticket #38181: 38181.2.diff

File 38181.2.diff, 4.6 KB (added by morganestes, 9 years ago)

Updated patch to fix some standards issues.

  • src/wp-includes/class-oembed.php

    diff --git src/wp-includes/class-oembed.php src/wp-includes/class-oembed.php
    index 052a215..b0a4c6c 100644
    class WP_oEmbed { 
    4747        private $compat_methods = array( '_fetch_with_format', '_parse_json', '_parse_xml', '_parse_body' );
    4848
    4949        /**
     50         * Regex used to handle Amazon oEmbed requests.
     51         *
     52         * @since  4.7.0
     53         * @access public
     54         * @var string
     55         */
     56        public static $oembed_amazon_format = '#https?://([a-z0-9-]+\.)?amazon\.(com|co\.uk|de|fr|it|es|co\.jp|cn|com\.au|in|com\.mx|com\.br|ca|nl|ru)/.*#i';
     57
     58        /**
    5059         * Constructor.
    5160         *
    5261         * @since 2.9.0
    class WP_oEmbed { 
    104113                        '#https?://www\.facebook\.com/notes/.*#i'             => array( 'https://www.facebook.com/plugins/post/oembed.json/',        true  ),
    105114                        '#https?://www\.facebook\.com/.*/videos/.*#i'         => array( 'https://www.facebook.com/plugins/video/oembed.json/',       true  ),
    106115                        '#https?://www\.facebook\.com/video\.php.*#i'         => array( 'https://www.facebook.com/plugins/video/oembed.json/',       true  ),
     116                        self::$oembed_amazon_format                           => array( 'https://read.amazon.com/kp/api/oembed',                     true  ),
     117                        '#https?://(www\.)?a.co/.*#i'                         => array( 'https://read.amazon.com/kp/api/oembed',                     true  ),
     118                        '#https?://(www\.)?amz.onl/.*#i'                      => array( 'https://read.amazon.com/kp/api/oembed',                     true  ),
     119                        '#https?://(www\.)?amzn.to/.*#i'                      => array( 'https://read.amazon.com/kp/api/oembed',                     true  ),
     120                        '#https?://(www\.)?amzn.eu/.*#i'                      => array( 'https://read.amazon.co.uk/kp/api/oembed',                   true  ),
     121                        '#https?://(www\.)?amzn.in/.*#i'                      => array( 'https://read.amazon.in/kp/api/oembed',                      true  ),
     122                        '#https?://(www\.)?amzn.asia/.*#i'                    => array( 'https://read.amazon.com.au/kp/api/oembed',                  true  ),
     123                        '#https?://(www\.)?z.cn/.*#i'                         => array( 'https://read.amazon.cn/kp/api/oembed',                      true  ),
    107124                );
    108125
    109126                if ( ! empty( self::$early_providers['add'] ) ) {
    class WP_oEmbed { 
    174191                 * | Twitter      | twitter.com/timelines |      Yes       | 4.5.0     |
    175192                 * | Twitter      | twitter.com/moments   |      Yes       | 4.5.0     |
    176193                 * | Facebook     | facebook.com          |      Yes       | 4.7.0     |
     194                 * | Amazon Kindle| a.co                  |      Yes       | 4.7.0     |
     195                 * | Amazon Kindle| amzn.onl              |      Yes       | 4.7.0     |
     196                 * | Amazon Kindle| amzn.to               |      Yes       | 4.7.0     |
     197                 * | Amazon Kindle| amzn.eu               |      Yes       | 4.7.0     |
     198                 * | Amazon Kindle| amzn.in               |      Yes       | 4.7.0     |
     199                 * | Amazon Kindle| amzn.asia             |      Yes       | 4.7.0     |
     200                 * | Amazon Kindle| z.cn                  |      Yes       | 4.7.0     |
    177201                 *
    178202                 * No longer supported providers:
    179203                 *
    class WP_oEmbed { 
    683707
    684708                return str_replace( $tokens, $pre, $stripped );
    685709        }
     710
     711        /**
     712         * Checks if the given URL is an Amazon URL, and if so, alters the
     713         * provider's subdomain and TLD to match the URL's TLD.
     714         *
     715         * These transformations are applied to the oEmbed endpoint served by
     716         * one of the read.amazon.com regionalized domains, which services all
     717         * *.amazon.* URLs for the corresponding region.
     718         *
     719         * This method ensures that oEmbed requests for different Amazon
     720         * marketplaces (.com, .de, .jp, etc) are routed to the correct oEmbed
     721         * endpoint for those marketplaces.
     722         *
     723         * @since  4.7.0
     724         * @access public
     725         *
     726         * @param string $provider The URL to the default oEmbed provider.
     727         * @param string $url      The URL to the content that is desired to be embedded.
     728         * @return string The URL to the oEmbed provider.
     729         */
     730        public function _match_amazon_tld( $provider, $url ) {
     731                if ( 1 !== preg_match( self::$oembed_amazon_format, $url, $matches ) ) {
     732                        return $provider;
     733                }
     734
     735                $tld = $matches[2];
     736                switch ( $tld ) {
     737                        case 'de':
     738                                $subdomain = 'lesen';
     739                                break;
     740                        case 'fr':
     741                                $subdomain = 'lire';
     742                                break;
     743                        case 'it':
     744                                $subdomain = 'leggi';
     745                                break;
     746                        case 'es':
     747                        case 'com.mx':
     748                                $subdomain = 'leer';
     749                                break;
     750                        case 'com.br':
     751                                $subdomain = 'ler';
     752                                break;
     753                        case 'nl':
     754                                $subdomain = 'lezen';
     755                                break;
     756                        default:
     757                                $subdomain = 'read';
     758                }
     759
     760                return preg_replace(
     761                        '#^https://read.amazon.com/#',
     762                        sprintf( 'https://%s.amazon.%s/', $subdomain, $tld ),
     763                        $provider
     764                );
     765        }
    686766}