PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.6.4
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.6.4
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 +169 -34 1.4.0 → 2.6.4 View file →
@@ -26,10 +26,10 @@
26 26 *
27 27 * @since 1.0.0
28 28 */
29 29 public function __construct() {
30 - add_shortcode( "automatic_youtube_gallery", array( $this, "shortcode_automatic_youtube_gallery" ) );
31 - }
30 + add_shortcode( 'automatic_youtube_gallery', array( $this, 'shortcode_automatic_youtube_gallery' ) );
31 + }
32 32
33 33 /**
34 34 * Enqueue styles for the public-facing side of the site.
35 35 *
@@ -35,12 +35,27 @@
35 35 *
36 36 * @since 1.0.0
37 37 */
38 38 public function register_styles() {
39 + $player_settings = get_option( 'ayg_player_settings' );
40 +
41 + $deps = array();
42 + if ( isset( $player_settings['player_type'] ) && 'custom' == $player_settings['player_type'] ) {
43 + $deps[] = AYG_SLUG . '-plyr';
44 + }
45 +
39 46 wp_register_style(
47 + AYG_SLUG . '-plyr',
48 + AYG_URL . 'vendor/plyr/plyr.css',
49 + array(),
50 + '3.7.8',
51 + 'all'
52 + );
53 +
54 + wp_register_style(
40 55 AYG_SLUG . '-public',
41 - AYG_URL . 'public/assets/css/public.css',
42 - array(),
56 + AYG_URL . 'public/assets/css/public.min.css',
57 + $deps,
43 58 AYG_VERSION,
44 59 'all'
45 60 );
46 61 }
@@ -50,46 +65,117 @@
50 65 *
51 66 * @since 1.0.0
52 67 */
53 68 public function register_scripts() {
69 + $strings_settings = get_option( 'ayg_strings_settings' );
70 + $gallery_settings = get_option( 'ayg_gallery_settings' );
71 + $player_settings = get_option( 'ayg_player_settings' );
72 + $privacy_settings = get_option( 'ayg_privacy_settings' );
73 +
74 + $deps = array( 'jquery' );
75 + if ( isset( $player_settings['player_type'] ) && 'custom' == $player_settings['player_type'] ) {
76 + $deps[] = AYG_SLUG . '-plyr';
77 + }
78 +
54 79 wp_register_script(
80 + AYG_SLUG . '-plyr',
81 + AYG_URL . 'vendor/plyr/plyr.polyfilled.js',
82 + array(),
83 + '3.7.8',
84 + array( 'strategy' => 'defer' )
85 + );
86 +
87 + wp_register_script(
55 88 AYG_SLUG . '-public',
56 - AYG_URL . 'public/assets/js/public.js',
57 - array( 'jquery' ),
89 + AYG_URL . 'public/assets/js/public.min.js',
90 + $deps,
58 91 AYG_VERSION,
59 - false
92 + array( 'strategy' => 'defer' )
60 93 );
61 94
95 + $scroll_top_offset = ( isset( $gallery_settings['scroll_top_offset'] ) && ! empty( $gallery_settings['scroll_top_offset'] ) ) ? (int) $gallery_settings['scroll_top_offset'] : 10;
96 + $scroll_top_offset = apply_filters( 'ayg_gallery_scrolltop_offset', $scroll_top_offset ); // Backward compatibility to 2.4.3
97 + $scroll_top_offset = apply_filters( 'ayg_gallery_scroll_top_offset', $scroll_top_offset );
98 +
99 + $show_more_label = ! empty( $strings_settings['show_more_label'] ) ? sanitize_text_field( $strings_settings['show_more_label'] ) : __( 'Show More', 'automatic-youtube-gallery' );
100 + $show_less_label = ! empty( $strings_settings['show_less_label'] ) ? sanitize_text_field( $strings_settings['show_less_label'] ) : __( 'Show Less', 'automatic-youtube-gallery' );
101 +
102 + $script_args = array(
103 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
104 + 'ajax_nonce' => wp_create_nonce( 'ayg_ajax_nonce' ),
105 + 'current_page_url' => get_permalink(),
106 + 'current_gallery_id' => get_query_var( 'ayg_gallery_id' ),
107 + 'player_type' => isset( $player_settings['player_type'] ) ? sanitize_text_field( $player_settings['player_type'] ) : 'youtube',
108 + 'player_color' => isset( $player_settings['player_color'] ) ? sanitize_text_field( $player_settings['player_color'] ) : '#00b3ff',
109 + 'privacy_enhanced_mode' => isset( $player_settings['privacy_enhanced_mode'] ) ? (int) $player_settings['privacy_enhanced_mode'] : 0,
110 + 'origin' => '',
111 + 'cookieconsent' => 0,
112 + 'top_offset' => $scroll_top_offset,
113 + 'i18n' => array(
114 + 'show_more' => $show_more_label,
115 + 'show_less' => $show_less_label
116 + )
117 + );
118 +
119 + if ( isset( $player_settings['origin'] ) && ! empty( $player_settings['origin'] ) ) {
120 + $url_parts = parse_url( site_url() );
121 + $script_args['origin'] = $url_parts['scheme'] . '://' . $url_parts['host'];
122 + }
123 +
124 + if ( ! isset( $_COOKIE['ayg_gdpr_consent'] ) ) {
125 + if ( ! empty( $privacy_settings['cookie_consent'] ) && ! empty( $privacy_settings['consent_message'] ) && ! empty( $privacy_settings['button_label'] ) ) {
126 + $script_args['cookieconsent'] = 1;
127 + $script_args['cookieconsent_message'] = wp_kses_post( trim( $privacy_settings['consent_message'] ) );
128 + $script_args['cookieconsent_button_label'] = esc_html( $privacy_settings['button_label'] );
129 + }
130 + }
131 +
62 132 wp_localize_script(
63 133 AYG_SLUG . '-public',
64 - 'ayg_public',
65 - array(
66 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
67 - 'i18n' => array(
68 - 'show_more' => __( 'Show More', 'automatic-youtube-gallery' ),
69 - 'show_less' => __( 'Show Less', 'automatic-youtube-gallery' )
70 - ),
71 - 'players' => array()
72 - )
134 + 'ayg_config',
135 + $script_args
73 136 );
137 +
138 + wp_register_script(
139 + AYG_SLUG . '-theme-classic',
140 + AYG_URL . 'public/assets/js/theme-classic.min.js',
141 + array( 'jquery' ),
142 + AYG_VERSION,
143 + array( 'strategy' => 'defer' )
144 + );
74 145 }
75 146
76 147 /**
77 - * Process the shortcode [automatic_youtube_gallery].
148 + * Enqueue Gutenberg block assets for backend editor.
78 149 *
79 - * @since 1.0.0
80 - * @param array $atts An associative array of attributes.
81 - * @return string Shortcode HTML output.
150 + * @since 1.6.1
82 151 */
83 - public function shortcode_automatic_youtube_gallery( $atts ) {
84 - // Enqueue dependencies
152 + public function enqueue_block_editor_assets() {
153 + // Styles
154 + $this->register_styles();
85 155 wp_enqueue_style( AYG_SLUG . '-public' );
156 +
157 + // Scripts
158 + $this->register_scripts();
159 +
86 160 wp_enqueue_script( AYG_SLUG . '-public' );
161 + wp_enqueue_script( AYG_SLUG . '-theme-classic' );
162 + }
87 163
88 - do_action( 'ayg_enqueue_scripts' );
164 + /**
165 + * Process the shortcode [automatic_youtube_gallery].
166 + *
167 + * @since 1.0.0
168 + * @param array $attributes An associative array of attributes.
169 + * @param string $content Enclosing content.
170 + * @return string Shortcode HTML output.
171 + */
172 + public function shortcode_automatic_youtube_gallery( $attributes, $content = null ) {
173 + if ( ! empty( $content ) ) {
174 + $attributes['content'] = $content;
175 + }
89 176
90 - // ...
91 - return ayg_build_gallery( $atts );
177 + return ayg_build_gallery( $attributes );
92 178 }
93 179
94 180 /**
95 181 * Load more videos.
@@ -95,39 +181,62 @@
95 181 * Load more videos.
96 182 *
97 183 * @since 1.0.0
98 184 */
99 - public function ajax_callback_load_more_videos() {
185 + public function ajax_callback_load_videos() {
100 186 // Security check
101 - check_ajax_referer( 'ayg_pagination_nonce', 'nonce' );
187 + check_ajax_referer( 'ayg_ajax_nonce', 'security' );
102 188
103 189 // Proceed safe
104 190 $json = array();
105 - $attributes = $_POST;
106 - $source_type = sanitize_text_field( $attributes['type'] );
191 + $attributes = array_map( 'sanitize_text_field', $_POST );
192 + $source_type = $attributes['type'];
107 193
108 194 $api_params = array(
195 + 'uid' => $attributes['uid'],
109 196 'type' => $source_type,
110 - 'id' => sanitize_text_field( $attributes['id'] ),
111 - 'order' => sanitize_text_field( $attributes['order'] ), // works only when type=search
197 + 'src' => $attributes['src'],
198 + 'order' => $attributes['order'], // works only when type=search
199 + 'limit' => (int) $attributes['limit'],
112 200 'maxResults' => (int) $attributes['per_page'],
113 201 'cache' => (int) $attributes['cache'],
114 - 'pageToken' => sanitize_text_field( $attributes['pageToken'] )
202 + 'pageToken' => $attributes['pageToken']
115 203 );
116 204
205 + if ( ! empty( $attributes['searchTerm'] ) ) {
206 + $api_params['searchTerm'] = $attributes['searchTerm'];
207 + }
208 +
117 209 $youtube_api = new AYG_YouTube_API();
118 - $response = $youtube_api->get_videos( $api_params );
210 + $response = $youtube_api->query( $api_params );
119 211
120 212 if ( ! isset( $response->error ) ) {
121 213 if ( isset( $response->page_info ) ) {
122 214 $json = $response->page_info;
215 + $json['message'] = sprintf(
216 + _n( '%s video found matching your query.', '%s videos found matching your query.', $json['videos_found'], 'automatic-youtube-gallery' ),
217 + number_format_i18n( $json['videos_found'] )
218 + );
123 219 }
124 220
125 221 if ( isset( $response->videos ) ) {
126 222 $videos = $response->videos;
223 + $columns = (int) $attributes['columns'];
127 224
128 225 ob_start();
129 - the_ayg_gallery( $videos, $attributes );
226 + foreach ( $videos as $index => $video ) {
227 + $classes = array();
228 + $classes[] = 'ayg-video';
229 + $classes[] = 'ayg-video-' . $video->id;
230 + $classes[] = 'ayg-col';
231 + $classes[] = 'ayg-col-' . $columns;
232 + if ( $columns > 3 ) $classes[] = 'ayg-col-sm-3';
233 + if ( $columns > 2 ) $classes[] = 'ayg-col-xs-2';
234 +
235 + echo'<div class="' . implode( ' ', $classes ) . '">';
236 + the_ayg_gallery_thumbnail( $video, $attributes );
237 + echo '</div>';
238 + }
130 239 $json['html'] = ob_get_clean();
131 240 }
132 241
133 242 wp_send_json_success( $json );
@@ -134,7 +243,33 @@
134 243 } else {
135 244 $json['message'] = $response->error_message;
136 245 wp_send_json_error( $json );
137 246 }
247 + }
248 +
249 + /**
250 + * Set cookie for accepting the privacy consent.
251 + *
252 + * @since 2.0.0
253 + */
254 + public function set_gdpr_cookie() {
255 + // Security check
256 + check_ajax_referer( 'ayg_ajax_nonce', 'security' );
257 +
258 + // Proceed safe
259 + setcookie( 'ayg_gdpr_consent', 1, time() + ( 30 * 24 * 60 * 60 ), COOKIEPATH, COOKIE_DOMAIN );
260 + wp_send_json_success();
261 + }
262 +
263 + /**
264 + * [SMUSH] Skip YouTube iframes from lazy loading.
265 + *
266 + * @since 1.5.0
267 + * @param bool $skip Should skip? Default: false.
268 + * @param string $src Iframe url.
269 + * @return bool
270 + */
271 + public function smush( $skip, $src ) {
272 + return false !== strpos( $src, 'youtube' );
138 273 }
139 274
140 275 }