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
photonic / Admin / Wizard / SmugMug.php

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

663 lines 25.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Photonic_Plugin\Admin\Wizard;
4
5 use Photonic_Plugin\Core\Photonic;
6 use Photonic_Plugin\Core\Utilities;
7
8 class SmugMug extends Source {
9 private static ?SmugMug $instance = null;
10
11 protected function __construct() {
12 parent::__construct();
13 $this->provider = 'smugmug';
14 $this->api_base = Wizard::base_apis()['smugmug'];
15
16 global $photonic_smug_thumb_size, $photonic_smug_tile_size, $photonic_smug_main_size, $photonic_smug_video_size;
17 $this->allowed_image_sizes['smugmug'] = [
18 'thumb_size' => [
19 '' => $this->default_from_settings,
20 'Tiny' => esc_html__('Tiny', 'photonic'),
21 'Thumb' => esc_html__('Thumb', 'photonic'),
22 'Small' => esc_html__('Small', 'photonic'),
23 'custom' => esc_html__('Custom', 'photonic'),
24 ],
25 'tile_size' => [
26 '' => $this->default_from_settings,
27 'same' => esc_html__('Same as Main image size', 'photonic'),
28 '4K' => esc_html__('4K (not always available)', 'photonic'),
29 '5K' => esc_html__('5K (not always available)', 'photonic'),
30 'Medium' => esc_html__('Medium', 'photonic'),
31 'Original' => esc_html__('Original (not always available)', 'photonic'),
32 'Large' => esc_html__('Large', 'photonic'),
33 'Largest' => esc_html__('Largest available', 'photonic'),
34 'XLarge' => esc_html__('XLarge (not always available)', 'photonic'),
35 'X2Large' => esc_html__('X2Large (not always available)', 'photonic'),
36 'X3Large' => esc_html__('X3Large (not always available)', 'photonic'),
37 'X4Large' => esc_html__('X4Large (not always available)', 'photonic'),
38 'X5Large' => esc_html__('X5Large (not always available)', 'photonic'),
39 ],
40 'main_size' => [
41 '' => $this->default_from_settings,
42 '4K' => esc_html__('4K (not always available)', 'photonic'),
43 '5K' => esc_html__('5K (not always available)', 'photonic'),
44 'Medium' => esc_html__('Medium', 'photonic'),
45 'Original' => esc_html__('Original (not always available)', 'photonic'),
46 'Large' => esc_html__('Large', 'photonic'),
47 'Largest' => esc_html__('Largest available', 'photonic'),
48 'XLarge' => esc_html__('XLarge (not always available)', 'photonic'),
49 'X2Large' => esc_html__('X2Large (not always available)', 'photonic'),
50 'X3Large' => esc_html__('X3Large (not always available)', 'photonic'),
51 'X4Large' => esc_html__('X4Large (not always available)', 'photonic'),
52 'X5Large' => esc_html__('X5Large (not always available)', 'photonic'),
53 ],
54 'video_size' => [
55 '' => $this->default_from_settings,
56 '110' => esc_html__('110px along longest side', 'photonic'),
57 '200' => esc_html__('200px along longest side', 'photonic'),
58 '320' => esc_html__('320px along longest side', 'photonic'),
59 '640' => esc_html__('640px along longest side', 'photonic'),
60 '1280' => esc_html__('1280px along longest side', 'photonic'),
61 '1920' => esc_html__('1920px along longest side', 'photonic'),
62 'Largest' => esc_html__('Largest available', 'photonic'),
63 ],
64 ];
65
66 $this->allowed_image_sizes['smugmug']['thumb_size'][''] .= ' - ' . $this->allowed_image_sizes['smugmug']['thumb_size'][$photonic_smug_thumb_size];
67 $this->allowed_image_sizes['smugmug']['tile_size'][''] .= ' - ' . $this->allowed_image_sizes['smugmug']['tile_size'][$photonic_smug_tile_size];
68 $this->allowed_image_sizes['smugmug']['main_size'][''] .= ' - ' . $this->allowed_image_sizes['smugmug']['main_size'][$photonic_smug_main_size];
69 $this->allowed_image_sizes['smugmug']['video_size'][''] .= ' - ' . $this->allowed_image_sizes['smugmug']['video_size'][$photonic_smug_video_size];
70 }
71
72 public static function get_instance(): SmugMug {
73 if (null === self::$instance) {
74 self::$instance = new SmugMug();
75 }
76 return self::$instance;
77 }
78
79 public function get_screen_2(): array {
80 return [
81 'header' => esc_html__('Choose Type of Gallery', 'photonic'),
82 'display' => [
83 'kind' => [
84 'type' => 'field_list',
85 'list_type' => 'sequence',
86 'list' => [
87 'display_type' => [
88 'desc' => esc_html__('What do you want to show?', 'photonic'),
89 'type' => 'select',
90 'options' => [
91 '' => '',
92 'album-photo' => esc_html__('Photos from an Album', 'photonic'),
93 'folder-photo' => esc_html__('Photos from a Folder', 'photonic'),
94 'user-photo' => esc_html__('Photos from a User', 'photonic'),
95 'multi-album' => esc_html__('Multiple Albums', 'photonic'),
96 'folder' => esc_html__('Albums in a Folder', 'photonic'),
97 'tree' => esc_html__('User Tree', 'photonic'),
98 ],
99 'req' => 1,
100 ],
101 'for' => [
102 'desc' => esc_html__('For whom?', 'photonic'),
103 'type' => 'radio',
104 'options' => [
105 'current' => sprintf(esc_html__('Current user (Defined under %s)', 'photonic'), '<em>Photonic &rarr; Settings &rarr; SmugMug &rarr; SmugMug Settings &rarr; Default user</em>'),
106 'other' => esc_html__('Another user', 'photonic'),
107 ],
108 'req' => 1,
109 ],
110 'user' => [
111 'desc' => sprintf(esc_html__('User name, e.g. %s', 'photonic'), 'https://<span style="text-decoration: underline">username</span>.smugmug.com/'),
112 'type' => 'text',
113 'std' => '',
114 'conditions' => ['for' => ['other']],
115 'req' => 1,
116 ],
117 ],
118 ],
119 ],
120 ];
121 }
122
123 public function get_screen_3(): array {
124 return [
125 'header' => esc_html__('Build your gallery', 'photonic'),
126 'album-photo' => [
127 'header' => esc_html__('Pick your album', 'photonic'),
128 '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'),
129 'display' => [
130 'text' => [
131 'desc' => esc_html__('Only show photos with this text', 'photonic'),
132 'type' => 'text',
133 'std' => '',
134 'hint' => esc_html__('Comma-separated list of values. Filters will be applied on the front-end, not on the display below', 'photonic'),
135 ],
136 'keywords' => [
137 'desc' => esc_html__('Only show photos with these keywords', 'photonic'),
138 'type' => 'text',
139 'std' => '',
140 'hint' => esc_html__('Comma-separated list of values. Filters will be applied on the front-end, not on the display below', 'photonic'),
141 ],
142 'container' => [
143 'type' => 'thumbnail-selector',
144 'mode' => 'single',
145 'for' => 'selected_data',
146 ],
147 ],
148 ],
149 'folder-photo' => [
150 'header' => esc_html__('Pick your folder', 'photonic'),
151 'desc' => esc_html__('From the list below pick the folder whose photos you wish to display. Photos from that folder will show up as thumbnails.', 'photonic'),
152 'display' => [
153 'text' => [
154 'desc' => esc_html__('Only show photos with this text', 'photonic'),
155 'type' => 'text',
156 'std' => '',
157 'hint' => esc_html__('Comma-separated list of values. Filters will be applied on the front-end, not on the display below', 'photonic'),
158 ],
159 'keywords' => [
160 'desc' => esc_html__('Only show photos with these keywords', 'photonic'),
161 'type' => 'text',
162 'std' => '',
163 'hint' => esc_html__('Comma-separated list of values. Filters will be applied on the front-end, not on the display below.', 'photonic'),
164 ],
165 'container' => [
166 'type' => 'thumbnail-selector',
167 'mode' => 'single',
168 'for' => 'selected_data',
169 ],
170 ],
171 ],
172 'user-photo' => [
173 'header' => esc_html__('Photos for a User', 'photonic'),
174 'desc' => esc_html__('The following lists the top-level folders and albums for the selected user. All photos from these folders will show up as thumbnails.', 'photonic'),
175 'display' => [
176 'text' => [
177 'desc' => esc_html__('Only show photos with this text', 'photonic'),
178 'type' => 'text',
179 'std' => '',
180 'hint' => esc_html__('Comma-separated list of values', 'photonic'),
181 ],
182 'keywords' => [
183 'desc' => esc_html__('Only show photos with these keywords', 'photonic'),
184 'type' => 'text',
185 'std' => '',
186 'hint' => esc_html__('Comma-separated list of values', 'photonic'),
187 ],
188 'container' => [
189 'type' => 'thumbnail-selector',
190 'mode' => 'none',
191 'for' => 'selected_data',
192 ],
193 ],
194 ],
195 'multi-album' => [
196 'header' => esc_html__('Pick your albums', 'photonic'),
197 'desc' => esc_html__('From the list below pick the albums you wish to display. Each album will show up as a single thumbnail.', 'photonic'),
198 'display' => [
199 'selection' => [
200 'desc' => esc_html__('What do you want to show?', 'photonic'),
201 'type' => 'select',
202 'options' => [
203 'all' => esc_html__('Automatic all (will automatically add new albums)', 'photonic'),
204 'selected' => esc_html__('Selected albums', 'photonic'),
205 'not-selected' => esc_html__('All except selected albums', 'photonic'),
206 ],
207 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'),
208 'req' => 1,
209 ],
210 'container' => [
211 'type' => 'thumbnail-selector',
212 'mode' => 'multi',
213 'for' => 'selected_data',
214 ],
215 ],
216 ],
217 'folder' => [
218 'header' => esc_html__('Pick your folder', 'photonic'),
219 'desc' => esc_html__('From the list below pick the folder you wish to display. The albums within the folder will show up as single thumbnails.', 'photonic'),
220 'display' => [
221 'container' => [
222 'type' => 'thumbnail-selector',
223 'mode' => 'single',
224 'for' => 'selected_data',
225 ],
226 ],
227 ],
228 'tree' => [
229 'header' => esc_html__('User Tree', 'photonic'),
230 'desc' => esc_html__('The following user tree will be displayed on your site. Only top level folders and albums are shown here. The albums within the folders will show up as single thumbnails and can be clicked to show the images within.', 'photonic'),
231 'display' => [
232 'container' => [
233 'type' => 'thumbnail-selector',
234 'mode' => 'none',
235 'for' => 'selected_data',
236 ],
237 ],
238 ],
239 ];
240 }
241
242 public function get_screen_4(): array {
243 return [];
244 }
245
246 public function get_screen_5(): array {
247 global $photonic_smug_media, $photonic_smug_title_caption;
248 return [
249 'smugmug' => [
250 'L1' => [
251 'media' => [
252 'desc' => esc_html__('Media to Show', 'photonic'),
253 'type' => 'select',
254 'options' => Utilities::media_options(true, $photonic_smug_media),
255 'std' => '',
256 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; SmugMug &rarr; SmugMug Settings &rarr; Media to show</em>'),
257 ],
258 'caption' => [
259 'desc' => esc_html__('Photo titles and captions', 'photonic'),
260 'type' => 'select',
261 'options' => Utilities::title_caption_options(true, $photonic_smug_title_caption),
262 'std' => '',
263 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; SmugMug &rarr; SmugMug Settings &rarr; Photo titles and captions</em>'),
264 ],
265 'password' => [
266 'desc' => esc_html__('Password for password-protected album', 'photonic'),
267 'type' => 'text',
268 'req' => 1,
269 'hint' => esc_html__('You are trying to display photos from a password-protected album. The password is mandatory for such an album.', 'photonic'),
270 'conditions' => ['selection_passworded' => ['1']],
271 ],
272 'sort_method' => [
273 'desc' => esc_html__('Sort photos by', 'photonic'),
274 'type' => 'select',
275 'options' => [
276 '' => '',
277 'DateTaken' => esc_html__('Date Taken', 'photonic'),
278 'DateUploaded' => esc_html__('Date Uploaded', 'photonic'),
279 'Popular' => esc_html__('Popular', 'photonic'),
280 ],
281 ],
282 'sort_order' => [
283 'desc' => esc_html__('Sort order', 'photonic'),
284 'type' => 'select',
285 'options' => [
286 '' => '',
287 'Ascending' => esc_html__('Ascending', 'photonic'),
288 'Descending' => esc_html__('Descending', 'photonic'),
289 ],
290 ],
291 'headers' => $this->get_header_options(),
292 ],
293 'L2' => [
294 'site_password' => [
295 'desc' => esc_html__('Site Password for password-protected sites', 'photonic'),
296 'type' => 'text',
297 'hint' => esc_html__('If you SmugMug site is password-protected you will need to provide the password to be able to show your photos.', 'photonic'),
298 ],
299 'album_sort_order' => [
300 'desc' => esc_html__('Album sort order', 'photonic'),
301 'type' => 'select',
302 'options' => [
303 '' => $this->default_from_settings,
304 'Last Updated (Descending)' => esc_html__('Last Updated (Descending)', 'photonic'),
305 'Last Updated (Ascending)' => esc_html__('Last Updated (Ascending)', 'photonic'),
306 'Date Added (Descending)' => esc_html__('Date Added (Descending)', 'photonic'),
307 'Date Added (Ascending)' => esc_html__('Date Added (Ascending)', 'photonic'),
308 ],
309 ],
310 ],
311 'L3' => [
312 'site_password' => [
313 'desc' => esc_html__('Site Password for password-protected sites', 'photonic'),
314 'type' => 'text',
315 'hint' => esc_html__('If you SmugMug site is password-protected you will need to provide the password to be able to show your photos.', 'photonic'),
316 ],
317 ],
318 'main_size' => [
319 'desc' => esc_html__('Main image size', 'photonic'),
320 'type' => 'select',
321 'options' => $this->allowed_image_sizes['smugmug']['main_size'],
322 'std' => '',
323 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; SmugMug &rarr; SmugMug Settings &rarr; Main image size</em>'),
324 ],
325 'video_size' => [
326 'desc' => esc_html__('Main video size', 'photonic'),
327 'type' => 'select',
328 'options' => $this->allowed_image_sizes['smugmug']['video_size'],
329 'std' => '',
330 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; SmugMug &rarr; SmugMug Settings &rarr; Video size</em>'),
331 ],
332 ]
333 ];
334 }
335
336 public function get_square_size_options(): array {
337 return [
338 'thumb_size' => [
339 'desc' => esc_html__('Thumbnail size', 'photonic'),
340 'type' => 'select',
341 'options' => $this->allowed_image_sizes['smugmug']['thumb_size'],
342 'std' => '',
343 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; SmugMug &rarr; SmugMug Settings &rarr; Thumbnail size</em>'),
344 ],
345 'custom_thumb_size' => [
346 'desc' => esc_html__('Size of custom thumbnail', 'photonic'),
347 'type' => 'text',
348 'hint' => esc_html__('E.g. 300x300 for an image that is 300px on the longest side and 300x300! (with the "!") for a square image', 'photonic'),
349 'conditions' => ['thumb_size' => ['custom']],
350 ],
351 ];
352 }
353
354 public function get_random_size_options(): array {
355 return [
356 'tile_size' => [
357 'desc' => esc_html__('Tile size', 'photonic'),
358 'type' => 'select',
359 'options' => $this->allowed_image_sizes['smugmug']['tile_size'],
360 'std' => '',
361 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; SmugMug &rarr; SmugMug Settings &rarr; Tile image size</em>'),
362 ],
363 ];
364 }
365
366 public function make_request($display_type, $for, $flattened_fields): array {
367 if (check_ajax_referer('photonic-wizard-next-' . get_current_user_id())) {
368 global $photonic_smug_access_token, $photonic_smug_default_user;
369 require_once PHOTONIC_PATH . '/Platforms/SmugMug.php';
370 $module = \Photonic_Plugin\Platforms\SmugMug::get_instance();
371
372 if ('current' === $for && empty($photonic_smug_default_user)) {
373 return ['error' => sprintf(esc_html__('Default user not defined under %1$s. %2$sSelect "Another user" and put in your user id.', 'photonic'), '<em>Photonic &rarr; Settings &rarr; SmugMug &rarr; SmugMug Settings &rarr; Default User</em>', '<br/>')];
374 }
375
376 if ('other' === $for && empty($_POST['user'])) {
377 return ['error' => $this->error_mandatory];
378 }
379
380 $nick_name = sanitize_text_field(wp_unslash($_POST['user']));
381 $user = 'current' === $for ? $photonic_smug_default_user : ('other' === $for ? $nick_name : '');
382 $args = [
383 'APIKey' => $module->api_key,
384 '_accept' => 'application/json',
385 '_expandmethod' => 'inline',
386 '_verbosity' => '1',
387 ];
388
389 if ('album-photo' === $display_type || 'multi-album' === $display_type) {
390 $call = "https://{$this->api_base}/api/v2/user/$user!albums";
391 $args['_expand'] = 'HighlightImage.ImageSizes';
392 $args['count'] = 500;
393 }
394 else {
395 $call = "https://{$this->api_base}/api/v2/user/$user";
396 }
397
398 if (!empty($photonic_smug_access_token)) {
399 $args = $module->sign_call($call, 'GET', $args);
400 }
401
402 if ('folder' === $display_type || 'tree' === $display_type || 'folder-photo' === $display_type || 'user-photo' === $display_type) {
403 // Not able to use wp_remote_request - getting a signature_invalid response
404 $temp = Photonic::http($call, 'GET', $args, null, 300);
405 $temp = $this->process_response($temp, 'smugmug', 'user');
406
407 if (!empty($temp['success'])) {
408 $node = $temp['success'];
409 $call = 'https://' . $this->api_base . $node . '!children';
410 if ('tree' === $display_type || 'user-photo' === $display_type) {
411 $args['_expand'] = 'NodeCoverImage.ImageSizes';
412 }
413 else {
414 global $photonic_smug_nesting_levels;
415 $config = $module->get_config_object(500, $photonic_smug_nesting_levels);
416 $config_str = wp_json_encode($config);
417 $args['_config'] = $config_str;
418 }
419
420 // Sign call again because we made an interim call
421 if (!empty($photonic_smug_access_token)) {
422 unset($args['oauth_consumer_key']);
423 unset($args['oauth_nonce']);
424 unset($args['oauth_signature']);
425 unset($args['oauth_signature_method']);
426 unset($args['oauth_timestamp']);
427 unset($args['oauth_version']);
428 unset($args['oauth_token']);
429 unset($args['oauth_verifier']);
430 $args = $module->sign_call($call, 'GET', $args);
431 }
432 }
433 else {
434 return $temp;
435 }
436 }
437
438 $response = Photonic::http($call, 'GET', $args, null, 300);
439 return [$response, ['nick_name' => $user], $call];
440 }
441 return ['error' => $this->error_unauthorized];
442 }
443
444 /**
445 * Processes a response from SmugMug to build it out into a gallery of thumbnails. SmugMug has L1, L2 and L3 displays in the flow.
446 *
447 * @param $response
448 * @param $display_type
449 * @param null $url
450 * @param array $pagination
451 * @return array
452 */
453 public function process_response($response, $display_type, $url = null, &$pagination = []): array {
454 $objects = [];
455 $body = json_decode(wp_remote_retrieve_body($response));
456 if (isset($body->Response) && isset($body->Response->Album)) {
457 $albums = $body->Response->Album;
458 foreach ($albums as $album) {
459 $object = [];
460 if (isset($album->AlbumKey)) {
461 $object['id'] = $album->AlbumKey;
462 }
463 else {
464 $uri = $album->Uris->Album->Uri;
465 $uri = explode('/', $uri);
466 $object['id'] = $uri[count($uri) - 1];
467 }
468 $object['title'] = !empty($album->Name) ? esc_attr($album->Name) : '';
469 if (isset($album->ImageCount)) {
470 $object['counters'] = [esc_html(sprintf(_n('%s media item', '%s media items', $album->ImageCount, 'photonic'), $album->ImageCount))];
471 }
472
473 $highlight = $album->Uris->HighlightImage;
474 if (isset($highlight->Image)) {
475 $thumbURL = $highlight->Image->Uris->ImageSizes->ImageSizes->ThumbImageUrl;
476 }
477 else {
478 $thumbURL = PHOTONIC_URL . 'include/images/placeholder-Th.png';
479 }
480
481 $object['thumbnail'] = $thumbURL;
482 if (isset($album->SecurityType) && 'Password' === $album->SecurityType) {
483 $object['passworded'] = 1;
484 }
485
486 $objects[] = $object;
487 }
488
489 if (isset($body->Response->Pages)) {
490 $pages = $body->Response->Pages;
491 if ($pages->Start + $pages->Count - 1 < $pages->Total) {
492 $pagination['url'] = add_query_arg(['start' => $pages->Start + $pages->Count, 'count' => $pages->Count], remove_query_arg(['start', 'count'], $url));
493 }
494 }
495 }
496 elseif (isset($body->Response) && isset($body->Response->Node)) {
497 $nodes = $body->Response->Node;
498 foreach ($nodes as $node) {
499 if ('folder' === $display_type && 'Album' === $node->Type) {
500 continue;
501 }
502 elseif ('folder' === $display_type) {
503 $this->get_smugmug_folders($objects, $node);
504 }
505 else {
506 $object = [];
507 if ('Album' === $node->Type) {
508 $uri = $node->Uris->Album->Uri;
509 $uri = explode('/', $uri);
510 $uri = $uri[count($uri) - 1];
511 $object['id'] = $uri;
512 }
513 elseif ('Folder' === $node->Type) {
514 $object['id'] = $node->NodeID;
515 }
516 $object['title'] = !empty($node->Name) ? esc_attr($node->Name) : '';
517 if ('tree' === $display_type) {
518 $object['title'] .= " ({$node->Type})";
519 }
520 if (isset($node->Uris->NodeCoverImage->Image->Uris->ImageSizes->ImageSizes->ThumbImageUrl)) {
521 $object['thumbnail'] = $node->Uris->NodeCoverImage->Image->Uris->ImageSizes->ImageSizes->ThumbImageUrl;
522 }
523 else {
524 $object['thumbnail'] = PHOTONIC_URL . 'include/images/placeholder-Th.png';
525 }
526 $objects[] = $object;
527 }
528 }
529 }
530 elseif (isset($body->Response) && isset($body->Response->User)) {
531 $user = $body->Response->User;
532 return ['success' => $user->Uris->Node->Uri];
533 }
534 else {
535 Photonic::log($body);
536 return ['error' => $this->error_not_found];
537 }
538
539 return $objects;
540 }
541
542 /**
543 * A recursive call to traverse a SmugMug node and generate a list of objects, with each object corresponding to a folder.
544 * Actually a node is used instead of the folder because the folder object is deprecated by SmugMug, but nodes are only being
545 * used for folders in Photonic.
546 *
547 * @param array $objects
548 * @param $node
549 */
550 private function get_smugmug_folders(&$objects, $node) {
551 $object = [];
552 if ('Folder' === $node->Type) {
553 $object['id'] = $node->NodeID;
554 $object['title'] = !empty($node->Name) ? esc_attr($node->Name) : '';
555
556 if (isset($node->Uris->NodeCoverImage->Image->Uris->ImageSizes->ImageSizes->ThumbImageUrl)) {
557 $object['thumbnail'] = $node->Uris->NodeCoverImage->Image->Uris->ImageSizes->ImageSizes->ThumbImageUrl;
558 }
559 else {
560 $object['thumbnail'] = PHOTONIC_URL . 'include/images/placeholder-Th.png';
561 }
562
563 if (isset($node->Uris->ChildNodes->Node)) {
564 $child_nodes = $node->Uris->ChildNodes->Node;
565 if (is_array($child_nodes)) {
566 foreach ($child_nodes as $child_node) {
567 $this->get_smugmug_folders($objects, $child_node);
568 }
569 }
570 }
571 $objects[] = $object;
572 }
573 }
574
575 /**
576 * @param $display_type
577 * @return array
578 */
579 public function construct_shortcode_from_screen_selections($display_type): array {
580 $short_code = [];
581
582 if (check_ajax_referer('photonic-wizard-next-' . get_current_user_id())) {
583 if ('album-photo' === $display_type) {
584 $short_code['view'] = 'album';
585 $short_code['album'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? ''));
586 }
587 elseif ('folder-photo' === $display_type) {
588 $short_code['view'] = 'images';
589 $short_code['folder'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? ''));
590 }
591 elseif ('user-photo' === $display_type) {
592 $short_code['view'] = 'images';
593 }
594 elseif ('multi-album' === $display_type) {
595 $short_code['view'] = 'albums';
596 }
597 elseif ('tree' === $display_type) {
598 $short_code['view'] = 'tree';
599 }
600 elseif ('folder' === $display_type) {
601 $short_code['view'] = 'folder';
602 $short_code['folder'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? ''));
603 }
604 }
605
606 return $short_code;
607 }
608
609 /**
610 * @param $input
611 * @return array
612 */
613 public function deconstruct_shortcode_to_screen_selections($input): array {
614 $deconstructed = [];
615
616 if (!empty($input->view)) {
617 if ('tree' === $input->view) {
618 $deconstructed['display_type'] = 'tree';
619 }
620 elseif ('folder' === $input->view) {
621 $deconstructed['display_type'] = 'folder';
622 }
623 elseif ('albums' === $input->view) {
624 $deconstructed['display_type'] = 'multi-album';
625 }
626 elseif ('images' === $input->view || 'album' === $input->view) {
627 if (!empty($input->album) || !empty($input->album_key) || !empty($input->album_id)) {
628 $deconstructed['display_type'] = 'album-photo';
629 }
630 elseif (!empty($input->folder)) {
631 $deconstructed['display_type'] = 'folder-photo';
632 }
633 elseif (!empty($input->nick_name)) {
634 $deconstructed['display_type'] = 'user-photo';
635 }
636 }
637
638 if (!empty($input->folder)) {
639 $deconstructed['selected_data'] = trim($input->folder);
640 }
641 elseif (!empty($input->album_key)) { // old syntax
642 $deconstructed['selected_data'] = $input->album_key;
643 }
644 elseif (!empty($input->album)) {
645 $album = explode('_', $input->album);
646 if (count($album) === 2) {
647 $deconstructed['selected_data'] = $album[1];
648 }
649 elseif (count($album) === 1) {
650 $deconstructed['selected_data'] = $album[0];
651 }
652 }
653
654 if (!empty($input->nick_name)) {
655 $deconstructed['for'] = 'other';
656 $deconstructed['user'] = $input->nick_name;
657 }
658 }
659
660 return $deconstructed;
661 }
662 }
663