PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.3.8
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.3.8
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 | public/public.php +65 -25 1.6.12.3.8 View file →
@@ -27,9 +27,9 @@
27 27 * @since 1.0.0
28 28 */
29 29 public function __construct() {
30 30 add_shortcode( 'automatic_youtube_gallery', array( $this, 'shortcode_automatic_youtube_gallery' ) );
31 - }
31 + }
32 32
33 33 /**
34 34 * Enqueue styles for the public-facing side of the site.
35 35 *
@@ -37,9 +37,9 @@
37 37 */
38 38 public function register_styles() {
39 39 wp_register_style(
40 40 AYG_SLUG . '-public',
41 - AYG_URL . 'public/assets/css/public.css',
41 + AYG_URL . 'public/assets/css/public.min.css',
42 42 array(),
43 43 AYG_VERSION,
44 44 'all'
45 45 );
@@ -50,28 +50,50 @@
50 50 *
51 51 * @since 1.0.0
52 52 */
53 53 public function register_scripts() {
54 + $player_settings = get_option( 'ayg_player_settings' );
55 + $privacy_settings = get_option( 'ayg_privacy_settings' );
56 +
54 57 wp_register_script(
55 58 AYG_SLUG . '-public',
56 - AYG_URL . 'public/assets/js/public.js',
59 + AYG_URL . 'public/assets/js/public.min.js',
57 60 array( 'jquery' ),
58 61 AYG_VERSION,
59 - false
62 + array( 'strategy' => 'defer' )
60 63 );
61 64
62 - $top_offset = apply_filters( 'ayg_gallery_scrolltop_offset', 10 );
63 -
64 65 $script_args = array(
65 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
66 - 'i18n' => array(
67 - 'show_more' => __( 'Show More', 'automatic-youtube-gallery' ),
68 - 'show_less' => __( 'Show Less', 'automatic-youtube-gallery' )
69 - ),
70 - 'top_offset' => $top_offset,
71 - 'players' => array()
66 + 'current_url' => get_permalink(),
67 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
68 + 'ajax_nonce' => wp_create_nonce( 'ayg_ajax_nonce' ),
69 + 'gallery_index' => 0,
70 + 'gallery_id' => get_query_var( 'ayg_gallery_id' ),
71 + 'video_id' => get_query_var( 'ayg_video_id' ),
72 + 'active_player_id' => '',
73 + 'privacy_enhanced_mode' => isset( $player_settings['privacy_enhanced_mode'] ) ? (int) $player_settings['privacy_enhanced_mode'] : 0,
74 + 'origin' => '',
75 + 'cookie_consent' => 0,
76 + 'top_offset' => apply_filters( 'ayg_gallery_scrolltop_offset', 10 ),
77 + 'i18n' => array(
78 + 'show_more' => '[+] ' . __( 'Show More', 'automatic-youtube-gallery' ),
79 + 'show_less' => '[-] ' . __( 'Show Less', 'automatic-youtube-gallery' )
80 + )
72 81 );
73 82
83 + if ( isset( $player_settings['origin'] ) && ! empty( $player_settings['origin'] ) ) {
84 + $url_parts = parse_url( site_url() );
85 + $script_args['origin'] = $url_parts['scheme'] . '://' . $url_parts['host'];
86 + }
87 +
88 + if ( ! isset( $_COOKIE['ayg_gdpr_consent'] ) ) {
89 + if ( ! empty( $privacy_settings['cookie_consent'] ) && ! empty( $privacy_settings['consent_message'] ) && ! empty( $privacy_settings['button_label'] ) ) {
90 + $script_args['cookie_consent'] = 1;
91 + $script_args['consent_message'] = wp_kses_post( trim( $privacy_settings['consent_message'] ) );
92 + $script_args['button_label'] = esc_html( $privacy_settings['button_label'] );
93 + }
94 + }
95 +
74 96 wp_localize_script(
75 97 AYG_SLUG . '-public',
76 98 'ayg_public',
77 99 $script_args
@@ -96,13 +118,13 @@
96 118 /**
97 119 * Process the shortcode [automatic_youtube_gallery].
98 120 *
99 121 * @since 1.0.0
100 - * @param array $atts An associative array of attributes.
101 - * @return string Shortcode HTML output.
122 + * @param array $attributes An associative array of attributes.
123 + * @return string Shortcode HTML output.
102 124 */
103 - public function shortcode_automatic_youtube_gallery( $atts ) {
104 - return ayg_build_gallery( $atts );
125 + public function shortcode_automatic_youtube_gallery( $attributes ) {
126 + return ayg_build_gallery( $attributes );
105 127 }
106 128
107 129 /**
108 130 * Load more videos.
@@ -110,26 +132,26 @@
110 132 * @since 1.0.0
111 133 */
112 134 public function ajax_callback_load_more_videos() {
113 135 // Security check
114 - check_ajax_referer( 'ayg_pagination_nonce', 'nonce' );
136 + check_ajax_referer( 'ayg_ajax_nonce', 'security' );
115 137
116 138 // Proceed safe
117 139 $json = array();
118 - $attributes = $_POST;
119 - $source_type = sanitize_text_field( $attributes['type'] );
140 + $attributes = array_map( 'sanitize_text_field', $_POST );
141 + $source_type = $attributes['type'];
120 142
121 143 $api_params = array(
122 144 'type' => $source_type,
123 - 'id' => sanitize_text_field( $attributes['id'] ),
124 - 'order' => sanitize_text_field( $attributes['order'] ), // works only when type=search
145 + 'src' => $attributes['src'],
146 + 'order' => $attributes['order'], // works only when type=search
125 147 'maxResults' => (int) $attributes['per_page'],
126 148 'cache' => (int) $attributes['cache'],
127 - 'pageToken' => sanitize_text_field( $attributes['pageToken'] )
149 + 'pageToken' => $attributes['pageToken']
128 150 );
129 151
130 152 $youtube_api = new AYG_YouTube_API();
131 - $response = $youtube_api->get_videos( $api_params );
153 + $response = $youtube_api->query( $api_params );
132 154
133 155 if ( ! isset( $response->error ) ) {
134 156 if ( isset( $response->page_info ) ) {
135 157 $json = $response->page_info;
@@ -138,9 +160,13 @@
138 160 if ( isset( $response->videos ) ) {
139 161 $videos = $response->videos;
140 162
141 163 ob_start();
142 - the_ayg_gallery( $videos, $attributes );
164 + foreach ( $videos as $index => $video ) {
165 + echo'<div class="ayg-item ayg-item-' . $video->id . ' ayg-col ayg-col-' . (int) $attributes['columns'] . '">';
166 + the_ayg_gallery_thumbnail( $video, $attributes );
167 + echo '</div>';
168 + }
143 169 $json['html'] = ob_get_clean();
144 170 }
145 171
146 172 wp_send_json_success( $json );
@@ -147,8 +173,22 @@
147 173 } else {
148 174 $json['message'] = $response->error_message;
149 175 wp_send_json_error( $json );
150 176 }
177 + }
178 +
179 + /**
180 + * Set cookie for accepting the privacy consent.
181 + *
182 + * @since 2.0.0
183 + */
184 + public function set_gdpr_cookie() {
185 + // Security check
186 + check_ajax_referer( 'ayg_ajax_nonce', 'security' );
187 +
188 + // Proceed safe
189 + setcookie( 'ayg_gdpr_consent', 1, time() + ( 30 * 24 * 60 * 60 ), COOKIEPATH, COOKIE_DOMAIN );
190 + wp_send_json_success();
151 191 }
152 192
153 193 /**
154 194 * [SMUSH] Skip YouTube iframes from lazy loading.