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 +96 -31 1.2.02.3.8 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 *
@@ -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,46 +50,81 @@
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
65 + $script_args = 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 + )
81 + );
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 +
62 96 wp_localize_script(
63 97 AYG_SLUG . '-public',
64 98 '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 - )
99 + $script_args
73 100 );
74 101 }
75 102
76 103 /**
77 - * Process the shortcode [automatic_youtube_gallery].
104 + * Enqueue Gutenberg block assets for backend editor.
78 105 *
79 - * @since 1.0.0
80 - * @param array $atts An associative array of attributes.
81 - * @return string Shortcode HTML output.
106 + * @since 1.6.1
82 107 */
83 - public function shortcode_automatic_youtube_gallery( $atts ) {
84 - // Enqueue dependencies
108 + public function enqueue_block_editor_assets() {
109 + // Styles
110 + $this->register_styles();
85 111 wp_enqueue_style( AYG_SLUG . '-public' );
112 +
113 + // Scripts
114 + $this->register_scripts();
86 115 wp_enqueue_script( AYG_SLUG . '-public' );
116 + }
87 117
88 - do_action( 'ayg_enqueue_scripts' );
89 -
90 - // ...
91 - return ayg_build_gallery( $atts );
118 + /**
119 + * Process the shortcode [automatic_youtube_gallery].
120 + *
121 + * @since 1.0.0
122 + * @param array $attributes An associative array of attributes.
123 + * @return string Shortcode HTML output.
124 + */
125 + public function shortcode_automatic_youtube_gallery( $attributes ) {
126 + return ayg_build_gallery( $attributes );
92 127 }
93 128
94 129 /**
95 130 * Load more videos.
@@ -97,26 +132,26 @@
97 132 * @since 1.0.0
98 133 */
99 134 public function ajax_callback_load_more_videos() {
100 135 // Security check
101 - check_ajax_referer( 'ayg_pagination_nonce', 'nonce' );
136 + check_ajax_referer( 'ayg_ajax_nonce', 'security' );
102 137
103 138 // Proceed safe
104 139 $json = array();
105 - $attributes = $_POST;
106 - $source_type = sanitize_text_field( $attributes['type'] );
140 + $attributes = array_map( 'sanitize_text_field', $_POST );
141 + $source_type = $attributes['type'];
107 142
108 143 $api_params = array(
109 144 'type' => $source_type,
110 - 'id' => sanitize_text_field( $attributes['id'] ),
111 - 'order' => sanitize_text_field( $attributes['order'] ), // works only when type=search
145 + 'src' => $attributes['src'],
146 + 'order' => $attributes['order'], // works only when type=search
112 147 'maxResults' => (int) $attributes['per_page'],
113 148 'cache' => (int) $attributes['cache'],
114 - 'pageToken' => sanitize_text_field( $attributes['pageToken'] )
149 + 'pageToken' => $attributes['pageToken']
115 150 );
116 151
117 152 $youtube_api = new AYG_YouTube_API();
118 - $response = $youtube_api->get_videos( $api_params );
153 + $response = $youtube_api->query( $api_params );
119 154
120 155 if ( ! isset( $response->error ) ) {
121 156 if ( isset( $response->page_info ) ) {
122 157 $json = $response->page_info;
@@ -125,9 +160,13 @@
125 160 if ( isset( $response->videos ) ) {
126 161 $videos = $response->videos;
127 162
128 163 ob_start();
129 - 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 + }
130 169 $json['html'] = ob_get_clean();
131 170 }
132 171
133 172 wp_send_json_success( $json );
@@ -134,7 +173,33 @@
134 173 } else {
135 174 $json['message'] = $response->error_message;
136 175 wp_send_json_error( $json );
137 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();
191 + }
192 +
193 + /**
194 + * [SMUSH] Skip YouTube iframes from lazy loading.
195 + *
196 + * @since 1.5.0
197 + * @param bool $skip Should skip? Default: false.
198 + * @param string $src Iframe url.
199 + * @return bool
200 + */
201 + public function smush( $skip, $src ) {
202 + return false !== strpos( $src, 'youtube' );
138 203 }
139 204
140 205 }