Make WordPress Core

Changeset 24902


Ignore:
Timestamp:
07/30/2013 09:57:27 PM (13 years ago)
Author:
mdawaffe
Message:

Improved XML handling for oEmbed.

File:
1 edited

Legend:

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

    r24480 r24902  
    222222         */
    223223        function _parse_xml( $response_body ) {
    224                 if ( !function_exists('simplexml_load_string') ) {
    225                         return false;
    226                 }
    227224                if ( ! function_exists( 'libxml_disable_entity_loader' ) )
    228225                        return false;
    229226
    230227                $loader = libxml_disable_entity_loader( true );
    231 
    232228                $errors = libxml_use_internal_errors( true );
    233                 $data = simplexml_load_string( $response_body );
     229
     230                $return = $this->_parse_xml_body( $response_body );
     231
    234232                libxml_use_internal_errors( $errors );
    235 
    236                 $return = false;
    237                 if ( is_object( $data ) ) {
    238                         $return = new stdClass;
    239                         foreach ( $data as $key => $value ) {
    240                                 $return->$key = (string) $value;
    241                         }
    242                 }
    243 
    244233                libxml_disable_entity_loader( $loader );
     234
     235                return $return;
     236        }
     237
     238        /**
     239         * Helper function for parsing an XML response body.
     240         *
     241         * @since 3.6.0
     242         * @access private
     243         */
     244        private function _parse_xml_body( $response_body ) {
     245                if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument' ) )
     246                        return false;
     247
     248                $dom = new DOMDocument;
     249                $success = $dom->loadXML( $response_body );
     250                if ( ! $success )
     251                        return false;
     252
     253                if ( isset( $dom->doctype ) )
     254                        return false;
     255
     256                foreach ( $dom->childNodes as $child ) {
     257                        if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType )
     258                                return false;
     259                }
     260
     261                $xml = simplexml_import_dom( $dom );
     262                if ( ! $xml )
     263                        return false;
     264
     265                $return = new stdClass;
     266                foreach ( $xml as $key => $value ) {
     267                        $return->$key = (string) $value;
     268                }
     269
    245270                return $return;
    246271        }
Note: See TracChangeset for help on using the changeset viewer.