PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.32
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.32
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 / layouts / Layout_Default.php

Layout_Default.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.32, at layouts/Layout_Default.php

717 lines 30.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Layout Manager to generate the grid layouts and the "Justified Grid" layout, all of which use the same markup. The Justified Grid layout is
5 * modified by JS on the front-end, however the base markup for it is similar to the square and circular thumbnails layout.
6 *
7 * All other layout managers extend this, and might implement their own versions of generate_level_1_gallery and generate_level_2_gallery
8 *
9 * @package Photonic
10 * @subpackage Layouts
11 */
12 class Photonic_Layout {
13 private $library;
14
15 function __construct() {
16 global $photonic_slideshow_library, $photonic_custom_lightbox;
17 if ($photonic_slideshow_library != 'custom') {
18 $this->library = $photonic_slideshow_library;
19 }
20 else {
21 $this->library = $photonic_custom_lightbox;
22 }
23 }
24
25 /**
26 * Generates the markup for a single photo.
27 *
28 * @param $data array Pertinent pieces of information about the photo - the source (src), the photo page (href), title and caption
29 * @param $processor Photonic_Processor The object calling this. A CSS class is created in the header, photonic-single-<code>$processor->provider</code>-photo-header
30 * @return string
31 */
32 function generate_single_photo_markup($data, $processor) {
33 $processor->push_to_stack('Generate single photo markup');
34 $ret = '';
35 $photo = array_merge(
36 ['src' => '', 'href' => '', 'title' => '', 'caption' => ''],
37 $data
38 );
39
40 if (empty($photo['src'])) {
41 $processor->pop_from_stack();
42 return $ret;
43 }
44
45 global $photonic_external_links_in_new_tab;
46 if (!empty($photo['title'])) {
47 $ret .= "\t".'<h3 class="photonic-single-photo-header photonic-single-'.$processor->provider.'-photo-header">'.$photo['title']."</h3>\n";
48 }
49
50 $img = '<img src="'.$photo['src'].'" alt="'.esc_attr(empty($photo['caption']) ? $photo['title'] : $photo['caption']).'" loading="eager"/>';
51 if (!empty($photo['href'])) {
52 $img = '<a href="'.$photo['href'].'" title="'.esc_attr(empty($photo['caption']) ? $photo['title'] : $photo['caption']).'" '.
53 (!empty($photonic_external_links_in_new_tab) ? ' target="_blank" ' : '').'>'.$img.'</a>';
54 }
55
56 if (!empty($photo['caption'])) {
57 $ret .= "\t".'<div class="wp-caption">'."\n\t\t".$img."\n\t\t".'<div class="wp-caption-text">'.$photo['caption']."</div>\n\t</div><!-- .wp-caption -->\n";
58 }
59 else {
60 $ret .= $img;
61 }
62
63 $processor->pop_from_stack();
64 return $ret;
65 }
66
67 /**
68 * Generates the HTML for the lowest level gallery, i.e. the photos. This is used for both, in-page and popup displays.
69 * The code for the random layouts is handled in JS, but just the HTML markers for it are provided here.
70 *
71 * @param $photos
72 * @param array $options
73 * @param $short_code
74 * @param $processor Photonic_Processor
75 * @return string
76 */
77 function generate_level_1_gallery($photos, $options, $short_code, $processor) {
78 $processor->push_to_stack('Generate level 1 gallery');
79 $layout = !empty($short_code['layout']) ? $short_code['layout'] : 'square';
80 $columns = !empty($short_code['columns']) && ($layout !== 'random' && $layout !== 'mosaic') ? $short_code['columns'] : 'auto';
81 $display = !empty($short_code['display']) ? $short_code['display'] : 'in-page';
82 $more = !empty($short_code['more']) ? esc_attr($short_code['more']) : '';
83 $more = (empty($more) && !empty($short_code['photo_more'])) ? esc_attr($short_code['photo_more']) : $more;
84 $panel = !empty($short_code['panel']) ? $short_code['panel'] : '';
85
86 $title_position = empty($short_code['title_position']) ? $options['title_position'] : $short_code['title_position'];
87 $row_constraints = isset($options['row_constraints']) && is_array($options['row_constraints']) ? $options['row_constraints'] : [];
88 $sizes = isset($options['sizes']) && is_array($options['sizes']) ? $options['sizes'] : [];
89 $show_lightbox = !isset($options['show_lightbox']) ? true: $options['show_lightbox'];
90 $type = !empty($options['type']) ? $options['type'] : 'photo';
91 $parent = !empty($options['parent']) ? $options['parent'] : 'stream';
92 $pagination = isset($options['level_2_meta']) && is_array($options['level_2_meta']) ? $options['level_2_meta'] : [];
93 $indent = !isset($options['indent']) ? "\t" : $options['indent'];
94
95 list($container_id, $container_end) = $this->get_container_details($short_code, $processor);
96
97 $non_standard = $layout == 'random' || $layout == 'masonry' || $layout == 'mosaic';
98
99 $col_class = '';
100 if (absint($columns)) {
101 $col_class = 'photonic-gallery-'.$columns.'c';
102 }
103
104 if ($col_class == '' && $row_constraints['constraint-type'] == 'padding') {
105 $col_class = 'photonic-pad-photos';
106 }
107 else if ($col_class == '') {
108 $col_class = 'photonic-gallery-'.$row_constraints['count'].'c';
109 }
110 $col_class .= ' photonic-level-1 photonic-thumb photonic-thumb-'.$layout;
111
112 $link_attributes = $this->get_lightbox_attributes($show_lightbox, $panel, $processor);
113 $link_attributes_text = $this->get_text_from_link_attributes($link_attributes);
114
115 $effect = $this->get_thumbnail_effect($short_code, $layout, $title_position);
116 $ul_class = "class='title-display-$title_position photonic-level-1-container ".($non_standard ? 'photonic-'.$layout.'-layout' : 'photonic-standard-layout')." photonic-thumbnail-effect-$effect'";
117 if ($display == 'popup') {
118 $ul_class = "class='slideshow-grid-panel lib-{$this->library} photonic-level-1-container title-display-$title_position'";
119 }
120
121 $ret = '';
122 if (!$non_standard && $display != 'popup') {
123 $container_tag = 'ul';
124 $element_tag = 'li';
125 }
126 else {
127 $container_tag = 'div';
128 $element_tag = 'div';
129 }
130
131 list($pagination_data, $pagination, $columns_data) = $this->get_gallery_data_attributes($short_code, $processor, $pagination, $columns);
132
133 $start_with = "$indent<$container_tag $container_id $ul_class $pagination_data $columns_data>\n";
134 $ret .= $start_with;
135
136 global $photonic_external_links_in_new_tab;
137 if (!empty($photonic_external_links_in_new_tab)) {
138 $target = " target='_blank' ";
139 }
140 else {
141 $target = '';
142 }
143
144 $counter = 0;
145 $thumbnail_class = " class='$layout' ";
146
147 $element_start = "$indent\t<".$element_tag.' class="photonic-'.$processor->provider.'-image photonic-'.$processor->provider.'-'.$type.' '.$col_class.'">'."\n";
148 foreach ($photos as $photo) {
149 $counter++;
150
151 $thumb = ($non_standard && $display == 'in-page') ? (isset($photo['tile_image']) ? $photo['tile_image'] : $photo['main_image']) : $photo['thumbnail'];
152 $orig = empty($photo['video']) ? $photo['main_image'] : $photo['video'];
153 // $orig = $photo['main_image'];
154 $url = isset($photo['main_page']) ? $photo['main_page'] : '';
155 $title = esc_attr($photo['title']);
156 $description = esc_attr($photo['description']);
157 $alt = esc_attr($photo['alt_title']);
158 $orig = ($this->library == 'none' || !$show_lightbox) ? $url : $orig;
159
160 $title = empty($title) ? ((empty($alt) && $processor->link_lightbox_title && $this->library != 'thickbox') ? apply_filters('photonic_default_lightbox_text', esc_attr__('View', 'photonic')) : $alt) : $title;
161 $ret .= $element_start;
162
163 $deep_value = 'gallery[photonic-'.$processor->provider.'-'.$parent.'-'.(empty($panel) ? $processor->gallery_index : $panel).']/'.(empty($photo['id']) ? $counter : $photo['id']).'/';
164 $deep_link = ' data-photonic-deep="'.$deep_value.'" ';
165
166 $buy = '';
167 if (!empty($photo['buy_link']) && $processor->show_buy_link) {
168 $buy = ' data-photonic-buy="'.$photo['buy_link'].'" ';
169 }
170
171 $style = [];
172 if (!empty($sizes['thumb-width'])) $style[] = 'width:'.$sizes['thumb-width'].'px';
173 if (!empty($sizes['thumb-height'])) $style[] = 'height:'.$sizes['thumb-height'].'px';
174 if (!empty($style)) $style = 'style="'.implode(';', $style).'"'; else $style = '';
175 if ($processor->link_lightbox_title && $this->library != 'thickbox' && !empty($url)) {
176 $title_link_start = esc_attr("<a href='$url' $target>");
177 $title_link_end = esc_attr("</a>");
178 }
179 else {
180 $title_link_start = '';
181 $title_link_end = '';
182 }
183
184 if (!empty($short_code['caption']) && ($short_code['caption'] == 'desc' || ($short_code['caption'] == 'title-desc' && empty($title)) || ($short_code['caption'] == 'desc-title' && !empty($description)))) {
185 $title = $description;
186 }
187 else if (empty($short_code['caption']) || (($short_code['caption'] == 'desc-title' && empty($title)) || $short_code['caption'] == 'none')) {
188 $title = '';
189 }
190
191 if (!empty($title)) {
192 $title_markup = $title_link_start.esc_attr($title).$title_link_end;
193 $title_markup = apply_filters('photonic_lightbox_title_markup', $title_markup);
194 }
195 else {
196 $title_markup = '';
197 }
198
199 if ($processor->link_lightbox_title && $this->library != 'thickbox' && !empty($photo['buy_link']) && $processor->show_buy_link) {
200 $buy_link = esc_attr('<a class="photonic-buy-link" href="'.$photo['buy_link'].'" target="_blank" title="'.__('Buy', 'photonic').'"><div class="icon-buy"></div></a>');
201 $title_markup .= $buy_link;
202 }
203
204 $shown_title = '';
205 if (in_array($title_position, ['below', 'hover-slideup-show', 'hover-slidedown-show', 'slideup-stick']) && !empty($title)) {
206 $shown_title = '<div class="photonic-title-info"><div class="photonic-photo-title photonic-title">'.wp_specialchars_decode($title, ENT_QUOTES).'</div></div>';
207 }
208
209 $photo_data = ['title' => $title_markup, 'deep' => $deep_value, 'raw_title' => $title, 'href' => $orig];
210 if (!empty($photo['download'])) {
211 $photo_data['download'] = $photo['download'];
212 }
213 if (!empty($photo['video'])) {
214 $photo_data['video'] = $photo['video'];
215 }
216 else {
217 $photo_data['image'] = $photo['main_image'];
218 }
219 $photo_data['provider'] = $processor->provider;
220 $photo_data['gallery_index'] = $processor->gallery_index;
221 $photo_data['id'] = $photo['id'];
222
223 $lb_specific_data = $this->get_lightbox_specific_photo_data($photo_data, $processor);
224 if (!empty($photo['video'])) {
225 $lb_specific_data .= ' data-photonic-media-type="video" ';
226 }
227 else {
228 $lb_specific_data .= ' data-photonic-media-type="image" ';
229 }
230 if (!empty($photo['video']) && $this->library == 'lightgallery') {
231 $video_id = $processor->provider.'-'.$processor->gallery_index.'-'.$photo['id'];
232 $ret .= $indent."\t\t".'<div style="display:none;" id="photonic-video-'.$video_id.'">'."\n";
233 $ret .= $indent."\t\t\t".'<video class="lg-video-object lg-html5 photonic" controls preload="none">'."\n";
234 $ret .= $indent."\t\t\t\t".'<source src="'.$photo['video'].'" type="'.(!empty($photo['mime']) ? $photo['mime']: 'video/mp4').'">'."\n";
235 $ret .= $indent."\t\t\t\t".esc_html__('Your browser does not support HTML5 videos.', 'photonic')."\n";
236 $ret .= $indent."\t\t\t".'</video>'."\n";
237 $ret .= $indent."\t\t".'</div>'."\n";
238
239 $orig = ''; // href should be blank
240 }
241 else if (!empty($photo['video']) && (in_array($this->library, ['colorbox', 'fancybox', 'fancybox2', 'magnific', 'photoswipe', 'swipebox',])
242 || (in_array($this->library, ['fancybox3']) && in_array($processor->provider, ['flickr', 'google']))
243 )) {
244 $video_id = $processor->provider.'-'.$processor->gallery_index.'-'.$photo['id'];
245 $ret .= $indent."\t\t".'<div class="photonic-html5-external" id="photonic-video-'.$video_id.'">'."\n";
246 $ret .= $indent."\t\t\t".'<video class="photonic" controls preload="none">'."\n";
247 $ret .= $indent."\t\t\t\t".'<source src="'.$photo['video'].'" type="'.(!empty($photo['mime']) ? $photo['mime']: 'video/mp4').'">'."\n";
248 $ret .= $indent."\t\t\t\t".esc_html__('Your browser does not support HTML5 videos.', 'photonic')."\n";
249 $ret .= $indent."\t\t\t".'</video>'."\n";
250 $ret .= $indent."\t\t".'</div>'."\n";
251
252 $orig = '#photonic-video-'.$video_id;
253 }
254
255 if ($this->library == 'magnific') {
256 $magnific = !empty($photo['video']) ? 'mfp-inline' : 'mfp-image';
257 $link_attributes['class']['magnific'] = $magnific;
258 $link_attributes_text = $this->get_text_from_link_attributes($link_attributes);
259 }
260
261 if ($title_position == 'tooltip') {
262 $tooltip = 'data-photonic-tooltip="'.esc_attr($title).'" ';
263 }
264 else {
265 $tooltip = '';
266 }
267 $ret .= $indent."\t\t".'<a '.$link_attributes_text.' href="'.$orig.'" title="'.($title_position != 'none' ? esc_attr($title) : '').'" data-title="'.$title_markup.'" '.$tooltip.' '.$lb_specific_data.' '.$target.$deep_link.$buy.">\n";
268 $ret .= $indent."\t\t\t".'<img alt="'.$alt.'" src="'.$thumb.'" '.$style.$thumbnail_class." loading='eager'/>\n";
269 $ret .= $indent."\t\t\t".$shown_title."\n";
270 $ret .= $indent."\t\t"."</a>\n";
271 $ret .= $indent."\t"."</$element_tag>\n";
272 }
273
274 $ret = trim($ret);
275 if ($ret != $start_with) {
276 $trailing = strlen($element_tag) + 3;
277 if (substr($ret, -$trailing) != "</$element_tag>" && $short_code['popup'] == 'show' && !$non_standard) {
278 $ret .= "\n$indent</$element_tag><!-- last $element_tag.photonic-pad-photos -->";
279 }
280
281 $ret .= "\n$indent</$container_tag> <!-- ./photonic-level-1-container -->\n";
282 $ret .= "<span id='$container_end'></span>";
283
284 if (!empty($pagination) && isset($pagination['end']) && isset($pagination['total']) && $pagination['total'] > $pagination['end']) {
285 $ret .= !empty($more) ? "<a href='#' class='photonic-more-button photonic-more-dynamic'>$more</a>\n" : '';
286 }
287 }
288 else {
289 $ret = '';
290 }
291
292 if (is_archive() || is_home()) {
293 global $photonic_archive_thumbs;
294 if (!empty($photonic_archive_thumbs) && $counter < $photonic_archive_thumbs) {
295 $processor->is_more_required = false;
296 }
297 }
298
299 $processor->pop_from_stack();
300 return $ret;
301 }
302
303 /**
304 * Generates the HTML for a group of level-2 items, i.e. Photosets (Albums) and Galleries for Flickr, Albums for Google Photos,
305 * Albums for SmugMug, and Photosets (Galleries and Collections) for Zenfolio. No concept of albums
306 * exists in native WP and Instagram.
307 *
308 * @param $objects
309 * @param $options
310 * @param $short_code
311 * @param $processor Photonic_Processor
312 * @return string
313 */
314 function generate_level_2_gallery($objects, $options, $short_code, $processor) {
315 $processor->push_to_stack('Generate Level 2 Gallery');
316 $row_constraints = isset($options['row_constraints']) && is_array($options['row_constraints']) ? $options['row_constraints'] : [];
317 $type = $options['type'];
318 $singular_type = $options['singular_type'];
319 $title_position = empty($short_code['title_position']) ? $options['title_position'] : $short_code['title_position'];
320 $level_1_count_display = $options['level_1_count_display'];
321 $indent = !isset($options['indent']) ? '' : $options['indent'];
322 $provider = $processor->provider;
323
324 $columns = $short_code['columns'];
325 $layout = !isset($short_code['layout']) ? 'square' : $short_code['layout'];
326 $popup = ' data-photonic-popup="'.$short_code['popup'].'"';
327
328 $non_standard = $layout == 'random' || $layout == 'masonry' || $layout == 'mosaic';
329 $effect = $this->get_thumbnail_effect($short_code, $layout, $title_position);
330 $ul_class = "class='title-display-$title_position photonic-level-2-container ".($non_standard ? 'photonic-'.$layout.'-layout' : 'photonic-standard-layout')." photonic-thumbnail-effect-$effect'";
331
332 list($container_id, $container_end) = $this->get_container_details($short_code, $processor);
333
334 $pagination = isset($options['pagination']) && is_array($options['pagination']) ? $options['pagination'] : [];
335 $more = !empty($short_code['more']) ? esc_attr($short_code['more']) : '';
336
337 list($pagination_data, $pagination, $columns_data) = $this->get_gallery_data_attributes($short_code, $processor, $pagination, $columns);
338
339 $ret = "\n$indent<ul $container_id $ul_class $pagination_data $columns_data>";
340 if ($non_standard) {
341 $ret = "\n$indent<div $container_id $ul_class $pagination_data $columns_data>";
342 }
343
344 if ($columns != 'auto') {
345 $col_class = 'photonic-gallery-'.$columns.'c';
346 }
347 else if ($row_constraints['constraint-type'] == 'padding') {
348 $col_class = 'photonic-pad-'.$type;
349 }
350 else {
351 $col_class = 'photonic-gallery-'.$row_constraints['count'].'c';
352 }
353
354 $col_class .= ' photonic-level-2 photonic-thumb';
355
356 $counter = 0;
357 foreach ($objects as $object) {
358 $data_attributes = isset($object['data_attributes']) && is_array($object['data_attributes']) ? $object['data_attributes'] : [];
359 $data_attributes['provider'] = $provider;
360 $data_attributes['singular'] = $singular_type;
361 $data_array = [];
362 foreach ($data_attributes as $attr => $value) {
363 $data_array[] = 'data-photonic-'.$attr.'="'.$value.'"';
364 }
365
366 $data_array = implode(' ', $data_array);
367
368
369 $id = empty($object['id_1']) ? '' : $object['id_1'].'-';
370 $id = $id.$processor->gallery_index;
371 $id = empty($object['id_2']) ? $id : ($id.'-'.$object['id_2']);
372 $title = esc_attr($object['title']);
373 $image = "<img src='".(($non_standard && isset($object['tile_image'])) ? $object['tile_image'] : $object['thumbnail'])."' alt='".$title."' class='$layout' loading='eager'/>";
374 $additional_classes = !empty($object['classes']) ? implode(' ', $object['classes']) : '';
375 $realm_class = '';
376 if (!empty($object['classes'])) {
377 foreach ($object['classes'] as $class) {
378 if (stripos($class, 'photonic-'.$provider.'-realm') !== FALSE) {
379 $realm_class = $class;
380 }
381 }
382 }
383 if ($title_position == 'tooltip') {
384 $tooltip = "data-photonic-tooltip='".esc_attr($title)."' ";
385 }
386 else {
387 $tooltip = '';
388 }
389 $anchor = "\n{$indent}\t\t<a href='{$object['main_page']}' class='photonic-{$provider}-{$singular_type}-thumb photonic-level-2-thumb $additional_classes' id='photonic-{$provider}-$singular_type-thumb-$id' title='".($title_position != 'none' ? esc_attr($title) : '')."' data-title='".$title."' $tooltip $data_array$popup>\n$indent\t\t\t".$image;
390 $text = '';
391 if (in_array($title_position, ['below', 'hover-slideup-show', 'hover-slidedown-show', 'slideup-stick'])) {
392 $text = "\n{$indent}\t\t\t<div class='photonic-title-info'>\n{$indent}\t\t\t\t<div class='photonic-$singular_type-title photonic-title'>".$title."";
393 if (!$level_1_count_display && !empty($object['counter'])) {
394 $text .= '<span class="photonic-title-photo-count photonic-'.$singular_type.'-photo-count">'.sprintf(esc_html__('%s photos', 'photonic'), $object['counter']).'</span>';
395 }
396 }
397 if ($text != '') {
398 $text .= "</div>\n{$indent}\t\t\t</div>";
399 }
400
401 $anchor .= $text."\n{$indent}\t\t</a>";
402 $password_prompt = '';
403 if (!empty($object['passworded'])) {
404 $prompt_title = esc_attr__('Protected Content', 'photonic');
405 $prompt_submit = esc_attr__('Access', 'photonic');
406 $password_type = " type='password' ";
407 $prompt_type = 'password';
408 $prompt_text = esc_attr__('This album is password-protected. Please provide a valid password.', 'photonic');
409 if (in_array("photonic-$provider-passworded-authkey", $object['classes'])) {
410 $prompt_text = esc_attr__('This album is protected. Please provide a valid authorization key.', 'photonic');
411 }
412 else if (in_array("photonic-$provider-passworded-link", $object['classes'])) {
413 $prompt_text = esc_attr__('This album is protected. Please provide the short-link for it.', 'photonic');
414 $password_type = '';
415 $prompt_type = 'link';
416 }
417
418 $password_prompt = "
419 <div class='photonic-password-prompter $realm_class' id='photonic-{$provider}-$singular_type-prompter-$id' title='$prompt_title' data-photonic-prompt='$prompt_type'>
420 <div class='photonic-password-prompter-content'>
421 <div class='photonic-prompt-head'>
422 <h3>
423 <span class='title'>$prompt_title</span>
424 <button class='close'>&times;</button>
425 </h3>
426 </div>
427 <div class='photonic-prompt-body'>
428 <p>$prompt_text</p>
429 <input $password_type name='photonic-{$provider}-password' />
430 <button class='photonic-{$provider}-submit photonic-password-submit confirm'>$prompt_submit</button>
431 </div>
432 </div>
433 </div>";
434 }
435
436 if ($non_standard) {
437 $ret .= "\n$indent\t<div class='photonic-{$provider}-image photonic-{$provider}-$singular_type-thumb $col_class' id='photonic-{$provider}-$singular_type-$id'>{$anchor}{$password_prompt}\n$indent\t</div>";
438 }
439 else {
440 $ret .= "\n$indent\t<li class='photonic-{$provider}-image photonic-{$provider}-$singular_type-thumb $col_class' id='photonic-{$provider}-$singular_type-$id'>{$anchor}{$password_prompt}\n$indent\t</li>";
441 }
442 $counter++;
443 }
444
445 if ($ret != "\n$indent<ul $container_id $ul_class $pagination_data $columns_data>" && !$non_standard) {
446 $ret .= "\n$indent</ul>\n";
447 }
448 else if ($non_standard) {
449 $ret .= "\n$indent</div>\n";
450 }
451 else {
452 $ret = '';
453 }
454
455 if (!empty($ret)) {
456 $ret .= "<span id='$container_end'></span>";
457 if (!empty($pagination) && isset($pagination['end']) && isset($pagination['total']) && $pagination['total'] > $pagination['end']) {
458 $ret .= !empty($more) ? "<a href='#' class='photonic-more-button photonic-more-dynamic'>$more</a>\n" : '';
459 }
460 }
461
462 if (is_archive() || is_home()) {
463 global $photonic_archive_thumbs;
464 if (!empty($photonic_archive_thumbs) && $counter < $photonic_archive_thumbs) {
465 $processor->is_more_required = false;
466 }
467 }
468
469 $processor->pop_from_stack();
470 return $ret;
471 }
472
473 /**
474 * Depending on the lightbox library, this function provides the CSS class and the rel tag for the thumbnail. This method borrows heavily from
475 * Justin Tadlock's Cleaner Gallery Plugin.
476 *
477 * @param $show_lightbox
478 * @param $rel_id
479 * @param $processor
480 * @return array
481 */
482 function get_lightbox_attributes($show_lightbox, $rel_id, $processor) {
483 global $photonic_slideshow_mode;
484 $rel = '';
485 $ret = [
486 'class' => [],
487 'rel' => [],
488 'specific' => [],
489 ];
490
491 if ($this->library != 'none' && $show_lightbox) {
492 $ret['class'] = ['photonic-launch-gallery', 'launch-gallery-'.$this->library, $this->library];
493 $rel = 'lightbox-photonic-'.$processor->provider.'-stream-'.(empty($rel_id) ? $processor->gallery_index : $rel_id);
494 $ret['rel'] = [$rel];
495
496 switch ($this->library) {
497 case 'lightbox':
498 case 'jquery_lightbox_plugin':
499 case 'jquery_lightbox_balupton':
500 $ret['class'] = ['launch-gallery-lightbox', 'lightbox'];
501 $ret['rel'] = ["lightbox[{$rel}]"];
502 break;
503
504 case 'fancybox2':
505 $ret['class'] = ['photonic-launch-gallery', 'launch-gallery-fancybox', 'fancybox'];
506 break;
507
508 case 'fancybox3':
509 $ret['class'] = ['photonic-launch-gallery', 'launch-gallery-fancybox', 'fancybox'];
510 $ret['specific'] = [
511 'data-fancybox' => [$rel],
512 ];
513 break;
514
515 case 'prettyphoto':
516 $ret['rel'] = ["photonic-prettyPhoto[{$rel}]"];
517 break;
518
519 case 'featherlight':
520 $ret['class'] = ['photonic-launch-gallery', 'launch-gallery-featherlight'];
521 break;
522
523 case 'lightcase':
524 $ret['specific'] = [
525 'data-rel' => ['lightcase:lightbox-photonic-'.$processor->provider.'-stream-'.(empty($rel_id) ? $processor->gallery_index : $rel_id).((isset($photonic_slideshow_mode) && $photonic_slideshow_mode == 'on') ? ':slideshow' : '')],
526 ];
527 break;
528
529 case 'strip':
530 global $photonic_lightbox_no_loop;
531 $ret['specific'] = [
532 'data-strip-group' => [$rel],
533 ];
534 if (!empty($photonic_lightbox_no_loop)) {
535 $ret['specific']['data-strip-group-options'] = ["loop: false"];
536 }
537 break;
538
539 default:
540 $ret['class'] = ['photonic-launch-gallery', 'launch-gallery-'.$this->library, $this->library];
541 $ret['rel'] = ['lightbox-photonic-'.$processor->provider.'-stream-'.(empty($rel_id) ? $processor->gallery_index : $rel_id)];
542 break;
543 }
544 }
545
546 return $ret;
547 }
548
549 /**
550 * @param array $link_attributes
551 * @return string
552 */
553 function get_text_from_link_attributes($link_attributes) {
554 $class = '';
555 $rel = '';
556 $specific = '';
557 if (!empty($link_attributes['class'])) {
558 $class = " class='".implode(' ', array_values($link_attributes['class']))."' ";
559 }
560
561 if (!empty($link_attributes['rel'])) {
562 $rel = " rel='".implode(' ', $link_attributes['rel'])."' ";
563 }
564
565 if (!empty($link_attributes['specific'])) {
566 foreach ($link_attributes['specific'] as $key => $val) {
567 $specific .= $key.'="'.implode(' ', $val).'" ';
568 }
569 }
570 return $class.$rel.$specific;
571 }
572
573 /**
574 * Some lightboxes require some additional attributes for individual photos. E.g. Lightgallery requires something to show the title etc.
575 * This method returns such additional information. Not to be confused with <code>get_lightbox_attributes</code>, which
576 * returns information for the gallery as a whole.
577 *
578 * @param $photo_data
579 * @return string
580 */
581 function get_lightbox_specific_photo_data($photo_data, $processor) {
582 if ($this->library == 'lightgallery') {
583 $download = !empty($photo_data['download']) ? 'data-download-url="'.$photo_data['download'].'" ' : '';
584 $video = !empty($photo_data['video']) ? ' data-html="#photonic-video-'.$processor->provider.'-'.$processor->gallery_index.'-'.$photo_data['id'].'" ' : '';
585 return ' data-sub-html="'.$photo_data['title'].'" '.$video.$download;
586 }
587 else if ($this->library == 'strip') {
588 return ' data-strip-caption="'.$photo_data['title'].'" data-strip-options="onShow: function(a) { photonicStripSetHash('."'{$photo_data['deep']}'".'); }, afterHide: function() { photonicStripUnsetHash(); } " ';
589 }
590 else if ($this->library == 'lightcase' && $processor->provider == 'google') {
591 if (empty($photo_data['video'])) {
592 return " data-lc-options='{\"type\": \"image\"}' ";
593 }
594 else {
595 return " data-lc-options='{\"type\": \"video\"}' ";
596 }
597 }
598 else if ($this->library == 'fancybox' && $processor->provider == 'google') {
599 if (empty($photo_data['video'])) {
600 return " data-fancybox='{type: \"image\"}' ";
601 }
602 }
603 else if ($this->library == 'fancybox2' && $processor->provider == 'google') {
604 if (empty($photo_data['video'])) {
605 return " data-fancybox-type='image' ";
606 }
607 }
608 else if (in_array($this->library, ['colorbox', 'fancybox', 'fancybox2', 'photoswipe', 'swipebox',]) ||
609 (in_array($this->library, ['fancybox3', 'lightcase']) && in_array($processor->provider, ['flickr'])) ||
610 (in_array($this->library, ['fancybox3',]) && in_array($processor->provider, ['google']))) {
611 return !empty($photo_data['video']) ? ' data-html5-href="'.$photo_data['video'].'" ': '';
612 }
613 else if ($this->library == 'featherlight') {
614 $mime = (!empty($photo['mime']) ? $photo['mime']: 'video/mp4');
615 if ($processor->provider == 'google' && empty($photo_data['video'])) {
616 return " data-featherlight-type='image' ";
617 }
618 else if ($processor->provider == 'google' && !empty($photo_data['video'])) {
619 return " data-featherlight='<video class=\"photonic\" controls preload=\"none\"><source src=\"".$photo_data['video']."\" type=\"".$mime."\">".esc_html__('Your browser does not support HTML5 videos.', 'photonic')."</video>' data-featherlight-type='html'";
620 }
621
622 return !empty($photo_data['video']) ? " data-featherlight='<video class=\"photonic\" controls preload=\"none\"><source src=\"".$photo_data['video']."\" type=\"".$mime."\">".esc_html__('Your browser does not support HTML5 videos.', 'photonic')."</video>' data-featherlight-type='video'" : '';
623 }
624 return '';
625 }
626
627 /**
628 * Returns the thumbnail effect that should be used for a gallery. Not all effects can be used by all types of layouts.
629 *
630 * @param $short_code
631 * @param $layout
632 * @param $title_position
633 * @return string
634 */
635 function get_thumbnail_effect($short_code, $layout, $title_position) {
636 if (!empty($short_code['thumbnail_effect'])) {
637 $effect = $short_code['thumbnail_effect'];
638 }
639 else {
640 global $photonic_standard_thumbnail_effect, $photonic_justified_thumbnail_effect, $photonic_mosaic_thumbnail_effect, $photonic_masonry_thumbnail_effect;
641 $effect = $layout == 'mosaic' ? $photonic_mosaic_thumbnail_effect :
642 ($layout == 'masonry' ? $photonic_masonry_thumbnail_effect :
643 ($layout == 'random' ? $photonic_justified_thumbnail_effect :
644 $photonic_standard_thumbnail_effect));
645 }
646
647 if ($layout == 'circle' && $effect != 'opacity') { // "Zoom" doesn't work for circle
648 $thumbnail_effect = 'none';
649 }
650 else if (($layout == 'square' || $layout == 'launch' || $layout == 'masonry') && $title_position == 'below') { // For these combinations, Zoom doesn't work
651 $thumbnail_effect = 'none';
652 }
653 else {
654 $thumbnail_effect = $effect;
655 }
656 return apply_filters('photonic_thumbnail_effect', $thumbnail_effect, $short_code, $layout, $title_position);
657 }
658
659 /**
660 * @param $short_code
661 * @param $processor
662 * @return array
663 */
664 private function get_container_details($short_code, $processor): array {
665 if ($short_code['display'] != 'popup') {
666 $container_id = "id='photonic-{$processor->provider}-stream-{$processor->gallery_index}-container'";
667 $container_end = "photonic-{$processor->provider}-stream-{$processor->gallery_index}-container-end";
668 } else {
669 $container_id = "id='photonic-{$processor->provider}-panel-" . $short_code['panel'] . "-container'";
670 $container_end = "photonic-{$processor->provider}-panel-{$short_code['panel']}-container-end";
671 }
672 return array($container_id, $container_end);
673 }
674
675 /**
676 * @param $short_code
677 * @param $processor
678 * @param array $pagination
679 * @param string $columns
680 * @return array
681 */
682 private function get_gallery_data_attributes($short_code, $processor, array $pagination, string $columns): array {
683 $pagination_data = '';
684 if (!empty($pagination)) {
685 $pagination_data = [];
686 // Should have total, start, end, per-page
687 foreach ($pagination as $meta => $value) {
688 $pagination_data[] = 'data-photonic-stream-' . $meta . '="' . $value . '"';
689 }
690
691 $pagination_data = implode(' ', $pagination_data);
692 if (empty($pagination['provider'])) {
693 $pagination_data .= ' data-photonic-stream-provider="' . $processor->provider . '"';
694 }
695 }
696
697 $to_be_glued = '';
698 if (!empty($short_code)) {
699 $to_be_glued = [];
700 foreach ($short_code as $name => $value) {
701 if (is_scalar($value)) {
702 $to_be_glued[] = $name . '=' . $value;
703 }
704 }
705 if (!empty($pagination['next-token'])) {
706 $to_be_glued[] = 'next_token=' . $pagination['next-token'];
707 }
708 $to_be_glued = implode('&', $to_be_glued);
709 $to_be_glued = esc_attr($to_be_glued);
710 }
711
712 $pagination_data .= ' data-photonic-stream-query="' . $to_be_glued . '"';
713 $columns_data = ' data-photonic-gallery-columns="' . $columns . '"';
714 return array($pagination_data, $pagination, $columns_data);
715 }
716 }
717