PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.41
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.41
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 2.44 All 141 releases
photonic / Admin / Wizard / Flickr.php

Flickr.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.41, at Admin/Wizard/Flickr.php

717 lines 30.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Photonic_Plugin\Admin\Wizard;
3
4 use Photonic_Plugin\Core\Photonic;
5 use Photonic_Plugin\Core\Utilities;
6
7 class Flickr extends Source {
8 private static $instance;
9
10 protected function __construct() {
11 parent::__construct();
12 $this->provider = 'flickr';
13
14 global $photonic_flickr_thumb_size, $photonic_flickr_tile_size, $photonic_flickr_main_size, $photonic_flickr_video_size;
15 $this->allowed_image_sizes['flickr'] = [
16 'thumb_size' => [
17 '' => $this->default_from_settings,
18 's' => esc_html__('Small square, 75x75px', 'photonic'),
19 'q' => esc_html__('Large square, 150x150px', 'photonic'),
20 't' => esc_html__('Thumbnail, 100px on longest side', 'photonic'),
21 'm' => esc_html__('Small, 240px on longest side', 'photonic'),
22 'n' => esc_html__('Small, 320px on longest side', 'photonic'),
23 ],
24 'tile_size' => [
25 '' => $this->default_from_settings,
26 'same' => esc_html__('Same as Main image size', 'photonic'),
27 'n' => esc_html__('Small, 320px on longest side', 'photonic'),
28 'none' => esc_html__('Medium, 500px on the longest side', 'photonic'),
29 'z' => esc_html__('Medium, 640px on longest side', 'photonic'),
30 'c' => esc_html__('Medium, 800px on longest side', 'photonic'),
31 'b' => esc_html__('Large, 1024px on longest side', 'photonic'),
32 'h' => esc_html__('Large, 1600px on longest side', 'photonic'),
33 'k' => esc_html__('Large, 2048px on longest side', 'photonic'),
34 'o' => esc_html__('Original', 'photonic'),
35 ],
36 'main_size' => [
37 '' => $this->default_from_settings,
38 'none' => esc_html__('Medium, 500px on the longest side', 'photonic'),
39 'z' => esc_html__('Medium, 640px on longest side', 'photonic'),
40 'c' => esc_html__('Medium, 800px on longest side', 'photonic'),
41 'b' => esc_html__('Large, 1024px on longest side', 'photonic'),
42 'h' => esc_html__('Large, 1600px on longest side', 'photonic'),
43 'k' => esc_html__('Large, 2048px on longest side', 'photonic'),
44 'o' => esc_html__('Original', 'photonic'),
45 ],
46 'video_size' => [
47 '' => $this->default_from_settings,
48 'Site MP4' => esc_html__('Site MP4', 'photonic'),
49 'Mobile MP4' => esc_html__('Mobile MP4', 'photonic'),
50 'HD MP4' => esc_html__('HD MP4', 'photonic'),
51 'Video Original' => esc_html__('Video Original', 'photonic'),
52 ],
53 ];
54 $this->allowed_image_sizes['flickr']['thumb_size'][''] .= ' - '.$this->allowed_image_sizes['flickr']['thumb_size'][$photonic_flickr_thumb_size];
55 $this->allowed_image_sizes['flickr']['tile_size'][''] .= ' - '.$this->allowed_image_sizes['flickr']['tile_size'][$photonic_flickr_tile_size];
56 $this->allowed_image_sizes['flickr']['main_size'][''] .= ' - '.$this->allowed_image_sizes['flickr']['main_size'][$photonic_flickr_main_size];
57 $this->allowed_image_sizes['flickr']['video_size'][''] .= ' - '.$this->allowed_image_sizes['flickr']['video_size'][$photonic_flickr_video_size];
58
59 }
60
61 public static function get_instance() {
62 if (self::$instance == null) {
63 self::$instance = new Flickr();
64 }
65 return self::$instance;
66 }
67
68 function get_screen_2() {
69 return [
70 'header' => esc_html__('Choose Type of Gallery', 'photonic'),
71 'display' => [
72 'kind' => [
73 'type' => 'field_list',
74 'list_type' => 'sequence',
75 'list' => [
76 'display_type' => [
77 'desc' => esc_html__('What do you want to show?', 'photonic'),
78 'type' => 'select',
79 'options' => [
80 '' => '',
81 'single-photo' => esc_html__('A Single Photo', 'photonic'),
82 'multi-photo' => esc_html__('Multiple Photos', 'photonic'),
83 'album-photo' => esc_html__('Photos from an Album / Photoset', 'photonic'),
84 'gallery-photo' => esc_html__('Photos from a Gallery', 'photonic'),
85 'multi-album' => esc_html__('Multiple Albums', 'photonic'),
86 'multi-gallery' => esc_html__('Multiple Galleries', 'photonic'),
87 'collection' => esc_html__('Albums from a single collection', 'photonic'),
88 'collections' => esc_html__('Multiple collections', 'photonic'),
89 ],
90 'req' => 1,
91 ],
92 'for' => [
93 'desc' => esc_html__('For whom?', 'photonic'),
94 'type' => 'radio',
95 'options' => [
96 'current' => sprintf(esc_html__('Current user (Defined under %s)', 'photonic'), '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Default user</em>'),
97 'other' => esc_html__('Another user', 'photonic'),
98 'group' => esc_html__('Group', 'photonic'),
99 'any' => esc_html__('All users', 'photonic'),
100 ],
101 'option-conditions' => [
102 'group' => ['display_type' => ['multi-photo']],
103 'any' => ['display_type' => ['multi-photo']],
104 ],
105 'req' => 1,
106 ],
107 'login' => [
108 'desc' => sprintf(esc_html__('User name, e.g. %s', 'photonic'), 'https://www.flickr.com/photos/<span style="text-decoration: underline">username</span>/'),
109 'type' => 'text',
110 'std' => '',
111 'conditions' => ['for' => ['other']],
112 'req' => 1,
113 ],
114 'group' => [
115 'desc' => sprintf(esc_html__('Group name, e.g. %s', 'photonic'), 'https://www.flickr.com/groups/<span style="text-decoration: underline">groupname</span>/'),
116 'type' => 'text',
117 'std' => '',
118 'conditions' => ['for' => ['group']],
119 'req' => 1,
120 ],
121 ],
122 ],
123 ],
124 ];
125 }
126
127 function get_screen_3() {
128 return [
129 'header' => esc_html__('Build your gallery', 'photonic'),
130 'single-photo' => [
131 'header' => esc_html__('Pick a photo', 'photonic'),
132 'desc' => esc_html__('From the list below pick the single photo you wish to display.', 'photonic'),
133 'display' => [
134 'container' => [
135 'type' => 'thumbnail-selector',
136 'mode' => 'single',
137 'for' => 'selected_data',
138 ],
139 ],
140 ],
141 'multi-photo' => [
142 'header' => esc_html__('All your photos', 'photonic'),
143 'desc' => esc_html__('You can show all your photos, or apply tags to show some of them.', 'photonic'),
144 'display' => [
145 'tags' => [
146 'desc' => esc_html__('Tags', 'photonic'),
147 'type' => 'text',
148 'hint' => esc_html__('Comma-separated list of tags', 'photonic')
149 ],
150
151 'tag_mode' => [
152 'desc' => esc_html__('Tag mode', 'photonic'),
153 'type' => 'select',
154 'options' => [
155 'any' => esc_html__('Any tag', 'photonic'),
156 'all' => esc_html__('All tags', 'photonic'),
157 ],
158 ],
159
160 'text' => [
161 'desc' => esc_html__('With text', 'photonic'),
162 'type' => 'text',
163 ],
164
165 'privacy_filter' => [
166 'desc' => esc_html__('Privacy filter', 'photonic'),
167 'type' => 'select',
168 'options' => [
169 '' => esc_html__('None', 'photonic'),
170 '1' => esc_html__('Public photos', 'photonic'),
171 '2' => esc_html__('Private photos visible to friends', 'photonic'),
172 '3' => esc_html__('Private photos visible to family', 'photonic'),
173 '4' => esc_html__('Private photos visible to friends & family', 'photonic'),
174 '5' => esc_html__('Completely private photos', 'photonic'),
175 ],
176 'hint' => sprintf(esc_html__('Applicable only if Flickr private photos are turned on (%1$s) and Back-end authentication is off (%2$s)', 'photonic'), '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Allow User Login</em>', '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Access Token</em>'),
177 ],
178
179 'container' => [
180 'type' => 'thumbnail-selector',
181 'mode' => 'none',
182 'for' => 'selected_data',
183 ],
184 ],
185 ],
186 'album-photo' => [
187 'header' => esc_html__('Pick your album', 'photonic'),
188 'desc' => esc_html__('From the list below pick the album whose photos you wish to display. Photos from that album will show up as thumbnails.', 'photonic'),
189 'display' => [
190 'privacy_filter' => [
191 'desc' => esc_html__('Privacy filter', 'photonic'),
192 'type' => 'select',
193 'options' => [
194 '' => esc_html__('None', 'photonic'),
195 '1' => esc_html__('Public photos', 'photonic'),
196 '2' => esc_html__('Private photos visible to friends', 'photonic'),
197 '3' => esc_html__('Private photos visible to family', 'photonic'),
198 '4' => esc_html__('Private photos visible to friends & family', 'photonic'),
199 '5' => esc_html__('Completely private photos', 'photonic'),
200 ],
201 'hint' => sprintf(esc_html__('Applicable only if Flickr private photos are turned on (%1$s) and Back-end authentication is off (%2$s)', 'photonic'), '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Allow User Login</em>', '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Access Token</em>'),
202 ],
203
204 'container' => [
205 'type' => 'thumbnail-selector',
206 'mode' => 'single',
207 'for' => 'selected_data',
208 ],
209 ],
210 ],
211 'gallery-photo' => [
212 'header' => esc_html__('Pick your gallery', 'photonic'),
213 'desc' => esc_html__('From the list below pick the gallery whose photos you wish to display. Photos from that gallery will show up as thumbnails.', 'photonic'),
214 'display' => [
215 'container' => [
216 'type' => 'thumbnail-selector',
217 'mode' => 'single',
218 'for' => 'selected_data',
219 ],
220 ],
221 ],
222 'multi-album' => [
223 'header' => esc_html__('Pick your albums / photosets', 'photonic'),
224 'desc' => esc_html__('From the list below pick the albums / photosets you wish to display. Each album will show up as a single thumbnail.', 'photonic'),
225 'display' => [
226 'selection' => [
227 'desc' => esc_html__('What do you want to show?', 'photonic'),
228 'type' => 'select',
229 'options' => [
230 'all' => esc_html__('Automatic all (will automatically add new albums)', 'photonic'),
231 'selected' => esc_html__('Selected albums / photosets', 'photonic'),
232 'not-selected' => esc_html__('All except selected albums / photosets', 'photonic'),
233 ],
234 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'),
235 'req' => 1,
236 ],
237 'container' => [
238 'type' => 'thumbnail-selector',
239 'mode' => 'multi',
240 'for' => 'selected_data',
241 ],
242 ],
243 ],
244 'multi-gallery' => [
245 'header' => esc_html__('Pick your galleries', 'photonic'),
246 'desc' => esc_html__('From the list below pick the galleries you wish to display. Each album will show up as a single thumbnail.', 'photonic'),
247 'display' => [
248 'selection' => [
249 'desc' => esc_html__('What do you want to show?', 'photonic'),
250 'type' => 'select',
251 'options' => [
252 'all' => esc_html__('Automatic all (will automatically add new galleries)', 'photonic'),
253 'selected' => esc_html__('Selected galleries', 'photonic'),
254 'not-selected' => esc_html__('All except selected galleries', 'photonic'),
255 ],
256 'req' => 1,
257 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'),
258 ],
259 'container' => [
260 'type' => 'thumbnail-selector',
261 'mode' => 'multi',
262 'for' => 'selected_data',
263 ],
264 ],
265 ],
266 'collection' => [
267 'header' => esc_html__('Pick your collection', 'photonic'),
268 'desc' => esc_html__('From the list below pick the collection you wish to display. The albums within the collections will show up as single thumbnails.', 'photonic'),
269 'display' => [
270 'container' => [
271 'type' => 'thumbnail-selector',
272 'mode' => 'single',
273 'for' => 'selected_data',
274 ],
275 ],
276 ],
277 'collections' => [
278 'header' => esc_html__('Pick your collections', 'photonic'),
279 'desc' => esc_html__('From the list below pick the collections you wish to display. The albums within the collections will show up as single thumbnails.', 'photonic'),
280 'display' => [
281 'selection' => [
282 'desc' => esc_html__('What do you want to show?', 'photonic'),
283 'type' => 'select',
284 'options' => [
285 'all' => esc_html__('Automatic all (will automatically add new collections)', 'photonic'),
286 'selected' => esc_html__('Selected collections', 'photonic'),
287 'not-selected' => esc_html__('All except selected collections', 'photonic'),
288 ],
289 'req' => 1,
290 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'),
291 ],
292 'container' => [
293 'type' => 'thumbnail-selector',
294 'mode' => 'multi',
295 'for' => 'selected_data',
296 ],
297 ],
298 ],
299 ];
300 }
301
302 function get_screen_4() {
303 return [];
304 }
305
306 function get_screen_5() {
307 global $photonic_flickr_media, $photonic_flickr_title_caption;
308 $output = [
309 'flickr' => [
310 'L1' => [
311 'sort' => [
312 'desc' => esc_html__('Sort by', 'photonic'),
313 'type' => 'select',
314 'options' => [
315 '' => '',
316 'date-posted-desc' => esc_html__('Date posted, descending', 'photonic'),
317 'date-posted-asc' => esc_html__('Date posted, ascending', 'photonic'),
318 'date-taken-asc' => esc_html__('Date taken, ascending', 'photonic'),
319 'date-taken-desc' => esc_html__('Date taken, descending', 'photonic'),
320 'interestingness-desc' => esc_html__('Interestingness, descending', 'photonic'),
321 'interestingness-asc' => esc_html__('Interestingness, ascending', 'photonic'),
322 'relevance' => esc_html__('Relevance', 'photonic'),
323 ],
324 ],
325 'media' => [
326 'desc' => esc_html__('Media to Show', 'photonic'),
327 'type' => 'select',
328 'options' => Utilities::media_options(true, $photonic_flickr_media),
329 'std' => '',
330 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Media to show</em>'),
331 ],
332 'caption' => [
333 'desc' => esc_html__('Photo titles and captions', 'photonic'),
334 'type' => 'select',
335 'options' => Utilities::title_caption_options(true, $photonic_flickr_title_caption),
336 'std' => '',
337 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Photo titles and captions</em>'),
338 ],
339 'headers' => [
340 'desc' => esc_html__('Show Header', 'photonic'),
341 'type' => 'select',
342 'options' => [
343 '' => $this->default_from_settings,
344 'none' => esc_html__('No header', 'photonic'),
345 'title' => esc_html__('Title only', 'photonic'),
346 'thumbnail' => esc_html__('Thumbnail only', 'photonic'),
347 'counter' => esc_html__('Counts only', 'photonic'),
348 'title,counter' => esc_html__('Title and counts', 'photonic'),
349 'thumbnail,counter' => esc_html__('Thumbnail and counts', 'photonic'),
350 'thumbnail,title' => esc_html__('Thumbnail and title', 'photonic'),
351 'thumbnail,title,counter' => esc_html__('Thumbnail, title and counts', 'photonic'),
352 ],
353 'conditions' => ['display_type' => ['album-photo', 'gallery-photo']],
354 ],
355 ],
356 'L2' => [],
357 'L3' => [
358 'collections_display' => [
359 'desc' => esc_html__('Expand Collections', 'photonic'),
360 'type' => 'select',
361 'options' => [
362 '' => '',
363 'lazy' => esc_html__('Lazy loading', 'photonic'),
364 'expanded' => esc_html__('Expanded upfront', 'photonic'),
365 ],
366 'hint' => sprintf(esc_html__('The Collections API is slow, so, if you are displaying collections, pick %1$slazy loading%2$s if your collections have many albums / photosets.', 'photonic'),
367 '<a href="https://aquoid.com/plugins/photonic/flickr/flickr-collections/" target="_blank">', '</a>'),
368 ],
369 'headers' => [
370 'desc' => esc_html__('Show Header', 'photonic'),
371 'type' => 'select',
372 'options' => [
373 '' => $this->default_from_settings,
374 'none' => esc_html__('No header', 'photonic'),
375 'title' => esc_html__('Title only', 'photonic'),
376 'thumbnail' => esc_html__('Thumbnail only', 'photonic'),
377 'counter' => esc_html__('Counts only', 'photonic'),
378 'title,counter' => esc_html__('Title and counts', 'photonic'),
379 'thumbnail,counter' => esc_html__('Thumbnail and counts', 'photonic'),
380 'thumbnail,title' => esc_html__('Thumbnail and title', 'photonic'),
381 'thumbnail,title,counter' => esc_html__('Thumbnail, title and counts', 'photonic'),
382 ],
383 ],
384 ],
385 'main_size' => [
386 'desc' => esc_html__('Main image size', 'photonic'),
387 'type' => 'select',
388 'options' => $this->allowed_image_sizes['flickr']['main_size'],
389 'std' => '',
390 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Main image size</em>'),
391 ],
392 'video_size' => [
393 'desc' => esc_html__('Main video size', 'photonic'),
394 'type' => 'select',
395 'options' => $this->allowed_image_sizes['flickr']['video_size'],
396 'std' => '',
397 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Video size</em>'),
398 ],
399 ]
400 ];
401 // $output['slideshow'] = $this->get_slideshow_options();
402 return $output;
403 }
404
405 function get_square_size_options() {
406 return [
407 'thumb_size' => [
408 'desc' => esc_html__('Thumbnail size', 'photonic'),
409 'type' => 'select',
410 'options' => $this->allowed_image_sizes['flickr']['thumb_size'],
411 'std' => '',
412 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Thumbnail size</em>'),
413 ],
414 ];
415 }
416
417 function get_random_size_options() {
418 return [
419 'tile_size' => [
420 'desc' => esc_html__('Tile size', 'photonic'),
421 'type' => 'select',
422 'options' => $this->allowed_image_sizes['flickr']['tile_size'],
423 'std' => '',
424 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Tile image size</em>'),
425 ],
426 ];
427 }
428
429 function make_request($display_type, $for, $flattened_fields) {
430 if ($display_type != 'multi-photo' && in_array($for, ['group', 'any'])) {
431 $err = esc_html__('Incompatible selections:', 'photonic') . "<br/>\n";
432 $err .= $flattened_fields['display_type']['desc'] . ": " . $flattened_fields['display_type']['options'][$display_type] . "<br/>\n";
433 $err .= $flattened_fields['for']['desc'] . ": " . $flattened_fields['for']['options'][$for] . "<br/>\n";
434 return ['error' => $err];
435 }
436
437 $group = sanitize_text_field($_POST['group']);
438 $login = sanitize_text_field($_POST['login']);
439 global $photonic_flickr_default_user, $photonic_flickr_api_key;
440 if ($for == 'current' && empty($photonic_flickr_default_user)) {
441 return ['error' => sprintf(esc_html__('Default user not defined under %1$s. %2$sSelect "Another user" and put in your user id.', 'photonic'),
442 '<em>Photonic &rarr; Settings &rarr; Flickr &rarr; Flickr Settings &rarr; Default User</em>', '<br/>')];
443 }
444
445 if (($for == 'group' && empty($group)) || ($for == 'other' && empty($login))) {
446 return ['error' => $this->error_mandatory];
447 }
448
449 $parameters = [];
450 $user = $for == 'current' ? $photonic_flickr_default_user : ($for == 'other' ? $login : '');
451 if (($for == 'other' || $for == 'current') && !empty($user)) {
452 $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupUser&url=' . urlencode('https://www.flickr.com/photos/') . $user;
453 $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]);
454 $response = $this->process_response($response, 'flickr', 'user');
455 if (!empty($response['error'])) {
456 // Maybe the user provided the full URL instead of just the user name?
457 $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupUser&url=' . urlencode($user);
458 $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]);
459 $response = $this->process_response($response, 'flickr', 'user');
460 if (!empty($response['error'])) {
461 return $response;
462 }
463 $parameters = array_merge($response['success'], $parameters);
464 }
465 else {
466 $parameters = array_merge($response['success'], $parameters);
467 }
468 }
469
470 if ($for == 'group' && !empty($group)) {
471 $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupGroup&url=' . urlencode('https://www.flickr.com/groups/') . $group;
472 $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]);
473 $response = $this->process_response($response, 'flickr', 'group');
474 if (!empty($response['error'])) {
475 // Maybe the user provided the full URL instead of just the group name?
476 $url = 'https://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=' . $photonic_flickr_api_key . '&method=flickr.urls.lookupGroup&url=' . urlencode($user);
477 $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]);
478 $response = $this->process_response($response, 'flickr', 'group');
479 if (!empty($response['error'])) {
480 return $response;
481 }
482 $parameters = array_merge($response['success'], $parameters);
483 }
484 else {
485 $parameters = array_merge($response['success'], $parameters);
486 }
487 }
488
489 // All OK so far. Let's try to get the data for the next screen
490 $parameters['api_key'] = $photonic_flickr_api_key;
491 $parameters['format'] = 'json';
492 $parameters['nojsoncallback'] = 1;
493
494 if ($display_type == 'single-photo') {
495 $parameters['view'] = 'photo';
496 $parameters['method'] = 'flickr.photos.search';
497 $parameters['per_page'] = 500;
498 }
499 else if ($display_type == 'multi-photo') {
500 $parameters['view'] = 'photos';
501 $parameters['method'] = 'flickr.photos.search';
502 }
503 else if ($display_type == 'multi-album' || $display_type == 'album-photo') {
504 $parameters['view'] = 'photosets';
505 $parameters['method'] = 'flickr.photosets.getList';
506 }
507 else if ($display_type == 'multi-gallery' || $display_type == 'gallery-photo') {
508 $parameters['view'] = 'galleries';
509 $parameters['method'] = 'flickr.galleries.getList';
510 $parameters['per_page'] = 500;
511 }
512 else if ($display_type == 'collection' || $display_type == 'collections') {
513 $parameters['view'] = 'collections';
514 $parameters['method'] = 'flickr.collections.getTree';
515 }
516
517 global $photonic_flickr_access_token;
518 require_once(PHOTONIC_PATH.'/Modules/Flickr.php');
519 $module = \Photonic_Plugin\Modules\Flickr::get_instance();
520 if (!empty($photonic_flickr_access_token)) {
521 $parameters = $module->sign_call('https://api.flickr.com/services/rest/', 'GET', $parameters);
522 }
523
524 $url = add_query_arg($parameters, 'https://api.flickr.com/services/rest/');
525 $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY]);
526
527 $hidden = [];
528 if (isset($parameters['user_id'])) $hidden['user_id'] = $parameters['user_id'];
529 if (isset($parameters['group_id'])) $hidden['group_id'] = $parameters['group_id'];
530
531 return [$response, $hidden, $url];
532 }
533
534 /**
535 * Processes a response from Flickr to build it out into a gallery of thumbnails. Flickr has L1, L2 and L3 displays in the flow.
536 *
537 * @param $response
538 * @param $display_type
539 * @param null $url
540 * @param array $pagination
541 * @return mixed|void
542 */
543 function process_response($response, $display_type, $url = null, &$pagination = []) {
544 $objects = [];
545 $body = json_decode(wp_remote_retrieve_body($response));
546
547 if (isset($body->stat) && $body->stat == 'fail') {
548 Photonic::log($response);
549 return ['error' => $body->message];
550 }
551
552 if (isset($body->photosets) && isset($body->photosets->photoset)) {
553 // $page = (int)($body->photosets->page); // Not needed because apparently the photosets.getList call returns all photosets for now
554 // $pages = (int)($body->photosets->pages); // Not needed because apparently the photosets.getList call returns all photosets for now
555 $photosets = $body->photosets->photoset;
556 foreach ($photosets as $flickr_object) {
557 $object = [];
558 $object['id'] = $flickr_object->id;
559 $object['title'] = esc_attr($flickr_object->title->_content);
560 $object['counters'] = [];
561 if (!empty($flickr_object->photos)) $object['counters'][] = esc_html(sprintf(_n('%s photo', '%s photos', $flickr_object->photos, 'photonic'), $flickr_object->photos));
562 if (!empty($flickr_object->videos)) $object['counters'][] = esc_html(sprintf(_n('%s video', '%s videos', $flickr_object->videos, 'photonic'), $flickr_object->videos));
563 $object['thumbnail'] = "https://farm" . $flickr_object->farm . ".staticflickr.com/" . $flickr_object->server . "/" . $flickr_object->primary . "_" . $flickr_object->secret . "_q.jpg";
564 $objects[] = $object;
565 }
566 }
567 else if (isset($body->galleries) && isset($body->galleries->gallery)) {
568 $page = (int)($body->galleries->page);
569 $pages = (int)($body->galleries->pages);
570 $galleries = $body->galleries->gallery;
571 foreach ($galleries as $flickr_object) {
572 $object = [];
573 $object['id'] = substr($flickr_object->id, strpos($flickr_object->id, '-') + 1); //$flickr_object->id;
574 $object['title'] = esc_attr($flickr_object->title->_content);
575 $object['counters'] = [];
576 if (!empty($flickr_object->count_photos)) $object['counters'][] = esc_html(sprintf(_n('%s photo', '%s photos', $flickr_object->count_photos, 'photonic'), $flickr_object->count_photos));
577 if (!empty($flickr_object->count_videos)) $object['counters'][] = esc_html(sprintf(_n('%s video', '%s videos', $flickr_object->count_videos, 'photonic'), $flickr_object->count_videos));
578 $object['thumbnail'] = "https://farm" . $flickr_object->primary_photo_farm . ".staticflickr.com/" . $flickr_object->primary_photo_server . "/" . $flickr_object->primary_photo_id . "_" . $flickr_object->primary_photo_secret . "_q.jpg";
579 $objects[] = $object;
580 }
581 }
582 else if (isset($body->photos) && isset($body->photos->photo)) {
583 if ($display_type == 'single-photo') {
584 $page = (int)($body->photos->page);
585 $pages = (int)($body->photos->pages);
586 if ($page < $pages && !empty($url)) {
587 $url = remove_query_arg('page', $url);
588 $pagination['url'] = add_query_arg(['page' => $page + 1], $url);
589 }
590 }
591 $photos = $body->photos->photo;
592 foreach ($photos as $flickr_object) {
593 $object = [];
594 $object['id'] = $flickr_object->id;
595 $object['title'] = esc_attr($flickr_object->title);
596 $object['thumbnail'] = 'https://farm' . $flickr_object->farm . '.staticflickr.com/' . $flickr_object->server . '/' . $flickr_object->id . '_' . $flickr_object->secret . '_q.jpg';
597 $objects[] = $object;
598 }
599 }
600 else if (isset($body->collections) && isset($body->collections->collection)) {
601 $collections = $body->collections->collection;
602 foreach ($collections as $flickr_object) {
603 $object = [];
604 $object['id'] = substr($flickr_object->id, strpos($flickr_object->id, '-') + 1);
605 $object['title'] = esc_attr($flickr_object->title);
606 $object['counters'] = [];
607 if (!empty($flickr_object->set)) $object['counters'][] = esc_html(sprintf(_n('%s album', '%s albums', count($flickr_object->set), 'photonic'), count($flickr_object->set)));
608 $object['thumbnail'] = $flickr_object->iconlarge;
609 $objects[] = $object;
610 }
611 }
612 else if (isset($body->user)) {
613 return ['success' => ['user_id' => $body->user->id]];
614 }
615 else if (isset($body->group)) {
616 return ['success' => ['group_id' => $body->group->id]];
617 }
618
619 if (!empty($page) && !empty($pages) && $page < $pages && !empty($url)) {
620 $url = remove_query_arg('page', $url);
621 $pagination['url'] = add_query_arg(['page' => $page + 1], $url);
622 }
623 return $objects;
624 }
625
626 /**
627 * @param $display_type
628 * @return array|mixed
629 */
630 function construct_shortcode_from_screen_selections($display_type) {
631 $short_code = [];
632
633 if ($display_type == 'single-photo') {
634 $short_code['view'] = 'photo';
635 $short_code['photo_id'] = sanitize_text_field($_POST['selected_data']);
636 }
637 else if ($display_type == 'multi-photo') {
638 $short_code['view'] = 'photos';
639 }
640 else if ($display_type == 'album-photo') {
641 $short_code['view'] = 'photosets';
642 $short_code['photoset_id'] = sanitize_text_field($_POST['selected_data']);
643 }
644 else if ($display_type == 'gallery-photo') {
645 $short_code['view'] = 'galleries';
646 $short_code['gallery_id'] = sanitize_text_field($_POST['selected_data']);
647 }
648 else if ($display_type == 'multi-album') {
649 $short_code['view'] = 'photosets';
650 }
651 else if ($display_type == 'multi-gallery') {
652 $short_code['view'] = 'galleries';
653 }
654 else if ($display_type == 'collection') {
655 $short_code['view'] = 'collections';
656 $short_code['collection_id'] = sanitize_text_field($_POST['selected_data']);
657 }
658 else if ($display_type == 'collections') {
659 $short_code['view'] = 'collections';
660 }
661
662 return $short_code;
663 }
664
665 /**
666 * @param $input
667 * @return array|mixed
668 */
669 function deconstruct_shortcode_to_screen_selections($input) {
670 $deconstructed = [];
671
672 // Potential for an existing (old) shortcode to not have a user_id. E.g. Just defining photoset_id.
673 // Rather than defaulting to the default user, we will make the user put it in this time.
674 if (!empty($input->user_id)) {
675 $deconstructed['for'] = 'other';
676 $deconstructed['login'] = $input->user_id;
677 }
678 else if (!empty($input->group_id)) {
679 $deconstructed['for'] = 'group';
680 $deconstructed['group'] = $input->group_id;
681 }
682
683 if (!empty($input->view)) {
684 if ($input->view == 'collections' && empty($input->collection_id)) {
685 $deconstructed['display_type'] = 'collections';
686 }
687 else if ($input->view == 'galleries' && empty($input->gallery_id)) {
688 $deconstructed['display_type'] = 'multi-gallery';
689 }
690 else if ($input->view == 'photosets' && empty($input->photoset_id)) {
691 $deconstructed['display_type'] = 'multi-album';
692 }
693 else if ($input->view == 'photos') {
694 $deconstructed['display_type'] = 'multi-photo';
695 }
696 }
697
698 if (!empty($input->collection_id)) {
699 $deconstructed['display_type'] = 'collection';
700 $deconstructed['selected_data'] = $input->collection_id;
701 }
702 else if (!empty($input->gallery_id)) {
703 $deconstructed['display_type'] = 'gallery-photo';
704 $deconstructed['selected_data'] = $input->gallery_id;
705 }
706 else if (!empty($input->photoset_id)) {
707 $deconstructed['display_type'] = 'album-photo';
708 $deconstructed['selected_data'] = $input->photoset_id;
709 }
710 else if (!empty($input->photo_id)) {
711 $deconstructed['display_type'] = 'single-photo';
712 $deconstructed['selected_data'] = $input->photo_id;
713 }
714
715 return $deconstructed;
716 }
717 }