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

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

730 lines 28.3 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 use Requests;
7
8 class Zenfolio extends Source {
9 private static $instance;
10
11 protected function __construct() {
12 parent::__construct();
13 $this->provider = 'zenfolio';
14
15 global $photonic_zenfolio_thumb_size, $photonic_zenfolio_tile_size, $photonic_zenfolio_main_size, $photonic_zenfolio_video_size;
16 $this->allowed_image_sizes['zenfolio'] = [
17 'thumb_size' => [
18 '' => $this->default_from_settings,
19 "1" => esc_html__("Square thumbnail, 60 &times; 60px, cropped square", 'photonic'),
20 "0" => esc_html__("Small thumbnail, upto 80 &times; 80px", 'photonic'),
21 "10" => esc_html__("Medium thumbnail, upto 120 &times; 120px", 'photonic'),
22 "11" => esc_html__("Large thumbnail, upto 120 &times; 120px", 'photonic'),
23 "2" => esc_html__("Small image, upto 400 &times; 400px", 'photonic'),
24 ],
25 'tile_size' => [
26 '' => $this->default_from_settings,
27 'same' => esc_html__('Same as Main image size', 'photonic'),
28 '2' => esc_html__('Small image, upto 400 &times; 400px', 'photonic'),
29 '3' => esc_html__('Medium image, upto 580 &times; 450px', 'photonic'),
30 '4' => esc_html__('Large image, upto 800 &times; 630px', 'photonic'),
31 '5' => esc_html__('X-Large image, upto 1100 &times; 850px', 'photonic'),
32 '6' => esc_html__('XX-Large image, upto 1550 &times; 960px', 'photonic'),
33 ],
34 'main_size' => [
35 '' => $this->default_from_settings,
36 '2' => esc_html__('Small image, upto 400 &times; 400px', 'photonic'),
37 '3' => esc_html__('Medium image, upto 580 &times; 450px', 'photonic'),
38 '4' => esc_html__('Large image, upto 800 &times; 630px', 'photonic'),
39 '5' => esc_html__('X-Large image, upto 1100 &times; 850px', 'photonic'),
40 '6' => esc_html__('XX-Large image, upto 1550 &times; 960px', 'photonic'),
41 ],
42 'video_size' => [
43 '' => $this->default_from_settings,
44 '220' => esc_html__('360p resolution (MP4)', 'photonic'),
45 '215' => esc_html__('480p resolution (MP4)', 'photonic'),
46 '210' => esc_html__('720p resolution (MP4)', 'photonic'),
47 '200' => esc_html__('1080p resolution (MP4)', 'photonic'),
48 ],
49 ];
50 $this->allowed_image_sizes['zenfolio']['thumb_size'][''] .= ' - '.$this->allowed_image_sizes['zenfolio']['thumb_size'][$photonic_zenfolio_thumb_size];
51 $this->allowed_image_sizes['zenfolio']['tile_size'][''] .= ' - '.$this->allowed_image_sizes['zenfolio']['tile_size'][$photonic_zenfolio_tile_size];
52 $this->allowed_image_sizes['zenfolio']['main_size'][''] .= ' - '.$this->allowed_image_sizes['zenfolio']['main_size'][$photonic_zenfolio_main_size];
53 $this->allowed_image_sizes['zenfolio']['video_size'][''] .= ' - '.$this->allowed_image_sizes['zenfolio']['video_size'][$photonic_zenfolio_video_size];
54 }
55
56 public static function get_instance() {
57 if (self::$instance == null) {
58 self::$instance = new Zenfolio();
59 }
60 return self::$instance;
61 }
62
63 function get_screen_2() {
64 return [
65 'header' => esc_html__('Choose Type of Gallery', 'photonic'),
66 'display' => [
67 'kind' => [
68 'type' => 'field_list',
69 'list_type' => 'sequence',
70 'list' => [
71 'display_type' => [
72 'desc' => esc_html__('What do you want to show?', 'photonic'),
73 'type' => 'select',
74 'options' => [
75 '' => '',
76 'single-photo' => esc_html__('Single Photo', 'photonic'),
77 'multi-photo' => esc_html__('Multiple Photos', 'photonic'),
78 'gallery-photo' => esc_html__('Photos from a Gallery or Collection', 'photonic'),
79 // 'collection-photo' => esc_html__('Photos from a Collection', 'photonic'),
80 'multi-gallery' => esc_html__('Multiple Galleries', 'photonic'),
81 'multi-collection' => esc_html__('Multiple Collections', 'photonic'),
82 'multi-gallery-collection' => esc_html__('Multiple Galleries and Collections', 'photonic'),
83 'group' => esc_html__('Single Group', 'photonic'),
84 'group-hierarchy' => esc_html__('Group Hierarchy', 'photonic'),
85 ],
86 'req' => 1,
87 ],
88 'for' => [
89 'desc' => esc_html__('For whom?', 'photonic'),
90 'type' => 'radio',
91 'options' => [
92 'current' => sprintf(esc_html__('Current user (Defined under %s)', 'photonic'), '<em>Photonic &rarr; Settings &rarr; Zenfolio &rarr; Zenfolio Photo Settings &rarr; Default user</em>'),
93 'other' => esc_html__('Another user', 'photonic'),
94 'any' => esc_html__('All users', 'photonic'),
95 ],
96 'option-conditions' => [
97 'current' => ['display_type' => ['single-photo', 'gallery-photo', 'collection-photo', 'multi-gallery', 'multi-collection', 'multi-gallery-collection', 'group', 'group-hierarchy']],
98 'other' => ['display_type' => ['single-photo', 'gallery-photo', 'collection-photo', 'multi-gallery', 'multi-collection', 'multi-gallery-collection', 'group', 'group-hierarchy']],
99 'any' => ['display_type' => ['multi-photo', /*'multi-gallery', 'multi-collection', */]],
100 ],
101 'req' => 1,
102 ],
103 'login_name' => [
104 'desc' => sprintf(esc_html__('User name, e.g. %s', 'photonic'), 'https://<span style="text-decoration: underline">username</span>.zenfolio.com/'),
105 'type' => 'text',
106 'std' => '',
107 'conditions' => ['for' => ['other']],
108 'req' => 1,
109 ],
110 ],
111 ],
112 ],
113 ];
114 }
115
116 function get_screen_3() {
117 return [
118 'header' => esc_html__('Build your gallery', 'photonic'),
119 'single-photo' => [
120 'header' => esc_html__('Pick a photo', 'photonic'),
121 'desc' => esc_html__('From the list below pick the single photo you wish to display.', 'photonic'),
122 'display' => [
123 'container' => [
124 'type' => 'thumbnail-selector',
125 'mode' => 'single',
126 'for' => 'selected_data',
127 ],
128 ],
129 ],
130 'multi-photo' => [
131 'header' => esc_html__('Photos from all users', 'photonic'),
132 'desc' => esc_html__('You can show photos from all users, and apply text or category filters to show some of them.', 'photonic'),
133 'display' => [
134 'text' => [
135 'desc' => esc_html__('With text', 'photonic'),
136 'type' => 'text',
137 ],
138
139 'category_code' => [
140 'desc' => esc_html__('Category', 'photonic'),
141 'type' => 'select',
142 'options' => $this->get_zenfolio_categories(),
143 ],
144
145 'container' => [
146 'type' => 'thumbnail-selector',
147 'mode' => 'none',
148 'for' => 'selected_data',
149 ],
150 ],
151 ],
152 'gallery-photo' => [
153 'header' => esc_html__('Pick your gallery', 'photonic'),
154 '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'),
155 'display' => [
156 'container' => [
157 'type' => 'thumbnail-selector',
158 'mode' => 'single',
159 'for' => 'selected_data',
160 ],
161 ],
162 ],
163 'collection-photo' => [
164 'header' => esc_html__('Pick your collection', 'photonic'),
165 'desc' => esc_html__('From the list below pick the collection whose photos you wish to display. Photos from that collection will show up as thumbnails.', 'photonic'),
166 'display' => [
167 'container' => [
168 'type' => 'thumbnail-selector',
169 'mode' => 'single',
170 'for' => 'selected_data',
171 ],
172 ],
173 ],
174 'multi-gallery' => [
175 'header' => esc_html__('Pick your galleries', 'photonic'),
176 'desc' => esc_html__('From the list below pick the galleries you wish to display. Each album will show up as a single thumbnail. Note that text and category filters are not applied here but will be applied on the front-end.', 'photonic'),
177 'display' => [
178 'selection' => [
179 'desc' => esc_html__('What do you want to show?', 'photonic'),
180 'type' => 'select',
181 'options' => [
182 'all' => esc_html__('Automatic all (will automatically add new galleries)', 'photonic'),
183 'selected' => esc_html__('Selected galleries', 'photonic'),
184 'not-selected' => esc_html__('All except selected galleries', 'photonic'),
185 ],
186 'req' => 1,
187 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'),
188 ],
189
190 'text' => [
191 'desc' => esc_html__('With text', 'photonic'),
192 'type' => 'text',
193 ],
194
195 'category_code' => [
196 'desc' => esc_html__('Category', 'photonic'),
197 'type' => 'select',
198 'options' => $this->get_zenfolio_categories(),
199 ],
200
201 'container' => [
202 'type' => 'thumbnail-selector',
203 'mode' => 'multi',
204 'for' => 'selected_data',
205 ],
206 ],
207 ],
208 'multi-collection' => [
209 'header' => esc_html__('Pick your collections', 'photonic'),
210 'desc' => esc_html__('From the list below pick the collections you wish to display. Each collection will show up as a single thumbnail. Note that text and category filters are not applied here but will be applied on the front-end.', 'photonic'),
211 'display' => [
212 'selection' => [
213 'desc' => esc_html__('What do you want to show?', 'photonic'),
214 'type' => 'select',
215 'options' => [
216 'all' => esc_html__('Automatic all (will automatically add new collections)', 'photonic'),
217 'selected' => esc_html__('Selected collections', 'photonic'),
218 'not-selected' => esc_html__('All except selected collections', 'photonic'),
219 ],
220 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'),
221 'req' => 1,
222 ],
223
224 'text' => [
225 'desc' => esc_html__('With text', 'photonic'),
226 'type' => 'text',
227 ],
228
229 'category_code' => [
230 'desc' => esc_html__('Category', 'photonic'),
231 'type' => 'select',
232 'options' => $this->get_zenfolio_categories(),
233 ],
234
235 'container' => [
236 'type' => 'thumbnail-selector',
237 'mode' => 'multi',
238 'for' => 'selected_data',
239 ],
240 ],
241 ],
242 'multi-gallery-collection' => [
243 'header' => esc_html__('Pick your galleries and collections', 'photonic'),
244 'desc' => esc_html__('From the list below pick the galleries and collections you wish to display. Each gallery and collection will show up as a single thumbnail. Note that text and category filters are not applied here but will be applied on the front-end.', 'photonic'),
245 'display' => [
246 'selection' => [
247 'desc' => esc_html__('What do you want to show?', 'photonic'),
248 'type' => 'select',
249 'options' => [
250 'all' => esc_html__('Automatic all (will automatically add new galleries and collections)', 'photonic'),
251 'selected' => esc_html__('Selected galleries and collections', 'photonic'),
252 'not-selected' => esc_html__('All except selected galleries and collections', 'photonic'),
253 ],
254 'hint' => esc_html__('If you pick "Automatic all" your selections below will be ignored.', 'photonic'),
255 'req' => 1,
256 ],
257
258 'text' => [
259 'desc' => esc_html__('With text', 'photonic'),
260 'type' => 'text',
261 ],
262
263 'category_code' => [
264 'desc' => esc_html__('Category', 'photonic'),
265 'type' => 'select',
266 'options' => $this->get_zenfolio_categories(),
267 ],
268
269 'container' => [
270 'type' => 'thumbnail-selector',
271 'mode' => 'multi',
272 'for' => 'selected_data',
273 ],
274 ],
275 ],
276 'group' => [
277 'header' => esc_html__('Pick your group', 'photonic'),
278 'desc' => esc_html__('From the list below pick the group you wish to display. The galleries / collections within the group will show up as single thumbnails.', 'photonic'),
279 'display' => [
280 'container' => [
281 'type' => 'thumbnail-selector',
282 'mode' => 'single',
283 'for' => 'selected_data',
284 ],
285 ],
286 ],
287 'group-hierarchy' => [
288 'header' => esc_html__('Your group hierarchy', 'photonic'),
289 'desc' => esc_html__('The following group hierarchy will be displayed on your site. Only top level groups and galleries / collections are shown here. The galleries / collections within the groups will show up as single thumbnails and can be clicked to show the images within.', 'photonic'),
290 'display' => [
291 'container' => [
292 'type' => 'thumbnail-selector',
293 'mode' => 'none',
294 'for' => 'selected_data',
295 ],
296 ],
297 ],
298 ];
299 }
300
301 function get_screen_4() {
302 return [];
303 }
304
305 function get_screen_5() {
306 global $photonic_zenfolio_media, $photonic_zenfolio_title_caption;
307 return [
308 'zenfolio' => [
309 'L1' => [
310 'media' => [
311 'desc' => esc_html__('Media to Show', 'photonic'),
312 'type' => 'select',
313 'options' => Utilities::media_options(true, $photonic_zenfolio_media),
314 'std' => '',
315 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Zenfolio &rarr; Zenfolio Photo Settings &rarr; Media to show</em>'),
316 ],
317 'caption' => [
318 'desc' => esc_html__('Photo titles and captions', 'photonic'),
319 'type' => 'select',
320 'options' => Utilities::title_caption_options(true, $photonic_zenfolio_title_caption),
321 'std' => '',
322 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Zenfolio &rarr; Zenfolio Photo Settings &rarr; Photo titles and captions</em>'),
323 ],
324 'sort_order' => [
325 'desc' => esc_html__('Search results sort order', 'photonic'),
326 'type' => 'select',
327 'options' => [
328 '' => '',
329 'Date' => esc_html__('Date', 'photonic'),
330 'Popularity' => esc_html__('Popularity', 'photonic'),
331 'Rank' => esc_html__('Rank (for searching by text only)', 'photonic'),
332 ],
333 ],
334 'password' => [
335 'desc' => esc_html__('Password for password-protected album', 'photonic'),
336 'type' => 'text',
337 'req' => 1,
338 'hint' => esc_html__('You are trying to display photos from a password-protected album. The password is mandatory for such an album.', 'photonic'),
339 'conditions' => ['selection_passworded' => ['1']],
340 ],
341 ],
342 'L2' => [
343 'sort_order' => [
344 'desc' => esc_html__('Search results sort order', 'photonic'),
345 'type' => 'select',
346 'options' => [
347 '' => '',
348 'Date' => esc_html__('Date', 'photonic'),
349 'Popularity' => esc_html__('Popularity', 'photonic'),
350 'Rank' => esc_html__('Rank (for searching by text only)', 'photonic'),
351 ],
352 ],
353 ],
354 'L3' => [
355 'structure' => [
356 'desc' => esc_html__('Group / Hierarchy structure', 'photonic'),
357 'type' => 'select',
358 'options' => [
359 '' => '',
360 'flat' => esc_html__('All photosets shown in single level', 'photonic'),
361 'nested' => esc_html__('Photosets shown nested within groups', 'photonic'),
362 ],
363 'hint' => sprintf(esc_html__('See examples %1$shere%2$s.', 'photonic'), '<a href="https://aquoid.com/plugins/photonic/zenfolio/group-hierarchy/" target="_blank">', '</a>'),
364 ],
365 'headers' => [
366 'desc' => esc_html__('Show Group Header', 'photonic'),
367 'type' => 'select',
368 'options' => [
369 '' => $this->default_from_settings,
370 'none' => esc_html__('No header', 'photonic'),
371 'title' => esc_html__('Title only', 'photonic'),
372 'counter' => esc_html__('Counts only', 'photonic'),
373 'title,counter' => esc_html__('Title and counts', 'photonic'),
374 ],
375 ],
376 ],
377 'main_size' => [
378 'desc' => esc_html__('Main image size', 'photonic'),
379 'type' => 'select',
380 'options' => $this->allowed_image_sizes['zenfolio']['main_size'],
381 'std' => '',
382 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Zenfolio &rarr; Zenfolio Photo Settings &rarr; Main image size</em>'),
383 ],
384 'video_size' => [
385 'desc' => esc_html__('Main video size', 'photonic'),
386 'type' => 'select',
387 'options' => $this->allowed_image_sizes['zenfolio']['video_size'],
388 'std' => '',
389 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Zenfolio &rarr; Zenfolio Photo Settings &rarr; Video size</em>'),
390 ],
391 ]
392 ];
393 }
394
395 private function get_zenfolio_categories() {
396 $response = wp_remote_request('https://api.zenfolio.com/api/1.8/zfapi.asmx/GetCategories', ['sslverify' => PHOTONIC_SSL_VERIFY]);
397 $category_list = ['' => ''];
398
399 if (!is_wp_error($response)) {
400 if (isset($response['response']) && isset($response['response']['code'])) {
401 if ($response['response']['code'] == 200) {
402 if (isset($response['body'])) {
403 $response = simplexml_load_string($response['body']);
404 if (!empty($response->Category)) {
405 $categories = $response->Category;
406 foreach ($categories as $category) {
407 $category_list[esc_attr($category->Code)] = $category->DisplayName;
408 }
409 }
410 }
411 }
412 }
413 }
414 asort($category_list);
415 return $category_list;
416 }
417
418 function get_square_size_options() {
419 return [
420 'thumb_size' => [
421 'desc' => esc_html__('Thumbnail size', 'photonic'),
422 'type' => 'select',
423 'options' => $this->allowed_image_sizes['zenfolio']['thumb_size'],
424 'std' => '',
425 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Zenfolio &rarr; Zenfolio Photo Settings &rarr; Thumbnail size</em>'),
426 ],
427 ];
428 }
429
430 function get_random_size_options() {
431 return [
432 'tile_size' => [
433 'desc' => esc_html__('Tile size', 'photonic'),
434 'type' => 'select',
435 'options' => $this->allowed_image_sizes['zenfolio']['tile_size'],
436 'std' => '',
437 'hint' => sprintf($this->default_under, '<em>Photonic &rarr; Settings &rarr; Zenfolio &rarr; Zenfolio Photo Settings &rarr; Tile image size</em>'),
438 ],
439 ];
440 }
441
442 function make_request($display_type, $for, $flattened_fields) {
443 if ((!in_array($display_type, ['multi-photo', /*'multi-gallery', 'multi-collection'*/]) && $for == 'any') ||
444 (!in_array($display_type, ['single-photo', 'gallery-photo', 'collection-photo', 'multi-gallery', 'multi-collection', 'multi-gallery-collection', 'group', 'group-hierarchy']) && in_array($for, ['current', 'other']))) {
445 $err = esc_html__('Incompatible selections:', 'photonic') . "<br/>\n";
446 $err .= $flattened_fields['display_type']['desc'] . ": " . $flattened_fields['display_type']['options'][$display_type] . "<br/>\n";
447 $err .= $flattened_fields['for']['desc'] . ": " . $flattened_fields['for']['options'][$for] . "<br/>\n";
448 return ['error' => $err];
449 }
450
451 if ($for == 'other' && empty($_POST['login_name'])) {
452 return ['error' => $this->error_mandatory];
453 }
454
455 $login_name = sanitize_text_field($_POST['login_name']);
456 global $photonic_zenfolio_default_user;
457 if ($for == 'current' && empty($photonic_zenfolio_default_user)) {
458 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; Zenfolio &rarr; Zenfolio Photo Settings &rarr; Default User</em>', '<br/>')];
459 }
460
461 $parameters = [];
462 $user = $for == 'current' ? $photonic_zenfolio_default_user : ($for == 'other' ? $login_name : '');
463
464 if ($display_type == 'multi-photo') {
465 $url = 'https://api.zenfolio.com/api/1.8/zfapi.asmx/SearchPhotoByCategory';
466 $parameters['searchId'] = '5';
467 $parameters['sortOrder'] = 'Popularity';
468 $parameters['categoryCode'] = '1018000';
469 $parameters['offset'] = 0;
470 $parameters['limit'] = 500;
471 }
472 else if (in_array($display_type, ['multi-gallery', 'multi-collection']) && $for == 'any') {
473 $url = 'https://api.zenfolio.com/api/1.8/zfapi.asmx/SearchSetByCategory';
474 $parameters['searchId'] = '5';
475 $parameters['sortOrder'] = 'Popularity';
476 $parameters['categoryCode'] = '1018000';
477 $parameters['offset'] = 0;
478 $parameters['limit'] = 500;
479 }
480 else {
481 $url = 'https://api.zenfolio.com/api/1.8/zfapi.asmx/LoadGroupHierarchy';
482 $parameters['loginName'] = $user;
483 }
484
485 $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY, 'body' => $parameters]);
486 return [$response, ['login_name' => $user], $url];
487 }
488
489 /**
490 * Processes a response from Zenfolio to build it out into a gallery of thumbnails. Zenfolio has both, L1 and L2 displays in the flow.
491 *
492 * @param $response
493 * @param $display_type
494 * @param $url
495 * @param array $pagination
496 * @return array
497 */
498 function process_response($response, $display_type, $url = null, &$pagination = []) {
499 $body = wp_remote_retrieve_body($response);
500 $body = preg_replace('/"Id":(\d+)/', '"Id":"$1"', $body);
501 $body = simplexml_load_string($body);
502 $objects = [];
503 if ($display_type != 'multi-photo') {
504 if (!empty($body->Elements)) {
505 $elements = $body->Elements;
506 $this->get_zenfolio_groups($objects, $elements, $display_type);
507 }
508 else if (!empty($body->PhotoSets)) {
509 $photosets = $body->PhotoSets;
510 $this->get_zenfolio_groups($objects, $photosets, $display_type);
511 }
512
513 if ($display_type == 'single-photo') {
514 require_once(PHOTONIC_PATH.'/Modules/Zenfolio.php');
515
516 $photo_array = [];
517 $gallery = \Photonic_Plugin\Modules\Zenfolio::get_instance();
518 $requests = [];
519 foreach ($objects as $object) {
520 $parameters = [];
521 $parameters['photoSetId'] = substr($object['id'], 1);
522 $parameters['level'] = 'Level1';
523 $parameters['includePhotos'] = 'true';
524
525 $request = $gallery->prepare_request('LoadPhotoSet', $parameters);
526 $requests[] = [
527 'url' => 'https://api.zenfolio.com/api/1.8/zfapi.asmx',
528 'type' => 'POST',
529 'headers' => $request['headers'],
530 'data' => $request['body'],
531 ];
532 }
533 $responses = Requests::request_multiple($requests);
534 if (!empty($responses)) {
535 foreach ($responses as $ps_response) {
536 if (is_a($ps_response, 'Requests_Response')) {
537 $ps_response = json_decode($ps_response->body);
538 if (!empty($ps_response->result)) {
539 $ps_response = $ps_response->result;
540 if (!empty($ps_response->Photos)) {
541 $photo_array['psid'.$ps_response->Id] = $ps_response->Title;
542 foreach ($ps_response->Photos as $ps_photo) {
543 if (array_key_exists($ps_photo->Id, $photo_array)) {
544 continue;
545 }
546 $photo = [];
547 $photo['id'] = $ps_photo->Id;
548 $url_parts = explode('/', $ps_photo->UrlCore);
549 $photo['alt_id'] = 'h'.dechex((int)substr($url_parts[count($url_parts) - 1], 1));
550 $photo['alt_id2'] = $url_parts[count($url_parts) - 1];
551 $photo['title'] = esc_attr($ps_photo->Title);
552 $photo['thumbnail'] = 'https://' . $ps_photo->UrlHost . $ps_photo->UrlCore . '-1.jpg';
553 $photo_array[$ps_photo->Id] = $photo;
554 }
555 }
556 }
557 }
558 }
559 }
560 $objects = array_values($photo_array);
561 }
562 return $objects;
563 }
564 else {
565 $photos = $body->Photos;
566 foreach ($photos->Photo as $photo) {
567 $object = [];
568 $object['id'] = $photo->Id;
569 $object['title'] = esc_attr($photo->Title);
570 $object['thumbnail'] = 'https://' . $photo->UrlHost . $photo->UrlCore . '-1.jpg';
571 $objects[] = $object;
572 }
573 return $objects;
574 }
575 }
576
577 /**
578 * A recursive call to traverse a Zenfolio group and generate a list of objects, with each object corresponding to a photoset.
579 *
580 * @param $objects
581 * @param $elements
582 * @param $display_type
583 */
584 private function get_zenfolio_groups(&$objects, $elements, $display_type) {
585 if (!empty($elements->PhotoSet) && $display_type != 'group') {
586 foreach ($elements->PhotoSet as $photoset) {
587 if ((($display_type == 'gallery-photo' || $display_type == 'multi-gallery') && $photoset->Type == 'Gallery') ||
588 (($display_type == 'collection-photo' || $display_type == 'multi-collection') && $photoset->Type == 'Collection') ||
589 $display_type == 'multi-gallery-collection' || $display_type == 'group-hierarchy' || $display_type == 'single-photo'
590 ) {
591 $object = [];
592 $page_url = parse_url($photoset->PageUrl);
593 $page_url = $page_url['path'];
594 $page_url = explode('/', $page_url);
595 if (count($page_url) > 1) {
596 $page_url = $page_url[1];
597 }
598
599 if (!is_array($page_url) && preg_match('/^p\d{9}/', $page_url) === 0) {
600 $page_url = [];
601 }
602
603 $object['id'] = !is_array($page_url) ? $page_url : $photoset->Id;
604 $object['alt_id'] = $photoset->Id;
605 $object['title'] = esc_attr($photoset->Title);
606 $object['counters'] = [esc_html(sprintf(_n('%s media item', '%s media items', $photoset->PhotoCount, 'photonic'), $photoset->PhotoCount))];
607
608 $photo = $photoset->TitlePhoto;
609 $object['thumbnail'] = 'https://' . $photo->UrlHost . $photo->UrlCore . '-1.jpg';
610
611 if (!empty($photoset->AccessDescriptor) && !empty($photoset->AccessDescriptor->AccessType) && $photoset->AccessDescriptor->AccessType == 'Password') {
612 $object['passworded'] = 1;
613 }
614
615 $objects[] = $object;
616 }
617 }
618 }
619
620 if (!empty($elements->Group)) {
621 foreach ($elements->Group as $group) {
622 if ($display_type == 'group' || $display_type == 'group-hierarchy') {
623 $object = [];
624 $object['id'] = $group->Id;
625 $object['title'] = $group->Title;
626 $object['thumbnail'] = PHOTONIC_URL.'include/images/placeholder-Ti.png';
627 $objects[] = $object;
628 }
629
630 if ($display_type != 'group-hierarchy' && !empty($group->Elements)) {
631 $this->get_zenfolio_groups($objects, $group->Elements, $display_type);
632 }
633 }
634 }
635 }
636
637 /**
638 * @param $display_type
639 * @return array|mixed
640 */
641 function construct_shortcode_from_screen_selections($display_type) {
642 $short_code = [];
643
644 if ($display_type == 'multi-photo') {
645 $short_code['view'] = 'photos';
646 }
647 else if ($display_type == 'single-photo') {
648 $short_code['view'] = 'photos';
649 $short_code['object_id'] = sanitize_text_field($_POST['selected_data']);
650 }
651 else if ($display_type == 'gallery-photo'/* || $display_type == 'collection-photo'*/) {
652 $short_code['view'] = 'photosets';
653 $short_code['object_id'] = sanitize_text_field($_POST['selected_data']);
654 }
655 else if ($display_type == 'multi-gallery' || $display_type == 'multi-collection' || $display_type == 'multi-gallery-collection') {
656 $short_code['view'] = 'photosets';
657 if ($display_type == 'multi-gallery') {
658 $short_code['photoset_type'] = 'Gallery';
659 }
660 else if ($display_type == 'multi-collection') {
661 $short_code['photoset_type'] = 'Collection';
662 }
663 }
664 else if ($display_type == 'group') {
665 $short_code['view'] = 'group';
666 $short_code['object_id'] = sanitize_text_field($_POST['selected_data']);
667 }
668 else if ($display_type == 'group-hierarchy') {
669 $short_code['view'] = 'hierarchy';
670 }
671
672 return $short_code;
673 }
674
675 /**
676 * @param $input
677 * @return array|mixed
678 */
679 function deconstruct_shortcode_to_screen_selections($input) {
680 $deconstructed = [];
681
682 if (!empty($input->view)) {
683 if ($input->view == 'photos' && empty($input->object_id)) {
684 $deconstructed['display_type'] = 'multi-photo';
685 }
686 else if ($input->view == 'photos' && !empty($input->object_id)) {
687 $deconstructed['display_type'] = 'single-photo';
688 $deconstructed['selected_data'] = $input->object_id;
689 }
690 else if ($input->view == 'photosets') {
691 if (!empty($input->object_id)) {
692 $deconstructed['display_type'] = 'gallery-photo';
693 $deconstructed['selected_data'] = $input->object_id;
694 }
695 else if (empty($input->photoset_type)) {
696 $deconstructed['display_type'] = 'multi-gallery-collection';
697 }
698 else if (strtolower($input->photoset_type) == 'collection') {
699 $deconstructed['display_type'] = 'multi-collection';
700 }
701 else if (strtolower($input->photoset_type) == 'gallery') {
702 $deconstructed['display_type'] = 'multi-gallery';
703 }
704 }
705 else if ($input->view == 'hierarchy') {
706 $deconstructed['display_type'] = 'group-hierarchy';
707 }
708 else if ($input->view == 'group') {
709 $deconstructed['display_type'] = 'group';
710 if (!empty($input->object_id)) {
711 $deconstructed['selected_data'] = $input->object_id;
712 }
713 }
714
715 if ($input->view == 'photosets' || $input->view == 'hierarchy' || $input->view == 'group' ||
716 $deconstructed['display_type'] == 'single-photo') {
717 global $photonic_zenfolio_default_user;
718 if (!isset($input->login_name) && !empty($photonic_zenfolio_default_user)) {
719 $deconstructed['for'] = 'current';
720 }
721 else if (!empty($input->login_name)) {
722 $deconstructed['login_name'] = $input->login_name;
723 $deconstructed['for'] = 'other';
724 }
725 }
726 }
727
728 return $deconstructed;
729 }
730 }