PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.3.2
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.3.2
2.9.1 2.9.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 2.0.0 2.1.0 2.2.0 2.3.2 2.3.3 2.3.5 2.3.6 2.3.8 2.3.9 2.4.3 All 37 releases
← All changes | includes/youtube-api.php +16 -80 2.3.92.3.2 View file →
@@ -100,12 +100,8 @@
100 100
101 101 // Get playlist id from the channel
102 102 $playlist_id = $this->get_playlist_id( $params );
103 103
104 - if ( is_object( $playlist_id ) && isset( $playlist_id->error ) ) {
105 - return $playlist_id;
106 - }
107 -
108 104 if ( empty( $playlist_id ) ) {
109 105 return $this->get_error( __( 'No videos found matching your query.', 'automatic-youtube-gallery' ) );
110 106 }
111 107
@@ -122,12 +118,8 @@
122 118 // Get playlist id from the channel
123 119 $params['forUsername'] = $this->parse_youtube_id_from_url( $params['src'], 'username' );
124 120 $playlist_id = $this->get_playlist_id( $params );
125 121
126 - if ( is_object( $playlist_id ) && isset( $playlist_id->error ) ) {
127 - return $playlist_id;
128 - }
129 -
130 122 if ( empty( $playlist_id ) ) {
131 123 return $this->get_error( __( 'No videos found matching your query.', 'automatic-youtube-gallery' ) );
132 124 }
133 125
@@ -156,16 +148,14 @@
156 148 if ( empty( $params['src'] ) ) {
157 149 return $this->get_error( __( 'YouTube Channel ID (or) or a YouTube Video URL from the Channel is required.', 'automatic-youtube-gallery' ) );
158 150 }
159 151
160 - $params['channelId'] = $this->get_channel_id( $params );
152 + $response = new stdClass();
153 + $response->id = $this->get_channel_id( $params );
161 154
162 - if ( empty( $params['channelId'] ) ) {
155 + if ( empty( $response->id ) ) {
163 156 return $this->get_error( __( 'Invalid YouTube Channel ID.', 'automatic-youtube-gallery' ) );
164 157 }
165 -
166 - // Get live video using the channel id
167 - $response = $this->request_api_live_video( $params );
168 158 break;
169 159
170 160 default: // video
171 161 if ( empty( $params['src'] ) ) {
@@ -473,50 +463,8 @@
473 463 return $response;
474 464 }
475 465
476 466 /**
477 - * Get live video using search API.
478 - *
479 - * @since 2.3.7
480 - * @access private
481 - * @param array $params Array of query params.
482 - * @return mixed
483 - */
484 - private function request_api_live_video( $params = array() ) {
485 - $api_url = $this->get_api_url( 'search.list' );
486 -
487 - $params['type'] = 'video'; // Overrides user defined type value 'livestream'
488 -
489 - $api_params = $this->safe_merge_params(
490 - array(
491 - 'type' => 'video',
492 - 'eventType' => 'live',
493 - 'part' => 'snippet',
494 - 'channelId' => '',
495 - 'cache' => 0
496 - ),
497 - $params
498 - );
499 -
500 - $api_response = $this->request_api( $api_url, $api_params, 'live' );
501 - if ( isset( $api_response->error ) ) {
502 - return $api_response;
503 - }
504 -
505 - $videos = $this->parse_videos( $api_response );
506 - if ( isset( $videos->error ) ) {
507 - $livestream_settings = get_option( 'ayg_livestream_settings' );
508 - return $this->get_error( '<div class="ayg-livestream-fallback-message">' . $livestream_settings['fallback_message'] . '</div>' );
509 - }
510 -
511 - // Process output
512 - $response = new stdClass();
513 - $response->videos = $videos;
514 -
515 - return $response;
516 - }
517 -
518 - /**
519 467 * Get details of the given video ID.
520 468 *
521 469 * @since 1.0.0
522 470 * @access private
@@ -703,38 +651,26 @@
703 651 return $this->get_error( $message );
704 652 }
705 653
706 654 // Store in cache (transients)
707 - $can_store_in_transients = false;
655 + if ( ! $this->is_development_mode && 'videos' == $context && $cache_duration > 0 ) {
656 + if ( isset( $data->items ) && is_array( $data->items ) && count( $data->items ) > 0 ) {
657 + set_transient( $cache_key, $data, $cache_duration );
708 658
709 - if ( ! $this->is_development_mode && $cache_duration > 0 ) {
710 - if ( 'videos' == $context ) {
711 - if ( isset( $data->items ) && is_array( $data->items ) && count( $data->items ) > 0 ) {
712 - $can_store_in_transients = true;
659 + // Get the current list of transients
660 + $cache_keys = get_option( 'ayg_transient_keys', array() );
661 + if ( ! is_array( $cache_keys ) ) {
662 + $cache_keys = (array) $cache_keys;
713 663 }
714 - }
715 664
716 - if ( 'live' == $context ) {
717 - $can_store_in_transients = true;
718 - }
719 - }
665 + // Append our new one
666 + if ( ! in_array( $cache_key, $cache_keys ) ) {
667 + $cache_keys[] = $cache_key;
668 + }
720 669
721 - if ( $can_store_in_transients ) {
722 - set_transient( $cache_key, $data, $cache_duration );
723 -
724 - // Get the current list of transients
725 - $cache_keys = get_option( 'ayg_transient_keys', array() );
726 - if ( ! is_array( $cache_keys ) ) {
727 - $cache_keys = (array) $cache_keys;
670 + // Save it to the DB
671 + update_option( 'ayg_transient_keys', $cache_keys );
728 672 }
729 -
730 - // Append our new one
731 - if ( ! in_array( $cache_key, $cache_keys ) ) {
732 - $cache_keys[] = $cache_key;
733 - }
734 -
735 - // Save it to the DB
736 - update_option( 'ayg_transient_keys', $cache_keys );
737 673 }
738 674
739 675 // Store videos in our custom database table "{$wpdb->prefix}ayg_videos"
740 676 ayg_db_store_videos( $data );