Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-oembed.php

    r42151 r42343  
    5050     */
    5151    public function __construct() {
    52         $host = urlencode( home_url() );
     52        $host      = urlencode( home_url() );
    5353        $providers = array(
    54             '#https?://((m|www)\.)?youtube\.com/watch.*#i'                        => array( 'https://www.youtube.com/oembed',                        true ),
    55             '#https?://((m|www)\.)?youtube\.com/playlist.*#i'                     => array( 'https://www.youtube.com/oembed',                        true ),
    56             '#https?://youtu\.be/.*#i'                                            => array( 'https://www.youtube.com/oembed',                        true ),
    57             '#https?://(.+\.)?vimeo\.com/.*#i'                                    => array( 'https://vimeo.com/api/oembed.{format}',                 true ),
    58             '#https?://(www\.)?dailymotion\.com/.*#i'                             => array( 'https://www.dailymotion.com/services/oembed',           true ),
    59             '#https?://dai\.ly/.*#i'                                              => array( 'https://www.dailymotion.com/services/oembed',           true ),
    60             '#https?://(www\.)?flickr\.com/.*#i'                                  => array( 'https://www.flickr.com/services/oembed/',               true ),
    61             '#https?://flic\.kr/.*#i'                                             => array( 'https://www.flickr.com/services/oembed/',               true ),
    62             '#https?://(.+\.)?smugmug\.com/.*#i'                                  => array( 'https://api.smugmug.com/services/oembed/',              true ),
    63             '#https?://(www\.)?hulu\.com/watch/.*#i'                              => array( 'http://www.hulu.com/api/oembed.{format}',               true ),
    64             'http://i*.photobucket.com/albums/*'                                  => array( 'http://api.photobucket.com/oembed',                    false ),
    65             'http://gi*.photobucket.com/groups/*'                                 => array( 'http://api.photobucket.com/oembed',                    false ),
    66             '#https?://(www\.)?scribd\.com/doc/.*#i'                              => array( 'https://www.scribd.com/services/oembed',                true ),
    67             '#https?://wordpress\.tv/.*#i'                                        => array( 'https://wordpress.tv/oembed/',                          true ),
    68             '#https?://(.+\.)?polldaddy\.com/.*#i'                                => array( 'https://polldaddy.com/oembed/',                         true ),
    69             '#https?://poll\.fm/.*#i'                                             => array( 'https://polldaddy.com/oembed/',                         true ),
    70             '#https?://(www\.)?funnyordie\.com/videos/.*#i'                       => array( 'http://www.funnyordie.com/oembed',                      true ),
    71             '#https?://(www\.)?twitter\.com/\w{1,15}/status(es)?/.*#i'            => array( 'https://publish.twitter.com/oembed',                    true ),
    72             '#https?://(www\.)?twitter\.com/\w{1,15}$#i'                          => array( 'https://publish.twitter.com/oembed',                    true ),
    73             '#https?://(www\.)?twitter\.com/\w{1,15}/likes$#i'                    => array( 'https://publish.twitter.com/oembed',                    true ),
    74             '#https?://(www\.)?twitter\.com/\w{1,15}/lists/.*#i'                  => array( 'https://publish.twitter.com/oembed',                    true ),
    75             '#https?://(www\.)?twitter\.com/\w{1,15}/timelines/.*#i'              => array( 'https://publish.twitter.com/oembed',                    true ),
    76             '#https?://(www\.)?twitter\.com/i/moments/.*#i'                       => array( 'https://publish.twitter.com/oembed',                    true ),
    77             '#https?://(www\.)?soundcloud\.com/.*#i'                              => array( 'https://soundcloud.com/oembed',                         true ),
    78             '#https?://(.+?\.)?slideshare\.net/.*#i'                              => array( 'https://www.slideshare.net/api/oembed/2',               true ),
    79             '#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i'                      => array( 'https://api.instagram.com/oembed',                      true ),
    80             '#https?://(open|play)\.spotify\.com/.*#i'                            => array( 'https://embed.spotify.com/oembed/',                     true ),
    81             '#https?://(.+\.)?imgur\.com/.*#i'                                    => array( 'https://api.imgur.com/oembed',                          true ),
    82             '#https?://(www\.)?meetu(\.ps|p\.com)/.*#i'                           => array( 'https://api.meetup.com/oembed',                         true ),
    83             '#https?://(www\.)?issuu\.com/.+/docs/.+#i'                           => array( 'https://issuu.com/oembed_wp',                           true ),
    84             '#https?://(www\.)?collegehumor\.com/video/.*#i'                      => array( 'https://www.collegehumor.com/oembed.{format}',          true ),
    85             '#https?://(www\.)?mixcloud\.com/.*#i'                                => array( 'https://www.mixcloud.com/oembed',                       true ),
    86             '#https?://(www\.|embed\.)?ted\.com/talks/.*#i'                       => array( 'https://www.ted.com/services/v1/oembed.{format}',       true ),
    87             '#https?://(www\.)?(animoto|video214)\.com/play/.*#i'                 => array( 'https://animoto.com/oembeds/create',                    true ),
    88             '#https?://(.+)\.tumblr\.com/post/.*#i'                               => array( 'https://www.tumblr.com/oembed/1.0',                     true ),
    89             '#https?://(www\.)?kickstarter\.com/projects/.*#i'                    => array( 'https://www.kickstarter.com/services/oembed',           true ),
    90             '#https?://kck\.st/.*#i'                                              => array( 'https://www.kickstarter.com/services/oembed',           true ),
    91             '#https?://cloudup\.com/.*#i'                                         => array( 'https://cloudup.com/oembed',                            true ),
    92             '#https?://(www\.)?reverbnation\.com/.*#i'                            => array( 'https://www.reverbnation.com/oembed',                   true ),
    93             '#https?://videopress\.com/v/.*#'                                     => array( 'https://public-api.wordpress.com/oembed/?for=' . $host, true ),
    94             '#https?://(www\.)?reddit\.com/r/[^/]+/comments/.*#i'                 => array( 'https://www.reddit.com/oembed',                         true ),
    95             '#https?://(www\.)?speakerdeck\.com/.*#i'                             => array( 'https://speakerdeck.com/oembed.{format}',               true ),
    96             '#https?://www\.facebook\.com/.*/posts/.*#i'                          => array( 'https://www.facebook.com/plugins/post/oembed.json/',    true ),
    97             '#https?://www\.facebook\.com/.*/activity/.*#i'                       => array( 'https://www.facebook.com/plugins/post/oembed.json/',    true ),
    98             '#https?://www\.facebook\.com/.*/photos/.*#i'                         => array( 'https://www.facebook.com/plugins/post/oembed.json/',    true ),
    99             '#https?://www\.facebook\.com/photo(s/|\.php).*#i'                    => array( 'https://www.facebook.com/plugins/post/oembed.json/',    true ),
    100             '#https?://www\.facebook\.com/permalink\.php.*#i'                     => array( 'https://www.facebook.com/plugins/post/oembed.json/',    true ),
    101             '#https?://www\.facebook\.com/media/.*#i'                             => array( 'https://www.facebook.com/plugins/post/oembed.json/',    true ),
    102             '#https?://www\.facebook\.com/questions/.*#i'                         => array( 'https://www.facebook.com/plugins/post/oembed.json/',    true ),
    103             '#https?://www\.facebook\.com/notes/.*#i'                             => array( 'https://www.facebook.com/plugins/post/oembed.json/',    true ),
    104             '#https?://www\.facebook\.com/.*/videos/.*#i'                         => array( 'https://www.facebook.com/plugins/video/oembed.json/',   true ),
    105             '#https?://www\.facebook\.com/video\.php.*#i'                         => array( 'https://www.facebook.com/plugins/video/oembed.json/',   true ),
    106             '#https?://(www\.)?screencast\.com/.*#i'                              => array( 'https://api.screencast.com/external/oembed',            true ),
    107             '#https?://([a-z0-9-]+\.)?amazon\.(com|com\.mx|com\.br|ca)/.*#i'      => array( 'https://read.amazon.com/kp/api/oembed',                 true ),
    108             '#https?://([a-z0-9-]+\.)?amazon\.(co\.uk|de|fr|it|es|in|nl|ru)/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed',               true ),
    109             '#https?://([a-z0-9-]+\.)?amazon\.(co\.jp|com\.au)/.*#i'              => array( 'https://read.amazon.com.au/kp/api/oembed',              true ),
    110             '#https?://([a-z0-9-]+\.)?amazon\.cn/.*#i'                            => array( 'https://read.amazon.cn/kp/api/oembed',                  true ),
    111             '#https?://(www\.)?a\.co/.*#i'                                        => array( 'https://read.amazon.com/kp/api/oembed',                 true ),
    112             '#https?://(www\.)?amzn\.to/.*#i'                                     => array( 'https://read.amazon.com/kp/api/oembed',                 true ),
    113             '#https?://(www\.)?amzn\.eu/.*#i'                                     => array( 'https://read.amazon.co.uk/kp/api/oembed',               true ),
    114             '#https?://(www\.)?amzn\.in/.*#i'                                     => array( 'https://read.amazon.in/kp/api/oembed',                  true ),
    115             '#https?://(www\.)?amzn\.asia/.*#i'                                   => array( 'https://read.amazon.com.au/kp/api/oembed',              true ),
    116             '#https?://(www\.)?z\.cn/.*#i'                                        => array( 'https://read.amazon.cn/kp/api/oembed',                  true ),
    117             '#https?://www\.someecards\.com/.+-cards/.+#i'                        => array( 'https://www.someecards.com/v2/oembed/',                 true ),
    118             '#https?://www\.someecards\.com/usercards/viewcard/.+#i'              => array( 'https://www.someecards.com/v2/oembed/',                 true ),
    119             '#https?://some\.ly\/.+#i'                                            => array( 'https://www.someecards.com/v2/oembed/',                 true ),
     54            '#https?://((m|www)\.)?youtube\.com/watch.*#i' => array( 'https://www.youtube.com/oembed', true ),
     55            '#https?://((m|www)\.)?youtube\.com/playlist.*#i' => array( 'https://www.youtube.com/oembed', true ),
     56            '#https?://youtu\.be/.*#i'                     => array( 'https://www.youtube.com/oembed', true ),
     57            '#https?://(.+\.)?vimeo\.com/.*#i'             => array( 'https://vimeo.com/api/oembed.{format}', true ),
     58            '#https?://(www\.)?dailymotion\.com/.*#i'      => array( 'https://www.dailymotion.com/services/oembed', true ),
     59            '#https?://dai\.ly/.*#i'                       => array( 'https://www.dailymotion.com/services/oembed', true ),
     60            '#https?://(www\.)?flickr\.com/.*#i'           => array( 'https://www.flickr.com/services/oembed/', true ),
     61            '#https?://flic\.kr/.*#i'                      => array( 'https://www.flickr.com/services/oembed/', true ),
     62            '#https?://(.+\.)?smugmug\.com/.*#i'           => array( 'https://api.smugmug.com/services/oembed/', true ),
     63            '#https?://(www\.)?hulu\.com/watch/.*#i'       => array( 'http://www.hulu.com/api/oembed.{format}', true ),
     64            'http://i*.photobucket.com/albums/*'           => array( 'http://api.photobucket.com/oembed', false ),
     65            'http://gi*.photobucket.com/groups/*'          => array( 'http://api.photobucket.com/oembed', false ),
     66            '#https?://(www\.)?scribd\.com/doc/.*#i'       => array( 'https://www.scribd.com/services/oembed', true ),
     67            '#https?://wordpress\.tv/.*#i'                 => array( 'https://wordpress.tv/oembed/', true ),
     68            '#https?://(.+\.)?polldaddy\.com/.*#i'         => array( 'https://polldaddy.com/oembed/', true ),
     69            '#https?://poll\.fm/.*#i'                      => array( 'https://polldaddy.com/oembed/', true ),
     70            '#https?://(www\.)?funnyordie\.com/videos/.*#i' => array( 'http://www.funnyordie.com/oembed', true ),
     71            '#https?://(www\.)?twitter\.com/\w{1,15}/status(es)?/.*#i' => array( 'https://publish.twitter.com/oembed', true ),
     72            '#https?://(www\.)?twitter\.com/\w{1,15}$#i'   => array( 'https://publish.twitter.com/oembed', true ),
     73            '#https?://(www\.)?twitter\.com/\w{1,15}/likes$#i' => array( 'https://publish.twitter.com/oembed', true ),
     74            '#https?://(www\.)?twitter\.com/\w{1,15}/lists/.*#i' => array( 'https://publish.twitter.com/oembed', true ),
     75            '#https?://(www\.)?twitter\.com/\w{1,15}/timelines/.*#i' => array( 'https://publish.twitter.com/oembed', true ),
     76            '#https?://(www\.)?twitter\.com/i/moments/.*#i' => array( 'https://publish.twitter.com/oembed', true ),
     77            '#https?://(www\.)?soundcloud\.com/.*#i'       => array( 'https://soundcloud.com/oembed', true ),
     78            '#https?://(.+?\.)?slideshare\.net/.*#i'       => array( 'https://www.slideshare.net/api/oembed/2', true ),
     79            '#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i' => array( 'https://api.instagram.com/oembed', true ),
     80            '#https?://(open|play)\.spotify\.com/.*#i'     => array( 'https://embed.spotify.com/oembed/', true ),
     81            '#https?://(.+\.)?imgur\.com/.*#i'             => array( 'https://api.imgur.com/oembed', true ),
     82            '#https?://(www\.)?meetu(\.ps|p\.com)/.*#i'    => array( 'https://api.meetup.com/oembed', true ),
     83            '#https?://(www\.)?issuu\.com/.+/docs/.+#i'    => array( 'https://issuu.com/oembed_wp', true ),
     84            '#https?://(www\.)?collegehumor\.com/video/.*#i' => array( 'https://www.collegehumor.com/oembed.{format}', true ),
     85            '#https?://(www\.)?mixcloud\.com/.*#i'         => array( 'https://www.mixcloud.com/oembed', true ),
     86            '#https?://(www\.|embed\.)?ted\.com/talks/.*#i' => array( 'https://www.ted.com/services/v1/oembed.{format}', true ),
     87            '#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'https://animoto.com/oembeds/create', true ),
     88            '#https?://(.+)\.tumblr\.com/post/.*#i'        => array( 'https://www.tumblr.com/oembed/1.0', true ),
     89            '#https?://(www\.)?kickstarter\.com/projects/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ),
     90            '#https?://kck\.st/.*#i'                       => array( 'https://www.kickstarter.com/services/oembed', true ),
     91            '#https?://cloudup\.com/.*#i'                  => array( 'https://cloudup.com/oembed', true ),
     92            '#https?://(www\.)?reverbnation\.com/.*#i'     => array( 'https://www.reverbnation.com/oembed', true ),
     93            '#https?://videopress\.com/v/.*#'              => array( 'https://public-api.wordpress.com/oembed/?for=' . $host, true ),
     94            '#https?://(www\.)?reddit\.com/r/[^/]+/comments/.*#i' => array( 'https://www.reddit.com/oembed', true ),
     95            '#https?://(www\.)?speakerdeck\.com/.*#i'      => array( 'https://speakerdeck.com/oembed.{format}', true ),
     96            '#https?://www\.facebook\.com/.*/posts/.*#i'   => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ),
     97            '#https?://www\.facebook\.com/.*/activity/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ),
     98            '#https?://www\.facebook\.com/.*/photos/.*#i'  => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ),
     99            '#https?://www\.facebook\.com/photo(s/|\.php).*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ),
     100            '#https?://www\.facebook\.com/permalink\.php.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ),
     101            '#https?://www\.facebook\.com/media/.*#i'      => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ),
     102            '#https?://www\.facebook\.com/questions/.*#i'  => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ),
     103            '#https?://www\.facebook\.com/notes/.*#i'      => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ),
     104            '#https?://www\.facebook\.com/.*/videos/.*#i'  => array( 'https://www.facebook.com/plugins/video/oembed.json/', true ),
     105            '#https?://www\.facebook\.com/video\.php.*#i'  => array( 'https://www.facebook.com/plugins/video/oembed.json/', true ),
     106            '#https?://(www\.)?screencast\.com/.*#i'       => array( 'https://api.screencast.com/external/oembed', true ),
     107            '#https?://([a-z0-9-]+\.)?amazon\.(com|com\.mx|com\.br|ca)/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ),
     108            '#https?://([a-z0-9-]+\.)?amazon\.(co\.uk|de|fr|it|es|in|nl|ru)/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ),
     109            '#https?://([a-z0-9-]+\.)?amazon\.(co\.jp|com\.au)/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ),
     110            '#https?://([a-z0-9-]+\.)?amazon\.cn/.*#i'     => array( 'https://read.amazon.cn/kp/api/oembed', true ),
     111            '#https?://(www\.)?a\.co/.*#i'                 => array( 'https://read.amazon.com/kp/api/oembed', true ),
     112            '#https?://(www\.)?amzn\.to/.*#i'              => array( 'https://read.amazon.com/kp/api/oembed', true ),
     113            '#https?://(www\.)?amzn\.eu/.*#i'              => array( 'https://read.amazon.co.uk/kp/api/oembed', true ),
     114            '#https?://(www\.)?amzn\.in/.*#i'              => array( 'https://read.amazon.in/kp/api/oembed', true ),
     115            '#https?://(www\.)?amzn\.asia/.*#i'            => array( 'https://read.amazon.com.au/kp/api/oembed', true ),
     116            '#https?://(www\.)?z\.cn/.*#i'                 => array( 'https://read.amazon.cn/kp/api/oembed', true ),
     117            '#https?://www\.someecards\.com/.+-cards/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ),
     118            '#https?://www\.someecards\.com/usercards/viewcard/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ),
     119            '#https?://some\.ly\/.+#i'                     => array( 'https://www.someecards.com/v2/oembed/', true ),
    120120        );
    121121
     
    222222
    223223        // Fix any embeds that contain new lines in the middle of the HTML which breaks wpautop().
    224         add_filter( 'oembed_dataparse', array($this, '_strip_newlines'), 10, 3 );
     224        add_filter( 'oembed_dataparse', array( $this, '_strip_newlines' ), 10, 3 );
    225225    }
    226226
     
    257257        $provider = false;
    258258
    259         if ( !isset($args['discover']) )
     259        if ( ! isset( $args['discover'] ) ) {
    260260            $args['discover'] = true;
     261        }
    261262
    262263        foreach ( $this->providers as $matchmask => $data ) {
     
    264265
    265266            // Turn the asterisk-type provider URLs into regex
    266             if ( !$regex ) {
     267            if ( ! $regex ) {
    267268                $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
    268269                $matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask );
     
    275276        }
    276277
    277         if ( !$provider && $args['discover'] )
     278        if ( ! $provider && $args['discover'] ) {
    278279            $provider = $this->discover( $url );
     280        }
    279281
    280282        return $provider;
     
    423425    public function discover( $url ) {
    424426        $providers = array();
    425         $args = array(
     427        $args      = array(
    426428            'limit_response_size' => 153600, // 150 KB
    427429        );
     
    452454             *                      used by at least Vimeo).
    453455             */
    454             $linktypes = apply_filters( 'oembed_linktypes', array(
    455                 'application/json+oembed' => 'json',
    456                 'text/xml+oembed' => 'xml',
    457                 'application/xml+oembed' => 'xml',
    458             ) );
     456            $linktypes = apply_filters(
     457                'oembed_linktypes', array(
     458                    'application/json+oembed' => 'json',
     459                    'text/xml+oembed'         => 'xml',
     460                    'application/xml+oembed'  => 'xml',
     461                )
     462            );
    459463
    460464            // Strip <body>
     
    466470            $tagfound = false;
    467471            foreach ( $linktypes as $linktype => $format ) {
    468                 if ( stripos($html, $linktype) ) {
     472                if ( stripos( $html, $linktype ) ) {
    469473                    $tagfound = true;
    470474                    break;
     
    476480                    $atts = shortcode_parse_atts( $link );
    477481
    478                     if ( !empty($atts['type']) && !empty($linktypes[$atts['type']]) && !empty($atts['href']) ) {
    479                         $providers[$linktypes[$atts['type']]] = htmlspecialchars_decode( $atts['href'] );
     482                    if ( ! empty( $atts['type'] ) && ! empty( $linktypes[ $atts['type'] ] ) && ! empty( $atts['href'] ) ) {
     483                        $providers[ $linktypes[ $atts['type'] ] ] = htmlspecialchars_decode( $atts['href'] );
    480484
    481485                        // Stop here if it's JSON (that's all we need)
    482                         if ( 'json' == $linktypes[$atts['type']] )
     486                        if ( 'json' == $linktypes[ $atts['type'] ] ) {
    483487                            break;
     488                        }
    484489                    }
    485490                }
     
    488493
    489494        // JSON is preferred to XML
    490         if ( !empty($providers['json']) )
     495        if ( ! empty( $providers['json'] ) ) {
    491496            return $providers['json'];
    492         elseif ( !empty($providers['xml']) )
     497        } elseif ( ! empty( $providers['xml'] ) ) {
    493498            return $providers['xml'];
    494         else
    495             return false;
     499        } else {
     500            return false;
     501        }
    496502    }
    497503
     
    511517        $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
    512518        $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider );
    513         $provider = add_query_arg( 'url', urlencode($url), $provider );
     519        $provider = add_query_arg( 'url', urlencode( $url ), $provider );
    514520        $provider = add_query_arg( 'dnt', 1, $provider );
    515521
     
    528534        foreach ( array( 'json', 'xml' ) as $format ) {
    529535            $result = $this->_fetch_with_format( $provider, $format );
    530             if ( is_wp_error( $result ) && 'not-implemented' == $result->get_error_code() )
     536            if ( is_wp_error( $result ) && 'not-implemented' == $result->get_error_code() ) {
    531537                continue;
     538            }
    532539            return ( $result && ! is_wp_error( $result ) ) ? $result : false;
    533540        }
     
    551558
    552559        $response = wp_safe_remote_get( $provider_url_with_args, $args );
    553         if ( 501 == wp_remote_retrieve_response_code( $response ) )
     560        if ( 501 == wp_remote_retrieve_response_code( $response ) ) {
    554561            return new WP_Error( 'not-implemented' );
    555         if ( ! $body = wp_remote_retrieve_body( $response ) )
    556             return false;
     562        }
     563        if ( ! $body = wp_remote_retrieve_body( $response ) ) {
     564            return false;
     565        }
    557566        $parse_method = "_parse_$format";
    558567        return $this->$parse_method( $body );
     
    581590     */
    582591    private function _parse_xml( $response_body ) {
    583         if ( ! function_exists( 'libxml_disable_entity_loader' ) )
    584             return false;
     592        if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
     593            return false;
     594        }
    585595
    586596        $loader = libxml_disable_entity_loader( true );
     
    604614     */
    605615    private function _parse_xml_body( $response_body ) {
    606         if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument', false ) )
    607             return false;
    608 
    609         $dom = new DOMDocument;
     616        if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument', false ) ) {
     617            return false;
     618        }
     619
     620        $dom     = new DOMDocument;
    610621        $success = $dom->loadXML( $response_body );
    611         if ( ! $success )
    612             return false;
    613 
    614         if ( isset( $dom->doctype ) )
    615             return false;
     622        if ( ! $success ) {
     623            return false;
     624        }
     625
     626        if ( isset( $dom->doctype ) ) {
     627            return false;
     628        }
    616629
    617630        foreach ( $dom->childNodes as $child ) {
    618             if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType )
     631            if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) {
    619632                return false;
     633            }
    620634        }
    621635
    622636        $xml = simplexml_import_dom( $dom );
    623         if ( ! $xml )
    624             return false;
     637        if ( ! $xml ) {
     638            return false;
     639        }
    625640
    626641        $return = new stdClass;
     
    642657     */
    643658    public function data2html( $data, $url ) {
    644         if ( ! is_object( $data ) || empty( $data->type ) )
    645             return false;
     659        if ( ! is_object( $data ) || empty( $data->type ) ) {
     660            return false;
     661        }
    646662
    647663        $return = false;
     
    649665        switch ( $data->type ) {
    650666            case 'photo':
    651                 if ( empty( $data->url ) || empty( $data->width ) || empty( $data->height ) )
     667                if ( empty( $data->url ) || empty( $data->width ) || empty( $data->height ) ) {
    652668                    break;
    653                 if ( ! is_string( $data->url ) || ! is_numeric( $data->width ) || ! is_numeric( $data->height ) )
     669                }
     670                if ( ! is_string( $data->url ) || ! is_numeric( $data->width ) || ! is_numeric( $data->height ) ) {
    654671                    break;
    655 
    656                 $title = ! empty( $data->title ) && is_string( $data->title ) ? $data->title : '';
    657                 $return = '<a href="' . esc_url( $url ) . '"><img src="' . esc_url( $data->url ) . '" alt="' . esc_attr($title) . '" width="' . esc_attr($data->width) . '" height="' . esc_attr($data->height) . '" /></a>';
     672                }
     673
     674                $title  = ! empty( $data->title ) && is_string( $data->title ) ? $data->title : '';
     675                $return = '<a href="' . esc_url( $url ) . '"><img src="' . esc_url( $data->url ) . '" alt="' . esc_attr( $title ) . '" width="' . esc_attr( $data->width ) . '" height="' . esc_attr( $data->height ) . '" /></a>';
    658676                break;
    659677
    660678            case 'video':
    661679            case 'rich':
    662                 if ( ! empty( $data->html ) && is_string( $data->html ) )
     680                if ( ! empty( $data->html ) && is_string( $data->html ) ) {
    663681                    $return = $data->html;
     682                }
    664683                break;
    665684
    666685            case 'link':
    667                 if ( ! empty( $data->title ) && is_string( $data->title ) )
     686                if ( ! empty( $data->title ) && is_string( $data->title ) ) {
    668687                    $return = '<a href="' . esc_url( $url ) . '">' . esc_html( $data->title ) . '</a>';
     688                }
    669689                break;
    670690
     
    703723        }
    704724
    705         $count = 1;
    706         $found = array();
    707         $token = '__PRE__';
    708         $search = array( "\t", "\n", "\r", ' ' );
    709         $replace = array( '__TAB__', '__NL__', '__CR__', '__SPACE__' );
     725        $count     = 1;
     726        $found     = array();
     727        $token     = '__PRE__';
     728        $search    = array( "\t", "\n", "\r", ' ' );
     729        $replace   = array( '__TAB__', '__NL__', '__CR__', '__SPACE__' );
    710730        $tokenized = str_replace( $search, $replace, $html );
    711731
    712732        preg_match_all( '#(<pre[^>]*>.+?</pre>)#i', $tokenized, $matches, PREG_SET_ORDER );
    713733        foreach ( $matches as $i => $match ) {
    714             $tag_html = str_replace( $replace, $search, $match[0] );
     734            $tag_html  = str_replace( $replace, $search, $match[0] );
    715735            $tag_token = $token . $i;
    716736
    717737            $found[ $tag_token ] = $tag_html;
    718             $html = str_replace( $tag_html, $tag_token, $html, $count );
     738            $html                = str_replace( $tag_html, $tag_token, $html, $count );
    719739        }
    720740
    721741        $replaced = str_replace( $replace, $search, $html );
    722742        $stripped = str_replace( array( "\r\n", "\n" ), '', $replaced );
    723         $pre = array_values( $found );
    724         $tokens = array_keys( $found );
     743        $pre      = array_values( $found );
     744        $tokens   = array_keys( $found );
    725745
    726746        return str_replace( $tokens, $pre, $stripped );
Note: See TracChangeset for help on using the changeset viewer.