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
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/accelera.../classes
File: class-ampforwp-youtube-embed.php
<?php
[0] Fix | Delete
[1] Fix | Delete
// Exit if accessed directly
[2] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[3] Fix | Delete
exit;
[4] Fix | Delete
}
[5] Fix | Delete
use AMPforWP\AMPVendor\AMP_Base_Embed_Handler;
[6] Fix | Delete
use AMPforWP\AMPVendor\AMP_HTML_Utils;
[7] Fix | Delete
$file_path = AMP__VENDOR__DIR__ . '/includes/embeds/class-amp-base-embed-handler.php';
[8] Fix | Delete
if( file_exists($file_path) ){
[9] Fix | Delete
require_once $file_path;
[10] Fix | Delete
}
[11] Fix | Delete
[12] Fix | Delete
// Much of this class is borrowed from Jetpack embeds
[13] Fix | Delete
class AMPforWP_YouTube_Embed_Handler extends AMP_Base_Embed_Handler {
[14] Fix | Delete
const SHORT_URL_HOST = 'youtu.be';
[15] Fix | Delete
// Only handling single videos. Playlists are handled elsewhere.
[16] Fix | Delete
const URL_PATTERN = '#https?://(?:www\.)?(?:youtube.com/(?:v/|e/|embed/|watch[/\#?])|youtu\.be/).*#i';
[17] Fix | Delete
const RATIO = 0.5625;
[18] Fix | Delete
[19] Fix | Delete
protected $DEFAULT_WIDTH = 600;
[20] Fix | Delete
protected $DEFAULT_HEIGHT = 338;
[21] Fix | Delete
[22] Fix | Delete
private static $script_slug = 'amp-youtube';
[23] Fix | Delete
private static $script_src = 'https://cdn.ampproject.org/v0/amp-youtube-0.1.js';
[24] Fix | Delete
[25] Fix | Delete
function __construct( $args = array() ) {
[26] Fix | Delete
parent::__construct( $args );
[27] Fix | Delete
[28] Fix | Delete
if ( isset( $this->args['content_max_width'] ) ) {
[29] Fix | Delete
$max_width = $this->args['content_max_width'];
[30] Fix | Delete
$this->args['width'] = $max_width;
[31] Fix | Delete
$this->args['height'] = round( $max_width * self::RATIO );
[32] Fix | Delete
}
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
function register_embed() {
[36] Fix | Delete
wp_embed_register_handler( 'amp-youtube', self::URL_PATTERN, array( $this, 'oembed' ), -1 );
[37] Fix | Delete
add_shortcode( 'youtube', array( $this, 'shortcode' ) );
[38] Fix | Delete
add_filter( 'wp_video_shortcode_override', array( $this, 'video_override') , 10, 2 );
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
public function unregister_embed() {
[42] Fix | Delete
wp_embed_unregister_handler( 'amp-youtube', -1 );
[43] Fix | Delete
remove_shortcode( 'youtube' );
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
public function get_scripts() {
[47] Fix | Delete
if ( ! $this->did_convert_elements ) {
[48] Fix | Delete
return array();
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
return array( self::$script_slug => self::$script_src );
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
public function shortcode( $attr ) {
[55] Fix | Delete
$url = false;
[56] Fix | Delete
$video_id = false;
[57] Fix | Delete
if ( isset( $attr[0] ) ) {
[58] Fix | Delete
$url = ltrim( $attr[0] , '=' );
[59] Fix | Delete
} elseif ( function_exists ( 'ampforwp_youtube_shortcode' ) ) {
[60] Fix | Delete
$url = ampforwp_youtube_shortcode( $attr );
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
if ( empty( $url ) ) {
[64] Fix | Delete
return '';
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
$video_id = $this->get_video_id_from_url( $url );
[68] Fix | Delete
[69] Fix | Delete
return $this->render( array(
[70] Fix | Delete
'url' => $url,
[71] Fix | Delete
'video_id' => $video_id,
[72] Fix | Delete
) );
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
[76] Fix | Delete
public function oembed( $matches, $attr, $url, $rawattr ) {
[77] Fix | Delete
return $this->shortcode( array( $url ) );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
public function render( $args ) {
[81] Fix | Delete
$args = wp_parse_args( $args, array(
[82] Fix | Delete
'video_id' => false,
[83] Fix | Delete
) );
[84] Fix | Delete
[85] Fix | Delete
if ( empty( $args['video_id'] ) ) {
[86] Fix | Delete
return AMP_HTML_Utils::build_tag( 'a', array( 'href' => esc_url( $args['url'] ), 'class' => 'amp-wp-embed-fallback' ), esc_html( $args['url'] ) );
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
$this->did_convert_elements = true;
[90] Fix | Delete
// Return it with a filter for the modification purpose #1378
[91] Fix | Delete
$attrs = array(
[92] Fix | Delete
'data-videoid' => $args['video_id'],
[93] Fix | Delete
'layout' => 'responsive',
[94] Fix | Delete
'width' => $this->args['width'],
[95] Fix | Delete
'height' => $this->args['height'],
[96] Fix | Delete
);
[97] Fix | Delete
if(ampforwp_get_setting('ampforwp-amp-video-docking')==true){
[98] Fix | Delete
$attrs['dock'] = '#dock-slot';
[99] Fix | Delete
}
[100] Fix | Delete
if(ampforwp_get_setting('ampforwp-amp-video-lightbox')==true){
[101] Fix | Delete
$attrs['autoplay'] = true;
[102] Fix | Delete
}
[103] Fix | Delete
$attrs = ampforwp_amp_consent_check( $attrs );
[104] Fix | Delete
return AMP_HTML_Utils::build_tag('amp-youtube',apply_filters('amp_youtube_params', $attrs) );
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
private function get_video_id_from_url( $url ) {
[108] Fix | Delete
$video_id = false;
[109] Fix | Delete
$parsed_url = parse_url( $url );
[110] Fix | Delete
if(!isset($parsed_url['host'])){
[111] Fix | Delete
$parsed_url['host'] = '';
[112] Fix | Delete
}
[113] Fix | Delete
if ( self::SHORT_URL_HOST === substr( $parsed_url['host'], -strlen( self::SHORT_URL_HOST ) ) ) {
[114] Fix | Delete
// youtu.be/{id}
[115] Fix | Delete
$parts = explode( '/', $parsed_url['path'] );
[116] Fix | Delete
if ( ! empty( $parts ) ) {
[117] Fix | Delete
$video_id = $parts[1];
[118] Fix | Delete
}
[119] Fix | Delete
} else {
[120] Fix | Delete
// ?v={id} or ?list={id}
[121] Fix | Delete
if(isset($parsed_url['query'])){
[122] Fix | Delete
parse_str( $parsed_url['query'], $query_args );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
if ( isset( $query_args['v'] ) ) {
[126] Fix | Delete
$video_id = $this->sanitize_v_arg( $query_args['v'] );
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
if ( empty( $video_id ) ) {
[131] Fix | Delete
// /(v|e|embed)/{id}
[132] Fix | Delete
$parts = explode( '/', $parsed_url['path'] );
[133] Fix | Delete
[134] Fix | Delete
if ( in_array( $parts[1], array( 'v', 'e', 'embed' ) ) ) {
[135] Fix | Delete
$video_id = $parts[2];
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
return $video_id;
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
private function sanitize_v_arg( $value ) {
[143] Fix | Delete
// Deal with broken params like `?v=123?rel=0`
[144] Fix | Delete
if ( false !== strpos( $value, '?' ) ) {
[145] Fix | Delete
$value = strtok( $value, '?' );
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
return $value;
[149] Fix | Delete
}
[150] Fix | Delete
/**
[151] Fix | Delete
* Override the output of YouTube videos.
[152] Fix | Delete
*
[153] Fix | Delete
* This overrides the value in wp_video_shortcode().
[154] Fix | Delete
* The pattern matching is copied from WP_Widget_Media_Video::render().
[155] Fix | Delete
*
[156] Fix | Delete
* @param string $html Empty variable to be replaced with shortcode markup.
[157] Fix | Delete
* @param array $attr The shortcode attributes.
[158] Fix | Delete
* @return string|null $markup The markup to output.
[159] Fix | Delete
*/
[160] Fix | Delete
public function video_override( $html, $attr ) {
[161] Fix | Delete
if ( ! isset( $attr['src'] ) ) {
[162] Fix | Delete
return $html;
[163] Fix | Delete
}
[164] Fix | Delete
$src = $attr['src'];
[165] Fix | Delete
$youtube_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#';
[166] Fix | Delete
if ( 1 === preg_match( $youtube_pattern, $src ) ) {
[167] Fix | Delete
return $this->shortcode( [ $src ] );
[168] Fix | Delete
}
[169] Fix | Delete
return $html;
[170] Fix | Delete
}
[171] Fix | Delete
}
[172] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function