PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.7
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.7
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / blocks / includes / post-slider / Post_Slider.php

Post_Slider.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.7, at blocks/includes/post-slider/Post_Slider.php

144 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post slider block class for Smart Post Show Blocks.
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 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Class Post_Slider
21 *
22 * Handles the Post Slider block functionality for Smart Post Show Pro.
23 */
24 class Post_Slider extends Block_Base {
25 /**
26 * Set_block_properties
27 *
28 * @return void
29 */
30 protected function set_block_properties() {
31 $this->block_name = 'post-slider';
32 $this->scripts = array( 'sp_smart_post_blocks_script_js', 'pcp_swiper' );
33 $this->styles = array( 'sp_smart_post_blocks_css', 'sp_smart_post_blocks_social_icons_style', 'pcp_swiper', 'sp_smart_post_blocks_google_fonts' );
34 $this->editor_scripts = array( 'sp_smart_post_blocks_index_js' );
35 $this->editor_styles = array( 'sp_smart_post_blocks_editor_style' );
36 $this->keywords = array( 'Smart post', 'Slider', 'Live Filter', 'Pagination', ' Ajax Live Filter' );
37 }
38
39 /**
40 * Render block
41 *
42 * @param array $attributes attributes.
43 * @param mixed $content content.
44 * @param array $blocks blocks.
45 * @return string
46 */
47 public function render_block( $attributes, $content = '', $blocks = array() ) {
48 if ( Helper::is_editor_page() ) {
49 return $content;
50 }
51
52 $attributes['page_id'] = get_the_ID();
53 $sp_user_additional_class = $attributes['additionalCssClass'] ?? '';
54 $unique_id = $attributes['uniqueId'] ?? '';
55 $sp_block_id = $attributes['spBlockId'] ?? ''; // Not changeable id.
56 $align = $attributes['align'] ?? '';
57 $layout = $attributes['blockLayoutName'] ?? '';
58 $block_name = $attributes['blockName'] ?? '';
59 $orientation = $attributes['contentOrientation'] ?? 'orientation_one';
60 $image_position = $attributes['imagePosition'] ?? 'top';
61
62 $category_position = $attributes['catTabCategoryPosition'] ?? '';
63 $carousel_style = $attributes['carouselStyle'] ?? '';
64 $carousel_animation_effect = $attributes['carouselAnimationEffect'] ?? '';
65 $carousel_pagination_style = $attributes['carouselPaginationStyle'] ?? '';
66 $carousel_data = $attributes['carouselData'] ?? '';
67 $nav_arrow_visibility_hover = $attributes['navArrowVisibilityOnHover'] ?? '';
68 $preloader_enable = $attributes['postSliderGeneralPreloader'] ?? false;
69 $post_not_found = ! empty( $attributes['noResultFoundResult'] ) ? $attributes['noResultFoundResult'] : 'No post found';
70 $preloader_svg = SP_PC_URL . 'public/assets/img/preloader.svg';
71 $pagination_style = $attributes['carouselPaginationStyle'] ?? '';
72 $post_slider_layout = $attributes['postSliderLayout'] ?? '';
73 $post_slider_animation_effect = $attributes['postSliderAnimationEffect'] ?? '';
74 unset(
75 $attributes['dynamicCss'],
76 $attributes['fontListsEditPage'],
77 $attributes['fontLists']
78 );
79 $query_attr = ( ! empty( $attributes['postQuery'] ) && isset( $attributes['postQuery'] ) ) ? (array) json_decode( $attributes['postQuery'] ) : $attributes;
80
81 $post_query = $this->get_cached_post_query_result( $query_attr, $unique_id, $sp_block_id );
82 $post_query = $post_query[0];
83
84 $category_position = $attributes['catTabCategoryPosition'] ?? false;
85
86 $category_position = $category_position ? ' sp-cat-position-' . $category_position : '';
87
88 $hide_part = array( 'readMoreButton', 'taxonomy', 'excerpt' );
89 $align_class = isset( $align ) ? 'align' . $align : '';
90 $content_h_position = isset( $attributes['contentHorizontalPosition'] ) ? $attributes['contentHorizontalPosition'] : '';
91 $content_position = 'post-slider-layout-five' === $post_slider_layout ? 'content-' . $content_h_position : '';
92 $block_location = $attributes['blockLocation'] ?? '';
93 ob_start();
94 ?>
95 <div class="<?php echo esc_attr( $align_class ); ?>">
96 <div id="<?php echo esc_attr( $unique_id ); ?>" class="sp-smart-post-wrapper sp-smart-<?php echo esc_attr( $block_name . $category_position ); ?> <?php echo esc_attr( $sp_user_additional_class ); ?>" data-blockid="<?php echo esc_attr( $sp_block_id ); ?>" data-pageid="<?php echo esc_attr( $attributes['page_id'] ); ?>" data-location="<?php echo esc_attr( $block_location ); ?>">
97 <div class="sp-smart-post-show-pro-pre-query">
98 <?php
99 if ( empty( $post_query ) ) {
100 Template_Part::no_posts_found_text( $post_not_found );}
101 Template_Part::preloader_front( $preloader_enable, $preloader_svg );
102 ?>
103 </div>
104 <div class="sp-smart-post-block-wrapper sp-smart-post-slider sp-smart-md-10px <?php echo esc_attr( $post_slider_layout ); ?>">
105 <div class="swiper swiper-container sp-swiper-<?php echo esc_attr( $post_slider_animation_effect ); ?> sp-smart-post-swiper <?php echo esc_attr( $post_slider_layout ); ?> sp-smart-post-background-layout <?php echo esc_attr( $content_position ); ?>" data-swiper-options='<?php echo esc_attr( $carousel_data ); ?>'>
106 <div class="swiper-wrapper">
107 <?php
108 foreach ( $post_query as $data ) {
109 ?>
110 <div class="swiper-slide sp-slide-item">
111 <?php
112 Template::template_one( $attributes, $data );
113 ?>
114 </div>
115 <?php
116 }
117 ?>
118 </div>
119 </div>
120 <?php
121 $attributes['carouselNavArrow'] ? Template_part::swiper_nav_arrow( $nav_arrow_visibility_hover, $attributes['carouselArrowStyle'] ) : '';
122 ?>
123 <?php $attributes['carouselPaginationDot'] && 'scrollbar' !== $pagination_style ? Template_part::pagination( $pagination_style ) : ''; ?>
124 <?php if ( $attributes['carouselPaginationDot'] && 'scrollbar' === $pagination_style ) { ?>
125 <div class="swiper-scrollbar sp-pagination-horizontal swiper-scrollbar-horizontal"></div>
126 <?php } ?>
127 </div>
128 <?php
129 // Moved modal rendering to footer.
130 add_action(
131 'wp_footer',
132 function () use ( $attributes, $post_query ) {
133 Template_Part::modal_lightbox( $attributes, $post_query );
134 },
135 20
136 );
137 ?>
138 </div>
139 </div>
140 <?php
141 return ob_get_clean();
142 }
143 }
144