WP YouTube Lyte

Created Diff never expires
3 removals
501 lines
4 additions
502 lines
<?php
<?php
/*
/*
Plugin Name: WP YouTube Lyte
Plugin Name: WP YouTube Lyte
Plugin URI: http://blog.futtta.be/wp-youtube-lyte/
Plugin URI: http://blog.futtta.be/wp-youtube-lyte/
Description: Lite and accessible YouTube audio and video embedding.
Description: Lite and accessible YouTube audio and video embedding.
Author: Frank Goossens (futtta)
Author: Frank Goossens (futtta)
Version: 1.7.19
Version: 1.7.19
Author URI: http://blog.futtta.be/
Author URI: http://blog.futtta.be/
Text Domain: wp-youtube-lyte
Text Domain: wp-youtube-lyte
*/
*/


// fixme: add logic to remove settings/ cache/ ... when removing plugin
// fixme: add logic to remove settings/ cache/ ... when removing plugin


if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! defined( 'ABSPATH' ) ) exit;


$debug = false;
$debug = false;
$lyte_version = '1.7.19';
$lyte_version = '1.7.19';
$lyte_db_version = get_option( 'lyte_version', 'none' );
$lyte_db_version = get_option( 'lyte_version', 'none' );


/** have we updated? */
/** have we updated? */
if ($lyte_db_version !== $lyte_version) {
if ($lyte_db_version !== $lyte_version) {
switch( $lyte_db_version ) {
switch( $lyte_db_version ) {
case '1.5.0':
case '1.5.0':
lyte_rm_cache();
lyte_rm_cache();
break;
break;
case '1.4.2':
case '1.4.2':
case '1.4.1':
case '1.4.1':
case '1.4.0':
case '1.4.0':
lyte_rm_cache();
lyte_rm_cache();
lyte_not_greedy();
lyte_not_greedy();
break;
break;
case '1.7.0':
case '1.7.0':
case '1.7.1':
case '1.7.1':
case '1.7.2':
case '1.7.2':
case '1.7.3':
case '1.7.3':
case '1.7.4':
case '1.7.4':
case '1.7.5':
case '1.7.5':
case '1.7.6':
case '1.7.6':
case '1.7.7':
case '1.7.7':
case '1.7.8':
case '1.7.8':
case '1.7.9':
case '1.7.9':
case '1.7.10':
case '1.7.10':
case '1.7.11':
case '1.7.11':
lyte_mv_cache();
lyte_mv_cache();
break;
break;
}
}
update_option( 'lyte_version', $lyte_version );
update_option( 'lyte_version', $lyte_version );
$lyte_db_version = $lyte_version;
$lyte_db_version = $lyte_version;
}
}


/** are we in debug-mode */
/** are we in debug-mode */


if (!$debug) {
if (!$debug) {
$wyl_version = $lyte_version;
$wyl_version = $lyte_version;
$wyl_file = 'lyte-min.js';
$wyl_file = 'lyte-min.js';
$wyl_file_lazyload = 'bg-image-layzload.min.js';
$wyl_file_lazyload = 'bg-image-layzload.min.js';
} else {
} else {
$wyl_version = rand()/1000;
$wyl_version = rand()/1000;
$wyl_file = 'lyte.js';
$wyl_file = 'lyte.js';
$wyl_file_lazyload = 'bg-image-layzload.js';
$wyl_file_lazyload = 'bg-image-layzload.js';
lyte_rm_cache();
lyte_rm_cache();
}
}


/** get paths, language and includes */
/** get paths, language and includes */
$plugin_dir = basename( dirname( __FILE__ ) ) . '/languages';
$plugin_dir = basename( dirname( __FILE__ ) ) . '/languages';
load_plugin_textdomain( 'wp-youtube-lyte', null, $plugin_dir );
load_plugin_textdomain( 'wp-youtube-lyte', null, $plugin_dir );
require_once( dirname( __FILE__ ) . '/player_sizes.inc.php' );
require_once( dirname( __FILE__ ) . '/player_sizes.inc.php' );
require_once( dirname( __FILE__ ) . '/widget.php' );
require_once( dirname( __FILE__ ) . '/widget.php' );


/** get default embed size and build array to change size later if requested */
/** get default embed size and build array to change size later if requested */
$oSize = (int) get_option( 'lyte_size' );
$oSize = (int) get_option( 'lyte_size' );
if ( (is_bool( $oSize ) ) || ( $pSize[$oSize]['a'] === false ) ) {
if ( (is_bool( $oSize ) ) || ( $pSize[$oSize]['a'] === false ) ) {
$sel = (int) $pDefault;
$sel = (int) $pDefault;
} else {
} else {
$sel=$oSize;
$sel=$oSize;
}
}


$pSizeFormat = $pSize[$sel]['f'];
$pSizeFormat = $pSize[$sel]['f'];
$j = 0;
$j = 0;


foreach ( $pSizeOrder[$pSizeFormat] as $sizeId ) {
foreach ( $pSizeOrder[$pSizeFormat] as $sizeId ) {
$sArray[$j]['w'] = (int) $pSize[$sizeId]['w'];
$sArray[$j]['w'] = (int) $pSize[$sizeId]['w'];
$sArray[$j]['h'] = (int) $pSize[$sizeId]['h'];
$sArray[$j]['h'] = (int) $pSize[$sizeId]['h'];
if ( $sizeId === $sel ) {
if ( $sizeId === $sel ) {
$selSize=$j;
$selSize=$j;
}
}
$j++;
$j++;
}
}


/** get other options and push in array*/
/** get other options and push in array*/
$lyteSettings['sizeArray'] = $sArray;
$lyteSettings['sizeArray'] = $sArray;
$lyteSettings['selSize'] = $selSize;
$lyteSettings['selSize'] = $selSize;
$lyteSettings['links'] = get_option( 'lyte_show_links' );
$lyteSettings['links'] = get_option( 'lyte_show_links' );
$lyteSettings['file'] = $wyl_file . '?wyl_version=' . $wyl_version;
$lyteSettings['file'] = $wyl_file . '?wyl_version=' . $wyl_version;
$lyteSettings['file_lazyload'] = $wyl_file_lazyload . '?wyl_version=' . $wyl_version;
$lyteSettings['file_lazyload'] = $wyl_file_lazyload . '?wyl_version=' . $wyl_version;
$lyteSettings['ratioClass'] = ( $pSizeFormat === '43' ) ? ' fourthree' : '';
$lyteSettings['ratioClass'] = ( $pSizeFormat === '43' ) ? ' fourthree' : '';
$lyteSettings['pos'] = ( get_option( 'lyte_position', '0' ) === '1' ) ? 'margin:5px auto;' : 'margin:5px;';
$lyteSettings['pos'] = ( get_option( 'lyte_position', '0' ) === '1' ) ? 'margin:5px auto;' : 'margin:5px;';
$lyteSettings['microdata'] = get_option( 'lyte_microdata', '1' );
$lyteSettings['microdata'] = get_option( 'lyte_microdata', '1' );
$lyteSettings['hidef'] = get_option( 'lyte_hidef', 0 );
$lyteSettings['hidef'] = get_option( 'lyte_hidef', 0 );
$lyteSettings['scheme'] = ( is_ssl() ) ? 'https' : 'http';
$lyteSettings['scheme'] = ( is_ssl() ) ? 'https' : 'http';


/** API: filter hook to alter $lyteSettings */
/** API: filter hook to alter $lyteSettings */
function lyte_settings_enforcer() {
function lyte_settings_enforcer() {
global $lyteSettings;
global $lyteSettings;
$lyteSettings['lyte_use_internal_lazyloader'] = apply_filters( 'lyte_use_internal_lazyloader', false );
$lyteSettings['lyte_use_internal_lazyloader'] = apply_filters( 'lyte_use_internal_lazyloader', false );
$lyteSettings = apply_filters( 'lyte_settings', $lyteSettings );
$lyteSettings = apply_filters( 'lyte_settings', $lyteSettings );
}
}
add_action( 'after_setup_theme', 'lyte_settings_enforcer' );
add_action( 'after_setup_theme', 'lyte_settings_enforcer' );


function lyte_parse( $the_content, $doExcerpt = false ) {
function lyte_parse( $the_content, $doExcerpt = false ) {
/** bail if AMP or if LYTE feed disabled and is_feed */
/** bail if AMP or if LYTE feed disabled and is_feed */
if ( is_amp() || ( apply_filters( 'lyte_filter_dofeed', true ) === false && is_feed() ) ) {
if ( is_amp() || ( apply_filters( 'lyte_filter_dofeed', true ) === false && is_feed() ) ) {
return str_replace( 'httpv://', 'https://', $the_content );
return str_replace( 'httpv://', 'https://', $the_content );
}
}


/** main function to parse the content, searching and replacing httpv-links */
/** main function to parse the content, searching and replacing httpv-links */
global $lyteSettings, $toCache_index, $postID, $cachekey;
global $lyteSettings, $toCache_index, $postID, $cachekey;
$lyteSettings['path'] = plugins_url() . '/' . dirname( plugin_basename( __FILE__ ) ) . '/lyte/';
$lyteSettings['path'] = plugins_url() . '/' . dirname( plugin_basename( __FILE__ ) ) . '/lyte/';
$urlArr = parse_url( $lyteSettings['path'] );
$urlArr = parse_url( $lyteSettings['path'] );
$origin = $urlArr['scheme'] . '://' . $urlArr['host'];
$origin = $urlArr['scheme'] . '://' . $urlArr['host'];


/** API: filter hook to preparse the_content, e.g. to force normal youtube links to be parsed */
/** API: filter hook to preparse the_content, e.g. to force normal youtube links to be parsed */
$the_content = apply_filters( 'lyte_content_preparse', $the_content );
$the_content = apply_filters( 'lyte_content_preparse', $the_content );


if ( get_option( 'lyte_greedy', '1' ) === '1' && strpos( $the_content, 'youtu' ) !== false ){
if ( get_option( 'lyte_greedy', '1' ) === '1' && strpos( $the_content, 'youtu' ) !== false ){
// new: also replace original YT embed code (iframes)
// new: also replace original YT embed code (iframes)
if ( apply_filters( 'lyte_eats_yframes', true ) && preg_match_all( '#<iframe(?:[^<]*)?\ssrc=["|\'](?:http(?:s)?:)?\/\/www\.youtube(?:-nocookie)?\.com\/embed\/(.*)["|\'](?:.*)><\/iframe>#Usm', $the_content, $matches, PREG_SET_ORDER ) ) {
if ( apply_filters( 'lyte_eats_yframes', true ) && preg_match_all( '#<iframe(?:[^<]*)?\ssrc=["|\'](?:http(?:s)?:)?\/\/www\.youtube(?:-nocookie)?\.com\/embed\/(.*)["|\'](?:.*)><\/iframe>#Usm', $the_content, $matches, PREG_SET_ORDER ) ) {
foreach ( $matches as $match ) {
foreach ( $matches as $match ) {
if ( strpos( $match[1], 'videoseries' ) === false) {
if ( strpos( $match[1], 'videoseries' ) === false) {
$the_content = str_replace( $match[0], 'httpv://youtu.be/'.$match[1], $the_content );
$the_content = str_replace( $match[0], 'httpv://youtu.be/'.$match[1], $the_content );
} else {
} else {
$the_content = str_replace( $match[0], 'httpv://youtube.com/playlist?list=' . str_replace( 'videoseries?list=', '', $match[1] ), $the_content );
$the_content = str_replace( $match[0], 'httpv://youtube.com/playlist?list=' . str_replace( 'videoseries?list=', '', $match[1] ), $the_content );
}
}
}
}
}
}
}
}


if ( ( strpos( $the_content, 'httpv' ) !== false ) || ( strpos( $the_content, 'httpa' ) !== false ) ) {
if ( ( strpos( $the_content, 'httpv' ) !== false ) || ( strpos( $the_content, 'httpa' ) !== false ) ) {
if ( apply_filters( 'lyte_remove_wpautop', false ) ) {
if ( apply_filters( 'lyte_remove_wpautop', false ) ) {
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_content', 'wpautop' );
}
}


if ( apply_filters( 'lyte_kinda_textureize', true ) ) {
if ( apply_filters( 'lyte_kinda_textureize', true ) ) {
$char_codes = array( '&#215;', '&#8211;', '\u002d' );
$char_codes = array( '&#215;', '&#8211;', '\u002d' );
$replacements = array( 'x', '--', '-');
$replacements = array( 'x', '--', '-');
$the_content = str_replace( $char_codes, $replacements, $the_content );
$the_content = str_replace( $char_codes, $replacements, $the_content );
}
}


$lyte_feed = is_feed();
$lyte_feed = is_feed();
$hidefClass = ( $lyteSettings['hidef'] === '1') ? ' hidef' : '';
$hidefClass = ( $lyteSettings['hidef'] === '1') ? ' hidef' : '';
$postID = get_the_ID();
$postID = get_the_ID();
$toCache_index = array();
$toCache_index = array();
$lytes_regexp = '/(?:<p>)?http(v|a):\/\/([a-zA-Z0-9\-\_]+\.|)(youtube|youtu)(\.com|\.be)\/(((watch(\?v\=|\/v\/)|.+?v\=|)([a-zA-Z0-9\-\_]{11}))|(playlist\?list\=([a-zA-Z0-9\-\_]*)))([^\s<]*)(<?:\/p>)?/';
$lytes_regexp = '/(?:<p>)?http(v|a):\/\/([a-zA-Z0-9\-\_]+\.|)(youtube|youtu)(\.com|\.be)\/(((watch(\?v\=|\/v\/)|.+?v\=|)([a-zA-Z0-9\-\_]{11}))|(playlist\?list\=([a-zA-Z0-9\-\_]*)))([^\s<]*)(<?:\/p>)?/';


preg_match_all( $lytes_regexp, $the_content, $matches, PREG_SET_ORDER );
preg_match_all( $lytes_regexp, $the_content, $matches, PREG_SET_ORDER );


foreach( $matches as $match ) {
foreach( $matches as $match ) {
/** API: filter hook to preparse fragment in a httpv-url, e.g. to force hqThumb=1 or showinfo=0 */
/** API: filter hook to preparse fragment in a httpv-url, e.g. to force hqThumb=1 or showinfo=0 */
$match[12] = apply_filters( 'lyte_match_preparse_fragment', $match[12] );
$match[12] = apply_filters( 'lyte_match_preparse_fragment', $match[12] );


preg_match( '/stepSize\=([\+\-0-9]{2})/', $match[12], $sMatch );
preg_match( '/stepSize\=([\+\-0-9]{2})/', $match[12], $sMatch );
preg_match( '/showinfo\=([0-1]{1})/', $match[12], $showinfo );
preg_match( '/showinfo\=([0-1]{1})/', $match[12], $showinfo );
preg_match( '/start\=([0-9]*)/', $match[12], $start );
preg_match( '/start\=([0-9]*)/', $match[12], $start );
preg_match( '/enablejsapi\=([0-1]{1})/', $match[12], $jsapi );
preg_match( '/enablejsapi\=([0-1]{1})/', $match[12], $jsapi );
preg_match( '/hqThumb\=([0-1]{1})/', $match[12], $hqThumb );
preg_match( '/hqThumb\=([0-1]{1})/', $match[12], $hqThumb );
preg_match( '/noMicroData\=([0-1]{1})/', $match[12], $microData );
preg_match( '/noMicroData\=([0-1]{1})/', $match[12], $microData );


$thumb = 'normal';
$thumb = 'normal';
if ( $lyteSettings['hidef'] === '1' ) {
if ( $lyteSettings['hidef'] === '1' ) {
$thumb = 'highres';
$thumb = 'highres';
} else if ( ! empty( $hqThumb ) ) {
} else if ( ! empty( $hqThumb ) ) {
if ( $hqThumb[0] === 'hqThumb=1' ) {
if ( $hqThumb[0] === 'hqThumb=1' ) {
$thumb = 'highres';
$thumb = 'highres';
}
}
}
}


$noMicroData = '0';
$noMicroData = '0';
if ( ! empty( $microData ) ) {
if ( ! empty( $microData ) ) {
if ( $microData[0] === 'noMicroData=1' ) {
if ( $microData[0] === 'noMicroData=1' ) {
$noMicroData = '1';
$noMicroData = '1';
}
}
}
}


$qsa='';
$qsa='';
if ( ! empty( $showinfo[0] ) ) {
if ( ! empty( $showinfo[0] ) ) {
$qsa = '&amp;' . $showinfo[0];
$qsa = '&amp;' . $showinfo[0];
$titleClass = ' hidden';
$titleClass = ' hidden';
} else {
} else {
$titleClass = '';
$titleClass = '';
}
}
if ( ! empty( $start[0] ) ) {
if ( ! empty( $start[0] ) ) {
$qsa = $qsa . '&amp;' . $start[0];
$qsa = $qsa . '&amp;' . $start[0];
}
}
if ( ! empty( $jsapi[0] ) ) {
if ( ! empty( $jsapi[0] ) ) {
$qsa = $qsa . '&amp;' . $jsapi[0] . '&amp;origin=' . $origin;
$qsa = $qsa . '&amp;' . $jsapi[0] . '&amp;origin=' . $origin;
}
}
if ( ! empty( $qsa ) ) {
if ( ! empty( $qsa ) ) {
$esc_arr = array( '&' => '\&', '?' => '\?', '=' => '\=');
$esc_arr = array( '&' => '\&', '?' => '\?', '=' => '\=');
$qsaClass = ' qsa_' . strtr( $qsa, $esc_arr ) ;
$qsaClass = ' qsa_' . strtr( $qsa, $esc_arr ) ;
} else {
} else {
$qsaClass = '';
$qsaClass = '';
}
}


if ( ! empty( $sMatch ) ) {
if ( ! empty( $sMatch ) ) {
$newSize = (int) $sMatch[1];
$newSize = (int) $sMatch[1];
$newPos = (int) $lyteSettings['selSize'] + $newSize;
$newPos = (int) $lyteSettings['selSize'] + $newSize;
if ( $newPos < 0 ) {
if ( $newPos < 0 ) {
$newPos = 0;
$newPos = 0;
} else if ( $newPos > count( $lyteSettings['sizeArray'] ) - 1 ) {
} else if ( $newPos > count( $lyteSettings['sizeArray'] ) - 1 ) {
$newPos = count($lyteSettings['sizeArray']) - 1;
$newPos = count($lyteSettings['sizeArray']) - 1;
}
}
$lyteSettings[2] = $lyteSettings['sizeArray'][$newPos]['w'];
$lyteSettings[2] = $lyteSettings['sizeArray'][$newPos]['w'];
$lyteSettings[3] = $lyteSettings['sizeArray'][$newPos]['h'];
$lyteSettings[3] = $lyteSettings['sizeArray'][$newPos]['h'];
} else {
} else {
$lyteSettings[2] = $lyteSettings['sizeArray'][$lyteSettings['selSize']]['w'];
$lyteSettings[2] = $lyteSettings['sizeArray'][$lyteSettings['selSize']]['w'];
$lyteSettings[3] = $lyteSettings['sizeArray'][$lyteSettings['selSize']]['h'];
$lyteSettings[3] = $lyteSettings['sizeArray'][$lyteSettings['selSize']]['h'];
}
}


if ( $match[1] !== 'a' ) {
if ( $match[1] !== 'a' ) {
$divHeight = $lyteSettings[3];
$divHeight = $lyteSettings[3];
$audioClass = '';
$audioClass = '';
$audio = false;
$audio = false;
} else {
} else {
$audio = true;
$audio = true;
$audioClass = ' lyte-audio';
$audioClass = ' lyte-audio';
$divHeight = 38;
$divHeight = 38;
}
}


$NSimgHeight = $divHeight - 20;
$NSimgHeight = $divHeight - 20;


if ( $match[11] != '' ) {
if ( $match[11] != '' ) {
$plClass = ' playlist';
$plClass = ' playlist';
$vid = $match[11];
$vid = $match[11];
switch ( $lyteSettings['links'] ) {
switch ( $lyteSettings['links'] ) {
case '0':
case '0':
$noscript_post = '<br />' . __( 'Watch this playlist on YouTube', 'wp-youtube-lyte' );
$noscript_post = '<br />' . __( 'Watch this playlist on YouTube', 'wp-youtube-lyte' );
$noscript = '<noscript><a href="' . $lyteSettings['scheme'] . '://youtube.com/playlist?list=' . $vid . '" rel="nofollow">' . $noscript_post . '</a></noscript>';
$noscript = '<noscript><a href="' . $lyteSettings['scheme'] . '://youtube.com/playlist?list=' . $vid . '">' . $noscript_post . '</a></noscript>';
$lytelinks_txt = '';
$lytelinks_txt = '';
break;
break;
default:
default:
$noscript = '';
$noscript = '';
$lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] . '">' . __( 'Watch this playlist', 'wp-youtube-lyte') . ' <a href="' . $lyteSettings['scheme'] . '://www.youtube.com/playlist?list=' . $vid . '">' . __( 'on YouTube', 'wp-youtube-lyte') . '</a></div>';
$lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] . '">' . __( 'Watch this playlist', 'wp-youtube-lyte') . ' <a href="' . $lyteSettings['scheme'] . '://www.youtube.com/playlist?list=' . $vid . '">' . __( 'on YouTube', 'wp-youtube-lyte') . '</a></div>';
}
}
} else if ($match[9]!="") {
} else if ($match[9]!="") {
$plClass="";
$plClass="";
$vid=$match[9];
$vid=$match[9];
switch ($lyteSettings['links']) {
switch ($lyteSettings['links']) {
case "0":
case "0":
$noscript_post = '<br />' . __( 'Watch this video on YouTube', 'wp-youtube-lyte' );
$noscript_post = '<br />' . __( 'Watch this video on YouTube', 'wp-youtube-lyte' );
$lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] .'"></div>';
$lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] .'"></div>';
break;
break;
default:
default:
$noscript_post = '';
$noscript_post = '';
$lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] . '">' . __( 'Watch this video', 'wp-youtube-lyte' ) . ' <a href="' . $lyteSettings['scheme'] . '://youtu.be/' . $vid . '">' . __( 'on YouTube', 'wp-youtube-lyte' ) . '</a>.</div>';
$lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] . '">' . __( 'Watch this video', 'wp-youtube-lyte' ) . ' <a href="' . $lyteSettings['scheme'] . '://youtu.be/' . $vid . '">' . __( 'on YouTube', 'wp-youtube-lyte' ) . '</a>.</div>';
}
}
$thumbUrl = $lyteSettings['scheme'] . '://i.ytimg.com/vi/' . $vid . '/0.jpg';
$thumbUrl = $lyteSettings['scheme'] . '://i.ytimg.com/vi/' . $vid . '/0.jpg';
if ( get_option( 'lyte_local_thumb', '0' ) === '1' ) {
if ( get_option( 'lyte_local_thumb', '0' ) === '1' ) {
$thumbUrl = plugins_url( 'lyteCache.php?origThumbUrl=' . urlencode($thumbUrl) , __FILE__ );
$thumbUrl = plugins_url( 'lyteCache.php?origThumbUrl=' . urlencode($thumbUrl) , __FILE__ );
}
}
$thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl, $vid );
$thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl, $vid );
$noscript = '<noscript><a href="' . $lyteSettings['scheme'] . '://youtu.be/' . $vid . '" rel="nofollow"><img src="' . $thumbUrl . '" alt="" width="' . $lyteSettings[2] . '" height="' . $NSimgHeight . '" />' . $noscript_post . '</a></noscript>';
$noscript = '<noscript><a href="' . $lyteSettings['scheme'] . '://youtu.be/' . $vid . '"><img src="' . $thumbUrl . '" alt="" width="' . $lyteSettings[2] . '" height="' . $NSimgHeight . '" />' . $noscript_post . '</a></noscript>';
}
}


// add disclaimer to lytelinks
// add disclaimer to lytelinks
$disclaimer = wp_kses_data( get_option( 'lyte_disclaimer', '') );
$disclaimer = wp_kses_data( get_option( 'lyte_disclaimer', '') );
$disclaimer = apply_filters('lyte_disclaimer', $disclaimer);
$disclaimer = apply_filters('lyte_disclaimer', $disclaimer);
if ( !empty( $disclaimer ) ) {
if ( !empty( $disclaimer ) ) {
$disclaimer = '<span class="lyte_disclaimer">' . $disclaimer . '</span>';
$disclaimer = '<span class="lyte_disclaimer">' . $disclaimer . '</span>';
}
}


if ( $disclaimer && empty( $lytelinks_txt ) ) {
if ( $disclaimer && empty( $lytelinks_txt ) ) {
$lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] . '">' . $disclaimer . '</div>';
$lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] . '">' . $disclaimer . '</div>';
} else if ( $disclaimer ) {
} else if ( $disclaimer ) {
$lytelinks_txt = str_replace( '</div>', '<br/>' . $disclaimer . '</div>', $lytelinks_txt );
$lytelinks_txt = str_replace( '</div>', '<br/>' . $disclaimer . '</div>', $lytelinks_txt );
}
}


// fetch data from YT api (v2 or v3)
// fetch data from YT api (v2 or v3)
$isPlaylist = false;
$isPlaylist = false;
if ( $plClass ===' playlist' ) {
if ( $plClass ===' playlist' ) {
$isPlaylist = true;
$isPlaylist = true;
}
}
$cachekey = '_lyte_' . $vid;
$cachekey = '_lyte_' . $vid;
$yt_resp_array = lyte_get_YT_resp( $vid, $isPlaylist, $cachekey );
$yt_resp_array = lyte_get_YT_resp( $vid, $isPlaylist, $cachekey );


// If there was a result from youtube or from cache, use it
// If there was a result from youtube or from cache, use it
if ( $yt_resp_array && is_array( $yt_resp_array ) ) {
if ( $yt_resp_array && is_array( $yt_resp_array ) ) {
if ( $isPlaylist !== true ) {
if ( $isPlaylist !== true ) {
// captions
// captions
$captionsMeta = '';
$captionsMeta = '';
$doCaptions = true;
$doCaptions = true;


/** API: filter hook to disable captions */
/** API: filter hook to disable captions */
$doCaptions = apply_filters( 'lyte_docaptions', $doCaptions );
$doCaptions = apply_filters( 'lyte_docaptions', $doCaptions );


if ( ( $lyteSettings['microdata'] === "1" ) && ( $noMicroData !== "1" ) && ( $doCaptions === true ) ) {
if ( ( $lyteSettings['microdata'] === "1" ) && ( $noMicroData !== "1" ) && ( $doCaptions === true ) ) {
if ( array_key_exists( 'captions_data', $yt_resp_array ) && $yt_resp_array['captions_data'] == 'true') {
if ( array_key_exists( 'captions_data', $yt_resp_array ) && $yt_resp_array['captions_data'] == 'true') {
$captionsMeta = '<meta itemprop="accessibilityFeature" content="captions" />';
$captionsMeta = '<meta itemprop="accessibilityFeature" content="captions" />';
}
}
}
}
}
}


$thumbUrl = '';
$thumbUrl = '';
if ( ( $thumb === 'highres' ) && ( ! empty( $yt_resp_array['HQthumbUrl'] ) ) ){
if ( ( $thumb === 'highres' ) && ( ! empty( $yt_resp_array['HQthumbUrl'] ) ) ){
$thumbUrl = $yt_resp_array['HQthumbUrl'];
$thumbUrl = $yt_resp_array['HQthumbUrl'];
} else {
} else {
if ( ! empty( $yt_resp_array['thumbUrl'] ) ) {
if ( ! empty( $yt_resp_array['thumbUrl'] ) ) {
$thumbUrl = $yt_resp_array['thumbUrl'];
$thumbUrl = $yt_resp_array['thumbUrl'];
} else {
} else {
$thumbUrl = '//i.ytimg.com/vi/' . $vid . '/hqdefault.jpg';
$thumbUrl = '//i.ytimg.com/vi/' . $vid . '/hqdefault.jpg';
}
}
}
}
if ( strpos( $noscript, 'alt=""' ) !== false && array_key_exists( 'title', $yt_resp_array ) ) {
if ( strpos( $noscript, 'alt=""' ) !== false && array_key_exists( 'title', $yt_resp_array ) ) {
$noscript = str_replace( 'alt=""', 'alt="' . htmlentities( $yt_resp_array["title"] ). '"', $noscript );
$noscript = str_replace( 'alt=""', 'alt="' . htmlentities( $yt_resp_array["title"] ). '"', $noscript );
}
}
} else {
} else {
$thumbUrl = "//i.ytimg.com/vi/".$vid."/hqdefault.jpg";
$thumbUrl = "//i.ytimg.com/vi/".$vid."/hqdefault.jpg";
}
}


// do we have to serve the thumbnail from local cache?
// do we have to serve the thumbnail from local cache?
if ( get_option( 'lyte_local_thumb', '0' ) === '1' ) {
if ( get_option( 'lyte_local_thumb', '0' ) === '1' ) {
$thumbUrl = plugins_url( 'lyteCache.php?origThumbUrl=' . urlencode( $thumbUrl ) , __FILE__ );
$thumbUrl = plugins_url( 'lyteCache.php?origThumbUrl=' . urlencode( $thumbUrl ) , __FILE__ );
}
}


/** API: filter hook to override thumbnail URL */
/** API: filter hook to override thumbnail URL */
$thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl, $vid );
$thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl, $vid );


if ( isset( $yt_resp_array ) && ! empty( $yt_resp_array ) && ! empty( $yt_resp_array['title'] ) ) {
if ( isset( $yt_resp_array ) && ! empty( $yt_resp_array ) && ! empty( $yt_resp_array['title'] ) ) {
$_this_title = $yt_resp_array['title'];
$_this_title = $yt_resp_array['title'];
$_this_title_tag = ' title="' . htmlentities( $_this_title ) . '"';
$_this_title_tag = ' title="' . htmlentities( $_this_title ) . '"';
} else {
} else {
$_this_title = false;
$_this_title = false;
$_this_title_tag = '';
$_this_title_tag = '';
}
}


if ( $audio === true ) {
if ( $audio === true ) {
$wrapper = '<div class="lyte-wrapper-audio"' . $_this_title_tag . ' style="width:' . $lyteSettings[2] . 'px;max-width:100%;overflow:hidden;height:38px;' . $lyteSettings['pos'] . '">';
$wrapper = '<div class="lyte-wrapper-audio"' . $_this_title_tag . ' style="width:' . $lyteSettings[2] . 'px;max-width:100%;overflow:hidden;height:38px;' . $lyteSettings['pos'] . '">';
} else {
} else {
$wrapper = '<div class="lyte-wrapper' . $lyteSettings['ratioClass'] . '"' . $_this_title_tag . ' style="width:' . $lyteSettings[2] . 'px;max-width:100%;' . $lyteSettings['pos'] . '">';
$wrapper = '<div class="lyte-wrapper' . $lyteSettings['ratioClass'] . '"' . $_this_title_tag . ' style="width:' . $lyteSettings[2] . 'px;max-width:100%;' . $lyteSettings['pos'] . '">';
}
}


// do we have usable microdata fiels from the YT API, if not no microdata below.
// do we have usable microdata fiels from the YT API, if not no microdata below.
foreach ( array( 'title', 'description', 'dateField' ) as $resp_key ) {
foreach ( array( 'title', 'description', 'dateField' ) as $resp_key ) {
if ( empty( $yt_resp_array[$resp_key] ) ) {
if ( empty( $yt_resp_array[$resp_key] ) ) {
$noMicroData = '1';
$noMicroData = '1';
break;
break;
}
}
}
}


// do we have a YT API key, if not; no microdata below.
// do we have a YT API key, if not; no microdata below.
$lyte_yt_api_key = apply_filters( 'lyte_filter_yt_api_key', get_option( 'lyte_yt_api_key', '' ) );
$lyte_yt_api_key = apply_filters( 'lyte_filter_yt_api_key', get_option( 'lyte_yt_api_key', '' ) );
if ( $lyte_yt_api_key === "none" || empty( $lyte_yt_api_key ) ) {
if ( $lyte_yt_api_key === "none" || empty( $lyte_yt_api_key ) ) {
$noMicroData = '1';
$noMicroData = '1';
}
}


if ( $doExcerpt ) {
if ( $doExcerpt ) {
$lytetemplate = '';
$lytetemplate = '';
$templateType = 'excerpt';
$templateType = 'excerpt';
} elseif ( $lyte_feed ) {
} elseif ( $lyte_feed ) {
$postURL = get_permalink( $postID );
$postURL = get_permalink( $postID );
$textLink = ( $lyteSettings['links'] ===0 ) ? '' : '<br />' . strip_tags( $lytelinks_txt, '<a>' ) . '<br />';
$textLink = ( $lyteSettings['links'] ===0 ) ? '' : '<br />' . strip_tags( $lytelinks_txt, '<a>' ) . '<br />';
$lytetemplate = '<a href="' . $postURL . '"><img src="' . $thumbUrl . '" alt="YouTube Video"></a>' . $textLink;
$lytetemplate = '<a href="' . $postURL . '"><img src="' . $thumbUrl . '" alt="YouTube Video"></a>' . $textLink;
$templateType = 'feed';
$templateType = 'feed';
} elseif ( $audio !== true && $plClass !== " playlist" && $lyteSettings['microdata'] === "1" && $noMicroData !== "1" ) {
} elseif ( $audio !== true && $plClass !== " playlist" && $lyteSettings['microdata'] === "1" && $noMicroData !== "1" ) {
$lytetemplate = $wrapper . '<div class="lyMe' . $audioClass . $hidefClass . $plClass . $qsaClass . '" id="WYL_' . $vid . '" itemprop="video" itemscope itemtype="https://schema.org/VideoObject"><div><meta itemprop="thumbnailUrl" content="' . $thumbUrl . '" /><meta itemprop="embedURL" content="https://www.youtube.com/embed/' . $vid . '" /><meta itemprop="duration" content="' . $yt_resp_array['duration'] . '" /><meta itemprop="uploadDate" content="' . $yt_resp_array["dateField"] . '" /></div>' . $captionsMeta. '<div id="lyte_' . $vid . '" data-src="' . $thumbUrl . '" class="pL'.($lyteSettings['lyte_use_internal_lazyloader'] ? " wyl-lazy" : "").'"><div class="tC' . $titleClass . '"><div class="tT" itemprop="name">' . $yt_resp_array["title"] . '</div></div><div class="play"></div><div class="ctrl"><div class="Lctrl"></div><div class="Rctrl"></div></div></div>' . $noscript . '<meta itemprop="description" content="' . $yt_resp_array["description"] . '"></div></div>' . $lytelinks_txt;
$lytetemplate = $wrapper . '<div class="lyMe' . $audioClass . $hidefClass . $plClass . $qsaClass . '" id="WYL_' . $vid . '" itemprop="video" itemscope itemtype="https://schema.org/VideoObject"><div><meta itemprop="thumbnailUrl" content="' . $thumbUrl . '" /><meta itemprop="embedURL" content="https://www.youtube.com/embed/' . $vid . '" /><meta itemprop="duration" content="' . $yt_resp_array['duration'] . '" /><meta itemprop="uploadDate" content="' . $yt_resp_array["dateField"] . '" /></div>' . $captionsMeta. '<div id="lyte_' . $vid . '" data-src="' . $thumbUrl . '" class="pL'.($lyteSettings['lyte_use_internal_lazyloader'] ? " wyl-lazy" : "").'"><div class="tC' . $titleClass . '"><div class="tT" itemprop="name">' . $yt_resp_array["title"] . '</div></div><div class="play"></div><div class="ctrl"><div class="Lctrl"></div><div class="Rctrl"></div></div></div>' . $noscript . '<meta itemprop="description" content="' . $yt_resp_array["description"] . '"></div></div>' . $lytelinks_txt;
$templateType = 'postMicrodata';
$templateType = 'postMicrodata';
} else {
} else {
$lytetemplate = $wrapper . '<div class="lyMe' . $audioClass . $hidefClass . $plClass . $qsaClass . '" id="WYL_' . $vid . '"><div id="lyte_' . $vid . '" data-src="' . $thumbUrl . '" class="pL'.($lyteSettings['lyte_use_internal_lazyloader'] ? " wyl-lazy" : "").'">';
$lytetemplate = $wrapper . '<div class="lyMe' . $audioClass . $hidefClass . $plClass . $qsaClass . '" id="WYL_' . $vid . '"><div id="lyte_' . $vid . '" data-src="' . $thumbUrl . '" class="pL'.($lyteSettings['lyte_use_internal_lazyloader'] ? " wyl-lazy" : "").'">';
if ( isset( $_this_title ) ) {
if ( isset( $_this_title ) ) {
$lytetemplate .= '<div class="tC' . $titleClass . '"><div class="tT">' . $_this_title . '</div></div>';
$lytetemplate .= '<div class="tC' . $titleClass . '"><div class="tT">' . $_this_title . '</div></div>';
}
}


$lytetemplate .= '<div class="play"></div><div class="ctrl"><div class="Lctrl"></div><div class="Rctrl"></div></div></div>' . $noscript . '</div></div>' . $lytelinks_txt;
$lytetemplate .= '<div class="play"></div><div class="ctrl"><div class="Lctrl"></div><div class="Rctrl"></div></div></div>' . $noscript . '</div></div>' . $lytelinks_txt;
$templateType="post";
$templateType="post";
}
}


/** API: filter hook to parse template before being applied */
/** API: filter hook to parse template before being applied */
$lytetemplate = str_replace( '$', '&#36;', $lytetemplate );
$lytetemplate = str_replace( '$', '&#36;', $lytetemplate );


// make sure *something* is passed as $yt_resp_array to avoid notices in below filter.
// make sure *something* is passed as $yt_resp_array to avoid notices in below filter.
if ( ! isset( $yt_resp_array ) ) {
if ( ! isset( $yt_resp_array ) ) {
$yt_resp_array = '';
$yt_resp_array = '';
}
}
$lytetemplate = apply_filters( 'lyte_match_postparse_template', $lytetemplate, $templateType, $yt_resp_array );
$lytetemplate = apply_filters( 'lyte_match_postparse_template', $lytetemplate, $templateType, $yt_resp_array );
$the_content = preg_replace( $lytes_regexp, $lytetemplate, $the_content, 1 );
$the_content = preg_replace( $lytes_regexp, $lytetemplate, $the_content, 1 );
}
}


// update lyte_cache_index
// update lyte_cache_index
if ( ( is_array( $toCache_index ) ) && ( ! empty( $toCache_index ) ) ) {
if ( ( is_array( $toCache_index ) ) && ( ! empty( $toCache_index ) ) ) {
$lyte_cache = json_decode( get_option( 'lyte_cache_index' ), true );
$lyte_cache = json_decode( get_option( 'lyte_cache_index' ), true );
$lyte_cache[$postID] = $toCache_index;
$lyte_cache[$postID] = $toCache_index;
update_option( 'lyte_cache_index', json_encode( $lyte_cache ) );
update_option( 'lyte_cache_index', json_encode( $lyte_cache ) );
}
}


if ( ! $lyte_feed ) {
if ( ! $lyte_feed ) {
lyte_initer();
lyte_initer();
}
}
}
}


if ( apply_filters( 'lyte_kinda_textureize', true ) ) {
if ( apply_filters( 'lyte_kinda_textureize', true ) ) {
// replace remaining double dash but restore it in comment tags (this is getting ugly though).
// replace remaining double dash but restore it in comment tags (this is getting ugly though).
$the_content = str_replace( array( ' -- ', '-- ', ' --' ), ' &#8211; ', $the_content );
$the_content = str_replace( array( ' -- ', '-- ', ' --' ), ' &#8211; ', $the_content );
$the_content = str_replace( '<! &#8211;', '<!--', $the_content );
$the_content = str_replace( '<! &#8211;', '<!--', $the_content );
$the_content = str_replace( '&#8211; >', '-->', $the_content );
$the_content = str_replace( '&#8211; >', '-->', $the_content );
}
}


/** API: filter hook to postparse the_content before returning */
/** API: filter hook to postparse the_content before returning */
$the_content = apply_filters( 'lyte_content_postparse', $the_content );
$the_content = apply_filters( 'lyte_content_postparse', $the_content );


return $the_content;
return $the_content;
}
}


function lyte_get_YT_resp( $vid, $playlist=false, $cachekey='', $apiTestKey='', $isWidget=false ) {
function lyte_get_YT_resp( $vid, $playlist=false, $cachekey='', $apiTestKey='', $isWidget=false ) {
/** logic to get video info from cache or get it from YouTube and set it */
/** logic to get video info from cache or get it from YouTube and set it */
global $postID, $cachekey, $toCache_index;
global $postID, $cachekey, $toCache_index;


$_thisLyte = array();
$_thisLyte = array();
$yt_error = array();
$yt_error = array();


if ( $postID && empty( $apiTestKey ) && ! $isWidget ) {
if ( $postID && empty( $apiTestKey ) && ! $isWidget ) {
$cache_resp = get_post_meta( $postID, $cachekey, true );
$cache_resp = get_post_meta( $postID, $cachekey, true );
if ( ! empty( $cache_resp ) ) {
if ( ! empty( $cache_resp ) ) {
$_thisLyte = json_decode( gzuncompress( base64_decode( $cache_resp ) ), 1 );
$_thisLyte = json_decode( gzuncompress( base64_decode( $cache_resp ) ), 1 );
// make sure there are not old APIv2 full responses in cache
// make sure there are not old APIv2 full responses in cache
if ( array_key_exists( 'entry', $_thisLyte ) ) {
if ( array_key_exists( 'entry', $_thisLyte ) ) {
if ( $_thisLyte['entry']['xmlns$yt'] === 'http://gdata.youtube.com/schemas/2007' ) {
if ( $_thisLyte['entry']['xmlns$yt'] === 'http://gdata.youtube.com/schemas/2007' ) {
$_thisLyte = array();
$_thisLyte = array();
}
}
}
}
}
}
} else if ( $isWidget ) {
} else if ( $isWidget ) {
$cache_resp = get_option( 'lyte_widget_cache' );
$cache_resp = get_option( 'lyte_widget_cache' );
if ( ! empty( $cache_resp ) ) {
if ( ! empty( $cache_resp ) ) {
$widget_cache = json_decode( gzuncompress( base64_decode( $cache_resp ) ), 1 );
$widget_cache = json_decode( gzuncompress( base64_decode( $cache_resp ) ), 1 );
$_thisLyte = $widget_cache[$vid];
$_thisLyte = $widget_cache[$vid];
}
}
}
}


// set caching duration used to check if data is fresh enough, default max cachetime is 2 months.
// set caching duration used to check if data is fresh enough, default max cachetime is 2 months.
$_lyte_cache_gracetime = apply_filters( 'lyte_ytapi_cache_gracetime', 2 * 30 * 24 * 60 * 60 );
$_lyte_cache_gracetime = apply_filters( 'lyte_ytapi_cache_gracetime', 2 * 30 * 24 * 60 * 60 );
$_lyte_cache_time_expired = time() - $_lyte_cache_gracetime;
$_lyte_cache_time_expired = time() - $_lyte_cache_gracetime;


if ( empty( $_thisLyte ) || ( apply_filters( 'lyte_ytapi_check_cache', true ) && $_thisLyte['lyte_date_added'] < $_lyte_cache_time_expired ) ) {
if ( empty( $_thisLyte ) || ( apply_filters( 'lyte_ytapi_check_cache', true ) && $_thisLyte['lyte_date_added'] < $_lyte_cache_time_expired ) ) {
// no result from cache or expired so fetch info from youtube
// no result from cache or expired so fetch info from youtube
// first get yt api key
// first get yt api key
$lyte_yt_api_key = get_option('lyte_yt_api_key','');
$lyte_yt_api_key = get_option('lyte_yt_api_key','');
$lyte_yt_api_key = apply_filters('lyte_filter_yt_api_key', $lyte_yt_api_key);
$lyte_yt_api_key = apply_filters('lyte_filter_yt_api_key', $lyte_yt_api_key);
if ( ! empty( $apiTestKey ) ) {
if ( ! empty( $apiTestKey ) ) {
$lyte_yt_api_key = $apiTestKey;
$lyte_yt_api_key = $apiTestKey;
}
}


if ( ( $lyte_yt_api_key === 'none' ) || ( empty( $lyte_yt_api_key ) ) ) {
if ( ( $lyte_yt_api_key === 'none' ) || ( empty( $lyte_yt_api_key ) ) ) {
$_thisLyte['title'] = '';
$_thisLyte['title'] = '';
if ( $playlist ) {
if ( $playlist ) {
$_thisLyte['thumbUrl'] = '';
$_thisLyte['thumbUrl'] = '';
$_thisLyte['HQthumbUrl'] = '';
$_thisLyte['HQthumbUrl'] = '';
} else {
} else {
$_thisLyte['thumbUrl'] = '//i.ytimg.com/vi/' . $vid . '/hqdefault.jpg';
$_thisLyte['thumbUrl'] = '//i.ytimg.com/vi/' . $vid . '/hqdefault.jpg';
$_thisLyte['HQthumbUrl'] = '//i.ytimg.com/vi/' . $vid . '/maxresdefault.jpg';
$_thisLyte['HQthumbUrl'] = '//i.ytimg.com/vi/' . $vid . '/maxresdefault.jpg';
}
}
$_thisLyte['dateField'] = '';
$_thisLyte['dateField'] = '';
$_thisLyte['duration'] = '';
$_thisLyte['duration'] = '';
$_thisLyte['description'] = '';
$_thisLyte['description'] = '';
$_thisLyte['captions_data'] = 'false';
$_thisLyte['captions_data'] = 'false';
return $_thisLyte;
return $_thisLyte;
} else {
} else {
// v3, feeling somewhat lonely now v2 has gently been put to sleep
// v3, feeling somewhat lonely now v2 has gently been put to sleep
$yt_api_base = 'https://www.googleapis.com/youtube/v3/';
$yt_api_base = 'https://www.googleapis.com/youtube/v3/';


if ( $playlist ) {
if ( $playlist ) {
// filter to allow extra data to be requested from YT API, eg. statistics (to get view count).
// filter to allow extra data to be requested from YT API, eg. statistics (to get view count).
$yt_api_target = apply_filters( 'lyte_filter_ytapi_playlist_params', 'playlists?part=snippet%2C+id&id=' . $vid . '&key=' . $lyte_yt_api_key );
$yt_api_target = apply_filters( 'lyte_filter_ytapi_playlist_params', 'playlists?part=snippet%2C+id&id=' . $vid . '&key=' . $lyte_yt_api_key );
} else {
} else {
// filter to allow extra data to be requested from YT API, eg. statistics (to get view count).
// filter to allow extra data to be requested from YT API, eg. statistics (to get view count).
$yt_api_target = apply_filters( 'lyte_filter_ytapi_video_params', 'videos?part=id%2C+snippet%2C+contentDetails&id=' . $vid . '&key=' . $lyte_yt_api_key );
$yt_api_target = apply_filters( 'lyte_filter_ytapi_video_params', 'videos?part=id%2C+snippet%2C+contentDetails&id=' . $vid . '&key=' . $lyte_yt_api_key );
}
}
}
}


$yt_api_url = $yt_api_base . $yt_api_target;
$yt_api_url = $yt_api_base . $yt_api_target;
$yt_resp = wp_remote_get( $yt_api_url, array(
$yt_resp = wp_remote_get( $yt_api_url, array(
'headers' => array(
'headers' => array(
'referer' => home_url()
'referer' => home_url()
)
)
)
)
);
);


// check if we got through
// check if we got through
if ( is_wp_error( $yt_resp ) ) {
if ( is_wp_error( $yt_resp ) ) {
$yt_error['code'] = 408;
$yt_error['code'] = 408;
$yt_error['reason'] = $yt_resp->get_error_message();
$yt_error['reason'] = $yt_resp->get_error_message();
$yt_error['timestamp'] = strtotime('now');
$yt_error['timestamp'] = strtotime('now');
if ( ! empty( $apiTestKey ) ) {
if ( ! empty( $apiTestKey ) ) {
return $yt_error;
return $yt_error;
}
}
} else {
} else {
$yt_resp_array = (array) json_decode( wp_remote_retrieve_body( $yt_resp ), true );
$yt_resp_array = (array) json_decode( wp_remote_retrieve_body( $yt_resp ), true );
if ( is_array( $yt_resp_array ) ) {
if ( is_array( $yt_resp_array ) ) {
// extract relevant data
// extract relevant data
// v3
// v3
if ( in_array( wp_remote_retrieve_response_code( $yt_resp ), array( 400, 403, 404 ) ) ) {
if ( in_array( wp_remote_retrieve_response_code( $yt_resp ), array( 400, 403, 404 ) ) ) {
$yt_error['code'] = wp_remote_retrieve_response_code( $yt_resp );
$yt_error['code'] = wp_remote_retrieve_response_code( $yt_resp );
$yt_error['reason'] = $yt_resp_array['error']['errors'][0][
$yt_error['reason'] = $yt_resp_array['error']['errors'][0]['reason'];