Youtube Channel Gallery - Version 1.4

Version Description

  • Added shortcode feature.
  • Multiple instances of the plugin on the same page.
  • Added theme selector.
  • Improved use of Iframe YouTube Player API (now synchronous).
  • Added effect: hover on thumbnails to display a play button.
Download this release

Release Info

Developer javitxu123
Plugin Icon 128x128 Youtube Channel Gallery
Version 1.4
Comparing to
See all releases

Code changes from version 1.0 to 1.4

languages/youtube-channel-gallery-es_ES.mo CHANGED
Binary file
languages/youtube-channel-gallery-es_ES.po CHANGED
@@ -7,8 +7,8 @@ msgid ""
7
msgstr ""
8
"Project-Id-Version: youtube-channel-gallery\n"
9
"Report-Msgid-Bugs-To: \n"
10
- "POT-Creation-Date: 2012-07-09 17:28+0100\n"
11
- "PO-Revision-Date: 2012-07-09 17:38+0100\n"
12
"Last-Translator: Javier <javierpose@gmail.com>\n"
13
"Language-Team: PoseLab <javierpose@gmail.com>\n"
14
"MIME-Version: 1.0\n"
@@ -23,50 +23,91 @@ msgstr ""
23
"X-Poedit-SourceCharset: utf-8\n"
24
"X-Poedit-SearchPath-0: .\n"
25
26
- #: youtube-channel-gallery.php:42
27
msgid "Youtube Channel Gallery"
28
msgstr "Galería de Canal de Youtube"
29
30
- #: youtube-channel-gallery.php:43
31
msgid "Show a youtube video and a gallery of thumbnails for a youtube channel"
32
msgstr "Muestra un vídeo y una galería de miniaturas de una canal de Youtube "
33
34
- #: youtube-channel-gallery.php:99
35
msgid "Title:"
36
msgstr "Título:"
37
38
- #: youtube-channel-gallery.php:104
39
msgid "YouTube user name:"
40
msgstr "Nombre de usuario de Youtube:"
41
42
- #: youtube-channel-gallery.php:110
43
msgid "Show link to channel:"
44
msgstr "Mostrar enlace al canal:"
45
46
- #: youtube-channel-gallery.php:114
47
msgid "Number of videos to show:"
48
msgstr "Número de vídeos a mostrar:"
49
50
- #: youtube-channel-gallery.php:119
51
msgid "Video width:"
52
msgstr "Ancho del vídeo:"
53
54
- #: youtube-channel-gallery.php:124
55
msgid "Thumbnail width:"
56
msgstr "Ancho de miniaturas:"
57
58
- #: youtube-channel-gallery.php:129
59
msgid "Thumbnail columns:"
60
msgstr "Columnas de las miniaturas:"
61
62
- #: youtube-channel-gallery.php:259
63
msgid "Show more videos»"
64
msgstr "Ver más vídeos»"
65
66
- #: youtube-channel-gallery.php:265
67
msgid "There is no video to show."
68
msgstr "No hay ningún vídeo para mostrar."
69
70
#~ msgid "No post to duplicate has been supplied!"
71
#~ msgstr "No se facilitó ninguna entrada a copiar"
72
#~ msgid "Post creation failed, could not find original post:"
7
msgstr ""
8
"Project-Id-Version: youtube-channel-gallery\n"
9
"Report-Msgid-Bugs-To: \n"
10
+ "POT-Creation-Date: 2012-07-24 14:14+0100\n"
11
+ "PO-Revision-Date: 2012-07-24 14:15+0100\n"
12
"Last-Translator: Javier <javierpose@gmail.com>\n"
13
"Language-Team: PoseLab <javierpose@gmail.com>\n"
14
"MIME-Version: 1.0\n"
23
"X-Poedit-SourceCharset: utf-8\n"
24
"X-Poedit-SearchPath-0: .\n"
25
26
+ #: youtube-channel-gallery.php:44
27
+ #: pruebas/youtube-channel-gallery_bueno.php:46
28
+ #: pruebas/youtube-channel-gallery_bueno2.php:46
29
msgid "Youtube Channel Gallery"
30
msgstr "Galería de Canal de Youtube"
31
32
+ #: youtube-channel-gallery.php:45
33
+ #: pruebas/youtube-channel-gallery_bueno.php:47
34
+ #: pruebas/youtube-channel-gallery_bueno2.php:47
35
msgid "Show a youtube video and a gallery of thumbnails for a youtube channel"
36
msgstr "Muestra un vídeo y una galería de miniaturas de una canal de Youtube "
37
38
+ #: youtube-channel-gallery.php:100
39
+ #: pruebas/youtube-channel-gallery_bueno.php:109
40
+ #: pruebas/youtube-channel-gallery_bueno2.php:107
41
msgid "Title:"
42
msgstr "Título:"
43
44
+ #: youtube-channel-gallery.php:105
45
+ #: pruebas/youtube-channel-gallery_bueno.php:114
46
+ #: pruebas/youtube-channel-gallery_bueno2.php:112
47
msgid "YouTube user name:"
48
msgstr "Nombre de usuario de Youtube:"
49
50
+ #: youtube-channel-gallery.php:111
51
+ #: pruebas/youtube-channel-gallery_bueno.php:120
52
+ #: pruebas/youtube-channel-gallery_bueno2.php:118
53
msgid "Show link to channel:"
54
msgstr "Mostrar enlace al canal:"
55
56
+ #: youtube-channel-gallery.php:115
57
+ #: pruebas/youtube-channel-gallery_bueno.php:124
58
+ #: pruebas/youtube-channel-gallery_bueno2.php:122
59
msgid "Number of videos to show:"
60
msgstr "Número de vídeos a mostrar:"
61
62
+ #: youtube-channel-gallery.php:120
63
+ #: pruebas/youtube-channel-gallery_bueno.php:129
64
+ #: pruebas/youtube-channel-gallery_bueno2.php:127
65
msgid "Video width:"
66
msgstr "Ancho del vídeo:"
67
68
+ #: youtube-channel-gallery.php:125
69
+ #: pruebas/youtube-channel-gallery_bueno.php:134
70
+ #: pruebas/youtube-channel-gallery_bueno2.php:132
71
msgid "Thumbnail width:"
72
msgstr "Ancho de miniaturas:"
73
74
+ #: youtube-channel-gallery.php:130
75
+ #: pruebas/youtube-channel-gallery_bueno.php:139
76
+ #: pruebas/youtube-channel-gallery_bueno.php:144
77
+ #: pruebas/youtube-channel-gallery_bueno2.php:137
78
msgid "Thumbnail columns:"
79
msgstr "Columnas de las miniaturas:"
80
81
+ #: youtube-channel-gallery.php:135
82
+ #: pruebas/youtube-channel-gallery_bueno.php:149
83
+ msgid "Theme:"
84
+ msgstr "Tema:"
85
+
86
+ #: youtube-channel-gallery.php:137
87
+ #: pruebas/youtube-channel-gallery_bueno.php:151
88
+ msgid "Dark"
89
+ msgstr "Oscuro"
90
+
91
+ #: youtube-channel-gallery.php:138
92
+ msgid "Light"
93
+ msgstr "Claro"
94
+
95
+ #: youtube-channel-gallery.php:270
96
+ #: pruebas/youtube-channel-gallery_bueno.php:345
97
+ #: pruebas/youtube-channel-gallery_bueno2.php:315
98
msgid "Show more videos»"
99
msgstr "Ver más vídeos»"
100
101
+ #: youtube-channel-gallery.php:276
102
+ #: pruebas/youtube-channel-gallery_bueno.php:351
103
+ #: pruebas/youtube-channel-gallery_bueno2.php:321
104
msgid "There is no video to show."
105
msgstr "No hay ningún vídeo para mostrar."
106
107
+ #: pruebas/youtube-channel-gallery_bueno.php:152
108
+ msgid "Light:"
109
+ msgstr "Claro"
110
+
111
#~ msgid "No post to duplicate has been supplied!"
112
#~ msgstr "No se facilitó ninguna entrada a copiar"
113
#~ msgid "Post creation failed, could not find original post:"
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://poselab.com/
4
Tags: widget, gallery, youtube, channel, user
5
Requires at least: 2.8
6
Tested up to: 3.4.1
7
- Stable tag: 1.0
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
@@ -18,6 +18,8 @@ Show a youtube video and a gallery of thumbnails for a youtube user channel.
18
* Display latest thumbnail videos from YouTube user channel.
19
* When you click on one of the thumbnails the video plays at the top.
20
* This plugin uses the YouTube IFrame player API that allows YouTube to serve an HTML5 player rather than a Flash player for mobile devices that do not support Flash.
21
22
= Widget fields: =
23
* Title: Widget Title.
@@ -27,6 +29,23 @@ Show a youtube video and a gallery of thumbnails for a youtube user channel.
27
* Video width: indicates the width of the video player.
28
* Thumbnail size: indicates the width of the thumbnails. The height is automatically generated.
29
* Thumbnail columns: assign a numeric class to each thumbnail based on the number of columns to apply styles to each column.
30
31
= Demo: =
32
You can see a demo of the plugin at the following URL:
@@ -42,14 +61,14 @@ If you have created your own language pack, or have an update of an existing one
42
== Installation ==
43
44
1. Upload the *.zip copy of this plugin into your WordPress through your 'Plugin' admin page.
45
- 2. Activate the plugin through the 'Plugins' menu in WordPress
46
- 3. Place the widget in your desired sidebar through the "widgets" admin page
47
48
== Frequently Asked Questions ==
49
50
= Where is the “widgets” admin page? =
51
52
- The “widgets” admin page is found in the administrator part (wp-admin) of your WordPress site. Go to Appearance > Widgets
53
54
= How do I find the YouTube user name? =
55
@@ -62,5 +81,12 @@ The username who uploaded a video to Youtube is located below each video, where
62
63
== Changelog ==
64
65
= 1.0 =
66
- * Initial Release
4
Tags: widget, gallery, youtube, channel, user
5
Requires at least: 2.8
6
Tested up to: 3.4.1
7
+ Stable tag: 1.4
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
18
* Display latest thumbnail videos from YouTube user channel.
19
* When you click on one of the thumbnails the video plays at the top.
20
* This plugin uses the YouTube IFrame player API that allows YouTube to serve an HTML5 player rather than a Flash player for mobile devices that do not support Flash.
21
+ * You can choose to use this plugin as a widget or as a shortcode.
22
+ * You can use multiple instances of the plugin on the same page.
23
24
= Widget fields: =
25
* Title: Widget Title.
29
* Video width: indicates the width of the video player.
30
* Thumbnail size: indicates the width of the thumbnails. The height is automatically generated.
31
* Thumbnail columns: assign a numeric class to each thumbnail based on the number of columns to apply styles to each column.
32
+ * Theme: select the youtube player theme (dark or light).
33
+
34
+ = Shortcode syntax: =
35
+ If you want to use it as Shortcode:
36
+
37
+ `[Youtube_Channel_Gallery user="MaxonC4D" maxitems="3" theme="dark"]`
38
+
39
+ The attributes used in the shortcode are the same as the fields available in the widget, except the title field.
40
+
41
+ * user: YouTube user name (required).
42
+ * link: Show link to channel. Values: 0 or 1. (optional).
43
+ * maxitems: Number of videos to show (optional).
44
+ * videowidth: Video width (optional).
45
+ * thumbwidth: Thumbnail size (optional).
46
+ * thumbcolumns: Thumbnail columns (optional).
47
+ * theme: Theme. Values: dark or light (optional).
48
+
49
50
= Demo: =
51
You can see a demo of the plugin at the following URL:
61
== Installation ==
62
63
1. Upload the *.zip copy of this plugin into your WordPress through your 'Plugin' admin page.
64
+ 2. Activate the plugin through the 'Plugins' menu in WordPress.
65
+ 3. Place the widget in your desired sidebar through the "widgets" admin page.
66
67
== Frequently Asked Questions ==
68
69
= Where is the “widgets” admin page? =
70
71
+ The “widgets” admin page is found in the administrator part (wp-admin) of your WordPress site. Go to Appearance > Widgets.
72
73
= How do I find the YouTube user name? =
74
81
82
== Changelog ==
83
84
+ = 1.4 =
85
+ * Added shortcode feature.
86
+ * Multiple instances of the plugin on the same page.
87
+ * Added theme selector.
88
+ * Improved use of Iframe YouTube Player API (now synchronous).
89
+ * Added effect: hover on thumbnails to display a play button.
90
+
91
= 1.0 =
92
+ * Initial Release.
scripts.js ADDED
@@ -0,0 +1,15 @@
1
+ function ytcplayVideo (iframeid, youtubeid) {
2
+ if(window[iframeid].loadVideoById) {
3
+ window[iframeid].loadVideoById(youtubeid);
4
+ }else{
5
+ window[iframeid] = new YT.Player(iframeid, {
6
+ events: {
7
+ 'onReady': function(){
8
+ window[iframeid].loadVideoById(youtubeid);
9
+ }
10
+ }
11
+ });
12
+ }
13
+
14
+
15
+ }
youtube-channel-gallery.css → styles.css RENAMED
@@ -12,4 +12,13 @@ ul.ytcgallery li a{
12
border:1px solid #999;
13
background-position: center center;
14
background-repeat: no-repeat;
15
}
12
border:1px solid #999;
13
background-position: center center;
14
background-repeat: no-repeat;
15
+ }
16
+ ul.ytcgallery li a .ytcplay{
17
+ background: url(img/play.png) -9999px -9999px no-repeat;
18
+ }
19
+ ul.ytcgallery li a:hover{
20
+ opacity: 0.75;
21
+ }
22
+ ul.ytcgallery li a:hover .ytcplay{
23
+ background-position: center center;
24
}
youtube-channel-gallery.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.poselab.com/
5
Description: Show a youtube video and a gallery of thumbnails for a youtube channel.
6
Author: Javier Gómez Pose
7
Author URI: http://www.poselab.com/
8
- Version: 1.0
9
License: GPL2
10
11
Copyright 2010 Javier Gómez Pose (email : javierpose@gmail.com)
@@ -26,10 +26,9 @@ License: GPL2
26
27
28
29
- /*
30
- class
31
-
32
- */
33
class YoutubeChannelGallery_Widget extends WP_Widget {
34
35
/**
@@ -48,7 +47,6 @@ class YoutubeChannelGallery_Widget extends WP_Widget {
48
49
// Load JavaScript and stylesheets
50
$this->register_scripts_and_styles();
51
-
52
}
53
54
/**
@@ -62,7 +60,7 @@ class YoutubeChannelGallery_Widget extends WP_Widget {
62
if ( ! empty( $title ) )
63
echo $before_title . $title . $after_title;
64
65
- $this->ytchag_rss_markup($instance);
66
67
echo $after_widget;
68
}
@@ -73,13 +71,14 @@ class YoutubeChannelGallery_Widget extends WP_Widget {
73
public function update( $new_instance, $old_instance ) {
74
$instance = $old_instance;
75
$instance['title'] = strip_tags( $new_instance['title'] );
76
- $instance['ytchag_user'] = strip_tags( $new_instance['ytchag_user'] );
77
78
- $instance['ytchag_link'] = $new_instance['ytchag_link'];
79
- $instance['ytchag_maxitems'] = strip_tags( $new_instance['ytchag_maxitems'] );
80
- $instance['ytchag_video_width'] = strip_tags( $new_instance['ytchag_video_width'] );
81
- $instance['ytchag_thumb_width'] = strip_tags( $new_instance['ytchag_thumb_width'] );
82
- $instance['ytchag_thumb_columns'] = strip_tags( $new_instance['ytchag_thumb_columns'] );
83
84
return $instance;
85
}
@@ -89,12 +88,13 @@ class YoutubeChannelGallery_Widget extends WP_Widget {
89
*/
90
public function form( $instance ) {
91
$title = esc_attr($instance['title']);
92
- $ytchag_user = strip_tags($instance['ytchag_user']);
93
- $ytchag_link = esc_attr($instance['ytchag_link']);
94
- $ytchag_maxitems = strip_tags($instance['ytchag_maxitems']);
95
- $ytchag_video_width = strip_tags($instance['ytchag_video_width']);
96
- $ytchag_thumb_width = strip_tags($instance['ytchag_thumb_width']);
97
- $ytchag_thumb_columns = strip_tags($instance['ytchag_thumb_columns']);
98
?>
99
<p>
100
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'youtube-channel-gallery' ); ?></label>
@@ -102,33 +102,41 @@ class YoutubeChannelGallery_Widget extends WP_Widget {
102
</p>
103
104
<p>
105
- <label for="<?php echo $this->get_field_id( 'ytchag_user' ); ?>"><?php _e( 'YouTube user name:', 'youtube-channel-gallery' ); ?></label>
106
- <input class="widefat" id="<?php echo $this->get_field_id( 'ytchag_user' ); ?>" name="<?php echo $this->get_field_name( 'ytchag_user' ); ?>" type="text" value="<?php echo esc_attr( $ytchag_user ); ?>" />
107
</p>
108
109
<p>
110
- <input class="checkbox" type="checkbox" <?php checked( (bool) $instance['ytchag_link'], true ); ?> id="<?php echo $this->get_field_id( 'ytchag_link' ); ?>" name="<?php echo $this->get_field_name( 'ytchag_link' ); ?>" />
111
- <label for="<?php echo $this->get_field_id( 'ytchag_link' ); ?>"><?php _e('Show link to channel:', 'youtube-channel-gallery'); ?></label><br />
112
</p>
113
114
<p>
115
- <label for="ytchag_maxitems"><?php _e( 'Number of videos to show:', 'youtube-channel-gallery' ); ?></label>
116
- <input class="widefat" id="<?php echo $this->get_field_id( 'ytchag_maxitems' ); ?>" name="<?php echo $this->get_field_name( 'ytchag_maxitems' ); ?>" type="text" value="<?php echo esc_attr( $ytchag_maxitems ); ?>" />
117
</p>
118
119
<p>
120
- <label for="ytchag_video_width"><?php _e( 'Video width:', 'youtube-channel-gallery' ); ?></label>
121
- <input class="widefat" id="<?php echo $this->get_field_id( 'ytchag_video_width' ); ?>" name="<?php echo $this->get_field_name( 'ytchag_video_width' ); ?>" type="text" value="<?php echo esc_attr( $ytchag_video_width ); ?>" />
122
</p>
123
124
<p>
125
- <label for="ytchag_thumb_width"><?php _e( 'Thumbnail width:', 'youtube-channel-gallery' ); ?></label>
126
- <input class="widefat" id="<?php echo $this->get_field_id( 'ytchag_thumb_width' ); ?>" name="<?php echo $this->get_field_name( 'ytchag_thumb_width' ); ?>" type="text" value="<?php echo esc_attr( $ytchag_thumb_width ); ?>" />
127
</p>
128
129
<p>
130
- <label for="ytchag_thumb_columns"><?php _e( 'Thumbnail columns:', 'youtube-channel-gallery' ); ?></label>
131
- <input class="widefat" id="<?php echo $this->get_field_id( 'ytchag_thumb_columns' ); ?>" name="<?php echo $this->get_field_name( 'ytchag_thumb_columns' ); ?>" type="text" value="<?php echo esc_attr( $ytchag_thumb_columns ); ?>" />
132
</p>
133
134
<?php
@@ -138,171 +146,173 @@ class YoutubeChannelGallery_Widget extends WP_Widget {
138
/*--------------------------------------------------*/
139
/* Private Functions
140
/*--------------------------------------------------*/
141
- private function ytchag_rss_markup($instance){
142
-
143
- //$instance variables
144
- $ytchag_user = apply_filters('ytchag_user', $instance['ytchag_user']);
145
- $ytchag_link = apply_filters('ytchag_link', $instance['ytchag_link']);
146
- $ytchag_maxitems = apply_filters('ytchag_maxitems', $instance['ytchag_maxitems']);
147
- $ytchag_video_width = apply_filters('ytchag_video_width', $instance['ytchag_video_width']);
148
- $ytchag_thumb_width = apply_filters('ytchag_thumb_width', $instance['ytchag_thumb_width']);
149
- $ytchag_thumb_columns = apply_filters('ytchag_thumb_columns', $instance['ytchag_thumb_columns']);
150
-
151
- //defaults
152
- $ytchag_video_width = ( $ytchag_video_width ) ? $ytchag_video_width : 250;
153
- $ytchag_thumb_width = ( $ytchag_thumb_width ) ? $ytchag_thumb_width : 85;
154
- $ytchag_thumb_columns = ( $ytchag_thumb_columns ) ? $ytchag_thumb_columns : 0;
155
-
156
- //heights of video and thumbnail
157
- $ytchag_video_heigh = round($ytchag_video_width/(16/9) + 32);
158
- $ytchag_thumb_height = $ytchag_thumb_width*75/100; // 75% 'cos sizes of thumbnail in xml file are 480x360 and 120x90
159
-
160
- if( $ytchag_user ) { // only if user name inserted
161
-
162
- // links
163
- $ytchag_rss_url = "http://gdata.youtube.com/feeds/api/users/" . $ytchag_user . "/uploads";
164
- $ytchag_link_url = "http://www.youtube.com/user/" . $ytchag_user;
165
-
166
-
167
- //RSS Feed
168
-
169
- include_once(ABSPATH . WPINC . '/feed.php');
170
-
171
- $rss = fetch_feed($ytchag_rss_url);
172
- $maxitems = ( $ytchag_maxitems ) ? $ytchag_maxitems : 9;
173
- $items = $rss->get_items(0, $maxitems);
174
-
175
-
176
- if (!empty($items)) {
177
- $i = 0;
178
- $column = 0;
179
- foreach ( $items as $item ) {
180
-
181
- $url = $item->get_permalink();
182
- $youtubeid = $this->youtubeid($url);
183
- $title = $item->get_title();
184
-
185
- if ($enclosure = $item->get_enclosure()){
186
-
187
- //extract thumbnail
188
- //-----------------
189
-
190
- //thumbnail index in xml
191
- $big = 0;
192
- $small = 1;
193
- $size = $small;
194
- if($ytchag_thumb_width > '120'){
195
- $size = $big;
196
- }
197
198
- $allThumbs = $enclosure->get_thumbnails();
199
- foreach ($allThumbs as $index => $allThumb) {
200
- if ($index == $size) {
201
- $thumb = $allThumbs[$index];
202
- }
203
- }
204
}
205
-
206
- //Show me the player: iframe player
207
- if($i == 0) {
208
- //option IFrame embeds using <iframe> tags
209
- //echo '<iframe id="ytcplayer" type="text/html" width="250" height="200" src="http://www.youtube.com/embed/'.$youtubeid.'?&autoplay=0&origin='.site_url().'" frameborder="0"></iframe>';
210
-
211
- //IFrame Player API
212
- ?>
213
- <div id="ytcplayer" class="ytcplayer"></div>
214
- <script>
215
- var tag = document.createElement('script');
216
- tag.src = 'http://www.youtube.com/player_api';
217
- var firstScriptTag = document.getElementsByTagName('script')[0];
218
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
219
- var player;
220
- function onYouTubePlayerAPIReady() {
221
-
222
- player = new YT.Player('ytcplayer', {
223
- width: '<?php echo $ytchag_video_width; ?>',
224
- height: '<?php echo $ytchag_video_heigh; ?>',
225
- videoId: '<?php echo $youtubeid; ?>'
226
- });
227
- }
228
-
229
- function onYouTubePlayerAPIReady2(other) {
230
- player.stopVideo();
231
- player.loadVideoById(other);
232
- }
233
- </script>
234
- <ul class="ytcgallery">
235
-
236
- <?php
237
- } // if player end
238
- $i++;
239
-
240
- $column++;
241
- // list of thumbnail videos
242
- ?>
243
- <li class="ytccell-<?php echo $column; ?>">
244
- <a class="db-yt-thumb" href="javascript: onYouTubePlayerAPIReady2('<?php echo $youtubeid; ?>');" alt="<?php echo $title; ?>" title="<?php echo $title; ?>" style="background-image: url(<?php echo $thumb; ?>); width: <?php echo $ytchag_thumb_width; ?>px; height: <?php echo $ytchag_thumb_height; ?>px">
245
- <div class="db-yt-play"></div>
246
- </a>
247
- </li>
248
-
249
- <?php
250
- if($ytchag_thumb_columns !=0 && $column%$ytchag_thumb_columns === 0){
251
- $column = 0;
252
}
253
- } //foreach end
254
?>
255
- </ul>
256
- <?php
257
- //link to youtube.com gallery
258
- if( $ytchag_link) {
259
- ?>
260
- <a href="<?php echo $ytchag_link_url ?>" class="more"><?php _e('Show more videos»', 'youtube-channel-gallery') ?></a>
261
- <?php
262
- }
263
- }
264
- } else {
265
?>
266
- <p class="empty"><?php _e('There is no video to show.', 'youtube-channel-gallery') ?></p>
267
<?php
268
}
269
}
270
271
- //parse youtube url to extract id
272
- private function youtubeid($url) {
273
- $url_string = parse_url($url, PHP_URL_QUERY);
274
- parse_str($url_string, $args);
275
- return isset($args['v']) ? $args['v'] : false;
276
- }
277
278
- // load css or js
279
- private function register_scripts_and_styles() {
280
- //$this->load_file(PLUGIN_NAME, '/' . PLUGIN_SLUG . '/js/admin.js', true);
281
- $this->load_file('youtube-channel-gallery', '/' . 'youtube-channel-gallery' . '/youtube-channel-gallery.css');
282
- }
283
284
- //register css or js
285
- private function load_file($name, $file_path, $is_script = false) {
286
- $url = WP_PLUGIN_URL . $file_path;
287
- $file = WP_PLUGIN_DIR . $file_path;
288
-
289
- if(file_exists($file)) {
290
- if($is_script) {
291
- wp_register_script($name, $url);
292
- wp_enqueue_script($name);
293
- } else {
294
- wp_register_style($name, $url);
295
- wp_enqueue_style($name);
296
- }
297
- }
298
- } // end load_file
299
300
301
302
303
- } // class YoutubeChannelGallery_Widget
304
305
- // register YoutubeChannelGallery_Widget widget
306
- add_action( 'widgets_init', create_function( '', 'register_widget( "YoutubeChannelGallery_Widget" );' ) );
307
308
?>
5
Description: Show a youtube video and a gallery of thumbnails for a youtube channel.
6
Author: Javier Gómez Pose
7
Author URI: http://www.poselab.com/
8
+ Version: 1.4
9
License: GPL2
10
11
Copyright 2010 Javier Gómez Pose (email : javierpose@gmail.com)
26
27
28
29
+ /**
30
+ * widget class.
31
+ */
32
class YoutubeChannelGallery_Widget extends WP_Widget {
33
34
/**
47
48
// Load JavaScript and stylesheets
49
$this->register_scripts_and_styles();
50
}
51
52
/**
60
if ( ! empty( $title ) )
61
echo $before_title . $title . $after_title;
62
63
+ ytcg_rss_markup($instance);
64
65
echo $after_widget;
66
}
71
public function update( $new_instance, $old_instance ) {
72
$instance = $old_instance;
73
$instance['title'] = strip_tags( $new_instance['title'] );
74
+ $instance['ytcg_user'] = strip_tags( $new_instance['ytcg_user'] );
75
76
+ $instance['ytcg_link'] = $new_instance['ytcg_link'];
77
+ $instance['ytcg_maxitems'] = strip_tags( $new_instance['ytcg_maxitems'] );
78
+ $instance['ytcg_video_width'] = strip_tags( $new_instance['ytcg_video_width'] );
79
+ $instance['ytcg_thumb_width'] = strip_tags( $new_instance['ytcg_thumb_width'] );
80
+ $instance['ytcg_thumb_columns'] = strip_tags( $new_instance['ytcg_thumb_columns'] );
81
+ $instance['ytcg_theme'] = strip_tags( $new_instance['ytcg_theme'] );
82
83
return $instance;
84
}
88
*/
89
public function form( $instance ) {
90
$title = esc_attr($instance['title']);
91
+ $ytcg_user = strip_tags($instance['ytcg_user']);
92
+ $ytcg_link = esc_attr($instance['ytcg_link']);
93
+ $ytcg_maxitems = strip_tags($instance['ytcg_maxitems']);
94
+ $ytcg_video_width = strip_tags($instance['ytcg_video_width']);
95
+ $ytcg_thumb_width = strip_tags($instance['ytcg_thumb_width']);
96
+ $ytcg_thumb_columns = strip_tags($instance['ytcg_thumb_columns']);
97
+ $ytcg_theme = strip_tags($instance['ytcg_theme']);
98
?>
99
<p>
100
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'youtube-channel-gallery' ); ?></label>
102
</p>
103
104
<p>
105
+ <label for="<?php echo $this->get_field_id( 'ytcg_user' ); ?>"><?php _e( 'YouTube user name:', 'youtube-channel-gallery' ); ?></label>
106
+ <input class="widefat" id="<?php echo $this->get_field_id( 'ytcg_user' ); ?>" name="<?php echo $this->get_field_name( 'ytcg_user' ); ?>" type="text" value="<?php echo esc_attr( $ytcg_user ); ?>" />
107
</p>
108
109
<p>
110
+ <input class="checkbox" type="checkbox" <?php checked( (bool) $instance['ytcg_link'], true ); ?> id="<?php echo $this->get_field_id( 'ytcg_link' ); ?>" name="<?php echo $this->get_field_name( 'ytcg_link' ); ?>" />
111
+ <label for="<?php echo $this->get_field_id( 'ytcg_link' ); ?>"><?php _e('Show link to channel:', 'youtube-channel-gallery'); ?></label><br />
112
</p>
113
114
<p>
115
+ <label for="ytcg_maxitems"><?php _e( 'Number of videos to show:', 'youtube-channel-gallery' ); ?></label>
116
+ <input class="widefat" id="<?php echo $this->get_field_id( 'ytcg_maxitems' ); ?>" name="<?php echo $this->get_field_name( 'ytcg_maxitems' ); ?>" type="text" value="<?php echo esc_attr( $ytcg_maxitems ); ?>" />
117
</p>
118
119
<p>
120
+ <label for="ytcg_video_width"><?php _e( 'Video width:', 'youtube-channel-gallery' ); ?></label>
121
+ <input class="widefat" id="<?php echo $this->get_field_id( 'ytcg_video_width' ); ?>" name="<?php echo $this->get_field_name( 'ytcg_video_width' ); ?>" type="text" value="<?php echo esc_attr( $ytcg_video_width ); ?>" />
122
</p>
123
124
<p>
125
+ <label for="ytcg_thumb_width"><?php _e( 'Thumbnail width:', 'youtube-channel-gallery' ); ?></label>
126
+ <input class="widefat" id="<?php echo $this->get_field_id( 'ytcg_thumb_width' ); ?>" name="<?php echo $this->get_field_name( 'ytcg_thumb_width' ); ?>" type="text" value="<?php echo esc_attr( $ytcg_thumb_width ); ?>" />
127
</p>
128
129
<p>
130
+ <label for="ytcg_thumb_columns"><?php _e( 'Thumbnail columns:', 'youtube-channel-gallery' ); ?></label>
131
+ <input class="widefat" id="<?php echo $this->get_field_id( 'ytcg_thumb_columns' ); ?>" name="<?php echo $this->get_field_name( 'ytcg_thumb_columns' ); ?>" type="text" value="<?php echo esc_attr( $ytcg_thumb_columns ); ?>" />
132
+ </p>
133
+
134
+ <p>
135
+ <label for="ytcg_theme"><?php _e( 'Theme:', 'youtube-channel-gallery' ); ?></label>
136
+ <select class="widefat" id="<?php echo $this->get_field_id( 'ytcg_theme' ); ?>" name="<?php echo $this->get_field_name( 'ytcg_theme' ); ?>">
137
+ <option value="dark"<?php selected( $instance['ytcg_theme'], 'dark' ); ?>><?php _e( 'Dark', 'youtube-channel-gallery' ); ?></option>
138
+ <option value="light"<?php selected( $instance['ytcg_theme'], 'light' ); ?>><?php _e( 'Light', 'youtube-channel-gallery' ); ?></option>
139
+ </select>
140
</p>
141
142
<?php
146
/*--------------------------------------------------*/
147
/* Private Functions
148
/*--------------------------------------------------*/
149
150
+
151
+ // load css or js
152
+ private function register_scripts_and_styles() {
153
+ wp_enqueue_script('youtube_player_api', 'http://www.youtube.com/player_api', false, false, true);
154
+ wp_enqueue_script('youtube-channel-gallery', plugins_url('/scripts.js', __FILE__), false, false, true);
155
+ wp_enqueue_style('youtube-channel-gallery', plugins_url('/styles.css', __FILE__), false, false, 'all');
156
+ }
157
+
158
+ } // class YoutubeChannelGallery_Widget
159
+
160
+ // register YoutubeChannelGallery_Widget widget
161
+ add_action( 'widgets_init', create_function( '', 'register_widget( "YoutubeChannelGallery_Widget" );' ) );
162
+
163
+
164
+
165
+ /*--------------------------------------------------*/
166
+ /* Functions
167
+ /*--------------------------------------------------*/
168
+
169
+ function ytcg_rss_markup($instance){
170
+
171
+ //$instance variables
172
+ $ytcg_user = apply_filters('ytcg_user', $instance['ytcg_user']);
173
+ $ytcg_link = apply_filters('ytcg_link', $instance['ytcg_link']);
174
+ $ytcg_maxitems = apply_filters('ytcg_maxitems', $instance['ytcg_maxitems']);
175
+ $ytcg_video_width = apply_filters('ytcg_video_width', $instance['ytcg_video_width']);
176
+ $ytcg_thumb_width = apply_filters('ytcg_thumb_width', $instance['ytcg_thumb_width']);
177
+ $ytcg_thumb_columns = apply_filters('ytcg_thumb_columns', $instance['ytcg_thumb_columns']);
178
+ $ytcg_theme = apply_filters('ytcg_theme', $instance['ytcg_theme']);
179
+
180
+ //defaults
181
+ $ytcg_video_width = ( $ytcg_video_width ) ? $ytcg_video_width : 250;
182
+ $ytcg_thumb_width = ( $ytcg_thumb_width ) ? $ytcg_thumb_width : 85;
183
+ $ytcg_thumb_columns = ( $ytcg_thumb_columns ) ? $ytcg_thumb_columns : 0;
184
+ $ytcg_theme = ( $ytcg_theme ) ? $ytcg_theme : 'dark';
185
+
186
+ //heights of video and thumbnail
187
+ $ytcg_video_heigh = round($ytcg_video_width/(16/9) + 32);
188
+ $ytcg_thumb_height = $ytcg_thumb_width*75/100; // 75% 'cos sizes of thumbnail in xml file are 480x360 and 120x90
189
+
190
+ if( $ytcg_user ) { // only if user name inserted
191
+
192
+ // links
193
+ $ytcg_rss_url = "http://gdata.youtube.com/feeds/api/users/" . $ytcg_user . "/uploads";
194
+ $ytcg_link_url = "http://www.youtube.com/user/" . $ytcg_user;
195
+
196
+
197
+ //RSS Feed
198
+
199
+ include_once(ABSPATH . WPINC . '/feed.php');
200
+
201
+ $rss = fetch_feed($ytcg_rss_url);
202
+ $maxitems = ( $ytcg_maxitems ) ? $ytcg_maxitems : 9;
203
+ $items = $rss->get_items(0, $maxitems);
204
+
205
+
206
+ if (!empty($items)) {
207
+ $i = 0;
208
+ $column = 0;
209
+ foreach ( $items as $item ) {
210
+
211
+ $url = $item->get_permalink();
212
+ $youtubeid = youtubeid($url);
213
+ $title = $item->get_title();
214
+
215
+ if ($enclosure = $item->get_enclosure()){
216
+
217
+ //extract thumbnail
218
+ //-----------------
219
+
220
+ //thumbnail index in xml
221
+ $big = 0;
222
+ $small = 1;
223
+ $size = $small;
224
+ if($ytcg_thumb_width > '120'){
225
+ $size = $big;
226
}
227
+
228
+ $allThumbs = $enclosure->get_thumbnails();
229
+ foreach ($allThumbs as $index => $allThumb) {
230
+ if ($index == $size) {
231
+ $thumb = $allThumbs[$index];
232
+ }
233
}
234
+ }
235
+
236
+ //Show me the player: iframe player
237
+ if($i == 0) {
238
+ //count the plugin occurrences on page
239
+ STATIC $plugincount = 0;
240
+ $plugincount++;
241
+ ?>
242
+ <iframe id="ytcplayer<?php echo $plugincount; ?>" type="text/html" width="250" height="200" src="http://www.youtube.com/embed/<?php echo $youtubeid; ?>?&autoplay=0&theme=<?php echo $ytcg_theme; ?>&enablejsapi=1&origin=<?php echo site_url(); ?>" frameborder="0"></iframe>
243
+ <ul class="ytcgallery">
244
+
245
+ <?php
246
+ } // if player end
247
+ $i++;
248
+
249
+ $column++;
250
+ // list of thumbnail videos
251
?>
252
+ <li class="ytccell-<?php echo $column; ?>">
253
+ <a class="ytcthumb" href="javascript: ytcplayVideo('ytcplayer<?php echo $plugincount; ?>', '<?php echo $youtubeid; ?>');" alt="<?php echo $title; ?>" title="<?php echo $title; ?>" style="background-image: url(<?php echo $thumb; ?>);">
254
+ <div class="ytcplay" style="width: <?php echo $ytcg_thumb_width; ?>px; height: <?php echo $ytcg_thumb_height; ?>px"></div>
255
+ </a>
256
+ </li>
257
+
258
+ <?php
259
+ if($ytcg_thumb_columns !=0 && $column%$ytcg_thumb_columns === 0){
260
+ $column = 0;
261
+ }
262
+ } //foreach end
263
?>
264
+ </ul>
265
<?php
266
+ //link to youtube.com gallery
267
+ if( $ytcg_link) {
268
+ ?>
269
+ <a href="<?php echo $ytcg_link_url ?>" class="more"><?php _e('Show more videos»', 'youtube-channel-gallery') ?></a>
270
+ <?php
271
+ }
272
}
273
+ } else {
274
+ ?>
275
+ <p class="empty"><?php _e('There is no video to show.', 'youtube-channel-gallery') ?></p>
276
+ <?php
277
}
278
+ }
279
280
+ //parse youtube url to extract id
281
+ function youtubeid($url) {
282
+ $url_string = parse_url($url, PHP_URL_QUERY);
283
+ parse_str($url_string, $args);
284
+ return isset($args['v']) ? $args['v'] : false;
285
+ }
286
287
288
289
+ /*--------------------------------------------------*/
290
+ /* Shortcode
291
+ /*--------------------------------------------------*/
292
293
+ function YoutubeChannelGallery_Shortcode($atts) {
294
295
+ extract( shortcode_atts( array(
296
+ 'user' => '',
297
+ 'link' => '0',
298
+ 'maxitems' => '9',
299
+ 'videowidth' => '280',
300
+ 'thumbwidth' => '85',
301
+ 'thumbcolumns' => '0',
302
+ 'theme' => 'dark',
303
+ ), $atts ) );
304
305
+ $instance['ytcg_user'] = $user;
306
+
307
+ $instance['ytcg_link'] = $link;
308
+ $instance['ytcg_maxitems'] = $maxitems;
309
+ $instance['ytcg_video_width'] = $videowidth;
310
+ $instance['ytcg_thumb_width'] = $thumbwidth;
311
+ $instance['ytcg_thumb_columns'] = $thumbcolumns;
312
+ $instance['ytcg_theme'] = $theme;
313
314
315
+ ytcg_rss_markup($instance);
316
+ }
317
+ add_shortcode('Youtube_Channel_Gallery', 'YoutubeChannelGallery_Shortcode');
318
?>