| 1 |
<?php |
| 2 |
|
| 3 |
namespace gutenify; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
|
| 8 |
class Gallery_Carousel { |
| 9 |
public static function init() { |
| 10 |
add_action( 'init', array( __CLASS__, 'register_block' ) ); |
| 11 |
// add_filter( 'gutenify_render_block_gutenify/gallery-carousel', array( __CLASS__, 'gutenify_render_gallery_carousel' ), 10, 3 ); |
| 12 |
} |
| 13 |
|
| 14 |
public static function register_block() { |
| 15 |
register_block_type( __DIR__ , array( |
| 16 |
'render_callback' => array( __CLASS__, 'render_callback' ) |
| 17 |
)); |
| 18 |
} |
| 19 |
|
| 20 |
public static function render_callback ( $attributes, $context, $props ) { |
| 21 |
$constants = Helpers::plugin_constants(); |
| 22 |
$plugin_main_slug = $constants['plugin_main_slug']; |
| 23 |
|
| 24 |
$wrapper_attributes = get_block_wrapper_attributes( array( |
| 25 |
'class' => esc_attr( implode( ' ', array( 'gutenify--gallery-carousel--' . $attributes['layout'], 'swiper' ) ) ) |
| 26 |
) ); |
| 27 |
|
| 28 |
$block_content = sprintf( |
| 29 |
'<div %s><div class="swiper-wrapper">', |
| 30 |
$wrapper_attributes, |
| 31 |
); |
| 32 |
|
| 33 |
$list_items_markup = ''; |
| 34 |
|
| 35 |
if ( ! empty( $attributes['images'] ) ) { |
| 36 |
foreach ( $attributes['images'] as $image ) { |
| 37 |
$title = ! empty( $image['id'] ) && ! empty( $attributes['imagesData'][ $image['id'] ]['title'] ) ? $attributes['imagesData'][ $image['id'] ]['title'] : ''; |
| 38 |
$sub_title = ! empty( $image['id'] ) && ! empty( $attributes['imagesData'][ $image['id'] ]['subTitle'] ) ? $attributes['imagesData'][ $image['id'] ]['subTitle'] : ''; |
| 39 |
$description = ! empty( $image['id'] ) && ! empty( $attributes['imagesData'][ $image['id'] ]['description'] ) ? $attributes['imagesData'][ $image['id'] ]['description'] : ''; |
| 40 |
$button_text = ! empty( $image['id'] ) && ! empty( $attributes['imagesData'][ $image['id'] ]['buttonText'] ) ? $attributes['imagesData'][ $image['id'] ]['buttonText'] : ''; |
| 41 |
|
| 42 |
$list_items_markup .= '<div class="gutenify-gallery-carousel-item swiper-slide">'; |
| 43 |
if ( ! empty( $image['url'] ) ) { |
| 44 |
$list_items_markup .= ' |
| 45 |
<div class="gutenify-slider-image-wrapper"> |
| 46 |
<div class="gutenify-slider-content-image featured-image"> |
| 47 |
<img src="' . ( $image['url'] ) . '" /> |
| 48 |
</div> |
| 49 |
</div>'; |
| 50 |
} |
| 51 |
$list_items_markup .=' |
| 52 |
<div class="gutenify-slider-content-wrapper"> |
| 53 |
<div class="gutenify-slider-content-inner">'; |
| 54 |
if ( ! empty( $title ) ) { |
| 55 |
$list_items_markup .= '<h2 class="gutenify-slider-title">' . esc_html( $title ) . '</h2>'; |
| 56 |
} |
| 57 |
if ( ! empty( $sub_title ) ) { |
| 58 |
$list_items_markup .= '<h2 class="gutenify-slider-sub-title">' . esc_html( $sub_title ) . '</h2>'; |
| 59 |
} |
| 60 |
|
| 61 |
$list_items_markup .= '<div class="gutenify-slider-content-inner-wrapper">'; |
| 62 |
if ( ! empty( $description ) ) { |
| 63 |
$list_items_markup .= '<div class="gutenify-slider-content clear-fix"> |
| 64 |
<p>' . $description . '</p> |
| 65 |
</div>'; |
| 66 |
} |
| 67 |
// if ( ! empty( $button_text ) ) { |
| 68 |
// $list_items_markup .= '<p class="gutenify-slider-buttons clear-fix gutenify-button-link wp-block-button__link"> |
| 69 |
// ' . $button_text . ' |
| 70 |
// </p>'; |
| 71 |
// } |
| 72 |
$list_items_markup .= '</div>'; |
| 73 |
$list_items_markup .= '</div> |
| 74 |
</div></div>'; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
$block_content .= $list_items_markup; |
| 79 |
$block_content .= '</div>'; |
| 80 |
$has_navigation = ! empty( $attributes['hasNavigation'] ) && true === $attributes['hasNavigation']; |
| 81 |
$has_pagination = ! empty( $attributes['hasPagination'] ) && true === $attributes['hasPagination']; |
| 82 |
if ( $has_pagination ) { |
| 83 |
$block_content .= '<div class="swiper-pagination"></div>'; |
| 84 |
} |
| 85 |
if ( $has_navigation ) { |
| 86 |
$block_content .= '<div class="navigation-wrap"> |
| 87 |
<div class="swiper-button-prev"></div> |
| 88 |
<div class="swiper-button-next"></div> |
| 89 |
</div>'; |
| 90 |
} |
| 91 |
$block_content .= '</div>'; |
| 92 |
|
| 93 |
return $block_content; |
| 94 |
|
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
Gallery_Carousel::init(); |
| 99 |
|