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 / thumbnail-slider / Thumbnail_Slider.php

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

159 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Thumbnail slider 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 * Container
21 */
22 class Thumbnail_Slider extends Block_Base {
23 /**
24 * Set_block_properties
25 *
26 * @return void
27 */
28 protected function set_block_properties() {
29 $this->block_name = 'thumbnail-slider';
30 $this->scripts = array( 'pcp_swiper', 'sp_smart_post_blocks_script_js' );
31 $this->styles = array( 'pcp_swiper', 'sp_smart_post_blocks_css', 'sp_smart_post_blocks_social_icons_style', 'sp_smart_post_blocks_google_fonts' );
32 $this->editor_scripts = array( 'sp_smart_post_blocks_index_js' );
33 $this->editor_styles = array( 'sp_smart_post_blocks_editor_style' );
34 $this->keywords = array( 'Smart post', 'Slider', 'Thumbnails Slider' );
35 }
36
37 /**
38 * Render Thumbnail Slider block.
39 *
40 * @param array $attributes Block attributes.
41 * @param string $content Block content.
42 * @param array $blocks Inner blocks.
43 * @return $content.
44 */
45 public function render_block( $attributes, $content = '', $blocks = array() ) {
46 if ( Helper::is_editor_page() ) {
47 return $content;
48 }
49
50 // Setup and sanitize attributes.
51 $attributes['page_id'] = get_the_ID();
52 $unique_id = $attributes['uniqueId'] ?? '';
53 $sp_block_id = $attributes['spBlockId'] ?? ''; // Not changeable id.
54 $block_name = $attributes['blockName'] ?? '';
55 $align = $attributes['align'] ?? '';
56 $additional_class = $attributes['additionalCssClass'] ?? '';
57 $animation_effect = $attributes['postThumbnailAnimationEffect'] ?? '';
58 $layout = $attributes['thumbnailSliderLayout'] ?? '';
59 $carousel_data = $attributes['carouselData'] ?? '';
60 $thumbnails_data = $attributes['thumbnailsData'] ?? '';
61 $arrow_on_hover = $attributes['navArrowVisibilityOnHover'] ?? '';
62 $arrow_style = $attributes['carouselArrowStyle'] ?? '';
63 $pagination_style = $attributes['carouselPaginationStyle'] ?? '';
64 $show_pagination = $attributes['carouselPaginationDot'] ?? false;
65 $post_thumbnail_pos = $attributes['postThumbnailPosition'] ?? '';
66 $category_position = $attributes['catTabCategoryPosition'] ?? '';
67 $preloader_enable = $attributes['preloaderEnable'] ?? false;
68 $post_not_found = ! empty( $attributes['noResultFoundResult'] ) ? $attributes['noResultFoundResult'] : 'No post found';
69 $preloader_svg = SP_PC_URL . 'public/assets/img/preloader.svg';
70
71 // Clean up unnecessary attributes.
72 unset( $attributes['dynamicCss'], $attributes['fontListsEditPage'], $attributes['fontLists'] );
73
74 // Fetch posts.
75 $query_attr = ( ! empty( $attributes['postQuery'] ) && isset( $attributes['postQuery'] ) ) ? (array) json_decode( $attributes['postQuery'] ) : $attributes;
76
77 $post_query = $this->get_cached_post_query_result( $query_attr, $unique_id, $sp_block_id );
78 $post_query = $post_query[0];
79
80 // Layout class condition.
81 $background_layout_class = ! in_array( $layout, array( 'thumbnail-slider-layout-three', 'thumbnail-slider-layout-four' ), true )
82 ? 'sp-smart-post-background-layout'
83 : '';
84 $align_class = isset( $align ) ? 'align' . $align : '';
85
86 // Start output buffering.
87 ob_start();
88 ?>
89
90 <div class="<?php echo esc_attr( $align_class ); ?>">
91 <div id="<?php echo esc_attr( $unique_id ); ?>" class="sp-smart-post-wrapper sp-smart-<?php echo esc_attr( $block_name ); ?> <?php echo esc_attr( $additional_class ); ?>" data-blockid="<?php echo esc_attr( $sp_block_id ); ?>" data-pageid="<?php echo esc_attr( $attributes['page_id'] ); ?>">
92 <div class="sp-smart-post-show-pro-pre-query">
93 <?php
94 if ( empty( $post_query ) ) {
95 Template_Part::no_posts_found_text( $post_not_found );}
96 Template_Part::preloader_front( $preloader_enable, $preloader_svg );
97 ?>
98 </div>
99 <div class="sp-smart-post-block-wrapper sp-smart-post-thumbnail-slider sp-smart-post-slider sp-smart-md-10px sp-thumbnail-<?php echo esc_attr( $post_thumbnail_pos ); ?> <?php echo esc_attr( $layout ); ?>">
100
101 <!-- Main Slide -->
102 <div class="sp-smart-post-thumbnail-slide sp-cat-position-<?php echo esc_attr( $category_position ); ?>">
103 <div class="swiper swiper-container thumbnail-slider-layout-one sp-swiper-<?php echo esc_attr( $animation_effect ); ?> sp-smart-post-swiper sp-smart-post-background-layout <?php echo esc_attr( $layout ); ?>" data-swiper-options='<?php echo esc_attr( $carousel_data ); ?>'>
104 <div class="swiper-wrapper">
105 <?php foreach ( $post_query as $data ) : ?>
106 <div class="swiper-slide sp-slide-item">
107 <?php Template::template_one( $attributes, $data ); ?>
108 </div>
109 <?php endforeach; ?>
110 </div>
111 <?php
112 if ( ! empty( $attributes['carouselNavArrow'] ) ) {
113 Template_part::swiper_nav_arrow( $arrow_on_hover, $arrow_style );
114 }
115 ?>
116 </div>
117
118 </div>
119
120 <!-- Thumbnail Navigation -->
121 <div class="sp-smart-post-thumbnail-thumb">
122 <div class="sp-smart-post-swiper2 swiper swiper-container <?php echo esc_attr( $background_layout_class ); ?>" data-swiper-options='<?php echo esc_attr( $thumbnails_data ); ?>'>
123 <div class="swiper-wrapper">
124 <?php foreach ( $post_query as $data ) : ?>
125 <div class="swiper-slide sp-slide-item-thumb">
126 <?php
127 Template::thumb_template( $attributes, $data );
128 ?>
129 </div>
130 <?php endforeach; ?>
131 </div>
132 </div>
133 </div>
134
135 <!-- Pagination -->
136 <?php
137 if ( $show_pagination && 'scrollbar' !== $pagination_style ) {
138 Template_part::pagination( $pagination_style );
139 }
140 ?>
141 </div>
142 <?php
143 // Moved modal rendering to footer.
144 add_action(
145 'wp_footer',
146 function () use ( $attributes, $post_query ) {
147 Template_Part::modal_lightbox( $attributes, $post_query );
148 },
149 20
150 );
151 ?>
152 </div>
153 </div>
154 <?php
155
156 return ob_get_clean();
157 }
158 }
159