PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.37
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.37
3.37 3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 All 142 releases
← All changes | Admin/Wizard/Instagram.php +75 -68 2.41 → 3.37 View file →
@@ -1,96 +1,100 @@
1 1 <?php
2 +
2 3 namespace Photonic_Plugin\Admin\Wizard;
3 4
4 5 use Photonic_Plugin\Core\Utilities;
5 6
6 7 class Instagram extends Source {
7 - private static $instance;
8 + private static ?Instagram $instance = null;
8 9
9 10 protected function __construct() {
10 11 parent::__construct();
11 12 $this->provider = 'instagram';
13 + $this->api_base = Wizard::base_apis()['instagram'];
12 14 }
13 15
14 - public static function get_instance() {
15 - if (self::$instance == null) {
16 + public static function get_instance(): Instagram {
17 + if (null === self::$instance) {
16 18 self::$instance = new Instagram();
17 19 }
18 20 return self::$instance;
19 21 }
20 22
21 - function get_screen_2() {
23 + public function get_screen_2(): array {
22 24 return [
23 - 'header' => esc_html__('Choose Type of Gallery', 'photonic'),
25 + 'header' => esc_html__('Choose Type of Gallery', 'photonic'),
24 26 'display' => [
25 27 'display_type' => [
26 - 'desc' => esc_html__('What do you want to show?', 'photonic'),
27 - 'type' => 'select',
28 + 'desc' => esc_html__('What do you want to show?', 'photonic'),
29 + 'type' => 'select',
28 30 'options' => [
29 - '' => '',
31 + '' => '',
30 32 'single-photo' => esc_html__('Single Photo', 'photonic'),
31 - 'album-photo' => esc_html__('Photos in a Post', 'photonic'),
32 - 'multi-photo' => esc_html__('Multiple Photos', 'photonic'),
33 + 'album-photo' => esc_html__('Photos in a Post', 'photonic'),
34 + 'multi-photo' => esc_html__('Multiple Photos', 'photonic'),
33 35 ],
34 - 'req' => 1,
36 + 'req' => 1,
35 37 ],
36 38 ],
37 39 ];
38 40 }
39 41
40 - function get_screen_3() {
42 + public function get_screen_3(): array {
41 43 return [
42 - 'header' => esc_html__('Build your gallery', 'photonic'),
44 + 'header' => esc_html__('Build your gallery', 'photonic'),
43 45 'single-photo' => [
44 - 'header' => esc_html__('Pick a photo', 'photonic'),
45 - 'desc' => esc_html__('From the list below pick the single photo you wish to display.', 'photonic'),
46 + 'header' => esc_html__('Pick a photo', 'photonic'),
47 + 'desc' => esc_html__('From the list below pick the single photo you wish to display.', 'photonic'),
46 48 'display' => [
47 - 'embed_type' => [
48 - 'desc' => esc_html__('How do you want to display your photo?', 'photonic'),
49 - 'type' => 'select',
50 - 'options' => [
51 - '' => '',
52 - 'embed' => esc_html__('Show as an "Instagram embed"', 'photonic'),
53 - 'integrate' => esc_html__('Show similar to other photos, without embedding Instagram', 'photonic'),
54 - ],
55 - 'std' => '',
56 - ],
57 49 'container' => [
58 50 'type' => 'thumbnail-selector',
59 51 'mode' => 'single',
60 - 'for' => 'selected_data',
52 + 'for' => 'selected_data',
61 53 ],
62 54 ],
63 55 ],
64 - 'album-photo' => [
65 - 'header' => esc_html__('Pick a post (a.k.a. Carousel)', 'photonic'),
66 - 'desc' => esc_html__('From the list below pick the post whose photos you wish to display.', 'photonic'),
56 + 'album-photo' => [
57 + 'header' => esc_html__('Pick a post (a.k.a. Carousel)', 'photonic'),
58 + 'desc' => esc_html__('From the list below pick the post whose photos you wish to display.', 'photonic'),
67 59 'display' => [
68 - 'container' => [
60 + 'carousel_caption' => [
61 + 'desc' => esc_html__('Where do you want to show the caption for the post / carousel?', 'photonic'),
62 + 'type' => 'select',
63 + 'options' => [
64 + '' => $this->default_from_settings,
65 + 'none' => esc_html__('Do not show the caption', 'photonic'),
66 + 'above' => esc_html__('Show above the photos', 'photonic'),
67 + 'below' => esc_html__('Show below the photos', 'photonic'),
68 + ],
69 + 'std' => '',
70 + 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Instagram &rarr; Instagram Settings &rarr; Caption positioning for carousels / posts</em>'),
71 + ],
72 + 'container' => [
69 73 'type' => 'thumbnail-selector',
70 74 'mode' => 'single',
71 - 'for' => 'selected_data',
75 + 'for' => 'selected_data',
72 76 ],
73 77 ],
74 78 ],
75 - 'multi-photo' => [
76 - 'header' => esc_html__('All your photos', 'photonic'),
77 - 'desc' => esc_html__('You can only show all your photos without filtering. In the following only the latest 25 photos are displayed. You can change this in subsequent screens.', 'photonic'),
79 + 'multi-photo' => [
80 + 'header' => esc_html__('All your photos', 'photonic'),
81 + 'desc' => esc_html__('You can only show all your photos without filtering. In the following only the latest 25 photos are displayed. You can change this in subsequent screens.', 'photonic'),
78 82 'display' => [
79 83 'carousel_handling' => [
80 - 'desc' => esc_html__('How do you want to show photos in a carousel?', 'photonic'),
81 - 'type' => 'select',
84 + 'desc' => esc_html__('How do you want to show photos in a carousel?', 'photonic'),
85 + 'type' => 'select',
82 86 'options' => [
83 - '' => '',
87 + '' => '',
84 88 'single' => esc_html__('Show first photo', 'photonic'),
85 89 'expand' => esc_html__('Show all photos', 'photonic'),
86 90 ],
87 - 'std' => '',
91 + 'std' => '',
88 92 ],
89 - 'container' => [
93 + 'container' => [
90 94 'type' => 'thumbnail-selector',
91 95 'mode' => 'none',
92 - 'for' => 'selected_data',
96 + 'for' => 'selected_data',
93 97 ],
94 98 ],
95 99 ],
96 100 ];
@@ -95,39 +99,39 @@
95 99 ],
96 100 ];
97 101 }
98 102
99 - function get_screen_4() {
103 + public function get_screen_4(): array {
100 104 return [];
101 105 }
102 106
103 - function get_screen_5() {
107 + public function get_screen_5(): array {
104 108 global $photonic_instagram_media;
105 109 return [
106 110 'instagram' => [
107 111 'media' => [
108 - 'desc' => esc_html__('Media to Show', 'photonic'),
109 - 'type' => 'select',
112 + 'desc' => esc_html__('Media to Show', 'photonic'),
113 + 'type' => 'select',
110 114 'options' => Utilities::media_options(true, $photonic_instagram_media),
111 - 'std' => '',
112 - 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Instagram &rarr; Instagram Settings &rarr; Media to show</em>'),
115 + 'std' => '',
116 + 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Instagram &rarr; Instagram Settings &rarr; Media to show</em>'),
113 117 ],
114 118 ]
115 119 ];
116 120 }
117 121
118 - function get_square_size_options() {
122 + public function get_square_size_options(): array {
119 123 return [];
120 124 }
121 125
122 - function get_random_size_options() {
126 + public function get_random_size_options(): array {
123 127 return [];
124 128 }
125 129
126 - function make_request($display_type, $for, $flattened_fields) {
127 - require_once(PHOTONIC_PATH.'/Modules/Instagram.php');
128 - $module = \Photonic_Plugin\Modules\Instagram::get_instance();
129 - $base_url = 'https://graph.instagram.com/me/media?fields='.$module->field_list.'&access_token='.$module->access_token;
130 + public function make_request($display_type, $for, $flattened_fields): array {
131 + require_once PHOTONIC_PATH . '/Platforms/Instagram.php';
132 + $module = \Photonic_Plugin\Platforms\Instagram::get_instance();
133 + $base_url = 'https://' . $this->api_base . '/me/media?fields=' . $module->field_list . '&access_token=' . $module->access_token;
130 134 $response = wp_remote_request($base_url, ['sslverify' => PHOTONIC_SSL_VERIFY]);
131 135
132 136 return [$response, [], $base_url];
133 137 }
@@ -140,16 +144,16 @@
140 144 * @param $url
141 145 * @param array $pagination
142 146 * @return array
143 147 */
144 - function process_response($response, $display_type, $url = null, &$pagination = []) {
148 + public function process_response($response, $display_type, $url = null, &$pagination = []): array {
145 149 $objects = [];
146 150 $body = json_decode($response['body']);
147 151 if (isset($body->data)) {
148 152 $data = $body->data;
149 153 foreach ($data as $photo) {
150 - if (isset($photo->media_type) && (strtolower($photo->media_type) == 'image' || strtolower($photo->media_type) == 'carousel_album' || strtolower($photo->media_type) == 'video')) {
151 - if (($display_type == 'album-photo' && strtolower($photo->media_type) == 'carousel_album') || $display_type != 'album-photo') {
154 + if (isset($photo->media_type) && ('image' === strtolower($photo->media_type) || 'carousel_album' === strtolower($photo->media_type) || 'video' === strtolower($photo->media_type))) {
155 + if (('album-photo' === $display_type && 'carousel_album' === strtolower($photo->media_type)) || 'album-photo' !== $display_type) {
152 156 $object = [];
153 157 $link = $photo->permalink;
154 158 $link = explode('/', $link);
155 159 if (empty($link[count($link) - 1])) {
@@ -170,10 +174,11 @@
170 174 $objects[] = $object;
171 175 }
172 176 }
173 177 }
174 - if (isset($body->pagination) && isset($body->pagination->next_max_id) && $display_type == 'single-photo') {
175 - $pagination['url'] = add_query_arg(['max_id' => $body->pagination->next_max_id], remove_query_arg(['max_id'], $url));
178 +
179 + if (isset($body->paging) && isset($body->paging->next) && 'single-photo' === $display_type) {
180 + $pagination['url'] = $body->paging->next; // add_query_arg(['max_id' => $body->pagination->next_max_id], remove_query_arg(['max_id'], $url));
176 181 }
177 182 }
178 183 return $objects;
179 184 }
@@ -179,19 +184,21 @@
179 184 }
180 185
181 186 /**
182 187 * @param $display_type
183 - * @return array|mixed
188 + * @return array
184 189 */
185 - function construct_shortcode_from_screen_selections($display_type) {
190 + public function construct_shortcode_from_screen_selections($display_type): array {
186 191 $short_code = [];
187 192
188 - if ($display_type == 'single-photo') {
189 - $short_code['media_id'] = sanitize_text_field($_POST['selected_data']);
193 + if (check_ajax_referer('photonic-wizard-next-' . get_current_user_id())) {
194 + if ('single-photo' === $display_type) {
195 + $short_code['media_id'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? ''));
196 + }
197 + elseif ('album-photo' === $display_type) {
198 + $short_code['carousel'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? ''));
199 + }
190 200 }
191 - else if ($display_type == 'album-photo') {
192 - $short_code['carousel'] = sanitize_text_field($_POST['selected_data']);
193 - }
194 201
195 202 return $short_code;
196 203 }
197 204
@@ -196,11 +203,11 @@
196 203 }
197 204
198 205 /**
199 206 * @param $input
200 - * @return array|mixed
207 + * @return array
201 208 */
202 - function deconstruct_shortcode_to_screen_selections($input) {
209 + public function deconstruct_shortcode_to_screen_selections($input): array {
203 210 $deconstructed = [];
204 211
205 212 if (!empty($input->media_id)) {
206 213 $deconstructed['display_type'] = 'single-photo';
@@ -205,9 +212,9 @@
205 212 if (!empty($input->media_id)) {
206 213 $deconstructed['display_type'] = 'single-photo';
207 214 $deconstructed['selected_data'] = $input->media_id;
208 215 }
209 - else if (!empty($input->carousel)) {
216 + elseif (!empty($input->carousel)) {
210 217 $deconstructed['display_type'] = 'album-photo';
211 218 $deconstructed['selected_data'] = $input->carousel;
212 219 }
213 220 else {
@@ -215,5 +222,5 @@
215 222 }
216 223
217 224 return $deconstructed;
218 225 }
219 -}
226 +}