| 1 |
<?php |
| 2 |
/** |
| 3 |
* Taxonomy Block Class for Smart Post Show Pro |
| 4 |
* |
| 5 |
* @package Smart_Post_Show_Pro |
| 6 |
* @subpackage Smart_Post_Show_Pro/blocks/includes |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SmartPostShow\Blocks; |
| 10 |
|
| 11 |
use SmartPostShow\Blocks\Helper; |
| 12 |
|
| 13 |
use SmartPostShow\Blocks\Block_Base; |
| 14 |
|
| 15 |
defined( 'ABSPATH' ) || exit; |
| 16 |
|
| 17 |
/** |
| 18 |
* Handles rendering of the Taxonomy block |
| 19 |
*/ |
| 20 |
class Taxonomy extends Block_Base { |
| 21 |
|
| 22 |
|
| 23 |
/** |
| 24 |
* Sets block properties |
| 25 |
* |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
protected function set_block_properties() { |
| 29 |
$this->block_name = 'taxonomy'; |
| 30 |
|
| 31 |
$this->styles = array( 'sp_smart_post_blocks_css', 'sp_smart_post_blocks_google_fonts', 'sp_smart_post_blocks_social_icons_style' ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Renders the Taxonomy block (consolidated single-method version) |
| 36 |
* |
| 37 |
* @param array $attributes Block attributes. |
| 38 |
* @param string $content Existing block content. |
| 39 |
* @param array $blocks array. |
| 40 |
* @return string Rendered HTML |
| 41 |
*/ |
| 42 |
public function render_block( $attributes, $content = '', $blocks = array() ) { |
| 43 |
if ( Helper::is_editor_page() ) { |
| 44 |
return $content; |
| 45 |
} |
| 46 |
|
| 47 |
// Get settings with fallbacks. |
| 48 |
$attributes['page_id'] = get_the_ID(); |
| 49 |
unset( $attributes['dynamicCss'], $attributes['fontListsEditPage'], $attributes['fontLists'] ); |
| 50 |
$unique_id = $attributes['uniqueId'] ?? ''; |
| 51 |
$block_name = sanitize_html_class( $attributes['blockName'] ?? '' ); |
| 52 |
$layout = $attributes['layout'] ?? 'taxonomy-layout-one'; |
| 53 |
$no_result_found_text = $attributes['noResultFoundText'] ?? 'No Data Found'; |
| 54 |
$taxonomy_type = $attributes['taxonomyType'] ?? 'category'; |
| 55 |
$empty_category = $attributes['emptyCategory'] ?? true; |
| 56 |
$all_taxonomy_term = $attributes['allTaxonomyTerm'] ?? true; |
| 57 |
$include_terms = $attributes['SelectTerms'] ?? array(); |
| 58 |
$exclude_terms = $attributes['excludeTerms'] ?? array(); |
| 59 |
$limit = $attributes['limit'] ?? 6; |
| 60 |
$is_layout_five_six = in_array( $layout, array( 'taxonomy-layout-five', 'taxonomy-layout-six' ) ); |
| 61 |
$align_class = ! empty( $attributes['align'] ) ? 'align' . $attributes['align'] : ''; |
| 62 |
$title_enable = $attributes['titleEnable'] ?? true; |
| 63 |
$display_overly_thum = $attributes['displayOverlyThum'] ?? true; |
| 64 |
$display_overly_hover_thum = $attributes['displayOverlyHoverThum'] ?? true; |
| 65 |
$after_count = $attributes['afterCount'] ?? ')'; |
| 66 |
$before_count = $attributes['beforeCount'] ?? '('; |
| 67 |
$count_enable = $attributes['countEnable'] ?? true; |
| 68 |
$content_multi_color_bg = $attributes['contentMultiColorBg'] ?? true; |
| 69 |
$icon = $attributes['icon'] ?? true; |
| 70 |
$show_hide_divider = $attributes['showHideDivider'] ?? true; |
| 71 |
$show_excerpt = $attributes['excerptShow'] ?? false; |
| 72 |
$taxonomy_icon_style = $attributes['taxonomyIconStyle'] ?? ''; |
| 73 |
$counter_multi_color_bg = $attributes['counterMultiColorBg'] ?? ''; |
| 74 |
$excerpt_length = $attributes['excerptLength'] ?? 7; |
| 75 |
$post_card_bg = $attributes['postCardBg'] ?? array(); |
| 76 |
$image_overlay_color = $attributes['imageOverlayColor'] ?? ''; |
| 77 |
$image_overlay_hover_color = $attributes['imageOverlayHoverColor'] ?? ''; |
| 78 |
$image_overlay_custom_color = $attributes['imageOverlayCustomColor'] ?? ''; |
| 79 |
$image_overlay_custom_hover_color = $attributes['imageOverlayCustomHoverColor'] ?? ''; |
| 80 |
$image_enable = $attributes['imageEnable'] ?? true; |
| 81 |
$hover_effect = $attributes['hoverEffect'] ?? 'normal'; |
| 82 |
$image_overlay = $attributes['imageOverlay'] ?? ''; |
| 83 |
$hover_animation = $attributes['hoverAnimation'] ?? ''; |
| 84 |
$title_global_typography_class = isset( $attributes['titleGlobalTypography']['class'] ) ? $attributes['titleGlobalTypography']['class'] : ''; |
| 85 |
$excerpt_global_typography_class = isset( $attributes['excerptGlobalTypography']['class'] ) ? $attributes['excerptGlobalTypography']['class'] : ''; |
| 86 |
$counter_global_typography_class = isset( $attributes['counterGlobalTypography']['class'] ) ? $attributes['counterGlobalTypography']['class'] : ''; |
| 87 |
|
| 88 |
$base_args = array( |
| 89 |
'layout' => $layout, |
| 90 |
'title_enable' => $title_enable, |
| 91 |
'after_count' => $after_count, |
| 92 |
'before_count' => $before_count, |
| 93 |
'count_enable' => $count_enable, |
| 94 |
'show_excerpt' => $show_excerpt, |
| 95 |
'excerpt_length' => $excerpt_length, |
| 96 |
'title_global_typography_class' => $title_global_typography_class, |
| 97 |
'excerpt_global_typography_class' => $excerpt_global_typography_class, |
| 98 |
'counter_global_typography_class' => $counter_global_typography_class, |
| 99 |
); |
| 100 |
|
| 101 |
$args_five_six = array_merge( |
| 102 |
$base_args, |
| 103 |
array( |
| 104 |
'image_overlay' => $image_overlay, |
| 105 |
'hover_effect' => $hover_effect, |
| 106 |
'image_enable' => $image_enable, |
| 107 |
) |
| 108 |
); |
| 109 |
|
| 110 |
$args_default = array_merge( |
| 111 |
$base_args, |
| 112 |
array( |
| 113 |
'display_overly_thum' => $display_overly_thum, |
| 114 |
'display_overly_hover_thum' => $display_overly_hover_thum, |
| 115 |
'content_multi_color_bg' => $content_multi_color_bg, |
| 116 |
'icon' => $icon, |
| 117 |
'show_hide_divider' => $show_hide_divider, |
| 118 |
'taxonomy_icon_style' => $taxonomy_icon_style, |
| 119 |
'counter_multi_color_bg' => $counter_multi_color_bg, |
| 120 |
'hover_animation' => $hover_animation, |
| 121 |
'post_card_bg' => $post_card_bg, |
| 122 |
'image_overlay_color' => $image_overlay_color, |
| 123 |
'image_overlay_hover_color' => $image_overlay_hover_color, |
| 124 |
'image_overlay_custom_color' => $image_overlay_custom_color, |
| 125 |
'image_overlay_custom_hover_color' => $image_overlay_custom_hover_color, |
| 126 |
|
| 127 |
) |
| 128 |
); |
| 129 |
|
| 130 |
// Loader markup before fetching terms. |
| 131 |
ob_start(); |
| 132 |
?> |
| 133 |
<div id="<?php echo esc_attr( $unique_id ); ?>" class="sp-smart-post-<?php echo esc_attr( $block_name ); ?> <?php echo esc_attr( $align_class ); ?> "> |
| 134 |
|
| 135 |
<!-- Loader (Visible on load) --> |
| 136 |
<div class="sp-taxonomy-loader" id="sp-loader-<?php echo esc_attr( $unique_id ); ?>"> |
| 137 |
<img src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '../../../public/assets/img/preloader.svg' ); ?>" alt="Loading..." /> |
| 138 |
</div> |
| 139 |
<?php |
| 140 |
|
| 141 |
$terms = Helper::get_custom_terms_by_type( $taxonomy_type, $empty_category, $include_terms, $limit, $exclude_terms, $all_taxonomy_term ); |
| 142 |
|
| 143 |
?> |
| 144 |
<!-- Rendered Terms --> |
| 145 |
<div class="sp-smart-post-taxonomy-render" id="sp-content-<?php echo esc_attr( $unique_id ); ?>"> |
| 146 |
<?php if ( ! empty( $terms ) ) : ?> |
| 147 |
<?php foreach ( $terms as $term ) : ?> |
| 148 |
<?php if ( $is_layout_five_six ) : ?> |
| 149 |
<?php echo wp_kses_post( $this->render_five_six_layout( $term, $args_five_six ) ); ?> |
| 150 |
<?php else : ?> |
| 151 |
<?php |
| 152 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The HTML output is already properly escaped at the time of generation, so additional escaping is not required here. |
| 153 |
echo $this->render_default_layout( $term, $args_default ); |
| 154 |
?> |
| 155 |
<?php endif; ?> |
| 156 |
<?php endforeach; ?> |
| 157 |
<?php else : ?> |
| 158 |
<p class="sp-taxonomy-no-results"> |
| 159 |
<?php |
| 160 |
echo esc_html( ! empty( $no_result_found_text ) ? $no_result_found_text : 'No result found.' ); |
| 161 |
?> |
| 162 |
|
| 163 |
</p> |
| 164 |
<?php endif; ?> |
| 165 |
|
| 166 |
</div> |
| 167 |
|
| 168 |
<!-- Inline style and loader logic --> |
| 169 |
<style> |
| 170 |
.sp-taxonomy-loader { |
| 171 |
text-align: center; |
| 172 |
padding: 40px 0; |
| 173 |
} |
| 174 |
|
| 175 |
.sp-loader-svg { |
| 176 |
width: 50px; |
| 177 |
height: 50px; |
| 178 |
} |
| 179 |
</style> |
| 180 |
<script> |
| 181 |
document.addEventListener('DOMContentLoaded', function() { |
| 182 |
const loader = document.getElementById('sp-loader-<?php echo esc_js( $unique_id ); ?>'); |
| 183 |
const content = document.getElementById('sp-content-<?php echo esc_js( $unique_id ); ?>'); |
| 184 |
|
| 185 |
if (loader && content) { |
| 186 |
loader.style.display = 'none'; |
| 187 |
content.style.display = 'grid'; |
| 188 |
} |
| 189 |
}); |
| 190 |
</script> |
| 191 |
|
| 192 |
</div> |
| 193 |
<?php |
| 194 |
|
| 195 |
return $content . ob_get_clean(); |
| 196 |
} |
| 197 |
/** |
| 198 |
* Renders the default_layout. |
| 199 |
* |
| 200 |
* @param object $term item data. |
| 201 |
* @param array $args of the attributes. |
| 202 |
* @return string Rendered HTML |
| 203 |
*/ |
| 204 |
private function render_default_layout( $term, $args = array() ) { |
| 205 |
|
| 206 |
$layout = $args['layout'] ?? ''; |
| 207 |
$title_enable = $args['title_enable'] ?? false; |
| 208 |
$display_overly_thum = $args['display_overly_thum'] ?? ''; |
| 209 |
$display_overly_hover_thum = $args['display_overly_hover_thum'] ?? ''; |
| 210 |
$after_count = $args['after_count'] ?? 0; |
| 211 |
$before_count = $args['before_count'] ?? 0; |
| 212 |
$count_enable = $args['count_enable'] ?? false; |
| 213 |
$content_multi_color_bg = $args['content_multi_color_bg'] ?? ''; |
| 214 |
$icon = $args['icon'] ?? ''; |
| 215 |
$show_hide_divider = $args['show_hide_divider'] ?? false; |
| 216 |
$show_excerpt = $args['show_excerpt'] ?? false; |
| 217 |
$taxonomy_icon_style = $args['taxonomy_icon_style'] ?? ''; |
| 218 |
$counter_multi_color_bg = $args['counter_multi_color_bg'] ?? ''; |
| 219 |
$excerpt_length = $args['excerpt_length'] ?? 0; |
| 220 |
$hover_animation = $args['hover_animation'] ?? ''; |
| 221 |
$post_card_bg = $args['post_card_bg'] ?? ''; |
| 222 |
$image_overlay_color = $args['image_overlay_color'] ?? ''; |
| 223 |
$image_overlay_hover_color = $args['image_overlay_hover_color'] ?? ''; |
| 224 |
$image_overlay_custom_color = $args['image_overlay_custom_color'] ?? ''; |
| 225 |
$image_overlay_custom_hover_color = $args['image_overlay_custom_hover_color'] ?? ''; |
| 226 |
$should_show_count_in_name = $count_enable && in_array( $layout, array( 'taxonomy-layout-four', 'taxonomy-layout-eight' ), true ); |
| 227 |
$should_show_before_after_count = in_array( $layout, array( 'taxonomy-layout-seven', 'taxonomy-layout-eight' ), true ); |
| 228 |
$placeholder_img = apply_filters( 'pcp_no_thumb_placeholder', SP_PC_URL . 'public/assets/img/placeholder.png' ); |
| 229 |
$title_global_typography_class = $args['title_global_typography_class'] ?? ''; |
| 230 |
$excerpt_global_typography_class = $args['excerpt_global_typography_class'] ?? ''; |
| 231 |
$counter_global_typography_class = $args['counter_global_typography_class'] ?? ''; |
| 232 |
|
| 233 |
$args = array( |
| 234 |
'term' => $term, |
| 235 |
'placeholder_img' => $placeholder_img, |
| 236 |
'display_overly_thum' => $display_overly_thum, |
| 237 |
'display_overly_hover_thum' => $display_overly_hover_thum, |
| 238 |
'post_card_bg' => $post_card_bg, |
| 239 |
'image_overlay_color' => $image_overlay_color, |
| 240 |
'image_overlay_hover_color' => $image_overlay_hover_color, |
| 241 |
'image_overlay_custom_color' => $image_overlay_custom_color, |
| 242 |
'image_overlay_custom_hover_color' => $image_overlay_custom_hover_color, |
| 243 |
'layout' => $layout, |
| 244 |
); |
| 245 |
|
| 246 |
$hover = $this->hover_animate( $hover_animation ?? '', $layout ); |
| 247 |
|
| 248 |
// --- Inline style variables (overlay effects) --- |
| 249 |
$style_array = ( 'taxonomy-layout-three' !== $layout ) |
| 250 |
? $this->get_style( $args ) |
| 251 |
: array(); |
| 252 |
|
| 253 |
$style_array['--transformValue'] = $hover['transformValue'] ?? ''; |
| 254 |
$style_array['--initialValue'] = $hover['initialValue'] ?? ''; |
| 255 |
|
| 256 |
$inline_style = ''; |
| 257 |
foreach ( $style_array as $key => $value ) { |
| 258 |
if ( ! empty( $value ) ) { |
| 259 |
$inline_style .= esc_attr( $key ) . ':' . esc_attr( $value ) . ';'; |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
// --- Counter style for inline badge --- |
| 264 |
$counter_style_attr = ''; |
| 265 |
if ( $should_show_count_in_name && $counter_multi_color_bg && ! empty( $term->category_color ) ) { |
| 266 |
$counter_style_attr = 'background:' . esc_attr( $term->category_color ) . ';'; |
| 267 |
} |
| 268 |
|
| 269 |
// --- Main wrapper background for layout-8 and layout-3 --- |
| 270 |
$style = array(); |
| 271 |
|
| 272 |
$layout_four_eight = array( 'taxonomy-layout-four', 'taxonomy-layout-eight' ); |
| 273 |
|
| 274 |
if ( in_array( $layout, $layout_four_eight, true ) ) { |
| 275 |
$style['background'] = ! empty( $term->category_color ) ? $term->category_color : '#FFFFFF'; |
| 276 |
} |
| 277 |
|
| 278 |
if ( 'taxonomy-layout-three' === $layout ) { |
| 279 |
$style = array_merge( $style, $this->get_style( $args ) ); |
| 280 |
} |
| 281 |
|
| 282 |
$style_attr = ''; |
| 283 |
foreach ( $style as $key => $value ) { |
| 284 |
if ( ! empty( $value ) ) { |
| 285 |
$style_attr .= esc_attr( $key ) . ':' . esc_attr( $value ) . ';'; |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
$should_show_excerpt = $show_excerpt && in_array( |
| 290 |
$layout, |
| 291 |
array( |
| 292 |
'taxonomy-layout-one', |
| 293 |
'taxonomy-layout-two', |
| 294 |
'taxonomy-layout-three', |
| 295 |
'taxonomy-layout-five', |
| 296 |
'taxonomy-layout-six', |
| 297 |
), |
| 298 |
true |
| 299 |
); |
| 300 |
|
| 301 |
ob_start(); |
| 302 |
?> |
| 303 |
<div style="<?php echo esc_attr( $inline_style ); ?>" |
| 304 |
|
| 305 |
|
| 306 |
class="<?php echo esc_attr( $this->get_taxonomy_class( $layout, $display_overly_thum, $display_overly_hover_thum, $show_hide_divider ) ); ?>"> |
| 307 |
<div style="<?php echo esc_attr( $style_attr ); ?>" |
| 308 |
class=" |
| 309 |
<?php |
| 310 |
echo esc_attr( |
| 311 |
implode( |
| 312 |
' ', |
| 313 |
array_filter( |
| 314 |
array( |
| 315 |
'sp-smart-post-taxonomy-name', |
| 316 |
( 'taxonomy-layout-three' === $layout ) ? 'sp-smart-post-taxonomy-name-layout-three' : '', |
| 317 |
( $display_overly_thum && 'taxonomy-layout-three' === $layout ) ? 'sp-taxonomy-overlay-three' : '', |
| 318 |
( $display_overly_hover_thum && 'taxonomy-layout-three' === $layout ) ? 'sp-taxonomy-hover-overlay-three' : '', |
| 319 |
) |
| 320 |
) |
| 321 |
) |
| 322 |
); |
| 323 |
?> |
| 324 |
"> |
| 325 |
<?php if ( $title_enable ) : ?> |
| 326 |
|
| 327 |
<div class="sps-taxonomy-title-wrapper"> |
| 328 |
<?php if ( ! empty( $icon ) ) : ?> |
| 329 |
<span style="z-index: 2;" class="sp-smart-post-taxonomy-icon"> |
| 330 |
<i class="sp-icon-left-<?php echo esc_attr( $taxonomy_icon_style ); ?>"></i> |
| 331 |
</span> |
| 332 |
<?php endif; ?> |
| 333 |
<a href="<?php echo esc_url( $term->term_link ); ?>" class="sps-taxonomy-terms-link"> |
| 334 |
<span class="sps-taxonomy-title-name <?php echo esc_attr( $title_global_typography_class ); ?>"><?php echo esc_html( $term->name ?? '' ); ?></span> |
| 335 |
</a> |
| 336 |
</div> |
| 337 |
|
| 338 |
<?php endif; ?> |
| 339 |
|
| 340 |
<?php if ( $should_show_count_in_name ) : ?> |
| 341 |
<div class="sp-smart-post-taxonomy-count" style="<?php echo esc_attr( $counter_style_attr ); ?>"> |
| 342 |
<span class="<?php echo esc_attr( $counter_global_typography_class ); ?>"> |
| 343 |
<?php echo esc_html( $should_show_before_after_count ? $before_count : '' ); ?> |
| 344 |
<?php echo esc_html( $term->count ?? '' ); ?> |
| 345 |
<?php echo esc_html( 'taxonomy-layout-eight' === $layout ? $after_count : '' ); ?> |
| 346 |
</span> |
| 347 |
</div> |
| 348 |
<?php endif; ?> |
| 349 |
|
| 350 |
|
| 351 |
<?php if ( ! empty( $term->description ) && $should_show_excerpt ) : ?> |
| 352 |
<p class="taxonomy-excerpt <?php echo esc_attr( $excerpt_global_typography_class ); ?>"> |
| 353 |
<?php echo esc_html( Helper::sp_string_trim( $term->description ?? '', $excerpt_length ) ); ?> |
| 354 |
</p> |
| 355 |
<?php endif; ?> |
| 356 |
</div> |
| 357 |
|
| 358 |
<?php if ( $count_enable && ! $should_show_count_in_name ) : ?> |
| 359 |
|
| 360 |
<div class="sp-smart-post-taxonomy-count" |
| 361 |
style=" |
| 362 |
<?php |
| 363 |
echo esc_attr( |
| 364 |
$counter_multi_color_bg && ! empty( $term->category_color ) |
| 365 |
? 'background:' . esc_attr( $term->category_color ) . ';' |
| 366 |
: '' |
| 367 |
); |
| 368 |
?> |
| 369 |
"> |
| 370 |
|
| 371 |
<span class="<?php echo esc_attr( $counter_global_typography_class ); ?>"> |
| 372 |
<?php |
| 373 |
if ( $should_show_before_after_count ) { |
| 374 |
echo esc_html( $before_count ); |
| 375 |
} |
| 376 |
echo esc_html( $term->count ); |
| 377 |
if ( $should_show_before_after_count ) { |
| 378 |
echo esc_html( $after_count ); |
| 379 |
} |
| 380 |
echo ' '; |
| 381 |
if ( 'taxonomy-layout-three' === $layout ) { |
| 382 |
$post_label = ( $term->count <= 1 ) ? 'Post' : 'Posts'; |
| 383 |
echo '<span class="taxonomy-hide-post-text">' . esc_html( $post_label ) . '</span>'; |
| 384 |
} |
| 385 |
?> |
| 386 |
</span> |
| 387 |
</div> |
| 388 |
|
| 389 |
<?php endif; ?> |
| 390 |
</div> |
| 391 |
<?php |
| 392 |
|
| 393 |
return ob_get_clean(); |
| 394 |
} |
| 395 |
|
| 396 |
/** |
| 397 |
* Renders the five six layout. |
| 398 |
* |
| 399 |
* @param object $term item data. |
| 400 |
* @param array $args of the attributes. |
| 401 |
* @return string Rendered HTML |
| 402 |
*/ |
| 403 |
private function render_five_six_layout( $term, $args = array() ) { |
| 404 |
|
| 405 |
$title_enable = $args['title_enable'] ?? false; |
| 406 |
$after_count = $args['after_count'] ?? 0; |
| 407 |
$before_count = $args['before_count'] ?? 0; |
| 408 |
$count_enable = $args['count_enable'] ?? false; |
| 409 |
$show_excerpt = $args['show_excerpt'] ?? false; |
| 410 |
$excerpt_length = $args['excerpt_length'] ?? 0; |
| 411 |
$layout = $args['layout'] ?? ''; |
| 412 |
$image_overlay = $args['image_overlay'] ?? ''; |
| 413 |
$hover_effect = $args['hover_effect'] ?? ''; |
| 414 |
$image_enable = $args['image_enable'] ?? false; |
| 415 |
$title_global_typography_class = $args['title_global_typography_class'] ?? ''; |
| 416 |
$excerpt_global_typography_class = $args['excerpt_global_typography_class'] ?? ''; |
| 417 |
$counter_global_typography_class = $args['counter_global_typography_class'] ?? ''; |
| 418 |
|
| 419 |
$placeholder_img = SP_PC_URL . 'public/assets/img/placeholder.png'; |
| 420 |
$placeholder_img = apply_filters( 'pcp_no_thumb_placeholder', $placeholder_img ); |
| 421 |
$thumbnail_url = $term->category_thumbnail; |
| 422 |
if ( empty( $thumbnail_url ) ) { |
| 423 |
$thumbnail_url = $placeholder_img; |
| 424 |
} |
| 425 |
|
| 426 |
$should_show_excerpt = $show_excerpt && in_array( |
| 427 |
$layout, |
| 428 |
array( |
| 429 |
'taxonomy-layout-one', |
| 430 |
'taxonomy-layout-two', |
| 431 |
'taxonomy-layout-three', |
| 432 |
'taxonomy-layout-five', |
| 433 |
'taxonomy-layout-six', |
| 434 |
), |
| 435 |
true |
| 436 |
); |
| 437 |
|
| 438 |
ob_start(); |
| 439 |
?> |
| 440 |
|
| 441 |
<div class="sp-smart-post-taxonomy-info taxonomy-layout-five-six sp-smart-post-card"> |
| 442 |
|
| 443 |
<div |
| 444 |
class="taxonomy-layout-five-six-img-div sp-smart-post-card-image img-<?php echo esc_attr( $hover_effect ); ?>" |
| 445 |
style=" |
| 446 |
--bg-url: url(<?php echo esc_url( $thumbnail_url ); ?>); |
| 447 |
--hover-bg-url: url(<?php echo esc_url( $thumbnail_url ); ?>); |
| 448 |
"> |
| 449 |
<?php if ( $image_enable ) : ?> |
| 450 |
<img |
| 451 |
class="taxonomy-layout-five-six-img" |
| 452 |
src="<?php echo esc_url( $thumbnail_url ); ?>" |
| 453 |
alt="<?php echo esc_attr( $thumbnail_url ); ?>" /> |
| 454 |
<?php if ( 'noOverlay' !== $image_overlay ) : ?> |
| 455 |
<div |
| 456 |
class="taxonomy-image-overlay overlay-<?php echo esc_attr( $image_overlay ); ?> pointer-none" |
| 457 |
style="background: <?php echo esc_attr( $this->overlay_random_solid_color( $image_overlay ) ); ?>;"></div> |
| 458 |
<?php endif; ?> |
| 459 |
<?php endif; ?> |
| 460 |
|
| 461 |
|
| 462 |
</div> |
| 463 |
|
| 464 |
<div class="sp-smart-post-taxonomy-name"> |
| 465 |
<div> |
| 466 |
|
| 467 |
<span class="sp-smart-post-taxonomy-icon"></span> |
| 468 |
|
| 469 |
<?php if ( $title_enable ) : ?> |
| 470 |
<a href="<?php echo esc_url( $term->term_link ); ?>" class="sps-taxonomy-terms-link"> |
| 471 |
<span class="sps-taxonomy-title-name <?php echo esc_attr( $title_global_typography_class ); ?>"><?php echo esc_html( $term->name ?? '' ); ?></span> |
| 472 |
</a> |
| 473 |
<?php endif; ?> |
| 474 |
|
| 475 |
<?php if ( $count_enable ) : ?> |
| 476 |
<span class="sp-smart-post-taxonomy-count"> |
| 477 |
<span class="<?php echo esc_attr( $counter_global_typography_class ); ?>"> |
| 478 |
<?php echo esc_html( $before_count ?? '' ); ?> |
| 479 |
<?php echo esc_html( $term->count ?? 0 ); ?> |
| 480 |
<?php echo esc_html( $after_count ?? '' ); ?> |
| 481 |
</span> |
| 482 |
</span> |
| 483 |
<?php endif; ?> |
| 484 |
</div> |
| 485 |
|
| 486 |
<?php if ( ! empty( $term->description ) && $should_show_excerpt ) : ?> |
| 487 |
<p class="taxonomy-excerpt <?php echo esc_attr( $excerpt_global_typography_class ); ?>"> |
| 488 |
<?php echo esc_html( Helper::sp_string_trim( $term->description ?? '', $excerpt_length ) ); ?> |
| 489 |
</p> |
| 490 |
<?php endif; ?> |
| 491 |
</div> |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
</div> |
| 496 |
|
| 497 |
<?php |
| 498 |
return ob_get_clean(); |
| 499 |
} |
| 500 |
|
| 501 |
/** |
| 502 |
* Renders the five six layout. |
| 503 |
* |
| 504 |
* @param string $layout Layout name. |
| 505 |
* @param bool $display_overly_thum Whether to show overlay thumbnail. |
| 506 |
* @param bool $display_overly_hover_thum Whether to show hover overlay thumbnail. |
| 507 |
* @param bool $show_hide_divider Whether hide or show. |
| 508 |
* |
| 509 |
* @return string HTML class names. |
| 510 |
*/ |
| 511 |
protected function get_taxonomy_class( $layout, $display_overly_thum, $display_overly_hover_thum, $show_hide_divider ) { |
| 512 |
$classes = array( |
| 513 |
'sp-smart-post-taxonomy-info', |
| 514 |
( 'taxonomy-layout-one' !== $layout ) ? 'sp-smart-post-taxonomy-info-overlay' : '', |
| 515 |
$display_overly_thum ? 'sp-taxonomy-overlay' : '', |
| 516 |
$display_overly_hover_thum ? 'sp-taxonomy-hover-overlay' : '', |
| 517 |
( 'taxonomy-layout-one' === $layout && $show_hide_divider ) ? 'sp-smart-post-taxonomy-info-layout-one' : '', |
| 518 |
); |
| 519 |
|
| 520 |
// Filter out empty values and join with spaces. |
| 521 |
return implode( ' ', array_filter( $classes ) ); |
| 522 |
} |
| 523 |
|
| 524 |
/** |
| 525 |
* Renders the five six layout. |
| 526 |
* |
| 527 |
* @param array $args item data. |
| 528 |
* @return object. |
| 529 |
*/ |
| 530 |
protected function get_style( $args ) { |
| 531 |
|
| 532 |
$term = $args['term']; |
| 533 |
$placeholder_img = $args['placeholder_img']; |
| 534 |
$display_overly_thum = $args['display_overly_thum']; |
| 535 |
$display_overly_hover_thum = $args['display_overly_hover_thum']; |
| 536 |
$post_card_bg = $args['post_card_bg']; |
| 537 |
$image_overlay_color = $args['image_overlay_color']; |
| 538 |
$image_overlay_hover_color = $args['image_overlay_hover_color']; |
| 539 |
$image_overlay_custom_color = $args['image_overlay_custom_color']; |
| 540 |
$image_overlay_custom_hover_color = $args['image_overlay_custom_hover_color']; |
| 541 |
$layout = $args['layout']; |
| 542 |
$get_overlay_colors = $this->get_overlay_colors( $image_overlay_color, $image_overlay_hover_color, $image_overlay_custom_color, $image_overlay_custom_hover_color, $layout ); |
| 543 |
$style = array(); |
| 544 |
|
| 545 |
// Make sure the thumbnail is a valid URL string. |
| 546 |
$thumbnail_url = ''; |
| 547 |
if ( ! empty( $term->category_thumbnail ) ) { |
| 548 |
if ( is_array( $term->category_thumbnail ) && isset( $term->category_thumbnail['url'] ) ) { |
| 549 |
$thumbnail_url = $term->category_thumbnail['url']; |
| 550 |
} elseif ( is_string( $term->category_thumbnail ) ) { |
| 551 |
$thumbnail_url = $term->category_thumbnail; |
| 552 |
} |
| 553 |
} |
| 554 |
if ( empty( $thumbnail_url ) ) { |
| 555 |
$thumbnail_url = $placeholder_img; |
| 556 |
} |
| 557 |
|
| 558 |
$style['--bg-url'] = $display_overly_thum |
| 559 |
? 'url(' . esc_url( $thumbnail_url ) . ')' |
| 560 |
: 'none'; |
| 561 |
|
| 562 |
$style['--hover-bg-url'] = $display_overly_hover_thum |
| 563 |
? 'url(' . esc_url( $thumbnail_url ) . ')' |
| 564 |
: $this->color_controls( |
| 565 |
$post_card_bg['hover']['style'] ?? '', |
| 566 |
$post_card_bg['hover']['solidColor'] ?? '', |
| 567 |
$post_card_bg['hover']['gradient'] ?? '' |
| 568 |
); |
| 569 |
|
| 570 |
$style['--overlay-color'] = $get_overlay_colors['overlayColor'] ?? ''; |
| 571 |
$style['--overlay-hover-color'] = $get_overlay_colors['overlayHoverColor'] ?? ''; |
| 572 |
|
| 573 |
return $style; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
/** |
| 578 |
* Renders the five six layout. |
| 579 |
* |
| 580 |
* @param object $color_type item data. |
| 581 |
* @param object $normal_color image url. |
| 582 |
* @param string $gradient_color of the method. |
| 583 |
* @param string $type of the method. |
| 584 |
* @return object. |
| 585 |
*/ |
| 586 |
protected function color_controls( $color_type, $normal_color, $gradient_color, $type = 'normal' ) { |
| 587 |
if ( 'normal' === $type ) { |
| 588 |
$color_type_object = array( |
| 589 |
'transparent' => 'transparent', |
| 590 |
'color' => $normal_color, |
| 591 |
'gradient' => $gradient_color, |
| 592 |
); |
| 593 |
return $color_type_object[ $color_type ] ?? $normal_color; |
| 594 |
} else { |
| 595 |
$hover_color_type_object = array( |
| 596 |
'transparentHover' => 'transparent', |
| 597 |
'colorHover' => $normal_color, |
| 598 |
'gradientHover' => $gradient_color, |
| 599 |
); |
| 600 |
return $hover_color_type_object[ $color_type ] ?? $normal_color; |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
/** |
| 606 |
* Renders the five six layout. |
| 607 |
* |
| 608 |
* @param object $hover_animation item data. |
| 609 |
* @param object $layout image url. |
| 610 |
* @return object. |
| 611 |
*/ |
| 612 |
protected function hover_animate( $hover_animation, $layout ) { |
| 613 |
$transform_value = ''; |
| 614 |
$initial_value = ''; |
| 615 |
|
| 616 |
switch ( $hover_animation ) { |
| 617 |
case 'zoomIn': |
| 618 |
$transform_value = 'scale(1.05)'; |
| 619 |
$initial_value = 'scale(1)'; |
| 620 |
break; |
| 621 |
case 'zoomOut': |
| 622 |
$transform_value = 'scale(1)'; |
| 623 |
$initial_value = 'scale(1.05)'; |
| 624 |
break; |
| 625 |
case 'slideLeft': |
| 626 |
$transform_value = 'scale(1.10) translateX(-10px)'; |
| 627 |
$initial_value = 'scale(1.10) translateX(3%)'; |
| 628 |
break; |
| 629 |
case 'slideRight': |
| 630 |
$transform_value = 'scale(1.10) translateX(10px)'; |
| 631 |
$initial_value = 'scale(1.10) translateX(-3%)'; |
| 632 |
break; |
| 633 |
default: |
| 634 |
$transform_value = 'scale(1)'; |
| 635 |
$initial_value = 'scale(1)'; |
| 636 |
} |
| 637 |
|
| 638 |
if ( 'taxonomy-layout-one' === $layout ) { |
| 639 |
return array(); |
| 640 |
} |
| 641 |
|
| 642 |
return array( |
| 643 |
'transformValue' => $transform_value, |
| 644 |
'initialValue' => $initial_value, |
| 645 |
); |
| 646 |
} |
| 647 |
|
| 648 |
/** |
| 649 |
* Renders the five six layout. |
| 650 |
* |
| 651 |
* @param string $image_overlay_color item data. |
| 652 |
* @param string $image_overlay_hover_color item data. |
| 653 |
* @param string $image_overlay_custom_color item data. |
| 654 |
* @param string $image_overlay_custom_hover_color item data. |
| 655 |
* @param string $layout item data. |
| 656 |
|
| 657 |
* @return object. |
| 658 |
*/ |
| 659 |
protected function get_overlay_colors( $image_overlay_color, $image_overlay_hover_color, $image_overlay_custom_color, $image_overlay_custom_hover_color, $layout ) { |
| 660 |
if ( 'taxonomy-layout-one' === $layout ) { |
| 661 |
return array(); |
| 662 |
} |
| 663 |
|
| 664 |
$gradient_map = array( |
| 665 |
'warm-sunset' => 'linear-gradient(2deg, rgba(244, 66, 70, 0.4) 33.02%, rgba(221, 36, 118, 0.4) 98.51%)', |
| 666 |
'ocean-breeze' => 'linear-gradient(1deg, rgba(43, 88, 118, 0.4) 0.5%, rgba(78, 67, 118, 0.4) 99.51%)', |
| 667 |
'royal-gold' => 'linear-gradient(1deg, rgba(255, 215, 0, 0.4) 0.5%, rgba(184, 134, 11, 0.4) 99.51%)', |
| 668 |
'cool-blues' => 'linear-gradient(1deg, rgba(30, 60, 114, 0.4) 0.5%, rgba(42, 82, 152, 0.4) 99.51%)', |
| 669 |
'soft-pastel' => 'linear-gradient(1deg, rgba(252, 227, 138, 0.4) 0.5%, rgba(243, 129, 129, 0.4) 99.51%)', |
| 670 |
'elegant-purple' => 'linear-gradient(180deg, rgba(65, 41, 90, 0.4) 0%, rgba(47, 7, 67, 0.4) 100%)', |
| 671 |
'energetic-orange' => 'linear-gradient(180deg, rgba(255, 81, 47, 0.4) 0%, rgba(240, 152, 25, 0.4) 100%)', |
| 672 |
); |
| 673 |
|
| 674 |
$random_color = $this->overlay_random_solid_color( $image_overlay_color ); |
| 675 |
$random_hover_color = $this->overlay_random_solid_color( $image_overlay_hover_color ); |
| 676 |
|
| 677 |
if ( in_array( $image_overlay_color, array( 'multi-gradient', 'multi-solid' ), true ) ) { |
| 678 |
$overlay_color = $random_color; |
| 679 |
} elseif ( 'custom' === $image_overlay_color ) { |
| 680 |
$overlay_color = $image_overlay_custom_color; |
| 681 |
} else { |
| 682 |
$overlay_color = $gradient_map[ $image_overlay_color ] ?? 'transparent'; |
| 683 |
} |
| 684 |
|
| 685 |
if ( in_array( $image_overlay_hover_color, array( 'multi-gradient', 'multi-solid' ), true ) ) { |
| 686 |
$overlay_hover_color = $random_hover_color; |
| 687 |
} elseif ( 'custom' === $image_overlay_hover_color ) { |
| 688 |
$overlay_hover_color = $image_overlay_custom_hover_color; |
| 689 |
} else { |
| 690 |
$overlay_hover_color = $gradient_map[ $image_overlay_hover_color ] ?? 'transparent'; |
| 691 |
} |
| 692 |
|
| 693 |
return array( |
| 694 |
'overlayColor' => $overlay_color, |
| 695 |
'overlayHoverColor' => $overlay_hover_color, |
| 696 |
); |
| 697 |
} |
| 698 |
|
| 699 |
/** |
| 700 |
* Renders the five six layout. |
| 701 |
* |
| 702 |
* @param object $color_type item data. |
| 703 |
* @return object. |
| 704 |
*/ |
| 705 |
protected function overlay_random_solid_color( $color_type = '' ) { |
| 706 |
if ( 'multi-solid' === $color_type ) { |
| 707 |
$r = wp_rand( 0, 255 ); |
| 708 |
$g = wp_rand( 0, 255 ); |
| 709 |
$b = wp_rand( 0, 255 ); |
| 710 |
return "rgba($r, $g, $b, 0.7)"; |
| 711 |
} |
| 712 |
|
| 713 |
if ( 'multi-gradient' === $color_type ) { |
| 714 |
$color_list = array( |
| 715 |
'linear-gradient(293deg, rgba(251, 218, 97, .7) -0.37%, rgba(255, 90, 205, .7) 100%)', |
| 716 |
'linear-gradient(90deg, rgba(203, 173, 109, .7) 0%, rgba(213, 51, 105, .7) 100%)', |
| 717 |
'linear-gradient(90deg, rgba(36, 198, 220, .7) 0%, rgba(81, 74, 157, .7) 100%)', |
| 718 |
'linear-gradient(90deg, rgba(255, 224, 0, .7) 0%, rgba(255, 75, 31, .7) 100%)', |
| 719 |
'linear-gradient(90deg, rgba(28, 216, 210, .7) 0%, rgba(147, 237, 199, .7) 100%)', |
| 720 |
'linear-gradient(90deg, rgba(255, 212, 82, .7) 0%, rgba(84, 74, 125, .7) 100%)', |
| 721 |
'linear-gradient(90deg, rgba(91, 134, 229, .7) 0%, rgba(54, 209, 220, .7) 100%)', |
| 722 |
'linear-gradient(90deg, rgba(253, 185, 155, .7) 0%, rgba(167, 112, 239, .7) 100%)', |
| 723 |
); |
| 724 |
return $color_list[ array_rand( $color_list ) ]; |
| 725 |
} |
| 726 |
|
| 727 |
return ''; |
| 728 |
} |
| 729 |
} |
| 730 |
|