| 1 |
<?php |
| 2 |
|
| 3 |
namespace gutenify; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
class Slider { |
| 8 |
public static function init() { |
| 9 |
add_action( 'init', array( __CLASS__, 'register_block' ) ); |
| 10 |
// add_filter( 'gutenify_render_block_gutenify/slider', array( __CLASS__, 'render_block' ), 10, 3 ); |
| 11 |
} |
| 12 |
public static function register_block() { |
| 13 |
register_block_type( __DIR__ , array( |
| 14 |
'render_callback' => array( __CLASS__, 'render_callback' ) |
| 15 |
)); |
| 16 |
} |
| 17 |
|
| 18 |
public static function render_callback( $attr, $block_content ){ |
| 19 |
$constants = Helpers::plugin_constants(); |
| 20 |
$main_slug = $constants['plugin_main_slug']; |
| 21 |
|
| 22 |
$layout = ! empty( $attr['blockAdvanceOptions']['layout'] ) ? esc_attr( $attr['blockAdvanceOptions']['layout'] ) : 'layout-1'; |
| 23 |
|
| 24 |
$wrapper_attributes = get_block_wrapper_attributes( array( |
| 25 |
'class' => implode( ' ', array( |
| 26 |
$main_slug . '-section-' . $layout, |
| 27 |
'swiper', |
| 28 |
) ) |
| 29 |
) ); |
| 30 |
|
| 31 |
$has_navigation = ! empty( $attr['hasNavigation'] ) && true === $attr['hasNavigation']; |
| 32 |
$has_pagination = ! empty( $attr['hasPagination'] ) && true === $attr['hasPagination']; |
| 33 |
|
| 34 |
$new_content = sprintf( '<div %s>', $wrapper_attributes ); |
| 35 |
$new_content .= '<div class="swiper-wrapper">'; |
| 36 |
$new_content .= $block_content; |
| 37 |
$new_content .= '</div>'; |
| 38 |
if ( $has_navigation ) { |
| 39 |
$new_content .= '<div class="navigation-wrap"> |
| 40 |
<div class="swiper-button-prev"></div> |
| 41 |
<div class="swiper-button-next"></div> |
| 42 |
</div>'; |
| 43 |
} |
| 44 |
|
| 45 |
if ( $has_pagination ) { |
| 46 |
$new_content .= '<div class="swiper-pagination"></div>'; |
| 47 |
} |
| 48 |
$new_content .= '</div>'; |
| 49 |
return $new_content; |
| 50 |
} |
| 51 |
|
| 52 |
public static function render_callback1( $attributes, $content, $props ) { |
| 53 |
$constants = Helpers::plugin_constants(); |
| 54 |
|
| 55 |
$class_name = array(); |
| 56 |
// $class = array( 'swiper-container', 'gutenify-slider' ); |
| 57 |
// $styles = array(); |
| 58 |
// $block_style = ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'is-style-stacked' ) !== false ? 'stacked' : 'horizontal'; |
| 59 |
|
| 60 |
|
| 61 |
$layout = ! empty( $attributes['blockAdvanceOptions']['layout'] ) ? $attributes['blockAdvanceOptions']['layout'] : 'layout-1'; |
| 62 |
|
| 63 |
array_push( $class_name, 'gutenify-section-' . $layout, 'swiper' ); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
// if ( isset( $attributes['columns'] ) ) { |
| 69 |
// array_push( $class, 'has-columns has-' . $attributes['columns'] . '-columns has-responsive-columns' ); |
| 70 |
// } |
| 71 |
|
| 72 |
// if ( isset( $attributes['listPosition'] ) && 'right' === $attributes['listPosition'] && 'horizontal' === $block_style ) { |
| 73 |
// array_push( $class, 'has-image-right' ); |
| 74 |
// } |
| 75 |
|
| 76 |
// if ( isset( $attributes['imageSize'] ) && 'horizontal' === $block_style ) { |
| 77 |
// array_push( $class, 'has-' . $attributes['imageSize'] . '-image' ); |
| 78 |
// } |
| 79 |
|
| 80 |
// if ( isset( $attributes['imageStyle'] ) ) { |
| 81 |
// array_push( $class, 'has-' . $attributes['imageStyle'] . '-image' ); |
| 82 |
// } |
| 83 |
|
| 84 |
$class_name = apply_filters( 'gutenify--slider--wrapper-class', $class_name, $props ); |
| 85 |
|
| 86 |
$wrapper_attributes = get_block_wrapper_attributes( array( |
| 87 |
'class' => esc_attr( implode( ' ', $class_name ) ) |
| 88 |
) ); |
| 89 |
|
| 90 |
$block_content = sprintf( '<div %s> <div class="swiper-wrapper">', $wrapper_attributes ); |
| 91 |
|
| 92 |
$list_items_markup = ''; |
| 93 |
|
| 94 |
$list_items_markup = $content; |
| 95 |
|
| 96 |
$block_content .= $list_items_markup; |
| 97 |
$block_content .= '</div>'; |
| 98 |
$has_navigation = ! empty( $attributes['hasNavigation'] ) && true === $attributes['hasNavigation']; |
| 99 |
$has_pagination = ! empty( $attributes['hasPagination'] ) && true === $attributes['hasPagination']; |
| 100 |
if ( $has_navigation ) { |
| 101 |
$block_content .= '<div class="swiper-button-next"></div> |
| 102 |
<div class="swiper-button-prev"></div>'; |
| 103 |
} |
| 104 |
if ( $has_pagination ) { |
| 105 |
$block_content .= '<div class="swiper-pagination"></div>'; |
| 106 |
} |
| 107 |
$block_content .= '</div>'; |
| 108 |
$block_content .= '</div>'; |
| 109 |
|
| 110 |
|
| 111 |
return $block_content; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
Slider::init(); |
| 116 |
|
| 117 |
|