PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 1.4.0
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v1.4.0
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
automatic-youtube-gallery / public / public.php

public.php in Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels 1.4.0, at public/public.php

141 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The public-facing functionality of the plugin.
5 *
6 * @link https://plugins360.com
7 * @since 1.0.0
8 *
9 * @package Automatic_YouTube_Gallery
10 */
11
12 // Exit if accessed directly
13 if ( ! defined( 'WPINC' ) ) {
14 die;
15 }
16
17 /**
18 * AYG_Public class.
19 *
20 * @since 1.0.0
21 */
22 class AYG_Public {
23
24 /**
25 * Get things started.
26 *
27 * @since 1.0.0
28 */
29 public function __construct() {
30 add_shortcode( "automatic_youtube_gallery", array( $this, "shortcode_automatic_youtube_gallery" ) );
31 }
32
33 /**
34 * Enqueue styles for the public-facing side of the site.
35 *
36 * @since 1.0.0
37 */
38 public function register_styles() {
39 wp_register_style(
40 AYG_SLUG . '-public',
41 AYG_URL . 'public/assets/css/public.css',
42 array(),
43 AYG_VERSION,
44 'all'
45 );
46 }
47
48 /**
49 * Enqueue scripts for the public-facing side of the site.
50 *
51 * @since 1.0.0
52 */
53 public function register_scripts() {
54 wp_register_script(
55 AYG_SLUG . '-public',
56 AYG_URL . 'public/assets/js/public.js',
57 array( 'jquery' ),
58 AYG_VERSION,
59 false
60 );
61
62 wp_localize_script(
63 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 )
73 );
74 }
75
76 /**
77 * Process the shortcode [automatic_youtube_gallery].
78 *
79 * @since 1.0.0
80 * @param array $atts An associative array of attributes.
81 * @return string Shortcode HTML output.
82 */
83 public function shortcode_automatic_youtube_gallery( $atts ) {
84 // Enqueue dependencies
85 wp_enqueue_style( AYG_SLUG . '-public' );
86 wp_enqueue_script( AYG_SLUG . '-public' );
87
88 do_action( 'ayg_enqueue_scripts' );
89
90 // ...
91 return ayg_build_gallery( $atts );
92 }
93
94 /**
95 * Load more videos.
96 *
97 * @since 1.0.0
98 */
99 public function ajax_callback_load_more_videos() {
100 // Security check
101 check_ajax_referer( 'ayg_pagination_nonce', 'nonce' );
102
103 // Proceed safe
104 $json = array();
105 $attributes = $_POST;
106 $source_type = sanitize_text_field( $attributes['type'] );
107
108 $api_params = array(
109 'type' => $source_type,
110 'id' => sanitize_text_field( $attributes['id'] ),
111 'order' => sanitize_text_field( $attributes['order'] ), // works only when type=search
112 'maxResults' => (int) $attributes['per_page'],
113 'cache' => (int) $attributes['cache'],
114 'pageToken' => sanitize_text_field( $attributes['pageToken'] )
115 );
116
117 $youtube_api = new AYG_YouTube_API();
118 $response = $youtube_api->get_videos( $api_params );
119
120 if ( ! isset( $response->error ) ) {
121 if ( isset( $response->page_info ) ) {
122 $json = $response->page_info;
123 }
124
125 if ( isset( $response->videos ) ) {
126 $videos = $response->videos;
127
128 ob_start();
129 the_ayg_gallery( $videos, $attributes );
130 $json['html'] = ob_get_clean();
131 }
132
133 wp_send_json_success( $json );
134 } else {
135 $json['message'] = $response->error_message;
136 wp_send_json_error( $json );
137 }
138 }
139
140 }
141