Version Description
- misc improvements as suggested by WordPress Plugins team
- filter added to set description as proposed & contributed by Patrick Robertson
- filter added to disable fallback to youtube thumbnail as proposed & contributed by Benjamin Pick
- logic added to switch to different type of lazyload behavior proposed & contributed by @softmanro
Download this release
Release Info
Developer | futtta |
Plugin | WP YouTube Lyte |
Version | 1.7.17 |
Comparing to | |
See all releases |
Code changes from version 1.7.16 to 1.7.17
- lyte/bg-image-layzload.js +51 -0
- lyte/bg-image-layzload.min.js +1 -0
- lyte/lyte-min.js +1 -1
- lyte/lyte.js +1 -0
- lyteCache.php +32 -14
- lytePartners.php +5 -5
- lyte_helper.php_example +4 -0
- options.php +10 -6
- readme.txt +7 -1
- widget.php +4 -4
- wp-youtube-lyte.php +63 -47
lyte/bg-image-layzload.js
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Original source taken from: https://imagekit.io/blog/lazy-loading-images-complete-guide/#lazy-loading-css-background-images
|
3 |
+
*/
|
4 |
+
|
5 |
+
document.addEventListener("DOMContentLoaded", function() {
|
6 |
+
var wyl_lazyloadImages;
|
7 |
+
|
8 |
+
if ("IntersectionObserver" in window) {
|
9 |
+
wyl_lazyloadImages = document.querySelectorAll(".wyl-lazy");
|
10 |
+
var imageObserver = new IntersectionObserver(function(entries, observer) {
|
11 |
+
entries.forEach(function(entry) {
|
12 |
+
if (entry.isIntersecting) {
|
13 |
+
var image = entry.target;
|
14 |
+
image.classList.remove("wyl-lazy");
|
15 |
+
imageObserver.unobserve(image);
|
16 |
+
}
|
17 |
+
});
|
18 |
+
});
|
19 |
+
|
20 |
+
wyl_lazyloadImages.forEach(function(image) {
|
21 |
+
imageObserver.observe(image);
|
22 |
+
});
|
23 |
+
} else {
|
24 |
+
var lazyloadThrottleTimeout;
|
25 |
+
wyl_lazyloadImages = document.querySelectorAll(".wyl-lazy");
|
26 |
+
|
27 |
+
function wyl_lazyload () {
|
28 |
+
if(lazyloadThrottleTimeout) {
|
29 |
+
clearTimeout(lazyloadThrottleTimeout);
|
30 |
+
}
|
31 |
+
|
32 |
+
lazyloadThrottleTimeout = setTimeout(function() {
|
33 |
+
var scrollTop = window.pageYOffset;
|
34 |
+
wyl_lazyloadImages.forEach(function(img) {
|
35 |
+
if(img.offsetTop < (window.innerHeight + scrollTop)) {
|
36 |
+
img.classList.remove('wyl-lazy');
|
37 |
+
}
|
38 |
+
});
|
39 |
+
if(wyl_lazyloadImages.length == 0) {
|
40 |
+
document.removeEventListener("scroll", wyl_lazyload);
|
41 |
+
window.removeEventListener("resize", wyl_lazyload);
|
42 |
+
window.removeEventListener("orientationChange", wyl_lazyload);
|
43 |
+
}
|
44 |
+
}, 20);
|
45 |
+
}
|
46 |
+
|
47 |
+
document.addEventListener("scroll", wyl_lazyload);
|
48 |
+
window.addEventListener("resize", wyl_lazyload);
|
49 |
+
window.addEventListener("orientationChange", wyl_lazyload);
|
50 |
+
}
|
51 |
+
})
|
lyte/bg-image-layzload.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
document.addEventListener("DOMContentLoaded",function(){var e;if("IntersectionObserver"in window){e=document.querySelectorAll(".wyl-lazy");var n=new IntersectionObserver(function(e,t){e.forEach(function(e){if(e.isIntersecting){var t=e.target;t.classList.remove("wyl-lazy"),n.unobserve(t)}})});e.forEach(function(e){n.observe(e)})}else{var t;function o(){t&&clearTimeout(t),t=setTimeout(function(){var n=window.pageYOffset;e.forEach(function(e){e.offsetTop<window.innerHeight+n&&e.classList.remove("wyl-lazy")}),0==e.length&&(document.removeEventListener("scroll",o),window.removeEventListener("resize",o),window.removeEventListener("orientationChange",o))},20)}e=document.querySelectorAll(".wyl-lazy"),document.addEventListener("scroll",o),window.addEventListener("resize",o),window.addEventListener("orientationChange",o)}});
|
lyte/lyte-min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
(function(e){var t=document;var n="https";e.te=function(){if(!r){var r=1;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(mOs===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-nocookie.com/embed/"+vid+"?"}else{eU=n+"://www.youtube-nocookie.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 allow="autoplay"></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)}})()
|
1 |
+
(function(e){var t=document;var n="https";e.te=function(){if(!r){var r=1;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(mOs===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);e.addCss("#"+bgId+".wyl-lazy { background-image: none; background-color: #ccc; }");}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-nocookie.com/embed/"+vid+"?"}else{eU=n+"://www.youtube-nocookie.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 allow="autoplay"></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
@@ -22,6 +22,7 @@ ly.te = function() {
|
|
22 |
if (thumb !== "") {
|
23 |
bgCss="#"+bgId+" { background-image: url("+thumb+"); }";
|
24 |
ly.addCss(bgCss);
|
|
|
25 |
} else {
|
26 |
scr = d.createElement('script');
|
27 |
scr.src = sch+"://gdata.youtube.com/feeds/api/playlists/"+ vid +"?v=2&alt=json-in-script&callback=ly.parsePL&fields=id,entry";
|
22 |
if (thumb !== "") {
|
23 |
bgCss="#"+bgId+" { background-image: url("+thumb+"); }";
|
24 |
ly.addCss(bgCss);
|
25 |
+
ly.addCss("#"+bgId+".wyl-lazy { background-image: none; background-color: #ccc; }");
|
26 |
} else {
|
27 |
scr = d.createElement('script');
|
28 |
scr.src = sch+"://gdata.youtube.com/feeds/api/playlists/"+ vid +"?v=2&alt=json-in-script&callback=ly.parsePL&fields=id,entry";
|
lyteCache.php
CHANGED
@@ -10,8 +10,16 @@
|
|
10 |
*
|
11 |
*/
|
12 |
|
13 |
-
// no error reporting, those break header() output
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
/*
|
17 |
* step 0: set constant for dir where thumbs are stored + declaring some variables
|
@@ -42,7 +50,6 @@ if ( array_key_exists( 'reportErr', $_GET ) ) {
|
|
42 |
/*
|
43 |
* step 2: check if it is safe to serve from cache and redirect if not.
|
44 |
*/
|
45 |
-
|
46 |
if ( ! file_exists( LYTE_CACHE_DIR ) || ( file_exists( LYTE_CACHE_DIR . '/doubleCheckLyteThumbnailCache.txt' ) && ! array_key_exists( 'lyteCookie', $_COOKIE ) ) ) {
|
47 |
// local thumbnail caching not on or no cookie found, redirect to original at youtube.
|
48 |
$lyte_thumb_error = 'possible hotlinker/';
|
@@ -72,7 +79,7 @@ $now = time();
|
|
72 |
|
73 |
if ( ! file_exists( $localThumb ) || $lyte_thumb_dontsave || ( file_exists( $localThumb ) && $expiryTime < $now ) ) {
|
74 |
$thumbContents = lyte_get_thumb( $origThumbURL );
|
75 |
-
|
76 |
if ( $thumbContents != '' && ! $lyte_thumb_dontsave ) {
|
77 |
// save file but immediately check if it is a jpeg and delete if not.
|
78 |
file_put_contents( $localThumb, $thumbContents );
|
@@ -118,7 +125,11 @@ function lyte_output_image( $thumbContents, $contentType = 'image/jpeg' ) {
|
|
118 |
header( 'Connection: close' );
|
119 |
} else {
|
120 |
// send all sorts of headers
|
121 |
-
|
|
|
|
|
|
|
|
|
122 |
header( 'Content-Length: '. strlen( $thumbContents) );
|
123 |
header( 'Cache-Control: max-age=' . $expireTime . ', public, immutable' );
|
124 |
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expireTime ).' GMT' );
|
@@ -145,7 +156,7 @@ function is_jpeg( $in ) {
|
|
145 |
return true;
|
146 |
} else {
|
147 |
return false;
|
148 |
-
}
|
149 |
}
|
150 |
|
151 |
function lyte_check_cache_dir( $dir ) {
|
@@ -176,16 +187,21 @@ function lyte_get_thumb( $thumbUrl ) {
|
|
176 |
$lyte_thumb_error .= 'no curl/ ';
|
177 |
}
|
178 |
|
179 |
-
// if no curl or if curl error
|
180 |
-
|
181 |
-
return $
|
182 |
}
|
183 |
|
184 |
function get_origThumbURL() {
|
185 |
$invalid = false;
|
186 |
|
187 |
-
//
|
188 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
189 |
$origThumbURL = urldecode( $_GET['origThumbUrl'] );
|
190 |
} else {
|
191 |
$invalid = true;
|
@@ -225,12 +241,14 @@ function lyte_thumb_fallback() {
|
|
225 |
}
|
226 |
|
227 |
if ( strpos( $origThumbURL, 'http' ) !== 0) {
|
228 |
-
$origThumbURL = 'https:' . $origThumbURL;
|
229 |
}
|
230 |
if ( $lyte_thumb_report_err ) {
|
231 |
header( 'X-lyte-error: '.$lyte_thumb_error );
|
232 |
}
|
233 |
-
|
234 |
-
header(
|
|
|
|
|
235 |
exit;
|
236 |
}
|
10 |
*
|
11 |
*/
|
12 |
|
13 |
+
// no error reporting, those break header() output but only if standalone to avoid impact on other plugins.
|
14 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
15 |
+
error_reporting( 0 );
|
16 |
+
}
|
17 |
+
|
18 |
+
// include our custom configuration file in case it exists
|
19 |
+
$wp_root_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
|
20 |
+
if ( file_exists( $wp_root_path . 'lyteCache-config.php' ) ) {
|
21 |
+
require_once( $wp_root_path . 'lyteCache-config.php' );
|
22 |
+
}
|
23 |
|
24 |
/*
|
25 |
* step 0: set constant for dir where thumbs are stored + declaring some variables
|
50 |
/*
|
51 |
* step 2: check if it is safe to serve from cache and redirect if not.
|
52 |
*/
|
|
|
53 |
if ( ! file_exists( LYTE_CACHE_DIR ) || ( file_exists( LYTE_CACHE_DIR . '/doubleCheckLyteThumbnailCache.txt' ) && ! array_key_exists( 'lyteCookie', $_COOKIE ) ) ) {
|
54 |
// local thumbnail caching not on or no cookie found, redirect to original at youtube.
|
55 |
$lyte_thumb_error = 'possible hotlinker/';
|
79 |
|
80 |
if ( ! file_exists( $localThumb ) || $lyte_thumb_dontsave || ( file_exists( $localThumb ) && $expiryTime < $now ) ) {
|
81 |
$thumbContents = lyte_get_thumb( $origThumbURL );
|
82 |
+
|
83 |
if ( $thumbContents != '' && ! $lyte_thumb_dontsave ) {
|
84 |
// save file but immediately check if it is a jpeg and delete if not.
|
85 |
file_put_contents( $localThumb, $thumbContents );
|
125 |
header( 'Connection: close' );
|
126 |
} else {
|
127 |
// send all sorts of headers
|
128 |
+
if ( ! defined( 'LYTE_CACHE_EXPIRE_TIME' ) ) {
|
129 |
+
$expireTime = 60 * 60 * 24 * 7; // 1w
|
130 |
+
} else {
|
131 |
+
$expireTime = LYTE_CACHE_EXPIRE_TIME;
|
132 |
+
}
|
133 |
header( 'Content-Length: '. strlen( $thumbContents) );
|
134 |
header( 'Cache-Control: max-age=' . $expireTime . ', public, immutable' );
|
135 |
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expireTime ).' GMT' );
|
156 |
return true;
|
157 |
} else {
|
158 |
return false;
|
159 |
+
}
|
160 |
}
|
161 |
|
162 |
function lyte_check_cache_dir( $dir ) {
|
187 |
$lyte_thumb_error .= 'no curl/ ';
|
188 |
}
|
189 |
|
190 |
+
// if no curl or if curl error
|
191 |
+
// consider switching to alternative approach (fsockopen/ streams)?
|
192 |
+
return file_get_contents( $thumbUrl );
|
193 |
}
|
194 |
|
195 |
function get_origThumbURL() {
|
196 |
$invalid = false;
|
197 |
|
198 |
+
// if origThumbUrl has no scheme prepend it with "https:" (else filter_var fails).
|
199 |
+
if ( 0 === strpos( $_GET['origThumbUrl'], '//' ) ) {
|
200 |
+
$_GET['origThumbUrl'] = 'https:' . $_GET['origThumbUrl'];
|
201 |
+
}
|
202 |
+
|
203 |
+
// get thumbnail-url from request.
|
204 |
+
if ( array_key_exists( 'origThumbUrl', $_GET ) && $_GET['origThumbUrl'] !== '' && 0 === strpos( $_GET['origThumbUrl'], 'https://' ) && false !== filter_var( $_GET['origThumbUrl'], FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED ) ) {
|
205 |
$origThumbURL = urldecode( $_GET['origThumbUrl'] );
|
206 |
} else {
|
207 |
$invalid = true;
|
241 |
}
|
242 |
|
243 |
if ( strpos( $origThumbURL, 'http' ) !== 0) {
|
244 |
+
$origThumbURL = 'https:' . $origThumbURL;
|
245 |
}
|
246 |
if ( $lyte_thumb_report_err ) {
|
247 |
header( 'X-lyte-error: '.$lyte_thumb_error );
|
248 |
}
|
249 |
+
// avoid caching and use a "soft" redirect, as we might have got here due to some temporary issue
|
250 |
+
header('Cache-Control: no-cache');
|
251 |
+
header('HTTP/1.1 302 Moved Temporarily');
|
252 |
+
header('Location: '. $origThumbURL );
|
253 |
exit;
|
254 |
}
|
lytePartners.php
CHANGED
@@ -84,7 +84,7 @@ function lyte_partners() {
|
|
84 |
}
|
85 |
|
86 |
function getLytePartnerFeed() {
|
87 |
-
$noFeedText=
|
88 |
|
89 |
if ( apply_filters( 'wp-youtube-lyte_settingsscreen_remotehttp', true ) ) {
|
90 |
$rss = fetch_feed( 'https://feeds.feedburner.com/OptimizingMattersDownloads' );
|
@@ -102,15 +102,15 @@ function getLytePartnerFeed() {
|
|
102 |
foreach ( $rss_items as $item ) :
|
103 |
$itemURL = esc_url( $item->get_permalink() ); ?>
|
104 |
<li class="itemDetail">
|
105 |
-
<h3 class="itemTitle"><a href="<?php echo $itemURL; ?>" target="_blank"><?php echo esc_html( $item->get_title() ); ?></a></h3>
|
106 |
<?php
|
107 |
-
if (($enclosure = $item->get_enclosure()) && ( strpos( $enclosure->get_type(), 'image') !== false ) ) {
|
108 |
$itemImgURL = esc_url( $enclosure->get_link() );
|
109 |
-
echo '<div class="itemImage"><a href="' . $itemURL . '" target="_blank"><img src="' . $itemImgURL . '"/></a></div>';
|
110 |
}
|
111 |
?>
|
112 |
<div class="itemDescription"><?php echo wp_kses_post($item -> get_description() ); ?></div>
|
113 |
-
<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="<?php echo $itemURL; ?>" target="_blank">More info</a></div></div>
|
114 |
</li>
|
115 |
<?php endforeach; ?>
|
116 |
<?php } ?>
|
84 |
}
|
85 |
|
86 |
function getLytePartnerFeed() {
|
87 |
+
$noFeedText = esc_html__( 'Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for wp-youtube-lyte power-ups!', 'wp-youtube-lyte' );
|
88 |
|
89 |
if ( apply_filters( 'wp-youtube-lyte_settingsscreen_remotehttp', true ) ) {
|
90 |
$rss = fetch_feed( 'https://feeds.feedburner.com/OptimizingMattersDownloads' );
|
102 |
foreach ( $rss_items as $item ) :
|
103 |
$itemURL = esc_url( $item->get_permalink() ); ?>
|
104 |
<li class="itemDetail">
|
105 |
+
<h3 class="itemTitle"><a href="<?php echo esc_url( $itemURL ); ?>" target="_blank"><?php echo esc_html( $item->get_title() ); ?></a></h3>
|
106 |
<?php
|
107 |
+
if ( ( $enclosure = $item->get_enclosure() ) && ( strpos( $enclosure->get_type(), 'image') !== false ) ) {
|
108 |
$itemImgURL = esc_url( $enclosure->get_link() );
|
109 |
+
echo '<div class="itemImage"><a href="' . esc_url( $itemURL ) . '" target="_blank"><img src="' . esc_url( $itemImgURL ) . '"/></a></div>';
|
110 |
}
|
111 |
?>
|
112 |
<div class="itemDescription"><?php echo wp_kses_post($item -> get_description() ); ?></div>
|
113 |
+
<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="<?php echo esc_url( $itemURL ); ?>" target="_blank">More info</a></div></div>
|
114 |
</li>
|
115 |
<?php endforeach; ?>
|
116 |
<?php } ?>
|
lyte_helper.php_example
CHANGED
@@ -110,4 +110,8 @@ function fgo_lyte_change_css($lyte_css) {
|
|
110 |
function no_lyte_on_mobile(){
|
111 |
return false;
|
112 |
}
|
|
|
|
|
|
|
|
|
113 |
?>
|
110 |
function no_lyte_on_mobile(){
|
111 |
return false;
|
112 |
}
|
113 |
+
|
114 |
+
/** activate internal lazy loader if you don't have another one configured on your site; the default for this filter is false */
|
115 |
+
//add_filter('lyte_use_internal_lazyloader','__return_true');
|
116 |
+
|
117 |
?>
|
options.php
CHANGED
@@ -400,14 +400,18 @@ function lyte_settings_page() {
|
|
400 |
add_action( 'wp_ajax_lyte_check_yt_api_key', 'lyte_check_yt_api_key_callback' );
|
401 |
function lyte_check_yt_api_key_callback() {
|
402 |
check_ajax_referer( 'lyte_check_api_key', 'lyte_nonce' );
|
403 |
-
$api_key =
|
404 |
|
405 |
// use random video to make sure a cache is not spoiling things
|
406 |
$vidToCheck = array('ZmnZHudtzXg', '2_7oQcAkyl8', 'nOvv80wkSgI', 'pBCt5nfsZ30', 'KHw7gdJ14uQ', 'qJ_PMvjmC6M', 'DVwHCGAr_OE', 'LtOGa5M8AuU', 'VHO9uZX9FNU' );
|
407 |
$randVidIndex = array_rand( $vidToCheck );
|
408 |
|
409 |
-
|
410 |
-
|
|
|
|
|
|
|
|
|
411 |
if ( is_array( $api_response ) ) {
|
412 |
if ( ! empty( $api_response['title'] ) ) {
|
413 |
_e( 'API seems OK, you can Save Changes below now.', 'wp-youtube-lyte' );
|
@@ -485,9 +489,9 @@ if ( apply_filters( 'lyte_settingsscreen_remotehttp', true ) ) {
|
|
485 |
function lyte_admin_tabs(){
|
486 |
$tabs = apply_filters( 'wp-youtube-lyte_filter_settingsscreen_tabs', array( 'lyte_settings_page' => __('Main', 'wp-youtube-lyte' ) ) );
|
487 |
$tabContent = '';
|
488 |
-
if (count($tabs) >= 1) {
|
489 |
-
if(isset($_GET['page'])){
|
490 |
-
$currentId = $_GET['page'];
|
491 |
} else {
|
492 |
$currentId = 'wp-youtube-lyte';
|
493 |
}
|
400 |
add_action( 'wp_ajax_lyte_check_yt_api_key', 'lyte_check_yt_api_key_callback' );
|
401 |
function lyte_check_yt_api_key_callback() {
|
402 |
check_ajax_referer( 'lyte_check_api_key', 'lyte_nonce' );
|
403 |
+
$api_key = ( ctype_alnum( $_POST['lyte_yt_api_key'] ) ) ? $_POST['lyte_yt_api_key'] : '' ;
|
404 |
|
405 |
// use random video to make sure a cache is not spoiling things
|
406 |
$vidToCheck = array('ZmnZHudtzXg', '2_7oQcAkyl8', 'nOvv80wkSgI', 'pBCt5nfsZ30', 'KHw7gdJ14uQ', 'qJ_PMvjmC6M', 'DVwHCGAr_OE', 'LtOGa5M8AuU', 'VHO9uZX9FNU' );
|
407 |
$randVidIndex = array_rand( $vidToCheck );
|
408 |
|
409 |
+
if ( ! empty( $api_key ) ) {
|
410 |
+
$api_response = lyte_get_YT_resp( $vidToCheck[$randVidIndex], false, '', $api_key );
|
411 |
+
} else {
|
412 |
+
$api_response = 'API key not alphanumeric.';
|
413 |
+
}
|
414 |
+
|
415 |
if ( is_array( $api_response ) ) {
|
416 |
if ( ! empty( $api_response['title'] ) ) {
|
417 |
_e( 'API seems OK, you can Save Changes below now.', 'wp-youtube-lyte' );
|
489 |
function lyte_admin_tabs(){
|
490 |
$tabs = apply_filters( 'wp-youtube-lyte_filter_settingsscreen_tabs', array( 'lyte_settings_page' => __('Main', 'wp-youtube-lyte' ) ) );
|
491 |
$tabContent = '';
|
492 |
+
if ( count( $tabs ) >= 1 ) {
|
493 |
+
if( isset( $_GET['page'] ) ) {
|
494 |
+
$currentId = sanitize_text_field( $_GET['page'] );
|
495 |
} else {
|
496 |
$currentId = 'wp-youtube-lyte';
|
497 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: youtube, video, performance, gdpr, lazy load
|
|
4 |
Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
|
5 |
Requires at least: 4.0
|
6 |
Tested up to: 5.7
|
7 |
-
Stable tag: 1.7.
|
8 |
|
9 |
High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
|
10 |
|
@@ -143,6 +143,12 @@ Just tell me, I like the feedback! Use the [Contact-page on my blog](http://blog
|
|
143 |
|
144 |
== Changelog ==
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
= 1.7.16 =
|
147 |
* removed old captions code (captions are not natively supported through the YouTube API + the Benetech backend was no longer working)
|
148 |
* added extra sanitization, thanks m0ze!
|
4 |
Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
|
5 |
Requires at least: 4.0
|
6 |
Tested up to: 5.7
|
7 |
+
Stable tag: 1.7.17
|
8 |
|
9 |
High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
|
10 |
|
143 |
|
144 |
== Changelog ==
|
145 |
|
146 |
+
= 1.7.17 =
|
147 |
+
* misc improvements as suggested by WordPress Plugins team
|
148 |
+
* filter added to set description as proposed & contributed by Patrick Robertson
|
149 |
+
* filter added to disable fallback to youtube thumbnail as proposed & contributed by Benjamin Pick
|
150 |
+
* logic added to switch to different type of lazyload behavior proposed & contributed by @softmanro
|
151 |
+
|
152 |
= 1.7.16 =
|
153 |
* removed old captions code (captions are not natively supported through the YouTube API + the Benetech backend was no longer working)
|
154 |
* added extra sanitization, thanks m0ze!
|
widget.php
CHANGED
@@ -160,13 +160,13 @@ class WYLWidget extends WP_Widget {
|
|
160 |
$vselected = ' selected="true"';
|
161 |
$aselected = '';
|
162 |
}
|
163 |
-
echo '<option value="audio"' . $aselected . '>' . __( 'audio', 'wp-youtube-lyte' ) . '</option>';
|
164 |
-
echo '<option value="video"' . $vselected . '>' . __( 'video', 'wp-youtube-lyte' ) . '</option>';
|
165 |
?>
|
166 |
</select>
|
167 |
</label></p>
|
168 |
-
<p><label for="<?php echo $this->get_field_id( 'WYLurl' ); ?>"><?php _e( 'Youtube-URL:', 'wp-youtube-lyte' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'WYLurl' ); ?>" name="<?php echo $this->get_field_name( 'WYLurl' ); ?>" type="text" value="<?php echo $WYLurl; ?>" /></label></p>
|
169 |
-
<p><label for="<?php echo $this->get_field_id( 'WYLtext' ); ?>"><?php _e( 'Text:', 'wp-youtube-lyte' ); ?> <textarea class="widefat" id="<?php echo $this->get_field_id( 'WYLtext' ); ?>" name="<?php echo $this->get_field_name( 'WYLtext' ); ?>" rows="16" cols="20"><?php echo $WYLtext; ?></textarea></label></p>
|
170 |
<?php
|
171 |
}
|
172 |
}
|
160 |
$vselected = ' selected="true"';
|
161 |
$aselected = '';
|
162 |
}
|
163 |
+
echo '<option value="audio"' . esc_html( $aselected ) . '>' . __( 'audio', 'wp-youtube-lyte' ) . '</option>';
|
164 |
+
echo '<option value="video"' . esc_html( $vselected ) . '>' . __( 'video', 'wp-youtube-lyte' ) . '</option>';
|
165 |
?>
|
166 |
</select>
|
167 |
</label></p>
|
168 |
+
<p><label for="<?php echo $this->get_field_id( 'WYLurl' ); ?>"><?php _e( 'Youtube-URL:', 'wp-youtube-lyte' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'WYLurl' ); ?>" name="<?php echo $this->get_field_name( 'WYLurl' ); ?>" type="text" value="<?php echo esc_url( $WYLurl ); ?>" /></label></p>
|
169 |
+
<p><label for="<?php echo esc_html( $this->get_field_id( 'WYLtext' ) ); ?>"><?php _e( 'Text:', 'wp-youtube-lyte' ); ?> <textarea class="widefat" id="<?php echo esc_html( $this->get_field_id( 'WYLtext' ) ); ?>" name="<?php echo esc_html( $this->get_field_name( 'WYLtext' ) ); ?>" rows="16" cols="20"><?php echo esc_html( $WYLtext ); ?></textarea></label></p>
|
170 |
<?php
|
171 |
}
|
172 |
}
|
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.
|
8 |
Author URI: http://blog.futtta.be/
|
9 |
Text Domain: wp-youtube-lyte
|
10 |
*/
|
@@ -12,33 +12,33 @@ Text Domain: wp-youtube-lyte
|
|
12 |
if ( ! defined( 'ABSPATH' ) ) exit;
|
13 |
|
14 |
$debug = false;
|
15 |
-
$lyte_version = '1.7.
|
16 |
$lyte_db_version = get_option( 'lyte_version', 'none' );
|
17 |
|
18 |
/** have we updated? */
|
19 |
if ($lyte_db_version !== $lyte_version) {
|
20 |
switch( $lyte_db_version ) {
|
21 |
-
case
|
22 |
lyte_rm_cache();
|
23 |
break;
|
24 |
-
case
|
25 |
-
case
|
26 |
-
case
|
27 |
lyte_rm_cache();
|
28 |
lyte_not_greedy();
|
29 |
break;
|
30 |
-
case
|
31 |
-
case
|
32 |
-
case
|
33 |
-
case
|
34 |
-
case
|
35 |
-
case
|
36 |
-
case
|
37 |
-
case
|
38 |
-
case
|
39 |
-
case
|
40 |
-
case
|
41 |
-
case
|
42 |
lyte_mv_cache();
|
43 |
break;
|
44 |
}
|
@@ -47,33 +47,38 @@ if ($lyte_db_version !== $lyte_version) {
|
|
47 |
}
|
48 |
|
49 |
/** are we in debug-mode */
|
50 |
-
|
51 |
-
|
52 |
-
$
|
|
|
|
|
53 |
} else {
|
54 |
-
$wyl_version
|
55 |
-
$wyl_file
|
|
|
56 |
lyte_rm_cache();
|
57 |
}
|
58 |
|
59 |
/** get paths, language and includes */
|
60 |
-
$plugin_dir = basename(dirname(__FILE__)).'/languages';
|
61 |
load_plugin_textdomain( 'wp-youtube-lyte', null, $plugin_dir );
|
62 |
-
require_once(dirname(__FILE__).'/player_sizes.inc.php');
|
63 |
-
require_once(dirname(__FILE__).'/widget.php');
|
64 |
|
65 |
/** get default embed size and build array to change size later if requested */
|
66 |
-
$oSize = (int) get_option('lyte_size');
|
67 |
if ( (is_bool( $oSize ) ) || ( $pSize[$oSize]['a'] === false ) ) {
|
68 |
-
$sel = (int) $pDefault;
|
|
|
|
|
69 |
}
|
70 |
|
71 |
$pSizeFormat = $pSize[$sel]['f'];
|
72 |
$j = 0;
|
73 |
|
74 |
foreach ( $pSizeOrder[$pSizeFormat] as $sizeId ) {
|
75 |
-
$sArray[$j]['w']=(int) $pSize[$sizeId]['w'];
|
76 |
-
$sArray[$j]['h']=(int) $pSize[$sizeId]['h'];
|
77 |
if ( $sizeId === $sel ) {
|
78 |
$selSize=$j;
|
79 |
}
|
@@ -81,22 +86,24 @@ foreach ( $pSizeOrder[$pSizeFormat] as $sizeId ) {
|
|
81 |
}
|
82 |
|
83 |
/** get other options and push in array*/
|
84 |
-
$lyteSettings['sizeArray']
|
85 |
-
$lyteSettings['selSize']
|
86 |
-
$lyteSettings['links']
|
87 |
-
$lyteSettings['file']
|
88 |
-
$lyteSettings['
|
89 |
-
$lyteSettings['
|
90 |
-
$lyteSettings['
|
91 |
-
$lyteSettings['
|
92 |
-
$lyteSettings['
|
|
|
93 |
|
94 |
/** API: filter hook to alter $lyteSettings */
|
95 |
function lyte_settings_enforcer() {
|
96 |
global $lyteSettings;
|
|
|
97 |
$lyteSettings = apply_filters( 'lyte_settings', $lyteSettings );
|
98 |
}
|
99 |
-
add_action('after_setup_theme','lyte_settings_enforcer');
|
100 |
|
101 |
function lyte_parse( $the_content, $doExcerpt = false ) {
|
102 |
/** bail if AMP or if LYTE feed disabled and is_feed */
|
@@ -113,7 +120,7 @@ function lyte_parse( $the_content, $doExcerpt = false ) {
|
|
113 |
/** API: filter hook to preparse the_content, e.g. to force normal youtube links to be parsed */
|
114 |
$the_content = apply_filters( 'lyte_content_preparse', $the_content );
|
115 |
|
116 |
-
if ( get_option( 'lyte_greedy', '1' ) ===
|
117 |
// new: also replace original YT embed code (iframes)
|
118 |
if ( apply_filters( 'lyte_eats_yframes', true ) && preg_match_all( '#<iframe(?:[^<]*)?\ssrc=["|\'](?:http(?:s)?:)?\/\/www\.youtube(?:-nocookie)?\.com\/embed\/(.*)["|\'](?:.*)><\/iframe>#Usm', $the_content, $matches, PREG_SET_ORDER ) ) {
|
119 |
foreach ( $matches as $match ) {
|
@@ -254,12 +261,13 @@ function lyte_parse( $the_content, $doExcerpt = false ) {
|
|
254 |
|
255 |
// add disclaimer to lytelinks
|
256 |
$disclaimer = wp_kses_data( get_option( 'lyte_disclaimer', '') );
|
|
|
257 |
if ( !empty( $disclaimer ) ) {
|
258 |
$disclaimer = '<span class="lyte_disclaimer">' . $disclaimer . '</span>';
|
259 |
}
|
260 |
|
261 |
if ( $disclaimer && empty( $lytelinks_txt ) ) {
|
262 |
-
$lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] . '">' . $
|
263 |
} else if ( $disclaimer ) {
|
264 |
$lytelinks_txt = str_replace( '</div>', '<br/>' . $disclaimer . '</div>', $lytelinks_txt );
|
265 |
}
|
@@ -351,11 +359,10 @@ function lyte_parse( $the_content, $doExcerpt = false ) {
|
|
351 |
$lytetemplate = '<a href="' . $postURL . '"><img src="' . $thumbUrl . '" alt="YouTube Video"></a>' . $textLink;
|
352 |
$templateType = 'feed';
|
353 |
} elseif ( $audio !== true && $plClass !== " playlist" && $lyteSettings['microdata'] === "1" && $noMicroData !== "1" ) {
|
354 |
-
$lytetemplate = $wrapper . '<div class="lyMe' . $audioClass . $hidefClass . $plClass . $qsaClass . '" id="WYL_' . $vid . '" itemprop="video" itemscope itemtype="https://schema.org/VideoObject"><div><meta itemprop="thumbnailUrl" content="' . $thumbUrl . '" /><meta itemprop="embedURL" content="https://www.youtube.com/embed/' . $vid . '" /><meta itemprop="duration" content="' . $yt_resp_array['duration'] . '" /><meta itemprop="uploadDate" content="' . $yt_resp_array["dateField"] . '" /></div>' . $captionsMeta. '<div id="lyte_' . $vid . '" data-src="' . $thumbUrl . '" class="pL"><div class="tC' . $titleClass . '"><div class="tT" itemprop="name">' . $yt_resp_array["title"] . '</div></div><div class="play"></div><div class="ctrl"><div class="Lctrl"></div><div class="Rctrl"></div></div></div>' . $noscript . '<meta itemprop="description" content="' . $yt_resp_array["description"] . '"></div></div>' . $lytelinks_txt;
|
355 |
$templateType = 'postMicrodata';
|
356 |
} else {
|
357 |
-
$lytetemplate = $wrapper . '<div class="lyMe' . $audioClass . $hidefClass . $plClass . $qsaClass . '" id="WYL_' . $vid . '"><div id="lyte_' . $vid . '" data-src="' . $thumbUrl . '" class="pL">';
|
358 |
-
|
359 |
if ( isset( $_this_title ) ) {
|
360 |
$lytetemplate .= '<div class="tC' . $titleClass . '"><div class="tT">' . $_this_title . '</div></div>';
|
361 |
}
|
@@ -576,9 +583,18 @@ function lyte_init( $echo = true ) {
|
|
576 |
/** API: filter hook to change css */
|
577 |
$lyte_css = apply_filters( 'lyte_css', $lyte_css );
|
578 |
|
|
|
|
|
|
|
|
|
|
|
|
|
579 |
$inline_js = '<script type="text/javascript" data-cfasync="false">var bU="' . $lyteSettings['path'] . '";' . $mobJS . $doublecheck_thumb_cookie . 'style = document.createElement("style");style.type = "text/css";rules = document.createTextNode("' . $lyte_css . '");if(style.styleSheet) { style.styleSheet.cssText = rules.nodeValue;} else {style.appendChild(rules);}document.getElementsByTagName("head")[0].appendChild(style);</script>';
|
580 |
$linked_js = '<script type="text/javascript" data-cfasync="false" async src="' . $lyteSettings['path'] . $lyteSettings['file'] . '"></script>';
|
581 |
-
|
|
|
|
|
|
|
582 |
if ( false !== $echo ) {
|
583 |
echo $inline_js . $linked_js;
|
584 |
} else {
|
@@ -810,7 +826,7 @@ if ( is_admin() ) {
|
|
810 |
add_filter( 'the_content', 'lyte_parse', 10 );
|
811 |
add_shortcode( 'lyte', 'shortcode_lyte' );
|
812 |
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
|
813 |
-
add_filter( 'get_the_excerpt', 'lyte_trim_excerpt' );
|
814 |
add_action( 'init', 'lytecache_doublecheck_activator' );
|
815 |
|
816 |
/** API: action hook to allow extra actions or filters to be added */
|
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.17
|
8 |
Author URI: http://blog.futtta.be/
|
9 |
Text Domain: wp-youtube-lyte
|
10 |
*/
|
12 |
if ( ! defined( 'ABSPATH' ) ) exit;
|
13 |
|
14 |
$debug = false;
|
15 |
+
$lyte_version = '1.7.17';
|
16 |
$lyte_db_version = get_option( 'lyte_version', 'none' );
|
17 |
|
18 |
/** have we updated? */
|
19 |
if ($lyte_db_version !== $lyte_version) {
|
20 |
switch( $lyte_db_version ) {
|
21 |
+
case '1.5.0':
|
22 |
lyte_rm_cache();
|
23 |
break;
|
24 |
+
case '1.4.2':
|
25 |
+
case '1.4.1':
|
26 |
+
case '1.4.0':
|
27 |
lyte_rm_cache();
|
28 |
lyte_not_greedy();
|
29 |
break;
|
30 |
+
case '1.7.0':
|
31 |
+
case '1.7.1':
|
32 |
+
case '1.7.2':
|
33 |
+
case '1.7.3':
|
34 |
+
case '1.7.4':
|
35 |
+
case '1.7.5':
|
36 |
+
case '1.7.6':
|
37 |
+
case '1.7.7':
|
38 |
+
case '1.7.8':
|
39 |
+
case '1.7.9':
|
40 |
+
case '1.7.10':
|
41 |
+
case '1.7.11':
|
42 |
lyte_mv_cache();
|
43 |
break;
|
44 |
}
|
47 |
}
|
48 |
|
49 |
/** are we in debug-mode */
|
50 |
+
|
51 |
+
if (!$debug) {
|
52 |
+
$wyl_version = $lyte_version;
|
53 |
+
$wyl_file = 'lyte-min.js';
|
54 |
+
$wyl_file_lazyload = 'bg-image-layzload.min.js';
|
55 |
} else {
|
56 |
+
$wyl_version = rand()/1000;
|
57 |
+
$wyl_file = 'lyte.js';
|
58 |
+
$wyl_file_lazyload = 'bg-image-layzload.js';
|
59 |
lyte_rm_cache();
|
60 |
}
|
61 |
|
62 |
/** get paths, language and includes */
|
63 |
+
$plugin_dir = basename( dirname( __FILE__ ) ) . '/languages';
|
64 |
load_plugin_textdomain( 'wp-youtube-lyte', null, $plugin_dir );
|
65 |
+
require_once( dirname( __FILE__ ) . '/player_sizes.inc.php' );
|
66 |
+
require_once( dirname( __FILE__ ) . '/widget.php' );
|
67 |
|
68 |
/** get default embed size and build array to change size later if requested */
|
69 |
+
$oSize = (int) get_option( 'lyte_size' );
|
70 |
if ( (is_bool( $oSize ) ) || ( $pSize[$oSize]['a'] === false ) ) {
|
71 |
+
$sel = (int) $pDefault;
|
72 |
+
} else {
|
73 |
+
$sel=$oSize;
|
74 |
}
|
75 |
|
76 |
$pSizeFormat = $pSize[$sel]['f'];
|
77 |
$j = 0;
|
78 |
|
79 |
foreach ( $pSizeOrder[$pSizeFormat] as $sizeId ) {
|
80 |
+
$sArray[$j]['w'] = (int) $pSize[$sizeId]['w'];
|
81 |
+
$sArray[$j]['h'] = (int) $pSize[$sizeId]['h'];
|
82 |
if ( $sizeId === $sel ) {
|
83 |
$selSize=$j;
|
84 |
}
|
86 |
}
|
87 |
|
88 |
/** get other options and push in array*/
|
89 |
+
$lyteSettings['sizeArray'] = $sArray;
|
90 |
+
$lyteSettings['selSize'] = $selSize;
|
91 |
+
$lyteSettings['links'] = get_option( 'lyte_show_links' );
|
92 |
+
$lyteSettings['file'] = $wyl_file . '?wyl_version=' . $wyl_version;
|
93 |
+
$lyteSettings['file_lazyload'] = $wyl_file_lazyload . '?wyl_version=' . $wyl_version;
|
94 |
+
$lyteSettings['ratioClass'] = ( $pSizeFormat === '43' ) ? ' fourthree' : '';
|
95 |
+
$lyteSettings['pos'] = ( get_option( 'lyte_position', '0' ) === '1' ) ? 'margin:5px auto;' : 'margin:5px;';
|
96 |
+
$lyteSettings['microdata'] = get_option( 'lyte_microdata', '1' );
|
97 |
+
$lyteSettings['hidef'] = get_option( 'lyte_hidef', 0 );
|
98 |
+
$lyteSettings['scheme'] = ( is_ssl() ) ? 'https' : 'http';
|
99 |
|
100 |
/** API: filter hook to alter $lyteSettings */
|
101 |
function lyte_settings_enforcer() {
|
102 |
global $lyteSettings;
|
103 |
+
$lyteSettings['lyte_use_internal_lazyloader'] = apply_filters( 'lyte_use_internal_lazyloader', false );
|
104 |
$lyteSettings = apply_filters( 'lyte_settings', $lyteSettings );
|
105 |
}
|
106 |
+
add_action( 'after_setup_theme', 'lyte_settings_enforcer' );
|
107 |
|
108 |
function lyte_parse( $the_content, $doExcerpt = false ) {
|
109 |
/** bail if AMP or if LYTE feed disabled and is_feed */
|
120 |
/** API: filter hook to preparse the_content, e.g. to force normal youtube links to be parsed */
|
121 |
$the_content = apply_filters( 'lyte_content_preparse', $the_content );
|
122 |
|
123 |
+
if ( get_option( 'lyte_greedy', '1' ) === '1' && strpos( $the_content, 'youtu' ) !== false ){
|
124 |
// new: also replace original YT embed code (iframes)
|
125 |
if ( apply_filters( 'lyte_eats_yframes', true ) && preg_match_all( '#<iframe(?:[^<]*)?\ssrc=["|\'](?:http(?:s)?:)?\/\/www\.youtube(?:-nocookie)?\.com\/embed\/(.*)["|\'](?:.*)><\/iframe>#Usm', $the_content, $matches, PREG_SET_ORDER ) ) {
|
126 |
foreach ( $matches as $match ) {
|
261 |
|
262 |
// add disclaimer to lytelinks
|
263 |
$disclaimer = wp_kses_data( get_option( 'lyte_disclaimer', '') );
|
264 |
+
$disclaimer = apply_filters('lyte_disclaimer', $disclaimer);
|
265 |
if ( !empty( $disclaimer ) ) {
|
266 |
$disclaimer = '<span class="lyte_disclaimer">' . $disclaimer . '</span>';
|
267 |
}
|
268 |
|
269 |
if ( $disclaimer && empty( $lytelinks_txt ) ) {
|
270 |
+
$lytelinks_txt = '<div class="lL" style="max-width:100%;width:' . $lyteSettings[2] . 'px;' . $lyteSettings['pos'] . '">' . $disclaimer . '</div>';
|
271 |
} else if ( $disclaimer ) {
|
272 |
$lytelinks_txt = str_replace( '</div>', '<br/>' . $disclaimer . '</div>', $lytelinks_txt );
|
273 |
}
|
359 |
$lytetemplate = '<a href="' . $postURL . '"><img src="' . $thumbUrl . '" alt="YouTube Video"></a>' . $textLink;
|
360 |
$templateType = 'feed';
|
361 |
} elseif ( $audio !== true && $plClass !== " playlist" && $lyteSettings['microdata'] === "1" && $noMicroData !== "1" ) {
|
362 |
+
$lytetemplate = $wrapper . '<div class="lyMe' . $audioClass . $hidefClass . $plClass . $qsaClass . '" id="WYL_' . $vid . '" itemprop="video" itemscope itemtype="https://schema.org/VideoObject"><div><meta itemprop="thumbnailUrl" content="' . $thumbUrl . '" /><meta itemprop="embedURL" content="https://www.youtube.com/embed/' . $vid . '" /><meta itemprop="duration" content="' . $yt_resp_array['duration'] . '" /><meta itemprop="uploadDate" content="' . $yt_resp_array["dateField"] . '" /></div>' . $captionsMeta. '<div id="lyte_' . $vid . '" data-src="' . $thumbUrl . '" class="pL'.($lyteSettings['lyte_use_internal_lazyloader'] ? " wyl-lazy" : "").'"><div class="tC' . $titleClass . '"><div class="tT" itemprop="name">' . $yt_resp_array["title"] . '</div></div><div class="play"></div><div class="ctrl"><div class="Lctrl"></div><div class="Rctrl"></div></div></div>' . $noscript . '<meta itemprop="description" content="' . $yt_resp_array["description"] . '"></div></div>' . $lytelinks_txt;
|
363 |
$templateType = 'postMicrodata';
|
364 |
} else {
|
365 |
+
$lytetemplate = $wrapper . '<div class="lyMe' . $audioClass . $hidefClass . $plClass . $qsaClass . '" id="WYL_' . $vid . '"><div id="lyte_' . $vid . '" data-src="' . $thumbUrl . '" class="pL'.($lyteSettings['lyte_use_internal_lazyloader'] ? " wyl-lazy" : "").'">';
|
|
|
366 |
if ( isset( $_this_title ) ) {
|
367 |
$lytetemplate .= '<div class="tC' . $titleClass . '"><div class="tT">' . $_this_title . '</div></div>';
|
368 |
}
|
583 |
/** API: filter hook to change css */
|
584 |
$lyte_css = apply_filters( 'lyte_css', $lyte_css );
|
585 |
|
586 |
+
|
587 |
+
/** using esc_js on script tags breaks the JS as quotes are escaped, seems esc_js indeed is only to be used for onclick/ onfocus/ ... attributes.
|
588 |
+
echo '<script id="fgo1">' . esc_js('alert("boe")') . '</script>'; -> <script id="fgo1">alert("boe")</script>
|
589 |
+
echo '<script id="fgo2">' . esc_js("alert('boe')") . '</script>'; -> <script id="fgo2">alert(\'boe\')</script>
|
590 |
+
*/
|
591 |
+
|
592 |
$inline_js = '<script type="text/javascript" data-cfasync="false">var bU="' . $lyteSettings['path'] . '";' . $mobJS . $doublecheck_thumb_cookie . 'style = document.createElement("style");style.type = "text/css";rules = document.createTextNode("' . $lyte_css . '");if(style.styleSheet) { style.styleSheet.cssText = rules.nodeValue;} else {style.appendChild(rules);}document.getElementsByTagName("head")[0].appendChild(style);</script>';
|
593 |
$linked_js = '<script type="text/javascript" data-cfasync="false" async src="' . $lyteSettings['path'] . $lyteSettings['file'] . '"></script>';
|
594 |
+
if ( $lyteSettings['lyte_use_internal_lazyloader'] ) {
|
595 |
+
$linked_js .= '<script type="text/javascript" data-cfasync="false" async src="'.$lyteSettings['path'].$lyteSettings['file_lazyload'].'"></script>';
|
596 |
+
}
|
597 |
+
|
598 |
if ( false !== $echo ) {
|
599 |
echo $inline_js . $linked_js;
|
600 |
} else {
|
826 |
add_filter( 'the_content', 'lyte_parse', 10 );
|
827 |
add_shortcode( 'lyte', 'shortcode_lyte' );
|
828 |
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
|
829 |
+
add_filter( 'get_the_excerpt', 'lyte_trim_excerpt', 10, 2 );
|
830 |
add_action( 'init', 'lytecache_doublecheck_activator' );
|
831 |
|
832 |
/** API: action hook to allow extra actions or filters to be added */
|