WP YouTube Lyte - Version 1.7.6

Version Description

  • improvement: extra parameters for shortcode (start, showinfo, stepsize and hqthumb).
  • improvement: also turn youtube-nocookie.com iframes into LYTE's as proposed by Maxim.
  • improvement: also remove cached thumbnails when clearing cache.
  • improvement: also set image in noscript tag to local hosted thumbnail if that option is active.
  • bugfix: when multiple iframes were on one page, the ones after the LYTE got lost (reported by Daniel Pardella, thanks).
Download this release

Release Info

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

Code changes from version 1.7.5 to 1.7.6

Files changed (2) hide show
  1. readme.txt +9 -2
  2. wp-youtube-lyte.php +34 -10
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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.5
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
@@ -136,6 +136,13 @@ Just tell me, I like the feedback! Use the [Contact-page on my blog](http://blog
136
 
137
  == Changelog ==
138
 
 
 
 
 
 
 
 
139
  = 1.7.5 =
140
  * improvement: also act on YouTube iframe code if "also act on YouTube links" is on.
141
  * improvement: if extracted from Gutenburg YouTube embed blocks keep the figure-tag with all relevant CSS classes and keep the caption (if set).
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: 5.1
7
+ Stable tag: 1.7.6
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
136
 
137
  == Changelog ==
138
 
139
+ = 1.7.6 =
140
+ * improvement: extra parameters for shortcode (start, showinfo, stepsize and hqthumb).
141
+ * improvement: also turn youtube-nocookie.com iframes into LYTE's as proposed by Maxim.
142
+ * improvement: also remove cached thumbnails when clearing cache.
143
+ * improvement: also set image in noscript tag to local hosted thumbnail if that option is active.
144
+ * bugfix: when multiple iframes were on one page, the ones after the LYTE got lost (reported by Daniel Pardella, thanks).
145
+
146
  = 1.7.5 =
147
  * improvement: also act on YouTube iframe code if "also act on YouTube links" is on.
148
  * improvement: if extracted from Gutenburg YouTube embed blocks keep the figure-tag with all relevant CSS classes and keep the caption (if set).
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.7.5
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.7.0";
17
  $lyte_db_version=get_option('lyte_version','none');
18
 
19
  /** have we updated? */
@@ -102,7 +102,7 @@ function lyte_parse($the_content,$doExcerpt=false) {
102
  $the_content=preg_replace('/^https?:\/\/(www.)?youtu(be.com|.be)\/(watch\?v=)?/m','httpv://www.youtube.com/watch?v=',$the_content);
103
 
104
  // new: also replace original YT embed code (iframes)
105
- if ( apply_filters( 'lyte_eats_yframes', true ) && preg_match_all('#<iframe(?:.*)?\ssrc=["|\']https:\/\/www\.youtube\.com\/embed\/(.*)["|\']\s(?:.*)><\/iframe>#Usm', $the_content, $matches, PREG_SET_ORDER)) {
106
  foreach ($matches as $match) {
107
  $the_content = str_replace($match[0], 'httpv://youtu.be/'.$match[1], $the_content);
108
  }
@@ -240,9 +240,12 @@ function lyte_parse($the_content,$doExcerpt=false) {
240
  default:
241
  $noscript_post="";
242
  $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>";
243
- }
244
-
245
- $noscript="<noscript><a href=\"".$lyteSettings['scheme']."://youtu.be/".$vid."\"><img src=\"".$lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg\" alt=\"\" width=\"".$lyteSettings[2]."\" height=\"".$NSimgHeight."\" />".$noscript_post."</a></noscript>";
 
 
 
246
  }
247
 
248
  // add disclaimer to lytelinks
@@ -331,7 +334,7 @@ function lyte_parse($the_content,$doExcerpt=false) {
331
 
332
  // do we have to serve the thumbnail from local cache?
333
  if (get_option('lyte_local_thumb','0') === '1') {
334
- $thumbUrl = plugins_url( 'lyteThumbs.php?origThumbUrl=' . urlencode($thumbUrl) , __FILE__ );
335
  }
336
 
337
  /** API: filter hook to override thumbnail URL */
@@ -619,12 +622,23 @@ function shortcode_lyte($atts) {
619
  "id" => '',
620
  "audio" => '',
621
  "playlist" => '',
 
 
 
 
622
  ), $atts));
623
-
 
 
624
  if ($audio) {$proto="httpa";} else {$proto="httpv";}
 
 
 
 
625
  if ($playlist) {$action="playlist?list=";} else {$action="watch?v=";}
626
- return lyte_parse($proto.'://www.youtube.com/'.$action.$id);
627
- }
 
628
 
629
  /** update functions */
630
  /** upgrade, so lyte should not be greedy */
@@ -634,6 +648,16 @@ function lyte_not_greedy() {
634
 
635
  /** function to flush YT responses from cache */
636
  function lyte_rm_cache() {
 
 
 
 
 
 
 
 
 
 
637
  try {
638
  ini_set('max_execution_time',90); // give PHP some more time for this, post-meta can be sloooooow
639
 
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.6
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.6";
17
  $lyte_db_version=get_option('lyte_version','none');
18
 
19
  /** have we updated? */
102
  $the_content=preg_replace('/^https?:\/\/(www.)?youtu(be.com|.be)\/(watch\?v=)?/m','httpv://www.youtube.com/watch?v=',$the_content);
103
 
104
  // new: also replace original YT embed code (iframes)
105
+ 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)) {
106
  foreach ($matches as $match) {
107
  $the_content = str_replace($match[0], 'httpv://youtu.be/'.$match[1], $the_content);
108
  }
240
  default:
241
  $noscript_post="";
242
  $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>";
243
+ }
244
+ $thumbUrl = $lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg";
245
+ if (get_option('lyte_local_thumb','0') === '1') {
246
+ $thumbUrl = plugins_url( 'lyteThumbs.php?origThumbUrl=' . urlencode($thumbUrl) , __FILE__ );
247
+ }
248
+ $noscript="<noscript><a href=\"".$lyteSettings['scheme']."://youtu.be/".$vid."\"><img src=\"" . $thumbUrl . "\" alt=\"\" width=\"".$lyteSettings[2]."\" height=\"".$NSimgHeight."\" />".$noscript_post."</a></noscript>";
249
  }
250
 
251
  // add disclaimer to lytelinks
334
 
335
  // do we have to serve the thumbnail from local cache?
336
  if (get_option('lyte_local_thumb','0') === '1') {
337
+ $thumbUrl = plugins_url( 'lyteThumbs.php?origThumbUrl=' . urlencode($thumbUrl) , __FILE__ );
338
  }
339
 
340
  /** API: filter hook to override thumbnail URL */
622
  "id" => '',
623
  "audio" => '',
624
  "playlist" => '',
625
+ "start" => '',
626
+ "showinfo" => '',
627
+ "stepsize" => '',
628
+ "hqthumb" => '',
629
  ), $atts));
630
+
631
+ $qs = '';
632
+
633
  if ($audio) {$proto="httpa";} else {$proto="httpv";}
634
+ if ($start !== '') { $qs .= "&amp;start=".$start; }
635
+ if ($showinfo === "false") { $qs .= "&amp;showinfo=0"; }
636
+ if ($hqthumb) { $qs .= "&amp;hqThumb=1"; }
637
+ if ($stepsize) { $qs .= "#stepSize=".$stepsize; }
638
  if ($playlist) {$action="playlist?list=";} else {$action="watch?v=";}
639
+
640
+ return lyte_parse($proto.'://www.youtube.com/'.$action.$id.$qs);
641
+ }
642
 
643
  /** update functions */
644
  /** upgrade, so lyte should not be greedy */
648
 
649
  /** function to flush YT responses from cache */
650
  function lyte_rm_cache() {
651
+ // remove thumbnail cache
652
+ if (get_option('lyte_local_thumb','0') === '1') {
653
+ if ( ! defined( 'LYTE_CACHE_DIR' ) ) {
654
+ define( 'LYTE_CACHE_CHILD_DIR', 'cache/lyteThumbs' );
655
+ define( 'LYTE_CACHE_DIR', WP_CONTENT_DIR .'/'. LYTE_CACHE_CHILD_DIR );
656
+ }
657
+ array_map('unlink', glob(LYTE_CACHE_DIR . "/*"));
658
+ }
659
+
660
+ // and remove cached YT data from postmeta
661
  try {
662
  ini_set('max_execution_time',90); // give PHP some more time for this, post-meta can be sloooooow
663