PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.36
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.36
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 3.36, at Admin/Wizard/Zenfolio.php

738 lines 29.8 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\Utilities;
6 use WpOrg\Requests\Requests;
7
8 class Zenfolio extends Source {
9 private static ?Zenfolio $instance = null;
10
11 protected function __construct() {
12 parent::__construct();
13 $this->provider = 'zenfolio';
14 $this->api_base = Wizard::base_apis()['zenfolio'];
15
16 global $photonic_zenfolio_thumb_size, $photonic_zenfolio_tile_size, $photonic_zenfolio_main_size, $photonic_zenfolio_video_size;
17 $this->allowed_image_sizes['zenfolio'] = [
18 'thumb_size' => [
19 '' => $this->default_from_settings,
20 "1" => esc_html__("Square thumbnail, 60 &times; 60px, cropped square", 'photonic'),
21 "0" => esc_html__("Small thumbnail, upto 80 &times; 80px", 'photonic'),
22 "10" => esc_html__("Medium thumbnail, upto 120 &times; 120px", 'photonic'),
23 "11" => esc_html__("Large thumbnail, upto 120 &times; 120px", 'photonic'),
24 "2" => esc_html__("Small image, upto 400 &times; 400px", 'photonic'),
25 ],
26 'tile_size' => [
27 '' => $this->default_from_settings,
28 'same' => esc_html__('Same as Main image size', 'photonic'),
29 '2' => esc_html__('Small image, upto 400 &times; 400px', 'photonic'),
30 '3' => esc_html__('Medium image, upto 580 &times; 450px', 'photonic'),
31 '4' => esc_html__('Large image, upto 800 &times; 630px', 'photonic'),
32 '5' => esc_html__('X-Large image, upto 1100 &times; 850px', 'photonic'),
33 '6' => esc_html__('XX-Large image, upto 1550 &times; 960px', 'photonic'),
34 ],
35 'main_size' => [
36 '' => $this->default_from_settings,
37 '2' => esc_html__('Small image, upto 400 &times; 400px', 'photonic'),
38 '3' => esc_html__('Medium image, upto 580 &times; 450px', 'photonic'),
39 '4' => esc_html__('Large image, upto 800 &times; 630px', 'photonic'),
40 '5' => esc_html__('X-Large image, upto 1100 &times; 850px', 'photonic'),
41 '6' => esc_html__('XX-Large image, upto 1550 &times; 960px', 'photonic'),
42 ],
43 'video_size' => [
44 '' => $this->default_from_settings,
45 '220' => esc_html__('360p resolution (MP4)', 'photonic'),
46 '215' => esc_html__('480p resolution (MP4)', 'photonic'),
47 '210' => esc_html__('720p resolution (MP4)', 'photonic'),
48 '200' => esc_html__('1080p resolution (MP4)', 'photonic'),
49 ],
50 ];
51 $this->allowed_image_sizes['zenfolio']['thumb_size'][''] .= ' - ' . $this->allowed_image_sizes['zenfolio']['thumb_size'][$photonic_zenfolio_thumb_size];
52 $this->allowed_image_sizes['zenfolio']['tile_size'][''] .= ' - ' . $this->allowed_image_sizes['zenfolio']['tile_size'][$photonic_zenfolio_tile_size];
53 $this->allowed_image_sizes['zenfolio']['main_size'][''] .= ' - ' . $this->allowed_image_sizes['zenfolio']['main_size'][$photonic_zenfolio_main_size];
54 $this->allowed_image_sizes['zenfolio']['video_size'][''] .= ' - ' . $this->allowed_image_sizes['zenfolio']['video_size'][$photonic_zenfolio_video_size];
55 }
56
57 public static function get_instance(): Zenfolio {
58 if (null === self::$instance) {
59 self::$instance = new Zenfolio();
60 }
61 return self::$instance;
62 }
63
64 public function get_screen_2(): array {
65 return [
66 'header' => esc_html__('Choose Type of Gallery', 'photonic'),
67 'display' => [
68 'kind' => [
69 'type' => 'field_list',
70 'list_type' => 'sequence',
71 'list' => [
72 'display_type' => [
73 'desc' => esc_html__('What do you want to show?', 'photonic'),
74 'type' => 'select',
75 'options' => [
76 '' => '',
77 'single-photo' => esc_html__('Single Photo', 'photonic'),
78 'multi-photo' => esc_html__('Multiple Photos', 'photonic'),
79 'gallery-photo' => esc_html__('Photos from a Gallery or 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']],
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 public function get_screen_3(): array {
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 public function get_screen_4(): array {
302 return [];
303 }
304
305 public function get_screen_5(): array {
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(): array {
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']['code'])) {
401 if (200 === $response['response']['code']) {
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 public function get_square_size_options(): array {
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 public function get_random_size_options(): array {
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 public function make_request($display_type, $for, $flattened_fields): array {
443 if ((!in_array($display_type, ['multi-photo'], true) && 'any' === $for) ||
444 (!in_array($display_type, ['single-photo', 'gallery-photo', 'collection-photo', 'multi-gallery', 'multi-collection', 'multi-gallery-collection', 'group', 'group-hierarchy'], true) && in_array($for, ['current', 'other'], true))) {
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 (check_ajax_referer('photonic-wizard-next-' . get_current_user_id())) {
452 if ('other' === $for && empty($_POST['login_name'])) {
453 return ['error' => $this->error_mandatory];
454 }
455
456 $login_name = sanitize_text_field(wp_unslash($_POST['login_name']));
457 global $photonic_zenfolio_default_user;
458 if ('current' === $for && empty($photonic_zenfolio_default_user)) {
459 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/>')];
460 }
461
462 $parameters = [];
463 $user = esc_attr('current' === $for ? $photonic_zenfolio_default_user : ('other' === $for ? $login_name : ''));
464
465 if ('multi-photo' === $display_type) {
466 $url = 'https://' . $this->api_base . '/api/1.8/zfapi.asmx/SearchPhotoByCategory';
467 $parameters['searchId'] = '5';
468 $parameters['sortOrder'] = 'Popularity';
469 $parameters['categoryCode'] = '1018000';
470 $parameters['offset'] = 0;
471 $parameters['limit'] = 500;
472 }
473 elseif (in_array($display_type, ['multi-gallery', 'multi-collection'], true) && 'any' === $for) {
474 $url = 'https://' . $this->api_base . '/api/1.8/zfapi.asmx/SearchSetByCategory';
475 $parameters['searchId'] = '5';
476 $parameters['sortOrder'] = 'Popularity';
477 $parameters['categoryCode'] = '1018000';
478 $parameters['offset'] = 0;
479 $parameters['limit'] = 500;
480 }
481 else {
482 $url = 'https://' . $this->api_base . '/api/1.8/zfapi.asmx/LoadGroupHierarchy';
483 $parameters['loginName'] = $user;
484 }
485
486 $response = wp_remote_request($url, ['sslverify' => PHOTONIC_SSL_VERIFY, 'body' => $parameters]);
487 return [$response, ['login_name' => $user], $url];
488 }
489 return ['error' => $this->error_unauthorized];
490 }
491
492 /**
493 * Processes a response from Zenfolio to build it out into a gallery of thumbnails. Zenfolio has both, L1 and L2 displays in the flow.
494 *
495 * @param $response
496 * @param $display_type
497 * @param $url
498 * @param array $pagination
499 * @return array
500 */
501 public function process_response($response, $display_type, $url = null, &$pagination = []): array {
502 $body = wp_remote_retrieve_body($response);
503 $body = preg_replace('/"Id":(\d+)/', '"Id":"$1"', $body);
504 $body = simplexml_load_string($body);
505 $objects = [];
506 if ('multi-photo' !== $display_type) {
507 if (!empty($body->Elements)) {
508 $elements = $body->Elements;
509 $this->get_zenfolio_groups($objects, $elements, $display_type);
510 }
511 elseif (!empty($body->PhotoSets)) {
512 $photosets = $body->PhotoSets;
513 $this->get_zenfolio_groups($objects, $photosets, $display_type);
514 }
515
516 if ('single-photo' === $display_type) {
517 require_once PHOTONIC_PATH . '/Platforms/Zenfolio.php';
518
519 $photo_array = [];
520 $gallery = \Photonic_Plugin\Platforms\Zenfolio::get_instance();
521 $requests = [];
522 foreach ($objects as $object) {
523 $parameters = [];
524 $parameters['photoSetId'] = substr($object['id'], 1);
525 $parameters['level'] = 'Level1';
526 $parameters['includePhotos'] = 'true';
527
528 $request = $gallery->prepare_request('LoadPhotoSet', $parameters);
529 $requests[] = [
530 'url' => 'https://' . $this->api_base . '/api/1.8/zfapi.asmx',
531 'type' => 'POST',
532 'headers' => $request['headers'],
533 'data' => $request['body'],
534 ];
535 }
536
537 $responses = Requests::request_multiple($requests);
538
539 if (!empty($responses)) {
540 foreach ($responses as $ps_response) {
541 if (is_a($ps_response, 'WpOrg\Requests\Response')) {
542 $ps_response = json_decode($ps_response->body);
543 if (!empty($ps_response->result)) {
544 $ps_response = $ps_response->result;
545 if (!empty($ps_response->Photos)) {
546 $photo_array['psid' . $ps_response->Id] = $ps_response->Title;
547 foreach ($ps_response->Photos as $ps_photo) {
548 if (array_key_exists($ps_photo->Id, $photo_array)) {
549 continue;
550 }
551 $photo = [];
552 $photo['id'] = $ps_photo->Id;
553 $url_parts = explode('/', $ps_photo->UrlCore);
554 $photo['alt_id'] = 'h' . dechex((int) substr($url_parts[count($url_parts) - 1], 1));
555 $photo['alt_id2'] = $url_parts[count($url_parts) - 1];
556 $photo['title'] = esc_attr($ps_photo->Title);
557 $photo['thumbnail'] = 'https://' . $ps_photo->UrlHost . $ps_photo->UrlCore . '-1.jpg';
558 $photo_array[$ps_photo->Id] = $photo;
559 }
560 }
561 }
562 }
563 }
564 }
565 $objects = array_values($photo_array);
566 }
567 return $objects;
568 }
569 else {
570 $photos = $body->Photos;
571 foreach ($photos->Photo as $photo) {
572 $object = [];
573 $object['id'] = $photo->Id;
574 $object['title'] = esc_attr($photo->Title);
575 $object['thumbnail'] = 'https://' . $photo->UrlHost . $photo->UrlCore . '-1.jpg';
576 $objects[] = $object;
577 }
578 return $objects;
579 }
580 }
581
582 /**
583 * A recursive call to traverse a Zenfolio group and generate a list of objects, with each object corresponding to a photoset.
584 *
585 * @param $objects
586 * @param $elements
587 * @param $display_type
588 */
589 private function get_zenfolio_groups(&$objects, $elements, $display_type) {
590 if (!empty($elements->PhotoSet) && 'group' !== $display_type) {
591 foreach ($elements->PhotoSet as $photoset) {
592 if ((('gallery-photo' === $display_type || 'multi-gallery' === $display_type) && 'Gallery' === (string) $photoset->Type) || // WARNING: No strict matching should be done for $photoset->Type without casting; this is an XML object that we are matching to a string
593 (('collection-photo' === $display_type || 'multi-collection' === $display_type) && 'Collection' === (string) $photoset->Type) || // WARNING: No strict matching should be done for $photoset->Type without casting; this is an XML object that we are matching to a string
594 'multi-gallery-collection' === $display_type || 'group-hierarchy' === $display_type || 'single-photo' === $display_type
595 ) {
596 $object = [];
597 $page_url = wp_parse_url($photoset->PageUrl);
598 $page_url = $page_url['path'];
599 $page_url = explode('/', $page_url);
600 if (count($page_url) > 1) {
601 $page_url = $page_url[1];
602 }
603
604 if (!is_array($page_url) && preg_match('/^p\d{9}/', $page_url) === 0) {
605 $page_url = [];
606 }
607
608 $object['id'] = !is_array($page_url) ? $page_url : $photoset->Id;
609 $object['alt_id'] = $photoset->Id;
610 $object['title'] = esc_attr($photoset->Title);
611 $object['counters'] = [esc_html(sprintf(_n('%s media item', '%s media items', $photoset->PhotoCount, 'photonic'), $photoset->PhotoCount))];
612
613 $photo = $photoset->TitlePhoto;
614 $object['thumbnail'] = 'https://' . $photo->UrlHost . $photo->UrlCore . '-1.jpg';
615
616 if (!empty($photoset->AccessDescriptor) && !empty($photoset->AccessDescriptor->AccessType) && 'Password' === $photoset->AccessDescriptor->AccessType) {
617 $object['passworded'] = 1;
618 }
619
620 $objects[] = $object;
621 }
622 }
623 }
624
625 if (!empty($elements->Group)) {
626 foreach ($elements->Group as $group) {
627 if ('group' === $display_type || 'group-hierarchy' === $display_type) {
628 $object = [];
629 $object['id'] = $group->Id;
630 $object['title'] = $group->Title;
631 $object['thumbnail'] = PHOTONIC_URL . 'include/images/placeholder-Ti.png';
632 $objects[] = $object;
633 }
634
635 if ('group-hierarchy' !== $display_type && !empty($group->Elements)) {
636 $this->get_zenfolio_groups($objects, $group->Elements, $display_type);
637 }
638 }
639 }
640 }
641
642 /**
643 * @param $display_type
644 * @return array
645 */
646 public function construct_shortcode_from_screen_selections($display_type): array {
647 $short_code = [];
648
649 if (check_ajax_referer('photonic-wizard-next-' . get_current_user_id())) {
650 if ('multi-photo' === $display_type) {
651 $short_code['view'] = 'photos';
652 }
653 elseif ('single-photo' === $display_type) {
654 $short_code['view'] = 'photos';
655 $short_code['object_id'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? ''));
656 }
657 elseif ('gallery-photo' === $display_type/* || $display_type == 'collection-photo'*/) {
658 $short_code['view'] = 'photosets';
659 $short_code['object_id'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? ''));
660 }
661 elseif ('multi-gallery' === $display_type || 'multi-collection' === $display_type || 'multi-gallery-collection' === $display_type) {
662 $short_code['view'] = 'photosets';
663 if ('multi-gallery' === $display_type) {
664 $short_code['photoset_type'] = 'Gallery';
665 }
666 elseif ('multi-collection' === $display_type) {
667 $short_code['photoset_type'] = 'Collection';
668 }
669 }
670 elseif ('group' === $display_type) {
671 $short_code['view'] = 'group';
672 $short_code['object_id'] = sanitize_text_field(wp_unslash($_POST['selected_data'] ?? ''));
673 }
674 elseif ('group-hierarchy' === $display_type) {
675 $short_code['view'] = 'hierarchy';
676 }
677 }
678
679 return $short_code;
680 }
681
682 /**
683 * @param $input
684 * @return array
685 */
686 public function deconstruct_shortcode_to_screen_selections($input): array {
687 $deconstructed = [];
688
689 if (!empty($input->view)) {
690 if ('photos' === $input->view && empty($input->object_id)) {
691 $deconstructed['display_type'] = 'multi-photo';
692 }
693 elseif ('photos' === $input->view && !empty($input->object_id)) {
694 $deconstructed['display_type'] = 'single-photo';
695 $deconstructed['selected_data'] = $input->object_id;
696 }
697 elseif ('photosets' === $input->view) {
698 if (!empty($input->object_id)) {
699 $deconstructed['display_type'] = 'gallery-photo';
700 $deconstructed['selected_data'] = $input->object_id;
701 }
702 elseif (empty($input->photoset_type)) {
703 $deconstructed['display_type'] = 'multi-gallery-collection';
704 }
705 elseif ('collection' === strtolower($input->photoset_type)) {
706 $deconstructed['display_type'] = 'multi-collection';
707 }
708 elseif ('gallery' === strtolower($input->photoset_type)) {
709 $deconstructed['display_type'] = 'multi-gallery';
710 }
711 }
712 elseif ('hierarchy' === $input->view) {
713 $deconstructed['display_type'] = 'group-hierarchy';
714 }
715 elseif ('group' === $input->view) {
716 $deconstructed['display_type'] = 'group';
717 if (!empty($input->object_id)) {
718 $deconstructed['selected_data'] = $input->object_id;
719 }
720 }
721
722 if ('photosets' === $input->view || 'hierarchy' === $input->view || 'group' === $input->view ||
723 'single-photo' === $deconstructed['display_type']) {
724 global $photonic_zenfolio_default_user;
725 if (!isset($input->login_name) && !empty($photonic_zenfolio_default_user)) {
726 $deconstructed['for'] = 'current';
727 }
728 elseif (!empty($input->login_name)) {
729 $deconstructed['login_name'] = $input->login_name;
730 $deconstructed['for'] = 'other';
731 }
732 }
733 }
734
735 return $deconstructed;
736 }
737 }
738