WP YouTube Lyte - Version 1.4.0

Version Description

  • new: if microdata is enabled, check if captions are available and if so add the accessibilityFeature=captions markup. Gracefully contributed by Benetech
  • bugfix: widgets with youtu.be short URL's were broken (as observed by Robert of audio-times.com.
  • bugfix: in some cases iframe size on mobile was not correct (reported by David of webquarry.com.
  • bugfix: mobile rotation handled more efficiently (based on feedback from Skyfield
Download this release

Release Info

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

Code changes from version 1.3.3 to 1.4.0

Files changed (6) hide show
  1. lyte/lyte-min.js +1 -1
  2. lyte/lyte.js +1 -1
  3. lyte_helper.php_example +8 -2
  4. readme.txt +11 -2
  5. widget.php +2 -0
  6. wp-youtube-lyte.php +92 -23
lyte/lyte-min.js CHANGED
@@ -1 +1 @@
1
- (function(e){var t=document;var n="http";if(bU.indexOf("https")!=-1){n+="s"}e.te=function(){if(!r){var r=1;var i=navigator.userAgent.match(/(iphone|ipad|ipod|android)/i);lts=e.getElementsByClassName("lyMe","div");for(var s=0,o=lts.length;s<o;s+=1){p=lts[s];vid=p.id.substring(4);if(i===null){cN=p.className.replace(/lyMe/,"lyte")+" lP";p.className=cN;sprite=bU+"lytesprite.png";e.addCss(".lyte .ctrl, .lyte .Rctrl, .lyte .Lctrl, .lyte .play { background-image: url("+sprite+"); }");if(cN.indexOf("audio")===-1){bgId="lyte_"+vid;thumb=t.getElementById(bgId).getAttribute("data-src");if(thumb!==""){bgCss="#"+bgId+" { background-image: url("+thumb+"); }";e.addCss(bgCss)}else{scr=t.createElement("script");scr.src=n+"://gdata.youtube.com/feeds/api/playlists/"+vid+"?v=2&alt=json-in-script&callback=ly.parsePL&fields=id,entry";scr.type="text/javascript";t.getElementsByTagName("head")[0].appendChild(scr)}}p.onclick=e.play}else{e.play(p.id)}}}var r=""};e.parsePL=function(t){thumb=t.feed.entry[0].media$group.media$thumbnail[1].url;if(n=="https"&&thumb.indexOf("https"==-1)){thumb=thumb.replace("http://","https://")}t_id=t.feed.id.$t.match(/:playlist:(PL[a-zA-Z0-9_]+)/);id="lyte_"+t_id[1];bgCss="#"+id+" { background-image: url("+thumb+"); }";e.addCss(bgCss)};e.getQ=function(e){qsa="";if(rqs=e.className.match(/qsa_(.*)\s/,"$1"))qsa=rqs[1].replace(/\\([\&\=\?])/g,"$1");return qsa};e.play=function(r){if(typeof r==="string"){tH=t.getElementById(r);aP=0}else{tH=this;tH.onclick="";aP=1}vid=tH.id.substring(4);hidef=0;if(tH.className.indexOf("hidef")!==-1){hidef="1&vq=hd720"}if(tH.className.indexOf("playlist")===-1){eU=n+"://www.youtube.com/embed/"+vid+"?"}else{eU=n+"://www.youtube.com/embed/videoseries?list="+vid+"&"}qsa=e.getQ(tH);if(tH.className.indexOf("audio")!==-1&&aP==1){qsa+="&autohide=0";aHgh="438";aSt="position:relative;top:-400px;"}else if(tH.className.indexOf("audio")!==-1&&aP==0){tH.parentNode.style.height="";tH.style.height="";aHgh=tH.clientHeight;aSt="height:"+aHgh+"px !important;"}else{aHgh=tH.clientHeight;aSt=""}tH.innerHTML='<iframe id="iF_'+vid+'" width="'+tH.clientWidth+'px" height="'+aHgh+'px" src="'+eU+"autoplay="+aP+"&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd="+hidef+qsa+'" frameborder="0" style="'+aSt+'" allowfullscreen></iframe>';if(aP==0){window.addEventListener("orientationchange",function(){ly.te();},false)};if(typeof tH.firstChild.getAttribute("kabl")=="string")tH.innerHTML="Please check Karma Blocker's config."};e.getElementsByClassName=function(e,n,r){if(t.getElementsByClassName){getElementsByClassName=function(e,n,r){r=r||t;var i=r.getElementsByClassName(e),s=n?new RegExp("\\b"+n+"\\b","i"):null,o=[],u;for(var a=0,f=i.length;a<f;a+=1){u=i[a];if(!s||s.test(u.nodeName)){o.push(u)}}return o}}else if(t.evaluate){getElementsByClassName=function(e,n,r){n=n||"*";r=r||t;var i=e.split(" "),s="",o="http://www.w3.org/1999/xhtml",u=t.documentElement.namespaceURI===o?o:null,a=[],f,l;for(var c=0,h=i.length;c<h;c+=1){s+="[contains(concat(' ', @class, ' '), ' "+i[c]+" ')]"}try{f=t.evaluate(".//"+n+s,r,u,0,null)}catch(p){f=t.evaluate(".//"+n+s,r,null,0,null)}while(l=f.iterateNext()){a.push(l)}return a}}else{getElementsByClassName=function(e,n,r){n=n||"*";r=r||t;var i=e.split(" "),s=[],o=n==="*"&&r.all?r.all:r.getElementsByTagName(n),u,a=[],f;for(var l=0,c=i.length;l<c;l+=1){s.push(new RegExp("(^|\\s)"+i[l]+"(\\s|$)"))}for(var h=0,p=o.length;h<p;h+=1){u=o[h];f=false;for(var v=0,m=s.length;v<m;v+=1){f=s[v].test(u.className);if(!f){break}}if(f){a.push(u)}}return a}}return getElementsByClassName(e,n,r)};e.addCss=function(e){var n=t.createElement("style");n.type="text/css";if(n.styleSheet){n.styleSheet.cssText=e}else{n.appendChild(document.createTextNode(e))}t.getElementsByTagName("head")[0].appendChild(n)}})(window.ly=window.ly||{});(function(){var e=window;var t=document;if(e.addEventListener){e.addEventListener("load",ly.te,false);t.addEventListener("DomContentLoaded",function(){setTimeout("ly.te()",750)},false)}else{e.onload=ly.te;setTimeout("ly.te()",1e3)}})()
1
+ (function(e){var t=document;var n="http";if(bU.indexOf("https")!=-1){n+="s"}e.te=function(){if(!r){var r=1;var i=navigator.userAgent.match(/(iphone|ipad|ipod|android)/i);lts=e.getElementsByClassName("lyMe","div");for(var s=0,o=lts.length;s<o;s+=1){p=lts[s];vid=p.id.substring(4);if(i===null){cN=p.className.replace(/lyMe/,"lyte")+" lP";p.className=cN;sprite=bU+"lytesprite.png";e.addCss(".lyte .ctrl, .lyte .Rctrl, .lyte .Lctrl, .lyte .play { background-image: url("+sprite+"); }");if(cN.indexOf("audio")===-1){bgId="lyte_"+vid;thumb=t.getElementById(bgId).getAttribute("data-src");if(thumb!==""){bgCss="#"+bgId+" { background-image: url("+thumb+"); }";e.addCss(bgCss)}else{scr=t.createElement("script");scr.src=n+"://gdata.youtube.com/feeds/api/playlists/"+vid+"?v=2&alt=json-in-script&callback=ly.parsePL&fields=id,entry";scr.type="text/javascript";t.getElementsByTagName("head")[0].appendChild(scr)}}p.onclick=e.play}else{e.play(p.id)}}}var r=""};e.parsePL=function(t){thumb=t.feed.entry[0].media$group.media$thumbnail[1].url;if(n=="https"&&thumb.indexOf("https"==-1)){thumb=thumb.replace("http://","https://")}t_id=t.feed.id.$t.match(/:playlist:(PL[a-zA-Z0-9_]+)/);id="lyte_"+t_id[1];bgCss="#"+id+" { background-image: url("+thumb+"); }";e.addCss(bgCss)};e.getQ=function(e){qsa="";if(rqs=e.className.match(/qsa_(.*)\s/,"$1"))qsa=rqs[1].replace(/\\([\&\=\?])/g,"$1");return qsa};e.play=function(r){if(typeof r==="string"){tH=t.getElementById(r);aP=0}else{tH=this;tH.onclick="";aP=1}vid=tH.id.substring(4);hidef=0;if(tH.className.indexOf("hidef")!==-1){hidef="1&vq=hd720"}if(tH.className.indexOf("playlist")===-1){eU=n+"://www.youtube.com/embed/"+vid+"?"}else{eU=n+"://www.youtube.com/embed/videoseries?list="+vid+"&"}qsa=e.getQ(tH);if(tH.className.indexOf("audio")!==-1&&aP==1){qsa+="&autohide=0";aHgh="438";aSt="position:relative;top:-400px;"}else if(tH.className.indexOf("audio")!==-1&&aP==0){tH.parentNode.style.height="";tH.style.height="";aHgh=tH.clientHeight;aSt="height:"+aHgh+"px !important;"}else{aHgh=tH.clientHeight;aSt=""}tH.innerHTML='<iframe id="iF_'+vid+'" width="'+tH.clientWidth*2+'" height="'+aHgh+'" src="'+eU+"autoplay="+aP+"&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd="+hidef+qsa+'" frameborder="0" style="'+aSt+'" allowfullscreen></iframe>';if(typeof tH.firstChild.getAttribute("kabl")=="string")tH.innerHTML="Please check Karma Blocker's config.";if(aP==0){window.addEventListener("orientationchange",function(){t.getElementById(r).width=t.getElementById(r).parentNode.clientWidth},false)}};e.getElementsByClassName=function(e,n,r){if(t.getElementsByClassName){getElementsByClassName=function(e,n,r){r=r||t;var i=r.getElementsByClassName(e),s=n?new RegExp("\\b"+n+"\\b","i"):null,o=[],u;for(var a=0,f=i.length;a<f;a+=1){u=i[a];if(!s||s.test(u.nodeName)){o.push(u)}}return o}}else if(t.evaluate){getElementsByClassName=function(e,n,r){n=n||"*";r=r||t;var i=e.split(" "),s="",o="http://www.w3.org/1999/xhtml",u=t.documentElement.namespaceURI===o?o:null,a=[],f,l;for(var c=0,h=i.length;c<h;c+=1){s+="[contains(concat(' ', @class, ' '), ' "+i[c]+" ')]"}try{f=t.evaluate(".//"+n+s,r,u,0,null)}catch(p){f=t.evaluate(".//"+n+s,r,null,0,null)}while(l=f.iterateNext()){a.push(l)}return a}}else{getElementsByClassName=function(e,n,r){n=n||"*";r=r||t;var i=e.split(" "),s=[],o=n==="*"&&r.all?r.all:r.getElementsByTagName(n),u,a=[],f;for(var l=0,c=i.length;l<c;l+=1){s.push(new RegExp("(^|\\s)"+i[l]+"(\\s|$)"))}for(var h=0,p=o.length;h<p;h+=1){u=o[h];f=false;for(var v=0,m=s.length;v<m;v+=1){f=s[v].test(u.className);if(!f){break}}if(f){a.push(u)}}return a}}return getElementsByClassName(e,n,r)};e.addCss=function(e){var n=t.createElement("style");n.type="text/css";if(n.styleSheet){n.styleSheet.cssText=e}else{n.appendChild(document.createTextNode(e))}t.getElementsByTagName("head")[0].appendChild(n)}})(window.ly=window.ly||{});(function(){var e=window;var t=document;if(e.addEventListener){e.addEventListener("load",ly.te,false);t.addEventListener("DomContentLoaded",function(){setTimeout("ly.te()",750)},false)}else{e.onload=ly.te;setTimeout("ly.te()",1e3)}})()
lyte/lyte.js CHANGED
@@ -94,7 +94,7 @@ ly.play = function(id) {
94
 
95
  if(typeof tH.firstChild.getAttribute('kabl')=="string") tH.innerHTML="Please check Karma Blocker's config.";
96
 
97
- if (aP==0){window.addEventListener("orientationchange", function() {ly.te();}, false);}
98
  }
99
 
100
  ly.getElementsByClassName = function(className, tag, elm) {
94
 
95
  if(typeof tH.firstChild.getAttribute('kabl')=="string") tH.innerHTML="Please check Karma Blocker's config.";
96
 
97
+ if (aP==0){window.addEventListener("orientationchange", function() {d.getElementById(id).width=d.getElementById(id).parentNode.clientWidth;}, false);}
98
  }
99
 
100
  ly.getElementsByClassName = function(className, tag, elm) {
lyte_helper.php_example CHANGED
@@ -4,12 +4,12 @@ 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.1
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
13
  available action hooks; lyte_actionsfilters
14
  */
15
 
@@ -76,6 +76,12 @@ function lyte_change_settings($settingsArray) {
76
  return $settingsArray;
77
  }
78
 
 
 
 
 
 
 
79
  /** force lyte javascript (which includes css) to be loaded in head instead of footer */
80
  // lyte_force_jshead();
81
  function lyte_force_jshead() {
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
13
  available action hooks; lyte_actionsfilters
14
  */
15
 
76
  return $settingsArray;
77
  }
78
 
79
+ /** disable captions lookup */
80
+ // add_filter('lyte_docaptions','lyte_nocaptions',10,0);
81
+ function lyte_nocaptions() {
82
+ return false;
83
+ }
84
+
85
  /** force lyte javascript (which includes css) to be loaded in head instead of footer */
86
  // lyte_force_jshead();
87
  function lyte_force_jshead() {
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: futtta
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: 2.9
6
- Tested up to: 3.7
7
- Stable tag: 1.3.3
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
@@ -69,6 +69,9 @@ This was added as a beta feature in version 1.1.0; add ?enablejsapi=1 to the htt
69
  * The videoobject microdata is NOT added for audio-only embeds, playlists or widgets
70
  * Google will not always display the thumbnail, this presumably depends of the relevance of the video to the rest of the page.
71
 
 
 
 
72
  = Responsive LYTE embeds =
73
  * The video width in posts and pages will adapt to the width of the container (the div) in which your blogposts/ pages are shown. This means that if your theme is responsive, WP YouTube Lyte will follow.
74
  * Widgets are not responsive.
@@ -106,6 +109,12 @@ Just tell me, I like the feedback! Use the [Contact-page on my blog](http://blog
106
 
107
  == Changelog ==
108
 
 
 
 
 
 
 
109
  = 1.3.3 =
110
  * fix for playlist shortcode as [reported by pete777](http://wordpress.org/support/topic/playlist-via-shortcode-broken)
111
  * fix for mobile orientation-change bug [described by Kevinlikes](http://wordpress.org/support/topic/rotation-bug-on-iphoneipad)
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: 2.9
6
+ Tested up to: 3.8
7
+ Stable tag: 1.4.0
8
 
9
  High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
10
 
69
  * The videoobject microdata is NOT added for audio-only embeds, playlists or widgets
70
  * Google will not always display the thumbnail, this presumably depends of the relevance of the video to the rest of the page.
71
 
72
+ = How does captions-support get added to the microdata? =
73
+ In January 2014 [Benetech](http://benetech.org/), a U.S. nonprofit that develops and uses technology to create positive social change, offered a patch that adds the [accessibilityFeature property](http://schema.org/accessibilityFeature) to the microdata for videos that have captions. If you have microdata enabled, WP YouTube Lyte will automatically try to check (in a seperate, asynchronous call via a proxy-webservice, as YouTube only offers captions in their API v3 which requires authentication) if captions are available and if so, adds the accessibilityFeature property with value captions to the microdata. This can be disabled by either disabling microdata or, if you want microdata but not the accessibilityFeature-property by using the "lyte_docaptions"-filter to set captions to false (example-code is in lyte_helper.php_example).
74
+
75
  = Responsive LYTE embeds =
76
  * The video width in posts and pages will adapt to the width of the container (the div) in which your blogposts/ pages are shown. This means that if your theme is responsive, WP YouTube Lyte will follow.
77
  * Widgets are not responsive.
109
 
110
  == Changelog ==
111
 
112
+ = 1.4.0 =
113
+ * new: if microdata is enabled, check if captions are available and if so add the accessibilityFeature=captions markup. Gracefully contributed [by Benetech](http://benetech.org/)
114
+ * bugfix: widgets with youtu.be short URL's were broken (as observed by [Robert of audio-times.com](http://www.audio-times.com/).
115
+ * bugfix: in some cases iframe size on mobile was not correct (reported by [David of webquarry.com](http://www.webquarry.com/).
116
+ * bugfix: mobile rotation handled more efficiently (based on [feedback from Skyfield](http://wordpress.org/support/topic/rotation-bug-on-iphoneipad#post-5102835)
117
+
118
  = 1.3.3 =
119
  * fix for playlist shortcode as [reported by pete777](http://wordpress.org/support/topic/playlist-via-shortcode-broken)
120
  * fix for mobile orientation-change bug [described by Kevinlikes](http://wordpress.org/support/topic/rotation-bug-on-iphoneipad)
widget.php CHANGED
@@ -33,6 +33,8 @@ class WYLWidget extends WP_Widget {
33
 
34
  if (strpos($WYLurl,'youtu.be')) {
35
  $WYLid=substr(parse_url($WYLurl,PHP_URL_PATH),1,11);
 
 
36
  } else {
37
  if (isset($WYLarr['v'])) {
38
  $WYLid=$WYLarr['v'];
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'];
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.3.3
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.3.3";
17
  $lyte_db_version=get_option('lyte_version','none');
18
 
19
  /** have we updated? */
@@ -97,9 +97,6 @@ function lyte_parse($the_content,$doExcerpt=false) {
97
  preg_match_all($lytes_regexp, $the_content, $matches, PREG_SET_ORDER);
98
 
99
  foreach($matches as $match) {
100
- /* echo "<pre>";
101
- print_r($match);
102
- echo "</pre>"; */
103
  /** API: filter hook to preparse fragment in a httpv-url, e.g. to force hqThumb=1 or showinfo=0 */
104
  $match[12] = apply_filters( 'lyte_match_preparse_fragment',$match[12] );
105
 
@@ -123,7 +120,7 @@ function lyte_parse($the_content,$doExcerpt=false) {
123
  $noMicroData="1";
124
  }
125
  }
126
-
127
  $qsa="";
128
  if (!empty($showinfo[0])) {
129
  $qsa="&amp;".$showinfo[0];
@@ -167,7 +164,6 @@ function lyte_parse($the_content,$doExcerpt=false) {
167
  }
168
 
169
  $NSimgHeight=$divHeight-20;
170
- $NSbanner="Embedded with WP YouTube Lyte.";
171
 
172
  if ($match[11]!="") {
173
  $plClass=" playlist";
@@ -175,11 +171,11 @@ function lyte_parse($the_content,$doExcerpt=false) {
175
  switch ($lyteSettings['links']) {
176
  case "0":
177
  $noscript_post="<br />".__("Watch this playlist on YouTube","wp-youtube-lyte");
178
- $noscript="<noscript><a href=\"".$lyteSettings['scheme']."://youtube.com/playlist?list=PL".$vid."\">".$noscript_post."</a> ".$NSbanner."</noscript>";
179
  $lytelinks_txt="";
180
  break;
181
  default:
182
- $noscript="<noscript>".$NSbanner."</noscript>";
183
  $lytelinks_txt="<div class=\"lL\" style=\"width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\">".__("Watch this playlist","wp-youtube-lyte")." <a href=\"".$lyteSettings['scheme']."://www.youtube.com/playlist?list=PL".$vid."\">".__("on YouTube","wp-youtube-lyte")."</a></div>";
184
  }
185
  } else if ($match[9]!="") {
@@ -199,17 +195,16 @@ function lyte_parse($the_content,$doExcerpt=false) {
199
  $lytelinks_txt="<div class=\"lL\" style=\"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>";
200
  }
201
 
202
- $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> ".$NSbanner."</noscript>";
203
  }
204
 
205
  /** logic to get video info from cache or get it from YouTube and set it */
206
- if ( $postID ) {
207
- // Check for a cached result (stored in the post meta)
208
- $cachekey = '_lyte_' . $vid;
209
- $yt_resp = get_post_meta( $postID, $cachekey, true );
210
  if (!empty($yt_resp)) {
211
  $yt_resp = gzuncompress(base64_decode($yt_resp));
212
- }
213
  } else {
214
  $yt_resp = "";
215
  }
@@ -235,11 +230,12 @@ function lyte_parse($the_content,$doExcerpt=false) {
235
 
236
  if ( $postID ) {
237
  // we can cache the result
238
-
239
- // first add timestamp
240
  $yt_resp_array=json_decode($yt_resp,true);
 
241
  if(is_array($yt_resp_array)) {
 
242
  $yt_resp_array['lyte_date_added']=time();
 
243
  $yt_resp_precache=json_encode($yt_resp_array);
244
 
245
  // then gzip + base64 (to limit amount of data + solve problems with wordpress removing slashes)
@@ -259,6 +255,7 @@ function lyte_parse($the_content,$doExcerpt=false) {
259
  // If there was a result from youtube or from cache, use it
260
  if ( $yt_resp ) {
261
  $yt_resp_array=json_decode($yt_resp,true);
 
262
  if (is_array($yt_resp_array)) {
263
  if ($plClass===" playlist") {
264
  $yt_title="Playlist: ".esc_attr(sanitize_text_field(@$yt_resp_array['feed']['title']['$t']));
@@ -272,8 +269,48 @@ function lyte_parse($the_content,$doExcerpt=false) {
272
  $dateField=sanitize_text_field(@$yt_resp_array['entry']['published']['$t']);
273
  $duration="T".sanitize_text_field(@$yt_resp_array['entry']['media$group']['yt$duration']['seconds'])."S";
274
  $description=esc_attr(sanitize_text_field(@$yt_resp_array['entry']['media$group']['media$description']['$t']));
275
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  }
 
277
  }
278
 
279
  if ($audio===true) {
@@ -291,12 +328,13 @@ function lyte_parse($the_content,$doExcerpt=false) {
291
  $lytetemplate = "<a href=\"".$postURL."\"><img src=\"".$lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg\" alt=\"YouTube Video\"></a>".$textLink;
292
  $templateType="feed";
293
  } elseif (($audio !== true) && ( $plClass !== " playlist") && (($lyteSettings['microdata'] === "1")&&($noMicroData !== "1" ))) {
294
- $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=\"".$dateField."\" /><div id=\"lyte_".$vid."\" data-src=\"".$thumbUrl."\" class=\"pL\"><div class=\"tC".$titleClass."\"><div class=\"tT\" itemprop=\"name\">".$yt_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=\"".$description."\"></div></div>".$lytelinks_txt;
295
  $templateType="postMicrodata";
296
  } else {
297
  $lytetemplate = $wrapper."<div class=\"lyMe".$audioClass.$hidefClass.$plClass.$qsaClass."\" id=\"WYL_".$vid."\"><div id=\"lyte_".$vid."\" data-src=\"".$thumbUrl."\" class=\"pL\"><div class=\"tC".$titleClass."\"><div class=\"tT\">".$yt_title."</div></div><div class=\"play\"></div><div class=\"ctrl\"><div class=\"Lctrl\"></div><div class=\"Rctrl\"></div></div></div>".$noscript."</div></div>".$lytelinks_txt;
298
  $templateType="post";
299
  }
 
300
  /** API: filter hook to parse template before being applied */
301
  $lytetemplate = apply_filters( 'lyte_match_postparse_template',$lytetemplate,$templateType );
302
 
@@ -315,10 +353,40 @@ function lyte_parse($the_content,$doExcerpt=false) {
315
  }
316
  }
317
 
318
- /** API: filter hook to postparse the_content before returning */
319
- $the_content = apply_filters( 'lyte_content_postparse',$the_content );
 
 
 
320
 
321
- return $the_content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  }
323
 
324
  /* only add js/css once and only if needed */
@@ -333,7 +401,7 @@ function lyte_initer() {
333
  /* actual initialization */
334
  function lyte_init() {
335
  global $lyteSettings;
336
- $lyte_css = ".lyte-wrapper-audio div, .lyte-wrapper div {margin:0px !important; 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} .lyte iframe,.lyte .pL{position:absolute;top:0;left:0;width:100%;height:100%;background:no-repeat scroll center #000;background-size:cover;cursor:pointer} .tC{background-color:rgba(0,0,0,0.5);left:0;position:absolute;top:0;width:100%} .tT{color:#FFF;font-family:sans-serif;font-size:12px;height:auto;text-align:left;padding:5px 10px} .tT:hover{text-decoration:underline} .play{background:no-repeat scroll 0 0 transparent;width:90px;height:62px;position:absolute;left:43%;left:calc(50% - 45px);left:-webkit-calc(50% - 45px);top:38%;top:calc(50% - 31px);top:-webkit-calc(50% - 31px);opacity:0.9;} .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; opacity:1;} .lyte-audio .pL{max-height:38px!important} .lyte-audio iframe{height:438px!important} .ctrl{background:repeat scroll 0 -215px transparent;width:100%;height:40px;bottom:0;left:0;position:absolute} .Lctrl{background:no-repeat scroll 0 -132px transparent;width:158px;height:40px;bottom:0;left:0;position:absolute} .Rctrl{background:no-repeat scroll -42px -174px transparent;width:117px;height:40px;bottom:0;right:0;position:absolute} .lyte-audio .play,.lyte-audio .tC{display:none} .hidden{display:none}";
337
 
338
  /** API: filter hook to change css */
339
  $lyte_css = apply_filters( 'lyte_css', $lyte_css);
@@ -426,6 +494,7 @@ if ( is_admin() ) {
426
  add_shortcode("lyte", "shortcode_lyte");
427
  remove_filter('get_the_excerpt', 'wp_trim_excerpt');
428
  add_filter('get_the_excerpt', 'lyte_trim_excerpt');
 
429
 
430
  /** API: action hook to allow extra actions or filters to be added */
431
  do_action("lyte_actionsfilters");
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.4.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.4.0";
17
  $lyte_db_version=get_option('lyte_version','none');
18
 
19
  /** have we updated? */
97
  preg_match_all($lytes_regexp, $the_content, $matches, PREG_SET_ORDER);
98
 
99
  foreach($matches as $match) {
 
 
 
100
  /** API: filter hook to preparse fragment in a httpv-url, e.g. to force hqThumb=1 or showinfo=0 */
101
  $match[12] = apply_filters( 'lyte_match_preparse_fragment',$match[12] );
102
 
120
  $noMicroData="1";
121
  }
122
  }
123
+
124
  $qsa="";
125
  if (!empty($showinfo[0])) {
126
  $qsa="&amp;".$showinfo[0];
164
  }
165
 
166
  $NSimgHeight=$divHeight-20;
 
167
 
168
  if ($match[11]!="") {
169
  $plClass=" playlist";
171
  switch ($lyteSettings['links']) {
172
  case "0":
173
  $noscript_post="<br />".__("Watch this playlist on YouTube","wp-youtube-lyte");
174
+ $noscript="<noscript><a href=\"".$lyteSettings['scheme']."://youtube.com/playlist?list=PL".$vid."\">".$noscript_post."</a></noscript>";
175
  $lytelinks_txt="";
176
  break;
177
  default:
178
+ $noscript="";
179
  $lytelinks_txt="<div class=\"lL\" style=\"width:".$lyteSettings[2]."px;".$lyteSettings['pos']."\">".__("Watch this playlist","wp-youtube-lyte")." <a href=\"".$lyteSettings['scheme']."://www.youtube.com/playlist?list=PL".$vid."\">".__("on YouTube","wp-youtube-lyte")."</a></div>";
180
  }
181
  } else if ($match[9]!="") {
195
  $lytelinks_txt="<div class=\"lL\" style=\"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>";
196
  }
197
 
198
+ $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>";
199
  }
200
 
201
  /** logic to get video info from cache or get it from YouTube and set it */
202
+ if ( $postID ) {
203
+ $cachekey = '_lyte_' . $vid;
204
+ $yt_resp = get_post_meta( $postID, $cachekey, true );
 
205
  if (!empty($yt_resp)) {
206
  $yt_resp = gzuncompress(base64_decode($yt_resp));
207
+ }
208
  } else {
209
  $yt_resp = "";
210
  }
230
 
231
  if ( $postID ) {
232
  // we can cache the result
 
 
233
  $yt_resp_array=json_decode($yt_resp,true);
234
+
235
  if(is_array($yt_resp_array)) {
236
+ //entry is new
237
  $yt_resp_array['lyte_date_added']=time();
238
+
239
  $yt_resp_precache=json_encode($yt_resp_array);
240
 
241
  // then gzip + base64 (to limit amount of data + solve problems with wordpress removing slashes)
255
  // If there was a result from youtube or from cache, use it
256
  if ( $yt_resp ) {
257
  $yt_resp_array=json_decode($yt_resp,true);
258
+
259
  if (is_array($yt_resp_array)) {
260
  if ($plClass===" playlist") {
261
  $yt_title="Playlist: ".esc_attr(sanitize_text_field(@$yt_resp_array['feed']['title']['$t']));
269
  $dateField=sanitize_text_field(@$yt_resp_array['entry']['published']['$t']);
270
  $duration="T".sanitize_text_field(@$yt_resp_array['entry']['media$group']['yt$duration']['seconds'])."S";
271
  $description=esc_attr(sanitize_text_field(@$yt_resp_array['entry']['media$group']['media$description']['$t']));
272
+
273
+ // captions, thanks to Benetech
274
+ $captionsMeta="";
275
+ $doCaptions=true;
276
+
277
+ /** API: filter hook to disable captions */
278
+ $doCaptions = apply_filters( 'lyte_docaptions', $doCaptions );
279
+
280
+ if(($lyteSettings['microdata'] === "1")&&($noMicroData !== "1" )&&($doCaptions === true)) {
281
+ if (array_key_exists('captions_data',$yt_resp_array)) {
282
+ if ($yt_resp_array["captions_data"]) {
283
+ $captionsMeta="<meta itemprop=\"accessibilityFeature\" content=\"captions\" />";
284
+ $forceCaptionsUpdate=false;
285
+ } else {
286
+ $forceCaptionsUpdate=true;
287
+ }
288
+ } else {
289
+ $forceCaptionsUpdate=true;
290
+ $yt_resp_array["captions_data"]=false;
291
+ }
292
+
293
+ if ($forceCaptionsUpdate===true) {
294
+ $captionsMeta="";
295
+ if (array_key_exists('captions_timestamp',$yt_resp_array)) {
296
+ $cache_timestamp = $yt_resp_array["captions_timestamp"];
297
+ $interval = (strtotime("now") - $cache_timestamp)/60/60/24;
298
+ } else {
299
+ $cache_timestamp = false;
300
+ $interval = 2;
301
+ }
302
+
303
+ if(!is_int($cache_timestamp) || ($interval > 1 && !is_null($yt_resp_array["captions_data"]))) {
304
+ $yt_resp_array['captions_timestamp'] = strtotime("now");
305
+ wp_schedule_single_event(strtotime("now") + 60*60, 'schedule_captions_lookup', array($postID, $cachekey, $vid));
306
+ $yt_resp_precache=json_encode($yt_resp_array);
307
+ $toCache=base64_encode(gzcompress($yt_resp_precache));
308
+ update_post_meta($postID, $cachekey, $toCache);
309
+ }
310
+ }
311
+ }
312
  }
313
+ }
314
  }
315
 
316
  if ($audio===true) {
328
  $lytetemplate = "<a href=\"".$postURL."\"><img src=\"".$lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg\" alt=\"YouTube Video\"></a>".$textLink;
329
  $templateType="feed";
330
  } elseif (($audio !== true) && ( $plClass !== " playlist") && (($lyteSettings['microdata'] === "1")&&($noMicroData !== "1" ))) {
331
+ $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=\"".$dateField."\" />".$captionsMeta."<div id=\"lyte_".$vid."\" data-src=\"".$thumbUrl."\" class=\"pL\"><div class=\"tC".$titleClass."\"><div class=\"tT\" itemprop=\"name\">".$yt_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=\"".$description."\"></div></div>".$lytelinks_txt;
332
  $templateType="postMicrodata";
333
  } else {
334
  $lytetemplate = $wrapper."<div class=\"lyMe".$audioClass.$hidefClass.$plClass.$qsaClass."\" id=\"WYL_".$vid."\"><div id=\"lyte_".$vid."\" data-src=\"".$thumbUrl."\" class=\"pL\"><div class=\"tC".$titleClass."\"><div class=\"tT\">".$yt_title."</div></div><div class=\"play\"></div><div class=\"ctrl\"><div class=\"Lctrl\"></div><div class=\"Rctrl\"></div></div></div>".$noscript."</div></div>".$lytelinks_txt;
335
  $templateType="post";
336
  }
337
+
338
  /** API: filter hook to parse template before being applied */
339
  $lytetemplate = apply_filters( 'lyte_match_postparse_template',$lytetemplate,$templateType );
340
 
353
  }
354
  }
355
 
356
+ /** API: filter hook to postparse the_content before returning */
357
+ $the_content = apply_filters( 'lyte_content_postparse',$the_content );
358
+
359
+ return $the_content;
360
+ }
361
 
362
+ // captions lookup at YouTube via a11ymetadata.org
363
+ function captions_lookup($postID, $cachekey, $vid) {
364
+ $response = wp_remote_request("http://api.a11ymetadata.org/captions/youtubeid=".$vid."/youtube");
365
+
366
+ if(!is_wp_error($response)) {
367
+ $rawJson = wp_remote_retrieve_body($response);
368
+ $decodeJson = json_decode($rawJson, true);
369
+
370
+ $yt_resp = get_post_meta($postID, $cachekey, true);
371
+
372
+ if (!empty($yt_resp)) {
373
+ $yt_resp = gzuncompress(base64_decode($yt_resp));
374
+ if($yt_resp) {
375
+ $yt_resp_array=json_decode($yt_resp,true);
376
+
377
+ if ($decodeJson['status'] == 'success' && $decodeJson['data']['captions'] == '1') {
378
+ $yt_resp_array['captions_data'] = true;
379
+ } else {
380
+ $yt_resp_array['captions_data'] = false;
381
+ }
382
+
383
+ $yt_resp_array['captions_timestamp'] = strtotime("now");
384
+ $yt_resp_precache=json_encode($yt_resp_array);
385
+ $toCache=base64_encode(gzcompress($yt_resp_precache));
386
+ update_post_meta($postID, $cachekey, $toCache);
387
+ }
388
+ }
389
+ }
390
  }
391
 
392
  /* only add js/css once and only if needed */
401
  /* actual initialization */
402
  function lyte_init() {
403
  global $lyteSettings;
404
+ $lyte_css = ".lyte-wrapper-audio div, .lyte-wrapper div {margin:0px !important; 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;top:0;left:0;width:100%;height:100%!important;background:no-repeat scroll center #000;background-size:cover;cursor:pointer} .tC{background-color:rgba(0,0,0,0.5);left:0;position:absolute;top:0;width:100%} .tT{color:#FFF;font-family:sans-serif;font-size:12px;height:auto;text-align:left;padding:5px 10px} .tT:hover{text-decoration:underline} .play{background:no-repeat scroll 0 0 transparent;width:90px;height:62px;position:absolute;left:43%;left:calc(50% - 45px);left:-webkit-calc(50% - 45px);top:38%;top:calc(50% - 31px);top:-webkit-calc(50% - 31px);opacity:0.9;} .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; opacity:1;} .lyte-audio .pL{max-height:38px!important} .lyte-audio iframe{height:438px!important} .ctrl{background:repeat scroll 0 -215px transparent;width:100%;height:40px;bottom:0;left:0;position:absolute} .Lctrl{background:no-repeat scroll 0 -132px transparent;width:158px;height:40px;bottom:0;left:0;position:absolute} .Rctrl{background:no-repeat scroll -42px -174px transparent;width:117px;height:40px;bottom:0;right:0;position:absolute} .lyte-audio .play,.lyte-audio .tC{display:none} .hidden{display:none}";
405
 
406
  /** API: filter hook to change css */
407
  $lyte_css = apply_filters( 'lyte_css', $lyte_css);
494
  add_shortcode("lyte", "shortcode_lyte");
495
  remove_filter('get_the_excerpt', 'wp_trim_excerpt');
496
  add_filter('get_the_excerpt', 'lyte_trim_excerpt');
497
+ add_action('schedule_captions_lookup', 'captions_lookup', 1, 3);
498
 
499
  /** API: action hook to allow extra actions or filters to be added */
500
  do_action("lyte_actionsfilters");