| @@ -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 | 56 | AYG_URL . 'public/assets/css/public.min.css', |
| 42 | - array(), | |
| 57 | + $deps, | |
| 43 | 58 | AYG_VERSION, |
| 44 | 59 | 'all' |
| 45 | 60 | ); |
| 46 | 61 | } |
| @@ -50,34 +65,55 @@ | ||
| 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' ); | |
| 54 | 71 | $player_settings = get_option( 'ayg_player_settings' ); |
| 55 | 72 | $privacy_settings = get_option( 'ayg_privacy_settings' ); |
| 56 | 73 | |
| 74 | + $deps = array( 'jquery' ); | |
| 75 | + if ( isset( $player_settings['player_type'] ) && 'custom' == $player_settings['player_type'] ) { | |
| 76 | + $deps[] = AYG_SLUG . '-plyr'; | |
| 77 | + } | |
| 78 | + | |
| 57 | 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( | |
| 58 | 88 | AYG_SLUG . '-public', |
| 59 | 89 | AYG_URL . 'public/assets/js/public.min.js', |
| 60 | - array( 'jquery' ), | |
| 90 | + $deps, | |
| 61 | 91 | AYG_VERSION, |
| 62 | 92 | array( 'strategy' => 'defer' ) |
| 63 | 93 | ); |
| 64 | 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 | + | |
| 65 | 102 | $script_args = array( |
| 66 | - 'current_url' => get_permalink(), | |
| 67 | 103 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 68 | 104 | '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' => '', | |
| 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', | |
| 73 | 109 | 'privacy_enhanced_mode' => isset( $player_settings['privacy_enhanced_mode'] ) ? (int) $player_settings['privacy_enhanced_mode'] : 0, |
| 74 | 110 | 'origin' => '', |
| 75 | - 'cookie_consent' => 0, | |
| 76 | - 'top_offset' => apply_filters( 'ayg_gallery_scrolltop_offset', 10 ), | |
| 111 | + 'cookieconsent' => 0, | |
| 112 | + 'top_offset' => $scroll_top_offset, | |
| 77 | 113 | 'i18n' => array( |
| 78 | - 'show_more' => '[+] ' . __( 'Show More', 'automatic-youtube-gallery' ), | |
| 79 | - 'show_less' => '[-] ' . __( 'Show Less', 'automatic-youtube-gallery' ) | |
| 114 | + 'show_more' => $show_more_label, | |
| 115 | + 'show_less' => $show_less_label | |
| 80 | 116 | ) |
| 81 | 117 | ); |
| 82 | 118 | |
| 83 | 119 | if ( isset( $player_settings['origin'] ) && ! empty( $player_settings['origin'] ) ) { |
| @@ -86,19 +122,27 @@ | ||
| 86 | 122 | } |
| 87 | 123 | |
| 88 | 124 | if ( ! isset( $_COOKIE['ayg_gdpr_consent'] ) ) { |
| 89 | 125 | 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'] ); | |
| 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'] ); | |
| 93 | 129 | } |
| 94 | 130 | } |
| 95 | 131 | |
| 96 | 132 | wp_localize_script( |
| 97 | 133 | AYG_SLUG . '-public', |
| 98 | - 'ayg_public', | |
| 134 | + 'ayg_config', | |
| 99 | 135 | $script_args |
| 100 | 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 | + ); | |
| 101 | 145 | } |
| 102 | 146 | |
| 103 | 147 | /** |
| 104 | 148 | * Enqueue Gutenberg block assets for backend editor. |
| @@ -111,9 +155,11 @@ | ||
| 111 | 155 | wp_enqueue_style( AYG_SLUG . '-public' ); |
| 112 | 156 | |
| 113 | 157 | // Scripts |
| 114 | 158 | $this->register_scripts(); |
| 159 | + | |
| 115 | 160 | wp_enqueue_script( AYG_SLUG . '-public' ); |
| 161 | + wp_enqueue_script( AYG_SLUG . '-theme-classic' ); | |
| 116 | 162 | } |
| 117 | 163 | |
| 118 | 164 | /** |
| 119 | 165 | * Process the shortcode [automatic_youtube_gallery]. |
| @@ -119,11 +165,16 @@ | ||
| 119 | 165 | * Process the shortcode [automatic_youtube_gallery]. |
| 120 | 166 | * |
| 121 | 167 | * @since 1.0.0 |
| 122 | 168 | * @param array $attributes An associative array of attributes. |
| 169 | + * @param string $content Enclosing content. | |
| 123 | 170 | * @return string Shortcode HTML output. |
| 124 | 171 | */ |
| 125 | - public function shortcode_automatic_youtube_gallery( $attributes ) { | |
| 172 | + public function shortcode_automatic_youtube_gallery( $attributes, $content = null ) { | |
| 173 | + if ( ! empty( $content ) ) { | |
| 174 | + $attributes['content'] = $content; | |
| 175 | + } | |
| 176 | + | |
| 126 | 177 | return ayg_build_gallery( $attributes ); |
| 127 | 178 | } |
| 128 | 179 | |
| 129 | 180 | /** |
| @@ -130,9 +181,9 @@ | ||
| 130 | 181 | * Load more videos. |
| 131 | 182 | * |
| 132 | 183 | * @since 1.0.0 |
| 133 | 184 | */ |
| 134 | - public function ajax_callback_load_more_videos() { | |
| 185 | + public function ajax_callback_load_videos() { | |
| 135 | 186 | // Security check |
| 136 | 187 | check_ajax_referer( 'ayg_ajax_nonce', 'security' ); |
| 137 | 188 | |
| 138 | 189 | // Proceed safe |
| @@ -140,16 +191,22 @@ | ||
| 140 | 191 | $attributes = array_map( 'sanitize_text_field', $_POST ); |
| 141 | 192 | $source_type = $attributes['type']; |
| 142 | 193 | |
| 143 | 194 | $api_params = array( |
| 195 | + 'uid' => $attributes['uid'], | |
| 144 | 196 | 'type' => $source_type, |
| 145 | 197 | 'src' => $attributes['src'], |
| 146 | 198 | 'order' => $attributes['order'], // works only when type=search |
| 199 | + 'limit' => (int) $attributes['limit'], | |
| 147 | 200 | 'maxResults' => (int) $attributes['per_page'], |
| 148 | 201 | 'cache' => (int) $attributes['cache'], |
| 149 | 202 | 'pageToken' => $attributes['pageToken'] |
| 150 | 203 | ); |
| 151 | 204 | |
| 205 | + if ( ! empty( $attributes['searchTerm'] ) ) { | |
| 206 | + $api_params['searchTerm'] = $attributes['searchTerm']; | |
| 207 | + } | |
| 208 | + | |
| 152 | 209 | $youtube_api = new AYG_YouTube_API(); |
| 153 | 210 | $response = $youtube_api->query( $api_params ); |
| 154 | 211 | |
| 155 | 212 | if ( ! isset( $response->error ) ) { |
| @@ -154,8 +211,12 @@ | ||
| 154 | 211 | |
| 155 | 212 | if ( ! isset( $response->error ) ) { |
| 156 | 213 | if ( isset( $response->page_info ) ) { |
| 157 | 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 | + ); | |
| 158 | 219 | } |
| 159 | 220 | |
| 160 | 221 | if ( isset( $response->videos ) ) { |
| 161 | 222 | $videos = $response->videos; |
| @@ -163,10 +224,10 @@ | ||
| 163 | 224 | |
| 164 | 225 | ob_start(); |
| 165 | 226 | foreach ( $videos as $index => $video ) { |
| 166 | 227 | $classes = array(); |
| 167 | - $classes[] = 'ayg-item'; | |
| 168 | - $classes[] = 'ayg-item-' . $video->id; | |
| 228 | + $classes[] = 'ayg-video'; | |
| 229 | + $classes[] = 'ayg-video-' . $video->id; | |
| 169 | 230 | $classes[] = 'ayg-col'; |
| 170 | 231 | $classes[] = 'ayg-col-' . $columns; |
| 171 | 232 | if ( $columns > 3 ) $classes[] = 'ayg-col-sm-3'; |
| 172 | 233 | if ( $columns > 2 ) $classes[] = 'ayg-col-xs-2'; |