mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 09:37:42 +01:00
Add access modifier to methods/members in WP_oEmbed
. Adds a magic __call()
method for BC.
See #27881, #22234. Built from https://develop.svn.wordpress.org/trunk@28507 git-svn-id: http://core.svn.wordpress.org/trunk@28333 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d6e5fcab4d
commit
27e8d17be2
@ -18,14 +18,14 @@
|
|||||||
* @since 2.9.0
|
* @since 2.9.0
|
||||||
*/
|
*/
|
||||||
class WP_oEmbed {
|
class WP_oEmbed {
|
||||||
var $providers = array();
|
public $providers = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @uses apply_filters() Filters a list of pre-defined oEmbed providers.
|
* @uses apply_filters() Filters a list of pre-defined oEmbed providers.
|
||||||
*/
|
*/
|
||||||
function __construct() {
|
public function __construct() {
|
||||||
$providers = array(
|
$providers = array(
|
||||||
'#http://(www\.)?youtube\.com/watch.*#i' => array( 'http://www.youtube.com/oembed', true ),
|
'#http://(www\.)?youtube\.com/watch.*#i' => array( 'http://www.youtube.com/oembed', true ),
|
||||||
'#https://(www\.)?youtube\.com/watch.*#i' => array( 'http://www.youtube.com/oembed?scheme=https', true ),
|
'#https://(www\.)?youtube\.com/watch.*#i' => array( 'http://www.youtube.com/oembed?scheme=https', true ),
|
||||||
@ -76,6 +76,18 @@ class WP_oEmbed {
|
|||||||
add_filter( 'oembed_dataparse', array($this, '_strip_newlines'), 10, 3 );
|
add_filter( 'oembed_dataparse', array($this, '_strip_newlines'), 10, 3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make private/protected methods readable for backwards compatibility
|
||||||
|
*
|
||||||
|
* @since 4.0.0
|
||||||
|
* @param string $name
|
||||||
|
* @param array $arguments
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function __call( $name, $arguments ) {
|
||||||
|
return call_user_func_array( array( $this, $name ), $arguments );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The do-it-all function that takes a URL and attempts to return the HTML.
|
* The do-it-all function that takes a URL and attempts to return the HTML.
|
||||||
*
|
*
|
||||||
@ -87,7 +99,7 @@ class WP_oEmbed {
|
|||||||
* @param array $args Optional arguments. Usually passed from a shortcode.
|
* @param array $args Optional arguments. Usually passed from a shortcode.
|
||||||
* @return bool|string False on failure, otherwise the UNSANITIZED (and potentially unsafe) HTML that should be used to embed.
|
* @return bool|string False on failure, otherwise the UNSANITIZED (and potentially unsafe) HTML that should be used to embed.
|
||||||
*/
|
*/
|
||||||
function get_html( $url, $args = '' ) {
|
public function get_html( $url, $args = '' ) {
|
||||||
$provider = false;
|
$provider = false;
|
||||||
|
|
||||||
if ( !isset($args['discover']) )
|
if ( !isset($args['discover']) )
|
||||||
@ -132,7 +144,7 @@ class WP_oEmbed {
|
|||||||
* @param string $url The URL that should be inspected for discovery <link> tags.
|
* @param string $url The URL that should be inspected for discovery <link> tags.
|
||||||
* @return bool|string False on failure, otherwise the oEmbed provider URL.
|
* @return bool|string False on failure, otherwise the oEmbed provider URL.
|
||||||
*/
|
*/
|
||||||
function discover( $url ) {
|
public function discover( $url ) {
|
||||||
$providers = array();
|
$providers = array();
|
||||||
|
|
||||||
// Fetch URL content
|
// Fetch URL content
|
||||||
@ -198,7 +210,7 @@ class WP_oEmbed {
|
|||||||
* @param array $args Optional arguments. Usually passed from a shortcode.
|
* @param array $args Optional arguments. Usually passed from a shortcode.
|
||||||
* @return bool|object False on failure, otherwise the result in the form of an object.
|
* @return bool|object False on failure, otherwise the result in the form of an object.
|
||||||
*/
|
*/
|
||||||
function fetch( $provider, $url, $args = '' ) {
|
public function fetch( $provider, $url, $args = '' ) {
|
||||||
$args = wp_parse_args( $args, wp_embed_defaults() );
|
$args = wp_parse_args( $args, wp_embed_defaults() );
|
||||||
|
|
||||||
$provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
|
$provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
|
||||||
@ -234,7 +246,7 @@ class WP_oEmbed {
|
|||||||
* @param string $format Format to use
|
* @param string $format Format to use
|
||||||
* @return bool|object False on failure, otherwise the result in the form of an object.
|
* @return bool|object False on failure, otherwise the result in the form of an object.
|
||||||
*/
|
*/
|
||||||
function _fetch_with_format( $provider_url_with_args, $format ) {
|
private function _fetch_with_format( $provider_url_with_args, $format ) {
|
||||||
$provider_url_with_args = add_query_arg( 'format', $format, $provider_url_with_args );
|
$provider_url_with_args = add_query_arg( 'format', $format, $provider_url_with_args );
|
||||||
$response = wp_safe_remote_get( $provider_url_with_args );
|
$response = wp_safe_remote_get( $provider_url_with_args );
|
||||||
if ( 501 == wp_remote_retrieve_response_code( $response ) )
|
if ( 501 == wp_remote_retrieve_response_code( $response ) )
|
||||||
@ -251,7 +263,7 @@ class WP_oEmbed {
|
|||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _parse_json( $response_body ) {
|
private function _parse_json( $response_body ) {
|
||||||
return ( ( $data = json_decode( trim( $response_body ) ) ) && is_object( $data ) ) ? $data : false;
|
return ( ( $data = json_decode( trim( $response_body ) ) ) && is_object( $data ) ) ? $data : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +273,7 @@ class WP_oEmbed {
|
|||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _parse_xml( $response_body ) {
|
private function _parse_xml( $response_body ) {
|
||||||
if ( ! function_exists( 'libxml_disable_entity_loader' ) )
|
if ( ! function_exists( 'libxml_disable_entity_loader' ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -318,7 +330,7 @@ class WP_oEmbed {
|
|||||||
* @param string $url The URL to the content that is desired to be embedded.
|
* @param string $url The URL to the content that is desired to be embedded.
|
||||||
* @return bool|string False on error, otherwise the HTML needed to embed.
|
* @return bool|string False on error, otherwise the HTML needed to embed.
|
||||||
*/
|
*/
|
||||||
function data2html( $data, $url ) {
|
public function data2html( $data, $url ) {
|
||||||
if ( ! is_object( $data ) || empty( $data->type ) )
|
if ( ! is_object( $data ) || empty( $data->type ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -373,7 +385,7 @@ class WP_oEmbed {
|
|||||||
* @param string $url The original URL passed to oEmbed.
|
* @param string $url The original URL passed to oEmbed.
|
||||||
* @return string Possibly modified $html
|
* @return string Possibly modified $html
|
||||||
*/
|
*/
|
||||||
function _strip_newlines( $html, $data, $url ) {
|
private function _strip_newlines( $html, $data, $url ) {
|
||||||
if ( false !== strpos( $html, "\n" ) )
|
if ( false !== strpos( $html, "\n" ) )
|
||||||
$html = str_replace( array( "\r\n", "\n" ), '', $html );
|
$html = str_replace( array( "\r\n", "\n" ), '', $html );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user