Improved XML handling for oEmbed.
git-svn-id: http://core.svn.wordpress.org/trunk@24902 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b1bd0841a4
commit
c30925d20e
|
@ -221,27 +221,52 @@ class WP_oEmbed {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _parse_xml( $response_body ) {
|
function _parse_xml( $response_body ) {
|
||||||
if ( !function_exists('simplexml_load_string') ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ( ! function_exists( 'libxml_disable_entity_loader' ) )
|
if ( ! function_exists( 'libxml_disable_entity_loader' ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$loader = libxml_disable_entity_loader( true );
|
$loader = libxml_disable_entity_loader( true );
|
||||||
|
|
||||||
$errors = libxml_use_internal_errors( true );
|
$errors = libxml_use_internal_errors( true );
|
||||||
$data = simplexml_load_string( $response_body );
|
|
||||||
libxml_use_internal_errors( $errors );
|
|
||||||
|
|
||||||
$return = false;
|
$return = $this->_parse_xml_body( $response_body );
|
||||||
if ( is_object( $data ) ) {
|
|
||||||
$return = new stdClass;
|
libxml_use_internal_errors( $errors );
|
||||||
foreach ( $data as $key => $value ) {
|
libxml_disable_entity_loader( $loader );
|
||||||
$return->$key = (string) $value;
|
|
||||||
}
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for parsing an XML response body.
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
private function _parse_xml_body( $response_body ) {
|
||||||
|
if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument' ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$dom = new DOMDocument;
|
||||||
|
$success = $dom->loadXML( $response_body );
|
||||||
|
if ( ! $success )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( isset( $dom->doctype ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
foreach ( $dom->childNodes as $child ) {
|
||||||
|
if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$xml = simplexml_import_dom( $dom );
|
||||||
|
if ( ! $xml )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$return = new stdClass;
|
||||||
|
foreach ( $xml as $key => $value ) {
|
||||||
|
$return->$key = (string) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
libxml_disable_entity_loader( $loader );
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue