Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../public_h.../wp-inclu...
File: class-wp-oembed.php
[500] Fix | Delete
// Stop here if it's JSON (that's all we need).
[501] Fix | Delete
if ( 'json' === $linktypes[ $atts['type'] ] ) {
[502] Fix | Delete
break;
[503] Fix | Delete
}
[504] Fix | Delete
}
[505] Fix | Delete
}
[506] Fix | Delete
}
[507] Fix | Delete
}
[508] Fix | Delete
[509] Fix | Delete
// JSON is preferred to XML.
[510] Fix | Delete
if ( ! empty( $providers['json'] ) ) {
[511] Fix | Delete
return $providers['json'];
[512] Fix | Delete
} elseif ( ! empty( $providers['xml'] ) ) {
[513] Fix | Delete
return $providers['xml'];
[514] Fix | Delete
} else {
[515] Fix | Delete
return false;
[516] Fix | Delete
}
[517] Fix | Delete
}
[518] Fix | Delete
[519] Fix | Delete
/**
[520] Fix | Delete
* Connects to an oEmbed provider and returns the result.
[521] Fix | Delete
*
[522] Fix | Delete
* @since 2.9.0
[523] Fix | Delete
*
[524] Fix | Delete
* @param string $provider The URL to the oEmbed provider.
[525] Fix | Delete
* @param string $url The URL to the content that is desired to be embedded.
[526] Fix | Delete
* @param string|array $args Optional. Additional arguments for retrieving embed HTML.
[527] Fix | Delete
* See wp_oembed_get() for accepted arguments. Default empty.
[528] Fix | Delete
* @return object|false The result in the form of an object on success, false on failure.
[529] Fix | Delete
*/
[530] Fix | Delete
public function fetch( $provider, $url, $args = '' ) {
[531] Fix | Delete
$args = wp_parse_args( $args, wp_embed_defaults( $url ) );
[532] Fix | Delete
[533] Fix | Delete
$provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
[534] Fix | Delete
$provider = add_query_arg( 'maxheight', (int) $args['height'], $provider );
[535] Fix | Delete
$provider = add_query_arg( 'url', urlencode( $url ), $provider );
[536] Fix | Delete
$provider = add_query_arg( 'dnt', 1, $provider );
[537] Fix | Delete
[538] Fix | Delete
/**
[539] Fix | Delete
* Filters the oEmbed URL to be fetched.
[540] Fix | Delete
*
[541] Fix | Delete
* @since 2.9.0
[542] Fix | Delete
* @since 4.9.0 The `dnt` (Do Not Track) query parameter was added to all oEmbed provider URLs.
[543] Fix | Delete
*
[544] Fix | Delete
* @param string $provider URL of the oEmbed provider.
[545] Fix | Delete
* @param string $url URL of the content to be embedded.
[546] Fix | Delete
* @param array $args Optional. Additional arguments for retrieving embed HTML.
[547] Fix | Delete
* See wp_oembed_get() for accepted arguments. Default empty.
[548] Fix | Delete
*/
[549] Fix | Delete
$provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args );
[550] Fix | Delete
[551] Fix | Delete
foreach ( array( 'json', 'xml' ) as $format ) {
[552] Fix | Delete
$result = $this->_fetch_with_format( $provider, $format );
[553] Fix | Delete
if ( is_wp_error( $result ) && 'not-implemented' === $result->get_error_code() ) {
[554] Fix | Delete
continue;
[555] Fix | Delete
}
[556] Fix | Delete
[557] Fix | Delete
return ( $result && ! is_wp_error( $result ) ) ? $result : false;
[558] Fix | Delete
}
[559] Fix | Delete
[560] Fix | Delete
return false;
[561] Fix | Delete
}
[562] Fix | Delete
[563] Fix | Delete
/**
[564] Fix | Delete
* Fetches result from an oEmbed provider for a specific format and complete provider URL
[565] Fix | Delete
*
[566] Fix | Delete
* @since 3.0.0
[567] Fix | Delete
*
[568] Fix | Delete
* @param string $provider_url_with_args URL to the provider with full arguments list (url, maxheight, etc.)
[569] Fix | Delete
* @param string $format Format to use.
[570] Fix | Delete
* @return object|false|WP_Error The result in the form of an object on success, false on failure.
[571] Fix | Delete
*/
[572] Fix | Delete
private function _fetch_with_format( $provider_url_with_args, $format ) {
[573] Fix | Delete
$provider_url_with_args = add_query_arg( 'format', $format, $provider_url_with_args );
[574] Fix | Delete
[575] Fix | Delete
/** This filter is documented in wp-includes/class-wp-oembed.php */
[576] Fix | Delete
$args = apply_filters( 'oembed_remote_get_args', array(), $provider_url_with_args );
[577] Fix | Delete
[578] Fix | Delete
$response = wp_safe_remote_get( $provider_url_with_args, $args );
[579] Fix | Delete
[580] Fix | Delete
if ( 501 === wp_remote_retrieve_response_code( $response ) ) {
[581] Fix | Delete
return new WP_Error( 'not-implemented' );
[582] Fix | Delete
}
[583] Fix | Delete
[584] Fix | Delete
$body = wp_remote_retrieve_body( $response );
[585] Fix | Delete
if ( ! $body ) {
[586] Fix | Delete
return false;
[587] Fix | Delete
}
[588] Fix | Delete
[589] Fix | Delete
$parse_method = "_parse_$format";
[590] Fix | Delete
[591] Fix | Delete
return $this->$parse_method( $body );
[592] Fix | Delete
}
[593] Fix | Delete
[594] Fix | Delete
/**
[595] Fix | Delete
* Parses a json response body.
[596] Fix | Delete
*
[597] Fix | Delete
* @since 3.0.0
[598] Fix | Delete
*
[599] Fix | Delete
* @param string $response_body
[600] Fix | Delete
* @return object|false
[601] Fix | Delete
*/
[602] Fix | Delete
private function _parse_json( $response_body ) {
[603] Fix | Delete
$data = json_decode( trim( $response_body ) );
[604] Fix | Delete
[605] Fix | Delete
return ( $data && is_object( $data ) ) ? $data : false;
[606] Fix | Delete
}
[607] Fix | Delete
[608] Fix | Delete
/**
[609] Fix | Delete
* Parses an XML response body.
[610] Fix | Delete
*
[611] Fix | Delete
* @since 3.0.0
[612] Fix | Delete
*
[613] Fix | Delete
* @param string $response_body
[614] Fix | Delete
* @return object|false
[615] Fix | Delete
*/
[616] Fix | Delete
private function _parse_xml( $response_body ) {
[617] Fix | Delete
if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
[618] Fix | Delete
return false;
[619] Fix | Delete
}
[620] Fix | Delete
[621] Fix | Delete
if ( PHP_VERSION_ID < 80000 ) {
[622] Fix | Delete
/*
[623] Fix | Delete
* This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading
[624] Fix | Delete
* is disabled by default, so this function is no longer needed to protect against XXE attacks.
[625] Fix | Delete
*/
[626] Fix | Delete
$loader = libxml_disable_entity_loader( true );
[627] Fix | Delete
}
[628] Fix | Delete
[629] Fix | Delete
$errors = libxml_use_internal_errors( true );
[630] Fix | Delete
[631] Fix | Delete
$return = $this->_parse_xml_body( $response_body );
[632] Fix | Delete
[633] Fix | Delete
libxml_use_internal_errors( $errors );
[634] Fix | Delete
[635] Fix | Delete
if ( PHP_VERSION_ID < 80000 && isset( $loader ) ) {
[636] Fix | Delete
// phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.libxml_disable_entity_loaderDeprecated
[637] Fix | Delete
libxml_disable_entity_loader( $loader );
[638] Fix | Delete
}
[639] Fix | Delete
[640] Fix | Delete
return $return;
[641] Fix | Delete
}
[642] Fix | Delete
[643] Fix | Delete
/**
[644] Fix | Delete
* Serves as a helper function for parsing an XML response body.
[645] Fix | Delete
*
[646] Fix | Delete
* @since 3.6.0
[647] Fix | Delete
*
[648] Fix | Delete
* @param string $response_body
[649] Fix | Delete
* @return stdClass|false
[650] Fix | Delete
*/
[651] Fix | Delete
private function _parse_xml_body( $response_body ) {
[652] Fix | Delete
if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument', false ) ) {
[653] Fix | Delete
return false;
[654] Fix | Delete
}
[655] Fix | Delete
[656] Fix | Delete
$dom = new DOMDocument();
[657] Fix | Delete
$success = $dom->loadXML( $response_body );
[658] Fix | Delete
if ( ! $success ) {
[659] Fix | Delete
return false;
[660] Fix | Delete
}
[661] Fix | Delete
[662] Fix | Delete
if ( isset( $dom->doctype ) ) {
[663] Fix | Delete
return false;
[664] Fix | Delete
}
[665] Fix | Delete
[666] Fix | Delete
foreach ( $dom->childNodes as $child ) {
[667] Fix | Delete
if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) {
[668] Fix | Delete
return false;
[669] Fix | Delete
}
[670] Fix | Delete
}
[671] Fix | Delete
[672] Fix | Delete
$xml = simplexml_import_dom( $dom );
[673] Fix | Delete
if ( ! $xml ) {
[674] Fix | Delete
return false;
[675] Fix | Delete
}
[676] Fix | Delete
[677] Fix | Delete
$return = new stdClass();
[678] Fix | Delete
foreach ( $xml as $key => $value ) {
[679] Fix | Delete
$return->$key = (string) $value;
[680] Fix | Delete
}
[681] Fix | Delete
[682] Fix | Delete
return $return;
[683] Fix | Delete
}
[684] Fix | Delete
[685] Fix | Delete
/**
[686] Fix | Delete
* Converts a data object from WP_oEmbed::fetch() and returns the HTML.
[687] Fix | Delete
*
[688] Fix | Delete
* @since 2.9.0
[689] Fix | Delete
*
[690] Fix | Delete
* @param object $data A data object result from an oEmbed provider.
[691] Fix | Delete
* @param string $url The URL to the content that is desired to be embedded.
[692] Fix | Delete
* @return string|false The HTML needed to embed on success, false on failure.
[693] Fix | Delete
*/
[694] Fix | Delete
public function data2html( $data, $url ) {
[695] Fix | Delete
if ( ! is_object( $data ) || empty( $data->type ) ) {
[696] Fix | Delete
return false;
[697] Fix | Delete
}
[698] Fix | Delete
[699] Fix | Delete
$return = false;
[700] Fix | Delete
[701] Fix | Delete
switch ( $data->type ) {
[702] Fix | Delete
case 'photo':
[703] Fix | Delete
if ( empty( $data->url ) || empty( $data->width ) || empty( $data->height ) ) {
[704] Fix | Delete
break;
[705] Fix | Delete
}
[706] Fix | Delete
if ( ! is_string( $data->url ) || ! is_numeric( $data->width ) || ! is_numeric( $data->height ) ) {
[707] Fix | Delete
break;
[708] Fix | Delete
}
[709] Fix | Delete
[710] Fix | Delete
$title = ! empty( $data->title ) && is_string( $data->title ) ? $data->title : '';
[711] Fix | Delete
$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>';
[712] Fix | Delete
break;
[713] Fix | Delete
[714] Fix | Delete
case 'video':
[715] Fix | Delete
case 'rich':
[716] Fix | Delete
if ( ! empty( $data->html ) && is_string( $data->html ) ) {
[717] Fix | Delete
$return = $data->html;
[718] Fix | Delete
}
[719] Fix | Delete
break;
[720] Fix | Delete
[721] Fix | Delete
case 'link':
[722] Fix | Delete
if ( ! empty( $data->title ) && is_string( $data->title ) ) {
[723] Fix | Delete
$return = '<a href="' . esc_url( $url ) . '">' . esc_html( $data->title ) . '</a>';
[724] Fix | Delete
}
[725] Fix | Delete
break;
[726] Fix | Delete
[727] Fix | Delete
default:
[728] Fix | Delete
$return = false;
[729] Fix | Delete
}
[730] Fix | Delete
[731] Fix | Delete
/**
[732] Fix | Delete
* Filters the returned oEmbed HTML.
[733] Fix | Delete
*
[734] Fix | Delete
* Use this filter to add support for custom data types, or to filter the result.
[735] Fix | Delete
*
[736] Fix | Delete
* @since 2.9.0
[737] Fix | Delete
*
[738] Fix | Delete
* @param string $return The returned oEmbed HTML.
[739] Fix | Delete
* @param object $data A data object result from an oEmbed provider.
[740] Fix | Delete
* @param string $url The URL of the content to be embedded.
[741] Fix | Delete
*/
[742] Fix | Delete
return apply_filters( 'oembed_dataparse', $return, $data, $url );
[743] Fix | Delete
}
[744] Fix | Delete
[745] Fix | Delete
/**
[746] Fix | Delete
* Strips any new lines from the HTML.
[747] Fix | Delete
*
[748] Fix | Delete
* @since 2.9.0 as strip_scribd_newlines()
[749] Fix | Delete
* @since 3.0.0
[750] Fix | Delete
*
[751] Fix | Delete
* @param string $html Existing HTML.
[752] Fix | Delete
* @param object $data Data object from WP_oEmbed::data2html()
[753] Fix | Delete
* @param string $url The original URL passed to oEmbed.
[754] Fix | Delete
* @return string Possibly modified $html
[755] Fix | Delete
*/
[756] Fix | Delete
public function _strip_newlines( $html, $data, $url ) {
[757] Fix | Delete
if ( ! str_contains( $html, "\n" ) ) {
[758] Fix | Delete
return $html;
[759] Fix | Delete
}
[760] Fix | Delete
[761] Fix | Delete
$count = 1;
[762] Fix | Delete
$found = array();
[763] Fix | Delete
$token = '__PRE__';
[764] Fix | Delete
$search = array( "\t", "\n", "\r", ' ' );
[765] Fix | Delete
$replace = array( '__TAB__', '__NL__', '__CR__', '__SPACE__' );
[766] Fix | Delete
$tokenized = str_replace( $search, $replace, $html );
[767] Fix | Delete
[768] Fix | Delete
preg_match_all( '#(<pre[^>]*>.+?</pre>)#i', $tokenized, $matches, PREG_SET_ORDER );
[769] Fix | Delete
foreach ( $matches as $i => $match ) {
[770] Fix | Delete
$tag_html = str_replace( $replace, $search, $match[0] );
[771] Fix | Delete
$tag_token = $token . $i;
[772] Fix | Delete
[773] Fix | Delete
$found[ $tag_token ] = $tag_html;
[774] Fix | Delete
$html = str_replace( $tag_html, $tag_token, $html, $count );
[775] Fix | Delete
}
[776] Fix | Delete
[777] Fix | Delete
$replaced = str_replace( $replace, $search, $html );
[778] Fix | Delete
$stripped = str_replace( array( "\r\n", "\n" ), '', $replaced );
[779] Fix | Delete
$pre = array_values( $found );
[780] Fix | Delete
$tokens = array_keys( $found );
[781] Fix | Delete
[782] Fix | Delete
return str_replace( $tokens, $pre, $stripped );
[783] Fix | Delete
}
[784] Fix | Delete
}
[785] Fix | Delete
[786] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function