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

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

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