Version Description
- WP YouTube Lyte now has an API to allow its behavior to be changed, with extensive examples in lyte_helper.php_example
- Support for higher quality thumbnails by adding #hqThumb=1 to httpv-link
- You can disable microdata on a per-video level by adding #noMicrodata=1 to the httpv-link when microdata is enabled.
- Checkbox on admin-page to flush WP YouTube Lyte cache (which holds title, description, ... from YouTube)
- added a lyte_preparse function to be used by themes/ plugins (input is the YouTube ID)
- improvement: added opacity to the play-button when not hovered over
- bugfix: suppress error messages if yt_resp does not contain all data
- bugfix: solve PHP notice for pS-array in options.php
Download this release
Release Info
Developer | futtta |
Plugin | WP YouTube Lyte |
Version | 1.3.0 |
Comparing to | |
See all releases |
Code changes from version 1.2.2 to 1.3.0
- lyte_helper.php_example +92 -0
- options.php +34 -2
- readme.txt +26 -13
- wp-youtube-lyte.php +78 -21
lyte_helper.php_example
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.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 |
+
|
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=)?/','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 css using lyte_css filter, e.g. to hide bottom control ui */
|
66 |
+
// add_filter('lyte_css','lyte_change_css',10,1);
|
67 |
+
function lyte_change_css($lyte_css) {
|
68 |
+
/** you can replace the entire css here or just add some declarations overriding the default ones */
|
69 |
+
return $lyte_css.=" .ctrl{display:none;}";
|
70 |
+
}
|
71 |
+
|
72 |
+
/** change setting from within code using lyte_settings filter */
|
73 |
+
// add_filter('lyte_settings','lyte_change_settings',10,1);
|
74 |
+
function lyte_change_settings($settingsArray) {
|
75 |
+
$settingsArray['links']="0";
|
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() {
|
82 |
+
add_filter('wp_head', lyte_init);
|
83 |
+
global $lynited;
|
84 |
+
$lynited=true;
|
85 |
+
}
|
86 |
+
|
87 |
+
/** function to filter out httpv/a links from description tag as generated by all in one seo pack */
|
88 |
+
// add_filter('aioseop_description','lyte_filter_aioseop_description');
|
89 |
+
function lyte_filter_aioseop_description($description) {
|
90 |
+
return preg_replace('/\shttp(v|a):\/\/([^\s<]*)/','',$description);
|
91 |
+
}
|
92 |
+
?>
|
options.php
CHANGED
@@ -4,6 +4,28 @@ load_plugin_textdomain( 'wp-youtube-lyte', false, $plugin_dir );
|
|
4 |
|
5 |
add_action('admin_menu', 'lyte_create_menu');
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
function lyte_create_menu() {
|
8 |
$hook=add_options_page( 'WP YouTube Lyte settings', 'WP YouTube Lyte', 'manage_options', 'lyte_settings_page', 'lyte_settings_page');
|
9 |
add_action( 'admin_init', 'register_lyte_settings' );
|
@@ -18,6 +40,7 @@ function register_lyte_settings() {
|
|
18 |
register_setting( 'lyte-settings-group', 'lyte_position' );
|
19 |
register_setting( 'lyte-settings-group', 'lyte_notification' );
|
20 |
register_setting( 'lyte-settings-group', 'lyte_microdata' );
|
|
|
21 |
}
|
22 |
|
23 |
function lyte_admin_scripts() {
|
@@ -61,9 +84,9 @@ function lyte_settings_page() {
|
|
61 |
foreach (array("169","43") as $f) {
|
62 |
foreach ($pSizeOrder[$f] as $i) {
|
63 |
$pS=$pSize[$i];
|
64 |
-
if ($pS[a]===true) {
|
65 |
?>
|
66 |
-
<label title="<?php echo $pS[w]."X".$pS[h]; ?>"><input type="radio" name="lyte_size" class="l_size" value="<?php echo $i."\"";if($i===$sel) echo " checked";echo " /> ".$pS[w]."X".$pS[h]." (".$pS[t];?>)</label><br />
|
67 |
<?php
|
68 |
}
|
69 |
}
|
@@ -114,6 +137,15 @@ function lyte_settings_page() {
|
|
114 |
</fieldset>
|
115 |
</td>
|
116 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
</table>
|
118 |
|
119 |
<p class="submit">
|
4 |
|
5 |
add_action('admin_menu', 'lyte_create_menu');
|
6 |
|
7 |
+
if (get_option('lyte_emptycache','0')==="1") {
|
8 |
+
$emptycache=lyte_rm_cache();
|
9 |
+
if ($emptycache==="OK") {
|
10 |
+
add_action('admin_notices', 'lyte_cacheclear_ok_notice');
|
11 |
+
} else {
|
12 |
+
add_action('admin_notices', 'lyte_cacheclear_fail_notice');
|
13 |
+
}
|
14 |
+
update_option('lyte_emptycache','0');
|
15 |
+
}
|
16 |
+
|
17 |
+
function lyte_cacheclear_ok_notice() {
|
18 |
+
echo '<div class="updated"><p>';
|
19 |
+
_e('Your WP YouTube Lyte cache has been succesfully cleared.', 'wp-youtube-lyte' );
|
20 |
+
echo '</p></div>';
|
21 |
+
}
|
22 |
+
|
23 |
+
function lyte_cacheclear_fail_notice() {
|
24 |
+
echo '<div class="error"><p>';
|
25 |
+
_e('There was a problem, the WP YouTube Lyte cache could not be cleared.', 'wp-youtube-lyte' );
|
26 |
+
echo '</p></div>';
|
27 |
+
}
|
28 |
+
|
29 |
function lyte_create_menu() {
|
30 |
$hook=add_options_page( 'WP YouTube Lyte settings', 'WP YouTube Lyte', 'manage_options', 'lyte_settings_page', 'lyte_settings_page');
|
31 |
add_action( 'admin_init', 'register_lyte_settings' );
|
40 |
register_setting( 'lyte-settings-group', 'lyte_position' );
|
41 |
register_setting( 'lyte-settings-group', 'lyte_notification' );
|
42 |
register_setting( 'lyte-settings-group', 'lyte_microdata' );
|
43 |
+
register_setting( 'lyte-settings-group', 'lyte_emptycache' );
|
44 |
}
|
45 |
|
46 |
function lyte_admin_scripts() {
|
84 |
foreach (array("169","43") as $f) {
|
85 |
foreach ($pSizeOrder[$f] as $i) {
|
86 |
$pS=$pSize[$i];
|
87 |
+
if ($pS['a']===true) {
|
88 |
?>
|
89 |
+
<label title="<?php echo $pS['w']."X".$pS['h']; ?>"><input type="radio" name="lyte_size" class="l_size" value="<?php echo $i."\"";if($i===$sel) echo " checked";echo " /> ".$pS['w']."X".$pS['h']." (".$pS['t'];?>)</label><br />
|
90 |
<?php
|
91 |
}
|
92 |
}
|
137 |
</fieldset>
|
138 |
</td>
|
139 |
</tr>
|
140 |
+
<tr valign="top">
|
141 |
+
<th scope="row"><?php _e("Empty WP YouTube Lyte's cache","wp-youtube-lyte") ?></th>
|
142 |
+
<td>
|
143 |
+
<fieldset>
|
144 |
+
<legend class="screen-reader-text"><span>Remove WP YouTube Lyte's cache</span></legend>
|
145 |
+
<input type="checkbox" name="lyte_emptycache" value="1" />
|
146 |
+
</fieldset>
|
147 |
+
</td>
|
148 |
+
</tr>
|
149 |
</table>
|
150 |
|
151 |
<p class="submit">
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: futtta
|
|
3 |
Tags: youtube, video, lyte, lite youtube embeds, html5 video, html5, widget, youtube audio, audio, playlist, youtube playlist, hd, performance, accessibility, sidebar, lazy load, responsive, microdata, videoobject
|
4 |
Requires at least: 2.9
|
5 |
Tested up to: 3.6
|
6 |
-
Stable tag: 1.
|
7 |
|
8 |
High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
|
9 |
|
@@ -52,8 +52,8 @@ As opposed to some of the [most important](http://blog.futtta.be/2010/12/15/word
|
|
52 |
If you want to stop YouTube from setting cookies, add the "&showinfo=0" parameter to your httpv-url. This will prevent the call to the Youtube API, which is used to fetch the title of the video, and stop YouTube-cookies from being set when the LYTE-player is loaded. This however does not work for playlists (the API-call is needed to be able to present something meaningful). You should also take into account that any user actually playing the video, will always receive YouTube-cookies ([as is the case with youtube-nocokie embeds as well](http://support.google.com/youtube/bin/answer.py?hl=en&answer=171780&expand=PrivacyEnhancedMode#privacy)).
|
53 |
|
54 |
= Can I use WP YouTube Lyte for a custom field? =
|
55 |
-
|
56 |
-
`if(function_exists('
|
57 |
and you're good to go!
|
58 |
|
59 |
= Does WP YouTube Lyte work with Infinite Scroll? =
|
@@ -74,23 +74,26 @@ This was added as a beta feature in version 1.1.0; add ?enablejsapi=1 to the htt
|
|
74 |
* if the content div width gets to around 200 pixels, the LYTE UI will become garbled (YouTube requires the minimum embed width to be 200px as well).
|
75 |
|
76 |
= Can I use WP YouTube Lyte on normal YouTube links? =
|
77 |
-
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
87 |
|
88 |
= Any bugs/ issues should I know about? =
|
89 |
* 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.
|
90 |
* 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)
|
91 |
* As youtube-nocookie.com does not serve the HTML5-player, WP YouTube Lyte uses the youtube.com domain (which provides less privacy), but as soon as youtube-nocookie.com serves HTML5-video, this will become the default domain for WP YouTube Lyte again.
|
92 |
* 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.
|
93 |
-
* The translations have not been updated entirely for version 1.2.0
|
94 |
|
95 |
= I found a bug/ I would like a feature to be added! =
|
96 |
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).
|
@@ -102,6 +105,16 @@ Just tell me, I like the feedback! Use the [Contact-page on my blog](http://blog
|
|
102 |
|
103 |
== Changelog ==
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
= 1.2.2 =
|
106 |
* bugfix: apply sanitize_text_field to microdata description- and title-fields to escape e.g. quotes
|
107 |
* bugfix: added CSS resets to better avoid CSS-conflicts with themes (as reported by longtime user [FruityOaty](http://fruityoaty.com/))
|
3 |
Tags: youtube, video, lyte, lite youtube embeds, html5 video, html5, widget, youtube audio, audio, playlist, youtube playlist, hd, performance, accessibility, sidebar, lazy load, responsive, microdata, videoobject
|
4 |
Requires at least: 2.9
|
5 |
Tested up to: 3.6
|
6 |
+
Stable tag: 1.3.0
|
7 |
|
8 |
High performance YouTube video, playlist and audio-only embeds which don't slow down your blog and offer optimal accessibility.
|
9 |
|
52 |
If you want to stop YouTube from setting cookies, add the "&showinfo=0" parameter to your httpv-url. This will prevent the call to the Youtube API, which is used to fetch the title of the video, and stop YouTube-cookies from being set when the LYTE-player is loaded. This however does not work for playlists (the API-call is needed to be able to present something meaningful). You should also take into account that any user actually playing the video, will always receive YouTube-cookies ([as is the case with youtube-nocokie embeds as well](http://support.google.com/youtube/bin/answer.py?hl=en&answer=171780&expand=PrivacyEnhancedMode#privacy)).
|
53 |
|
54 |
= Can I use WP YouTube Lyte for a custom field? =
|
55 |
+
Just pass the httpv url of such a field to lyte_preparse like this:
|
56 |
+
`if(function_exists('lyte_preparse')) { echo lyte_preparse($video); }`
|
57 |
and you're good to go!
|
58 |
|
59 |
= Does WP YouTube Lyte work with Infinite Scroll? =
|
74 |
* if the content div width gets to around 200 pixels, the LYTE UI will become garbled (YouTube requires the minimum embed width to be 200px as well).
|
75 |
|
76 |
= Can I use WP YouTube Lyte on normal YouTube links? =
|
77 |
+
Yes, using the API you can make WP YouTube Lyte parse normal YouTube links. The code for this is in lyte_helper.php_example.
|
78 |
|
79 |
+
= What can I do with the API? =
|
80 |
+
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
|
81 |
+
|
82 |
+
= How can I use/ activate lyte_helper.php_example? =
|
83 |
+
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.
|
84 |
+
|
85 |
+
= Problem with All In One Seo Pack =
|
86 |
+
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 lyte_helper.php (see above) and add lyte_filter_aioseop_description to the aioseop-filter in there.
|
87 |
+
|
88 |
+
= When I click on a LYTE video, a link to YouTube opens, what's up with that? =
|
89 |
+
You probably added a link (<a href>)around the httpv-url. No link is needed, just the httpv-url.
|
90 |
|
91 |
= Any bugs/ issues should I know about? =
|
92 |
* 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.
|
93 |
* 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)
|
94 |
* As youtube-nocookie.com does not serve the HTML5-player, WP YouTube Lyte uses the youtube.com domain (which provides less privacy), but as soon as youtube-nocookie.com serves HTML5-video, this will become the default domain for WP YouTube Lyte again.
|
95 |
* 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.
|
96 |
+
* 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)!
|
97 |
|
98 |
= I found a bug/ I would like a feature to be added! =
|
99 |
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).
|
105 |
|
106 |
== Changelog ==
|
107 |
|
108 |
+
= 1.3.0 =
|
109 |
+
* WP YouTube Lyte now has an API to allow its behavior to be changed, with extensive examples in lyte_helper.php_example
|
110 |
+
* Support for higher quality thumbnails by adding #hqThumb=1 to httpv-link
|
111 |
+
* You can disable microdata on a per-video level by adding #noMicrodata=1 to the httpv-link when microdata is enabled.
|
112 |
+
* Checkbox on admin-page to flush WP YouTube Lyte cache (which holds title, description, ... from YouTube)
|
113 |
+
* added a lyte_preparse function to be used by themes/ plugins (input is the YouTube ID)
|
114 |
+
* improvement: added opacity to the play-button when not hovered over
|
115 |
+
* bugfix: suppress error messages if yt_resp does not contain all data
|
116 |
+
* bugfix: solve PHP notice for pS-array in options.php
|
117 |
+
|
118 |
= 1.2.2 =
|
119 |
* bugfix: apply sanitize_text_field to microdata description- and title-fields to escape e.g. quotes
|
120 |
* bugfix: added CSS resets to better avoid CSS-conflicts with themes (as reported by longtime user [FruityOaty](http://fruityoaty.com/))
|
wp-youtube-lyte.php
CHANGED
@@ -4,14 +4,14 @@ 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.
|
8 |
Author URI: http://blog.futtta.be/
|
9 |
Text Domain: wp-youtube-lyte
|
10 |
Domain Path: /languages
|
11 |
*/
|
12 |
|
13 |
$debug=false;
|
14 |
-
$lyte_version="1.
|
15 |
$lyte_db_version=get_option('lyte_version','none');
|
16 |
|
17 |
/** have we updated? */
|
@@ -66,13 +66,19 @@ $lyteSettings['microdata']=get_option('lyte_microdata','1');
|
|
66 |
$lyteSettings['hidef']=get_option('lyte_hidef',0);
|
67 |
$lyteSettings['scheme'] = ( is_ssl() ) ? "https" : "http";
|
68 |
|
69 |
-
|
|
|
|
|
|
|
70 |
function lyte_parse($the_content,$doExcerpt=false) {
|
71 |
global $lyteSettings;
|
72 |
|
73 |
$urlArr=parse_url($lyteSettings['path']);
|
74 |
$origin=$urlArr['scheme']."://".$urlArr['host']."/";
|
75 |
|
|
|
|
|
|
|
76 |
if((strpos($the_content, "httpv")!==FALSE)||(strpos($the_content, "httpa")!==FALSE)) {
|
77 |
$char_codes = array('×','–');
|
78 |
$replacements = array("x", "--");
|
@@ -89,10 +95,29 @@ function lyte_parse($the_content,$doExcerpt=false) {
|
|
89 |
preg_match_all($lytes_regexp, $the_content, $matches, PREG_SET_ORDER);
|
90 |
|
91 |
foreach($matches as $match) {
|
|
|
|
|
|
|
92 |
preg_match("/stepSize\=([\+\-0-9]{2})/",$match[12],$sMatch);
|
93 |
preg_match("/showinfo\=([0-1]{1})/",$match[12],$showinfo);
|
94 |
preg_match("/start\=([0-9]*)/",$match[12],$start);
|
95 |
preg_match("/enablejsapi\=([0-1]{1})/",$match[12],$jsapi);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
$qsa="";
|
98 |
if (!empty($showinfo[0])) {
|
@@ -231,17 +256,17 @@ function lyte_parse($the_content,$doExcerpt=false) {
|
|
231 |
$yt_resp_array=json_decode($yt_resp,true);
|
232 |
if (is_array($yt_resp_array)) {
|
233 |
if ($plClass===" playlist") {
|
234 |
-
$yt_title="Playlist: ".esc_attr(sanitize_text_field(
|
235 |
-
$thumbUrl=esc_url(
|
236 |
-
$dateField=sanitize_text_field(
|
237 |
$duration="";
|
238 |
$description=$yt_title;
|
239 |
} else {
|
240 |
-
$yt_title=esc_attr(sanitize_text_field(
|
241 |
-
$thumbUrl=esc_url($lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/
|
242 |
-
$dateField=sanitize_text_field(
|
243 |
-
$duration="T".sanitize_text_field(
|
244 |
-
$description=esc_attr(sanitize_text_field(
|
245 |
}
|
246 |
}
|
247 |
}
|
@@ -254,15 +279,22 @@ function lyte_parse($the_content,$doExcerpt=false) {
|
|
254 |
|
255 |
if ($doExcerpt) {
|
256 |
$lytetemplate="";
|
|
|
257 |
} elseif ($lyte_feed) {
|
258 |
$postURL = get_permalink( $postID );
|
259 |
$textLink = ($lyteSettings['links']===0)? "" : "<br />".strip_tags($lytelinks_txt, '<a>')."<br />";
|
260 |
$lytetemplate = "<a href=\"".$postURL."\"><img src=\"".$lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg\" alt=\"YouTube Video\"></a>".$textLink;
|
261 |
-
|
262 |
-
|
|
|
|
|
263 |
} else {
|
264 |
$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;
|
|
|
265 |
}
|
|
|
|
|
|
|
266 |
$the_content = preg_replace($lytes_regexp, $lytetemplate, $the_content, 1);
|
267 |
}
|
268 |
|
@@ -277,6 +309,10 @@ function lyte_parse($the_content,$doExcerpt=false) {
|
|
277 |
lyte_initer();
|
278 |
}
|
279 |
}
|
|
|
|
|
|
|
|
|
280 |
return $the_content;
|
281 |
}
|
282 |
|
@@ -292,7 +328,14 @@ function lyte_initer() {
|
|
292 |
/* actual initialization */
|
293 |
function lyte_init() {
|
294 |
global $lyteSettings;
|
295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
echo "<script type=\"text/javascript\" async=true src=\"".$lyteSettings['path'].$lyteSettings['file']."\"></script>";
|
297 |
}
|
298 |
|
@@ -346,19 +389,30 @@ function lyte_options_update() {
|
|
346 |
}
|
347 |
}
|
348 |
|
349 |
-
/** function to
|
350 |
function lyte_rm_cache() {
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
foreach ($
|
355 |
-
|
|
|
|
|
356 |
}
|
|
|
357 |
}
|
358 |
-
|
|
|
|
|
359 |
}
|
360 |
}
|
361 |
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
/** hooking it all up to wordpress */
|
363 |
if ( is_admin() ) {
|
364 |
require_once(dirname(__FILE__).'/options.php');
|
@@ -367,5 +421,8 @@ if ( is_admin() ) {
|
|
367 |
add_shortcode("lyte", "shortcode_lyte");
|
368 |
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
|
369 |
add_filter('get_the_excerpt', 'lyte_trim_excerpt');
|
|
|
|
|
|
|
370 |
}
|
371 |
?>
|
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.0
|
8 |
Author URI: http://blog.futtta.be/
|
9 |
Text Domain: wp-youtube-lyte
|
10 |
Domain Path: /languages
|
11 |
*/
|
12 |
|
13 |
$debug=false;
|
14 |
+
$lyte_version="1.3.0";
|
15 |
$lyte_db_version=get_option('lyte_version','none');
|
16 |
|
17 |
/** have we updated? */
|
66 |
$lyteSettings['hidef']=get_option('lyte_hidef',0);
|
67 |
$lyteSettings['scheme'] = ( is_ssl() ) ? "https" : "http";
|
68 |
|
69 |
+
/** API: filter hook to alter $lyteSettings */
|
70 |
+
$lyteSettings = apply_filters( 'lyte_settings', $lyteSettings );
|
71 |
+
|
72 |
+
/** main function to parse the content, searching and replacing httpv-links */
|
73 |
function lyte_parse($the_content,$doExcerpt=false) {
|
74 |
global $lyteSettings;
|
75 |
|
76 |
$urlArr=parse_url($lyteSettings['path']);
|
77 |
$origin=$urlArr['scheme']."://".$urlArr['host']."/";
|
78 |
|
79 |
+
/** API: filter hook to preparse the_content, e.g. to force normal youtube links to be parsed */
|
80 |
+
$the_content = apply_filters( 'lyte_content_preparse',$the_content );
|
81 |
+
|
82 |
if((strpos($the_content, "httpv")!==FALSE)||(strpos($the_content, "httpa")!==FALSE)) {
|
83 |
$char_codes = array('×','–');
|
84 |
$replacements = array("x", "--");
|
95 |
preg_match_all($lytes_regexp, $the_content, $matches, PREG_SET_ORDER);
|
96 |
|
97 |
foreach($matches as $match) {
|
98 |
+
/** API: filter hook to preparse fragment in a httpv-url, e.g. to force hqThumb=1 or showinfo=0 */
|
99 |
+
$match[12] = apply_filters( 'lyte_match_preparse_fragment',$match[12] );
|
100 |
+
|
101 |
preg_match("/stepSize\=([\+\-0-9]{2})/",$match[12],$sMatch);
|
102 |
preg_match("/showinfo\=([0-1]{1})/",$match[12],$showinfo);
|
103 |
preg_match("/start\=([0-9]*)/",$match[12],$start);
|
104 |
preg_match("/enablejsapi\=([0-1]{1})/",$match[12],$jsapi);
|
105 |
+
preg_match("/hqThumb\=([0-1]{1})/",$match[12],$hqThumb);
|
106 |
+
preg_match("/noMicroData\=([0-1]{1})/",$match[12],$microData);
|
107 |
+
|
108 |
+
$thumb="0.jpg";
|
109 |
+
if (!empty($hqThumb)) {
|
110 |
+
if ($hqThumb[0]==="hqThumb=1") {
|
111 |
+
$thumb="maxresdefault.jpg";
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
$noMicroData="0";
|
116 |
+
if (!empty($microData)) {
|
117 |
+
if ($microData[0]==="noMicroData=1") {
|
118 |
+
$noMicroData="1";
|
119 |
+
}
|
120 |
+
}
|
121 |
|
122 |
$qsa="";
|
123 |
if (!empty($showinfo[0])) {
|
256 |
$yt_resp_array=json_decode($yt_resp,true);
|
257 |
if (is_array($yt_resp_array)) {
|
258 |
if ($plClass===" playlist") {
|
259 |
+
$yt_title="Playlist: ".esc_attr(sanitize_text_field(@$yt_resp_array['feed']['title']['$t']));
|
260 |
+
$thumbUrl=esc_url(@$yt_resp_array['feed']['media$group']['media$thumbnail'][2]['url']);
|
261 |
+
$dateField=sanitize_text_field(@$yt_resp_array['feed']['updated']['$t']);
|
262 |
$duration="";
|
263 |
$description=$yt_title;
|
264 |
} else {
|
265 |
+
$yt_title=esc_attr(sanitize_text_field(@$yt_resp_array['entry']['title']['$t']));
|
266 |
+
$thumbUrl=esc_url($lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/".$thumb);
|
267 |
+
$dateField=sanitize_text_field(@$yt_resp_array['entry']['published']['$t']);
|
268 |
+
$duration="T".sanitize_text_field(@$yt_resp_array['entry']['media$group']['yt$duration']['seconds'])."S";
|
269 |
+
$description=esc_attr(sanitize_text_field(@$yt_resp_array['entry']['media$group']['media$description']['$t']));
|
270 |
}
|
271 |
}
|
272 |
}
|
279 |
|
280 |
if ($doExcerpt) {
|
281 |
$lytetemplate="";
|
282 |
+
$templateType="excerpt";
|
283 |
} elseif ($lyte_feed) {
|
284 |
$postURL = get_permalink( $postID );
|
285 |
$textLink = ($lyteSettings['links']===0)? "" : "<br />".strip_tags($lytelinks_txt, '<a>')."<br />";
|
286 |
$lytetemplate = "<a href=\"".$postURL."\"><img src=\"".$lyteSettings['scheme']."://i.ytimg.com/vi/".$vid."/0.jpg\" alt=\"YouTube Video\"></a>".$textLink;
|
287 |
+
$templateType="feed";
|
288 |
+
} elseif (($audio !== true) && ( $plClass !== " playlist") && (($lyteSettings['microdata'] === "1")&&($noMicroData !== "1" ))) {
|
289 |
+
$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;
|
290 |
+
$templateType="postMicrodata";
|
291 |
} else {
|
292 |
$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;
|
293 |
+
$templateType="post";
|
294 |
}
|
295 |
+
/** API: filter hook to parse template before being applied */
|
296 |
+
$lytetemplate = apply_filters( 'lyte_match_postparse_template',$lytetemplate,$templateType );
|
297 |
+
|
298 |
$the_content = preg_replace($lytes_regexp, $lytetemplate, $the_content, 1);
|
299 |
}
|
300 |
|
309 |
lyte_initer();
|
310 |
}
|
311 |
}
|
312 |
+
|
313 |
+
/** API: filter hook to postparse the_content before returning */
|
314 |
+
$the_content = apply_filters( 'lyte_content_postparse',$the_content );
|
315 |
+
|
316 |
return $the_content;
|
317 |
}
|
318 |
|
328 |
/* actual initialization */
|
329 |
function lyte_init() {
|
330 |
global $lyteSettings;
|
331 |
+
$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}";
|
332 |
+
|
333 |
+
/** API: filter hook to change css */
|
334 |
+
$lyte_css = apply_filters( 'lyte_css', $lyte_css);
|
335 |
+
|
336 |
+
if (!empty($lyte_css)) {
|
337 |
+
echo "<script type=\"text/javascript\">var bU='".$lyteSettings['path']."';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>";
|
338 |
+
}
|
339 |
echo "<script type=\"text/javascript\" async=true src=\"".$lyteSettings['path'].$lyteSettings['file']."\"></script>";
|
340 |
}
|
341 |
|
389 |
}
|
390 |
}
|
391 |
|
392 |
+
/** function to flush YT responses from cache */
|
393 |
function lyte_rm_cache() {
|
394 |
+
try {
|
395 |
+
$lyte_posts=json_decode(get_option('lyte_cache_index'),true);
|
396 |
+
if (is_array($lyte_posts)){
|
397 |
+
foreach ($lyte_posts as $postID => $lyte_post) {
|
398 |
+
foreach ($lyte_post as $cachekey) {
|
399 |
+
delete_post_meta($postID, $cachekey);
|
400 |
+
}
|
401 |
}
|
402 |
+
delete_option('lyte_cache_index');
|
403 |
}
|
404 |
+
return "OK";
|
405 |
+
} catch(Exception $e) {
|
406 |
+
return $e->getMessage();
|
407 |
}
|
408 |
}
|
409 |
|
410 |
+
/** function to call from within themes */
|
411 |
+
/* use with e.g. : <?php if(function_exists('lyte_preparse')) { echo lyte_preparse($videoId); } ?> */
|
412 |
+
function lyte_preparse($videoId) {
|
413 |
+
return lyte_parse('httpv://www.youtube.com/watch?v='.$videoId);
|
414 |
+
}
|
415 |
+
|
416 |
/** hooking it all up to wordpress */
|
417 |
if ( is_admin() ) {
|
418 |
require_once(dirname(__FILE__).'/options.php');
|
421 |
add_shortcode("lyte", "shortcode_lyte");
|
422 |
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
|
423 |
add_filter('get_the_excerpt', 'lyte_trim_excerpt');
|
424 |
+
|
425 |
+
/** API: action hook to allow extra actions or filters to be added */
|
426 |
+
do_action("lyte_actionsfilters");
|
427 |
}
|
428 |
?>
|