push_to_stack('Generate level 1 gallery');
$layout = $short_code['layout'];
$columns = !empty($short_code['columns']) && ($layout !== 'random' && $layout !== 'mosaic') ? $short_code['columns'] : 'auto';
$display = !empty($short_code['display']) ? $short_code['display'] : 'in-page';
$more = !empty($short_code['more']) ? esc_attr($short_code['more']) : '';
$more = (empty($more) && !empty($short_code['photo_more'])) ? esc_attr($short_code['photo_more']) : $more;
$panel = !empty($short_code['panel']) ? $short_code['panel'] : '';
$title_position = empty($short_code['title_position']) ? $options['title_position'] : $short_code['title_position'];
$row_constraints = isset($options['row_constraints']) && is_array($options['row_constraints']) ? $options['row_constraints'] : [];
$sizes = isset($options['sizes']) && is_array($options['sizes']) ? $options['sizes'] : [];
$show_lightbox = !isset($options['show_lightbox']) ? true: $options['show_lightbox'];
$type = !empty($options['type']) ? $options['type'] : 'photo';
$parent = !empty($options['parent']) ? $options['parent'] : 'stream';
$pagination = isset($options['level_2_meta']) && is_array($options['level_2_meta']) ? $options['level_2_meta'] : [];
$indent = !isset($options['indent']) ? "\t" : $options['indent'];
list($container_id, $container_end) = $this->get_container_details($short_code, $module);
$non_standard = $layout == 'random' || $layout == 'masonry' || $layout == 'mosaic';
$col_class = '';
if (absint($columns)) {
$col_class = 'photonic-gallery-'.$columns.'c';
}
if ($col_class == '' && $row_constraints['constraint-type'] == 'padding') {
$col_class = 'photonic-pad-photos';
}
else if ($col_class == '') {
$col_class = 'photonic-gallery-'.$row_constraints['count'].'c';
}
$col_class .= ' photonic-level-1 photonic-thumb photonic-thumb-'.$layout;
$link_attributes = $this->get_lightbox_attributes($show_lightbox, $panel, $module);
$link_attributes_text = $this->get_text_from_link_attributes($link_attributes);
$effect = $this->get_thumbnail_effect($short_code, $layout, $title_position);
$ul_class = "class='title-display-$title_position photonic-level-1-container ".($non_standard ? 'photonic-'.$layout.'-layout' : 'photonic-standard-layout')." photonic-thumbnail-effect-$effect'";
if ($display == 'popup') {
$ul_class = "class='slideshow-grid-panel lib-{$this->library} photonic-level-1-container title-display-$title_position'";
}
$ret = '';
if (!$non_standard && $display != 'popup') {
$container_tag = 'ul';
$element_tag = 'li';
}
else {
$container_tag = 'div';
$element_tag = 'div';
}
list($pagination_data, $pagination, $columns_data) = $this->get_gallery_data_attributes($short_code, $module, $pagination, $columns);
$start_with = "$indent<$container_tag $container_id $ul_class $pagination_data $columns_data>\n";
$ret .= $start_with;
global $photonic_external_links_in_new_tab;
if (!empty($photonic_external_links_in_new_tab)) {
$target = " target='_blank' ";
}
else {
$target = '';
}
$counter = 0;
$thumbnail_class = " class='$layout' ";
$element_start = "$indent\t<".$element_tag.' class="photonic-'.$module->provider.'-image photonic-'.$module->provider.'-'.$type.' '.$col_class.'">'."\n";
$default_lightbox_text = apply_filters('photonic_default_lightbox_text', esc_attr__('View', 'photonic'));
foreach ($photos as $photo) {
$counter++;
$thumb = ($non_standard && $display == 'in-page') ? (isset($photo['tile_image']) ? $photo['tile_image'] : $photo['main_image']) : $photo['thumbnail'];
$orig = empty($photo['video']) ? $photo['main_image'] : $photo['video'];
// $orig = $photo['main_image'];
$url = isset($photo['main_page']) ? $photo['main_page'] : '';
$title = esc_attr($photo['title']);
$description = esc_attr($photo['description']);
$alt = esc_attr($photo['alt_title']);
$orig = ($this->library == 'none' || !$show_lightbox) ? $url : $orig;
$title = empty($title) ? ((empty($alt) && $module->link_lightbox_title && $this->library != 'thickbox') ? $default_lightbox_text : $alt) : $title;
$ret .= $element_start;
$deep_value = 'gallery[photonic-'.$module->provider.'-'.$parent.'-'.(empty($panel) ? $module->gallery_index : $panel).']/'.(empty($photo['id']) ? $counter : $photo['id']).'/';
$deep_link = ' data-photonic-deep="'.$deep_value.'" ';
$buy = '';
if (!empty($photo['buy_link']) && $module->show_buy_link) {
$buy = ' data-photonic-buy="'.$photo['buy_link'].'" ';
}
$style = [];
if (!empty($sizes['thumb-width'])) $style[] = 'width:'.$sizes['thumb-width'].'px';
if (!empty($sizes['thumb-height'])) $style[] = 'height:'.$sizes['thumb-height'].'px';
if (!empty($style)) $style = 'style="'.implode(';', $style).'"'; else $style = '';
if ($module->link_lightbox_title && $this->library != 'thickbox' && !empty($url)) {
$title_link_start = esc_attr("");
$title_link_end = esc_attr("");
}
else {
$title_link_start = '';
$title_link_end = '';
}
if (!empty($short_code['caption']) && ($short_code['caption'] == 'desc' || ($short_code['caption'] == 'title-desc' && empty($title)) || ($short_code['caption'] == 'desc-title' && !empty($description)))) {
$title = $description;
}
else if (empty($short_code['caption']) || (($short_code['caption'] == 'desc-title' && empty($title)) || $short_code['caption'] == 'none')) {
$title = '';
}
if (!empty($title)) {
$title_markup = $title_link_start.esc_attr($title).$title_link_end;
$title_markup = apply_filters('photonic_lightbox_title_markup', $title_markup);
}
else {
$title_markup = '';
}
if ($module->link_lightbox_title && $this->library != 'thickbox' && !empty($photo['buy_link']) && $module->show_buy_link) {
$buy_link = esc_attr('');
$title_markup .= $buy_link;
}
$shown_title = '';
if (in_array($title_position, ['below', 'hover-slideup-show', 'hover-slidedown-show', 'slideup-stick']) && !empty($title)) {
$shown_title = '
'.wp_specialchars_decode($title, ENT_QUOTES).'
';
}
$photo_data = ['title' => $title_markup, 'deep' => $deep_value, 'raw_title' => $title, 'href' => $orig];
if (!empty($photo['download'])) {
$photo_data['download'] = $photo['download'];
}
if (!empty($photo['video'])) {
$photo_data['video'] = $photo['video'];
}
else {
$photo_data['image'] = $photo['main_image'];
}
$photo_data['provider'] = $module->provider;
$photo_data['gallery_index'] = $module->gallery_index;
$photo_data['id'] = $photo['id'];
$lb_specific_data = $this->get_lightbox_specific_photo_data($photo_data, $module);
if (!empty($photo['video'])) {
$lb_specific_data .= ' data-photonic-media-type="video" ';
}
else {
$lb_specific_data .= ' data-photonic-media-type="image" ';
}
if (!empty($photo['video']) && $this->library == 'lightgallery') {
$video_id = $module->provider.'-'.$module->gallery_index.'-'.$photo['id'];
$ret .= $indent."\t\t".''."\n";
$ret .= $indent."\t\t\t".''."\n";
$ret .= $indent."\t\t".'
'."\n";
$orig = ''; // href should be blank
}
else if (!empty($photo['video']) && (in_array($this->library, ['colorbox', 'fancybox', 'fancybox2', 'magnific', 'photoswipe', 'swipebox',])
|| (in_array($this->library, ['fancybox3']) && in_array($module->provider, ['flickr', 'google']))
)) {
$video_id = $module->provider.'-'.$module->gallery_index.'-'.$photo['id'];
$ret .= $indent."\t\t".''."\n";
$ret .= $indent."\t\t\t".''."\n";
$ret .= $indent."\t\t".'
'."\n";
$orig = '#photonic-video-'.$video_id;
}
if ($this->library == 'magnific') {
$magnific = !empty($photo['video']) ? 'mfp-inline' : 'mfp-image';
$link_attributes['class']['magnific'] = $magnific;
$link_attributes_text = $this->get_text_from_link_attributes($link_attributes);
}
if ($title_position == 'tooltip') {
$tooltip = 'data-photonic-tooltip="'.esc_attr($title).'" ';
}
else {
$tooltip = '';
}
$ret .= $indent."\t\t".'\n";
$ret .= $indent."\t\t\t".'
\n";
$ret .= $indent."\t\t\t".$shown_title."\n";
$ret .= $indent."\t\t"."\n";
$ret .= $indent."\t"."$element_tag>\n";
}
$ret = trim($ret);
if ($ret != $start_with) {
$trailing = strlen($element_tag) + 3;
if (substr($ret, -$trailing) != "$element_tag>" && $short_code['popup'] == 'show' && !$non_standard) {
$ret .= "\n$indent$element_tag>";
}
$ret .= "\n$indent$container_tag> \n";
$ret .= "";
if (!empty($pagination) && isset($pagination['end']) && isset($pagination['total']) && $pagination['total'] > $pagination['end']) {
$ret .= !empty($more) ? "$more\n" : '';
}
}
else {
$ret = '';
}
if (is_archive() || is_home()) {
global $photonic_archive_thumbs;
if (!empty($photonic_archive_thumbs) && $counter < $photonic_archive_thumbs) {
$module->is_more_required = false;
}
}
$module->pop_from_stack();
return $ret;
}
/**
* Generates the HTML for a group of level-2 items, i.e. Photosets (Albums) and Galleries for Flickr, Albums for Google Photos,
* Albums for SmugMug, and Photosets (Galleries and Collections) for Zenfolio. No concept of albums
* exists in native WP and Instagram.
*
* @param $objects
* @param $options
* @param $short_code
* @param $module Core
* @return string
*/
function generate_level_2_gallery($objects, $options, $short_code, $module) {
$module->push_to_stack('Generate Level 2 Gallery');
$row_constraints = isset($options['row_constraints']) && is_array($options['row_constraints']) ? $options['row_constraints'] : [];
$type = $options['type'];
$singular_type = $options['singular_type'];
$title_position = empty($short_code['title_position']) ? $options['title_position'] : $short_code['title_position'];
$level_1_count_display = $options['level_1_count_display'];
$indent = !isset($options['indent']) ? '' : $options['indent'];
$provider = $module->provider;
$columns = $short_code['columns'];
$layout = !isset($short_code['layout']) ? 'square' : $short_code['layout'];
$popup = ' data-photonic-popup="'.$short_code['popup'].'"';
$non_standard = $layout == 'random' || $layout == 'masonry' || $layout == 'mosaic';
$effect = $this->get_thumbnail_effect($short_code, $layout, $title_position);
$ul_class = "class='title-display-$title_position photonic-level-2-container ".($non_standard ? 'photonic-'.$layout.'-layout' : 'photonic-standard-layout')." photonic-thumbnail-effect-$effect'";
list($container_id, $container_end) = $this->get_container_details($short_code, $module);
$pagination = isset($options['pagination']) && is_array($options['pagination']) ? $options['pagination'] : [];
$more = !empty($short_code['more']) ? esc_attr($short_code['more']) : '';
list($pagination_data, $pagination, $columns_data) = $this->get_gallery_data_attributes($short_code, $module, $pagination, $columns);
$ret = "\n$indent";
if ($non_standard) {
$ret = "\n$indent";
}
if ($columns != 'auto') {
$col_class = 'photonic-gallery-'.$columns.'c';
}
else if ($row_constraints['constraint-type'] == 'padding') {
$col_class = 'photonic-pad-'.$type;
}
else {
$col_class = 'photonic-gallery-'.$row_constraints['count'].'c';
}
$col_class .= ' photonic-level-2 photonic-thumb';
$counter = 0;
foreach ($objects as $object) {
$data_attributes = isset($object['data_attributes']) && is_array($object['data_attributes']) ? $object['data_attributes'] : [];
$data_attributes['provider'] = $provider;
$data_attributes['singular'] = $singular_type;
$data_array = [];
foreach ($data_attributes as $attr => $value) {
$data_array[] = 'data-photonic-'.$attr.'="'.$value.'"';
}
$data_array = implode(' ', $data_array);
$id = empty($object['id_1']) ? '' : $object['id_1'].'-';
$id = $id.$module->gallery_index;
$id = empty($object['id_2']) ? $id : ($id.'-'.$object['id_2']);
$title = esc_attr($object['title']);
$image = "

";
$additional_classes = !empty($object['classes']) ? implode(' ', $object['classes']) : '';
$realm_class = '';
if (!empty($object['classes'])) {
foreach ($object['classes'] as $class) {
if (stripos($class, 'photonic-'.$provider.'-realm') !== FALSE) {
$realm_class = $class;
}
}
}
if ($title_position == 'tooltip') {
$tooltip = "data-photonic-tooltip='".esc_attr($title)."' ";
}
else {
$tooltip = '';
}
if (empty($object['gallery_url'])) {
$anchor = "\n{$indent}\t\t
\n$indent\t\t\t".$image;
}
else {
$anchor = "\n{$indent}\t\t\n$indent\t\t\t".$image;
}
$text = '';
if (in_array($title_position, ['below', 'hover-slideup-show', 'hover-slidedown-show', 'slideup-stick'])) {
$text = "\n{$indent}\t\t\t\n{$indent}\t\t\t\t
".$title."";
if (!$level_1_count_display && !empty($object['counter'])) {
$text .= ''.sprintf(esc_html__('%s photos', 'photonic'), $object['counter']).'';
}
}
if ($text != '') {
$text .= "
\n{$indent}\t\t\t
";
}
$anchor .= $text."\n{$indent}\t\t";
$password_prompt = '';
if (!empty($object['passworded'])) {
$prompt_title = esc_attr__('Protected Content', 'photonic');
$prompt_submit = esc_attr__('Access', 'photonic');
$password_type = " type='password' ";
$prompt_type = 'password';
$prompt_text = esc_attr__('This album is password-protected. Please provide a valid password.', 'photonic');
if (in_array("photonic-$provider-passworded-authkey", $object['classes'])) {
$prompt_text = esc_attr__('This album is protected. Please provide a valid authorization key.', 'photonic');
}
else if (in_array("photonic-$provider-passworded-link", $object['classes'])) {
$prompt_text = esc_attr__('This album is protected. Please provide the short-link for it.', 'photonic');
$password_type = '';
$prompt_type = 'link';
}
$password_prompt = "
";
}
if ($non_standard) {
$ret .= "\n$indent\t
{$anchor}{$password_prompt}\n$indent\t
";
}
else {
$ret .= "\n$indent\t
- {$anchor}{$password_prompt}\n$indent\t
";
}
$counter++;
}
if ($ret != "\n$indent
" && !$non_standard) {
$ret .= "\n$indent
\n";
}
else if ($non_standard) {
$ret .= "\n$indent
\n";
}
else {
$ret = '';
}
if (!empty($ret)) {
$ret .= "";
if (!empty($pagination) && isset($pagination['end']) && isset($pagination['total']) && $pagination['total'] > $pagination['end']) {
$ret .= !empty($more) ? "$more\n" : '';
}
}
if (is_archive() || is_home()) {
global $photonic_archive_thumbs;
if (!empty($photonic_archive_thumbs) && $counter < $photonic_archive_thumbs) {
$module->is_more_required = false;
}
}
$module->pop_from_stack();
return $ret;
}
/**
* @param $short_code
* @param $module
* @return array
*/
private function get_container_details($short_code, $module) {
if ($short_code['display'] != 'popup') {
$container_id = "id='photonic-{$module->provider}-stream-{$module->gallery_index}-container'";
$container_end = "photonic-{$module->provider}-stream-{$module->gallery_index}-container-end";
} else {
$container_id = "id='photonic-{$module->provider}-panel-" . $short_code['panel'] . "-container'";
$container_end = "photonic-{$module->provider}-panel-{$short_code['panel']}-container-end";
}
return [$container_id, $container_end];
}
/**
* @param array $link_attributes
* @return string
*/
private function get_text_from_link_attributes($link_attributes) {
$class = '';
$rel = '';
$specific = '';
if (!empty($link_attributes['class'])) {
$class = " class='".implode(' ', array_values($link_attributes['class']))."' ";
}
if (!empty($link_attributes['rel'])) {
$rel = " rel='".implode(' ', $link_attributes['rel'])."' ";
}
if (!empty($link_attributes['specific'])) {
foreach ($link_attributes['specific'] as $key => $val) {
$specific .= $key.'="'.implode(' ', $val).'" ';
}
}
return $class.$rel.$specific;
}
/**
* Depending on the lightbox library, this function provides the CSS class and the rel tag for the thumbnail. This method borrows heavily from
* Justin Tadlock's Cleaner Gallery Plugin.
*
* @param $show_lightbox
* @param $rel_id
* @param $module
* @return array
*/
private function get_lightbox_attributes($show_lightbox, $rel_id, $module) {
global $photonic_slideshow_mode;
$rel = '';
$ret = [
'class' => [],
'rel' => [],
'specific' => [],
];
if ($this->library != 'none' && $show_lightbox) {
$ret['class'] = ['photonic-launch-gallery', 'launch-gallery-'.$this->library, $this->library];
$rel = 'lightbox-photonic-'.$module->provider.'-stream-'.(empty($rel_id) ? $module->gallery_index : $rel_id);
$ret['rel'] = [$rel];
switch ($this->library) {
case 'fancybox2':
$ret['class'] = ['photonic-launch-gallery', 'launch-gallery-fancybox', 'fancybox'];
break;
case 'fancybox3':
$ret['class'] = ['photonic-launch-gallery', 'launch-gallery-fancybox', 'fancybox'];
$ret['specific'] = [
'data-fancybox' => [$rel],
];
break;
case 'prettyphoto':
$ret['rel'] = ["photonic-prettyPhoto[{$rel}]"];
break;
case 'featherlight':
$ret['class'] = ['photonic-launch-gallery', 'launch-gallery-featherlight'];
break;
case 'lightcase':
$ret['specific'] = [
'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' : '')],
];
break;
case 'strip':
global $photonic_lightbox_no_loop;
$ret['specific'] = [
'data-strip-group' => [$rel],
];
if (!empty($photonic_lightbox_no_loop)) {
$ret['specific']['data-strip-group-options'] = ["loop: false"];
}
break;
default:
$ret['class'] = ['photonic-launch-gallery', 'launch-gallery-'.$this->library, $this->library];
$ret['rel'] = ['lightbox-photonic-'.$module->provider.'-stream-'.(empty($rel_id) ? $module->gallery_index : $rel_id)];
break;
}
}
return $ret;
}
/**
* Some lightboxes require some additional attributes for individual photos. E.g. Lightgallery requires something to show the title etc.
* This method returns such additional information. Not to be confused with get_lightbox_attributes, which
* returns information for the gallery as a whole.
*
* @param $photo_data
* @return string
*/
private function get_lightbox_specific_photo_data($photo_data, $module) {
if ($this->library == 'lightgallery') {
$download = !empty($photo_data['download']) ? 'data-download-url="'.$photo_data['download'].'" ' : '';
$video = !empty($photo_data['video']) ? ' data-html="#photonic-video-'.$module->provider.'-'.$module->gallery_index.'-'.$photo_data['id'].'" ' : '';
return ' data-sub-html="'.$photo_data['title'].'" '.$video.$download;
}
else if ($this->library == 'strip') {
return ' data-strip-caption="'.$photo_data['title'].'" data-strip-options="onShow: function(a) { photonicStripSetHash('."'{$photo_data['deep']}'".'); }, afterHide: function() { photonicStripUnsetHash(); } " ';
}
else if ($this->library == 'lightcase' && $module->provider == 'google') {
if (empty($photo_data['video'])) {
return " data-lc-options='{\"type\": \"image\"}' ";
}
else {
return " data-lc-options='{\"type\": \"video\"}' ";
}
}
else if ($this->library == 'fancybox' && $module->provider == 'google') {
if (empty($photo_data['video'])) {
return " data-fancybox='{type: \"image\"}' ";
}
}
else if ($this->library == 'fancybox2' && $module->provider == 'google') {
if (empty($photo_data['video'])) {
return " data-fancybox-type='image' ";
}
}
else if (in_array($this->library, ['colorbox', 'fancybox', 'fancybox2', 'photoswipe', 'swipebox',]) ||
(in_array($this->library, ['fancybox3', 'lightcase']) && in_array($module->provider, ['flickr'])) ||
(in_array($this->library, ['fancybox3',]) && in_array($module->provider, ['google']))) {
return !empty($photo_data['video']) ? ' data-html5-href="'.$photo_data['video'].'" ': '';
}
else if ($this->library == 'featherlight') {
$mime = (!empty($photo['mime']) ? $photo['mime']: 'video/mp4');
if ($module->provider == 'google' && empty($photo_data['video'])) {
return " data-featherlight-type='image' ";
}
else if ($module->provider == 'google' && !empty($photo_data['video'])) {
return " data-featherlight='' data-featherlight-type='html'";
}
return !empty($photo_data['video']) ? " data-featherlight='' data-featherlight-type='video'" : '';
}
return '';
}
/**
* @param $short_code
* @param $module
* @param $pagination
* @param $columns
* @return array
*/
private function get_gallery_data_attributes($short_code, $module, $pagination, $columns) {
$pagination_data = '';
if (!empty($pagination)) {
$pagination_data = [];
// Should have total, start, end, per-page
foreach ($pagination as $meta => $value) {
$pagination_data[] = 'data-photonic-stream-' . $meta . '="' . $value . '"';
}
$pagination_data = implode(' ', $pagination_data);
if (empty($pagination['provider'])) {
$pagination_data .= ' data-photonic-stream-provider="' . $module->provider . '"';
}
}
$to_be_glued = '';
if (!empty($short_code)) {
$to_be_glued = [];
foreach ($short_code as $name => $value) {
if (is_scalar($value)) {
$to_be_glued[] = $name . '=' . $value;
}
}
if (!empty($pagination['next-token'])) {
$to_be_glued[] = 'next_token=' . $pagination['next-token'];
}
$to_be_glued = implode('&', $to_be_glued);
$to_be_glued = esc_attr($to_be_glued);
}
$pagination_data .= ' data-photonic-stream-query="' . $to_be_glued . '"';
$columns_data = ' data-photonic-gallery-columns="' . $columns . '"';
return [$pagination_data, $pagination, $columns_data];
}
/**
* Returns the thumbnail effect that should be used for a gallery. Not all effects can be used by all types of layouts.
*
* @param $short_code
* @param $layout
* @param $title_position
* @return string
*/
private function get_thumbnail_effect($short_code, $layout, $title_position) {
if (!empty($short_code['thumbnail_effect'])) {
$effect = $short_code['thumbnail_effect'];
}
else {
global $photonic_standard_thumbnail_effect, $photonic_justified_thumbnail_effect, $photonic_mosaic_thumbnail_effect, $photonic_masonry_thumbnail_effect;
$effect = $layout == 'mosaic' ? $photonic_mosaic_thumbnail_effect :
($layout == 'masonry' ? $photonic_masonry_thumbnail_effect :
($layout == 'random' ? $photonic_justified_thumbnail_effect :
$photonic_standard_thumbnail_effect));
}
if ($layout == 'circle' && $effect != 'opacity') { // "Zoom" doesn't work for circle
$thumbnail_effect = 'none';
}
else if (($layout == 'square' || $layout == 'launch' || $layout == 'masonry') && $title_position == 'below') { // For these combinations, Zoom doesn't work
$thumbnail_effect = 'none';
}
else {
$thumbnail_effect = $effect;
}
return apply_filters('photonic_thumbnail_effect', $thumbnail_effect, $short_code, $layout, $title_position);
}
}