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