Youtube Channel Gallery - Version 1.7.5

Version Description

  • Corrected order of playlists videos.
  • Enqueue of admin style only in widget page.
  • admin-styles.css tweaks.
  • Update widget form after drag-and-drop (WP save bug).
  • Added scroll to player only if not in view.
Download this release

Release Info

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

Code changes from version 1.7.4.2 to 1.7.5

Files changed (4) hide show
  1. admin-styles.css +3 -3
  2. readme.txt +8 -1
  3. scripts.js +16 -0
  4. youtube-channel-gallery.php +77 -19
admin-styles.css CHANGED
@@ -1,8 +1,8 @@
1
 
2
  /*clearfix*/
3
- .clearfix:before, .clearfix:after { content: ""; display: table; }
4
- .clearfix:after { clear: both; }
5
- .clearfix { zoom: 1; }
6
 
7
 
8
  /*tabs ul*/
1
 
2
  /*clearfix*/
3
+ .ytchgtabs .clearfix:before, .ytchgtabs .clearfix:after { content: ""; display: table; }
4
+ .ytchgtabs .clearfix:after { clear: both; }
5
+ .ytchgtabs .clearfix { zoom: 1; }
6
 
7
 
8
  /*tabs ul*/
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://poselab.com/
4
  Tags: widget, gallery, youtube, channel, user, sidebar, video, youtube playlist, html5, iframe, Youtube channel, youtube videos
5
  Requires at least: 2.8
6
  Tested up to: 3.4.1
7
- Stable tag: 1.7.4.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -118,6 +118,13 @@ If you go to a playlist you will get the following url format: https://www.youtu
118
 
119
  == Changelog ==
120
 
 
 
 
 
 
 
 
121
  = 1.7.4.2 =
122
  * Corrected problem with jQuery.noConflict.
123
  * Corrected link to title.
4
  Tags: widget, gallery, youtube, channel, user, sidebar, video, youtube playlist, html5, iframe, Youtube channel, youtube videos
5
  Requires at least: 2.8
6
  Tested up to: 3.4.1
7
+ Stable tag: 1.7.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
118
 
119
  == Changelog ==
120
 
121
+ = 1.7.5 =
122
+ * Corrected order of playlists videos.
123
+ * Enqueue of admin style only in widget page.
124
+ * admin-styles.css tweaks.
125
+ * Update widget form after drag-and-drop (WP save bug).
126
+ * Added scroll to player only if not in view.
127
+
128
  = 1.7.4.2 =
129
  * Corrected problem with jQuery.noConflict.
130
  * Corrected link to title.
scripts.js CHANGED
@@ -6,6 +6,7 @@ jQuery(document).ready(function($) {
6
  var iframeid = $(this).attr('data-playerid');
7
  var youtubeid = $(this).attr('href').split("youtu.be/")[1];
8
  var quality = $(this).attr('data-quality');
 
9
  ytcplayVideo (iframeid, youtubeid, quality);
10
 
11
  return false;
@@ -28,6 +29,21 @@ jQuery(document).ready(function($) {
28
  }
29
 
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  //Equal Height Blocks in Rows
32
  //http://css-tricks.com/equal-height-blocks-in-rows/
33
  var currentTallest = 0,
6
  var iframeid = $(this).attr('data-playerid');
7
  var youtubeid = $(this).attr('href').split("youtu.be/")[1];
8
  var quality = $(this).attr('data-quality');
9
+ checkIfInView($('#' + iframeid));
10
  ytcplayVideo (iframeid, youtubeid, quality);
11
 
12
  return false;
29
  }
30
 
31
 
32
+ //Scroll to element only if not in view - jQuery
33
+ //http://stackoverflow.com/a/10130707/1504078
34
+ function checkIfInView(element){
35
+ if($(element).position()){
36
+ if($(element).position().top < $(window).scrollTop()){
37
+ //scroll up
38
+ $('html,body').animate({scrollTop:$(element).position().top - 10}, 500);
39
+ }
40
+ else if($(element).position().top + $(element).height() > $(window).scrollTop() + (window.innerHeight || document.documentElement.clientHeight)){
41
+ //scroll down
42
+ $('html,body').animate({scrollTop:$(element).position().top - (window.innerHeight || document.documentElement.clientHeight) + $(element).height() + 10}, 500);}
43
+ }
44
+ }
45
+
46
+
47
  //Equal Height Blocks in Rows
48
  //http://css-tricks.com/equal-height-blocks-in-rows/
49
  var currentTallest = 0,
youtube-channel-gallery.php CHANGED
@@ -5,10 +5,10 @@
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.7.4.2
9
  License: GPL2
10
 
11
- Copyright 2010 Javier Gómez Pose (email : javierpose@gmail.com)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License, version 2, as
@@ -41,7 +41,7 @@
41
  add_shortcode('Youtube_Channel_Gallery', array($this, 'YoutubeChannelGallery_Shortcode'));
42
 
43
  //load admin scripts
44
- add_action('admin_print_scripts', array($this, 'register_admin_scripts_and_styles'));
45
 
46
  parent::__construct(
47
  'youtubechannelgallery_widget', // Base ID
@@ -156,10 +156,42 @@
156
  <script type="text/javascript">
157
  jQuery(document).ready(function($) {
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  //tabs
160
  //---------------
161
- $('#tabs-<?php echo $this->id; ?> > div').hide();
162
- $('#tabs-<?php echo $this->id; ?>-1').show();
163
  $('#tabs-<?php echo $this->id; ?> ul li:first').addClass('active');
164
 
165
  $('#tabs-<?php echo $this->id; ?> ul li a').click(function(){
@@ -192,10 +224,10 @@
192
 
193
 
194
  function slide_title_description ( action ){
195
- if(action == 'slideDown'){
196
  $('#tabs-<?php echo $this->id; ?>-3 .ytchg-title-and-description').slideDown('fast');
197
  $('#tabs-<?php echo $this->id; ?>-3 fieldset.ytchg-field-tit-desc').addClass('ytchg-fieldborder active');
198
- } else if(action == 'slideUp'){
199
  $('#tabs-<?php echo $this->id; ?>-3 .ytchg-title-and-description').slideUp('fast');
200
  $('#tabs-<?php echo $this->id; ?>-3 fieldset.ytchg-field-tit-desc').removeClass('ytchg-fieldborder active');
201
  }
@@ -223,10 +255,10 @@
223
  });
224
 
225
  function changeFeedTitle (){
226
- if($(feedselect + ' option:selected').val() == 'user'){
227
  $(userLabel).text('<?php _e( 'YouTube user id:', 'youtube-channel-gallery' ); ?>');
228
  }
229
- if($(feedselect + ' option:selected').val() == 'userfav'){
230
  $(userLabel).text('<?php _e( 'YouTube user id:', 'youtube-channel-gallery' ); ?>');
231
  }
232
  if($(feedselect + ' option:selected').val() == 'playlist'){
@@ -240,8 +272,6 @@
240
  <?php //http://wordpress.stackexchange.com/questions/5515/update-widget-form-after-drag-and-drop-wp-save-bug?>
241
 
242
  <div id="tabs-<?php echo $this->id; ?>" class="ytchgtabs">
243
-
244
-
245
  <ul class="ytchgtabs-tabs">
246
  <li><a href="#tabs-<?php echo $this->id; ?>-1"><?php _e( 'Feed', 'youtube-channel-gallery' ); ?></a></li>
247
  <li><a href="#tabs-<?php echo $this->id; ?>-2"><?php _e( 'Player', 'youtube-channel-gallery' ); ?></a></li>
@@ -556,7 +586,8 @@
556
  $errorMesagge = __('You must insert a valid YouTube user id.', 'youtube-channel-gallery');
557
  }
558
  if($ytchag_feed == 'playlist'){
559
- $ytchag_rss_url = $youtube_feed_url . '/playlists/' . $ytchag_user . '?alt=rss&v=2&orderby=published&rel=0';
 
560
  $ytchag_link_url = 'http://www.youtube.com/playlist?list=' . $ytchag_user;
561
  $errorMesagge = __('You must insert a valid playlist id.', 'youtube-channel-gallery');
562
  }
@@ -566,13 +597,32 @@
566
 
567
  $rss = fetch_feed($ytchag_rss_url);
568
 
569
-
570
  // check if no correct user name
571
  if (!is_wp_error( $rss ) ) {
572
 
 
573
  $maxitems = ( $ytchag_maxitems ) ? $ytchag_maxitems : 9;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
574
  $items = $rss->get_items(0, $maxitems);
575
-
576
 
577
  if (!empty($items)) {
578
  $i = 0;
@@ -595,6 +645,16 @@
595
  $media_group = $item->get_item_tags('http://search.yahoo.com/mrss/', 'group');
596
  $media_content = $media_group[0]['child']['http://search.yahoo.com/mrss/']['thumbnail'];
597
 
 
 
 
 
 
 
 
 
 
 
598
  //Check the thumbnail width
599
  $thumbW = array();
600
  foreach ($media_content as $index => $media_contentw) {
@@ -610,8 +670,6 @@
610
  $thumb = $media_content[$thumbcorrectWIndex]['attribs']['']['url'];
611
 
612
 
613
-
614
-
615
  //rows and columns control
616
 
617
  $column++;
@@ -647,7 +705,6 @@
647
  $plugincount++;
648
 
649
  $content = '<iframe id="ytcplayer' . $plugincount . '" class="ytcplayer" allowfullscreen width="' . $ytchag_video_width . '" height="' . $ytchag_video_heigh . '" src="http://www.youtube.com/embed/' . $youtubeid . '?version=3' . $ytchag_theme . $ytchag_color . $ytchag_autoplay . $ytchag_rel . $ytchag_showinfo .'&enablejsapi=1" frameborder="0"></iframe>';
650
-
651
  $content.= '<ul class="ytchagallery ytccf' . $tableclass . $title_and_description_alignment_class . $columnnumber . '">';
652
 
653
  } // if player end
@@ -766,7 +823,9 @@
766
 
767
 
768
  public function register_admin_scripts_and_styles($hook) {
769
- wp_enqueue_style('youtube-channel-gallery', plugins_url('/admin-styles.css', __FILE__), false, false, 'all');
 
 
770
  }
771
 
772
  /*--------------------------------------------------*/
@@ -851,5 +910,4 @@
851
  // register YoutubeChannelGallery_Widget widget
852
  add_action( 'widgets_init', create_function( '', 'register_widget( "YoutubeChannelGallery_Widget" );' ) );
853
 
854
-
855
  ?>
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.7.5
9
  License: GPL2
10
 
11
+ Copyright 2013 Javier Gómez Pose (email : javierpose@gmail.com)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License, version 2, as
41
  add_shortcode('Youtube_Channel_Gallery', array($this, 'YoutubeChannelGallery_Shortcode'));
42
 
43
  //load admin scripts
44
+ add_action('admin_enqueue_scripts', array($this, 'register_admin_scripts_and_styles'));
45
 
46
  parent::__construct(
47
  'youtubechannelgallery_widget', // Base ID
156
  <script type="text/javascript">
157
  jQuery(document).ready(function($) {
158
 
159
+ //Update widget form after drag-and-drop (WP save bug)
160
+ //http://wordpress.stackexchange.com/a/37707/16964
161
+ $('#widgets-right').ajaxComplete(function(event, XMLHttpRequest, ajaxOptions){
162
+
163
+ // determine which ajax request is this (we're after "save-widget")
164
+ var request = {}, pairs = ajaxOptions.data.split('&'), i, split, widget;
165
+
166
+ for(i in pairs){
167
+ split = pairs[i].split('=');
168
+ request[decodeURIComponent(split[0])] = decodeURIComponent(split[1]);
169
+ }
170
+
171
+ // only proceed if this was a widget-save request
172
+ if(request.action && (request.action === 'save-widget')){
173
+
174
+ // locate the widget block
175
+ widget = $('input.widget-id[value="' + request['widget-id'] + '"]').parents('.widget');
176
+
177
+ // trigger manual save, if this was the save request
178
+ // and if we didn't get the form html response (the wp bug)
179
+ if(!XMLHttpRequest.responseText)
180
+ wpWidgets.save(widget, 0, 1, 0);
181
+
182
+ // we got an response, this could be either our request above,
183
+ // or a correct widget-save call, so fire an event on which we can hook our js
184
+ else
185
+ $(document).trigger('saved_widget', widget);
186
+
187
+ }
188
+
189
+ });
190
+
191
  //tabs
192
  //---------------
193
+ $('#tabs-<?php echo $this->id; ?> > div:not(:first)').hide();
194
+ //$('#tabs-<?php echo $this->id; ?>-1').show();
195
  $('#tabs-<?php echo $this->id; ?> ul li:first').addClass('active');
196
 
197
  $('#tabs-<?php echo $this->id; ?> ul li a').click(function(){
224
 
225
 
226
  function slide_title_description ( action ){
227
+ if(action === 'slideDown'){
228
  $('#tabs-<?php echo $this->id; ?>-3 .ytchg-title-and-description').slideDown('fast');
229
  $('#tabs-<?php echo $this->id; ?>-3 fieldset.ytchg-field-tit-desc').addClass('ytchg-fieldborder active');
230
+ } else if(action === 'slideUp'){
231
  $('#tabs-<?php echo $this->id; ?>-3 .ytchg-title-and-description').slideUp('fast');
232
  $('#tabs-<?php echo $this->id; ?>-3 fieldset.ytchg-field-tit-desc').removeClass('ytchg-fieldborder active');
233
  }
255
  });
256
 
257
  function changeFeedTitle (){
258
+ if($(feedselect + ' option:selected').val() === 'user'){
259
  $(userLabel).text('<?php _e( 'YouTube user id:', 'youtube-channel-gallery' ); ?>');
260
  }
261
+ if($(feedselect + ' option:selected').val() === 'userfav'){
262
  $(userLabel).text('<?php _e( 'YouTube user id:', 'youtube-channel-gallery' ); ?>');
263
  }
264
  if($(feedselect + ' option:selected').val() == 'playlist'){
272
  <?php //http://wordpress.stackexchange.com/questions/5515/update-widget-form-after-drag-and-drop-wp-save-bug?>
273
 
274
  <div id="tabs-<?php echo $this->id; ?>" class="ytchgtabs">
 
 
275
  <ul class="ytchgtabs-tabs">
276
  <li><a href="#tabs-<?php echo $this->id; ?>-1"><?php _e( 'Feed', 'youtube-channel-gallery' ); ?></a></li>
277
  <li><a href="#tabs-<?php echo $this->id; ?>-2"><?php _e( 'Player', 'youtube-channel-gallery' ); ?></a></li>
586
  $errorMesagge = __('You must insert a valid YouTube user id.', 'youtube-channel-gallery');
587
  }
588
  if($ytchag_feed == 'playlist'){
589
+ $ytchag_rss_url = $youtube_feed_url . '/playlists/' . $ytchag_user . '?alt=atom&v=2&orderby=published&prettyprint=true';
590
+ //print_r($ytchag_rss_url . '<br>');
591
  $ytchag_link_url = 'http://www.youtube.com/playlist?list=' . $ytchag_user;
592
  $errorMesagge = __('You must insert a valid playlist id.', 'youtube-channel-gallery');
593
  }
597
 
598
  $rss = fetch_feed($ytchag_rss_url);
599
 
 
600
  // check if no correct user name
601
  if (!is_wp_error( $rss ) ) {
602
 
603
+ //items requested by the user
604
  $maxitems = ( $ytchag_maxitems ) ? $ytchag_maxitems : 9;
605
+
606
+ //get totalResultsData from playlist rss to order correctly videos
607
+ if($ytchag_feed == 'playlist'){
608
+ //openSearch:totalResults
609
+ $totalResults = $rss->get_feed_tags('http://a9.com/-/spec/opensearch/1.1/', 'totalResults');
610
+ $totalResultsData = $totalResults[0]['data'];
611
+ //print_r($totalResultsData . '<br>');
612
+
613
+ //get rss playlist again with the last videos. YouTube does not load in the first request, even if the orderby parameter is set.
614
+ $startindex = $totalResultsData - $maxitems + 1;
615
+ //print_r($startindex . '<br>');
616
+ $ytchag_rss_url = $ytchag_rss_url . '&start-index=' . $startindex . '&max-results=' . $maxitems;
617
+ $rss = fetch_feed($ytchag_rss_url);
618
+
619
+ //to get the appropriate order of items
620
+ $rss->enable_order_by_date(false);
621
+ //print_r($ytchag_rss_url . '<br>');
622
+ }
623
+
624
  $items = $rss->get_items(0, $maxitems);
625
+
626
 
627
  if (!empty($items)) {
628
  $i = 0;
645
  $media_group = $item->get_item_tags('http://search.yahoo.com/mrss/', 'group');
646
  $media_content = $media_group[0]['child']['http://search.yahoo.com/mrss/']['thumbnail'];
647
 
648
+ /* to check order
649
+ $episode = $item->get_item_tags('http://gdata.youtube.com/schemas/2007', 'episode'); //yt
650
+ $episodecontent = $episode[0]['attribs']['']['number'];
651
+ if(!$episode){
652
+ $episode = $item->get_item_tags('http://gdata.youtube.com/schemas/2007', 'position'); //yt
653
+ $episodecontent = $episode[0]['data'];
654
+ }
655
+ print_r($episodecontent . '-');
656
+ */
657
+
658
  //Check the thumbnail width
659
  $thumbW = array();
660
  foreach ($media_content as $index => $media_contentw) {
670
  $thumb = $media_content[$thumbcorrectWIndex]['attribs']['']['url'];
671
 
672
 
 
 
673
  //rows and columns control
674
 
675
  $column++;
705
  $plugincount++;
706
 
707
  $content = '<iframe id="ytcplayer' . $plugincount . '" class="ytcplayer" allowfullscreen width="' . $ytchag_video_width . '" height="' . $ytchag_video_heigh . '" src="http://www.youtube.com/embed/' . $youtubeid . '?version=3' . $ytchag_theme . $ytchag_color . $ytchag_autoplay . $ytchag_rel . $ytchag_showinfo .'&enablejsapi=1" frameborder="0"></iframe>';
 
708
  $content.= '<ul class="ytchagallery ytccf' . $tableclass . $title_and_description_alignment_class . $columnnumber . '">';
709
 
710
  } // if player end
823
 
824
 
825
  public function register_admin_scripts_and_styles($hook) {
826
+ if( 'widgets.php' != $hook )
827
+ return;
828
+ wp_enqueue_style('youtube-channel-gallery', plugins_url('/admin-styles.css', __FILE__));
829
  }
830
 
831
  /*--------------------------------------------------*/
910
  // register YoutubeChannelGallery_Widget widget
911
  add_action( 'widgets_init', create_function( '', 'register_widget( "YoutubeChannelGallery_Widget" );' ) );
912
 
 
913
  ?>