| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) |
| 3 |
exit; // Exit if accessed directly |
| 4 |
|
| 5 |
// Load Gallery Content |
| 6 |
// Prioritize plugin specific meta, fallback to WordPress defaults |
| 7 |
$ufg_title = !empty($ufg_gallery['ufg-title'][$attachment_id]) ? $ufg_gallery['ufg-title'][$attachment_id] : get_the_title($attachment_id); |
| 8 |
$ufg_alt = !empty($ufg_gallery['ufg-alt'][$attachment_id]) ? $ufg_gallery['ufg-alt'][$attachment_id] : get_post_meta($attachment_id, '_wp_attachment_image_alt', TRUE); |
| 9 |
$ufg_description = isset($ufg_gallery['ufg-description'][$attachment_id]) ? $ufg_gallery['ufg-description'][$attachment_id] : ''; |
| 10 |
|
| 11 |
// If plugin description is empty, fallback to WP attachment content |
| 12 |
if (empty($ufg_description)) { |
| 13 |
$attachment = get_post($attachment_id); |
| 14 |
$ufg_description = $attachment ? $attachment->post_content : ''; |
| 15 |
} |
| 16 |
|
| 17 |
// Fetch image URLs - Cast ID to int and remove icon flag for stability |
| 18 |
$attachment_id_int = (int) $attachment_id; |
| 19 |
$medium_size = !empty($ufg_thumbnail_image_size) ? $ufg_thumbnail_image_size : 'medium'; |
| 20 |
$medium = wp_get_attachment_image_src($attachment_id_int, $medium_size); |
| 21 |
$full = wp_get_attachment_image_src($attachment_id_int, 'full'); |
| 22 |
|
| 23 |
$ufg_url = ''; |
| 24 |
|
| 25 |
if (!function_exists('ufg_get_filter_ancestors')) { |
| 26 |
function ufg_get_filter_ancestors($filters, $target_key, $current_path = array()) { |
| 27 |
if (is_array($filters)) { |
| 28 |
foreach ($filters as $f) { |
| 29 |
if (!isset($f->filterkey)) continue; |
| 30 |
$clean_key = strtolower(trim($f->filterkey)); |
| 31 |
$f_class = str_replace(" ", "-", $clean_key); |
| 32 |
|
| 33 |
$new_path = $current_path; |
| 34 |
$new_path[] = $f_class; |
| 35 |
|
| 36 |
if ($clean_key === strtolower(trim($target_key))) { |
| 37 |
return $new_path; |
| 38 |
} |
| 39 |
|
| 40 |
if (isset($f->children) && is_array($f->children)) { |
| 41 |
$res = ufg_get_filter_ancestors($f->children, $target_key, $new_path); |
| 42 |
if (!empty($res)) { |
| 43 |
return $res; |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
return array(); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
if (isset($ufg_gallery['ufg-image-filters'][$attachment_id]) && is_array($ufg_gallery['ufg-image-filters'][$attachment_id]) && count($ufg_gallery['ufg-image-filters'][$attachment_id])) { |
| 53 |
$filters_raw = $ufg_gallery['ufg-image-filters'][$attachment_id]; |
| 54 |
$filters = array(); |
| 55 |
foreach ($filters_raw as $fr) { |
| 56 |
if (strpos($fr, ',') !== false) { |
| 57 |
$parts = explode(',', $fr); |
| 58 |
foreach ($parts as $p) { |
| 59 |
$p = trim($p); |
| 60 |
if (!empty($p)) { |
| 61 |
$filters[] = $p; |
| 62 |
} |
| 63 |
} |
| 64 |
} else { |
| 65 |
$filters[] = trim($fr); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
$expanded_filters = array(); |
| 70 |
foreach ($filters as $f) { |
| 71 |
$expanded_filters[] = str_replace(" ", "-", strtolower($f)); |
| 72 |
} |
| 73 |
$filters = array_values(array_unique($expanded_filters)); |
| 74 |
} else { |
| 75 |
$filters = array(); |
| 76 |
} |
| 77 |
?> |
| 78 |
<div |
| 79 |
class="ufg-thumbnail <?php echo esc_attr($load_class); ?> <?php echo esc_attr(implode(" ", $filters)); ?>"> |
| 80 |
<div class="ufg-thumbnail-border"> |
| 81 |
<!-- Lightbox = Show --> |
| 82 |
<?php |
| 83 |
$is_lightbox_enabled = ($ufg_lightbox === 'on' || $ufg_lightbox == 1 || $ufg_lightbox === '1' || $ufg_lightbox === true); |
| 84 |
if ($is_lightbox_enabled) { ?> |
| 85 |
|
| 86 |
<!-- Read more link on: Image(2) = Link On Image --> |
| 87 |
<?php if ($ufg_read_more_link == 2 && $ufg_url != "") { ?> |
| 88 |
<a href="<?php echo esc_url($ufg_url); ?>" target="<?php echo esc_attr($ufg_read_more_button_target); ?>" |
| 89 |
class="ufg-no-underline"> |
| 90 |
<div class="ufg-img-wrap"> |
| 91 |
<img loading="lazy" src="<?php echo esc_url($medium[0]); ?>" width="<?php echo esc_attr($medium[1]); ?>" height="<?php echo esc_attr($medium[2]); ?>" |
| 92 |
class="ufg-thumbnail-img ufg-img-responsive" alt="<?php echo esc_attr($ufg_alt); ?>"> |
| 93 |
</div> |
| 94 |
</a> |
| 95 |
<?php } else { ?> |
| 96 |
<!-- Read more link on: Button(1) = Lightbox --> |
| 97 |
<a href="<?php echo esc_url($full[0]); ?>" class="ufg-lightbox <?php echo esc_attr(implode(" ", $filters)); ?>" |
| 98 |
data-title="<?php |
| 99 |
$caption_parts = array(); |
| 100 |
$show_lb_title = ($ufg_lightbox_title === 'on' || $ufg_lightbox_title == 1 || $ufg_lightbox_title === '1' || $ufg_lightbox_title === true); |
| 101 |
$show_lb_description = false; |
| 102 |
|
| 103 |
if ($show_lb_title && !empty($ufg_title)) { |
| 104 |
$caption_parts[] = $ufg_title; |
| 105 |
} |
| 106 |
if ($show_lb_description && !empty($ufg_description)) { |
| 107 |
$caption_parts[] = substr($ufg_description, 0, (int) $ufg_image_description_text_limit); |
| 108 |
} |
| 109 |
echo esc_attr(implode(" - ", $caption_parts)); |
| 110 |
?>" data-lightbox="ufg-lightbox" data-alt="<?php echo esc_attr($ufg_alt); ?>"> |
| 111 |
<div class="border-expand-one"></div> |
| 112 |
<div class="ufg-img-wrap"> |
| 113 |
<img loading="lazy" src="<?php echo esc_url($medium[0]); ?>" width="<?php echo esc_attr($medium[1]); ?>" height="<?php echo esc_attr($medium[2]); ?>" |
| 114 |
class="ufg-thumbnail-img ufg-img-responsive" alt="<?php echo esc_attr($ufg_alt); ?>"> |
| 115 |
</div> |
| 116 |
<div class="border-expand-two"></div> |
| 117 |
</a> |
| 118 |
<?php } ?> |
| 119 |
|
| 120 |
<?php } else { ?> |
| 121 |
|
| 122 |
<!-- Lightbox = Hide --> |
| 123 |
<!-- Read more link on: Image(2) = Link On Image --> |
| 124 |
<?php if ($ufg_read_more_link == 2 && $ufg_url != "") { ?> |
| 125 |
<a href="<?php echo esc_url($ufg_url); ?>" target="<?php echo esc_attr($ufg_read_more_button_target); ?>" |
| 126 |
class="ufg-no-underline"> |
| 127 |
<div class="ufg-img-wrap"> |
| 128 |
<img loading="lazy" src="<?php echo esc_url($medium[0]); ?>" width="<?php echo esc_attr($medium[1]); ?>" height="<?php echo esc_attr($medium[2]); ?>" |
| 129 |
class="ufg-thumbnail-img ufg-img-responsive" alt="<?php echo esc_attr($ufg_alt); ?>"> |
| 130 |
</div> |
| 131 |
</a> |
| 132 |
<?php } else { ?> |
| 133 |
<div class="ufg-img-wrap"> |
| 134 |
<img loading="lazy" src="<?php echo esc_url($medium[0]); ?>" width="<?php echo esc_attr($medium[1]); ?>" height="<?php echo esc_attr($medium[2]); ?>" |
| 135 |
class="ufg-thumbnail-img ufg-img-responsive" alt="<?php echo esc_attr($ufg_alt); ?>"> |
| 136 |
</div> |
| 137 |
<?php } ?> |
| 138 |
|
| 139 |
<?php } ?> |
| 140 |
<?php |
| 141 |
$show_grid_title = ($ufg_image_title === 'on' || $ufg_image_title == 1 || $ufg_image_title === '1' || $ufg_image_title === true); |
| 142 |
$show_grid_description = ($ufg_image_description === 'on' || $ufg_image_description == 1 || $ufg_image_description === '1' || $ufg_image_description === true); |
| 143 |
$show_read_more = ($ufg_read_more_link_sh == 1); |
| 144 |
|
| 145 |
$has_title_text = ($show_grid_title && strlen($ufg_title) > 0); |
| 146 |
$has_desc_text = ($show_grid_description && strlen($ufg_description) > 0); |
| 147 |
$has_read_more_btn = ($show_read_more && ($ufg_read_more_link == 1 || empty($ufg_read_more_link)) && !empty($ufg_url)); |
| 148 |
|
| 149 |
if ($has_title_text || $has_desc_text || $has_read_more_btn) { ?> |
| 150 |
<div class="ufg-image-content"> |
| 151 |
<?php if ($show_grid_title) { ?> |
| 152 |
<?php if (strlen($ufg_title) > 0) { ?> |
| 153 |
<div class="ufg-image-title"><?php echo esc_html($ufg_title); ?></div> |
| 154 |
<?php } ?> |
| 155 |
<?php } ?> |
| 156 |
|
| 157 |
<?php if ($show_grid_description) { ?> |
| 158 |
<?php if (strlen($ufg_description) > 0) { ?> |
| 159 |
<div class="ufg-image-description"> |
| 160 |
<?php echo esc_html(substr($ufg_description, 0, (int) $ufg_image_description_text_limit)); ?> |
| 161 |
</div> |
| 162 |
<?php } ?> |
| 163 |
<?php } ?> |
| 164 |
|
| 165 |
<?php if ($show_read_more) { ?> |
| 166 |
<?php if (($ufg_read_more_link == 1 || empty($ufg_read_more_link)) && !empty($ufg_url)) { ?> |
| 167 |
<a href="<?php echo esc_url($ufg_url); ?>" target="<?php echo esc_attr($ufg_read_more_button_target); ?>" |
| 168 |
class="ufg-read-more-button ufg-no-underline"> |
| 169 |
<?php if (!empty($ufg_read_more_button_icon)) { ?> |
| 170 |
<i class="<?php echo esc_attr($ufg_read_more_button_icon); ?>"></i> |
| 171 |
<?php } ?> |
| 172 |
<?php echo esc_html($ufg_read_more_button_text); ?> |
| 173 |
<?php if ($ufg_read_more_button_icon != "") { ?> <?php } ?></a> |
| 174 |
<?php } ?> |
| 175 |
<?php } ?> |
| 176 |
</div> |
| 177 |
<?php } ?> |
| 178 |
</div> |
| 179 |
<input type="hidden" class="count_attached" value="<?php echo intval($attachment_id); ?>"> |
| 180 |
</div> |