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 / Layouts / Grid.php

Grid.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.41, at Layouts/Grid.php

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