WP YouTube Lyte - Version 1.7.16

Version Description

  • removed old captions code (captions are not natively supported through the YouTube API + the Benetech backend was no longer working)
  • added extra sanitization, thanks m0ze!
  • optionally disable thumbnail fallback to youtube servers (contributed by Benjamin Pick)
  • general code cleanup (spaces, double -> single quotes around strings, ...)
  • misc. smaller fixes/ improvements, see Github commits for details.
Download this release

Release Info

Developer futtta
Plugin Icon 128x128 WP YouTube Lyte
Version 1.7.16
Comparing to
See all releases

Code changes from version 1.7.15 to 1.7.16

Files changed (7) hide show
  1. lyteCache.php +40 -26
  2. lytePartners.php +16 -16
  3. options.php +151 -153
  4. player_sizes.inc.php +78 -78
  5. readme.txt +11 -1
  6. widget.php +85 -85
  7. wp-youtube-lyte.php +345 -384
lyteCache.php CHANGED
@@ -11,7 +11,7 @@
11
  */
12
 
13
  // no error reporting, those break header() output
14
- error_reporting(0);
15
 
16
  /*
17
  * step 0: set constant for dir where thumbs are stored + declaring some variables
@@ -23,9 +23,9 @@ if ( ! defined( 'LYTE_CACHE_DIR' ) ) {
23
  define( 'LYTE_CACHE_DIR', WP_CONTENT_DIR .'/'. LYTE_CACHE_CHILD_DIR );
24
  }
25
 
26
- $lyte_thumb_error = '';
27
- $lyte_thumb_dontsave = '';
28
- $thumbContents = '';
29
  $lyte_thumb_report_err = false;
30
 
31
  /*
@@ -50,27 +50,27 @@ if ( ! file_exists( LYTE_CACHE_DIR ) || ( file_exists( LYTE_CACHE_DIR . '/double
50
  }
51
 
52
  /*
53
- * step 3: check for and if need be create wp-content/cache/lyte_thumbs
54
  */
55
 
56
  if ( lyte_check_cache_dir( LYTE_CACHE_DIR ) === false ) {
57
  $lyte_thumb_dontsave = true;
58
- $lyte_thumb_error .= 'checkcache fail/ ';
59
  }
60
 
61
  /*
62
  * step 4: if not in cache: fetch from YT and store in cache
63
  */
64
 
65
- if ( strpos($origThumbURL,'http') !== 0 && strpos($origThumbURL,'//') === 0 ) {
66
- $origThumbURL = 'https:'.$origThumbURL;
67
  }
68
 
69
- $localThumb = LYTE_CACHE_DIR . '/' . md5($origThumbURL) . '.jpg';
70
- $expiryTime = filemtime( $localThumb ) + 3*24*60*60; // images can be cached for 3 days.
71
  $now = time();
72
 
73
- if ( !file_exists( $localThumb ) || $lyte_thumb_dontsave || ( file_exists( $localThumb ) && $expiryTime < $now ) ) {
74
  $thumbContents = lyte_get_thumb( $origThumbURL );
75
 
76
  if ( $thumbContents != '' && ! $lyte_thumb_dontsave ) {
@@ -78,7 +78,7 @@ if ( !file_exists( $localThumb ) || $lyte_thumb_dontsave || ( file_exists( $loca
78
  file_put_contents( $localThumb, $thumbContents );
79
  if ( ! is_jpeg( $localThumb ) ) {
80
  unlink( $localThumb );
81
- $thumbContents = '';
82
  $lyte_thumb_error .= 'deleted as not jpeg/ ';
83
  }
84
  }
@@ -95,31 +95,38 @@ if ( $thumbContents == '' && ! $lyte_thumb_dontsave && file_exists( $localThumb
95
  }
96
 
97
  if ( $thumbContents != '') {
 
 
 
 
 
 
 
 
 
98
  if ( $lyte_thumb_error !== '' && $lyte_thumb_report_err ) {
99
  header('X-lyte-error: '.$lyte_thumb_error);
100
  }
101
 
102
- $modTime = filemtime($localThumb);
103
 
104
- date_default_timezone_set('UTC');
105
  $modTimeMatch = ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) && strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) === $modTime );
106
 
107
  if ( $modTimeMatch ) {
108
- header('HTTP/1.1 304 Not Modified');
109
- header('Connection: close');
110
  } else {
111
  // send all sorts of headers
112
  $expireTime = 60 * 60 * 24 * 7; // 1w
113
  header( 'Content-Length: '. strlen( $thumbContents) );
114
  header( 'Cache-Control: max-age=' . $expireTime . ', public, immutable' );
115
- header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expireTime).' GMT' );
116
- header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $modTime) . ' GMT' );
117
- header( 'Content-type:image/jpeg' );
118
  echo $thumbContents;
119
  }
120
- } else {
121
- $lyte_thumb_error .= 'no thumbContent/ ';
122
- lyte_thumb_fallback();
123
  }
124
 
125
  /*
@@ -142,7 +149,6 @@ function is_jpeg( $in ) {
142
  }
143
 
144
  function lyte_check_cache_dir( $dir ) {
145
- // Try creating the dir if it doesn't exist.
146
  if ( ! file_exists( $dir ) || ! is_writable( $dir ) ) {
147
  return false;
148
  }
@@ -211,12 +217,20 @@ function get_origThumbURL() {
211
  function lyte_thumb_fallback() {
212
  global $origThumbURL, $lyte_thumb_error, $lyte_thumb_report_err;
213
  // if for any reason we can't show a local thumbnail, we redirect to the original one
 
 
 
 
 
 
 
214
  if ( strpos( $origThumbURL, 'http' ) !== 0) {
215
  $origThumbURL = 'https:' . $origThumbURL;
216
  }
217
  if ( $lyte_thumb_report_err ) {
218
- header('X-lyte-error: '.$lyte_thumb_error);
219
  }
220
- header('HTTP/1.1 301 Moved Permanently');
221
- header('Location: '. $origThumbURL );
 
222
  }
11
  */
12
 
13
  // no error reporting, those break header() output
14
+ error_reporting( 0 );
15
 
16
  /*
17
  * step 0: set constant for dir where thumbs are stored + declaring some variables
23
  define( 'LYTE_CACHE_DIR', WP_CONTENT_DIR .'/'. LYTE_CACHE_CHILD_DIR );
24
  }
25
 
26
+ $lyte_thumb_error = '';
27
+ $lyte_thumb_dontsave = '';
28
+ $thumbContents = '';
29
  $lyte_thumb_report_err = false;
30
 
31
  /*
50
  }
51
 
52
  /*
53
+ * step 3: check for directory wp-content/cache/lyteCache
54
  */
55
 
56
  if ( lyte_check_cache_dir( LYTE_CACHE_DIR ) === false ) {
57
  $lyte_thumb_dontsave = true;
58
+ $lyte_thumb_error .= 'checkcache fail/ ';
59
  }
60
 
61
  /*
62
  * step 4: if not in cache: fetch from YT and store in cache
63
  */
64
 
65
+ if ( strpos( $origThumbURL, 'http' ) !== 0 && strpos( $origThumbURL, '//' ) === 0 ) {
66
+ $origThumbURL = 'https:' . $origThumbURL;
67
  }
68
 
69
+ $localThumb = LYTE_CACHE_DIR . '/' . md5( $origThumbURL ) . '.jpg';
70
+ $expiryTime = filemtime( $localThumb ) + 3 * 24 * 60 * 60; // images can be cached for 3 days.
71
  $now = time();
72
 
73
+ if ( ! file_exists( $localThumb ) || $lyte_thumb_dontsave || ( file_exists( $localThumb ) && $expiryTime < $now ) ) {
74
  $thumbContents = lyte_get_thumb( $origThumbURL );
75
 
76
  if ( $thumbContents != '' && ! $lyte_thumb_dontsave ) {
78
  file_put_contents( $localThumb, $thumbContents );
79
  if ( ! is_jpeg( $localThumb ) ) {
80
  unlink( $localThumb );
81
+ $thumbContents = '';
82
  $lyte_thumb_error .= 'deleted as not jpeg/ ';
83
  }
84
  }
95
  }
96
 
97
  if ( $thumbContents != '') {
98
+ lyte_output_image( $thumbContents );
99
+ } else {
100
+ $lyte_thumb_error .= 'no thumbContent/ ';
101
+ lyte_thumb_fallback();
102
+ }
103
+
104
+ function lyte_output_image( $thumbContents, $contentType = 'image/jpeg' ) {
105
+ global $lyte_thumb_error, $lyte_thumb_report_err;
106
+
107
  if ( $lyte_thumb_error !== '' && $lyte_thumb_report_err ) {
108
  header('X-lyte-error: '.$lyte_thumb_error);
109
  }
110
 
111
+ $modTime = filemtime( $localThumb );
112
 
113
+ date_default_timezone_set( 'UTC' );
114
  $modTimeMatch = ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) && strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) === $modTime );
115
 
116
  if ( $modTimeMatch ) {
117
+ header( 'HTTP/1.1 304 Not Modified' );
118
+ header( 'Connection: close' );
119
  } else {
120
  // send all sorts of headers
121
  $expireTime = 60 * 60 * 24 * 7; // 1w
122
  header( 'Content-Length: '. strlen( $thumbContents) );
123
  header( 'Cache-Control: max-age=' . $expireTime . ', public, immutable' );
124
+ header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expireTime ).' GMT' );
125
+ header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $modTime ) . ' GMT' );
126
+ header( 'Content-Type: ' . $contentType );
127
  echo $thumbContents;
128
  }
129
+ exit;
 
 
130
  }
131
 
132
  /*
149
  }
150
 
151
  function lyte_check_cache_dir( $dir ) {
 
152
  if ( ! file_exists( $dir ) || ! is_writable( $dir ) ) {
153
  return false;
154
  }
217
  function lyte_thumb_fallback() {
218
  global $origThumbURL, $lyte_thumb_error, $lyte_thumb_report_err;
219
  // if for any reason we can't show a local thumbnail, we redirect to the original one
220
+
221
+ if ( file_exists( LYTE_CACHE_DIR . '/disableThumbFallback.txt' ) ) {
222
+ // This is a 10x10 Pixel GIF with grey background
223
+ $thumb_error = base64_decode('R0lGODdhCgAKAIABAMzMzP///ywAAAAACgAKAAACCISPqcvtD2MrADs=');
224
+ lyte_output_image( $thumb_error, 'image/gif' );
225
+ }
226
+
227
  if ( strpos( $origThumbURL, 'http' ) !== 0) {
228
  $origThumbURL = 'https:' . $origThumbURL;
229
  }
230
  if ( $lyte_thumb_report_err ) {
231
+ header( 'X-lyte-error: '.$lyte_thumb_error );
232
  }
233
+ header( 'HTTP/1.1 301 Moved Permanently' );
234
+ header( 'Location: '. $origThumbURL );
235
+ exit;
236
  }
lytePartners.php CHANGED
@@ -5,22 +5,22 @@ Classlessly add a "more tools" tab to promote (future) AO addons and/ or affilia
5
 
6
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
7
 
8
- add_action('admin_init', 'lyte_partner_tabs_preinit');
9
  function lyte_partner_tabs_preinit() {
10
- if (apply_filters('wp-youtube-lyte_filter_show_partner_tabs',true)) {
11
- add_filter('wp-youtube-lyte_filter_settingsscreen_tabs','lyte_add_partner_tabs');
12
  }
13
  }
14
 
15
- function lyte_add_partner_tabs($in) {
16
- $in=array_merge($in,array('lyte_partners' => __('More Performance!','wp-youtube-lyte')));
17
  return $in;
18
  }
19
 
20
- add_action('admin_menu','lyte_partners_init');
21
  function lyte_partners_init() {
22
- if (apply_filters('wp-youtube-lyte_filter_show_partner_tabs',true)) {
23
- $hook=add_submenu_page(NULL,'Lyte partner','Lyte partner','manage_options','lyte_partners','lyte_partners');
24
  // register_settings here as well if needed
25
  }
26
  }
@@ -71,10 +71,10 @@ function lyte_partners() {
71
  }
72
  </style>
73
  <div class="wrap">
74
- <h1><?php _e('WP YouTube Lyte Settings','wp-youtube-lyte'); ?></h1>
75
  <?php echo lyte_admin_tabs(); ?>
76
  <?php
77
- echo '<h2>'. __("These related services will improve your site's performance even more!",'wp-youtube-lyte') . '</h2>';
78
  ?>
79
  <div>
80
  <?php getLytePartnerFeed(); ?>
@@ -86,12 +86,12 @@ function lyte_partners() {
86
  function getLytePartnerFeed() {
87
  $noFeedText=__( 'Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for wp-youtube-lyte power-ups!', 'wp-youtube-lyte' );
88
 
89
- if (apply_filters('wp-youtube-lyte_settingsscreen_remotehttp',true)) {
90
- $rss = fetch_feed( "http://feeds.feedburner.com/OptimizingMattersDownloads" );
91
  $maxitems = 0;
92
 
93
  if ( ! is_wp_error( $rss ) ) {
94
- $maxitems = $rss->get_item_quantity( 20 );
95
  $rss_items = $rss->get_items( 0, $maxitems );
96
  } ?>
97
  <ul>
@@ -104,9 +104,9 @@ function getLytePartnerFeed() {
104
  <li class="itemDetail">
105
  <h3 class="itemTitle"><a href="<?php echo $itemURL; ?>" target="_blank"><?php echo esc_html( $item->get_title() ); ?></a></h3>
106
  <?php
107
- if (($enclosure = $item->get_enclosure()) && (strpos($enclosure->get_type(),"image")!==false) ) {
108
- $itemImgURL=esc_url($enclosure->get_link());
109
- echo "<div class=\"itemImage\"><a href=\"".$itemURL."\" target=\"_blank\"><img src=\"".$itemImgURL."\"/></a></div>";
110
  }
111
  ?>
112
  <div class="itemDescription"><?php echo wp_kses_post($item -> get_description() ); ?></div>
5
 
6
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
7
 
8
+ add_action( 'admin_init', 'lyte_partner_tabs_preinit' );
9
  function lyte_partner_tabs_preinit() {
10
+ if ( apply_filters( 'wp-youtube-lyte_filter_show_partner_tabs', true ) ) {
11
+ add_filter( 'wp-youtube-lyte_filter_settingsscreen_tabs', 'lyte_add_partner_tabs' );
12
  }
13
  }
14
 
15
+ function lyte_add_partner_tabs( $in ) {
16
+ $in = array_merge( $in, array( 'lyte_partners' => __( 'More Performance!', 'wp-youtube-lyte' ) ) );
17
  return $in;
18
  }
19
 
20
+ add_action( 'admin_menu', 'lyte_partners_init' );
21
  function lyte_partners_init() {
22
+ if ( apply_filters( 'wp-youtube-lyte_filter_show_partner_tabs', true ) ) {
23
+ $hook = add_submenu_page( NULL, 'Lyte partner', 'Lyte partner', 'manage_options', 'lyte_partners', 'lyte_partners' );
24
  // register_settings here as well if needed
25
  }
26
  }
71
  }
72
  </style>
73
  <div class="wrap">
74
+ <h1><?php _e( 'WP YouTube Lyte Settings', 'wp-youtube-lyte' ); ?></h1>
75
  <?php echo lyte_admin_tabs(); ?>
76
  <?php
77
+ echo '<h2>'. __( 'These related services will improve your site\'s performance even more!', 'wp-youtube-lyte' ) . '</h2>';
78
  ?>
79
  <div>
80
  <?php getLytePartnerFeed(); ?>
86
  function getLytePartnerFeed() {
87
  $noFeedText=__( 'Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for wp-youtube-lyte power-ups!', 'wp-youtube-lyte' );
88
 
89
+ if ( apply_filters( 'wp-youtube-lyte_settingsscreen_remotehttp', true ) ) {
90
+ $rss = fetch_feed( 'https://feeds.feedburner.com/OptimizingMattersDownloads' );
91
  $maxitems = 0;
92
 
93
  if ( ! is_wp_error( $rss ) ) {
94
+ $maxitems = $rss->get_item_quantity( 20 );
95
  $rss_items = $rss->get_items( 0, $maxitems );
96
  } ?>
97
  <ul>
104
  <li class="itemDetail">
105
  <h3 class="itemTitle"><a href="<?php echo $itemURL; ?>" target="_blank"><?php echo esc_html( $item->get_title() ); ?></a></h3>
106
  <?php
107
+ if (($enclosure = $item->get_enclosure()) && ( strpos( $enclosure->get_type(), 'image') !== false ) ) {
108
+ $itemImgURL = esc_url( $enclosure->get_link() );
109
+ echo '<div class="itemImage"><a href="' . $itemURL . '" target="_blank"><img src="' . $itemImgURL . '"/></a></div>';
110
  }
111
  ?>
112
  <div class="itemDescription"><?php echo wp_kses_post($item -> get_description() ); ?></div>
options.php CHANGED
@@ -1,49 +1,49 @@
1
  <?php
2
  if ( ! defined( 'ABSPATH' ) ) exit;
3
 
4
- require("lytePartners.php");
5
 
6
- $plugin_dir = basename(dirname(__FILE__)).'/languages';
7
  load_plugin_textdomain( 'wp-youtube-lyte', false, $plugin_dir );
8
 
9
  add_action('admin_menu', 'lyte_create_menu');
10
 
11
- if (get_option('lyte_emptycache','0')==="1") {
12
- $emptycache=lyte_rm_cache();
13
- update_option('lyte_emptycache','0');
14
- if ($emptycache==="OK") {
15
- add_action('admin_notices', 'lyte_cacheclear_ok_notice');
16
- } elseif ($emptycache==="PART") {
17
- add_action('admin_notices', 'lyte_cacheclear_part_notice');
18
- update_option('lyte_emptycache','1'); // to ensure cache-purging continues
19
  } else {
20
- add_action('admin_notices', 'lyte_cacheclear_fail_notice');
21
  }
22
  }
23
 
24
  function lyte_cacheclear_ok_notice() {
25
  echo '<div class="updated"><p>';
26
- _e('Your WP YouTube Lyte cache has been succesfully cleared.', 'wp-youtube-lyte' );
27
  echo '</p></div>';
28
  }
29
 
30
  function lyte_cacheclear_part_notice() {
31
  echo '<div class="error"><p>';
32
- _e('WP YouTube Lyte cache was partially cleared, refresh this page to continue purging.', 'wp-youtube-lyte' );
33
  echo '</p></div>';
34
  }
35
 
36
  function lyte_cacheclear_fail_notice() {
37
  echo '<div class="error"><p>';
38
- _e('There was a problem, the WP YouTube Lyte cache could not be cleared.', 'wp-youtube-lyte' );
39
  echo '</p></div>';
40
  }
41
 
42
  function lyte_create_menu() {
43
  $hook=add_options_page( 'WP YouTube Lyte settings', 'WP YouTube Lyte', 'manage_options', 'lyte_settings_page', 'lyte_settings_page');
44
  add_action( 'admin_init', 'register_lyte_settings' );
45
- add_action( 'admin_print_scripts-'.$hook, 'lyte_admin_scripts' );
46
- add_action( 'admin_print_styles-'.$hook, 'lyte_admin_styles' );
47
  }
48
 
49
  function register_lyte_settings() {
@@ -51,7 +51,6 @@ function register_lyte_settings() {
51
  register_setting( 'lyte-settings-group', 'lyte_size' );
52
  register_setting( 'lyte-settings-group', 'lyte_hidef' );
53
  register_setting( 'lyte-settings-group', 'lyte_position' );
54
- register_setting( 'lyte-settings-group', 'lyte_notification' );
55
  register_setting( 'lyte-settings-group', 'lyte_microdata' );
56
  register_setting( 'lyte-settings-group', 'lyte_emptycache' );
57
  register_setting( 'lyte-settings-group', 'lyte_greedy' );
@@ -61,42 +60,42 @@ function register_lyte_settings() {
61
  }
62
 
63
  function lyte_admin_scripts() {
64
- wp_enqueue_script('jqcookie', plugins_url('/external/jquery.cookie.min.js', __FILE__), array('jquery'),null,true);
65
- wp_enqueue_script('unslider', plugins_url('/external/unslider-min.js', __FILE__), array('jquery'),null,true);
66
- }
67
 
68
  function lyte_admin_styles() {
69
- wp_enqueue_style('unslider', plugins_url('/external/unslider.css', __FILE__));
70
- wp_enqueue_style('unslider-dots', plugins_url('/external/unslider-dots.css', __FILE__));
71
  }
72
 
73
  function lyte_admin_nag_apikey() {
74
- echo "<div class=\"update-nag\">";
75
- _e('For WP YouTube Lyte to function optimally, you should enter an YouTube API key ', 'wp-youtube-lyte');
76
- echo " <a href=\"options-general.php?page=lyte_settings_page\">";
77
- _e('in the settings screen.','wp-youtube-lyte');
78
- echo "</a>.</div>";
79
  }
80
 
81
- $lyte_yt_api_key=get_option('lyte_yt_api_key','');
82
- $lyte_yt_api_key=apply_filters('lyte_filter_yt_api_key', $lyte_yt_api_key);
83
- if (empty($lyte_yt_api_key)) {
84
- add_action('admin_notices', 'lyte_admin_nag_apikey');
85
- }
86
 
87
  function lyte_admin_api_error(){
88
- $yt_error=json_decode(get_option('lyte_api_error'),1);
89
  echo '<div class="error"><p>';
90
- _e('WP YouTube Lyte got the following error back from the YouTube API: ','wp-youtube-lyte');
91
- echo "<strong>".$yt_error["reason"]."</strong>";
92
- echo " (".date("r",$yt_error["timestamp"]).").";
93
  echo '</a>.</p></div>';
94
- update_option('lyte_api_error','');
95
  }
96
 
97
- if (get_option('lyte_api_error','')!=='') {
98
- add_action('admin_notices', 'lyte_admin_api_error');
99
- }
100
 
101
  function lyte_settings_page() {
102
  global $pSize, $pSizeOrder;
@@ -167,42 +166,41 @@ function lyte_settings_page() {
167
  }
168
  </style>
169
  <div class="wrap">
170
- <h2><?php _e("WP YouTube Lyte Settings","wp-youtube-lyte") ?></h2>
171
  <div style="float:left;width:70%;">
172
  <?php echo lyte_admin_tabs(); ?>
173
  <form method="post" action="options.php">
174
  <?php settings_fields( 'lyte-settings-group' ); ?>
175
  <table class="form-table">
176
- <input type="hidden" name="lyte_notification" value="<?php echo get_option('lyte_notification','0'); ?>" />
177
  <tr valign="top">
178
- <th scope="row"><?php _e("Your YouTube API key.","wp-youtube-lyte") ?></th>
179
  <td>
180
  <?php // only show api key input field if there's no result from filter
181
- $filter_key=apply_filters('lyte_filter_yt_api_key','');
182
- if (empty($filter_key)) { ?>
183
  <fieldset>
184
- <legend class="screen-reader-text"><span><?php _e("Please enter your YouTube API key.","wp-youtube-lyte") ?></span></legend>
185
- <label title="<?php _e('API key','wp-youtube-lyte'); ?>"><input type="text" size="28" name="lyte_yt_api_key" id="lyte_yt_api_key" value="<?php echo get_option('lyte_yt_api_key',''); ?>"><span id="check_api_key" class="submit button-secondary" style="margin:0px 5px;"><?php _e("Test Key"); ?></span></label><br />
186
  <div id="lyte_key_check_output" style="display:none;margin-bottom:5px;background-color:white;border-left:solid;border-width:4px;border-color:#2ea2cc;padding:5px 5px 5px 15px;"></div>
187
- <?php _e("WP YouTube Lyte uses YouTube's API to fetch information on each video. For your site to use that API, you will have to <a href=\"https://console.developers.google.com/project/\" target=\"_blank\">register your site as a new application</a>, enable the YouTube API for it and get a server key and fill it out here.","wp-youtube-lyte"); ?>
188
  </fieldset>
189
  <?php } else { ?>
190
- <?php _e("Great, your YouTube API key has been taken care of!","wp-youtube-lyte"); ?>
191
  <?php } ?>
192
  </td>
193
  </tr>
194
  <tr valign="top">
195
- <th scope="row"><?php _e("Player size","wp-youtube-lyte") ?>:</th>
196
  <td>
197
- <fieldset><legend class="screen-reader-text"><span><?php _e("Player size","wp-youtube-lyte") ?></span></legend>
198
  <?php
199
- $sel = !is_bool(get_option('lyte_size')) ? (int) get_option('lyte_size') : 0;
200
- foreach (array("169","43") as $f) {
201
- foreach ($pSizeOrder[$f] as $i) {
202
- $pS=$pSize[$i];
203
- if ($pS['a']===true) {
204
  ?>
205
- <label title="<?php echo $pS['w']."X".$pS['h']; ?>"><input type="radio" name="lyte_size" class="l_size" value="<?php echo $i."\"";if($i===$sel) echo " checked";echo " /> ".$pS['w']."X".$pS['h']." (".$pS['t'];?>)</label><br />
206
  <?php
207
  }
208
  }
@@ -213,80 +211,80 @@ function lyte_settings_page() {
213
  </td>
214
  </tr>
215
  <tr valign="top">
216
- <th scope="row"><?php _e("Add links below the embedded videos?","wp-youtube-lyte") ?></th>
217
  <td>
218
  <fieldset>
219
- <legend class="screen-reader-text"><span><?php _e("Show links?","wp-youtube-lyte") ?></span></legend>
220
- <label title="<?php _e('Show YouTube-link','wp-youtube-lyte');?>"><input type="radio" name="lyte_show_links" value="1" <?php if (get_option('lyte_show_links')==="1" || get_option('lyte_show_links')==="2") echo "checked" ?> /><?php _e(" Add YouTube-link.","wp-youtube-lyte") ?></label><br />
221
- <label title="<?php _e('Don\'t include links.','wp-youtube-lyte');?>"><input type="radio" name="lyte_show_links" value="0" <?php if ((get_option('lyte_show_links')!=="1") && (get_option('lyte_show_links')!=="2")) echo "checked" ?> /><?php _e(" Don't add any links.","wp-youtube-lyte") ?></label>
222
  </fieldset>
223
  </td>
224
  </tr>
225
  <tr valign="top">
226
- <th scope="row"><?php _e("Player position:","wp-youtube-lyte") ?></th>
227
  <td>
228
  <fieldset>
229
- <legend class="screen-reader-text"><span><?php _e("Left, center or right?","wp-youtube-lyte"); ?></span></legend>
230
- <label title="<?php _e('Left','wp-youtube-lyte');?>"><input type="radio" name="lyte_position" value="0" <?php if (get_option('lyte_position','0')==="0") echo "checked" ?> /><?php _e("Left","wp-youtube-lyte") ?></label><br />
231
- <label title="<?php _e('Center','wp-youtube-lyte');?>"><input type="radio" name="lyte_position" value="1" <?php if (get_option('lyte_position','0')==="1") echo "checked" ?> /><?php _e("Center","wp-youtube-lyte") ?></label>
232
  </fieldset>
233
  </td>
234
  </tr>
235
  <tr valign="top">
236
- <th scope="row"><?php _e("Try to force HD?","wp-youtube-lyte") ?></th>
237
  <td>
238
  <fieldset>
239
- <legend class="screen-reader-text"><span><?php _e("HD or not?","wp-youtube-lyte"); ?></span></legend>
240
- <label title="<?php _e('Enable HD?','wp-youtube-lyte');?>"><input type="radio" name="lyte_hidef" value="1" <?php if (get_option('lyte_hidef','0')==="1") echo "checked" ?> /><?php _e("Enable HD","wp-youtube-lyte") ?></label><br />
241
- <label title="<?php _e('Don\'t enable HD playback','wp-youtube-lyte');?>"><input type="radio" name="lyte_hidef" value="0" <?php if (get_option('lyte_hidef','0')!=="1") echo "checked" ?> /><?php _e("No HD (default)","wp-youtube-lyte") ?></label>
242
  </fieldset>
243
  </td>
244
  </tr>
245
  <tr valign="top">
246
- <th scope="row"><?php _e("Add microdata?","wp-youtube-lyte") ?></th>
247
  <td>
248
  <fieldset>
249
- <legend class="screen-reader-text"><span><?php _e("Add video microdata to the HTML?","wp-youtube-lyte"); ?></span></legend>
250
- <label title="<?php _e('Sure, add microdata!','wp-youtube-lyte');?>"><input type="radio" name="lyte_microdata" value="1" <?php if (get_option('lyte_microdata','1')==="1") echo "checked" ?> /><?php _e("Yes (default)","wp-youtube-lyte") ?></label><br />
251
- <label title="<?php _e('No microdata in my HTML please.','wp-youtube-lyte');?>"><input type="radio" name="lyte_microdata" value="0" <?php if (get_option('lyte_microdata','1')!=="1") echo "checked" ?> /><?php _e("No microdata, thanks.","wp-youtube-lyte") ?></label>
252
  </fieldset>
253
  </td>
254
  </tr>
255
  <tr valign="top">
256
- <th scope="row"><?php _e("Also act on normal YouTube links and iframes?","wp-youtube-lyte") ?></th>
257
  <td>
258
  <fieldset>
259
- <legend class="screen-reader-text"><span><?php _e("Also act on normal YouTube links?","wp-youtube-lyte") ?></span></legend>
260
- <label title="<?php _e('That would be great!','wp-youtube-lyte');?>"><input type="radio" name="lyte_greedy" value="1" <?php if (get_option('lyte_greedy','1')==="1") echo "checked" ?> /><?php _e("Yes (default)","wp-youtube-lyte") ?></label><br />
261
- <label title="<?php _e('No, I\'ll stick to httpv or shortcodes.','wp-youtube-lyte');?>"><input type="radio" name="lyte_greedy" value="0" <?php if (get_option('lyte_greedy','1')!=="1") echo "checked" ?> /><?php _e("No thanks.","wp-youtube-lyte") ?></label>
262
  </fieldset>
263
  </td>
264
  </tr>
265
  <tr valign="top">
266
- <th scope="row"><?php _e("Cache thumbnails locally?","wp-youtube-lyte"); ?></th>
267
  <td>
268
  <fieldset>
269
- <legend class="screen-reader-text"><span><?php _e("Cache thumbnails locally?","wp-youtube-lyte") ?></span></legend>
270
- <label title="<?php _e('That would be great!','wp-youtube-lyte');?>"><input type="radio" name="lyte_local_thumb" value="1" <?php if (get_option('lyte_local_thumb','0')==="1") echo "checked" ?> /><?php _e("Yes.","wp-youtube-lyte") ?></label><br />
271
- <label title="<?php _e('No, keep on using YouTube hosted thumbnails.','wp-youtube-lyte');?>"><input type="radio" name="lyte_local_thumb" value="0" <?php if (get_option('lyte_local_thumb','0')!=="1") echo "checked" ?> /><?php _e("No (default).","wp-youtube-lyte") ?></label>
272
  <br />
273
- <?php _e("Having the thumbnails cached locally can improve performance and will enhance visitor privacy as by default no requests will be sent to YouTube unless the video is played.","wp-youtube-lyte"); ?>
274
  </fieldset>
275
  </td>
276
  </tr>
277
  <tr valign="top">
278
- <th scope="row"><?php _e("Text to be added under every LYTE video.","wp-youtube-lyte"); ?></th>
279
  <td>
280
  <fieldset>
281
- <legend class="screen-reader-text"><span><?php _e("Text (e.g. for disclaimer) to be added under every LYTE video.","wp-youtube-lyte") ?></span></legend>
282
- <input type="text" style="width:100%;" name="lyte_disclaimer" placeholder="" value="<?php echo esc_textarea(get_option('lyte_disclaimer','')); ?>" /><br />
283
  <br />
284
- <?php _e("If you want to add e.g. a privacy disclaimer under every LYTE embedded video, you can do so here. Some HTML is allowed. Simply leave empty not to show anything.","wp-youtube-lyte"); ?>
285
  </fieldset>
286
  </td>
287
  </tr>
288
  <tr valign="top">
289
- <th scope="row"><?php _e("Empty WP YouTube Lyte's cache","wp-youtube-lyte") ?></th>
290
  <td>
291
  <fieldset>
292
  <legend class="screen-reader-text"><span>Remove WP YouTube Lyte's cache</span></legend>
@@ -297,7 +295,7 @@ function lyte_settings_page() {
297
  </table>
298
 
299
  <p class="submit">
300
- <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
301
  </p>
302
 
303
  </form>
@@ -306,46 +304,46 @@ function lyte_settings_page() {
306
  <div class="lyte_banner ">
307
  <ul>
308
  <?php
309
- if (apply_filters('wp-youtube-lyte_settingsscreen_remotehttp',true)) {
310
- $lyte_banner=get_transient("wp-youtube-lyte_banner");
311
- if (empty($lyte_banner)) {
312
- $banner_resp = wp_remote_get("http://misc.optimizingmatters.com/wp-youtube-lyte_news.html");
313
- if (!is_wp_error($banner_resp)) {
314
- if (wp_remote_retrieve_response_code($banner_resp)=="200") {
315
- $lyte_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
316
- set_transient("wp-youtube-lyte_banner",$lyte_banner,DAY_IN_SECONDS);
317
  }
318
  }
319
  }
320
  echo $lyte_banner;
321
  }
322
  ?>
323
- <li><?php _e("Need help? <a href='https://wordpress.org/plugins/wp-youtube-lyte/faq/'>Check out the FAQ here</a>.","wp-youtube-lyte"); ?></li>
324
- <li><?php _e("Happy with wp-youtube-lyte?","wp-youtube-lyte"); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e("Try my other plugins!","wp-youtube-lyte"); ?></a></li>
325
  </ul>
326
  </div>
327
  <div style="margin-left:10px;margin-top:-5px;">
328
  <h2>
329
- <?php _e("futtta about","wp-youtube-lyte") ?>
330
  <select id="feed_dropdown" >
331
- <option value="1"><?php _e("WP YouTube Lyte","wp-youtube-lyte") ?></option>
332
- <option value="2"><?php _e("WordPress","wp-youtube-lyte") ?></option>
333
- <option value="3"><?php _e("Web Technology","wp-youtube-lyte") ?></option>
334
  </select>
335
  </h2>
336
  <div id="futtta_feed">
337
  <div id="wp-youtube-lytefeed">
338
- <?php getFutttaFeeds("http://feeds.feedburner.com/futtta_wp-youtube-lyte"); ?>
339
  </div>
340
  <div id="wordpressfeed">
341
- <?php getFutttaFeeds("http://feeds.feedburner.com/futtta_wordpress"); ?>
342
  </div>
343
  <div id="webtechfeed">
344
- <?php getFutttaFeeds("http://feeds.feedburner.com/futtta_webtech"); ?>
345
  </div>
346
  </div>
347
  </div>
348
- <div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e("Do not donate for this plugin!","wp-youtube-lyte"); ?>"></a></div>
349
  </div>
350
 
351
  <script type="text/javascript">
@@ -358,7 +356,7 @@ function lyte_settings_page() {
358
  jQuery(document).ready(function() {
359
  jQuery( "#check_api_key" ).click(function() {
360
  jQuery("#lyte_key_check_output").show();
361
- jQuery("#lyte_key_check_output").append('<p><?php _e("Checking your key ..."); ?></p>');
362
  lyte_yt_api_key=jQuery("input#lyte_yt_api_key").val();
363
  if ((lyte_yt_api_key.length>9) &&(lyte_yt_api_key.length<99)) {
364
  var data = {
@@ -370,7 +368,7 @@ function lyte_settings_page() {
370
  jQuery("#lyte_key_check_output").append('<p>'+response+'</p>');
371
  });
372
  } else {
373
- jQuery("#lyte_key_check_output").append('<p><?php _e("That does not seem to be a correct API key!"); ?></p>');
374
  }
375
  })
376
  jQuery('#lyte_admin_feed').fadeTo("slow",1).show();
@@ -401,78 +399,78 @@ function lyte_settings_page() {
401
  // ajax receiver for YT API key check
402
  add_action( 'wp_ajax_lyte_check_yt_api_key', 'lyte_check_yt_api_key_callback' );
403
  function lyte_check_yt_api_key_callback() {
404
- check_ajax_referer( "lyte_check_api_key", 'lyte_nonce' );
405
- $api_key = strip_tags($_POST['lyte_yt_api_key']);
406
 
407
  // use random video to make sure a cache is not spoiling things
408
- $vidToCheck=array("ZmnZHudtzXg","2_7oQcAkyl8","nOvv80wkSgI","pBCt5nfsZ30","KHw7gdJ14uQ","qJ_PMvjmC6M","DVwHCGAr_OE","LtOGa5M8AuU","VHO9uZX9FNU");
409
- $randVidIndex=array_rand($vidToCheck);
410
 
411
- $api_response = lyte_get_YT_resp($vidToCheck[$randVidIndex],false,"",$api_key);
412
 
413
- if (is_array($api_response)) {
414
- if (!empty($api_response["title"])) {
415
- _e("API seems OK, you can Save Changes below now.");
416
- } else if (!empty($api_response["reason"])) {
417
- $all_but_one = __("API key not OK, your key seems to ");
418
- switch ($api_response["reason"]) {
419
- case "keyInvalid":
420
  echo $all_but_one;
421
- _e("be invalid.",'wp-youtube-lyte');
422
  break;
423
- case "ipRefererBlocked":
424
  echo $all_but_one;
425
- _e("be valid, but restricted to an IP-address which is not your server's.",'wp-youtube-lyte');
426
- _e("Try changing the allowed IP for your API key to include this one: ",'wp-youtube-lyte');
427
  echo $_SERVER["SERVER_ADDR"];
428
  break;
429
- case "keyExpired":
430
  echo $all_but_one;
431
- _e("have expired, please check in the Google Developer Console.",'wp-youtube-lyte');
432
  break;
433
- case "limitExceeded":
434
- case "quotaExceeded":
435
- case "rateLimitExceeded":
436
- case "userRateLimitExceeded":
437
  echo $all_but_one;
438
- _e("be correct, but seems to have exceeded the number of requests that can be made with it.",'wp-youtube-lyte');
439
  break;
440
- case "videoNotFound":
441
  echo $all_but_one;
442
- _e("probably work, but as the video with id ",'wp-youtube-lyte');
443
  echo $vidToCheck[$randVidIndex];
444
- _e(" was not found we cannot be sure, please try again.",'wp-youtube-lyte');
445
  break;
446
  default:
447
- _e("Your API key might be OK, but the API call did not succeed or the response was not entirely expected. Technical error: ",'wp-youtube-lyte');
448
- echo $api_response["reason"];
449
  }
450
  }
451
  } else {
452
- _e("Something went wrong, WP YouTube Lyte might not have been able to retrieve information from the YouTube API, got error: ",'wp-youtube-lyte');
453
- print_r($api_response);
454
  }
455
  wp_die();
456
  }
457
 
458
  function getFutttaFeeds($url) {
459
- if (apply_filters('lyte_settingsscreen_remotehttp',true)) {
460
  $rss = fetch_feed( $url );
461
  $maxitems = 0;
462
 
463
  if ( ! is_wp_error( $rss ) ) {
464
- $maxitems = $rss->get_item_quantity( 7 );
465
  $rss_items = $rss->get_items( 0, $maxitems );
466
  }
467
  ?>
468
  <ul>
469
  <?php if ( $maxitems == 0 ) : ?>
470
- <li><?php _e( 'No items', 'autoptimize' ); ?></li>
471
  <?php else : ?>
472
  <?php foreach ( $rss_items as $item ) : ?>
473
  <li>
474
  <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
475
- title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date('j F Y | g:i a') ); ?>">
476
  <?php echo esc_html( $item->get_title() ); ?>
477
  </a>
478
  </li>
@@ -485,26 +483,26 @@ if (apply_filters('lyte_settingsscreen_remotehttp',true)) {
485
 
486
  // based on http://wordpress.stackexchange.com/a/58826
487
  function lyte_admin_tabs(){
488
- $tabs = apply_filters('wp-youtube-lyte_filter_settingsscreen_tabs',array('lyte_settings_page' => __('Main','wp-youtube-lyte')));
489
- $tabContent="";
490
  if (count($tabs) >= 1) {
491
  if(isset($_GET['page'])){
492
  $currentId = $_GET['page'];
493
  } else {
494
- $currentId = "wp-youtube-lyte";
495
  }
496
- $tabContent .= "<h2 class=\"nav-tab-wrapper\">";
497
- foreach($tabs as $tabId => $tabName){
498
- if($currentId == $tabId){
499
- $class = " nav-tab-active";
500
  } else{
501
- $class = "";
502
  }
503
- $tabContent .= '<a class="nav-tab'.$class.'" href="?page='.$tabId.'">'.$tabName.'</a>';
504
  }
505
- $tabContent .= "</h2>";
506
  } else {
507
- $tabContent = "<hr/>";
508
  }
509
 
510
  return $tabContent;
1
  <?php
2
  if ( ! defined( 'ABSPATH' ) ) exit;
3
 
4
+ require( 'lytePartners.php');
5
 
6
+ $plugin_dir = basename( dirname( __FILE__ ) ) . '/languages';
7
  load_plugin_textdomain( 'wp-youtube-lyte', false, $plugin_dir );
8
 
9
  add_action('admin_menu', 'lyte_create_menu');
10
 
11
+ if ( get_option( 'lyte_emptycache','0') === '1') {
12
+ $emptycache = lyte_rm_cache();
13
+ update_option( 'lyte_emptycache','0' );
14
+ if ( $emptycache === 'OK' ) {
15
+ add_action( 'admin_notices', 'lyte_cacheclear_ok_notice' );
16
+ } elseif ( $emptycache === 'PART') {
17
+ add_action( 'admin_notices', 'lyte_cacheclear_part_notice' );
18
+ update_option( 'lyte_emptycache', '1' ); // to ensure cache-purging continues
19
  } else {
20
+ add_action( 'admin_notices', 'lyte_cacheclear_fail_notice' );
21
  }
22
  }
23
 
24
  function lyte_cacheclear_ok_notice() {
25
  echo '<div class="updated"><p>';
26
+ _e( 'Your WP YouTube Lyte cache has been succesfully cleared.', 'wp-youtube-lyte' );
27
  echo '</p></div>';
28
  }
29
 
30
  function lyte_cacheclear_part_notice() {
31
  echo '<div class="error"><p>';
32
+ _e( 'WP YouTube Lyte cache was partially cleared, refresh this page to continue purging.', 'wp-youtube-lyte' );
33
  echo '</p></div>';
34
  }
35
 
36
  function lyte_cacheclear_fail_notice() {
37
  echo '<div class="error"><p>';
38
+ _e( 'There was a problem, the WP YouTube Lyte cache could not be cleared.', 'wp-youtube-lyte' );
39
  echo '</p></div>';
40
  }
41
 
42
  function lyte_create_menu() {
43
  $hook=add_options_page( 'WP YouTube Lyte settings', 'WP YouTube Lyte', 'manage_options', 'lyte_settings_page', 'lyte_settings_page');
44
  add_action( 'admin_init', 'register_lyte_settings' );
45
+ add_action( 'admin_print_scripts-' . $hook, 'lyte_admin_scripts' );
46
+ add_action( 'admin_print_styles-' . $hook, 'lyte_admin_styles' );
47
  }
48
 
49
  function register_lyte_settings() {
51
  register_setting( 'lyte-settings-group', 'lyte_size' );
52
  register_setting( 'lyte-settings-group', 'lyte_hidef' );
53
  register_setting( 'lyte-settings-group', 'lyte_position' );
 
54
  register_setting( 'lyte-settings-group', 'lyte_microdata' );
55
  register_setting( 'lyte-settings-group', 'lyte_emptycache' );
56
  register_setting( 'lyte-settings-group', 'lyte_greedy' );
60
  }
61
 
62
  function lyte_admin_scripts() {
63
+ wp_enqueue_script('jqcookie', plugins_url( '/external/jquery.cookie.min.js', __FILE__) , array( 'jquery' ), null, true );
64
+ wp_enqueue_script('unslider', plugins_url( '/external/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
65
+ }
66
 
67
  function lyte_admin_styles() {
68
+ wp_enqueue_style( 'unslider', plugins_url( '/external/unslider.css', __FILE__ ) );
69
+ wp_enqueue_style( 'unslider-dots', plugins_url( '/external/unslider-dots.css', __FILE__ ) );
70
  }
71
 
72
  function lyte_admin_nag_apikey() {
73
+ echo '<div class="update-nag">';
74
+ _e( 'For WP YouTube Lyte to function optimally, you should enter an YouTube API key ', 'wp-youtube-lyte' );
75
+ echo ' <a href="options-general.php?page=lyte_settings_page">';
76
+ _e( 'in the settings screen.', 'wp-youtube-lyte' );
77
+ echo '</a>.</div>';
78
  }
79
 
80
+ $lyte_yt_api_key = get_option( 'lyte_yt_api_key', '' );
81
+ $lyte_yt_api_key = apply_filters( 'lyte_filter_yt_api_key', $lyte_yt_api_key );
82
+ if ( empty( $lyte_yt_api_key ) ) {
83
+ add_action( 'admin_notices', 'lyte_admin_nag_apikey' );
84
+ }
85
 
86
  function lyte_admin_api_error(){
87
+ $yt_error = json_decode( get_option( 'lyte_api_error' ), 1 );
88
  echo '<div class="error"><p>';
89
+ _e( 'WP YouTube Lyte got the following error back from the YouTube API: ', 'wp-youtube-lyte' );
90
+ echo '<strong>' . $yt_error['reason'] . '</strong>';
91
+ echo ' (' . date('r', $yt_error['timestamp'] ) . ').';
92
  echo '</a>.</p></div>';
93
+ update_option( 'lyte_api_error', '' );
94
  }
95
 
96
+ if ( get_option( 'lyte_api_error', '' ) !== '' ) {
97
+ add_action( 'admin_notices', 'lyte_admin_api_error' );
98
+ }
99
 
100
  function lyte_settings_page() {
101
  global $pSize, $pSizeOrder;
166
  }
167
  </style>
168
  <div class="wrap">
169
+ <h2><?php _e( 'WP YouTube Lyte Settings', 'wp-youtube-lyte' ); ?></h2>
170
  <div style="float:left;width:70%;">
171
  <?php echo lyte_admin_tabs(); ?>
172
  <form method="post" action="options.php">
173
  <?php settings_fields( 'lyte-settings-group' ); ?>
174
  <table class="form-table">
 
175
  <tr valign="top">
176
+ <th scope="row"><?php _e( 'Your YouTube API key.', 'wp-youtube-lyte' ); ?></th>
177
  <td>
178
  <?php // only show api key input field if there's no result from filter
179
+ $filter_key = apply_filters( 'lyte_filter_yt_api_key', '' );
180
+ if ( empty( $filter_key ) ) { ?>
181
  <fieldset>
182
+ <legend class="screen-reader-text"><span><?php _e( 'Please enter your YouTube API key.', 'wp-youtube-lyte' ); ?></span></legend>
183
+ <label title="<?php _e( 'API key', 'wp-youtube-lyte' ); ?>"><input type="text" size="28" name="lyte_yt_api_key" id="lyte_yt_api_key" value="<?php echo esc_attr( wp_strip_all_tags( get_option( 'lyte_yt_api_key', '' ) ) ); ?>"><span id="check_api_key" class="submit button-secondary" style="margin:0px 5px;"><?php _e( 'Test Key' ); ?></span></label><br />
184
  <div id="lyte_key_check_output" style="display:none;margin-bottom:5px;background-color:white;border-left:solid;border-width:4px;border-color:#2ea2cc;padding:5px 5px 5px 15px;"></div>
185
+ <?php _e( "WP YouTube Lyte uses YouTube's API to fetch information on each video. For your site to use that API, you will have to <a href=\"https://console.developers.google.com/project/\" target=\"_blank\">register your site as a new application</a>, enable the YouTube API for it and get a server key and fill it out here.", 'wp-youtube-lyte' ); ?>
186
  </fieldset>
187
  <?php } else { ?>
188
+ <?php _e( 'Great, your YouTube API key has been taken care of!', 'wp-youtube-lyte' ); ?>
189
  <?php } ?>
190
  </td>
191
  </tr>
192
  <tr valign="top">
193
+ <th scope="row"><?php _e( 'Player size', 'wp-youtube-lyte' ); ?>:</th>
194
  <td>
195
+ <fieldset><legend class="screen-reader-text"><span><?php _e( 'Player size', 'wp-youtube-lyte' ); ?></span></legend>
196
  <?php
197
+ $sel = ! is_bool( get_option( 'lyte_size' ) ) ? (int) get_option( 'lyte_size' ) : 0;
198
+ foreach ( array ( '169', '43' ) as $f ) {
199
+ foreach ( $pSizeOrder[$f] as $i ) {
200
+ $pS = $pSize[$i];
201
+ if ( $pS['a'] === true ) {
202
  ?>
203
+ <label title="<?php echo $pS['w'] . 'X' . $pS['h']; ?>"><input type="radio" name="lyte_size" class="l_size" value="<?php echo $i . '"'; if ( $i===$sel ) echo ' checked'; echo ' /> ' . $pS['w'] . 'X' . $pS['h'] . ' (' . $pS['t'] ;?>)</label><br />
204
  <?php
205
  }
206
  }
211
  </td>
212
  </tr>
213
  <tr valign="top">
214
+ <th scope="row"><?php _e( 'Add links below the embedded videos?', 'wp-youtube-lyte' ); ?></th>
215
  <td>
216
  <fieldset>
217
+ <legend class="screen-reader-text"><span><?php _e( 'Show links?', 'wp-youtube-lyte' ) ?></span></legend>
218
+ <label title="<?php _e( 'Show YouTube-link', 'wp-youtube-lyte' );?>"><input type="radio" name="lyte_show_links" value="1" <?php if ( get_option( 'lyte_show_links') === '1' || get_option( 'lyte_show_links') === '2' ) echo 'checked' ?> /><?php _e( ' Add YouTube-link.', 'wp-youtube-lyte') ?></label><br />
219
+ <label title="<?php _e( 'Don\'t include links.', 'wp-youtube-lyte' );?>"><input type="radio" name="lyte_show_links" value="0" <?php if ( ( get_option( 'lyte_show_links' ) !== '1' ) && ( get_option( 'lyte_show_links')!=="2")) echo 'checked' ?> /><?php _e( ' Don\'t add any links.', 'wp-youtube-lyte' ); ?></label>
220
  </fieldset>
221
  </td>
222
  </tr>
223
  <tr valign="top">
224
+ <th scope="row"><?php _e( 'Player position:', 'wp-youtube-lyte' ); ?></th>
225
  <td>
226
  <fieldset>
227
+ <legend class="screen-reader-text"><span><?php _e( 'Left, center or right?', 'wp-youtube-lyte' ); ?></span></legend>
228
+ <label title="<?php _e( 'Left', 'wp-youtube-lyte' );?>"><input type="radio" name="lyte_position" value="0" <?php if ( get_option( 'lyte_position', '0' ) === '0') echo 'checked' ?> /><?php _e( 'Left', 'wp-youtube-lyte' ); ?></label><br />
229
+ <label title="<?php _e( 'Center', 'wp-youtube-lyte' );?>"><input type="radio" name="lyte_position" value="1" <?php if ( get_option( 'lyte_position', '0' ) === '1') echo 'checked' ?> /><?php _e( 'Center', 'wp-youtube-lyte' ); ?></label>
230
  </fieldset>
231
  </td>
232
  </tr>
233
  <tr valign="top">
234
+ <th scope="row"><?php _e( 'Try to force HD?', 'wp-youtube-lyte' ); ?></th>
235
  <td>
236
  <fieldset>
237
+ <legend class="screen-reader-text"><span><?php _e( 'HD or not?', 'wp-youtube-lyte' ); ?></span></legend>
238
+ <label title="<?php _e( 'Enable HD?', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_hidef" value="1" <?php if ( get_option( 'lyte_hidef','0') === '1') echo 'checked' ?> /><?php _e( 'Enable HD', 'wp-youtube-lyte' ); ?></label><br />
239
+ <label title="<?php _e( 'Don\'t enable HD playback', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_hidef" value="0" <?php if ( get_option( 'lyte_hidef','0') !== '1' ) echo 'checked' ?> /><?php _e( 'No HD (default)', 'wp-youtube-lyte' ); ?></label>
240
  </fieldset>
241
  </td>
242
  </tr>
243
  <tr valign="top">
244
+ <th scope="row"><?php _e( 'Add microdata?', 'wp-youtube-lyte' ); ?></th>
245
  <td>
246
  <fieldset>
247
+ <legend class="screen-reader-text"><span><?php _e( 'Add video microdata to the HTML?', 'wp-youtube-lyte' ); ?></span></legend>
248
+ <label title="<?php _e( 'Sure, add microdata!', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_microdata" value="1" <?php if ( get_option( 'lyte_microdata', '1' ) === '1') echo 'checked' ?> /><?php _e( 'Yes (default)', 'wp-youtube-lyte' ); ?></label><br />
249
+ <label title="<?php _e( 'No microdata in my HTML please.', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_microdata" value="0" <?php if ( get_option( 'lyte_microdata', '1' ) !== '1' ) echo 'checked' ?> /><?php _e( 'No microdata, thanks.', 'wp-youtube-lyte' ); ?></label>
250
  </fieldset>
251
  </td>
252
  </tr>
253
  <tr valign="top">
254
+ <th scope="row"><?php _e( 'Also act on normal YouTube links and iframes?', 'wp-youtube-lyte' ); ?></th>
255
  <td>
256
  <fieldset>
257
+ <legend class="screen-reader-text"><span><?php _e( 'Also act on normal YouTube links?', 'wp-youtube-lyte' ); ?></span></legend>
258
+ <label title="<?php _e( 'That would be great!', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_greedy" value="1" <?php if ( get_option( 'lyte_greedy', '1' ) === '1') echo 'checked' ?> /><?php _e( 'Yes (default)', 'wp-youtube-lyte' ); ?></label><br />
259
+ <label title="<?php _e( 'No, I\'ll stick to httpv or shortcodes.', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_greedy" value="0" <?php if ( get_option( 'lyte_greedy', '1' ) !== '1' ) echo 'checked' ?> /><?php _e( 'No thanks.', 'wp-youtube-lyte' ); ?></label>
260
  </fieldset>
261
  </td>
262
  </tr>
263
  <tr valign="top">
264
+ <th scope="row"><?php _e( 'Cache thumbnails locally?', 'wp-youtube-lyte' ); ?></th>
265
  <td>
266
  <fieldset>
267
+ <legend class="screen-reader-text"><span><?php _e( 'Cache thumbnails locally?', 'wp-youtube-lyte' ); ?></span></legend>
268
+ <label title="<?php _e( 'That would be great!', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_local_thumb" value="1" <?php if ( get_option( 'lyte_local_thumb','0') === '1') echo 'checked' ?> /><?php _e( 'Yes.', 'wp-youtube-lyte' ); ?></label><br />
269
+ <label title="<?php _e( 'No, keep on using YouTube hosted thumbnails.', 'wp-youtube-lyte' ); ?>"><input type="radio" name="lyte_local_thumb" value="0" <?php if ( get_option( 'lyte_local_thumb','0') !== '1' ) echo 'checked' ?> /><?php _e( 'No (default).', 'wp-youtube-lyte' ); ?></label>
270
  <br />
271
+ <?php _e( 'Having the thumbnails cached locally can improve performance and will enhance visitor privacy as by default no requests will be sent to YouTube unless the video is played.', 'wp-youtube-lyte' ); ?>
272
  </fieldset>
273
  </td>
274
  </tr>
275
  <tr valign="top">
276
+ <th scope="row"><?php _e( 'Text to be added under every LYTE video.', 'wp-youtube-lyte' ); ?></th>
277
  <td>
278
  <fieldset>
279
+ <legend class="screen-reader-text"><span><?php _e( 'Text (e.g. for disclaimer) to be added under every LYTE video.', 'wp-youtube-lyte' ); ?></span></legend>
280
+ <input type="text" style="width:100%;" name="lyte_disclaimer" placeholder="" value="<?php echo esc_textarea( get_option( 'lyte_disclaimer', '' ) ); ?>" /><br />
281
  <br />
282
+ <?php _e( 'If you want to add e.g. a privacy disclaimer under every LYTE embedded video, you can do so here. Some HTML is allowed. Simply leave empty not to show anything.', 'wp-youtube-lyte' ); ?>
283
  </fieldset>
284
  </td>
285
  </tr>
286
  <tr valign="top">
287
+ <th scope="row"><?php _e( 'Empty WP YouTube Lyte\'s cache', 'wp-youtube-lyte' ); ?></th>
288
  <td>
289
  <fieldset>
290
  <legend class="screen-reader-text"><span>Remove WP YouTube Lyte's cache</span></legend>
295
  </table>
296
 
297
  <p class="submit">
298
+ <input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ) ?>" />
299
  </p>
300
 
301
  </form>
304
  <div class="lyte_banner ">
305
  <ul>
306
  <?php
307
+ if ( apply_filters('wp-youtube-lyte_settingsscreen_remotehttp', true ) ) {
308
+ $lyte_banner = get_transient( 'wp-youtube-lyte_banner' );
309
+ if ( empty( $lyte_banner ) ) {
310
+ $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/wp-youtube-lyte_news.html');
311
+ if ( ! is_wp_error( $banner_resp ) ) {
312
+ if ( wp_remote_retrieve_response_code( $banner_resp ) == '200' ) {
313
+ $lyte_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
314
+ set_transient( 'wp-youtube-lyte_banner', $lyte_banner, DAY_IN_SECONDS );
315
  }
316
  }
317
  }
318
  echo $lyte_banner;
319
  }
320
  ?>
321
+ <li><?php _e( 'Need help? <a href="https://wordpress.org/plugins/wp-youtube-lyte/faq/">Check out the FAQ here</a>.', 'wp-youtube-lyte' ); ?></li>
322
+ <li><?php _e( 'Happy with wp-youtube-lyte?', 'wp-youtube-lyte' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'wp-youtube-lyte' ); ?></a></li>
323
  </ul>
324
  </div>
325
  <div style="margin-left:10px;margin-top:-5px;">
326
  <h2>
327
+ <?php _e( 'futtta about', 'wp-youtube-lyte' ); ?>
328
  <select id="feed_dropdown" >
329
+ <option value="1"><?php _e( 'WP YouTube Lyte', 'wp-youtube-lyte' ); ?></option>
330
+ <option value="2"><?php _e( 'WordPress', 'wp-youtube-lyte' ); ?></option>
331
+ <option value="3"><?php _e( 'Web Technology', 'wp-youtube-lyte' ); ?></option>
332
  </select>
333
  </h2>
334
  <div id="futtta_feed">
335
  <div id="wp-youtube-lytefeed">
336
+ <?php getFutttaFeeds( 'https://feeds.feedburner.com/futtta_wp-youtube-lyte' ); ?>
337
  </div>
338
  <div id="wordpressfeed">
339
+ <?php getFutttaFeeds( 'https://feeds.feedburner.com/futtta_wordpress' ); ?>
340
  </div>
341
  <div id="webtechfeed">
342
+ <?php getFutttaFeeds( 'https://feeds.feedburner.com/futtta_webtech'); ?>
343
  </div>
344
  </div>
345
  </div>
346
+ <div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'wp-youtube-lyte' ); ?>"></a></div>
347
  </div>
348
 
349
  <script type="text/javascript">
356
  jQuery(document).ready(function() {
357
  jQuery( "#check_api_key" ).click(function() {
358
  jQuery("#lyte_key_check_output").show();
359
+ jQuery("#lyte_key_check_output").append("<p><?php _e( 'Checking your key ...'); ?></p>");
360
  lyte_yt_api_key=jQuery("input#lyte_yt_api_key").val();
361
  if ((lyte_yt_api_key.length>9) &&(lyte_yt_api_key.length<99)) {
362
  var data = {
368
  jQuery("#lyte_key_check_output").append('<p>'+response+'</p>');
369
  });
370
  } else {
371
+ jQuery("#lyte_key_check_output").append('<p><?php _e( "That does not seem to be a correct API key!"); ?></p>');
372
  }
373
  })
374
  jQuery('#lyte_admin_feed').fadeTo("slow",1).show();
399
  // ajax receiver for YT API key check
400
  add_action( 'wp_ajax_lyte_check_yt_api_key', 'lyte_check_yt_api_key_callback' );
401
  function lyte_check_yt_api_key_callback() {
402
+ check_ajax_referer( 'lyte_check_api_key', 'lyte_nonce' );
403
+ $api_key = strip_tags( $_POST['lyte_yt_api_key'] );
404
 
405
  // use random video to make sure a cache is not spoiling things
406
+ $vidToCheck = array('ZmnZHudtzXg', '2_7oQcAkyl8', 'nOvv80wkSgI', 'pBCt5nfsZ30', 'KHw7gdJ14uQ', 'qJ_PMvjmC6M', 'DVwHCGAr_OE', 'LtOGa5M8AuU', 'VHO9uZX9FNU' );
407
+ $randVidIndex = array_rand( $vidToCheck );
408
 
409
+ $api_response = lyte_get_YT_resp( $vidToCheck[$randVidIndex], false, '', $api_key );
410
 
411
+ if ( is_array( $api_response ) ) {
412
+ if ( ! empty( $api_response['title'] ) ) {
413
+ _e( 'API seems OK, you can Save Changes below now.', 'wp-youtube-lyte' );
414
+ } else if ( ! empty($api_response['reason'] ) ) {
415
+ $all_but_one = __( 'API key not OK, your key seems to ', 'wp-youtube-lyte' );
416
+ switch ( $api_response['reason'] ) {
417
+ case 'keyInvalid':
418
  echo $all_but_one;
419
+ _e( 'be invalid.', 'wp-youtube-lyte' );
420
  break;
421
+ case 'ipRefererBlocked':
422
  echo $all_but_one;
423
+ _e( 'be valid, but restricted to an IP-address which is not your server\'s.', 'wp-youtube-lyte' );
424
+ _e( 'Try changing the allowed IP for your API key to include this one: ', 'wp-youtube-lyte' );
425
  echo $_SERVER["SERVER_ADDR"];
426
  break;
427
+ case 'keyExpired':
428
  echo $all_but_one;
429
+ _e( 'have expired, please check in the Google Developer Console.', 'wp-youtube-lyte' );
430
  break;
431
+ case 'limitExceeded':
432
+ case 'quotaExceeded':
433
+ case 'rateLimitExceeded':
434
+ case 'userRateLimitExceeded':
435
  echo $all_but_one;
436
+ _e( 'be correct, but seems to have exceeded the number of requests that can be made with it.', 'wp-youtube-lyte' );
437
  break;
438
+ case 'videoNotFound':
439
  echo $all_but_one;
440
+ _e( 'probably work, but as the video with id ', 'wp-youtube-lyte' );
441
  echo $vidToCheck[$randVidIndex];
442
+ _e( ' was not found we cannot be sure, please try again.', 'wp-youtube-lyte' );
443
  break;
444
  default:
445
+ _e( 'Your API key might be OK, but the API call did not succeed or the response was not entirely expected. Technical error: ', 'wp-youtube-lyte' );
446
+ echo $api_response['reason'];
447
  }
448
  }
449
  } else {
450
+ _e( 'Something went wrong, WP YouTube Lyte might not have been able to retrieve information from the YouTube API, got error: ', 'wp-youtube-lyte' );
451
+ print_r( $api_response );
452
  }
453
  wp_die();
454
  }
455
 
456
  function getFutttaFeeds($url) {
457
+ if ( apply_filters( 'lyte_settingsscreen_remotehttp', true ) ) {
458
  $rss = fetch_feed( $url );
459
  $maxitems = 0;
460
 
461
  if ( ! is_wp_error( $rss ) ) {
462
+ $maxitems = $rss->get_item_quantity( 7 );
463
  $rss_items = $rss->get_items( 0, $maxitems );
464
  }
465
  ?>
466
  <ul>
467
  <?php if ( $maxitems == 0 ) : ?>
468
+ <li><?php _e( 'No items', 'wp-youtube-lyte' ); ?></li>
469
  <?php else : ?>
470
  <?php foreach ( $rss_items as $item ) : ?>
471
  <li>
472
  <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
473
+ title="<?php printf( __( 'Posted %s', 'wp-youtube-lyte' ), $item->get_date('j F Y | g:i a') ); ?>">
474
  <?php echo esc_html( $item->get_title() ); ?>
475
  </a>
476
  </li>
483
 
484
  // based on http://wordpress.stackexchange.com/a/58826
485
  function lyte_admin_tabs(){
486
+ $tabs = apply_filters( 'wp-youtube-lyte_filter_settingsscreen_tabs', array( 'lyte_settings_page' => __('Main', 'wp-youtube-lyte' ) ) );
487
+ $tabContent = '';
488
  if (count($tabs) >= 1) {
489
  if(isset($_GET['page'])){
490
  $currentId = $_GET['page'];
491
  } else {
492
+ $currentId = 'wp-youtube-lyte';
493
  }
494
+ $tabContent .= '<h2 class="nav-tab-wrapper">';
495
+ foreach( $tabs as $tabId => $tabName ){
496
+ if( $currentId == $tabId ) {
497
+ $class = ' nav-tab-active';
498
  } else{
499
+ $class = '';
500
  }
501
+ $tabContent .= '<a class="nav-tab'.$class.'" href="?page='.$tabId.'">' . $tabName . '</a>';
502
  }
503
+ $tabContent .= '</h2>';
504
  } else {
505
+ $tabContent = '<hr/>';
506
  }
507
 
508
  return $tabContent;
player_sizes.inc.php CHANGED
@@ -1,99 +1,99 @@
1
  <?php
2
 
3
- $plugin_dir = basename(dirname(__FILE__)).'/languages';
4
  load_plugin_textdomain( 'wp-youtube-lyte', false, $plugin_dir );
5
 
6
  $pDefault=2;
7
 
8
- $pSize[8]['a']=true;
9
- $pSize[8]['w']=420;
10
- $pSize[8]['h']=236;
11
- $pSize[8]['t']=__("Mini 16:9 player","wp-youtube-lyte");
12
- $pSize[8]['f']="169";
13
 
14
- $pSize[0]['a']=true;
15
- $pSize[0]['w']=420;
16
- $pSize[0]['h']=315;
17
- $pSize[0]['t']=__("Smaller 4:3 player","wp-youtube-lyte");
18
- $pSize[0]['f']="43";
19
 
20
- $pSize[1]['a']=true;
21
- $pSize[1]['w']=560;
22
- $pSize[1]['h']=315;
23
- $pSize[1]['t']=__("Smaller 16:9 player","wp-youtube-lyte");
24
- $pSize[1]['f']="169";
25
 
26
- $pSize[2]['a']=true;
27
- $pSize[2]['w']=480;
28
- $pSize[2]['h']=360;
29
- $pSize[2]['t']=__("Standard value, YouTube default for 4:3-ratio video","wp-youtube-lyte");
30
- $pSize[2]['f']="43";
31
 
32
- $pSize[3]['a']=true;
33
- $pSize[3]['w']=640;
34
- $pSize[3]['h']=360;
35
- $pSize[3]['t']=__("YouTube default for 16:9-ratio video","wp-youtube-lyte");
36
- $pSize[3]['f']="169";
37
 
38
- $pSize[4]['a']=true;
39
- $pSize[4]['w']=640;
40
- $pSize[4]['h']=480;
41
- $pSize[4]['t']=__("Larger 4:3 player","wp-youtube-lyte");
42
- $pSize[4]['f']="43";
43
 
44
- $pSize[5]['a']=true;
45
- $pSize[5]['w']=853;
46
- $pSize[5]['h']=480;
47
- $pSize[5]['t']=__("Larger 16:9 player","wp-youtube-lyte");
48
- $pSize[5]['f']="169";
49
 
50
- $pSize[6]['a']=true;
51
- $pSize[6]['w']=960;
52
- $pSize[6]['h']=720;
53
- $pSize[6]['t']=__("Maxi 4:3 player","wp-youtube-lyte");
54
- $pSize[6]['f']="43";
55
 
56
- $pSize[7]['a']=true;
57
- $pSize[7]['w']=1280;
58
- $pSize[7]['h']=720;
59
- $pSize[7]['t']=__("Maxi 16:9 player","wp-youtube-lyte");
60
- $pSize[7]['f']="169";
61
 
62
- $pSizeOrder['169']=array(8,1,3,5,7);
63
- $pSizeOrder['43']=array(0,2,4,6);
64
 
65
  // widget sizes
66
  $wDefault=4;
67
- $wSize[1]['h']=125;
68
- $wSize[1]['w']=150;
69
- $wSize[1]['depr']=true;
70
- $wSize[2]['h']=133;
71
- $wSize[2]['w']=160;
72
- $wSize[2]['depr']=true;
73
- $wSize[3]['h']=150;
74
- $wSize[3]['w']=180;
75
- $wSize[3]['depr']=true;
76
- $wSize[4]['h']=200;
77
- $wSize[4]['w']=200;
78
- $wSize[4]['depr']=false;
79
- $wSize[5]['h']=200;
80
- $wSize[5]['w']=250;
81
- $wSize[5]['depr']=false;
82
- $wSize[6]['h']=225;
83
- $wSize[6]['w']=300;
84
- $wSize[6]['depr']=false;
85
- $wSize[7]['h']=300;
86
- $wSize[7]['w']=400;
87
- $wSize[7]['depr']=false;
88
 
89
  // bigger widgets, for use in pagebuilders rather then sidebars
90
- $wSize[8]['h']=400;
91
- $wSize[8]['w']=711;
92
- $wSize[8]['depr']=false;
93
- $wSize[9]['h']=500;
94
- $wSize[9]['w']=889;
95
- $wSize[9]['depr']=false;
96
- $wSize[10]['h']=600;
97
- $wSize[10]['w']=1066;
98
- $wSize[10]['depr']=false;
99
  ?>
1
  <?php
2
 
3
+ $plugin_dir = basename( dirname( __FILE__ ) ) . '/languages';
4
  load_plugin_textdomain( 'wp-youtube-lyte', false, $plugin_dir );
5
 
6
  $pDefault=2;
7
 
8
+ $pSize[8]['a'] = true;
9
+ $pSize[8]['w'] = 420;
10
+ $pSize[8]['h'] = 236;
11
+ $pSize[8]['t'] = __( 'Mini 16:9 player', 'wp-youtube-lyte' );
12
+ $pSize[8]['f'] = "169";
13
 
14
+ $pSize[0]['a'] = true;
15
+ $pSize[0]['w'] = 420;
16
+ $pSize[0]['h'] = 315;
17
+ $pSize[0]['t'] = __( 'Smaller 4:3 player', 'wp-youtube-lyte' );
18
+ $pSize[0]['f'] = "43";
19
 
20
+ $pSize[1]['a'] = true;
21
+ $pSize[1]['w'] = 560;
22
+ $pSize[1]['h'] = 315;
23
+ $pSize[1]['t'] = __( 'Smaller 16:9 player', 'wp-youtube-lyte' );
24
+ $pSize[1]['f'] = "169";
25
 
26
+ $pSize[2]['a'] = true;
27
+ $pSize[2]['w'] = 480;
28
+ $pSize[2]['h'] = 360;
29
+ $pSize[2]['t'] = __( 'Standard value, YouTube default for 4:3-ratio video', 'wp-youtube-lyte' );
30
+ $pSize[2]['f'] = "43";
31
 
32
+ $pSize[3]['a'] = true;
33
+ $pSize[3]['w'] = 640;
34
+ $pSize[3]['h'] = 360;
35
+ $pSize[3]['t'] = __( 'YouTube default for 16:9-ratio video', 'wp-youtube-lyte' );
36
+ $pSize[3]['f'] = "169";
37
 
38
+ $pSize[4]['a'] = true;
39
+ $pSize[4]['w'] = 640;
40
+ $pSize[4]['h'] = 480;
41
+ $pSize[4]['t'] = __( 'Larger 4:3 player', 'wp-youtube-lyte' );
42
+ $pSize[4]['f'] = "43";
43
 
44
+ $pSize[5]['a'] = true;
45
+ $pSize[5]['w'] = 853;
46
+ $pSize[5]['h'] = 480;
47
+ $pSize[5]['t'] = __( 'Larger 16:9 player', 'wp-youtube-lyte' );
48
+ $pSize[5]['f'] = "169";
49
 
50
+ $pSize[6]['a'] = true;
51
+ $pSize[6]['w'] = 960;
52
+ $pSize[6]['h'] = 720;
53
+ $pSize[6]['t'] = __( 'Maxi 4:3 player', 'wp-youtube-lyte' );
54
+ $pSize[6]['f'] = "43";
55
 
56
+ $pSize[7]['a'] = true;
57
+ $pSize[7]['w'] = 1280;
58
+ $pSize[7]['h'] = 720;
59
+ $pSize[7]['t'] = __( 'Maxi 16:9 player', 'wp-youtube-lyte' );
60
+ $pSize[7]['f'] = "169";
61
 
62
+ $pSizeOrder['169'] = array( 8, 1, 3, 5, 7 );
63
+ $pSizeOrder['43'] = array( 0, 2, 4, 6 );
64
 
65
  // widget sizes
66
  $wDefault=4;
67
+ $wSize[1]['h'] = 125;
68
+ $wSize[1]['w'] = 150;
69
+ $wSize[1]['depr'] = true;
70
+ $wSize[2]['h'] = 133;
71
+ $wSize[2]['w'] = 160;
72
+ $wSize[2]['depr'] = true;
73
+ $wSize[3]['h'] = 150;
74
+ $wSize[3]['w'] = 180;
75
+ $wSize[3]['depr'] = true;
76
+ $wSize[4]['h'] = 200;
77
+ $wSize[4]['w'] = 200;
78
+ $wSize[4]['depr'] = false;
79
+ $wSize[5]['h'] = 200;
80
+ $wSize[5]['w'] = 250;
81
+ $wSize[5]['depr'] = false;
82
+ $wSize[6]['h'] = 225;
83
+ $wSize[6]['w'] = 300;
84
+ $wSize[6]['depr'] = false;
85
+ $wSize[7]['h'] = 300;
86
+ $wSize[7]['w'] = 400;
87
+ $wSize[7]['depr'] = false;
88
 
89
  // bigger widgets, for use in pagebuilders rather then sidebars
90
+ $wSize[8]['h'] = 400;
91
+ $wSize[8]['w'] = 711;
92
+ $wSize[8]['depr'] = false;
93
+ $wSize[9]['h'] = 500;
94
+ $wSize[9]['w'] = 889;
95
+ $wSize[9]['depr'] = false;
96
+ $wSize[10]['h'] = 600;
97
+ $wSize[10]['w'] = 1066;
98
+ $wSize[10]['depr'] = false;
99
  ?>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: youtube, video, performance, gdpr, lazy load
4
  Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
5
  Requires at least: 4.0
6
  Tested up to: 5.7
7
- Stable tag: 1.7.15
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
@@ -67,6 +67,9 @@ An API is a way to have two pieces of software talk to each other to exchange in
67
 
68
  5. Copy your API key to WP YouTube Lyte settings page.
69
 
 
 
 
70
  = Will WP YouTube Lyte work if I don't provide an API key? =
71
  Yes, with some exceptions; WP YouTube Lyte will continue to work, rendering Lyte players, but without the title and microdata (description, time, ...) and without thumbnails for playlists.
72
 
@@ -140,6 +143,13 @@ Just tell me, I like the feedback! Use the [Contact-page on my blog](http://blog
140
 
141
  == Changelog ==
142
 
 
 
 
 
 
 
 
143
  = 1.7.15 =
144
  * To avoid YouTube cutting API access because no requests were made for 3 months, LYTE now by default caches the YouTube data for 2 months, after which it is refreshed. Previously cached data only refreshed if the cache got cleared manually.
145
 
4
  Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
5
  Requires at least: 4.0
6
  Tested up to: 5.7
7
+ Stable tag: 1.7.16
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
67
 
68
  5. Copy your API key to WP YouTube Lyte settings page.
69
 
70
+ = I'm getting "technical errors" when validating my YouTube API key =
71
+ In certain cases when adding restrictions the API key when tested might give technical warnings even if things are working correctly, make sure to check if new video’s are having the title displayed to confirm all is well.
72
+
73
  = Will WP YouTube Lyte work if I don't provide an API key? =
74
  Yes, with some exceptions; WP YouTube Lyte will continue to work, rendering Lyte players, but without the title and microdata (description, time, ...) and without thumbnails for playlists.
75
 
143
 
144
  == Changelog ==
145
 
146
+ = 1.7.16 =
147
+ * removed old captions code (captions are not natively supported through the YouTube API + the Benetech backend was no longer working)
148
+ * added extra sanitization, thanks m0ze!
149
+ * optionally disable thumbnail fallback to youtube servers (contributed by Benjamin Pick)
150
+ * general code cleanup (spaces, double -> single quotes around strings, ...)
151
+ * misc. smaller fixes/ improvements, see [Github commits](https://github.com/futtta/wp-youtube-lyte/commits/main) for details.
152
+
153
  = 1.7.15 =
154
  * To avoid YouTube cutting API access because no requests were made for 3 months, LYTE now by default caches the YouTube data for 2 months, after which it is refreshed. Previously cached data only refreshed if the cache got cleared manually.
155
 
widget.php CHANGED
@@ -8,66 +8,66 @@ class WYLWidget extends WP_Widget {
8
  extract( $args );
9
  global $wSize, $wyl_version, $wp_lyte_plugin_url, $lyteSettings;
10
  $lyteSettings['path']= plugins_url() . "/" . dirname(plugin_basename(__FILE__)) . '/lyte/';
11
- $qsa="";
12
 
13
- $WYLtitle = apply_filters('widget_title', $instance['WYLtitle']);
14
- $WYLtext = apply_filters( 'widget_text', $instance['WYLtext'], $instance );
15
- $WYLsize = apply_filters( 'widget_text', $instance['WYLsize'], $instance );
16
- if ($WYLsize=="") $WYLsize=$wDefault;
17
  $WYLaudio = apply_filters( 'widget_text', $instance['WYLaudio'], $instance );
18
- if ($WYLaudio!=="audio") {
19
- $wrapperClass = " lidget";
20
- $audioClass = "";
21
- $wHeight = $wSize[$WYLsize]['h'];
22
  } else {
23
- $wrapperClass = "-audio lidget";
24
- $audioClass = " lyte-audio";
25
- $wHeight = "38";
26
  }
27
- $WYLurl=str_replace("httpv://","https://",trim($instance['WYLurl']));
28
- $WYLqs=substr(strstr($WYLurl,'?'),1);
29
- parse_str($WYLqs,$WYLarr);
30
-
31
- if (strpos($WYLurl,'youtu.be')) {
32
- $WYLid=substr(parse_url($WYLurl,PHP_URL_PATH),1,11);
33
- $PLClass="";
34
- $WYLthumb="https://img.youtube.com/vi/".$WYLid."/hqdefault.jpg";
35
  } else {
36
- if (isset($WYLarr['v'])) {
37
- $WYLid=$WYLarr['v'];
38
- $PLClass="";
39
- $WYLthumb="https://img.youtube.com/vi/".$WYLid."/hqdefault.jpg";
40
- } else if (isset($WYLarr['list'])) {
41
- $WYLid=$WYLarr['list'];
42
- $yt_resp=lyte_get_YT_resp($WYLid,true,"","",true);
43
- $WYLthumb=$yt_resp["thumbUrl"];
44
- $PLClass=" playlist";
45
  }
46
  }
47
 
48
  // do we have to serve the thumbnail from local cache?
49
- if (get_option('lyte_local_thumb','0') === '1') {
50
- $WYLthumb = plugins_url( 'lyteCache.php?origThumbUrl=' . urlencode($WYLthumb) , __FILE__ );
51
  }
52
 
53
  // filter to alter the thumbnail
54
- $WYLthumb = apply_filters( "lyte_filter_widget_thumb", $WYLthumb, $WYLid );
55
 
56
- if (isset($WYLarr['start'])) $qsa="&amp;start=".$WYLarr['start'];
57
- if (isset($WYLarr['enablejsapi'])) {
58
- $urlArr=parse_url($lyteSettings['path']);
59
- $origin=$urlArr[scheme]."://".$urlArr[host];
60
- $qsa.="&amp;enablejsapi=".$WYLarr['enablejsapi']."&amp;origin=".$origin;
61
  }
62
 
63
- if (!empty($qsa)) {
64
- $esc_arr=array("&" => "\&", "?" => "\?", "=" => "\=");
65
- $qsaClass=" qsa_".strtr($qsa,$esc_arr);
66
  } else {
67
- $qsaClass="";
68
  }
69
 
70
- $WYL_dom_id="YLW_".$WYLid;
71
 
72
  ?>
73
  <?php echo $before_widget; ?>
@@ -81,15 +81,15 @@ class WYLWidget extends WP_Widget {
81
 
82
  function update($new_instance, $old_instance) {
83
  $instance = $old_instance;
84
- $instance['WYLtitle'] = strip_tags($new_instance['WYLtitle']);
85
- $instance['WYLurl'] = strip_tags($new_instance['WYLurl']);
86
- $instance['WYLsize'] = strip_tags($new_instance['WYLsize']);
87
- $instance['WYLaudio'] = strip_tags($new_instance['WYLaudio']);
88
 
89
  if ( current_user_can('unfiltered_html') ) {
90
  $instance['WYLtext'] = $new_instance['WYLtext'];
91
  } else {
92
- $instance['WYLtext'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['WYLtext']) ) );
93
  }
94
 
95
  return $instance;
@@ -98,81 +98,81 @@ class WYLWidget extends WP_Widget {
98
  function form($instance) {
99
  global $wSize, $wDefault;
100
 
101
- if (isset($instance['WYLtitle'])) {
102
- $WYLtitle = esc_attr($instance['WYLtitle']);
103
  } else {
104
- $WYLtitle = "";
105
  }
106
 
107
- if (isset($instance['WYLurl'])) {
108
- $WYLurl = esc_attr($instance['WYLurl']);
109
  } else {
110
- $WYLurl = "";
111
  }
112
 
113
- if (isset($instance['WYLtext'])) {
114
- $WYLtext = format_to_edit($instance['WYLtext']);
115
  } else {
116
- $WYLtext = "";
117
  }
118
 
119
- if (isset($instance['WYLaudio'])) {
120
- $WYLaudio = esc_attr($instance['WYLaudio']);
121
  } else {
122
- $WYLaudio = "";
123
  }
124
  if ($WYLaudio!=="audio") $WYLaudio="";
125
 
126
- if (isset($instance['WYLsize'])) {
127
- $WYLsize = esc_attr($instance['WYLsize']);
128
  } else {
129
- $WYLsize = "";
130
  }
131
 
132
- if ($WYLsize=="") $WYLsize=$wDefault;
133
  ?>
134
- <p><label for="<?php echo $this->get_field_id('WYLtitle'); ?>"><?php _e("Title:","wp-youtube-lyte") ?> <input class="widefat" id="<?php echo $this->get_field_id('WYLtitle'); ?>" name="<?php echo $this->get_field_name('WYLtitle'); ?>" type="text" value="<?php echo $WYLtitle; ?>" /></label></p>
135
- <p><label for="<?php echo $this->get_field_id('WYLsize'); ?>"><?php _e("Size:","wp-youtube-lyte") ?>
136
- <select class="widefat" id="<?php echo $this->get_field_id('WYLsize'); ?>" name="<?php echo $this->get_field_name('WYLsize'); ?>">
137
  <?php
138
- foreach ($wSize as $x => $size) {
139
- if ($x==$WYLsize) {
140
- $selected=" selected=\"true\"";
141
  } else {
142
- $selected="";
143
  }
144
 
145
- if ($wSize[$x]['depr']!==true) {
146
- echo "<option value=\"".$x."\"".$selected.">".$wSize[$x]['w']."X".$wSize[$x]['h']."</option>";
147
  }
148
  $x++;
149
  }
150
  ?>
151
  </select>
152
  </label></p>
153
- <p><label for="<?php echo $this->get_field_id('WYLaudio'); ?>"><?php _e("Type:","wp-youtube-lyte") ?>
154
- <select class="widefat" id="<?php echo $this->get_field_id('WYLaudio'); ?>" name="<?php echo $this->get_field_name('WYLaudio'); ?>">
155
  <?php
156
- if($WYLaudio==="audio") {
157
- $aselected=" selected=\"true\"";
158
- $vselected="";
159
  } else {
160
- $vselected=" selected=\"true\"";
161
- $aselected="";
162
  }
163
- echo "<option value=\"audio\"".$aselected.">".__("audio","wp-youtube-lyte")."</option>";
164
- echo "<option value=\"video\"".$vselected.">".__("video","wp-youtube-lyte")."</option>";
165
  ?>
166
  </select>
167
  </label></p>
168
- <p><label for="<?php echo $this->get_field_id('WYLurl'); ?>"><?php _e("Youtube-URL:","wp-youtube-lyte") ?> <input class="widefat" id="<?php echo $this->get_field_id('WYLurl'); ?>" name="<?php echo $this->get_field_name('WYLurl'); ?>" type="text" value="<?php echo $WYLurl; ?>" /></label></p>
169
- <p><label for="<?php echo $this->get_field_id('WYLtext'); ?>"><?php _e("Text:","wp-youtube-lyte") ?> <textarea class="widefat" id="<?php echo $this->get_field_id('WYLtext'); ?>" name="<?php echo $this->get_field_name('WYLtext'); ?>" rows="16" cols="20"><?php echo $WYLtext; ?></textarea></label></p>
170
  <?php
171
  }
172
  }
173
 
174
  function lyte_register_widget() {
175
- register_widget('WYLWidget');
176
  }
177
 
178
- add_action('widgets_init', 'lyte_register_widget');
8
  extract( $args );
9
  global $wSize, $wyl_version, $wp_lyte_plugin_url, $lyteSettings;
10
  $lyteSettings['path']= plugins_url() . "/" . dirname(plugin_basename(__FILE__)) . '/lyte/';
11
+ $qsa = '';
12
 
13
+ $WYLtitle = apply_filters( 'widget_title', $instance['WYLtitle'] );
14
+ $WYLtext = apply_filters( 'widget_text', $instance['WYLtext'], $instance );
15
+ $WYLsize = apply_filters( 'widget_text', $instance['WYLsize'], $instance );
16
+ if ( $WYLsize == '' ) $WYLsize=$wDefault;
17
  $WYLaudio = apply_filters( 'widget_text', $instance['WYLaudio'], $instance );
18
+ if ( $WYLaudio !== 'audio' ) {
19
+ $wrapperClass = ' lidget';
20
+ $audioClass = '';
21
+ $wHeight = $wSize[$WYLsize]['h'];
22
  } else {
23
+ $wrapperClass = '-audio lidget';
24
+ $audioClass = ' lyte-audio';
25
+ $wHeight = '38';
26
  }
27
+ $WYLurl = str_replace( 'httpv://', 'https://', trim( $instance['WYLurl'] ) );
28
+ $WYLqs = substr( strstr( $WYLurl, '?' ), 1 );
29
+ parse_str( $WYLqs, $WYLarr );
30
+
31
+ if ( strpos( $WYLurl, 'youtu.be' ) ) {
32
+ $WYLid = substr( parse_url( $WYLurl, PHP_URL_PATH ), 1, 11 );
33
+ $PLClass = '';
34
+ $WYLthumb = 'https://img.youtube.com/vi/' . $WYLid . '/hqdefault.jpg';
35
  } else {
36
+ if ( isset( $WYLarr['v'] ) ) {
37
+ $WYLid = $WYLarr['v'];
38
+ $PLClass = '';
39
+ $WYLthumb = 'https://img.youtube.com/vi/' . $WYLid . '/hqdefault.jpg';
40
+ } else if ( isset($WYLarr['list'] ) ) {
41
+ $WYLid = $WYLarr['list'];
42
+ $yt_resp = lyte_get_YT_resp( $WYLid, true, '', '', true );
43
+ $WYLthumb = $yt_resp['thumbUrl'];
44
+ $PLClass = ' playlist';
45
  }
46
  }
47
 
48
  // do we have to serve the thumbnail from local cache?
49
+ if ( get_option( 'lyte_local_thumb', '0' ) === '1' ) {
50
+ $WYLthumb = plugins_url( 'lyteCache.php?origThumbUrl=' . urlencode( $WYLthumb ) , __FILE__ );
51
  }
52
 
53
  // filter to alter the thumbnail
54
+ $WYLthumb = apply_filters( 'lyte_filter_widget_thumb', $WYLthumb, $WYLid );
55
 
56
+ if ( isset( $WYLarr['start'] ) ) $qsa = '&amp;start=' . $WYLarr['start'];
57
+ if ( isset( $WYLarr['enablejsapi'] ) ) {
58
+ $urlArr = parse_url($lyteSettings['path'] );
59
+ $origin = $urlArr[scheme] . '://' . $urlArr[host];
60
+ $qsa .= '&amp;enablejsapi=' . $WYLarr['enablejsapi'] . '&amp;origin=' . $origin;
61
  }
62
 
63
+ if ( ! empty( $qsa ) ) {
64
+ $esc_arr = array('&' => '\&', '?' => '\?', '=' => '\=');
65
+ $qsaClass = ' qsa_' . strtr( $qsa, $esc_arr );
66
  } else {
67
+ $qsaClass = '';
68
  }
69
 
70
+ $WYL_dom_id = 'YLW_' . $WYLid;
71
 
72
  ?>
73
  <?php echo $before_widget; ?>
81
 
82
  function update($new_instance, $old_instance) {
83
  $instance = $old_instance;
84
+ $instance['WYLtitle'] = strip_tags($new_instance['WYLtitle'] );
85
+ $instance['WYLurl'] = strip_tags($new_instance['WYLurl'] );
86
+ $instance['WYLsize'] = strip_tags($new_instance['WYLsize'] );
87
+ $instance['WYLaudio'] = strip_tags($new_instance['WYLaudio'] );
88
 
89
  if ( current_user_can('unfiltered_html') ) {
90
  $instance['WYLtext'] = $new_instance['WYLtext'];
91
  } else {
92
+ $instance['WYLtext'] = stripslashes( wp_filter_post_kses( addslashes( $new_instance['WYLtext'] ) ) );
93
  }
94
 
95
  return $instance;
98
  function form($instance) {
99
  global $wSize, $wDefault;
100
 
101
+ if ( isset( $instance['WYLtitle'] ) ) {
102
+ $WYLtitle = esc_attr( $instance['WYLtitle'] );
103
  } else {
104
+ $WYLtitle = '';
105
  }
106
 
107
+ if ( isset( $instance['WYLurl'] ) ) {
108
+ $WYLurl = esc_attr( $instance['WYLurl'] );
109
  } else {
110
+ $WYLurl = '';
111
  }
112
 
113
+ if ( isset( $instance['WYLtext'] ) ) {
114
+ $WYLtext = format_to_edit( $instance['WYLtext'] );
115
  } else {
116
+ $WYLtext = '';
117
  }
118
 
119
+ if ( isset( $instance['WYLaudio'] ) ) {
120
+ $WYLaudio = esc_attr( $instance['WYLaudio'] );
121
  } else {
122
+ $WYLaudio = '';
123
  }
124
  if ($WYLaudio!=="audio") $WYLaudio="";
125
 
126
+ if ( isset( $instance['WYLsize'] ) ) {
127
+ $WYLsize = esc_attr( $instance['WYLsize'] );
128
  } else {
129
+ $WYLsize = '';
130
  }
131
 
132
+ if ( $WYLsize == '' ) $WYLsize = $wDefault;
133
  ?>
134
+ <p><label for="<?php echo $this->get_field_id('WYLtitle'); ?>"><?php _e( 'Title:', 'wp-youtube-lyte' ); ?> <input class="widefat" id="<?php echo $this->get_field_id('WYLtitle'); ?>" name="<?php echo $this->get_field_name('WYLtitle'); ?>" type="text" value="<?php echo $WYLtitle; ?>" /></label></p>
135
+ <p><label for="<?php echo $this->get_field_id('WYLsize'); ?>"><?php _e( 'Size:', 'wp-youtube-lyte' ); ?>
136
+ <select class="widefat" id="<?php echo $this->get_field_id( 'WYLsize' ); ?>" name="<?php echo $this->get_field_name( 'WYLsize' ); ?>">
137
  <?php
138
+ foreach ( $wSize as $x => $size ) {
139
+ if ( $x == $WYLsize) {
140
+ $selected = ' selected="true"';
141
  } else {
142
+ $selected = '';
143
  }
144
 
145
+ if ( $wSize[$x]['depr'] !== true ) {
146
+ echo '<option value="' . $x . '"' . $selected . '>' . $wSize[$x]['w'] . 'X' . $wSize[$x]['h'] . '</option>';
147
  }
148
  $x++;
149
  }
150
  ?>
151
  </select>
152
  </label></p>
153
+ <p><label for="<?php echo $this->get_field_id( 'WYLaudio' ); ?>"><?php _e( 'Type:', 'wp-youtube-lyte' ); ?>
154
+ <select class="widefat" id="<?php echo $this->get_field_id( 'WYLaudio' ); ?>" name="<?php echo $this->get_field_name( 'WYLaudio' ); ?>">
155
  <?php
156
+ if($WYLaudio === 'audio' ) {
157
+ $aselected = ' selected="true"';
158
+ $vselected = '';
159
  } else {
160
+ $vselected = ' selected="true"';
161
+ $aselected = '';
162
  }
163
+ echo '<option value="audio"' . $aselected . '>' . __( 'audio', 'wp-youtube-lyte' ) . '</option>';
164
+ echo '<option value="video"' . $vselected . '>' . __( 'video', 'wp-youtube-lyte' ) . '</option>';
165
  ?>
166
  </select>
167
  </label></p>
168
+ <p><label for="<?php echo $this->get_field_id( 'WYLurl' ); ?>"><?php _e( 'Youtube-URL:', 'wp-youtube-lyte' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'WYLurl' ); ?>" name="<?php echo $this->get_field_name( 'WYLurl' ); ?>" type="text" value="<?php echo $WYLurl; ?>" /></label></p>
169
+ <p><label for="<?php echo $this->get_field_id( 'WYLtext' ); ?>"><?php _e( 'Text:', 'wp-youtube-lyte' ); ?> <textarea class="widefat" id="<?php echo $this->get_field_id( 'WYLtext' ); ?>" name="<?php echo $this->get_field_name( 'WYLtext' ); ?>" rows="16" cols="20"><?php echo $WYLtext; ?></textarea></label></p>
170
  <?php
171
  }
172
  }
173
 
174
  function lyte_register_widget() {
175
+ register_widget( 'WYLWidget' );
176
  }
177
 
178
+ add_action( 'widgets_init', 'lyte_register_widget' );
wp-youtube-lyte.php CHANGED
@@ -4,20 +4,20 @@ Plugin Name: WP YouTube Lyte
4
  Plugin URI: http://blog.futtta.be/wp-youtube-lyte/
5
  Description: Lite and accessible YouTube audio and video embedding.
6
  Author: Frank Goossens (futtta)
7
- Version: 1.7.15
8
  Author URI: http://blog.futtta.be/
9
  Text Domain: wp-youtube-lyte
10
  */
11
 
12
  if ( ! defined( 'ABSPATH' ) ) exit;
13
 
14
- $debug=false;
15
- $lyte_version = '1.7.15';
16
- $lyte_db_version=get_option('lyte_version','none');
17
 
18
  /** have we updated? */
19
  if ($lyte_db_version !== $lyte_version) {
20
- switch($lyte_db_version) {
21
  case "1.5.0":
22
  lyte_rm_cache();
23
  break;
@@ -42,17 +42,17 @@ if ($lyte_db_version !== $lyte_version) {
42
  lyte_mv_cache();
43
  break;
44
  }
45
- update_option('lyte_version',$lyte_version);
46
- $lyte_db_version=$lyte_version;
47
  }
48
 
49
  /** are we in debug-mode */
50
- if (!$debug) {
51
- $wyl_version=$lyte_version;
52
- $wyl_file="lyte-min.js";
53
  } else {
54
- $wyl_version=rand()/1000;
55
- $wyl_file="lyte.js";
56
  lyte_rm_cache();
57
  }
58
 
@@ -64,51 +64,58 @@ require_once(dirname(__FILE__).'/widget.php');
64
 
65
  /** get default embed size and build array to change size later if requested */
66
  $oSize = (int) get_option('lyte_size');
67
- if ((is_bool($oSize)) || ($pSize[$oSize]['a']===false)) { $sel = (int) $pDefault; } else { $sel=$oSize; }
 
 
 
 
 
68
 
69
- $pSizeFormat=$pSize[$sel]['f'];
70
- $j=0;
71
- foreach ($pSizeOrder[$pSizeFormat] as $sizeId) {
72
  $sArray[$j]['w']=(int) $pSize[$sizeId]['w'];
73
  $sArray[$j]['h']=(int) $pSize[$sizeId]['h'];
74
- if ($sizeId===$sel) $selSize=$j;
 
 
75
  $j++;
76
  }
77
 
78
  /** get other options and push in array*/
79
- $lyteSettings['sizeArray']=$sArray;
80
- $lyteSettings['selSize']=$selSize;
81
- $lyteSettings['links']=get_option('lyte_show_links');
82
- $lyteSettings['file']=$wyl_file."?wyl_version=".$wyl_version;
83
- $lyteSettings['ratioClass']= ( $pSizeFormat==="43" ) ? " fourthree" : "";
84
- $lyteSettings['pos']= ( get_option('lyte_position','0')==="1" ) ? "margin:5px auto;" : "margin:5px;";
85
- $lyteSettings['microdata']=get_option('lyte_microdata','1');
86
- $lyteSettings['hidef']=get_option('lyte_hidef',0);
87
- $lyteSettings['scheme'] = ( is_ssl() ) ? "https" : "http";
88
 
89
  /** API: filter hook to alter $lyteSettings */
90
  function lyte_settings_enforcer() {
91
  global $lyteSettings;
92
  $lyteSettings = apply_filters( 'lyte_settings', $lyteSettings );
93
- }
94
  add_action('after_setup_theme','lyte_settings_enforcer');
95
 
96
- function lyte_parse($the_content,$doExcerpt=false) {
97
  /** bail if AMP or if LYTE feed disabled and is_feed */
98
- if ( is_amp() || ( apply_filters( 'lyte_filter_dofeed', true ) === false && is_feed() ) ) { return str_replace( 'httpv://', 'https://', $the_content ); }
 
 
99
 
100
  /** main function to parse the content, searching and replacing httpv-links */
101
  global $lyteSettings, $toCache_index, $postID, $cachekey;
102
- $lyteSettings['path']=plugins_url() . "/" . dirname(plugin_basename(__FILE__)) . '/lyte/';
103
- $urlArr=parse_url($lyteSettings['path']);
104
- $origin=$urlArr['scheme']."://".$urlArr['host'];
105
 
106
  /** API: filter hook to preparse the_content, e.g. to force normal youtube links to be parsed */
107
  $the_content = apply_filters( 'lyte_content_preparse', $the_content );
108
 
109
  if ( get_option( 'lyte_greedy', '1' ) === "1" && strpos( $the_content, "youtu" ) !== false ){
110
  // new: also replace original YT embed code (iframes)
111
- if ( apply_filters( 'lyte_eats_yframes', true ) && preg_match_all( '#<iframe(?:[^<]*)?\ssrc=["|\']https:\/\/www\.youtube(?:-nocookie)?\.com\/embed\/(.*)["|\'](?:.*)><\/iframe>#Usm', $the_content, $matches, PREG_SET_ORDER ) ) {
112
  foreach ( $matches as $match ) {
113
  if ( strpos( $match[1], 'videoseries' ) === false) {
114
  $the_content = str_replace( $match[0], 'httpv://youtu.be/'.$match[1], $the_content );
@@ -119,128 +126,130 @@ function lyte_parse($the_content,$doExcerpt=false) {
119
  }
120
  }
121
 
122
- if((strpos($the_content, "httpv")!==FALSE)||(strpos($the_content, "httpa")!==FALSE)) {
123
- if (apply_filters('lyte_remove_wpautop',false)) {
124
- remove_filter('the_content','wpautop');
125
  }
 
126
  if ( apply_filters( 'lyte_kinda_textureize', true ) ) {
127
- $char_codes = array('&#215;','&#8211;','\u002d');
128
- $replacements = array("x", "--", "-");
129
- $the_content=str_replace($char_codes, $replacements, $the_content);
130
  }
131
- $lyte_feed=is_feed();
132
-
133
- $hidefClass = ($lyteSettings['hidef']==="1") ? " hidef" : "";
134
-
135
- $postID = get_the_ID();
136
- $toCache_index=array();
137
 
138
- $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>)?/";
 
 
 
 
139
 
140
- preg_match_all($lytes_regexp, $the_content, $matches, PREG_SET_ORDER);
141
 
142
- foreach($matches as $match) {
143
  /** API: filter hook to preparse fragment in a httpv-url, e.g. to force hqThumb=1 or showinfo=0 */
144
- $match[12] = apply_filters( 'lyte_match_preparse_fragment',$match[12] );
145
-
146
- preg_match("/stepSize\=([\+\-0-9]{2})/",$match[12],$sMatch);
147
- preg_match("/showinfo\=([0-1]{1})/",$match[12],$showinfo);
148
- preg_match("/start\=([0-9]*)/",$match[12],$start);
149
- preg_match("/enablejsapi\=([0-1]{1})/",$match[12],$jsapi);
150
- preg_match("/hqThumb\=([0-1]{1})/",$match[12],$hqThumb);
151
- preg_match("/noMicroData\=([0-1]{1})/",$match[12],$microData);
152
-
153
- $thumb="normal";
154
- if ($lyteSettings['hidef']==="1") {
155
- $thumb="highres";
156
- } else if (!empty($hqThumb)) {
157
- if ($hqThumb[0]==="hqThumb=1") {
158
- $thumb="highres";
159
  }
160
  }
161
 
162
- $noMicroData="0";
163
- if (!empty($microData)) {
164
- if ($microData[0]==="noMicroData=1") {
165
- $noMicroData="1";
166
  }
167
  }
168
 
169
- $qsa="";
170
- if (!empty($showinfo[0])) {
171
- $qsa="&amp;".$showinfo[0];
172
- $titleClass=" hidden";
173
  } else {
174
- $titleClass="";
175
  }
176
- if (!empty($start[0])) $qsa.="&amp;".$start[0];
177
- if (!empty($jsapi[0])) $qsa.="&amp;".$jsapi[0]."&amp;origin=".$origin;
178
-
179
- if (!empty($qsa)) {
180
- $esc_arr=array("&" => "\&", "?" => "\?", "=" => "\=");
181
- $qsaClass=" qsa_".strtr($qsa,$esc_arr);
 
 
 
182
  } else {
183
- $qsaClass="";
184
  }
185
 
186
- if (!empty($sMatch)) {
187
- $newSize=(int) $sMatch[1];
188
- $newPos=(int) $lyteSettings['selSize']+$newSize;
189
- if ($newPos<0) {
190
- $newPos=0;
191
- } else if ($newPos > count($lyteSettings['sizeArray'])-1) {
192
- $newPos=count($lyteSettings['sizeArray'])-1;
193
  }
194
- $lyteSettings[2]=$lyteSettings['sizeArray'][$newPos]['w'];
195
- $lyteSettings[3]=$lyteSettings['sizeArray'][$newPos]['h'];
196
  } else {
197
- $lyteSettings[2]=$lyteSettings['sizeArray'][$lyteSettings['selSize']]['w'];
198
- $lyteSettings[3]=$lyteSettings['sizeArray'][$lyteSettings['selSize']]['h'];
199
  }
200
 
201
- if ($match[1]!=="a") {
202
- $divHeight=$lyteSettings[3];
203
- $audioClass="";
204
- $audio=false;
205
  } else {
206
- $audio=true;
207
- $audioClass=" lyte-audio";
208
- $divHeight=38;
209
  }
210
 
211
- $NSimgHeight=$divHeight-20;
212
 
213
- if ($match[11]!="") {
214
- $plClass=" playlist";
215
- $vid=$match[11];
216
- switch ($lyteSettings['links']) {
217
- case "0":
218
- $noscript_post="<br />".__("Watch this playlist on YouTube","wp-youtube-lyte");
219
- $noscript="<noscript><a href=\"".$lyteSettings['scheme']."://youtube.com/playlist?list=".$vid."\">".$noscript_post."</a></noscript>";
220
- $lytelinks_txt="";
221
  break;
222
  default:
223
- $noscript="";
224
- $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>";
225
  }
226
  } else if ($match[9]!="") {
227
  $plClass="";
228
  $vid=$match[9];
229
  switch ($lyteSettings['links']) {
230
  case "0":
231
- $noscript_post="<br />".__("Watch this video on YouTube","wp-youtube-lyte");
232
- $lytelinks_txt="<div class=\"lL\" style=\"max-width:100%;width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\"></div>";
233
  break;
234
  default:
235
- $noscript_post="";
236
- $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>";
237
  }
238
- $thumbUrl = $lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg";
239
- if (get_option('lyte_local_thumb','0') === '1') {
240
  $thumbUrl = plugins_url( 'lyteCache.php?origThumbUrl=' . urlencode($thumbUrl) , __FILE__ );
241
  }
242
  $thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl, $vid );
243
- $noscript="<noscript><a href=\"".$lyteSettings['scheme']."://youtu.be/".$vid."\"><img src=\"" . $thumbUrl . "\" alt=\"\" width=\"".$lyteSettings[2]."\" height=\"".$NSimgHeight."\" />".$noscript_post."</a></noscript>";
244
  }
245
 
246
  // add disclaimer to lytelinks
@@ -250,110 +259,77 @@ function lyte_parse($the_content,$doExcerpt=false) {
250
  }
251
 
252
  if ( $disclaimer && empty( $lytelinks_txt ) ) {
253
- $lytelinks_txt = "<div class=\"lL\" style=\"max-width:100%;width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\">".$diclaimer."</div>";
254
  } else if ( $disclaimer ) {
255
- $lytelinks_txt = str_replace('</div>','<br/>'.$disclaimer.'</div>',$lytelinks_txt);
256
  }
257
 
258
  // fetch data from YT api (v2 or v3)
259
- $isPlaylist=false;
260
- if ($plClass===" playlist") {
261
- $isPlaylist=true;
262
  }
263
- $cachekey = '_lyte_' . $vid;
264
- $yt_resp_array=lyte_get_YT_resp($vid,$isPlaylist,$cachekey);
265
 
266
  // If there was a result from youtube or from cache, use it
267
- if ( $yt_resp_array ) {
268
- if (is_array($yt_resp_array)) {
269
- if ($isPlaylist!==true) {
270
- // captions, thanks to Benetech
271
- $captionsMeta="";
272
- $doCaptions=true;
273
-
274
- /** API: filter hook to disable captions */
275
- $doCaptions = apply_filters( 'lyte_docaptions', $doCaptions );
276
-
277
- if(($lyteSettings['microdata'] === "1")&&($noMicroData !== "1" )&&($doCaptions === true)) {
278
- if ( array_key_exists( 'captions_data', $yt_resp_array ) && is_int( $yt_resp_array["captions_timestamp"] ) ) {
279
- if ($yt_resp_array["captions_data"]=="true") {
280
- $captionsMeta="<meta itemprop=\"accessibilityFeature\" content=\"captions\" />";
281
- $forceCaptionsUpdate=false;
282
- } else {
283
- $forceCaptionsUpdate=true;
284
- }
285
- } else {
286
- $forceCaptionsUpdate=true;
287
- $yt_resp_array["captions_data"]=false;
288
- }
289
-
290
- if ($forceCaptionsUpdate===true) {
291
- $captionsMeta="";
292
- $threshold = 30;
293
- if (array_key_exists('captions_timestamp',$yt_resp_array)) {
294
- $cache_timestamp = (int) $yt_resp_array["captions_timestamp"];
295
- $interval = (strtotime("now") - $cache_timestamp)/60/60/24;
296
- } else {
297
- $cache_timestamp = false;
298
- $interval = $threshold+1;
299
- }
300
-
301
- if(!is_int($cache_timestamp) || ($interval > $threshold && !is_null( $yt_resp_array["captions_data"]))) {
302
- $yt_resp_array['captions_timestamp'] = strtotime("now");
303
- wp_schedule_single_event(strtotime("now") + 60*60, 'schedule_captions_lookup', array($postID, $cachekey, $vid));
304
- $yt_resp_precache=json_encode($yt_resp_array);
305
- $toCache=base64_encode(gzcompress($yt_resp_precache));
306
- update_post_meta($postID, $cachekey, $toCache);
307
- }
308
- }
309
  }
310
  }
311
- $thumbUrl="";
312
- if (($thumb==="highres") && (!empty($yt_resp_array["HQthumbUrl"]))){
313
- $thumbUrl=$yt_resp_array["HQthumbUrl"];
 
 
 
 
 
314
  } else {
315
- if (!empty($yt_resp_array["thumbUrl"])) {
316
- $thumbUrl=$yt_resp_array["thumbUrl"];
317
- } else {
318
- $thumbUrl="//i.ytimg.com/vi/".$vid."/hqdefault.jpg";
319
- }
320
- }
321
- if ( strpos( $noscript, 'alt=""' ) !== false && array_key_exists( 'title', $yt_resp_array ) ) {
322
- $noscript = str_replace( 'alt=""', 'alt="' . htmlentities( $yt_resp_array["title"] ). '"', $noscript );
323
  }
324
- } else {
325
- // no useable result from youtube, fallback on video thumbnail (doesn't work on playlist)
326
- $thumbUrl = "//i.ytimg.com/vi/".$vid."/hqdefault.jpg";
327
  }
328
  } else {
329
- // same fallback
330
  $thumbUrl = "//i.ytimg.com/vi/".$vid."/hqdefault.jpg";
331
  }
332
 
333
  // do we have to serve the thumbnail from local cache?
334
- if (get_option('lyte_local_thumb','0') === '1') {
335
- $thumbUrl = plugins_url( 'lyteCache.php?origThumbUrl=' . urlencode($thumbUrl) , __FILE__ );
336
  }
337
 
338
  /** API: filter hook to override thumbnail URL */
339
  $thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl, $vid );
340
 
341
- if (isset($yt_resp_array) && !empty($yt_resp_array) && !empty($yt_resp_array["title"])) {
342
- $_this_title = $yt_resp_array["title"];
343
- $_this_title_tag = ' title="'.htmlentities( $_this_title ).'"';
344
  } else {
345
  $_this_title = false;
346
  $_this_title_tag = '';
347
  }
348
 
349
- if ($audio===true) {
350
- $wrapper="<div class=\"lyte-wrapper-audio\"".$_this_title_tag." style=\"width:".$lyteSettings[2]."px;max-width:100%;overflow:hidden;height:38px;".$lyteSettings['pos']."\">";
351
  } else {
352
- $wrapper="<div class=\"lyte-wrapper".$lyteSettings['ratioClass']."\"".$_this_title_tag." style=\"width:".$lyteSettings[2]."px;max-width: 100%;".$lyteSettings['pos']."\">";
353
  }
354
 
355
  // do we have usable microdata fiels from the YT API, if not no microdata below.
356
- foreach ( array( 'title', 'description','dateField' ) as $resp_key ) {
357
  if ( empty( $yt_resp_array[$resp_key] ) ) {
358
  $noMicroData = '1';
359
  break;
@@ -366,42 +342,42 @@ function lyte_parse($the_content,$doExcerpt=false) {
366
  $noMicroData = '1';
367
  }
368
 
369
- if ($doExcerpt) {
370
- $lytetemplate="";
371
- $templateType="excerpt";
372
- } elseif ($lyte_feed) {
373
- $postURL = get_permalink( $postID );
374
- $textLink = ($lyteSettings['links']===0)? "" : "<br />".strip_tags($lytelinks_txt, '<a>')."<br />";
375
- $lytetemplate = "<a href=\"".$postURL."\"><img src=\"".$thumbUrl."\" alt=\"YouTube Video\"></a>".$textLink;
376
- $templateType="feed";
377
  } elseif ( $audio !== true && $plClass !== " playlist" && $lyteSettings['microdata'] === "1" && $noMicroData !== "1" ) {
378
- $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\"><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;
379
- $templateType="postMicrodata";
380
  } else {
381
- $lytetemplate = $wrapper."<div class=\"lyMe".$audioClass.$hidefClass.$plClass.$qsaClass."\" id=\"WYL_".$vid."\"><div id=\"lyte_".$vid."\" data-src=\"".$thumbUrl."\" class=\"pL\">";
382
 
383
  if ( isset( $_this_title ) ) {
384
- $lytetemplate .= "<div class=\"tC".$titleClass."\"><div class=\"tT\">".$_this_title."</div></div>";
385
  }
386
 
387
- $lytetemplate .= "<div class=\"play\"></div><div class=\"ctrl\"><div class=\"Lctrl\"></div><div class=\"Rctrl\"></div></div></div>".$noscript."</div></div>".$lytelinks_txt;
388
  $templateType="post";
389
  }
390
 
391
  /** API: filter hook to parse template before being applied */
392
- $lytetemplate = str_replace('$','&#36;',$lytetemplate);
393
- $lytetemplate = apply_filters( 'lyte_match_postparse_template',$lytetemplate,$templateType );
394
- $the_content = preg_replace($lytes_regexp, $lytetemplate, $the_content, 1);
395
  }
396
 
397
  // update lyte_cache_index
398
- if ((is_array($toCache_index))&&(!empty($toCache_index))) {
399
- $lyte_cache=json_decode(get_option('lyte_cache_index'),true);
400
- $lyte_cache[$postID]=$toCache_index;
401
- update_option('lyte_cache_index',json_encode($lyte_cache));
402
  }
403
 
404
- if (!$lyte_feed) {
405
  lyte_initer();
406
  }
407
  }
@@ -414,64 +390,34 @@ function lyte_parse($the_content,$doExcerpt=false) {
414
  }
415
 
416
  /** API: filter hook to postparse the_content before returning */
417
- $the_content = apply_filters( 'lyte_content_postparse',$the_content );
418
 
419
  return $the_content;
420
  }
421
 
422
- function captions_lookup($postID, $cachekey, $vid) {
423
- // captions lookup at YouTube via a11ymetadata.org
424
- $response = wp_remote_request("http://api.a11ymetadata.org/captions/youtubeid=".$vid."/youtube");
425
-
426
- if(!is_wp_error($response)) {
427
- $rawJson = wp_remote_retrieve_body($response);
428
- $decodeJson = json_decode($rawJson, true);
429
-
430
- $yt_resp = get_post_meta($postID, $cachekey, true);
431
-
432
- if (!empty($yt_resp)) {
433
- $yt_resp = gzuncompress(base64_decode($yt_resp));
434
- if($yt_resp) {
435
- $yt_resp_array=json_decode($yt_resp,true);
436
-
437
- if ($decodeJson['status'] == 'success' && $decodeJson['data']['captions'] == '1') {
438
- $yt_resp_array['captions_data'] = true;
439
- } else {
440
- $yt_resp_array['captions_data'] = false;
441
- }
442
-
443
- $yt_resp_array['captions_timestamp'] = strtotime("now");
444
- $yt_resp_precache=json_encode($yt_resp_array);
445
- $toCache=base64_encode(gzcompress($yt_resp_precache));
446
- update_post_meta($postID, $cachekey, $toCache);
447
- }
448
- }
449
- }
450
- }
451
-
452
  function lyte_get_YT_resp( $vid, $playlist=false, $cachekey='', $apiTestKey='', $isWidget=false ) {
453
  /** logic to get video info from cache or get it from YouTube and set it */
454
  global $postID, $cachekey, $toCache_index;
455
 
456
  $_thisLyte = array();
457
- $yt_error = array();
458
 
459
- if ( $postID && empty($apiTestKey) && !$isWidget ) {
460
  $cache_resp = get_post_meta( $postID, $cachekey, true );
461
- if (!empty($cache_resp)) {
462
- $_thisLyte = json_decode(gzuncompress(base64_decode($cache_resp)),1);
463
  // make sure there are not old APIv2 full responses in cache
464
- if (array_key_exists('entry', $_thisLyte)) {
465
- if ($_thisLyte['entry']['xmlns$yt']==="http://gdata.youtube.com/schemas/2007") {
466
  $_thisLyte = array();
467
  }
468
  }
469
  }
470
- } else if ($isWidget) {
471
- $cache_resp = get_option("lyte_widget_cache");
472
- if (!empty($cache_resp)) {
473
- $widget_cache = json_decode(gzuncompress(base64_decode($cache_resp)),1);
474
- $_thisLyte = $widget_cache[$vid];
475
  }
476
  }
477
 
@@ -484,80 +430,77 @@ function lyte_get_YT_resp( $vid, $playlist=false, $cachekey='', $apiTestKey='',
484
  // first get yt api key
485
  $lyte_yt_api_key = get_option('lyte_yt_api_key','');
486
  $lyte_yt_api_key = apply_filters('lyte_filter_yt_api_key', $lyte_yt_api_key);
487
- if (!empty($apiTestKey)) {
488
- $lyte_yt_api_key=$apiTestKey;
489
  }
490
 
491
- if (($lyte_yt_api_key==="none") || (empty($lyte_yt_api_key))) {
492
- $_thisLyte['title']="";
493
- if ($playlist) {
494
- $_thisLyte['thumbUrl']="";
495
- $_thisLyte['HQthumbUrl']="";
496
  } else {
497
- $_thisLyte['thumbUrl']="//i.ytimg.com/vi/".$vid."/hqdefault.jpg";
498
- $_thisLyte['HQthumbUrl']="//i.ytimg.com/vi/".$vid."/maxresdefault.jpg";
499
  }
500
- $_thisLyte['dateField']="";
501
- $_thisLyte['duration']="";
502
- $_thisLyte['description']="";
503
- $_thisLyte['captions_data']="false";
504
- $_thisLyte['captions_timestamp']=strtotime("now");
505
  return $_thisLyte;
506
  } else {
507
  // v3, feeling somewhat lonely now v2 has gently been put to sleep
508
- $yt_api_base = "https://www.googleapis.com/youtube/v3/";
509
 
510
- if ($playlist) {
511
- $yt_api_target = "playlists?part=snippet%2C+id&id=".$vid."&key=".$lyte_yt_api_key;
512
  } else {
513
- $yt_api_target = "videos?part=id%2C+snippet%2C+contentDetails&id=".$vid."&key=".$lyte_yt_api_key;
514
  }
515
  }
516
 
517
- $yt_api_url = $yt_api_base.$yt_api_target;
518
- $yt_resp = wp_remote_get($yt_api_url);
519
 
520
  // check if we got through
521
- if ( is_wp_error($yt_resp) ) {
522
- $yt_error['code']=408;
523
- $yt_error['reason']=$yt_resp->get_error_message();
524
- $yt_error['timestamp']=strtotime("now");
525
- if (!empty($apiTestKey)) {
526
  return $yt_error;
527
  }
528
  } else {
529
- $yt_resp_array = (array) json_decode(wp_remote_retrieve_body($yt_resp),true);
530
- if(is_array($yt_resp_array)) {
531
  // extract relevant data
532
  // v3
533
- if (in_array(wp_remote_retrieve_response_code($yt_resp),array(400,403,404))) {
534
- $yt_error['code']=wp_remote_retrieve_response_code($yt_resp);
535
- $yt_error['reason']=$yt_resp_array['error']['errors'][0]['reason'];
536
- $yt_error['timestamp']=strtotime("now");
537
- if (empty($apiTestKey)) {
538
- update_option("lyte_api_error",json_encode($yt_error));
539
  } else {
540
  return $yt_error;
541
  }
542
  } else {
543
  if ($playlist) {
544
- $_thisLyte['title']="Playlist: ".esc_attr(sanitize_text_field(@$yt_resp_array['items'][0]['snippet']['title']));
545
- $_thisLyte['thumbUrl']=esc_url(@$yt_resp_array['items'][0]['snippet']['thumbnails']['high']['url']);
546
- $_thisLyte['HQthumbUrl']=esc_url(@$yt_resp_array['items'][0]['snippet']['thumbnails']['maxres']['url']);
547
- $_thisLyte['dateField']=sanitize_text_field(@$yt_resp_array['items'][0]['snippet']['publishedAt']);
548
- $_thisLyte['duration']="";
549
- $_thisLyte['description']=esc_attr(sanitize_text_field(@$yt_resp_array['items'][0]['snippet']['description']));
550
- $_thisLyte['captions_data']="false";
551
- $_thisLyte['captions_timestamp'] = "";
552
  } else {
553
- $_thisLyte['title']=esc_attr(sanitize_text_field(@$yt_resp_array['items'][0]['snippet']['title']));
554
- $_thisLyte['thumbUrl']=esc_url(@$yt_resp_array['items'][0]['snippet']['thumbnails']['high']['url']);
555
- $_thisLyte['HQthumbUrl']=esc_url(@$yt_resp_array['items'][0]['snippet']['thumbnails']['maxres']['url']);
556
- $_thisLyte['dateField']=sanitize_text_field(@$yt_resp_array['items'][0]['snippet']['publishedAt']);
557
- $_thisLyte['duration']=sanitize_text_field(@$yt_resp_array['items'][0]['contentDetails']['duration']);
558
- $_thisLyte['description']=esc_attr(sanitize_text_field(@$yt_resp_array['items'][0]['snippet']['description']));
559
- $_thisLyte['captions_data']=sanitize_text_field(@$yt_resp_array['items'][0]['contentDetails']['caption']);
560
- $_thisLyte['captions_timestamp'] = strtotime("now");
561
  }
562
  }
563
 
@@ -568,32 +511,32 @@ function lyte_get_YT_resp( $vid, $playlist=false, $cachekey='', $apiTestKey='',
568
  $_thisLyte['description'] = apply_filters( 'lyte_ytapi_description', $_thisLyte['description'] );
569
 
570
  // try to cache the result
571
- if ( (($postID) || ($isWidget)) && !empty($_thisLyte) && empty($apiTestKey) ) {
572
- $_thisLyte['lyte_date_added']=time();
573
 
574
  if ( $postID && !$isWidget ) {
575
- $yt_resp_precache=json_encode($_thisLyte);
576
 
577
  // then gzip + base64 (to limit amount of data + solve problems with wordpress removing slashes)
578
- $yt_resp_precache=base64_encode(gzcompress($yt_resp_precache));
579
 
580
  // and do the actual caching
581
  $toCache = ( $yt_resp_precache ) ? $yt_resp_precache : '{{unknown}}';
582
 
583
  update_post_meta( $postID, $cachekey, $toCache );
584
  // and finally add new cache-entry to toCache_index which will be added to lyte_cache_index pref
585
- $toCache_index[]=$cachekey;
586
- } else if ($isWidget) {
587
- $widget_cache[$vid]=$_thisLyte;
588
- update_option("lyte_widget_cache",base64_encode(gzcompress(json_encode($widget_cache))));
589
  }
590
  }
591
  }
592
  }
593
  }
594
- foreach (array("title","thumbUrl","HQthumbUrl","dateField","duration","description","captions_data","captions_timestamp") as $key) {
595
- if (!array_key_exists($key,$_thisLyte)) {
596
- $_thisLyte[$key]="";
597
  }
598
  }
599
  return $_thisLyte;
@@ -602,25 +545,25 @@ function lyte_get_YT_resp( $vid, $playlist=false, $cachekey='', $apiTestKey='',
602
  /* only add js/css once and only if needed */
603
  function lyte_initer() {
604
  global $lynited;
605
- if (!$lynited) {
606
- $lynited=true;
607
- add_action('wp_footer', 'lyte_init');
608
  }
609
  }
610
 
611
  /* actual initialization */
612
- function lyte_init() {
613
  global $lyteSettings;
614
- $lyte_css = ".lyte-wrapper-audio div, .lyte-wrapper div {margin:0px; overflow:hidden;} .lyte,.lyMe{position:relative;padding-bottom:56.25%;height:0;overflow:hidden;background-color:#777;} .fourthree .lyMe, .fourthree .lyte {padding-bottom:75%;} .lidget{margin-bottom:5px;} .lidget .lyte, .widget .lyMe {padding-bottom:0!important;height:100%!important;} .lyte-wrapper-audio .lyte{height:38px!important;overflow:hidden;padding:0!important} .lyMe iframe, .lyte iframe,.lyte .pL{position:absolute !important;top:0;left:0;width:100%;height:100%!important;background:no-repeat scroll center #000;background-size:cover;cursor:pointer} .tC{left:0;position:absolute;top:0;width:100%} .tC{background-image:linear-gradient(to bottom,rgba(0,0,0,0.6),rgba(0,0,0,0))} .tT{color:#FFF;font-family:Roboto,sans-serif;font-size:16px;height:auto;text-align:left;padding:5px 10px 50px 10px} .play{background:no-repeat scroll 0 0 transparent;width:88px;height:63px;position:absolute;left:43%;left:calc(50% - 44px);left:-webkit-calc(50% - 44px);top:38%;top:calc(50% - 31px);top:-webkit-calc(50% - 31px);} .widget .play {top:30%;top:calc(45% - 31px);top:-webkit-calc(45% - 31px);transform:scale(0.6);-webkit-transform:scale(0.6);-ms-transform:scale(0.6);} .lyte:hover .play{background-position:0 -65px;} .lyte-audio .pL{max-height:38px!important} .lyte-audio iframe{height:438px!important} .ctrl{background:repeat scroll 0 -220px rgba(0,0,0,0.3);width:100%;height:40px;bottom:0px;left:0;position:absolute;} .lyte-wrapper .ctrl{display:none}.Lctrl{background:no-repeat scroll 0 -137px transparent;width:158px;height:40px;bottom:0;left:0;position:absolute} .Rctrl{background:no-repeat scroll -42px -179px transparent;width:117px;height:40px;bottom:0;right:0;position:absolute;padding-right:10px;}.lyte-audio .play{display:none}.lyte-audio .ctrl{background-color:rgba(0,0,0,1)}.lyte .hidden{display:none}";
615
 
616
  // by default show lyte vid on mobile (requiring user clicking play two times)
617
  // but can be overruled by this filter
618
  // also "do lyte mobile" when option to cache thumbnails is on to ensure privacy (gdpr)
619
  $mobLyte = apply_filters( 'lyte_do_mobile', false );
620
  if ( $mobLyte || get_option( 'lyte_local_thumb', 0 ) ) {
621
- $mobJS = "var mOs=null;";
622
  } else {
623
- $mobJS = "var mOs=navigator.userAgent.match(/(iphone|ipad|ipod|android)/i);";
624
  }
625
 
626
  // if we're caching local thumbnails and filter says so, create lyteCookie cookie to prevent image hotlinking.
@@ -631,10 +574,16 @@ function lyte_init() {
631
  }
632
 
633
  /** API: filter hook to change css */
634
- $lyte_css = apply_filters( 'lyte_css', $lyte_css);
635
 
636
- echo "<script type=\"text/javascript\">var bU='" . $lyteSettings['path'] . "';" . $mobJS . $doublecheck_thumb_cookie . "style = document.createElement('style');style.type = 'text/css';rules = document.createTextNode(\"".$lyte_css."\" );if(style.styleSheet) { style.styleSheet.cssText = rules.nodeValue;} else {style.appendChild(rules);}document.getElementsByTagName('head')[0].appendChild(style);</script>";
637
- echo "<script type=\"text/javascript\" async src=\"".$lyteSettings['path'].$lyteSettings['file']."\"></script>";
 
 
 
 
 
 
638
  }
639
 
640
  /** override default wp_trim_excerpt to have lyte_parse remove the httpv-links */
@@ -646,85 +595,87 @@ function lyte_trim_excerpt($text = '', $post = null) {
646
  $text = get_the_content( '', false, $post );
647
  $text = lyte_parse($text, true);
648
  $text = strip_shortcodes( $text );
649
- $text = excerpt_remove_blocks( $text );
650
- $text = apply_filters( 'the_content', $text );
651
- $text = str_replace( ']]>', ']]&gt;', $text );
 
 
652
  $excerpt_length = intval( _x( '55', 'excerpt_length' ) );
653
  $excerpt_length = (int) apply_filters( 'excerpt_length', $excerpt_length );
654
- $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
655
- $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
656
  }
657
 
658
  return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt );
659
  }
660
 
661
  /** Lyte shortcode */
662
- function shortcode_lyte($atts) {
663
- extract(shortcode_atts(array(
664
- "id" => '',
665
- "audio" => '',
666
- "playlist" => '',
667
- "start" => '',
668
- "showinfo" => '',
669
- "stepsize" => '',
670
- "hqthumb" => '',
671
- ), $atts));
672
 
673
  $qs = '';
674
 
675
- if ($audio) {$proto="httpa";} else {$proto="httpv";}
676
- if ($start !== '') { $qs .= "&amp;start=".$start; }
677
- if ($showinfo === "false") { $qs .= "&amp;showinfo=0"; }
678
- if ($hqthumb) { $qs .= "&amp;hqThumb=1"; }
679
- if ($stepsize) { $qs .= "#stepSize=".$stepsize; }
680
- if ($playlist) {$action="playlist?list=";} else {$action="watch?v=";}
681
 
682
- return lyte_parse($proto.'://www.youtube.com/'.$action.$id.$qs);
683
  }
684
 
685
  /** update functions */
686
  /** upgrade, so lyte should not be greedy */
687
  function lyte_not_greedy() {
688
- update_option( "lyte_greedy", "0" );
689
  }
690
 
691
  /** function to flush YT responses from cache */
692
  function lyte_rm_cache() {
693
  // remove thumbnail cache
694
- if (get_option('lyte_local_thumb','0') === '1') {
695
  if ( ! defined( 'LYTE_CACHE_DIR' ) ) {
696
  define( 'LYTE_CACHE_CHILD_DIR', 'cache/lyteCache' );
697
  define( 'LYTE_CACHE_DIR', WP_CONTENT_DIR .'/'. LYTE_CACHE_CHILD_DIR );
698
  }
699
- array_map('unlink', glob(LYTE_CACHE_DIR . "/*"));
700
  }
701
 
702
  // and remove cached YT data from postmeta
703
  try {
704
- ini_set('max_execution_time',90); // give PHP some more time for this, post-meta can be sloooooow
705
 
706
  // cache in post_meta, for posts
707
- $lyte_posts = json_decode(get_option("lyte_cache_index"),true);
708
- $lyteCacheIterator = 0;
709
  $lytePurgeThreshold = 500;
710
- $returnCode = "OK";
711
- if (is_array($lyte_posts)){
712
- foreach ($lyte_posts as $postID => $lyte_post) {
713
- foreach ($lyte_post as $cachekey) {
714
- delete_post_meta($postID, $cachekey);
715
  }
716
- unset ($lyte_posts[$postID]);
717
  $lyteCacheIterator++;
718
- if ($lyteCacheIterator > ($lytePurgeThreshold-1)) {
719
- $returnCode = "PART";
720
  break;
721
  }
722
  }
723
- update_option("lyte_cache_index",json_encode($lyte_posts));
724
  }
725
 
726
  // and the widget cache which isn't in post_meta
727
- update_option('lyte_widget_cache','');
728
 
729
  return $returnCode;
730
  } catch(Exception $e) {
@@ -753,23 +704,23 @@ function lyte_thumbcache_moved() {
753
 
754
  /** function to call from within themes */
755
  /* use with e.g. : <?php if(function_exists('lyte_preparse')) { echo lyte_preparse($videoId); } ?> */
756
- function lyte_preparse($videoId) {
757
- return lyte_parse('httpv://www.youtube.com/watch?v='.$videoId);
758
  }
759
 
760
- function lyte_add_action_link($links) {
761
- $links[]='<a href="' . admin_url( 'options-general.php?page=lyte_settings_page' ) . '">' . __('Settings') . '</a>';
762
  return $links;
763
  }
764
 
765
  /** is_amp, but I shouldn't have to do this, should I? */
766
- if (!function_exists("is_amp")) {
767
  function is_amp() {
768
- if ( function_exists('is_amp_endpoint') ) {
769
  return is_amp_endpoint();
770
- } else if ( function_exists('ampforwp_is_amp_endpoint') ) {
771
  return ampforwp_is_amp_endpoint();
772
- } else if ((strpos($_SERVER['REQUEST_URI'],'?amp')!==false) || (strpos($_SERVER['REQUEST_URI'],'/amp/')!==false)) {
773
  return true;
774
  } else {
775
  return false;
@@ -782,7 +733,7 @@ function lyte_prepare( $the_content ) {
782
  if ( is_amp() || ( apply_filters( 'lyte_filter_dofeed', true ) === false && is_feed() ) ) { return str_replace( 'httpv://', 'https://', $the_content ); }
783
 
784
  // catch gutenberg blocks before being rendered.
785
- if ( apply_filters( 'lyte_filter_do_gutenberg', true ) && strpos( $the_content, "<!-- wp:" ) !== false && strpos( $the_content, "youtu" ) !== false ) {
786
  /*
787
  * do Gutenberg stuff here, playlists if needed first and then single videos
788
  *
@@ -794,14 +745,14 @@ function lyte_prepare( $the_content ) {
794
  */
795
  if ( strpos( $the_content, '/playlist?list=' ) !== false ) {
796
  $gutenbeard_playlist_regex = '%<\!--\s?wp:(?:core[-|/])?embed(?:/youtube)?\s?{"url":"https://www.youtube.com/playlist\?list=(.*)"(?:.*)?}\s?-->.*(?:(?:<figcaption>(.*)</figcaption>).*)?<\!--\s?/wp:(?:core[-|/])?embed(?:/youtube)?\s?-->%Us';
797
- $the_content = preg_replace($gutenbeard_playlist_regex, '<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube">httpv://www.youtube.com/playlist?list=\1<figcaption>\2</figcaption></figure>',$the_content);
798
  }
799
  $gutenbeard_single_regex = '%<\!--\s?wp:(?:core[-|/])?embed(?:/youtube)?\s?{"url":"https?://(?:www\.)?youtu(?:be\.com/watch\?v=|.be/)(.*)"(?:.*)?}\s?-->.*(?:(?:<figcaption>(.*)</figcaption>).*)?<\!--\s?/wp:(?:core[-|/])?embed(?:/youtube)?\s?-->%Us';
800
- $the_content = preg_replace($gutenbeard_single_regex, '<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube">httpv://www.youtube.com/watch?v=\1<figcaption>\2</figcaption></figure>',$the_content);
801
  }
802
 
803
  // do the most of the greedy part early.
804
- if ( get_option( 'lyte_greedy', '1' ) === "1" && strpos( $the_content, "youtu" ) !== false ){
805
  // only preg_replace if "youtu" (as part of youtube.com or youtu.be) is found.
806
  if ( strpos( $the_content, '/playlist?list=' ) !== false ) {
807
  // only preg_replace for playlists if there are playlists to be parsed.
@@ -820,15 +771,15 @@ function lytecache_doublecheck_activator() {
820
  if ( ! defined( 'LYTE_CACHE_DIR' ) ) {
821
  define( 'LYTE_CACHE_DIR', WP_CONTENT_DIR .'/cache/lyteCache' );
822
  }
823
- $_doublecheck_activator_file = LYTE_CACHE_DIR . '/doubleCheckLyteThumbnailCache.txt';
 
 
 
 
824
 
 
825
  if ( ( get_option( 'lyte_local_thumb', '0' ) === '1' && apply_filters( 'lyte_filter_local_thumb_doublecheck', false ) ) || get_option( 'lyte_local_thumb', '0' ) !== '1' ) {
826
  if ( ! file_exists( $_doublecheck_activator_file ) ) {
827
- if ( ! file_exists( LYTE_CACHE_DIR ) ) {
828
- // create LYTE cache dir (and index.html) if it doesn't exist yet.
829
- @mkdir( LYTE_CACHE_DIR, 0775, true );
830
- @file_put_contents( LYTE_CACHE_DIR . '/index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/wp-youtube-lyte/" rel="nofollow">WP YouTube Lyte</a></body></html>' );
831
- }
832
  // file needed but not found, create it.
833
  @file_put_contents( $_doublecheck_activator_file, 'This file is used to ensure lyteCache.php is not abused (prevent hotlinking of cached YouTube thumbnails or lyteCache.php being accessed when local thumbnail caching is not active).' );
834
  }
@@ -836,6 +787,17 @@ function lytecache_doublecheck_activator() {
836
  // file exists but not needed (any more), delete it.
837
  @unlink( $_doublecheck_activator_file );
838
  }
 
 
 
 
 
 
 
 
 
 
 
839
  }
840
 
841
  /** hooking it all up to wordpress */
@@ -844,15 +806,14 @@ if ( is_admin() ) {
844
  add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'lyte_add_action_link' );
845
  add_action( 'admin_init', 'lytecache_doublecheck_activator' );
846
  } else {
847
- add_filter('the_content', 'lyte_prepare', 4);
848
- add_filter('the_content', 'lyte_parse', 10);
849
- add_shortcode("lyte", "shortcode_lyte");
850
- remove_filter('get_the_excerpt', 'wp_trim_excerpt');
851
- add_filter('get_the_excerpt', 'lyte_trim_excerpt');
852
- add_action('schedule_captions_lookup', 'captions_lookup', 1, 3);
853
  add_action( 'init', 'lytecache_doublecheck_activator' );
854
 
855
  /** API: action hook to allow extra actions or filters to be added */
856
- do_action("lyte_actionsfilters");
857
  }
858
  ?>
4
  Plugin URI: http://blog.futtta.be/wp-youtube-lyte/
5
  Description: Lite and accessible YouTube audio and video embedding.
6
  Author: Frank Goossens (futtta)
7
+ Version: 1.7.16
8
  Author URI: http://blog.futtta.be/
9
  Text Domain: wp-youtube-lyte
10
  */
11
 
12
  if ( ! defined( 'ABSPATH' ) ) exit;
13
 
14
+ $debug = false;
15
+ $lyte_version = '1.7.16';
16
+ $lyte_db_version = get_option( 'lyte_version', 'none' );
17
 
18
  /** have we updated? */
19
  if ($lyte_db_version !== $lyte_version) {
20
+ switch( $lyte_db_version ) {
21
  case "1.5.0":
22
  lyte_rm_cache();
23
  break;
42
  lyte_mv_cache();
43
  break;
44
  }
45
+ update_option( 'lyte_version', $lyte_version );
46
+ $lyte_db_version = $lyte_version;
47
  }
48
 
49
  /** are we in debug-mode */
50
+ if ( ! $debug ) {
51
+ $wyl_version = $lyte_version;
52
+ $wyl_file = 'lyte-min.js';
53
  } else {
54
+ $wyl_version = rand()/1000;
55
+ $wyl_file = 'lyte.js';
56
  lyte_rm_cache();
57
  }
58
 
64
 
65
  /** get default embed size and build array to change size later if requested */
66
  $oSize = (int) get_option('lyte_size');
67
+ if ( (is_bool( $oSize ) ) || ( $pSize[$oSize]['a'] === false ) ) {
68
+ $sel = (int) $pDefault; } else { $sel=$oSize;
69
+ }
70
+
71
+ $pSizeFormat = $pSize[$sel]['f'];
72
+ $j = 0;
73
 
74
+ foreach ( $pSizeOrder[$pSizeFormat] as $sizeId ) {
 
 
75
  $sArray[$j]['w']=(int) $pSize[$sizeId]['w'];
76
  $sArray[$j]['h']=(int) $pSize[$sizeId]['h'];
77
+ if ( $sizeId === $sel ) {
78
+ $selSize=$j;
79
+ }
80
  $j++;
81
  }
82
 
83
  /** get other options and push in array*/
84
+ $lyteSettings['sizeArray'] = $sArray;
85
+ $lyteSettings['selSize'] = $selSize;
86
+ $lyteSettings['links'] = get_option('lyte_show_links');
87
+ $lyteSettings['file'] = $wyl_file."?wyl_version=".$wyl_version;
88
+ $lyteSettings['ratioClass'] = ( $pSizeFormat === '43' ) ? ' fourthree' : '';
89
+ $lyteSettings['pos'] = ( get_option( 'lyte_position', '0' ) === '1' ) ? 'margin:5px auto;' : 'margin:5px;';
90
+ $lyteSettings['microdata'] = get_option( 'lyte_microdata', '1' );
91
+ $lyteSettings['hidef'] = get_option( 'lyte_hidef', 0 );
92
+ $lyteSettings['scheme'] = ( is_ssl() ) ? "https" : "http";
93
 
94
  /** API: filter hook to alter $lyteSettings */
95
  function lyte_settings_enforcer() {
96
  global $lyteSettings;
97
  $lyteSettings = apply_filters( 'lyte_settings', $lyteSettings );
98
+ }
99
  add_action('after_setup_theme','lyte_settings_enforcer');
100
 
101
+ function lyte_parse( $the_content, $doExcerpt = false ) {
102
  /** bail if AMP or if LYTE feed disabled and is_feed */
103
+ if ( is_amp() || ( apply_filters( 'lyte_filter_dofeed', true ) === false && is_feed() ) ) {
104
+ return str_replace( 'httpv://', 'https://', $the_content );
105
+ }
106
 
107
  /** main function to parse the content, searching and replacing httpv-links */
108
  global $lyteSettings, $toCache_index, $postID, $cachekey;
109
+ $lyteSettings['path'] = plugins_url() . '/' . dirname( plugin_basename( __FILE__ ) ) . '/lyte/';
110
+ $urlArr = parse_url( $lyteSettings['path'] );
111
+ $origin = $urlArr['scheme'] . '://' . $urlArr['host'];
112
 
113
  /** API: filter hook to preparse the_content, e.g. to force normal youtube links to be parsed */
114
  $the_content = apply_filters( 'lyte_content_preparse', $the_content );
115
 
116
  if ( get_option( 'lyte_greedy', '1' ) === "1" && strpos( $the_content, "youtu" ) !== false ){
117
  // new: also replace original YT embed code (iframes)
118
+ 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 ) ) {
119
  foreach ( $matches as $match ) {
120
  if ( strpos( $match[1], 'videoseries' ) === false) {
121
  $the_content = str_replace( $match[0], 'httpv://youtu.be/'.$match[1], $the_content );
126
  }
127
  }
128
 
129
+ if ( ( strpos( $the_content, 'httpv' ) !== false ) || ( strpos( $the_content, 'httpa' ) !== false ) ) {
130
+ if ( apply_filters( 'lyte_remove_wpautop', false ) ) {
131
+ remove_filter( 'the_content', 'wpautop' );
132
  }
133
+
134
  if ( apply_filters( 'lyte_kinda_textureize', true ) ) {
135
+ $char_codes = array( '&#215;', '&#8211;', '\u002d' );
136
+ $replacements = array( 'x', '--', '-');
137
+ $the_content = str_replace( $char_codes, $replacements, $the_content );
138
  }
 
 
 
 
 
 
139
 
140
+ $lyte_feed = is_feed();
141
+ $hidefClass = ( $lyteSettings['hidef'] === '1') ? ' hidef' : '';
142
+ $postID = get_the_ID();
143
+ $toCache_index = array();
144
+ $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>)?/';
145
 
146
+ preg_match_all( $lytes_regexp, $the_content, $matches, PREG_SET_ORDER );
147
 
148
+ foreach( $matches as $match ) {
149
  /** API: filter hook to preparse fragment in a httpv-url, e.g. to force hqThumb=1 or showinfo=0 */
150
+ $match[12] = apply_filters( 'lyte_match_preparse_fragment', $match[12] );
151
+
152
+ preg_match( '/stepSize\=([\+\-0-9]{2})/', $match[12], $sMatch );
153
+ preg_match( '/showinfo\=([0-1]{1})/', $match[12], $showinfo );
154
+ preg_match( '/start\=([0-9]*)/', $match[12], $start );
155
+ preg_match( '/enablejsapi\=([0-1]{1})/', $match[12], $jsapi );
156
+ preg_match( '/hqThumb\=([0-1]{1})/', $match[12], $hqThumb );
157
+ preg_match( '/noMicroData\=([0-1]{1})/', $match[12], $microData );
158
+
159
+ $thumb = 'normal';
160
+ if ( $lyteSettings['hidef'] === '1' ) {
161
+ $thumb = 'highres';
162
+ } else if ( ! empty( $hqThumb ) ) {
163
+ if ( $hqThumb[0] === 'hqThumb=1' ) {
164
+ $thumb = 'highres';
165
  }
166
  }
167
 
168
+ $noMicroData = '0';
169
+ if ( ! empty( $microData ) ) {
170
+ if ( $microData[0] === 'noMicroData=1' ) {
171
+ $noMicroData = '1';
172
  }
173
  }
174
 
175
+ $qsa='';
176
+ if ( ! empty( $showinfo[0] ) ) {
177
+ $qsa = '&amp;' . $showinfo[0];
178
+ $titleClass = ' hidden';
179
  } else {
180
+ $titleClass = '';
181
  }
182
+ if ( ! empty( $start[0] ) ) {
183
+ $qsa = $qsa . '&amp;' . $start[0];
184
+ }
185
+ if ( ! empty( $jsapi[0] ) ) {
186
+ $qsa = $qsa . '&amp;' . $jsapi[0] . '&amp;origin=' . $origin;
187
+ }
188
+ if ( ! empty( $qsa ) ) {
189
+ $esc_arr = array( '&' => '\&', '?' => '\?', '=' => '\=');
190
+ $qsaClass = ' qsa_' . strtr( $qsa, $esc_arr ) ;
191
  } else {
192
+ $qsaClass = '';
193
  }
194
 
195
+ if ( ! empty( $sMatch ) ) {
196
+ $newSize = (int) $sMatch[1];
197
+ $newPos = (int) $lyteSettings['selSize'] + $newSize;
198
+ if ( $newPos < 0 ) {
199
+ $newPos = 0;
200
+ } else if ( $newPos > count( $lyteSettings['sizeArray'] ) - 1 ) {
201
+ $newPos = count($lyteSettings['sizeArray']) - 1;
202
  }
203
+ $lyteSettings[2] = $lyteSettings['sizeArray'][$newPos]['w'];
204
+ $lyteSettings[3] = $lyteSettings['sizeArray'][$newPos]['h'];
205
  } else {
206
+ $lyteSettings[2] = $lyteSettings['sizeArray'][$lyteSettings['selSize']]['w'];
207
+ $lyteSettings[3] = $lyteSettings['sizeArray'][$lyteSettings['selSize']]['h'];
208
  }
209
 
210
+ if ( $match[1] !== 'a' ) {
211
+ $divHeight = $lyteSettings[3];
212
+ $audioClass = '';
213
+ $audio = false;
214
  } else {
215
+ $audio = true;
216
+ $audioClass = ' lyte-audio';
217
+ $divHeight = 38;
218
  }
219
 
220
+ $NSimgHeight = $divHeight - 20;
221
 
222
+ if ( $match[11] != '' ) {
223
+ $plClass = ' playlist';
224
+ $vid = $match[11];
225
+ switch ( $lyteSettings['links'] ) {
226
+ case '0':
227
+ $noscript_post = '<br />' . __( 'Watch this playlist on YouTube', 'wp-youtube-lyte' );
228
+ $noscript = '<noscript><a href="' . $lyteSettings['scheme'] . '://youtube.com/playlist?list=' . $vid . '">' . $noscript_post . '</a></noscript>';
229
+ $lytelinks_txt = '';
230
  break;
231
  default:
232
+ $noscript = '';
233
+ $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>';
234
  }
235
  } else if ($match[9]!="") {
236
  $plClass="";
237
  $vid=$match[9];
238
  switch ($lyteSettings['links']) {
239
  case "0":
240
+ $noscript_post = '<br />' . __( 'Watch this video on YouTube', 'wp-youtube-lyte' );
241
+ $lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] .'"></div>';
242
  break;
243
  default:
244
+ $noscript_post = '';
245
+ $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>';
246
  }
247
+ $thumbUrl = $lyteSettings['scheme'] . '://i.ytimg.com/vi/' . $vid . '/0.jpg';
248
+ if ( get_option( 'lyte_local_thumb', '0' ) === '1' ) {
249
  $thumbUrl = plugins_url( 'lyteCache.php?origThumbUrl=' . urlencode($thumbUrl) , __FILE__ );
250
  }
251
  $thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl, $vid );
252
+ $noscript = '<noscript><a href="' . $lyteSettings['scheme'] . '://youtu.be/' . $vid . '"><img src="' . $thumbUrl . '" alt="" width="' . $lyteSettings[2] . '" height="' . $NSimgHeight . '" />' . $noscript_post . '</a></noscript>';
253
  }
254
 
255
  // add disclaimer to lytelinks
259
  }
260
 
261
  if ( $disclaimer && empty( $lytelinks_txt ) ) {
262
+ $lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] . '">' . $diclaimer . '</div>';
263
  } else if ( $disclaimer ) {
264
+ $lytelinks_txt = str_replace( '</div>', '<br/>' . $disclaimer . '</div>', $lytelinks_txt );
265
  }
266
 
267
  // fetch data from YT api (v2 or v3)
268
+ $isPlaylist = false;
269
+ if ( $plClass ===' playlist' ) {
270
+ $isPlaylist = true;
271
  }
272
+ $cachekey = '_lyte_' . $vid;
273
+ $yt_resp_array = lyte_get_YT_resp( $vid, $isPlaylist, $cachekey );
274
 
275
  // If there was a result from youtube or from cache, use it
276
+ if ( $yt_resp_array && is_array( $yt_resp_array ) ) {
277
+ if ( $isPlaylist !== true ) {
278
+ // captions
279
+ $captionsMeta = '';
280
+ $doCaptions = true;
281
+
282
+ /** API: filter hook to disable captions */
283
+ $doCaptions = apply_filters( 'lyte_docaptions', $doCaptions );
284
+
285
+ if ( ( $lyteSettings['microdata'] === "1" ) && ( $noMicroData !== "1" ) && ( $doCaptions === true ) ) {
286
+ if ( array_key_exists( 'captions_data', $yt_resp_array ) && $yt_resp_array['captions_data'] == 'true') {
287
+ $captionsMeta = '<meta itemprop="accessibilityFeature" content="captions" />';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  }
289
  }
290
+ }
291
+
292
+ $thumbUrl = '';
293
+ if ( ( $thumb === 'highres' ) && ( ! empty( $yt_resp_array['HQthumbUrl'] ) ) ){
294
+ $thumbUrl = $yt_resp_array['HQthumbUrl'];
295
+ } else {
296
+ if ( ! empty( $yt_resp_array['thumbUrl'] ) ) {
297
+ $thumbUrl = $yt_resp_array['thumbUrl'];
298
  } else {
299
+ $thumbUrl = '//i.ytimg.com/vi/' . $vid . '/hqdefault.jpg';
 
 
 
 
 
 
 
300
  }
301
+ }
302
+ if ( strpos( $noscript, 'alt=""' ) !== false && array_key_exists( 'title', $yt_resp_array ) ) {
303
+ $noscript = str_replace( 'alt=""', 'alt="' . htmlentities( $yt_resp_array["title"] ). '"', $noscript );
304
  }
305
  } else {
 
306
  $thumbUrl = "//i.ytimg.com/vi/".$vid."/hqdefault.jpg";
307
  }
308
 
309
  // do we have to serve the thumbnail from local cache?
310
+ if ( get_option( 'lyte_local_thumb', '0' ) === '1' ) {
311
+ $thumbUrl = plugins_url( 'lyteCache.php?origThumbUrl=' . urlencode( $thumbUrl ) , __FILE__ );
312
  }
313
 
314
  /** API: filter hook to override thumbnail URL */
315
  $thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl, $vid );
316
 
317
+ if ( isset( $yt_resp_array ) && ! empty( $yt_resp_array ) && ! empty( $yt_resp_array['title'] ) ) {
318
+ $_this_title = $yt_resp_array['title'];
319
+ $_this_title_tag = ' title="' . htmlentities( $_this_title ) . '"';
320
  } else {
321
  $_this_title = false;
322
  $_this_title_tag = '';
323
  }
324
 
325
+ if ( $audio === true ) {
326
+ $wrapper = '<div class="lyte-wrapper-audio"' . $_this_title_tag . ' style="width:' . $lyteSettings[2] . 'px;max-width:100%;overflow:hidden;height:38px;' . $lyteSettings['pos'] . '">';
327
  } else {
328
+ $wrapper = '<div class="lyte-wrapper' . $lyteSettings['ratioClass'] . '"' . $_this_title_tag . ' style="width:' . $lyteSettings[2] . 'px;max-width:100%;' . $lyteSettings['pos'] . '">';
329
  }
330
 
331
  // do we have usable microdata fiels from the YT API, if not no microdata below.
332
+ foreach ( array( 'title', 'description', 'dateField' ) as $resp_key ) {
333
  if ( empty( $yt_resp_array[$resp_key] ) ) {
334
  $noMicroData = '1';
335
  break;
342
  $noMicroData = '1';
343
  }
344
 
345
+ if ( $doExcerpt ) {
346
+ $lytetemplate = '';
347
+ $templateType = 'excerpt';
348
+ } elseif ( $lyte_feed ) {
349
+ $postURL = get_permalink( $postID );
350
+ $textLink = ( $lyteSettings['links'] ===0 ) ? '' : '<br />' . strip_tags( $lytelinks_txt, '<a>' ) . '<br />';
351
+ $lytetemplate = '<a href="' . $postURL . '"><img src="' . $thumbUrl . '" alt="YouTube Video"></a>' . $textLink;
352
+ $templateType = 'feed';
353
  } elseif ( $audio !== true && $plClass !== " playlist" && $lyteSettings['microdata'] === "1" && $noMicroData !== "1" ) {
354
+ $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"><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;
355
+ $templateType = 'postMicrodata';
356
  } else {
357
+ $lytetemplate = $wrapper . '<div class="lyMe' . $audioClass . $hidefClass . $plClass . $qsaClass . '" id="WYL_' . $vid . '"><div id="lyte_' . $vid . '" data-src="' . $thumbUrl . '" class="pL">';
358
 
359
  if ( isset( $_this_title ) ) {
360
+ $lytetemplate .= '<div class="tC' . $titleClass . '"><div class="tT">' . $_this_title . '</div></div>';
361
  }
362
 
363
+ $lytetemplate .= '<div class="play"></div><div class="ctrl"><div class="Lctrl"></div><div class="Rctrl"></div></div></div>' . $noscript . '</div></div>' . $lytelinks_txt;
364
  $templateType="post";
365
  }
366
 
367
  /** API: filter hook to parse template before being applied */
368
+ $lytetemplate = str_replace( '$', '&#36;', $lytetemplate );
369
+ $lytetemplate = apply_filters( 'lyte_match_postparse_template', $lytetemplate, $templateType );
370
+ $the_content = preg_replace( $lytes_regexp, $lytetemplate, $the_content, 1 );
371
  }
372
 
373
  // update lyte_cache_index
374
+ if ( ( is_array( $toCache_index ) ) && ( ! empty( $toCache_index ) ) ) {
375
+ $lyte_cache = json_decode( get_option( 'lyte_cache_index' ), true );
376
+ $lyte_cache[$postID] = $toCache_index;
377
+ update_option( 'lyte_cache_index', json_encode( $lyte_cache ) );
378
  }
379
 
380
+ if ( ! $lyte_feed ) {
381
  lyte_initer();
382
  }
383
  }
390
  }
391
 
392
  /** API: filter hook to postparse the_content before returning */
393
+ $the_content = apply_filters( 'lyte_content_postparse', $the_content );
394
 
395
  return $the_content;
396
  }
397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
  function lyte_get_YT_resp( $vid, $playlist=false, $cachekey='', $apiTestKey='', $isWidget=false ) {
399
  /** logic to get video info from cache or get it from YouTube and set it */
400
  global $postID, $cachekey, $toCache_index;
401
 
402
  $_thisLyte = array();
403
+ $yt_error = array();
404
 
405
+ if ( $postID && empty( $apiTestKey ) && ! $isWidget ) {
406
  $cache_resp = get_post_meta( $postID, $cachekey, true );
407
+ if ( ! empty( $cache_resp ) ) {
408
+ $_thisLyte = json_decode( gzuncompress( base64_decode( $cache_resp ) ), 1 );
409
  // make sure there are not old APIv2 full responses in cache
410
+ if ( array_key_exists( 'entry', $_thisLyte ) ) {
411
+ if ( $_thisLyte['entry']['xmlns$yt'] === 'http://gdata.youtube.com/schemas/2007' ) {
412
  $_thisLyte = array();
413
  }
414
  }
415
  }
416
+ } else if ( $isWidget ) {
417
+ $cache_resp = get_option( 'lyte_widget_cache' );
418
+ if ( ! empty( $cache_resp ) ) {
419
+ $widget_cache = json_decode( gzuncompress( base64_decode( $cache_resp ) ), 1 );
420
+ $_thisLyte = $widget_cache[$vid];
421
  }
422
  }
423
 
430
  // first get yt api key
431
  $lyte_yt_api_key = get_option('lyte_yt_api_key','');
432
  $lyte_yt_api_key = apply_filters('lyte_filter_yt_api_key', $lyte_yt_api_key);
433
+ if ( ! empty( $apiTestKey ) ) {
434
+ $lyte_yt_api_key = $apiTestKey;
435
  }
436
 
437
+ if ( ( $lyte_yt_api_key === 'none' ) || ( empty( $lyte_yt_api_key ) ) ) {
438
+ $_thisLyte['title'] = '';
439
+ if ( $playlist ) {
440
+ $_thisLyte['thumbUrl'] = '';
441
+ $_thisLyte['HQthumbUrl'] = '';
442
  } else {
443
+ $_thisLyte['thumbUrl'] = '//i.ytimg.com/vi/' . $vid . '/hqdefault.jpg';
444
+ $_thisLyte['HQthumbUrl'] = '//i.ytimg.com/vi/' . $vid . '/maxresdefault.jpg';
445
  }
446
+ $_thisLyte['dateField'] = '';
447
+ $_thisLyte['duration'] = '';
448
+ $_thisLyte['description'] = '';
449
+ $_thisLyte['captions_data'] = 'false';
 
450
  return $_thisLyte;
451
  } else {
452
  // v3, feeling somewhat lonely now v2 has gently been put to sleep
453
+ $yt_api_base = 'https://www.googleapis.com/youtube/v3/';
454
 
455
+ if ( $playlist ) {
456
+ $yt_api_target = 'playlists?part=snippet%2C+id&id=' . $vid . '&key=' . $lyte_yt_api_key;
457
  } else {
458
+ $yt_api_target = 'videos?part=id%2C+snippet%2C+contentDetails&id=' . $vid . '&key=' . $lyte_yt_api_key;
459
  }
460
  }
461
 
462
+ $yt_api_url = $yt_api_base . $yt_api_target;
463
+ $yt_resp = wp_remote_get( $yt_api_url );
464
 
465
  // check if we got through
466
+ if ( is_wp_error( $yt_resp ) ) {
467
+ $yt_error['code'] = 408;
468
+ $yt_error['reason'] = $yt_resp->get_error_message();
469
+ $yt_error['timestamp'] = strtotime('now');
470
+ if ( ! empty( $apiTestKey ) ) {
471
  return $yt_error;
472
  }
473
  } else {
474
+ $yt_resp_array = (array) json_decode( wp_remote_retrieve_body( $yt_resp ), true );
475
+ if ( is_array( $yt_resp_array ) ) {
476
  // extract relevant data
477
  // v3
478
+ if ( in_array( wp_remote_retrieve_response_code( $yt_resp ), array( 400, 403, 404 ) ) ) {
479
+ $yt_error['code'] = wp_remote_retrieve_response_code( $yt_resp );
480
+ $yt_error['reason'] = $yt_resp_array['error']['errors'][0]['reason'];
481
+ $yt_error['timestamp'] = strtotime('now');
482
+ if ( empty( $apiTestKey ) ) {
483
+ update_option('lyte_api_error', json_encode( $yt_error ) );
484
  } else {
485
  return $yt_error;
486
  }
487
  } else {
488
  if ($playlist) {
489
+ $_thisLyte['title'] = 'Playlist: ' . esc_attr( sanitize_text_field( @$yt_resp_array['items'][0]['snippet']['title'] ) );
490
+ $_thisLyte['thumbUrl'] = esc_url(@$yt_resp_array['items'][0]['snippet']['thumbnails']['high']['url']);
491
+ $_thisLyte['HQthumbUrl'] = esc_url(@$yt_resp_array['items'][0]['snippet']['thumbnails']['maxres']['url']);
492
+ $_thisLyte['dateField'] = sanitize_text_field( @$yt_resp_array['items'][0]['snippet']['publishedAt'] );
493
+ $_thisLyte['duration'] = '';
494
+ $_thisLyte['description'] = esc_attr(sanitize_text_field(@$yt_resp_array['items'][0]['snippet']['description']) );
495
+ $_thisLyte['captions_data'] = 'false';
 
496
  } else {
497
+ $_thisLyte['title'] = esc_attr( sanitize_text_field( @$yt_resp_array['items'][0]['snippet']['title'] ) );
498
+ $_thisLyte['thumbUrl'] = esc_url( @$yt_resp_array['items'][0]['snippet']['thumbnails']['high']['url'] );
499
+ $_thisLyte['HQthumbUrl'] = esc_url( @$yt_resp_array['items'][0]['snippet']['thumbnails']['maxres']['url'] );
500
+ $_thisLyte['dateField'] = sanitize_text_field( @$yt_resp_array['items'][0]['snippet']['publishedAt'] );
501
+ $_thisLyte['duration'] = sanitize_text_field( @$yt_resp_array['items'][0]['contentDetails']['duration'] );
502
+ $_thisLyte['description'] = esc_attr(sanitize_text_field( @$yt_resp_array['items'][0]['snippet']['description'] ) );
503
+ $_thisLyte['captions_data'] = sanitize_text_field( @$yt_resp_array['items'][0]['contentDetails']['caption'] );
 
504
  }
505
  }
506
 
511
  $_thisLyte['description'] = apply_filters( 'lyte_ytapi_description', $_thisLyte['description'] );
512
 
513
  // try to cache the result
514
+ if ( ( ( $postID ) || ( $isWidget ) ) && ! empty( $_thisLyte ) && empty( $apiTestKey ) ) {
515
+ $_thisLyte['lyte_date_added'] = time();
516
 
517
  if ( $postID && !$isWidget ) {
518
+ $yt_resp_precache = json_encode( $_thisLyte );
519
 
520
  // then gzip + base64 (to limit amount of data + solve problems with wordpress removing slashes)
521
+ $yt_resp_precache = base64_encode( gzcompress( $yt_resp_precache ) );
522
 
523
  // and do the actual caching
524
  $toCache = ( $yt_resp_precache ) ? $yt_resp_precache : '{{unknown}}';
525
 
526
  update_post_meta( $postID, $cachekey, $toCache );
527
  // and finally add new cache-entry to toCache_index which will be added to lyte_cache_index pref
528
+ $toCache_index[] = $cachekey;
529
+ } else if ( $isWidget ) {
530
+ $widget_cache[$vid] = $_thisLyte;
531
+ update_option( 'lyte_widget_cache', base64_encode( gzcompress( json_encode( $widget_cache ) ) ) );
532
  }
533
  }
534
  }
535
  }
536
  }
537
+ foreach ( array( 'title', 'thumbUrl', 'HQthumbUrl', 'dateField', 'duration', 'description', 'captions_data' ) as $key ) {
538
+ if ( ! array_key_exists( $key, $_thisLyte ) ) {
539
+ $_thisLyte[$key] = '';
540
  }
541
  }
542
  return $_thisLyte;
545
  /* only add js/css once and only if needed */
546
  function lyte_initer() {
547
  global $lynited;
548
+ if ( ! $lynited ) {
549
+ $lynited = true;
550
+ add_action( 'wp_footer', 'lyte_init' );
551
  }
552
  }
553
 
554
  /* actual initialization */
555
+ function lyte_init( $echo = true ) {
556
  global $lyteSettings;
557
+ $lyte_css = '.lyte-wrapper-audio div, .lyte-wrapper div {margin:0px; overflow:hidden;} .lyte,.lyMe{position:relative;padding-bottom:56.25%;height:0;overflow:hidden;background-color:#777;} .fourthree .lyMe, .fourthree .lyte {padding-bottom:75%;} .lidget{margin-bottom:5px;} .lidget .lyte, .widget .lyMe {padding-bottom:0!important;height:100%!important;} .lyte-wrapper-audio .lyte{height:38px!important;overflow:hidden;padding:0!important} .lyMe iframe, .lyte iframe,.lyte .pL{position:absolute !important;top:0;left:0;width:100%;height:100%!important;background:no-repeat scroll center #000;background-size:cover;cursor:pointer} .tC{left:0;position:absolute;top:0;width:100%} .tC{background-image:linear-gradient(to bottom,rgba(0,0,0,0.6),rgba(0,0,0,0))} .tT{color:#FFF;font-family:Roboto,sans-serif;font-size:16px;height:auto;text-align:left;padding:5px 10px 50px 10px} .play{background:no-repeat scroll 0 0 transparent;width:88px;height:63px;position:absolute;left:43%;left:calc(50% - 44px);left:-webkit-calc(50% - 44px);top:38%;top:calc(50% - 31px);top:-webkit-calc(50% - 31px);} .widget .play {top:30%;top:calc(45% - 31px);top:-webkit-calc(45% - 31px);transform:scale(0.6);-webkit-transform:scale(0.6);-ms-transform:scale(0.6);} .lyte:hover .play{background-position:0 -65px;} .lyte-audio .pL{max-height:38px!important} .lyte-audio iframe{height:438px!important} .ctrl{background:repeat scroll 0 -220px rgba(0,0,0,0.3);width:100%;height:40px;bottom:0px;left:0;position:absolute;} .lyte-wrapper .ctrl{display:none}.Lctrl{background:no-repeat scroll 0 -137px transparent;width:158px;height:40px;bottom:0;left:0;position:absolute} .Rctrl{background:no-repeat scroll -42px -179px transparent;width:117px;height:40px;bottom:0;right:0;position:absolute;padding-right:10px;}.lyte-audio .play{display:none}.lyte-audio .ctrl{background-color:rgba(0,0,0,1)}.lyte .hidden{display:none}';
558
 
559
  // by default show lyte vid on mobile (requiring user clicking play two times)
560
  // but can be overruled by this filter
561
  // also "do lyte mobile" when option to cache thumbnails is on to ensure privacy (gdpr)
562
  $mobLyte = apply_filters( 'lyte_do_mobile', false );
563
  if ( $mobLyte || get_option( 'lyte_local_thumb', 0 ) ) {
564
+ $mobJS = 'var mOs=null;';
565
  } else {
566
+ $mobJS = 'var mOs=navigator.userAgent.match(/(iphone|ipad|ipod|android)/i);';
567
  }
568
 
569
  // if we're caching local thumbnails and filter says so, create lyteCookie cookie to prevent image hotlinking.
574
  }
575
 
576
  /** API: filter hook to change css */
577
+ $lyte_css = apply_filters( 'lyte_css', $lyte_css );
578
 
579
+ $inline_js = '<script type="text/javascript" data-cfasync="false">var bU="' . $lyteSettings['path'] . '";' . $mobJS . $doublecheck_thumb_cookie . 'style = document.createElement("style");style.type = "text/css";rules = document.createTextNode("' . $lyte_css . '");if(style.styleSheet) { style.styleSheet.cssText = rules.nodeValue;} else {style.appendChild(rules);}document.getElementsByTagName("head")[0].appendChild(style);</script>';
580
+ $linked_js = '<script type="text/javascript" data-cfasync="false" async src="' . $lyteSettings['path'] . $lyteSettings['file'] . '"></script>';
581
+
582
+ if ( false !== $echo ) {
583
+ echo $inline_js . $linked_js;
584
+ } else {
585
+ return $inline_js . $linked_js;
586
+ }
587
  }
588
 
589
  /** override default wp_trim_excerpt to have lyte_parse remove the httpv-links */
595
  $text = get_the_content( '', false, $post );
596
  $text = lyte_parse($text, true);
597
  $text = strip_shortcodes( $text );
598
+ if ( function_exists( 'excerpt_remove_blocks' ) ) {
599
+ $text = excerpt_remove_blocks( $text );
600
+ }
601
+ $text = apply_filters( 'the_content', $text );
602
+ $text = str_replace( ']]>', ']]&gt;', $text );
603
  $excerpt_length = intval( _x( '55', 'excerpt_length' ) );
604
  $excerpt_length = (int) apply_filters( 'excerpt_length', $excerpt_length );
605
+ $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
606
+ $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
607
  }
608
 
609
  return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt );
610
  }
611
 
612
  /** Lyte shortcode */
613
+ function shortcode_lyte( $atts ) {
614
+ extract( shortcode_atts( array(
615
+ 'id' => '',
616
+ 'audio' => '',
617
+ 'playlist' => '',
618
+ 'start' => '',
619
+ 'showinfo' => '',
620
+ 'stepsize' => '',
621
+ 'hqthumb' => '',
622
+ ), $atts ) );
623
 
624
  $qs = '';
625
 
626
+ if ($audio) { $proto = 'httpa'; } else { $proto = 'httpv'; }
627
+ if ( $start !== '' ) { $qs .= '&amp;start=' . $start; }
628
+ if ( $showinfo === 'false' ) { $qs .= '&amp;showinfo=0'; }
629
+ if ( $hqthumb ) { $qs .= '&amp;hqThumb=1'; }
630
+ if ( $stepsize ) { $qs .= '#stepSize=' . $stepsize; }
631
+ if ( $playlist ) { $action = 'playlist?list=';} else { $action = 'watch?v='; }
632
 
633
+ return lyte_parse( $proto . '://www.youtube.com/' . $action . $id . $qs );
634
  }
635
 
636
  /** update functions */
637
  /** upgrade, so lyte should not be greedy */
638
  function lyte_not_greedy() {
639
+ update_option( 'lyte_greedy', '0' );
640
  }
641
 
642
  /** function to flush YT responses from cache */
643
  function lyte_rm_cache() {
644
  // remove thumbnail cache
645
+ if ( get_option( 'lyte_local_thumb', '0' ) === '1' ) {
646
  if ( ! defined( 'LYTE_CACHE_DIR' ) ) {
647
  define( 'LYTE_CACHE_CHILD_DIR', 'cache/lyteCache' );
648
  define( 'LYTE_CACHE_DIR', WP_CONTENT_DIR .'/'. LYTE_CACHE_CHILD_DIR );
649
  }
650
+ array_map('unlink', glob( LYTE_CACHE_DIR . "/*" ) );
651
  }
652
 
653
  // and remove cached YT data from postmeta
654
  try {
655
+ ini_set( 'max_execution_time', 90 ); // give PHP some more time for this, post-meta can be sloooooow
656
 
657
  // cache in post_meta, for posts
658
+ $lyte_posts = json_decode( get_option( 'lyte_cache_index'), true );
659
+ $lyteCacheIterator = 0;
660
  $lytePurgeThreshold = 500;
661
+ $returnCode = 'OK';
662
+ if ( is_array( $lyte_posts ) ) {
663
+ foreach ( $lyte_posts as $postID => $lyte_post ) {
664
+ foreach ( $lyte_post as $cachekey ) {
665
+ delete_post_meta( $postID, $cachekey );
666
  }
667
+ unset ( $lyte_posts[$postID] );
668
  $lyteCacheIterator++;
669
+ if ( $lyteCacheIterator > ( $lytePurgeThreshold-1 ) ) {
670
+ $returnCode = 'PART';
671
  break;
672
  }
673
  }
674
+ update_option( 'lyte_cache_index', json_encode( $lyte_posts ) );
675
  }
676
 
677
  // and the widget cache which isn't in post_meta
678
+ update_option( 'lyte_widget_cache', '' );
679
 
680
  return $returnCode;
681
  } catch(Exception $e) {
704
 
705
  /** function to call from within themes */
706
  /* use with e.g. : <?php if(function_exists('lyte_preparse')) { echo lyte_preparse($videoId); } ?> */
707
+ function lyte_preparse( $videoId ) {
708
+ return lyte_parse( 'httpv://www.youtube.com/watch?v=' . $videoId );
709
  }
710
 
711
+ function lyte_add_action_link( $links ) {
712
+ $links[] = '<a href="' . admin_url( 'options-general.php?page=lyte_settings_page' ) . '">' . __( 'Settings' ) . '</a>';
713
  return $links;
714
  }
715
 
716
  /** is_amp, but I shouldn't have to do this, should I? */
717
+ if ( ! function_exists('is_amp') ) {
718
  function is_amp() {
719
+ if ( function_exists( 'is_amp_endpoint' ) ) {
720
  return is_amp_endpoint();
721
+ } else if ( function_exists( 'ampforwp_is_amp_endpoint' ) ) {
722
  return ampforwp_is_amp_endpoint();
723
+ } else if ( ( strpos( $_SERVER['REQUEST_URI'], '?amp' ) !== false) || ( strpos( $_SERVER['REQUEST_URI'], '/amp/' ) !== false ) ) {
724
  return true;
725
  } else {
726
  return false;
733
  if ( is_amp() || ( apply_filters( 'lyte_filter_dofeed', true ) === false && is_feed() ) ) { return str_replace( 'httpv://', 'https://', $the_content ); }
734
 
735
  // catch gutenberg blocks before being rendered.
736
+ if ( apply_filters( 'lyte_filter_do_gutenberg', true ) && strpos( $the_content, '<!-- wp:' ) !== false && strpos( $the_content, 'youtu' ) !== false ) {
737
  /*
738
  * do Gutenberg stuff here, playlists if needed first and then single videos
739
  *
745
  */
746
  if ( strpos( $the_content, '/playlist?list=' ) !== false ) {
747
  $gutenbeard_playlist_regex = '%<\!--\s?wp:(?:core[-|/])?embed(?:/youtube)?\s?{"url":"https://www.youtube.com/playlist\?list=(.*)"(?:.*)?}\s?-->.*(?:(?:<figcaption>(.*)</figcaption>).*)?<\!--\s?/wp:(?:core[-|/])?embed(?:/youtube)?\s?-->%Us';
748
+ $the_content = preg_replace( $gutenbeard_playlist_regex, '<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube">httpv://www.youtube.com/playlist?list=\1<figcaption>\2</figcaption></figure>', $the_content );
749
  }
750
  $gutenbeard_single_regex = '%<\!--\s?wp:(?:core[-|/])?embed(?:/youtube)?\s?{"url":"https?://(?:www\.)?youtu(?:be\.com/watch\?v=|.be/)(.*)"(?:.*)?}\s?-->.*(?:(?:<figcaption>(.*)</figcaption>).*)?<\!--\s?/wp:(?:core[-|/])?embed(?:/youtube)?\s?-->%Us';
751
+ $the_content = preg_replace( $gutenbeard_single_regex, '<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube">httpv://www.youtube.com/watch?v=\1<figcaption>\2</figcaption></figure>', $the_content );
752
  }
753
 
754
  // do the most of the greedy part early.
755
+ if ( get_option( 'lyte_greedy', '1' ) === '1' && strpos( $the_content, 'youtu' ) !== false ) {
756
  // only preg_replace if "youtu" (as part of youtube.com or youtu.be) is found.
757
  if ( strpos( $the_content, '/playlist?list=' ) !== false ) {
758
  // only preg_replace for playlists if there are playlists to be parsed.
771
  if ( ! defined( 'LYTE_CACHE_DIR' ) ) {
772
  define( 'LYTE_CACHE_DIR', WP_CONTENT_DIR .'/cache/lyteCache' );
773
  }
774
+ if ( ! file_exists( LYTE_CACHE_DIR ) ) {
775
+ // create LYTE cache dir (and index.html) if it doesn't exist yet.
776
+ @mkdir( LYTE_CACHE_DIR, 0775, true );
777
+ @file_put_contents( LYTE_CACHE_DIR . '/index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/wp-youtube-lyte/" rel="nofollow">WP YouTube Lyte</a></body></html>' );
778
+ }
779
 
780
+ $_doublecheck_activator_file = LYTE_CACHE_DIR . '/doubleCheckLyteThumbnailCache.txt';
781
  if ( ( get_option( 'lyte_local_thumb', '0' ) === '1' && apply_filters( 'lyte_filter_local_thumb_doublecheck', false ) ) || get_option( 'lyte_local_thumb', '0' ) !== '1' ) {
782
  if ( ! file_exists( $_doublecheck_activator_file ) ) {
 
 
 
 
 
783
  // file needed but not found, create it.
784
  @file_put_contents( $_doublecheck_activator_file, 'This file is used to ensure lyteCache.php is not abused (prevent hotlinking of cached YouTube thumbnails or lyteCache.php being accessed when local thumbnail caching is not active).' );
785
  }
787
  // file exists but not needed (any more), delete it.
788
  @unlink( $_doublecheck_activator_file );
789
  }
790
+
791
+ $_disable_thumb_fallback_file = LYTE_CACHE_DIR . '/disableThumbFallback.txt';
792
+ if ( ( get_option( 'lyte_local_thumb', '0' ) === '1' && apply_filters( 'lyte_filter_disable_thumb_fallback', false ) ) || get_option( 'lyte_local_thumb', '0' ) !== '1' ) {
793
+ if ( ! file_exists( $_disable_thumb_fallback_file ) ) {
794
+ // file needed but not found, create it.
795
+ @file_put_contents( $_disable_thumb_fallback_file, 'This file is used to ensure lyteCache.php will never redirect the client to the YouTube servers, even if there is an error serving or caching the thumbnail).' );
796
+ }
797
+ } elseif ( file_exists( $_disable_thumb_fallback_file ) ) {
798
+ // file exists but not needed (any more), delete it.
799
+ @unlink( $_disable_thumb_fallback_file );
800
+ }
801
  }
802
 
803
  /** hooking it all up to wordpress */
806
  add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'lyte_add_action_link' );
807
  add_action( 'admin_init', 'lytecache_doublecheck_activator' );
808
  } else {
809
+ add_filter( 'the_content', 'lyte_prepare', 4 );
810
+ add_filter( 'the_content', 'lyte_parse', 10 );
811
+ add_shortcode( 'lyte', 'shortcode_lyte' );
812
+ remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
813
+ add_filter( 'get_the_excerpt', 'lyte_trim_excerpt' );
 
814
  add_action( 'init', 'lytecache_doublecheck_activator' );
815
 
816
  /** API: action hook to allow extra actions or filters to be added */
817
+ do_action('lyte_actionsfilters');
818
  }
819
  ?>