WP YouTube Lyte - Version 1.7.0

Version Description

  • new: option to have thumbnail hosted locally to improve performance and privacy (I am not a lawyer, but this could make embedded YouTube GDPR compliant as not requests are sent to YouTube unless/ until the video is played).
  • removed option to add "easy youtube"-links (defunct)
  • make widgets not break HTTPS (thanks R33D3M33R)
Download this release

Release Info

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

Code changes from version 1.6.8 to 1.7.0

Files changed (6) hide show
  1. lyteThumbs.php +182 -0
  2. lyte_helper.php_example +113 -113
  3. options.php +15 -3
  4. readme.txt +24 -28
  5. widget.php +16 -9
  6. wp-youtube-lyte.php +11 -9
lyteThumbs.php ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * simple proxy for YouTube images
4
+ *
5
+ * @param string origThumbUrl
6
+ * @return image
7
+ *
8
+ * assumption 1: thumbnails are served from known domain ("ytimg.com","youtube.com","youtu.be")
9
+ * assumption 2: thumbnails are always jpg
10
+ *
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
18
+ */
19
+
20
+ if ( ! defined( 'LYTE_CACHE_DIR' ) ) {
21
+ define( 'WP_CONTENT_DIR', dirname( dirname( __DIR__ ) ) );
22
+ define( 'LYTE_CACHE_CHILD_DIR', 'cache/lyteThumbs' );
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
+ /*
32
+ * step 1: get vid ID (or full thumbnail URL) from request and validate
33
+ */
34
+
35
+ // should we output debug info in a header?
36
+ if ( array_key_exists("reportErr", $_GET) ) {
37
+ $lyte_thumb_report_err = true;
38
+ }
39
+
40
+ // get thumbnail-url from request
41
+ if ( array_key_exists("origThumbUrl", $_GET) && $_GET["origThumbUrl"] !== "" ) {
42
+ $origThumbURL = urldecode($_GET["origThumbUrl"]);
43
+ } else {
44
+ // faulty request, force a grey background
45
+ $origThumbURL = "https://i.ytimg.com/vi/thisisnotavalidvid/hqdefault.jpg";
46
+ }
47
+
48
+ // make sure the thumbnail-url is for youtube
49
+ $origThumbDomain = parse_url($origThumbURL, PHP_URL_HOST);
50
+ if ( str_replace( array("ytimg.com","youtube.com","youtu.be"), "", $origThumbDomain ) === $origThumbDomain ) {
51
+ // faulty request, force a grey background
52
+ $origThumbURL = "https://i.ytimg.com/vi/thisisnotavalidvid/hqdefault.jpg";
53
+ }
54
+
55
+ // make sure the thumbnail-url is for an image (.jpg)
56
+ $origThumbPath = parse_url($origThumbURL, PHP_URL_PATH);
57
+ if ( lyte_str_ends_in( $origThumbPath, ".jpg" ) !== true ) {
58
+ // faulty request, force a grey background
59
+ $origThumbURL = "https://i.ytimg.com/vi/thisisnotavalidvid/hqdefault.jpg";
60
+ }
61
+
62
+ // TODO: extra checks to prevent automated hotlinking abuse?
63
+
64
+ /*
65
+ * step 2: check for and if need be create wp-content/cache/lyte_thumbs
66
+ */
67
+
68
+ if ( lyte_check_cache_dir(LYTE_CACHE_DIR) === false ) {
69
+ $lyte_thumb_dontsave = true;
70
+ $lyte_thumb_error .= "checkcache fail/ ";
71
+ }
72
+
73
+ /*
74
+ * step 3: if not in cache: fetch from YT and store in cache
75
+ */
76
+
77
+ $localThumb = LYTE_CACHE_DIR . '/' . md5($origThumbURL) . ".jpg";
78
+
79
+ if ( !file_exists($localThumb) || $lyte_thumb_dontsave ) {
80
+ $thumbContents = lyte_get_thumb($origThumbURL);
81
+
82
+ if ( $thumbContents != "" && !$lyte_thumb_dontsave ) {
83
+ file_put_contents($localThumb, $thumbContents);
84
+ }
85
+ }
86
+
87
+ /*
88
+ * step 4: serve img
89
+ */
90
+
91
+ if ( $thumbContents == "" && !$lyte_thumb_dontsave && file_exists($localThumb) && mime_content_type($localThumb) === "image/jpeg" ) {
92
+ $thumbContents = file_get_contents( $localThumb );
93
+ } else {
94
+ $lyte_thumb_error .= "not from cache/ ";
95
+ }
96
+
97
+ if ( $thumbContents != "") {
98
+ if ( $lyte_thumb_error !== "" && $lyte_thumb_report_err ) {
99
+ header('X-lyte-error: '.$lyte_thumb_error);
100
+ }
101
+ header('Content-type:image/jpeg');
102
+ echo $thumbContents;
103
+ } else {
104
+ $lyte_thumb_error .= "no thumbContent/ ";
105
+ lyte_thumb_fallback();
106
+ }
107
+
108
+ /*
109
+ * helper functions
110
+ */
111
+
112
+ function lyte_check_cache_dir( $dir ) {
113
+ // Try creating the dir if it doesn't exist.
114
+ if ( ! file_exists( $dir ) ) {
115
+ @mkdir( $dir, 0775, true );
116
+ if ( ! file_exists( $dir ) ) {
117
+ return false;
118
+ }
119
+ }
120
+
121
+ // If we still cannot write, bail.
122
+ if ( ! is_writable( $dir ) ) {
123
+ return false;
124
+ }
125
+
126
+ // Create an index.html in there to avoid prying eyes!
127
+ $idx_file = rtrim( $dir, '/\\' ) . '/index.html';
128
+ if ( ! is_file( $idx_file ) ) {
129
+ @file_put_contents( $idx_file, '<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>' );
130
+ }
131
+
132
+ return true;
133
+ }
134
+
135
+ function lyte_str_ends_in($haystack,$needle) {
136
+ $needleLength = strlen($needle);
137
+ $haystackLength = strlen($haystack);
138
+ $lastPos=strrpos($haystack,$needle);
139
+ if ($lastPos === $haystackLength - $needleLength) {
140
+ return true;
141
+ } else {
142
+ return false;
143
+ }
144
+ }
145
+
146
+ function lyte_get_thumb($thumbUrl) {
147
+ global $lyte_thumb_error;
148
+ if (function_exists("curl_init")) {
149
+ $curl = curl_init();
150
+ curl_setopt($curl, CURLOPT_URL, $thumbUrl);
151
+ curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
152
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
153
+ curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
154
+ $str = curl_exec($curl);
155
+ $err = curl_error($curl);
156
+ curl_close($curl);
157
+ if ( !$err && $str != "" ) {
158
+ return $str;
159
+ } else {
160
+ $lyte_thumb_error .= "curl err/ ";
161
+ }
162
+ } else {
163
+ $lyte_thumb_error .= "no curl/ ";
164
+ }
165
+
166
+ // if no curl or if curl error
167
+ $resp = file_get_contents($thumbUrl);
168
+ return $resp;
169
+ }
170
+
171
+ function lyte_thumb_fallback() {
172
+ global $origThumbURL, $lyte_thumb_error;
173
+ // if for any reason we can't show a local thumbnail, we redirect to the original one
174
+ if ( strpos( $origThumbURL, "http" ) !== 0) {
175
+ $origThumbURL = "https:".$origThumbURL;
176
+ }
177
+ if ( $lyte_thumb_report_err ) {
178
+ header('X-lyte-error: '.$lyte_thumb_error);
179
+ }
180
+ header('HTTP/1.1 301 Moved Permanently');
181
+ header('Location: '. $origThumbURL );
182
+ }
lyte_helper.php_example CHANGED
@@ -1,113 +1,113 @@
1
- <?php
2
- /*
3
- Plugin Name: Lyte Helper
4
- Plugin URI: http://blog.futtta.be/category/wp-youtube-lyte/
5
- Description: Lyte Helper contains some helper functions to make WP YouTube Lyte even more flexible
6
- Author: Frank Goossens (futtta)
7
- Version: 0.2
8
- Author URI: http://blog.futtta.be/
9
- */
10
-
11
- /**
12
- available filter hooks: lyte_settings, lyte_content_preparse, lyte_match_preparse_fragment, lyte_match_postparse_template, lyte_content_postparse, lyte_css, lyte_docaptions, lyte_match_thumburl
13
- available action hooks; lyte_actionsfilters
14
- */
15
-
16
- /** force widget text to be parsed as well using lyte_actionsfilters action */
17
- // add_action('lyte_actionsfilters','lyte_force_widgets',10,0);
18
- function lyte_force_widgets() {
19
- add_filter('widget_text', 'lyte_parse', 4);
20
- }
21
-
22
- /** force wp youtube lyte to act on normal youtube url's as well using lyte_content_preparse filter */
23
- // add_filter('lyte_content_preparse','lyte_force_nonhttpv',10,1);
24
- function lyte_force_nonhttpv($content) {
25
- $content=preg_replace('/^https?:\/\/(www.)?youtu(be.com|.be)\/(watch\?v=)?/m','httpv://www.youtube.com/watch?v=',$content);
26
- return $content;
27
- }
28
-
29
- /** force hqThumb for all lytes using lyte_match_preparse_fragment */
30
- // add_filter('lyte_match_preparse_fragment','lyte_force_hqthumb',10,1);
31
- function lyte_force_hqthumb($httpv) {
32
- if (strpos($httpv,"hqThumb")===FALSE) {
33
- if (strpos($httpv,"#")===FALSE) {
34
- $httpv.="#hqThumb=1";
35
- } else {
36
- $httpv.="&hqThumb=1";
37
- }
38
- }
39
- return $httpv;
40
- }
41
-
42
- /** force showinfo=0 for all lytes using lyte_match_preparse_fragment filter */
43
- // add_filter('lyte_match_preparse_fragment','lyte_force_noinfo',10,1);
44
- function lyte_force_noinfo($httpv) {
45
- if (strpos($httpv,"showinfo")===FALSE) {
46
- if (strpos($httpv,"#")===FALSE) {
47
- $httpv.="#showinfo=0";
48
- } else {
49
- $httpv.="&showinfo=0";
50
- }
51
- }
52
- return $httpv;
53
- }
54
-
55
- /** add clickable video thumbnail to excerpt.*/
56
- // add_filter('lyte_match_postparse_template','lyte_override_excerpt_template',10,2);
57
- function lyte_override_excerpt_template($content,$type) {
58
- global $lyteSettings, $vid, $postID;
59
- if ($type==="excerpt") {
60
- $content = "<a href=\"".get_permalink( $postID )."\"><img src=\"".$lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg\" alt=\"YouTube Video\"></a>";
61
- }
62
- return $content;
63
- }
64
-
65
- /** change setting from within code using lyte_settings filter */
66
- // add_filter('lyte_settings','lyte_change_settings',10,1);
67
- function lyte_change_settings($settingsArray) {
68
- $settingsArray['links']="0";
69
- return $settingsArray;
70
- }
71
-
72
- /** disable captions lookup */
73
- // add_filter('lyte_docaptions','lyte_nocaptions',10,0);
74
- function lyte_nocaptions() {
75
- return false;
76
- }
77
-
78
- /** force lyte javascript (which includes css) to be loaded in head instead of footer */
79
- // lyte_force_jshead();
80
- function lyte_force_jshead() {
81
- add_filter('wp_head', lyte_init);
82
- global $lynited;
83
- $lynited=true;
84
- }
85
-
86
- /** function to filter out httpv/a links from description tag as generated by all in one seo pack */
87
- // add_filter('aioseop_description','lyte_filter_aioseop_description');
88
- function lyte_filter_aioseop_description($description) {
89
- return preg_replace('/\shttp(v|a):\/\/([^\s<]*)/','',$description);
90
- }
91
-
92
- /** function to override thumbnail used for a video */
93
- // add_filter('lyte_match_thumburl','lyte_my_own_thumburl');
94
- function lyte_my_own_thumburl($thumb) {
95
- return "http://images.vrt.be/mobile320/2014/08/05/8570f3aa-1c9e-11e4-b923-00163edf75b7.jpg";
96
- }
97
-
98
- /** change lyte css, for example to load Robota fond and force bottom control visible */
99
- // add_filter('lyte_css','fgo_lyte_change_css',10,1);
100
- function fgo_lyte_change_css($lyte_css) {
101
- // import robota
102
- $lyte_css="@import url(https://fonts.googleapis.com/css?family=Roboto&subset=latin,latin-ext);".$lyte_css;
103
- // show bottom control
104
- $lyte_css.=" .ctrl{display:block !important;}";
105
- return $lyte_css;
106
- }
107
-
108
- /** don't do lyte on mobile to avoid users having to press play twice */
109
- // add_filter('lyte_do_mobile','no_lyte_on_mobile',10,0);
110
- function no_lyte_on_mobile(){
111
- return false;
112
- }
113
- ?>
1
+ <?php
2
+ /*
3
+ Plugin Name: Lyte Helper
4
+ Plugin URI: http://blog.futtta.be/category/wp-youtube-lyte/
5
+ Description: Lyte Helper contains some helper functions to make WP YouTube Lyte even more flexible
6
+ Author: Frank Goossens (futtta)
7
+ Version: 0.2
8
+ Author URI: http://blog.futtta.be/
9
+ */
10
+
11
+ /**
12
+ available filter hooks: lyte_settings, lyte_content_preparse, lyte_match_preparse_fragment, lyte_match_postparse_template, lyte_content_postparse, lyte_css, lyte_docaptions, lyte_match_thumburl
13
+ available action hooks; lyte_actionsfilters
14
+ */
15
+
16
+ /** force widget text to be parsed as well using lyte_actionsfilters action */
17
+ // add_action('lyte_actionsfilters','lyte_force_widgets',10,0);
18
+ function lyte_force_widgets() {
19
+ add_filter('widget_text', 'lyte_parse', 4);
20
+ }
21
+
22
+ /** force wp youtube lyte to act on normal youtube url's as well using lyte_content_preparse filter */
23
+ // add_filter('lyte_content_preparse','lyte_force_nonhttpv',10,1);
24
+ function lyte_force_nonhttpv($content) {
25
+ $content=preg_replace('/^https?:\/\/(www.)?youtu(be.com|.be)\/(watch\?v=)?/m','httpv://www.youtube.com/watch?v=',$content);
26
+ return $content;
27
+ }
28
+
29
+ /** force hqThumb for all lytes using lyte_match_preparse_fragment */
30
+ // add_filter('lyte_match_preparse_fragment','lyte_force_hqthumb',10,1);
31
+ function lyte_force_hqthumb($httpv) {
32
+ if (strpos($httpv,"hqThumb")===FALSE) {
33
+ if (strpos($httpv,"#")===FALSE) {
34
+ $httpv.="#hqThumb=1";
35
+ } else {
36
+ $httpv.="&hqThumb=1";
37
+ }
38
+ }
39
+ return $httpv;
40
+ }
41
+
42
+ /** force showinfo=0 for all lytes using lyte_match_preparse_fragment filter */
43
+ // add_filter('lyte_match_preparse_fragment','lyte_force_noinfo',10,1);
44
+ function lyte_force_noinfo($httpv) {
45
+ if (strpos($httpv,"showinfo")===FALSE) {
46
+ if (strpos($httpv,"#")===FALSE) {
47
+ $httpv.="#showinfo=0";
48
+ } else {
49
+ $httpv.="&showinfo=0";
50
+ }
51
+ }
52
+ return $httpv;
53
+ }
54
+
55
+ /** add clickable video thumbnail to excerpt.*/
56
+ // add_filter('lyte_match_postparse_template','lyte_override_excerpt_template',10,2);
57
+ function lyte_override_excerpt_template($content,$type) {
58
+ global $lyteSettings, $vid, $postID;
59
+ if ($type==="excerpt") {
60
+ $content = "<a href=\"".get_permalink( $postID )."\"><img src=\"".$lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg\" alt=\"YouTube Video\"></a>";
61
+ }
62
+ return $content;
63
+ }
64
+
65
+ /** change setting from within code using lyte_settings filter */
66
+ // add_filter('lyte_settings','lyte_change_settings',10,1);
67
+ function lyte_change_settings($settingsArray) {
68
+ $settingsArray['links']="0";
69
+ return $settingsArray;
70
+ }
71
+
72
+ /** disable captions lookup */
73
+ // add_filter('lyte_docaptions','lyte_nocaptions',10,0);
74
+ function lyte_nocaptions() {
75
+ return false;
76
+ }
77
+
78
+ /** force lyte javascript (which includes css) to be loaded in head instead of footer */
79
+ // lyte_force_jshead();
80
+ function lyte_force_jshead() {
81
+ add_filter('wp_head', lyte_init);
82
+ global $lynited;
83
+ $lynited=true;
84
+ }
85
+
86
+ /** function to filter out httpv/a links from description tag as generated by all in one seo pack */
87
+ // add_filter('aioseop_description','lyte_filter_aioseop_description');
88
+ function lyte_filter_aioseop_description($description) {
89
+ return preg_replace('/\shttp(v|a):\/\/([^\s<]*)/','',$description);
90
+ }
91
+
92
+ /** function to override thumbnail used for a video */
93
+ // add_filter('lyte_match_thumburl','lyte_my_own_thumburl');
94
+ function lyte_my_own_thumburl($thumb) {
95
+ return "http://images.vrt.be/mobile320/2014/08/05/8570f3aa-1c9e-11e4-b923-00163edf75b7.jpg";
96
+ }
97
+
98
+ /** change lyte css, for example to load Robota fond and force bottom control visible */
99
+ // add_filter('lyte_css','fgo_lyte_change_css',10,1);
100
+ function fgo_lyte_change_css($lyte_css) {
101
+ // import robota
102
+ $lyte_css="@import url(https://fonts.googleapis.com/css?family=Roboto&subset=latin,latin-ext);".$lyte_css;
103
+ // show bottom control
104
+ $lyte_css.=" .ctrl{display:block !important;}";
105
+ return $lyte_css;
106
+ }
107
+
108
+ /** don't do lyte on mobile to avoid users having to press play twice */
109
+ // add_filter('lyte_do_mobile','no_lyte_on_mobile',10,0);
110
+ function no_lyte_on_mobile(){
111
+ return false;
112
+ }
113
+ ?>
options.php CHANGED
@@ -56,6 +56,7 @@ function register_lyte_settings() {
56
  register_setting( 'lyte-settings-group', 'lyte_emptycache' );
57
  register_setting( 'lyte-settings-group', 'lyte_greedy' );
58
  register_setting( 'lyte-settings-group', 'lyte_yt_api_key' );
 
59
  }
60
 
61
  function lyte_admin_scripts() {
@@ -215,8 +216,7 @@ function lyte_settings_page() {
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") echo "checked" ?> /><?php _e(" Add YouTube-link.","wp-youtube-lyte") ?></label><br />
219
- <label title="<?php _e('Show YouTube and Ease YouTube link','wp-youtube-lyte');?>"><input type="radio" name="lyte_show_links" value="2" <?php if (get_option('lyte_show_links')==="2") echo "checked" ?> /><?php _e(" Add both a YouTube and an <a href=\"http://icant.co.uk/easy-youtube/docs/index.html\" target=\"_blank\">Easy YouTube</a>-link.","wp-youtube-lyte") ?></label><br />
220
  <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>
221
  </fieldset>
222
  </td>
@@ -232,7 +232,7 @@ function lyte_settings_page() {
232
  </td>
233
  </tr>
234
  <tr valign="top">
235
- <th scope="row"><?php _e("Try to force HD (experimental)?","wp-youtube-lyte") ?></th>
236
  <td>
237
  <fieldset>
238
  <legend class="screen-reader-text"><span><?php _e("HD or not?","wp-youtube-lyte"); ?></span></legend>
@@ -261,6 +261,18 @@ function lyte_settings_page() {
261
  </fieldset>
262
  </td>
263
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
264
  <tr valign="top">
265
  <th scope="row"><?php _e("Empty WP YouTube Lyte's cache","wp-youtube-lyte") ?></th>
266
  <td>
56
  register_setting( 'lyte-settings-group', 'lyte_emptycache' );
57
  register_setting( 'lyte-settings-group', 'lyte_greedy' );
58
  register_setting( 'lyte-settings-group', 'lyte_yt_api_key' );
59
+ register_setting( 'lyte-settings-group', 'lyte_local_thumb' );
60
  }
61
 
62
  function lyte_admin_scripts() {
216
  <td>
217
  <fieldset>
218
  <legend class="screen-reader-text"><span><?php _e("Show links?","wp-youtube-lyte") ?></span></legend>
219
+ <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 />
 
220
  <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>
221
  </fieldset>
222
  </td>
232
  </td>
233
  </tr>
234
  <tr valign="top">
235
+ <th scope="row"><?php _e("Try to force HD?","wp-youtube-lyte") ?></th>
236
  <td>
237
  <fieldset>
238
  <legend class="screen-reader-text"><span><?php _e("HD or not?","wp-youtube-lyte"); ?></span></legend>
261
  </fieldset>
262
  </td>
263
  </tr>
264
+ <tr valign="top">
265
+ <th scope="row"><?php _e("Cache thumbnails locally?","wp-youtube-lyte"); ?> (beta)</th>
266
+ <td>
267
+ <fieldset>
268
+ <legend class="screen-reader-text"><span><?php _e("Cache thumbnails locally?","wp-youtube-lyte") ?></span></legend>
269
+ <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 />
270
+ <label title="<?php _e('No, I\'ll stick to httpv or shortcodes.','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>
271
+ <br />
272
+ <?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"); ?>
273
+ </fieldset>
274
+ </td>
275
+ </tr>
276
  <tr valign="top">
277
  <th scope="row"><?php _e("Empty WP YouTube Lyte's cache","wp-youtube-lyte") ?></th>
278
  <td>
readme.txt CHANGED
@@ -1,18 +1,18 @@
1
  === WP YouTube Lyte ===
2
  Contributors: futtta, optimizingmatters
3
- Tags: youtube, video, lyte, lite youtube embeds, html5 video, widget, youtube audio, audio, playlist, performance, accessibility, sidebar, lazy load, responsive, microdata, videoobject
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: 4.9
7
- Stable tag: 1.6.8
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
11
  == Description ==
12
 
13
- WP YouTube Lyte allows you to "lazy load" your video's, by inserting responsive "Lite YouTube Embeds". These look and feel like normal embedded YouTube, but only call the actual "fat" Flash or HTML5-player when clicked on, thereby [reducing download size & rendering time substantially](http://blog.futtta.be/2012/04/03/speed-matters-re-evaluating-wp-youtube-lytes-performance/) when embedding YouTube occasionally and improving page performance dramatically when you've got multiple YouTube video's on one and the same page.
14
 
15
- Just add a YouTube-link for a video or [an entire playlist](http://blog.futtta.be/2011/10/11/wp-youtube-lyte-support-for-playlists-almost-included/) with "httpv" (or "httpa" to [embed YouTube's audio](http://blog.futtta.be/2011/04/19/audio-only-youtube-embedding-with-wp-youtube-lyte-0-7/) only) instead of "http" or add a Lyte widget to your sidebar and WP YouTube Lyte replaces that link with the correct performance-optimized code. When a visitor clicks the play-button, WP YouTube Lyte seamlessly initiates [YouTube's new embedded player](http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html). Some examples:
16
 
17
  * httpv://www.youtube.com/watch?v=_SQkWbRublY (normal video embed)
18
  * httpv://youtu.be/_SQkWbRublY (video embed with youtube-shortlink)
@@ -26,8 +26,6 @@ Or using shortcodes:
26
  `[lyte id="_SQkWbRublY" audio="true" /]`
27
  `[lyte id="A486E741B25F8E00" playlist="true" /]`
28
 
29
- As from 1.5.0 WP YouTube Lyte can also parse normal YouTube links (i.e. without httpv or not using lyte shortcodes). This feature can be enabled and disabled in the settings-page.
30
-
31
  WP YouTube Lyte has been written with optimal performance as primary goal, but has been tested for maximum browser-compatibility (iPad included) while keeping an eye on accessibility. Starting with version 1.2.0 lyte embeds are fully responsive and can automatically embed [videoObject microdata](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=2413309) as well. The plugin is fully multi-language, with support for Catalan, Dutch, English, French, German, Hebrew, Romanian, Spanish and Slovene.
32
 
33
  Feedback is welcome; see [info in the faq](http://wordpress.org/extend/plugins/wp-youtube-lyte/faq/) for bug reports/ feature requests and feel free to [rate and/or report on compatibility on wordpress.org](http://wordpress.org/extend/plugins/wp-youtube-lyte/).
@@ -54,25 +52,23 @@ Up until WP YouTube Lyte 1.5.0 the v2 YouTube API was used, but [in September 20
54
 
55
  2. Click on 'Create Project' and:
56
  * Fill in a Project Name
 
57
  * Click on 'Create'
58
- * Wait while the project is created (see throbber in the top right corner) until a notification confirms project creation
59
 
60
- 3. Refresh the project list (or select the new project from the notification)
61
- On the next page (or when there is no next page, click on your Project's name):
62
- * Click on 'API's and services
63
- * Click on 'enable APi's and services
64
- * Fill out "YouTube" in the search field
65
- * Find "YouTube Data API v3" and click on it
66
- * Click on "Enable"
67
 
68
  4. In the sidebar on the left:
69
- * Click on 'Create credentials'
70
- * Select "Web Server" in the dropdown under "Where will you be calling the API from"
71
- * Select "Public data" in the dropdown under "What data will you be accessing"
72
- * Click on "What credentials do I need"
73
- * Copy the resulting API key (without setting restrictions, which could cause the key not to work)
74
 
75
- 5. Paste the API key on WP YouTube Lyte settings page.
76
 
77
  = Will WP YouTube Lyte work if I don't provide an API key? =
78
  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.
@@ -89,7 +85,7 @@ When playing, HTML5 video will not be visible for everyone (see requirements). I
89
  * Browsers that don't support those codecs will, upon playing, fall back to Flash.
90
 
91
  = Does WP YouTube Lyte protect my visitor's privacy? =
92
- As opposed to some of the [most important](http://blog.futtta.be/2010/12/15/wordpress-com-stats-trojan-horse-for-quantcast-tracking/) [plugins](http://blog.futtta.be/2010/01/22/add-to-any-removed-from-here/) there is no 3rd party tracking code in WP YouTube Lyte, but YouTube off course does see visitor requests coming in (see also the youtube-nocookie.com remark in Bugs/Issues below) for the thumbnails.
93
 
94
  = Can I use WP YouTube Lyte for a custom field? =
95
  Just pass the httpv url of such a field to lyte_preparse like this:
@@ -122,9 +118,6 @@ Yes, starting with version 1.5.0 normal YouTube links are automatically transfer
122
  = What can I do with the API? =
123
  A whole lot; there are filters to pre-parse the_content, to change settings, to change the CSS, to change the HTML of the LYTE-div, ... There are examples for all filters (and one action) in lyte_helper.php_example
124
 
125
- = How can I use/ activate lyte_helper.php_example? =
126
- Copy it to /wp-content/plugins/lyte_helper.php and activate it in WordPress' plugin page. After that you can simple remove the one of the comment-sequences (double-slash) to activate one (or more) of the functions in there.
127
-
128
  = Problem with All In One Seo Pack =
129
  All in One SEO Pack be default generates a description which still has httpv-links in it. To remove those, you'll have to use (example code in) lyte_helper.php (see above) and add lyte_filter_aioseop_description to the aioseop-filter in there.
130
 
@@ -132,7 +125,7 @@ All in One SEO Pack be default generates a description which still has httpv-lin
132
  You probably added a link around the httpv-url. No link is needed, just the httpv-url.
133
 
134
  = My video's seem to load slower on mobile devices? =
135
- By default WP YouTube Lyte will indeed load slower normal YouTube video's instead of Lyte ones, as Lyte video's require would require two clicks from the user to play a video (once to load the YouTube video and once to start it) because there is no autoplay-support on mobile. If you want to, you can force WP YouTube Lyte to make video's Lyte on mobile with this code (add it in your child theme's functions.php, in a seperate helper plugin or using the [code snippets plugin](https://wordpress.org/plugins/code-snippets/);
136
 
137
  `
138
  add_filter('lyte_do_mobile','lyte_on_mobile',10,0);
@@ -141,11 +134,9 @@ function lyte_on_mobile(){
141
  }
142
  `
143
 
144
- = Any bugs/ issues should I know about? =
145
  * Although the widget is available in (very) small sizes, these do not display that great and might, in the near future, be disabled by YouTube as their Terms of Service state that the smallest available embedded player is 200X200 pixels. Use the deprecated smaller sizes at your own risk.
146
  * Having the same YouTube-video on one page can cause WP YouTube Lyte to malfunction (as the YouTube id is used as the div's id in the DOM, and DOM id's are supposed to be unique)
147
- * When using the Firefox plugin Karma Blocker, the [video isn't visible when clicking "play", with a warning message being shown instead](http://blog.futtta.be/?p=7584). This is expected behavior and should be solved by tweaking Karma Blocker's configuration.
148
- * The translations have not been updated entirely for version 1.2.0 and later. Help with translations is high on my wish-list, [contact me if you are interested to help](http://blog.futtta.be/contact)!
149
 
150
  = I found a bug/ I would like a feature to be added! =
151
  Just tell me, I like the feedback! Use the [Contact-page on my blog](http://blog.futtta.be/contact/), [leave a comment in a post about wp-youtube-lyte](http://blog.futtta.be/tag/wp-youtube-lyte/) or [create a new topic on the wordpress.org forum](http://wordpress.org/tags/wp-youtube-lyte?forum_id=10#postform).
@@ -157,6 +148,11 @@ Just tell me, I like the feedback! Use the [Contact-page on my blog](http://blog
157
 
158
  == Changelog ==
159
 
 
 
 
 
 
160
  = 1.6.8 =
161
  * new: support for Gutenberg blocks with embedded YouTube (tested with Gutenberg plugin version 2.3.0)
162
  * updated admin screen
1
  === WP YouTube Lyte ===
2
  Contributors: futtta, optimizingmatters
3
+ 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: 4.9
7
+ Stable tag: 1.7.0
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
11
  == Description ==
12
 
13
+ WP YouTube Lyte allows you to "lazy load" your video's, by inserting responsive "Lite YouTube Embeds". These look and feel like normal embedded YouTube, but only call the "fat" YouTube-player when clicked on, thereby [reducing download size & rendering time substantially](http://blog.futtta.be/2012/04/03/speed-matters-re-evaluating-wp-youtube-lytes-performance/) when embedding YouTube occasionally and improving page performance dramatically when you've got multiple YouTube video's on one and the same page. The plugin can be configured to cache YouTube thumbnails locally, improving both performance and privacy. As such LYTE embedded YouTube videos do not require requests to the YouTube servers, probably (I am not a lawyer) allowing for better GDPR-compliance.
14
 
15
+ The plugin picks up on normal YouTube links, taking over from WordPress core's oEmbed. Alternatively you can add a YouTube-link for a video or [an entire playlist](http://blog.futtta.be/2011/10/11/wp-youtube-lyte-support-for-playlists-almost-included/) with "httpv" instead of "http(s)" or add a Lyte widget to your sidebar and WP YouTube Lyte replaces that link with the correct performance-optimized code. Some examples:
16
 
17
  * httpv://www.youtube.com/watch?v=_SQkWbRublY (normal video embed)
18
  * httpv://youtu.be/_SQkWbRublY (video embed with youtube-shortlink)
26
  `[lyte id="_SQkWbRublY" audio="true" /]`
27
  `[lyte id="A486E741B25F8E00" playlist="true" /]`
28
 
 
 
29
  WP YouTube Lyte has been written with optimal performance as primary goal, but has been tested for maximum browser-compatibility (iPad included) while keeping an eye on accessibility. Starting with version 1.2.0 lyte embeds are fully responsive and can automatically embed [videoObject microdata](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=2413309) as well. The plugin is fully multi-language, with support for Catalan, Dutch, English, French, German, Hebrew, Romanian, Spanish and Slovene.
30
 
31
  Feedback is welcome; see [info in the faq](http://wordpress.org/extend/plugins/wp-youtube-lyte/faq/) for bug reports/ feature requests and feel free to [rate and/or report on compatibility on wordpress.org](http://wordpress.org/extend/plugins/wp-youtube-lyte/).
52
 
53
  2. Click on 'Create Project' and:
54
  * Fill in a Project Name
55
+ * Fill in a Project ID
56
  * Click on 'Create'
 
57
 
58
+ 3. On the next page (or when there is no next page, click on your Project's name):
59
+ * Click on 'Enable an API'
60
+ * Scroll down to YouTube Data API v3 and click on it
61
+ * Click on 'OFF' at the top to enable the API
62
+ * Optionally disable other API's
 
 
63
 
64
  4. In the sidebar on the left:
65
+ * Click on 'Credentials'
66
+ * Click on 'Create new Key'
67
+ * Click on 'Server Key'
68
+ * Leave the box with whitelisted IP's empty
69
+ * Click on 'Create'
70
 
71
+ 5. Copy your API key to WP YouTube Lyte settings page.
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.
85
  * Browsers that don't support those codecs will, upon playing, fall back to Flash.
86
 
87
  = Does WP YouTube Lyte protect my visitor's privacy? =
88
+ As opposed to some of the [most important](http://blog.futtta.be/2010/12/15/wordpress-com-stats-trojan-horse-for-quantcast-tracking/) [plugins](http://blog.futtta.be/2010/01/22/add-to-any-removed-from-here/) there is no 3rd party tracking code in WP YouTube Lyte, but YouTube off course does see visitor requests coming in for the thumbnails unless the option to cache thumbnails locally is enabled. If thumbnails are cached locally, no request will be sent to YouTube by your visitor's browser until/ unless the video is played.
89
 
90
  = Can I use WP YouTube Lyte for a custom field? =
91
  Just pass the httpv url of such a field to lyte_preparse like this:
118
  = What can I do with the API? =
119
  A whole lot; there are filters to pre-parse the_content, to change settings, to change the CSS, to change the HTML of the LYTE-div, ... There are examples for all filters (and one action) in lyte_helper.php_example
120
 
 
 
 
121
  = Problem with All In One Seo Pack =
122
  All in One SEO Pack be default generates a description which still has httpv-links in it. To remove those, you'll have to use (example code in) lyte_helper.php (see above) and add lyte_filter_aioseop_description to the aioseop-filter in there.
123
 
125
  You probably added a link around the httpv-url. No link is needed, just the httpv-url.
126
 
127
  = My video's seem to load slower on mobile devices? =
128
+ By default (unless "cache thumbnail locally" is active) WP YouTube Lyte will indeed load slower normal YouTube video's instead of Lyte ones, as Lyte video's require would require two clicks from the user to play a video (once to load the YouTube video and once to start it) because there is no autoplay-support on mobile. If you want to, you can force WP YouTube Lyte to make video's Lyte on mobile with this code (add it in your child theme's functions.php, in a seperate helper plugin or using the [code snippets plugin](https://wordpress.org/plugins/code-snippets/);
129
 
130
  `
131
  add_filter('lyte_do_mobile','lyte_on_mobile',10,0);
134
  }
135
  `
136
 
137
+ = Any other issues should I know about? =
138
  * Although the widget is available in (very) small sizes, these do not display that great and might, in the near future, be disabled by YouTube as their Terms of Service state that the smallest available embedded player is 200X200 pixels. Use the deprecated smaller sizes at your own risk.
139
  * Having the same YouTube-video on one page can cause WP YouTube Lyte to malfunction (as the YouTube id is used as the div's id in the DOM, and DOM id's are supposed to be unique)
 
 
140
 
141
  = I found a bug/ I would like a feature to be added! =
142
  Just tell me, I like the feedback! Use the [Contact-page on my blog](http://blog.futtta.be/contact/), [leave a comment in a post about wp-youtube-lyte](http://blog.futtta.be/tag/wp-youtube-lyte/) or [create a new topic on the wordpress.org forum](http://wordpress.org/tags/wp-youtube-lyte?forum_id=10#postform).
148
 
149
  == Changelog ==
150
 
151
+ = 1.7.0 =
152
+ * new: option to have thumbnail hosted locally to improve performance and privacy (I am not a lawyer, but this could make embedded YouTube GDPR compliant as not requests are sent to YouTube unless/ until the video is played).
153
+ * removed option to add "easy youtube"-links (defunct)
154
+ * make widgets not break HTTPS (thanks R33D3M33R)
155
+
156
  = 1.6.8 =
157
  * new: support for Gutenberg blocks with embedded YouTube (tested with Gutenberg plugin version 2.3.0)
158
  * updated admin screen
widget.php CHANGED
@@ -27,26 +27,33 @@ class WYLWidget extends WP_Widget {
27
  $wHeight = "38";
28
  }
29
 
30
- $WYLurl=str_replace("httpv://","http://",trim($instance['WYLurl']));
31
  $WYLqs=substr(strstr($WYLurl,'?'),1);
32
  parse_str($WYLqs,$WYLarr);
33
 
34
- if (strpos($WYLurl,'youtu.be')) {
35
- $WYLid=substr(parse_url($WYLurl,PHP_URL_PATH),1,11);
36
- $PLClass="";
37
- $WYLthumb="http://img.youtube.com/vi/".$WYLid."/mqdefault.jpg";
38
- } else {
39
  if (isset($WYLarr['v'])) {
40
  $WYLid=$WYLarr['v'];
41
  $PLClass="";
42
- $WYLthumb="http://img.youtube.com/vi/".$WYLid."/mqdefault.jpg";
43
  } else if (isset($WYLarr['list'])) {
44
  $WYLid=$WYLarr['list'];
45
  $yt_resp=lyte_get_YT_resp($WYLid,true,"","",true);
46
  $WYLthumb=$yt_resp["thumbUrl"];
47
  $PLClass=" playlist";
48
  }
49
- }
 
 
 
 
 
 
 
50
  $WYLthumb = apply_filters( "lyte_filter_widget_thumb", $WYLthumb, $WYLid );
51
 
52
  if (isset($WYLarr['start'])) $qsa="&amp;start=".$WYLarr['start'];
@@ -68,7 +75,7 @@ class WYLWidget extends WP_Widget {
68
  ?>
69
  <?php echo $before_widget; ?>
70
  <?php if ( $WYLtitle ) echo $before_title . $WYLtitle . $after_title; ?>
71
- <div class="lyte-wrapper<?php echo $wrapperClass; ?>" style="width:<?php echo $wSize[$WYLsize]['w']; ?>px; height:<?php echo $wHeight; ?>px; min-width:200px; max-width:100%;"><div class="lyMe<?php echo $PLClass; echo $audioClass; echo $qsaClass; ?>" id="<?php echo $WYL_dom_id; ?>"><div id="lyte_<?php echo $WYLid; ?>" data-src="<?php echo $WYLthumb;?>" class="pL"><div class="play"></div><div class="ctrl"><div class="Lctrl"></div></div></div></div><noscript><a href="http://youtu.be/<?php echo $WYLid;?>"><img src="<?php echo $WYLthumb; ?>" alt="" /></a></noscript></div>
72
  <div><?php echo $WYLtext ?></div>
73
  <?php echo $after_widget; ?>
74
  <?php
27
  $wHeight = "38";
28
  }
29
 
30
+ $WYLurl=str_replace("httpv://","https://",trim($instance['WYLurl']));
31
  $WYLqs=substr(strstr($WYLurl,'?'),1);
32
  parse_str($WYLqs,$WYLarr);
33
 
34
+ if (strpos($WYLurl,'youtu.be')) {
35
+ $WYLid=substr(parse_url($WYLurl,PHP_URL_PATH),1,11);
36
+ $PLClass="";
37
+ $WYLthumb="https://img.youtube.com/vi/".$WYLid."/mqdefault.jpg";
38
+ } else {
39
  if (isset($WYLarr['v'])) {
40
  $WYLid=$WYLarr['v'];
41
  $PLClass="";
42
+ $WYLthumb="https://img.youtube.com/vi/".$WYLid."/mqdefault.jpg";
43
  } else if (isset($WYLarr['list'])) {
44
  $WYLid=$WYLarr['list'];
45
  $yt_resp=lyte_get_YT_resp($WYLid,true,"","",true);
46
  $WYLthumb=$yt_resp["thumbUrl"];
47
  $PLClass=" playlist";
48
  }
49
+ }
50
+
51
+ // do we have to serve the thumbnail from local cache?
52
+ if (get_option('lyte_local_thumb','0') === '1') {
53
+ $WYLthumb = plugins_url( 'lyteThumbs.php?origThumbUrl=' . urlencode($WYLthumb) , __FILE__ );
54
+ }
55
+
56
+ // filter to alter the thumbnail
57
  $WYLthumb = apply_filters( "lyte_filter_widget_thumb", $WYLthumb, $WYLid );
58
 
59
  if (isset($WYLarr['start'])) $qsa="&amp;start=".$WYLarr['start'];
75
  ?>
76
  <?php echo $before_widget; ?>
77
  <?php if ( $WYLtitle ) echo $before_title . $WYLtitle . $after_title; ?>
78
+ <div class="lyte-wrapper<?php echo $wrapperClass; ?>" style="width:<?php echo $wSize[$WYLsize]['w']; ?>px; height:<?php echo $wHeight; ?>px; min-width:200px; max-width:100%;"><div class="lyMe<?php echo $PLClass; echo $audioClass; echo $qsaClass; ?>" id="<?php echo $WYL_dom_id; ?>"><div id="lyte_<?php echo $WYLid; ?>" data-src="<?php echo $WYLthumb;?>" class="pL"><div class="play"></div><div class="ctrl"><div class="Lctrl"></div></div></div></div><noscript><a href="https://youtu.be/<?php echo $WYLid;?>"><img src="<?php echo $WYLthumb; ?>" alt="" /></a></noscript></div>
79
  <div><?php echo $WYLtext ?></div>
80
  <?php echo $after_widget; ?>
81
  <?php
wp-youtube-lyte.php CHANGED
@@ -4,7 +4,7 @@ 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.6.8
8
  Author URI: http://blog.futtta.be/
9
  Text Domain: wp-youtube-lyte
10
  Domain Path: /languages
@@ -13,7 +13,7 @@ Domain Path: /languages
13
  if ( ! defined( 'ABSPATH' ) ) exit;
14
 
15
  $debug=false;
16
- $lyte_version="1.6.0";
17
  $lyte_db_version=get_option('lyte_version','none');
18
 
19
  /** have we updated? */
@@ -230,10 +230,6 @@ function lyte_parse($the_content,$doExcerpt=false) {
230
  $noscript_post="<br />".__("Watch this video on YouTube","wp-youtube-lyte");
231
  $lytelinks_txt="<div class=\"lL\" style=\"max-width:100%;width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\"></div>";
232
  break;
233
- case "2":
234
- $noscript_post="";
235
- $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> ".__("or on","wp-youtube-lyte")." <a href=\"http://icant.co.uk/easy-youtube/?http://www.youtube.com/watch?v=".$vid."\">Easy Youtube</a>.</div>";
236
- break;
237
  default:
238
  $noscript_post="";
239
  $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>";
@@ -313,7 +309,12 @@ function lyte_parse($the_content,$doExcerpt=false) {
313
  // same fallback
314
  $thumbUrl = "//i.ytimg.com/vi/".$vid."/hqdefault.jpg";
315
  }
316
-
 
 
 
 
 
317
  /** API: filter hook to override thumbnail URL */
318
  $thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl );
319
 
@@ -333,7 +334,7 @@ function lyte_parse($the_content,$doExcerpt=false) {
333
  $lytetemplate = "<a href=\"".$postURL."\"><img src=\"".$thumbUrl."\" alt=\"YouTube Video\"></a>".$textLink;
334
  $templateType="feed";
335
  } elseif (($audio !== true) && ( $plClass !== " playlist") && (($lyteSettings['microdata'] === "1")&&($noMicroData !== "1" ))) {
336
- $lytetemplate = $wrapper."<div class=\"lyMe".$audioClass.$hidefClass.$plClass.$qsaClass."\" id=\"WYL_".$vid."\" itemprop=\"video\" itemscope itemtype=\"http://schema.org/VideoObject\"><meta itemprop=\"thumbnailUrl\" content=\"".$thumbUrl."\" /><meta itemprop=\"embedURL\" content=\"http://www.youtube.com/embed/".$vid."\" /><meta itemprop=\"uploadDate\" content=\"".$yt_resp_array["dateField"]."\" />".$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;
337
  $templateType="postMicrodata";
338
  } else {
339
  $lytetemplate = $wrapper."<div class=\"lyMe".$audioClass.$hidefClass.$plClass.$qsaClass."\" id=\"WYL_".$vid."\"><div id=\"lyte_".$vid."\" data-src=\"".$thumbUrl."\" class=\"pL\">";
@@ -549,8 +550,9 @@ function lyte_init() {
549
 
550
  // by default show lyte vid on mobile (requiring user clicking play two times)
551
  // but can be overruled by this filter
 
552
  $mobLyte = apply_filters( 'lyte_do_mobile', false );
553
- if ($mobLyte) {
554
  $mobJS = "var mOs=null;";
555
  } else {
556
  $mobJS = "var mOs=navigator.userAgent.match(/(iphone|ipad|ipod|android)/i);";
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.0
8
  Author URI: http://blog.futtta.be/
9
  Text Domain: wp-youtube-lyte
10
  Domain Path: /languages
13
  if ( ! defined( 'ABSPATH' ) ) exit;
14
 
15
  $debug=false;
16
+ $lyte_version="1.7.0";
17
  $lyte_db_version=get_option('lyte_version','none');
18
 
19
  /** have we updated? */
230
  $noscript_post="<br />".__("Watch this video on YouTube","wp-youtube-lyte");
231
  $lytelinks_txt="<div class=\"lL\" style=\"max-width:100%;width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\"></div>";
232
  break;
 
 
 
 
233
  default:
234
  $noscript_post="";
235
  $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>";
309
  // same fallback
310
  $thumbUrl = "//i.ytimg.com/vi/".$vid."/hqdefault.jpg";
311
  }
312
+
313
+ // do we have to serve the thumbnail from local cache?
314
+ if (get_option('lyte_local_thumb','0') === '1') {
315
+ $thumbUrl = plugins_url( 'lyteThumbs.php?origThumbUrl=' . urlencode($thumbUrl) , __FILE__ );
316
+ }
317
+
318
  /** API: filter hook to override thumbnail URL */
319
  $thumbUrl = apply_filters( 'lyte_match_thumburl', $thumbUrl );
320
 
334
  $lytetemplate = "<a href=\"".$postURL."\"><img src=\"".$thumbUrl."\" alt=\"YouTube Video\"></a>".$textLink;
335
  $templateType="feed";
336
  } elseif (($audio !== true) && ( $plClass !== " playlist") && (($lyteSettings['microdata'] === "1")&&($noMicroData !== "1" ))) {
337
+ $lytetemplate = $wrapper."<div class=\"lyMe".$audioClass.$hidefClass.$plClass.$qsaClass."\" id=\"WYL_".$vid."\" itemprop=\"video\" itemscope itemtype=\"https://schema.org/VideoObject\"><meta itemprop=\"thumbnailUrl\" content=\"".$thumbUrl."\" /><meta itemprop=\"embedURL\" content=\"https://www.youtube.com/embed/".$vid."\" /><meta itemprop=\"uploadDate\" content=\"".$yt_resp_array["dateField"]."\" />".$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;
338
  $templateType="postMicrodata";
339
  } else {
340
  $lytetemplate = $wrapper."<div class=\"lyMe".$audioClass.$hidefClass.$plClass.$qsaClass."\" id=\"WYL_".$vid."\"><div id=\"lyte_".$vid."\" data-src=\"".$thumbUrl."\" class=\"pL\">";
550
 
551
  // by default show lyte vid on mobile (requiring user clicking play two times)
552
  // but can be overruled by this filter
553
+ // also "do lyte mobile" when option to cache thumbnails is on to ensure privacy (gdpr)
554
  $mobLyte = apply_filters( 'lyte_do_mobile', false );
555
+ if ( $mobLyte || get_option( 'lyte_local_thumb', 0 ) ) {
556
  $mobJS = "var mOs=null;";
557
  } else {
558
  $mobJS = "var mOs=navigator.userAgent.match(/(iphone|ipad|ipod|android)/i);";