Version Description
- Fix: undefined vars notices
- Fix: embedding default plugin playlist instead custom set for "Embed standard playlist"
- Add: caching system
- Add: option to link to channel instead to user
- Add: support for enhanced privacy by YouTube
- Enhance: RSS feed replaced with JSON
- Enhance: better formatted debug info with site URL
- Enhance: re-group widget options
- Enhance: updated wording
- Enhance: added tooltips for options
- Enhance: playlist ID detection from URL
- Remove: modified error_reporting
Download this release
Release Info
Developer | urkekg |
Plugin | YouTube Channel |
Version | 2.0.0 |
Comparing to | |
See all releases |
Code changes from version 1.5.1 to 2.0.0
- readme.txt +47 -21
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- youtube-channel.php +372 -215
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
Contributors: urkekg
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Q6Q762MQ97XJ6
|
4 |
Tags: youtube, channel, playlist, single, widget, widgets, youtube player, flash player, rss, feed, video, thumbnail, embed, sidebar, chromeless, iframe, html5
|
5 |
-
Requires at least: 3.
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag:
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -22,10 +22,13 @@ If you like this extension and you find it useful, please rate it on the right s
|
|
22 |
* Display latest video from YouTube channel or playlist
|
23 |
* Option to get random video from channel or playlist
|
24 |
* Set custom widget title
|
|
|
25 |
* Custom set of width and height of video thumbnail/embeded object (default 220x165 px)
|
26 |
* Preferred aspect ratio relative to width (custom, 4:3, 16:10 and 16:9)
|
27 |
* Choose to display video thumbnail, iframe (HTML5 video), object embed (Flash video) or chromeless video
|
28 |
* Fix height for old and new YouTube embed and Chromeless video object taken by controls
|
|
|
|
|
29 |
* Option to enable autoplay video
|
30 |
* Option to hide video controls
|
31 |
* Option to hide video info
|
@@ -37,7 +40,6 @@ If you like this extension and you find it useful, please rate it on the right s
|
|
37 |
* Option to show link to channel
|
38 |
* Option to open channel in new tab/window
|
39 |
* Option to use target="_blank" instead of javascript window.open() for chanel link in new tab/window
|
40 |
-
* Translated to Serbian and Spanish (English by default)
|
41 |
|
42 |
= Styling =
|
43 |
You can use `style.css` from theme to style `YouTube Video` widget content.
|
@@ -76,39 +78,56 @@ If you have to upgrade manually simply repeat the installation steps and re-enab
|
|
76 |
|
77 |
* Add option to open video for thumbnail image in lightbox
|
78 |
* Improve autoplay option to start playing only first video item
|
79 |
-
* Add option to show favorite videos
|
80 |
|
81 |
== Frequently Asked Questions ==
|
82 |
|
83 |
-
=
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
= I set more thano one items to fetch, but only one video is displayed. How to fix this? =
|
88 |
-
|
89 |
-
Currently YTC can display only one video per time. Option `Items to fetch` us used for calculating what random video from channel or playlist to get as limit of videos of which random is calculated.
|
90 |
|
91 |
= How to get playlist ID? =
|
92 |
|
93 |
Playlist ID can be manualy extracted from YouTube playlist URL. Part of strings after `&list=` that begins with uppercase letters `PL` represent playlist ID. You can paste ID with or without leading `PL` string.
|
94 |
|
95 |
-
Since version 1.3.1 you can paste full YouTube playlist URL and ID will be automaticaly extracted.
|
96 |
|
97 |
= How to force embeding 320p video with better audio quality? =
|
98 |
|
99 |
-
YouTube provide 320p videos if height of embeded video is set to 320 or more. If you use small YTC video size, 240p will be loaded instead.
|
100 |
|
101 |
-
=
|
102 |
|
103 |
-
|
104 |
-
|
105 |
|
106 |
-
=
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
-
|
109 |
-
|
|
|
110 |
|
111 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
= 1.5.1 =
|
113 |
* Fix issue in widget settings when no apache_get_version() support on server
|
114 |
* Fix validation errors for widget settings
|
@@ -204,7 +223,14 @@ After upgrade please reconfigure widget. Some variables are changed and implemen
|
|
204 |
= 0.1.0 =
|
205 |
Just try it and rate it. Only initial release is available right now.
|
206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
== Screenshots ==
|
208 |
|
209 |
-
1.
|
210 |
-
2.
|
2 |
Contributors: urkekg
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Q6Q762MQ97XJ6
|
4 |
Tags: youtube, channel, playlist, single, widget, widgets, youtube player, flash player, rss, feed, video, thumbnail, embed, sidebar, chromeless, iframe, html5
|
5 |
+
Requires at least: 3.7.0
|
6 |
+
Tested up to: 3.8.1
|
7 |
+
Stable tag: 2.0.0
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
22 |
* Display latest video from YouTube channel or playlist
|
23 |
* Option to get random video from channel or playlist
|
24 |
* Set custom widget title
|
25 |
+
* Enhanced Privacy
|
26 |
* Custom set of width and height of video thumbnail/embeded object (default 220x165 px)
|
27 |
* Preferred aspect ratio relative to width (custom, 4:3, 16:10 and 16:9)
|
28 |
* Choose to display video thumbnail, iframe (HTML5 video), object embed (Flash video) or chromeless video
|
29 |
* Fix height for old and new YouTube embed and Chromeless video object taken by controls
|
30 |
+
* Custom caching timeout
|
31 |
+
* Optimized gdata feeds
|
32 |
* Option to enable autoplay video
|
33 |
* Option to hide video controls
|
34 |
* Option to hide video info
|
40 |
* Option to show link to channel
|
41 |
* Option to open channel in new tab/window
|
42 |
* Option to use target="_blank" instead of javascript window.open() for chanel link in new tab/window
|
|
|
43 |
|
44 |
= Styling =
|
45 |
You can use `style.css` from theme to style `YouTube Video` widget content.
|
78 |
|
79 |
* Add option to open video for thumbnail image in lightbox
|
80 |
* Improve autoplay option to start playing only first video item
|
|
|
81 |
|
82 |
== Frequently Asked Questions ==
|
83 |
|
84 |
+
= I set more than one items to fetch, but only one video is displayed. How to fix this? =
|
85 |
|
86 |
+
Below option `Fetch ... video(s)` you can find `Show ... video(s)` since version 2.0.0. Here you can set number of videos to display.
|
|
|
|
|
|
|
|
|
87 |
|
88 |
= How to get playlist ID? =
|
89 |
|
90 |
Playlist ID can be manualy extracted from YouTube playlist URL. Part of strings after `&list=` that begins with uppercase letters `PL` represent playlist ID. You can paste ID with or without leading `PL` string.
|
91 |
|
92 |
+
Since version 1.3.1 you can also paste full YouTube playlist URL and ID will be automaticaly extracted.
|
93 |
|
94 |
= How to force embeding 320p video with better audio quality? =
|
95 |
|
96 |
+
YouTube provide 320p videos if height of embeded video is set to 320 or more. If you use small YTC video size, 240p will be loaded instead. So, you could not force 720p in tiny YTC.
|
97 |
|
98 |
+
= What is a difference between `Fetch latest` and `Show ... videos`? =
|
99 |
|
100 |
+
Value for `Fetch latest` says how many items will containt videos feed for choosing random video.
|
101 |
+
Value for `Show ... videos` says how many videos will be displayed in widget.
|
102 |
|
103 |
+
= In wich way does the plugin order the videos? Not by the time they were uploaded... =
|
104 |
+
|
105 |
+
By default, YTC sort videos by publishing date/time, not by uploaded date/time.
|
106 |
+
|
107 |
+
If you have enabled option `Fix No items error/Respect playlist order`, then videos are not sorted by publishing date, but by YouTube default order.
|
108 |
+
|
109 |
+
= When I upload a new video at youtube, it is not in the list at my site =
|
110 |
|
111 |
+
Video feed for YTC has been retreived with standard youtube feed [uploads by specified user](https://developers.google.com/youtube/2.0/developers_guide_protocol?hl=en#User_Uploaded_Videos "User Uploaded Videos"), and as Google say: [uploaded videos will be included in a user's public uploaded videos feed a few minutes after the upload completes and YouTube finishes processing the video](https://developers.google.com/youtube/2.0/reference#Latency_Information).
|
112 |
+
|
113 |
+
If you does not see your latest video in your uplaods feed (which you can access at https://gdata.youtube.com/feeds/api/users/YOUR_YT_USERID/uploads by replacing YOUR_YT_USERID with your real youtube user ID), then YTC will not see it too.
|
114 |
|
115 |
== Changelog ==
|
116 |
+
|
117 |
+
= 2.0.0 =
|
118 |
+
* Fix: undefined vars notices
|
119 |
+
* Fix: embedding default plugin playlist instead custom set for "Embed standard playlist"
|
120 |
+
* Add: caching system
|
121 |
+
* Add: option to link to channel instead to user
|
122 |
+
* Add: support for enhanced privacy by YouTube
|
123 |
+
* Enhance: RSS feed replaced with JSON
|
124 |
+
* Enhance: better formatted debug info with site URL
|
125 |
+
* Enhance: re-group widget options
|
126 |
+
* Enhance: updated wording
|
127 |
+
* Enhance: added tooltips for options
|
128 |
+
* Enhance: playlist ID detection from URL
|
129 |
+
* Remove: modified error_reporting
|
130 |
+
|
131 |
= 1.5.1 =
|
132 |
* Fix issue in widget settings when no apache_get_version() support on server
|
133 |
* Fix validation errors for widget settings
|
223 |
= 0.1.0 =
|
224 |
Just try it and rate it. Only initial release is available right now.
|
225 |
|
226 |
+
== Upgrade Notice ==
|
227 |
+
|
228 |
+
= 2.0.0 =
|
229 |
+
|
230 |
+
This version introduces caching, optimized feeds, JSON, and better user experience.
|
231 |
+
We highly recommend to you made database backup before you upgrade to latest version 2.0.0.
|
232 |
+
|
233 |
== Screenshots ==
|
234 |
|
235 |
+
1. YouTube Channel widget settings
|
236 |
+
2. YouTube Channel widget settings customized
|
screenshot-1.png
DELETED
Binary file
|
screenshot-2.png
DELETED
Binary file
|
youtube-channel.php
CHANGED
@@ -1,155 +1,243 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: YouTube Channel
|
4 |
-
Plugin URI: http://
|
5 |
Description: <a href="widgets.php">Widget</a> that display latest video thumbnail, iframe (HTML5 video), object (Flash video) or chromeless video from YouTube Channel or Playlist.
|
6 |
Author: Aleksandar Urošević
|
7 |
-
Version:
|
8 |
Author URI: http://urosevic.net/
|
9 |
*/
|
10 |
-
|
11 |
-
define( 'YTCVER', '1.5.1' );
|
12 |
define( 'YOUTUBE_CHANNEL_URL', plugin_dir_url(__FILE__) );
|
13 |
define( 'YTCPLID', 'PLEC850BE962234400' );
|
14 |
define( 'YTCUID', 'urkekg' );
|
|
|
15 |
|
16 |
/* Load plugin's textdomain */
|
17 |
add_action( 'init', 'youtube_channel_init' );
|
18 |
function youtube_channel_init() {
|
19 |
-
load_plugin_textdomain(
|
20 |
}
|
21 |
|
22 |
/* youtube widget */
|
23 |
class YouTube_Channel_Widget extends WP_Widget {
|
24 |
-
|
25 |
-
|
26 |
-
parent::
|
|
|
|
|
|
|
|
|
27 |
}
|
28 |
|
29 |
-
function form($instance) {
|
30 |
// outputs the options form on admin
|
31 |
-
$title = esc_attr($instance['title']);
|
32 |
-
$channel = esc_attr($instance['channel']);
|
33 |
-
$vidqty = esc_attr($instance['vidqty']);
|
34 |
-
$playlist = esc_attr($instance['playlist']);
|
35 |
-
$
|
36 |
-
$only_pl = esc_attr($instance['only_pl']);
|
37 |
-
$
|
38 |
-
$
|
39 |
-
$
|
40 |
-
|
41 |
-
$
|
42 |
-
$
|
43 |
-
$
|
44 |
-
|
45 |
-
$
|
46 |
-
$
|
47 |
-
$
|
48 |
-
$
|
49 |
-
$
|
50 |
-
|
51 |
-
$
|
52 |
-
$
|
53 |
-
$
|
54 |
-
$
|
55 |
-
$
|
56 |
-
$
|
57 |
-
$
|
58 |
-
$
|
59 |
-
$
|
|
|
|
|
|
|
60 |
?>
|
61 |
-
<p
|
62 |
-
|
63 |
-
|
64 |
-
<p
|
65 |
-
|
66 |
-
|
67 |
-
<
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
<h4><?php _e('Video
|
72 |
-
<p
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
75 |
<select class="widefat" id="<?php echo $this->get_field_id( 'ratio' ); ?>" name="<?php echo $this->get_field_name( 'ratio' ); ?>">
|
76 |
-
<option value="0"<?php selected( $
|
77 |
-
<option value="1"<?php selected( $
|
78 |
-
<option value="2"<?php selected( $
|
79 |
-
<option value="3"<?php selected( $
|
80 |
</select>
|
81 |
</p>
|
82 |
-
<p
|
|
|
83 |
<select class="widefat" id="<?php echo $this->get_field_id( 'to_show' ); ?>" name="<?php echo $this->get_field_name( 'to_show' ); ?>">
|
84 |
-
<option value="thumbnail"<?php selected( $
|
85 |
-
<option value="object"<?php selected( $
|
86 |
-
<option value="iframe"<?php selected( $
|
87 |
-
<option value="chromeless"<?php selected( $
|
88 |
</select>
|
89 |
-
<input class="checkbox" type="checkbox" <?php checked( (bool) $
|
90 |
-
<input class="checkbox" type="checkbox" <?php checked( (bool) $
|
91 |
-
<input class="checkbox" type="checkbox" <?php checked( (bool) $
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
<h4><?php _e('Layout
|
96 |
-
<p>
|
97 |
-
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['showtitle'], true ); ?> id="<?php echo $this->get_field_id( 'showtitle' ); ?>" name="<?php echo $this->get_field_name( 'showtitle' ); ?>" /> <label for="<?php echo $this->get_field_id( 'showtitle' ); ?>"><?php _e('Show video title', 'youtube-channel'); ?></label><br />
|
98 |
-
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['showvidesc'], true ); ?> id="<?php echo $this->get_field_id( 'showvidesc' ); ?>" name="<?php echo $this->get_field_name( 'showvidesc' ); ?>" /> <label for="<?php echo $this->get_field_id( 'showvidesc' ); ?>"><?php _e('Show video description', 'youtube-channel'); ?></label><br />
|
99 |
-
<label for="<?php echo $this->get_field_id('videsclen'); ?>"><?php _e('Description length', 'youtube-channel'); ?>: <input class="small-text" id="<?php echo $this->get_field_id('videsclen'); ?>" name="<?php echo $this->get_field_name('videsclen'); ?>" type="number" value="<?php echo $videsclen; ?>" /> (0 = full)</label><br />
|
100 |
-
<label for="<?php echo $this->get_field_id('descappend'); ?>"><?php _e('Et cetera string', 'youtube-channel'); ?> <input class="small-text" id="<?php echo $this->get_field_id('descappend'); ?>" name="<?php echo $this->get_field_name('descappend'); ?>" type="text" value="<?php echo $descappend; ?>" /> default &hellip;</label><br />
|
101 |
-
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['hideanno'], true ); ?> id="<?php echo $this->get_field_id( 'hideanno' ); ?>" name="<?php echo $this->get_field_name( 'hideanno' ); ?>" /> <label for="<?php echo $this->get_field_id( 'hideanno' ); ?>"><?php _e('Hide annotations from video', 'youtube-channel'); ?></label><br />
|
102 |
-
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['hideinfo'], true ); ?> id="<?php echo $this->get_field_id( 'hideinfo' ); ?>" name="<?php echo $this->get_field_name( 'hideinfo' ); ?>" /> <label for="<?php echo $this->get_field_id( 'hideinfo' ); ?>"><?php _e('Hide video info', 'youtube-channel'); ?></label>
|
103 |
-
</p>
|
104 |
-
<h4><?php _e('Link to channel', 'youtube-channel'); ?></h4>
|
105 |
<p>
|
106 |
-
<
|
107 |
-
<input class="checkbox" type="checkbox" <?php checked( (bool) $
|
108 |
-
<
|
109 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
</p>
|
111 |
|
112 |
-
<h4><?php _e('Debug YTC',
|
113 |
<p>
|
114 |
-
<input class="checkbox" type="checkbox" <?php checked( (bool) $
|
115 |
|
116 |
<?php
|
117 |
-
if ( $
|
118 |
$debug_arr = array_merge(
|
119 |
array(
|
120 |
'server' => $_SERVER["SERVER_SOFTWARE"],
|
121 |
-
'php'
|
122 |
-
'wp'
|
123 |
-
'ytc'
|
|
|
124 |
),
|
125 |
$instance);
|
126 |
?>
|
127 |
|
128 |
-
<textarea name="debug" class="widefat" style="height: 100px;"><?php
|
129 |
Insert debug data to <a href="http://wordpress.org/support/plugin/youtube-channel" target="_support">support forum</a>.
|
130 |
<?php } ?>
|
131 |
</p>
|
132 |
|
133 |
-
<p
|
|
|
|
|
134 |
|
135 |
<?php
|
136 |
}
|
137 |
|
138 |
-
function update($new_instance, $old_instance) {
|
139 |
// processes widget options to be saved
|
140 |
$instance = $old_instance;
|
141 |
$instance['title'] = strip_tags($new_instance['title']);
|
142 |
$instance['channel'] = strip_tags($new_instance['channel']);
|
143 |
$instance['vidqty'] = $new_instance['vidqty'];
|
144 |
$instance['playlist'] = strip_tags($new_instance['playlist']);
|
145 |
-
$instance['
|
|
|
146 |
$instance['only_pl'] = $new_instance['only_pl'];
|
147 |
$instance['getrnd'] = $new_instance['getrnd'];
|
148 |
$instance['maxrnd'] = $new_instance['maxrnd'];
|
|
|
149 |
$instance['goto_txt'] = strip_tags($new_instance['goto_txt']);
|
150 |
$instance['showgoto'] = $new_instance['showgoto'];
|
151 |
-
$instance['
|
152 |
-
|
153 |
$instance['showtitle'] = $new_instance['showtitle'];
|
154 |
$instance['showvidesc'] = $new_instance['showvidesc'];
|
155 |
$instance['descappend'] = strip_tags($new_instance['descappend']);
|
@@ -158,7 +246,6 @@ if ( $instance['debugon'] == 'on' ) {
|
|
158 |
$instance['height'] = strip_tags($new_instance['height']);
|
159 |
$instance['to_show'] = strip_tags($new_instance['to_show']);
|
160 |
$instance['autoplay'] = $new_instance['autoplay'];
|
161 |
-
//$instance['lightbox'] = $new_instance['lightbox'];
|
162 |
$instance['controls'] = $new_instance['controls'];
|
163 |
$instance['fixnoitem'] = $new_instance['fixnoitem'];
|
164 |
$instance['ratio'] = strip_tags($new_instance['ratio']);
|
@@ -167,37 +254,37 @@ if ( $instance['debugon'] == 'on' ) {
|
|
167 |
$instance['hideanno'] = $new_instance['hideanno'];
|
168 |
$instance['themelight'] = $new_instance['themelight'];
|
169 |
$instance['debugon'] = $new_instance['debugon'];
|
|
|
|
|
170 |
|
171 |
return $instance;
|
172 |
}
|
173 |
|
174 |
-
function widget($args, $instance) {
|
175 |
// outputs the content of the widget
|
176 |
extract( $args );
|
|
|
177 |
$title = apply_filters('widget_title', $instance['title']);
|
178 |
|
179 |
// set default channel if nothing predefined
|
180 |
$channel = $instance['channel'];
|
181 |
-
if ( $channel == "" )
|
182 |
-
$channel = YTCUID;
|
183 |
|
184 |
// set playlist id
|
185 |
$playlist = $instance['playlist'];
|
186 |
-
if ( $playlist == "" )
|
187 |
-
$playlist = YTCPLID;
|
188 |
|
189 |
// trim PL in front of playlist ID
|
190 |
$playlist = preg_replace('/^PL/', '', $playlist);
|
191 |
-
$
|
192 |
|
193 |
$output = array();
|
194 |
$output[] = $before_widget;
|
195 |
-
if ( $title )
|
196 |
-
$output[] = $before_title . $title . $after_title;
|
197 |
|
198 |
$output[] = '<div class="youtube_channel">';
|
199 |
|
200 |
-
if ( $instance['only_pl'] ) { // print standard playlist
|
201 |
$output = array_merge($output, ytc_only_pl($instance));
|
202 |
} else { // channel or playlist single videos
|
203 |
|
@@ -206,47 +293,77 @@ if ( $instance['debugon'] == 'on' ) {
|
|
206 |
if ( $maxrnd < 1 ) { $maxrnd = 10; } // default 10
|
207 |
elseif ( $maxrnd > 50 ) { $maxrnd = 50; } // max 50
|
208 |
|
209 |
-
$
|
210 |
-
|
211 |
-
|
|
|
|
|
|
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
} else {
|
222 |
-
|
|
|
223 |
}
|
224 |
|
225 |
-
//
|
226 |
-
|
227 |
|
228 |
-
|
|
|
|
|
229 |
|
230 |
-
|
231 |
-
|
|
|
|
|
232 |
$vidqty = $instance['vidqty'];
|
233 |
if ( $vidqty > $maxrnd ) { $maxrnd = $vidqty; }
|
234 |
-
$maxitems = $
|
235 |
|
236 |
if ( $getrnd ) {
|
237 |
-
$items =
|
238 |
} else {
|
239 |
-
if ( !$vidqty )
|
240 |
-
|
241 |
-
$items = $rss->get_items(0, $vidqty); // set 0, 2 for next video
|
242 |
}
|
243 |
}
|
244 |
-
|
245 |
if ($maxitems == 0) {
|
246 |
-
$output[] = __( 'No items' ,
|
247 |
} else {
|
248 |
-
|
249 |
-
|
250 |
|
251 |
for ($y = 1; $y <= $vidqty; $y++) {
|
252 |
if ( $getrnd ) {
|
@@ -258,12 +375,12 @@ if ( $instance['debugon'] == 'on' ) {
|
|
258 |
$item = $items[$rnd_item];
|
259 |
} else {
|
260 |
$item = $items[$y-1];
|
261 |
-
//$next_item = $items[1];
|
262 |
}
|
263 |
|
264 |
// print single video block
|
265 |
$output = array_merge( $output, ytc_print_video($item, $instance, $y) );
|
266 |
}
|
|
|
267 |
}
|
268 |
} // single playlist or ytc way
|
269 |
|
@@ -284,26 +401,30 @@ function ytc_only_pl($instance) {
|
|
284 |
if ( empty($width) )
|
285 |
$width = 220;
|
286 |
|
287 |
-
$instance['playlist'];
|
288 |
if ( empty($playlist) )
|
289 |
$playlist = YTCPLID;
|
290 |
-
|
291 |
-
$height = height_ratio($width, $instance['ratio'])
|
|
|
|
|
|
|
292 |
$playlist = ytc_clean_playlist_id($playlist);
|
293 |
-
|
294 |
$autoplay = $instance['autoplay'];
|
295 |
if ( $autoplay )
|
296 |
$autoplay = '&autoplay=1';
|
|
|
|
|
|
|
297 |
$output[] = '<div class="ytc_video_container ytc_video_1 ytc_video_single">
|
298 |
-
<iframe src="http://
|
299 |
width="'.$width.'" height="'.$height.'" frameborder="0"></iframe></div>';
|
300 |
return $output;
|
301 |
}
|
302 |
|
303 |
/* function to print video in widget */
|
304 |
function ytc_print_video($item, $instance, $y) {
|
305 |
-
/* video settings */
|
306 |
-
//$output = '';
|
307 |
|
308 |
// get hideinfo, autoplay and controls settings
|
309 |
// where this is used?
|
@@ -315,7 +436,7 @@ function ytc_print_video($item, $instance, $y) {
|
|
315 |
$width = $instance['width'];
|
316 |
if ( empty($width) )
|
317 |
$width = 220;
|
318 |
-
$height = height_ratio($width, $instance['ratio']);
|
319 |
|
320 |
// calculate image height based on width for 4:3 thumbnail
|
321 |
$imgfixedheight = $width / 4 * 3;
|
@@ -333,28 +454,16 @@ function ytc_print_video($item, $instance, $y) {
|
|
333 |
$themelight = $instance['themelight'];
|
334 |
/* end of video settings */
|
335 |
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
$yt_id = explode(":", $item->get_id());
|
347 |
-
$yt_id = $yt_id[3];
|
348 |
-
$yt_url = "v/$yt_id";
|
349 |
-
}
|
350 |
-
|
351 |
-
$yt_thumb = "http://img.youtube.com/vi/$yt_id/0.jpg"; // zero for HD thumb
|
352 |
-
$yt_video = $item->get_permalink();
|
353 |
-
$yt_title = esc_html( $item->get_title() );
|
354 |
-
$yt_date = $item->get_date('j F Y | g:i a');
|
355 |
-
// $next_id = explode(":", $next_item->get_id());
|
356 |
-
// $next_id = $yt_id[3];
|
357 |
-
|
358 |
switch ($y) {
|
359 |
case 1:
|
360 |
$vnumclass = 'first';
|
@@ -378,12 +487,13 @@ function ytc_print_video($item, $instance, $y) {
|
|
378 |
// define object ID
|
379 |
$ytc_vid = 'ytc_' . $yt_id;
|
380 |
|
|
|
|
|
|
|
381 |
// print out video
|
382 |
if ( $to_show == "thumbnail" ) {
|
383 |
-
$title = sprintf( __( 'Watch video %1$s published on %2$s' ,
|
384 |
-
|
385 |
-
$output[] = '<a href="'.$yt_video.'" title="'.$title.'"><span style="width: '.$width.'px; height: '.$height.'px; overflow: hidden; display: block; background: url('.$yt_thumb.') 50% 50% no-repeat; background-size: '.$width.'px '.$imgfixedheight.'px;" title="'.$yt_title.'" id="'.$ytc_vid.'"></span></a>';
|
386 |
-
|
387 |
} else if ( $to_show == "chromeless" ) {
|
388 |
ob_start();
|
389 |
?>
|
@@ -398,36 +508,34 @@ function ytc_print_video($item, $instance, $y) {
|
|
398 |
$output[] = ob_get_contents();
|
399 |
ob_end_clean();
|
400 |
} else if ( $to_show == "iframe" ) {
|
401 |
-
if (
|
402 |
-
|
403 |
-
|
404 |
-
$output[] =
|
405 |
-
if ( $
|
406 |
-
|
407 |
-
if ( $
|
408 |
-
|
409 |
-
if ( $autoplay )
|
410 |
-
$output[] = "&autoplay=1";
|
411 |
-
if ( $hideanno )
|
412 |
-
$output[] = "&iv_load_policy=3";
|
413 |
-
if ( $themelight )
|
414 |
-
$output[] = "&theme=light";
|
415 |
|
416 |
-
$output[] = '"
|
417 |
} else { // default is object
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
ob_start();
|
419 |
?>
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
<!--<![endif]-->
|
430 |
-
</object>
|
431 |
<?php
|
432 |
$output[] = ob_get_contents();
|
433 |
ob_end_clean();
|
@@ -435,21 +543,36 @@ function ytc_print_video($item, $instance, $y) {
|
|
435 |
|
436 |
// do we need to show video description?
|
437 |
if ( $instance['showvidesc'] ) {
|
438 |
-
|
439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
if ( $instance['videsclen'] > 0 ) {
|
441 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
} else {
|
443 |
$video_description = $videsc[1];
|
|
|
444 |
}
|
445 |
-
if (
|
446 |
-
if ( $instance['descappend'] ) {
|
447 |
-
$etcetera = $instance['descappend'];
|
448 |
-
} else {
|
449 |
-
$etcetera = '…';
|
450 |
-
}
|
451 |
$output[] = '<p class="ytc_description">' .$video_description.$etcetera. '</p>';
|
452 |
-
}
|
453 |
}
|
454 |
$output[] = '</div><!-- .ytc_video_container -->';
|
455 |
|
@@ -457,7 +580,7 @@ function ytc_print_video($item, $instance, $y) {
|
|
457 |
}
|
458 |
|
459 |
// function to calculate height by width and ratio
|
460 |
-
function height_ratio($width, $ratio) {
|
461 |
if ( $width == "" )
|
462 |
$width = 220;
|
463 |
|
@@ -468,8 +591,8 @@ function height_ratio($width, $ratio) {
|
|
468 |
} elseif ( $ratio == 3 ) { // 16:9
|
469 |
$height = round(($width / 16 ) * 9);
|
470 |
} else { // set default if 0 or ratio not set
|
471 |
-
$height = $instance['height'];
|
472 |
-
if ( $height == "" )
|
473 |
$height = 165;
|
474 |
}
|
475 |
return $height;
|
@@ -486,19 +609,26 @@ function ytc_channel_link($instance) {
|
|
486 |
$channel = 'urkekg';
|
487 |
$goto_txt = $instance['goto_txt'];
|
488 |
if ( $goto_txt == "" )
|
489 |
-
$goto_txt = sprintf( __( 'Visit channel %1$s' ,
|
|
|
|
|
490 |
|
491 |
$output[] = '<div class="ytc_link">';
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
|
|
|
|
|
|
|
|
|
|
502 |
$output[] = '</div>';
|
503 |
|
504 |
} // showgoto
|
@@ -509,7 +639,7 @@ function ytc_channel_link($instance) {
|
|
509 |
function ytc_clean_playlist_id($playlist) {
|
510 |
if ( substr($playlist,0,4) == "http" ) {
|
511 |
// if URL provided, extract playlist ID
|
512 |
-
$playlist = preg_replace('/.*list=PL([A-
|
513 |
} else if ( substr($playlist,0,2) == 'PL' ) {
|
514 |
$playlist = substr($playlist,2);
|
515 |
}
|
@@ -521,4 +651,31 @@ function youtube_channel_register_widget() {
|
|
521 |
register_widget( 'YouTube_Channel_Widget' );
|
522 |
}
|
523 |
add_action( 'widgets_init', 'youtube_channel_register_widget' );
|
524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: YouTube Channel
|
4 |
+
Plugin URI: http://urosevic.net/wordpress/plugins/youtube-channel/
|
5 |
Description: <a href="widgets.php">Widget</a> that display latest video thumbnail, iframe (HTML5 video), object (Flash video) or chromeless video from YouTube Channel or Playlist.
|
6 |
Author: Aleksandar Urošević
|
7 |
+
Version: 2.0.0
|
8 |
Author URI: http://urosevic.net/
|
9 |
*/
|
10 |
+
define( 'YTCVER', '2.0.0' );
|
|
|
11 |
define( 'YOUTUBE_CHANNEL_URL', plugin_dir_url(__FILE__) );
|
12 |
define( 'YTCPLID', 'PLEC850BE962234400' );
|
13 |
define( 'YTCUID', 'urkekg' );
|
14 |
+
define( 'YTCTDOM', 'youtube-channel' );
|
15 |
|
16 |
/* Load plugin's textdomain */
|
17 |
add_action( 'init', 'youtube_channel_init' );
|
18 |
function youtube_channel_init() {
|
19 |
+
load_plugin_textdomain( YTCTDOM, false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
20 |
}
|
21 |
|
22 |
/* youtube widget */
|
23 |
class YouTube_Channel_Widget extends WP_Widget {
|
24 |
+
|
25 |
+
public function __construct() {
|
26 |
+
parent::__construct(
|
27 |
+
YTCTDOM,
|
28 |
+
__( 'Youtube Channel' , YTCTDOM ),
|
29 |
+
array( 'description' => __( 'Serve YouTube videos from channel or playlist right to widget area', YTCTDOM ) )
|
30 |
+
);
|
31 |
}
|
32 |
|
33 |
+
public function form($instance) {
|
34 |
// outputs the options form on admin
|
35 |
+
$title = (!empty($instance['title'])) ? esc_attr($instance['title']) : '';
|
36 |
+
$channel = (!empty($instance['channel'])) ? esc_attr($instance['channel']) : '';
|
37 |
+
$vidqty = (!empty($instance['vidqty'])) ? esc_attr($instance['vidqty']) : 1; // number of items to show
|
38 |
+
$playlist = (!empty($instance['playlist'])) ? esc_attr($instance['playlist']) : '';
|
39 |
+
$use_res = (!empty($instance['use_res'])) ? esc_attr($instance['use_res']) : 0; // resource to use: channel, favorites, playlis : ''t
|
40 |
+
$only_pl = (!empty($instance['only_pl'])) ? esc_attr($instance['only_pl']) : '';
|
41 |
+
$cache_time = (!empty($instance['cache_time'])) ? esc_attr($instance['cache_time']) : '';
|
42 |
+
$getrnd = (!empty($instance['getrnd'])) ? esc_attr($instance['getrnd']) : '';
|
43 |
+
$maxrnd = (!empty($instance['maxrnd'])) ? esc_attr($instance['maxrnd']) : 25; // items to fetch
|
44 |
+
|
45 |
+
$goto_txt = (!empty($instance['goto_txt'])) ? esc_attr($instance['goto_txt']) : '';
|
46 |
+
$showgoto = (!empty($instance['showgoto'])) ? esc_attr($instance['showgoto']) : '';
|
47 |
+
$popup_goto = (!empty($instance['popup_goto'])) ? esc_attr($instance['popup_goto']) : '';
|
48 |
+
|
49 |
+
$showtitle = (!empty($instance['showtitle'])) ? esc_attr($instance['showtitle']) : '';
|
50 |
+
$showvidesc = (!empty($instance['showvidesc'])) ? esc_attr($instance['showvidesc']) : '';
|
51 |
+
$videsclen = (!empty($instance['videsclen'])) ? esc_attr($instance['videsclen']) : 0;
|
52 |
+
$descappend = (!empty($instance['descappend'])) ? esc_attr($instance['descappend']) : '…';
|
53 |
+
$width = (!empty($instance['width'])) ? esc_attr($instance['width']) : 220;
|
54 |
+
$height = (!empty($instance['height'])) ? esc_attr($instance['height']) : '';
|
55 |
+
$to_show = (!empty($instance['to_show'])) ? esc_attr($instance['to_show']) : '';
|
56 |
+
$autoplay = (!empty($instance['autoplay'])) ? esc_attr($instance['autoplay']) : '';
|
57 |
+
$controls = (!empty($instance['controls'])) ? esc_attr($instance['controls']) : '';
|
58 |
+
$fixnoitem = (!empty($instance['fixnoitem'])) ? esc_attr($instance['fixnoitem']) : '';
|
59 |
+
$ratio = (!empty($instance['ratio'])) ? esc_attr($instance['ratio']) : '';
|
60 |
+
$fixyt = (!empty($instance['fixyt'])) ? esc_attr($instance['fixyt']) : '';
|
61 |
+
$hideinfo = (!empty($instance['hideinfo'])) ? esc_attr($instance['hideinfo']) : '';
|
62 |
+
$hideanno = (!empty($instance['hideanno'])) ? esc_attr($instance['hideanno']) : '';
|
63 |
+
$themelight = (!empty($instance['themelight'])) ? esc_attr($instance['themelight']) : '';
|
64 |
+
$debugon = (!empty($instance['debugon'])) ? esc_attr($instance['debugon']) : '';
|
65 |
+
$userchan = (!empty($instance['userchan'])) ? esc_attr($instance['userchan']) : '';
|
66 |
+
$enhprivacy = (!empty($instance['enhprivacy'])) ? esc_attr($instance['enhprivacy']) : '';
|
67 |
?>
|
68 |
+
<p>
|
69 |
+
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title:', YTCTDOM); ?><input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" title="<?php _e('Title for widget', YTCTDOM); ?>" /></label>
|
70 |
+
</p>
|
71 |
+
<p>
|
72 |
+
<label for="<?php echo $this->get_field_id('channel'); ?>"><?php _e('Channel ID:', YTCTDOM); ?><input type="text" class="widefat" id="<?php echo $this->get_field_id('channel'); ?>" name="<?php echo $this->get_field_name('channel'); ?>" value="<?php echo $channel; ?>" title="<?php _e('YouTube Channel name (not URL to channel)', YTCTDOM); ?>" /></label>
|
73 |
+
</p>
|
74 |
+
<p>
|
75 |
+
<label for="<?php echo $this->get_field_id('playlist'); ?>"><?php _e('Playlist ID:', YTCTDOM); ?><input type="text" class="widefat" id="<?php echo $this->get_field_id('playlist'); ?>" name="<?php echo $this->get_field_name('playlist'); ?>" value="<?php echo $playlist; ?>" title="<?php _e('YouTube Playlist ID (not playlist name)', YTCTDOM); ?>" /></label>
|
76 |
+
</p>
|
77 |
+
<p>
|
78 |
+
<label for="<?php echo $this->get_field_id('use_res'); ?>"><?php _e('Resource to use:', YTCTDOM); ?></label>
|
79 |
+
<select class="widefat" id="<?php echo $this->get_field_id( 'use_res' ); ?>" name="<?php echo $this->get_field_name( 'use_res' ); ?>">
|
80 |
+
<option value="0"<?php selected( $use_res, 0 ); ?>><?php _e('Channel', YTCTDOM); ?></option>
|
81 |
+
<option value="1"<?php selected( $use_res, 1 ); ?>><?php _e('Favorites', YTCTDOM); ?></option>
|
82 |
+
<option value="2"<?php selected( $use_res, 2 ); ?>><?php _e('Playlist', YTCTDOM); ?></option>
|
83 |
+
</select>
|
84 |
+
<br />
|
85 |
+
<label style="display: none" for="<?php echo $this->get_field_id( 'only_pl' ); ?>" id="<?php echo $this->get_field_id( 'only_pl' ); ?>_label"><input class="checkbox" type="checkbox" <?php checked( (bool) $only_pl, true ); ?> id="<?php echo $this->get_field_id( 'only_pl' ); ?>" name="<?php echo $this->get_field_name( 'only_pl' ); ?>" title="<?php _e('Enable this option to embed YouTube playlist widget instead single video from playlist', YTCTDOM); ?>" /> <?php _e('Embed standard playlist', YTCTDOM); ?></label>
|
86 |
+
</p>
|
87 |
+
<?php $onlypl_js_fn = str_replace('-','_',$this->get_field_id( 'only_pl' )); ?>
|
88 |
+
<script type="text/javascript">
|
89 |
+
jQuery(document).ready(function($){
|
90 |
+
toggle_<?php echo $onlypl_js_fn; ?>($('#<?php echo $this->get_field_id( 'use_res' ); ?>'));
|
91 |
+
$('#<?php echo $this->get_field_id( 'use_res' ); ?>').change(function(){
|
92 |
+
toggle_<?php echo $onlypl_js_fn; ?>($(this));
|
93 |
+
});
|
94 |
+
function toggle_<?php echo $onlypl_js_fn; ?>(d) {
|
95 |
+
if ( d.find(':selected')[0].value == 2 ) {
|
96 |
+
$('#<?php echo $this->get_field_id( 'only_pl' ); ?>_label').fadeIn();
|
97 |
+
} else {
|
98 |
+
$('#<?php echo $this->get_field_id( 'only_pl' ); ?>_label').fadeOut();
|
99 |
+
}
|
100 |
+
}
|
101 |
+
});
|
102 |
+
</script>
|
103 |
+
<p>
|
104 |
+
<label for="<?php echo $this->get_field_id('cache_time'); ?>"><?php _e('Cache feed:', YTCTDOM); ?></label>
|
105 |
+
<select class="widefat" id="<?php echo $this->get_field_id( 'cache_time' ); ?>" name="<?php echo $this->get_field_name( 'cache_time' ); ?>">
|
106 |
+
|
107 |
+
<option value="0"<?php selected( $cache_time, 0 ); ?>><?php _e('Do not chache', YTCTDOM); ?></option>
|
108 |
+
<?php $tt = 60; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('1 minute', YTCTDOM); ?></option>
|
109 |
+
<?php $tt = 60 * 5; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('5 minutes', YTCTDOM); ?></option>
|
110 |
+
<?php $tt = 60 * 15; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('15 minutes', YTCTDOM); ?></option>
|
111 |
+
<?php $tt = 60 * 30; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('30 minutes', YTCTDOM); ?></option>
|
112 |
+
<?php $tt = 60 * 60; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('1 hour', YTCTDOM); ?></option>
|
113 |
+
<?php $tt = 60 * 60 * 2; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('2 hours', YTCTDOM); ?></option>
|
114 |
+
<?php $tt = 60 * 60 * 5; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('5 hours', YTCTDOM); ?></option>
|
115 |
+
<?php $tt = 60 * 60 * 10; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('10 hours', YTCTDOM); ?></option>
|
116 |
+
<?php $tt = 60 * 60 * 12; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('12 hours', YTCTDOM); ?></option>
|
117 |
+
<?php $tt = 60 * 60 * 18; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('18 hours', YTCTDOM); ?></option>
|
118 |
+
<?php $tt = 60 * 60 * 24; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('1 day', YTCTDOM); ?></option>
|
119 |
+
<?php $tt = 60 * 60 * 24 * 2; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('2 days', YTCTDOM); ?></option>
|
120 |
+
<?php $tt = 60 * 60 * 24 * 3; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('3 days', YTCTDOM); ?></option>
|
121 |
+
<?php $tt = 60 * 60 * 24 * 4; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('4 days', YTCTDOM); ?></option>
|
122 |
+
<?php $tt = 60 * 60 * 24 * 5; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('5 days', YTCTDOM); ?></option>
|
123 |
+
<?php $tt = 60 * 60 * 24 * 6; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('6 days', YTCTDOM); ?></option>
|
124 |
+
<?php $tt = 60 * 60 * 24 * 7; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('1 week', YTCTDOM); ?></option>
|
125 |
+
<?php $tt = 60 * 60 * 24 * 7 * 2; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('2 weeks', YTCTDOM); ?></option>
|
126 |
+
<?php $tt = 60 * 60 * 24 * 7 * 3; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('3 weeks', YTCTDOM); ?></option>
|
127 |
+
<?php $tt = 60 * 60 * 24 * 7 * 4; ?><option value="<?=$tt?>"<?php selected( $cache_time, $tt ); ?>><?php _e('1 month', YTCTDOM); ?></option>
|
128 |
+
</select>
|
129 |
+
</p>
|
130 |
+
<p>
|
131 |
+
<label for="<?php echo $this->get_field_id('maxrnd'); ?>"><?php _e('Fetch:', YTCTDOM); ?> <input class="small-text" id="<?php echo $this->get_field_id('maxrnd'); ?>" name="<?php echo $this->get_field_name('maxrnd'); ?>" type="number" min="2" value="<?php echo $maxrnd; ?>" title="<?php _e('Number of videos that will be used for random pick (min 2, max 50, default 25)', YTCTDOM); ?>" /> video(s)</label>
|
132 |
+
<br />
|
133 |
+
<label for="<?php echo $this->get_field_id('vidqty'); ?>"><?php _e('Show:', YTCTDOM); ?></label> <input class="small-text" id="<?php echo $this->get_field_id('vidqty'); ?>" name="<?php echo $this->get_field_name('vidqty'); ?>" type="number" min="1" value="<?php echo ( $vidqty ) ? $vidqty : '1'; ?>" title="<?php _e('Number of videos to display', YTCTDOM); ?>" /> video(s)
|
134 |
+
</p>
|
135 |
+
<p>
|
136 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $enhprivacy, true ); ?> id="<?php echo $this->get_field_id( 'enhprivacy' ); ?>" name="<?php echo $this->get_field_name( 'enhprivacy' ); ?>" title="<?php _e('Enable this option to protect your visitors privacy', YTCTDOM); ?>" /> <label for="<?php echo $this->get_field_id( 'enhprivacy' ); ?>"><?php printf(__('Use <a href="%s" target="_blank">Enhanced Privacy</a>', YTCTDOM), 'http://support.google.com/youtube/bin/answer.py?hl=en-GB&answer=171780'); ?></label>
|
137 |
+
<br />
|
138 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $fixnoitem, true ); ?> id="<?php echo $this->get_field_id( 'fixnoitem' ); ?>" name="<?php echo $this->get_field_name( 'fixnoitem' ); ?>" title="<?php _e('Enable this option if you get error No Item', YTCTDOM); ?>" /> <label for="<?php echo $this->get_field_id( 'fixnoitem' ); ?>"><?php _e('Fix <em>No items</em> error/Respect playlist order', YTCTDOM); ?></label>
|
139 |
+
<br />
|
140 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $getrnd, true ); ?> id="<?php echo $this->get_field_id( 'getrnd' ); ?>" name="<?php echo $this->get_field_name( 'getrnd' ); ?>" title="<?php _e('Get random videos of all fetched from channel or playlist', YTCTDOM); ?>" /> <label for="<?php echo $this->get_field_id( 'getrnd' ); ?>"><?php _e('Show random video', YTCTDOM); ?></label>
|
141 |
+
</p>
|
142 |
|
143 |
+
<h4><?php _e('Video Settings', YTCTDOM); ?></h4>
|
144 |
+
<p>
|
145 |
+
<label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width', YTCTDOM); ?>:</label> <input class="small-text" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" type="number" min="32" value="<?php echo $width; ?>" title="<?php _e('Set video width in pixels', YTCTDOM); ?>" /> px (<?php _e('default', YTCTDOM); ?> 220)
|
146 |
+
<br />
|
147 |
+
<label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height', YTCTDOM); ?>:</label> <input class="small-text" id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" type="number" min="32" value="<?php echo $height; ?>" title="<?php _e('Set video height in pixels', YTCTDOM); ?>" /> px (<?php _e('default', YTCTDOM); ?> 165)
|
148 |
+
</p>
|
149 |
+
<p><label for="<?php echo $this->get_field_id('ratio'); ?>"><?php _e('Aspect ratio (relative to width):', YTCTDOM); ?></label>
|
150 |
<select class="widefat" id="<?php echo $this->get_field_id( 'ratio' ); ?>" name="<?php echo $this->get_field_name( 'ratio' ); ?>">
|
151 |
+
<option value="0"<?php selected( $ratio, 0 ); ?>><?php _e('Custom (as set above)', YTCTDOM); ?></option>
|
152 |
+
<option value="1"<?php selected( $ratio, 1 ); ?>>4:3</option>
|
153 |
+
<option value="2"<?php selected( $ratio, 2 ); ?>>16:10</option>
|
154 |
+
<option value="3"<?php selected( $ratio, 3 ); ?>>16:9</option>
|
155 |
</select>
|
156 |
</p>
|
157 |
+
<p>
|
158 |
+
<label for="<?php echo $this->get_field_id('to_show'); ?>"><?php _e('What to show?', YTCTDOM); ?></label>
|
159 |
<select class="widefat" id="<?php echo $this->get_field_id( 'to_show' ); ?>" name="<?php echo $this->get_field_name( 'to_show' ); ?>">
|
160 |
+
<option value="thumbnail"<?php selected( $to_show, 'thumbnail' ); ?>><?php _e('Thumbnail', YTCTDOM); ?></option>
|
161 |
+
<option value="object"<?php selected( $to_show, 'object' ); ?>><?php _e('Flash (object)', YTCTDOM); ?></option>
|
162 |
+
<option value="iframe"<?php selected( $to_show, 'iframe' ); ?>><?php _e('HTML5 (iframe)', YTCTDOM); ?></option>
|
163 |
+
<option value="chromeless"<?php selected( $to_show, 'chromeless' ); ?>><?php _e('Chromeless', YTCTDOM); ?></option>
|
164 |
</select>
|
165 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $themelight, true ); ?> id="<?php echo $this->get_field_id( 'themelight' ); ?>" name="<?php echo $this->get_field_name( 'themelight' ); ?>" /> <label for="<?php echo $this->get_field_id( 'themelight' ); ?>"><?php _e('Use light theme (default is dark)', YTCTDOM); ?></label><br />
|
166 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $controls, true ); ?> id="<?php echo $this->get_field_id( 'controls' ); ?>" name="<?php echo $this->get_field_name( 'controls' ); ?>" /> <label for="<?php echo $this->get_field_id( 'controls' ); ?>"><?php _e('Hide player controls', YTCTDOM); ?></label><br />
|
167 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $fixyt, true ); ?> id="<?php echo $this->get_field_id( 'fixyt' ); ?>" name="<?php echo $this->get_field_name( 'fixyt' ); ?>" /> <label for="<?php echo $this->get_field_id( 'fixyt' ); ?>"><?php _e('Fix height taken by controls', YTCTDOM); ?></label><br />
|
168 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $autoplay, true ); ?> id="<?php echo $this->get_field_id( 'autoplay' ); ?>" name="<?php echo $this->get_field_name( 'autoplay' ); ?>" /> <label for="<?php echo $this->get_field_id( 'autoplay' ); ?>"><?php _e('Autoplay video or playlist', YTCTDOM); ?></label>
|
169 |
+
</p>
|
170 |
+
|
171 |
+
<h4><?php _e('Content Layout', YTCTDOM); ?></h4>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
<p>
|
173 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $showtitle, true ); ?> id="<?php echo $this->get_field_id( 'showtitle' ); ?>" name="<?php echo $this->get_field_name( 'showtitle' ); ?>" /> <label for="<?php echo $this->get_field_id( 'showtitle' ); ?>"><?php _e('Show video title', YTCTDOM); ?></label><br />
|
174 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $showvidesc, true ); ?> id="<?php echo $this->get_field_id( 'showvidesc' ); ?>" name="<?php echo $this->get_field_name( 'showvidesc' ); ?>" /> <label for="<?php echo $this->get_field_id( 'showvidesc' ); ?>"><?php _e('Show video description', YTCTDOM); ?></label><br />
|
175 |
+
<label for="<?php echo $this->get_field_id('videsclen'); ?>"><?php _e('Description length', YTCTDOM); ?>: <input class="small-text" id="<?php echo $this->get_field_id('videsclen'); ?>" name="<?php echo $this->get_field_name('videsclen'); ?>" type="number" value="<?php echo $videsclen; ?>" title="<?php _e('Set number of characters to cut down video description to (0 means full length)', YTCTDOM);?>" /> (0 = full)</label><br />
|
176 |
+
<label for="<?php echo $this->get_field_id('descappend'); ?>"><?php _e('Et cetera string', YTCTDOM); ?> <input class="small-text" id="<?php echo $this->get_field_id('descappend'); ?>" name="<?php echo $this->get_field_name('descappend'); ?>" type="text" value="<?php echo $descappend; ?>" title="<?php _e('Default: &hellip;', YTCTDOM); ?>"/></label><br />
|
177 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $hideanno, true ); ?> id="<?php echo $this->get_field_id( 'hideanno' ); ?>" name="<?php echo $this->get_field_name( 'hideanno' ); ?>" /> <label for="<?php echo $this->get_field_id( 'hideanno' ); ?>"><?php _e('Hide annotations from video', YTCTDOM); ?></label><br />
|
178 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $hideinfo, true ); ?> id="<?php echo $this->get_field_id( 'hideinfo' ); ?>" name="<?php echo $this->get_field_name( 'hideinfo' ); ?>" /> <label for="<?php echo $this->get_field_id( 'hideinfo' ); ?>"><?php _e('Hide video info', YTCTDOM); ?></label>
|
179 |
+
</p>
|
180 |
+
|
181 |
+
<h4><?php _e('Link to Channel', YTCTDOM); ?></h4>
|
182 |
+
<p>
|
183 |
+
<label for="<?php echo $this->get_field_id('goto_txt'); ?>"><?php _e('Visit YouTube Channel text:', YTCTDOM); ?> <input class="widefat" id="<?php echo $this->get_field_id('goto_txt'); ?>" name="<?php echo $this->get_field_name('goto_txt'); ?>" type="text" value="<?php echo $goto_txt; ?>" title="<?php _e('Default: Visit channel %channel%. Use placeholder %channel% to insert channel name.', YTCTDOM); ?>" /></label>
|
184 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $showgoto, true ); ?> id="<?php echo $this->get_field_id( 'showgoto' ); ?>" name="<?php echo $this->get_field_name( 'showgoto' ); ?>" /> <label for="<?php echo $this->get_field_id( 'showgoto' ); ?>"><?php _e('Show link to channel', YTCTDOM); ?></label><br />
|
185 |
+
|
186 |
+
<select class="widefat" id="<?php echo $this->get_field_id( 'popup_goto' ); ?>" name="<?php echo $this->get_field_name( 'popup_goto' ); ?>">
|
187 |
+
<option value="0"<?php selected( $popup_goto, 0 ); ?>><?php _e('in same window', YTCTDOM); ?></option>
|
188 |
+
<option value="1"<?php selected( $popup_goto, 1 ); ?>><?php _e('in new window (JavaScript)', YTCTDOM); ?></option>
|
189 |
+
<option value="2"<?php selected( $popup_goto, 2 ); ?>><?php _e('in new window (Target)', YTCTDOM); ?></option>
|
190 |
+
</select>
|
191 |
+
|
192 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $userchan, true ); ?> id="<?php echo $this->get_field_id( 'userchan' ); ?>" name="<?php echo $this->get_field_name( 'userchan' ); ?>" /> <label for="<?php echo $this->get_field_id( 'userchan' ); ?>"><?php _e('Link to channel instead to user', YTCTDOM); ?></label><br />
|
193 |
</p>
|
194 |
|
195 |
+
<h4><?php _e('Debug YTC', YTCTDOM); ?></h4>
|
196 |
<p>
|
197 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $debugon, true ); ?> id="<?php echo $this->get_field_id( 'debugon' ); ?>" name="<?php echo $this->get_field_name( 'debugon' ); ?>" /> <label for="<?php echo $this->get_field_id( 'debugon' ); ?>">Enable debugging</label><br />
|
198 |
|
199 |
<?php
|
200 |
+
if ( $debugon == 'on' ) {
|
201 |
$debug_arr = array_merge(
|
202 |
array(
|
203 |
'server' => $_SERVER["SERVER_SOFTWARE"],
|
204 |
+
'php' => phpversion(),
|
205 |
+
'wp' => get_bloginfo('version'),
|
206 |
+
'ytc' => YTCVER,
|
207 |
+
'url' => get_site_url()
|
208 |
),
|
209 |
$instance);
|
210 |
?>
|
211 |
|
212 |
+
<textarea name="debug" class="widefat" style="height: 100px;"><?php echo au_ytc_dbg($debug_arr); ?></textarea><br />
|
213 |
Insert debug data to <a href="http://wordpress.org/support/plugin/youtube-channel" target="_support">support forum</a>.
|
214 |
<?php } ?>
|
215 |
</p>
|
216 |
|
217 |
+
<p>
|
218 |
+
<input type="button" value="Support YTC / Donate via PayPal" onclick="window.location='https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Q6Q762MQ97XJ6'" class="button-secondary">
|
219 |
+
</p>
|
220 |
|
221 |
<?php
|
222 |
}
|
223 |
|
224 |
+
public function update($new_instance, $old_instance) {
|
225 |
// processes widget options to be saved
|
226 |
$instance = $old_instance;
|
227 |
$instance['title'] = strip_tags($new_instance['title']);
|
228 |
$instance['channel'] = strip_tags($new_instance['channel']);
|
229 |
$instance['vidqty'] = $new_instance['vidqty'];
|
230 |
$instance['playlist'] = strip_tags($new_instance['playlist']);
|
231 |
+
$instance['use_res'] = $new_instance['use_res'];
|
232 |
+
$instance['cache_time'] = $new_instance['cache_time'];
|
233 |
$instance['only_pl'] = $new_instance['only_pl'];
|
234 |
$instance['getrnd'] = $new_instance['getrnd'];
|
235 |
$instance['maxrnd'] = $new_instance['maxrnd'];
|
236 |
+
|
237 |
$instance['goto_txt'] = strip_tags($new_instance['goto_txt']);
|
238 |
$instance['showgoto'] = $new_instance['showgoto'];
|
239 |
+
$instance['popup_goto'] = $new_instance['popup_goto'];
|
240 |
+
|
241 |
$instance['showtitle'] = $new_instance['showtitle'];
|
242 |
$instance['showvidesc'] = $new_instance['showvidesc'];
|
243 |
$instance['descappend'] = strip_tags($new_instance['descappend']);
|
246 |
$instance['height'] = strip_tags($new_instance['height']);
|
247 |
$instance['to_show'] = strip_tags($new_instance['to_show']);
|
248 |
$instance['autoplay'] = $new_instance['autoplay'];
|
|
|
249 |
$instance['controls'] = $new_instance['controls'];
|
250 |
$instance['fixnoitem'] = $new_instance['fixnoitem'];
|
251 |
$instance['ratio'] = strip_tags($new_instance['ratio']);
|
254 |
$instance['hideanno'] = $new_instance['hideanno'];
|
255 |
$instance['themelight'] = $new_instance['themelight'];
|
256 |
$instance['debugon'] = $new_instance['debugon'];
|
257 |
+
$instance['userchan'] = $new_instance['userchan'];
|
258 |
+
$instance['enhprivacy'] = $new_instance['enhprivacy'];
|
259 |
|
260 |
return $instance;
|
261 |
}
|
262 |
|
263 |
+
public function widget($args, $instance) {
|
264 |
// outputs the content of the widget
|
265 |
extract( $args );
|
266 |
+
|
267 |
$title = apply_filters('widget_title', $instance['title']);
|
268 |
|
269 |
// set default channel if nothing predefined
|
270 |
$channel = $instance['channel'];
|
271 |
+
if ( $channel == "" ) $channel = YTCUID;
|
|
|
272 |
|
273 |
// set playlist id
|
274 |
$playlist = $instance['playlist'];
|
275 |
+
if ( $playlist == "" ) $playlist = YTCPLID;
|
|
|
276 |
|
277 |
// trim PL in front of playlist ID
|
278 |
$playlist = preg_replace('/^PL/', '', $playlist);
|
279 |
+
$use_res = $instance['use_res'];
|
280 |
|
281 |
$output = array();
|
282 |
$output[] = $before_widget;
|
283 |
+
if ( $title ) $output[] = $before_title . $title . $after_title;
|
|
|
284 |
|
285 |
$output[] = '<div class="youtube_channel">';
|
286 |
|
287 |
+
if ( $instance['only_pl'] && $use_res == 2 ) { // print standard playlist
|
288 |
$output = array_merge($output, ytc_only_pl($instance));
|
289 |
} else { // channel or playlist single videos
|
290 |
|
293 |
if ( $maxrnd < 1 ) { $maxrnd = 10; } // default 10
|
294 |
elseif ( $maxrnd > 50 ) { $maxrnd = 50; } // max 50
|
295 |
|
296 |
+
$feed_attr = '?alt=json';
|
297 |
+
// select fields
|
298 |
+
$feed_attr .= "&fields=entry(published,title,link,content)";
|
299 |
+
|
300 |
+
if ( !$instance['fixnoitem'] && $use_res != 1 )
|
301 |
+
$feed_attr .= '&orderby=published';
|
302 |
|
303 |
+
$getrnd = $instance['getrnd'];
|
304 |
+
if ( $getrnd ) $feed_attr .= '&max-results='.$maxrnd;
|
305 |
+
|
306 |
+
$feed_attr .= '&rel=0';
|
307 |
+
switch ($use_res) {
|
308 |
+
case 1: // favorites
|
309 |
+
$feed_url = 'http://gdata.youtube.com/feeds/base/users/'.$channel.'/favorites'.$feed_attr;
|
310 |
+
break;
|
311 |
+
case 2: // playlist
|
312 |
+
$playlist = ytc_clean_playlist_id($playlist);
|
313 |
+
$feed_url = 'http://gdata.youtube.com/feeds/api/playlists/'.$playlist.$feed_attr;
|
314 |
+
break;
|
315 |
+
default:
|
316 |
+
$feed_url = 'http://gdata.youtube.com/feeds/base/users/'.$channel.'/uploads'.$feed_attr;
|
317 |
+
}
|
318 |
+
|
319 |
+
// do we need cache?
|
320 |
+
if ($instance['cache_time'] > 0 ) {
|
321 |
+
// generate feed cache key for caching time
|
322 |
+
$cache_key = 'ytc_'.md5($feed_url).'_'.$instance['cache_time'];
|
323 |
+
|
324 |
+
// get/set transient cache
|
325 |
+
if ( false === ($json = get_transient($cache_key)) ) {
|
326 |
+
// no cached JSON, get new
|
327 |
+
$json = file_get_contents($feed_url,0,null,null);
|
328 |
+
// set decoded JSON to transient cache_key
|
329 |
+
set_transient($cache_key, json_decode($json), $instance['cache_time']);
|
330 |
+
} else {
|
331 |
+
// we already have cached feed JSON, get it encoded
|
332 |
+
$json = json_encode($json);
|
333 |
+
}
|
334 |
} else {
|
335 |
+
// just get fresh feed if cache disabled
|
336 |
+
$json = file_get_contents($feed_url,0,null,null);
|
337 |
}
|
338 |
|
339 |
+
// decode JSON data
|
340 |
+
$json_output = json_decode($json);
|
341 |
|
342 |
+
if ( !is_wp_error($json_output) ) {
|
343 |
+
// sort by date uploaded
|
344 |
+
$json_entry = $json_output->feed->entry;
|
345 |
|
346 |
+
/* AU:20140216 for what we need this at all, when feed already have orderby=published */
|
347 |
+
// do we need sort when use playlist?
|
348 |
+
// if ( $use_res != 2 ) usort($json_entry, "ytc_json_sort_by_date");
|
349 |
+
|
350 |
$vidqty = $instance['vidqty'];
|
351 |
if ( $vidqty > $maxrnd ) { $maxrnd = $vidqty; }
|
352 |
+
$maxitems = ( $maxrnd > sizeof($json_entry) ) ? sizeof($json_entry) : $maxrnd;
|
353 |
|
354 |
if ( $getrnd ) {
|
355 |
+
$items = array_slice($json_entry,0,$maxitems);
|
356 |
} else {
|
357 |
+
if ( !$vidqty ) $vidqty = 1;
|
358 |
+
$items = array_slice($json_entry,0,$vidqty);
|
|
|
359 |
}
|
360 |
}
|
361 |
+
|
362 |
if ($maxitems == 0) {
|
363 |
+
$output[] = __( 'No items' , YTCTDOM );
|
364 |
} else {
|
365 |
+
|
366 |
+
if ( $getrnd ) $rnd_used = array(); // set array for unique random item
|
367 |
|
368 |
for ($y = 1; $y <= $vidqty; $y++) {
|
369 |
if ( $getrnd ) {
|
375 |
$item = $items[$rnd_item];
|
376 |
} else {
|
377 |
$item = $items[$y-1];
|
|
|
378 |
}
|
379 |
|
380 |
// print single video block
|
381 |
$output = array_merge( $output, ytc_print_video($item, $instance, $y) );
|
382 |
}
|
383 |
+
|
384 |
}
|
385 |
} // single playlist or ytc way
|
386 |
|
401 |
if ( empty($width) )
|
402 |
$width = 220;
|
403 |
|
404 |
+
$playlist = $instance['playlist'];
|
405 |
if ( empty($playlist) )
|
406 |
$playlist = YTCPLID;
|
407 |
+
|
408 |
+
$height = height_ratio($width, $instance['height'], $instance['ratio']);
|
409 |
+
|
410 |
+
$height += ($instance['fixyt']) ? 25 : 0;
|
411 |
+
|
412 |
$playlist = ytc_clean_playlist_id($playlist);
|
413 |
+
|
414 |
$autoplay = $instance['autoplay'];
|
415 |
if ( $autoplay )
|
416 |
$autoplay = '&autoplay=1';
|
417 |
+
|
418 |
+
// enhanced privacy
|
419 |
+
$yt_domain = yt_domain($instance); //( !empty($instance['enhprivacy']) ) ? 'www.youtube-nocookie.com' : 'www.youtube.com';
|
420 |
$output[] = '<div class="ytc_video_container ytc_video_1 ytc_video_single">
|
421 |
+
<iframe src="http://'.$yt_domain.'/embed/videoseries?list=PL'.$playlist.$autoplay.'"
|
422 |
width="'.$width.'" height="'.$height.'" frameborder="0"></iframe></div>';
|
423 |
return $output;
|
424 |
}
|
425 |
|
426 |
/* function to print video in widget */
|
427 |
function ytc_print_video($item, $instance, $y) {
|
|
|
|
|
428 |
|
429 |
// get hideinfo, autoplay and controls settings
|
430 |
// where this is used?
|
436 |
$width = $instance['width'];
|
437 |
if ( empty($width) )
|
438 |
$width = 220;
|
439 |
+
$height = height_ratio($width, $instance['height'], $instance['ratio']);
|
440 |
|
441 |
// calculate image height based on width for 4:3 thumbnail
|
442 |
$imgfixedheight = $width / 4 * 3;
|
454 |
$themelight = $instance['themelight'];
|
455 |
/* end of video settings */
|
456 |
|
457 |
+
$yt_id = $item->link[0]->href;
|
458 |
+
$yt_id = preg_replace('/^.*=(.*)&.*$/', '${1}', $yt_id);
|
459 |
+
$yt_url = "v/$yt_id";
|
460 |
+
|
461 |
+
$yt_thumb = "http://img.youtube.com/vi/$yt_id/0.jpg"; // zero for HD thumb
|
462 |
+
$yt_video = $item->link[0]->href;
|
463 |
+
$yt_title = $item->title->{'$t'};
|
464 |
+
$yt_date = $item->published->{'$t'};
|
465 |
+
//$yt_date = $item->get_date('j F Y | g:i a');
|
466 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
467 |
switch ($y) {
|
468 |
case 1:
|
469 |
$vnumclass = 'first';
|
487 |
// define object ID
|
488 |
$ytc_vid = 'ytc_' . $yt_id;
|
489 |
|
490 |
+
// enhanced privacy
|
491 |
+
$yt_domain = yt_domain($instance);
|
492 |
+
|
493 |
// print out video
|
494 |
if ( $to_show == "thumbnail" ) {
|
495 |
+
$title = sprintf( __( 'Watch video %1$s published on %2$s' , YTCTDOM ), $yt_title, $yt_date );
|
496 |
+
$output[] = '<a href="'.$yt_video.'" title="'.$title.'" target="_blank"><span style="width: '.$width.'px; height: '.$height.'px; overflow: hidden; display: block; background: url('.$yt_thumb.') 50% 50% no-repeat; background-size: '.$width.'px '.$imgfixedheight.'px;" title="'.$yt_title.'" id="'.$ytc_vid.'"></span></a>';
|
|
|
|
|
497 |
} else if ( $to_show == "chromeless" ) {
|
498 |
ob_start();
|
499 |
?>
|
508 |
$output[] = ob_get_contents();
|
509 |
ob_end_clean();
|
510 |
} else if ( $to_show == "iframe" ) {
|
511 |
+
if ( empty($usepl) ) $yt_url = $yt_id;
|
512 |
+
|
513 |
+
$output[] = '<iframe title="YouTube video player" width="'.$width.'" height="'.$height.'" src="//'.$yt_domain.'/embed/'.$yt_url.'?wmode=opaque'; //&enablejsapi=1';
|
514 |
+
if ( $controls ) $output[] = "&controls=0";
|
515 |
+
if ( $hideinfo ) $output[] = "&showinfo=0";
|
516 |
+
if ( $autoplay ) $output[] = "&autoplay=1";
|
517 |
+
if ( $hideanno ) $output[] = "&iv_load_policy=3";
|
518 |
+
if ( $themelight ) $output[] = "&theme=light";
|
|
|
|
|
|
|
|
|
|
|
|
|
519 |
|
520 |
+
$output[] = '" style="border: 0;" allowfullscreen id="'.$ytc_vid.'"></iframe>';
|
521 |
} else { // default is object
|
522 |
+
$obj_url = '//'.$yt_domain.'/'.$yt_url.'?version=3';
|
523 |
+
$obj_url .= ( $controls ) ? '&controls=0' : '';
|
524 |
+
$obj_url .= ( $hideinfo ) ? '&showinfo=0' : '';
|
525 |
+
$obj_url .= ( $autoplay ) ? '&autoplay=1' : '';
|
526 |
+
$obj_url .= ( $hideanno ) ? '&iv_load_policy=3' : '';
|
527 |
+
$obj_url .= ( $themelight ) ? '&theme=light' : '';
|
528 |
ob_start();
|
529 |
?>
|
530 |
+
<object width="<?php echo $width; ?>" height="<?php echo $height; ?>" type="application/x-shockwave-flash" data="<?php echo $obj_url; ?>">
|
531 |
+
<param name="movie" value="<?php echo $obj_url; ?>" />
|
532 |
+
<param name="allowFullScreen" value="true" />
|
533 |
+
<param name="allowscriptaccess" value="always" />
|
534 |
+
<param name="quality" value="high" />
|
535 |
+
<param name="wmode" value="opaque" />
|
536 |
+
<embed src="<?php echo $obj_url; ?>" type="application/x-shockwave-flash" width="<?php echo $width; ?>" height="<?php echo $height; ?>" allowscriptaccess="always" allowfullscreen="true" />
|
537 |
+
</object>
|
538 |
+
|
|
|
|
|
539 |
<?php
|
540 |
$output[] = ob_get_contents();
|
541 |
ob_end_clean();
|
543 |
|
544 |
// do we need to show video description?
|
545 |
if ( $instance['showvidesc'] ) {
|
546 |
+
|
547 |
+
preg_match('/><span>(.*)<\/span><\/div>/', $item->content->{'$t'}, $videsc);
|
548 |
+
if ( empty($videsc[1]) ) {
|
549 |
+
$videsc[1] = $item->content->{'$t'};
|
550 |
+
}
|
551 |
+
|
552 |
+
// clean HTML
|
553 |
+
$nohtml = explode("</div>",$videsc[1]);
|
554 |
+
if ( sizeof($nohtml) > 1 ) {
|
555 |
+
$videsc[1] = strip_tags($nohtml[2]);
|
556 |
+
unset($nohtml);
|
557 |
+
} else {
|
558 |
+
$videsc[1] = strip_tags($videsc[1]);
|
559 |
+
}
|
560 |
+
|
561 |
if ( $instance['videsclen'] > 0 ) {
|
562 |
+
if ( strlen($videsc[1]) > $instance['videsclen'] ) {
|
563 |
+
$video_description = substr($videsc[1], 0, $instance['videsclen']);
|
564 |
+
if ( $instance['descappend'] ) {
|
565 |
+
$etcetera = $instance['descappend'];
|
566 |
+
} else {
|
567 |
+
$etcetera = '…';
|
568 |
+
}
|
569 |
+
}
|
570 |
} else {
|
571 |
$video_description = $videsc[1];
|
572 |
+
$etcetera = '';
|
573 |
}
|
574 |
+
if (!empty($video_description))
|
|
|
|
|
|
|
|
|
|
|
575 |
$output[] = '<p class="ytc_description">' .$video_description.$etcetera. '</p>';
|
|
|
576 |
}
|
577 |
$output[] = '</div><!-- .ytc_video_container -->';
|
578 |
|
580 |
}
|
581 |
|
582 |
// function to calculate height by width and ratio
|
583 |
+
function height_ratio($width, $height=0, $ratio) {
|
584 |
if ( $width == "" )
|
585 |
$width = 220;
|
586 |
|
591 |
} elseif ( $ratio == 3 ) { // 16:9
|
592 |
$height = round(($width / 16 ) * 9);
|
593 |
} else { // set default if 0 or ratio not set
|
594 |
+
// $height = $instance['height'];
|
595 |
+
if ( $height == "" || $height == 0 )
|
596 |
$height = 165;
|
597 |
}
|
598 |
return $height;
|
609 |
$channel = 'urkekg';
|
610 |
$goto_txt = $instance['goto_txt'];
|
611 |
if ( $goto_txt == "" )
|
612 |
+
$goto_txt = sprintf( __( 'Visit channel %1$s' , YTCTDOM ), $channel );
|
613 |
+
else
|
614 |
+
$goto_txt = str_replace('%channel%', $channel, $goto_txt);
|
615 |
|
616 |
$output[] = '<div class="ytc_link">';
|
617 |
+
$userchan = ( $instance['userchan'] ) ? 'channel' : 'user';
|
618 |
+
$goto_url = 'http://www.youtube.com/'.$userchan.'/'.$channel.'/';
|
619 |
+
$newtab = __("in new window/tab", "youtube-channel");
|
620 |
+
$output[] = '<p>';
|
621 |
+
switch ( $instance['popup_goto'] ) {
|
622 |
+
case 1:
|
623 |
+
$output[] = '<a href="javascript: window.open(\''.$goto_url.'\'); void 0;" title="'.$goto_txt.' '.$newtab.'">'.$goto_txt.'</a>';
|
624 |
+
break;
|
625 |
+
case 2:
|
626 |
+
$output[] = '<a href="'.$goto_url.'" target="_blank" title="'.$goto_txt.' '.$newtab.'">'.$goto_txt.'</a>';
|
627 |
+
break;
|
628 |
+
default:
|
629 |
+
$output[] = '<a href="'.$goto_url.'" title="'.$goto_txt.'">'.$goto_txt.'</a>';
|
630 |
+
} // switch popup_goto
|
631 |
+
$output[] = '</p>';
|
632 |
$output[] = '</div>';
|
633 |
|
634 |
} // showgoto
|
639 |
function ytc_clean_playlist_id($playlist) {
|
640 |
if ( substr($playlist,0,4) == "http" ) {
|
641 |
// if URL provided, extract playlist ID
|
642 |
+
$playlist = preg_replace('/.*list=PL([A-Za-z0-9]*).*/','$1', $playlist);
|
643 |
} else if ( substr($playlist,0,2) == 'PL' ) {
|
644 |
$playlist = substr($playlist,2);
|
645 |
}
|
651 |
register_widget( 'YouTube_Channel_Widget' );
|
652 |
}
|
653 |
add_action( 'widgets_init', 'youtube_channel_register_widget' );
|
654 |
+
|
655 |
+
function au_ytc_dbg($arr) {
|
656 |
+
$out = '';
|
657 |
+
foreach ( $arr as $key => $val ) {
|
658 |
+
if ( empty($val) ) { $val = 'null'; }
|
659 |
+
$out .= $key . ': ' . $val . chr(13);
|
660 |
+
}
|
661 |
+
return $out;
|
662 |
+
}
|
663 |
+
// do we still need this?
|
664 |
+
function ytc_json_sort_by_date($a, $b) {
|
665 |
+
$ap = $a->published;
|
666 |
+
$bp = $b->published;
|
667 |
+
return strnatcmp($bp, $ap);
|
668 |
+
}
|
669 |
+
function yt_domain($instance) {
|
670 |
+
$yt_domain = ( !empty($instance['enhprivacy']) ) ? 'www.youtube-nocookie.com' : 'www.youtube.com';
|
671 |
+
return $yt_domain;
|
672 |
+
}
|
673 |
+
|
674 |
+
function adbg($i){
|
675 |
+
if ( is_array($i) )
|
676 |
+
$o = '<pre>'.print_r($i,1).'</pre>';
|
677 |
+
else
|
678 |
+
$o = $i;
|
679 |
+
|
680 |
+
apply_filters('debug', $o);
|
681 |
+
}
|