PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.8
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.8
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-list-three / Post_List_Three.php

Post_List_Three.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.8, at blocks/includes/post-list-three/Post_List_Three.php

126 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post list 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 * Post List Three Block Class.
21 */
22 class Post_List_Three extends Block_Base {
23
24 /**
25 * Set block properties.
26 */
27 protected function set_block_properties() {
28 $this->block_name = 'post-list-three';
29 $this->scripts = array( 'sp_smart_post_blocks_script_js' );
30 $this->styles = array( 'sp_smart_post_blocks_css', 'sp_smart_post_blocks_social_icons_style', 'sp_smart_post_blocks_google_fonts' );
31 $this->editor_scripts = array( 'sp_smart_post_blocks_index_js' );
32 $this->editor_styles = array( 'sp_smart_post_blocks_editor_style' );
33 $this->keywords = array( 'Smart post', 'List', 'Live Filter', 'Pagination', 'Ajax Live Filter' );
34 }
35
36 /**
37 * Render block.
38 *
39 * @param array $attributes Block attributes.
40 * @param string $content Block content.
41 * @param array $blocks Nested blocks.
42 * @return string Rendered HTML.
43 */
44 public function render_block( $attributes, $content = '', $blocks = array() ) {
45 if ( Helper::is_editor_page() ) {
46 return $content;
47 }
48
49 $attributes['page_id'] = get_the_ID();
50
51 $unique_id = $attributes['uniqueId'] ?? '';
52 $sp_block_id = $attributes['spBlockId'] ?? ''; // Not changeable id.
53 $block_name = $attributes['blockName'] ?? '';
54 $layout = $attributes['postListLayout'] ?? '';
55 $align = $attributes['align'] ?? '';
56 $overlay_type = $attributes['imageOverlayColor'] ?? 'no-overlay';
57
58 $sp_user_additional_class = $attributes['additionalCssClass'] ?? '';
59 $attributes['layout'] = $layout;
60
61 // Remove unused attributes.
62 unset( $attributes['dynamicCss'], $attributes['fontListsEditPage'], $attributes['fontLists'] );
63
64 $preloader_enable = $attributes['preloaderEnable'] ?? false;
65 $preloader_svg = SP_PC_URL . 'public/assets/img/preloader.svg';
66 $post_not_found = ! empty( $attributes['noResultFoundResult'] ) ? $attributes['noResultFoundResult'] : 'No post found';
67
68 $query_attr = ! empty( $attributes['postQuery'] ) ? (array) json_decode( $attributes['postQuery'], true ) : $attributes;
69
70 $post_query = $this->get_cached_post_query_result( $query_attr, $unique_id, $sp_block_id );
71 $total_pages = $post_query[1];
72 $post_query = $post_query[0];
73
74 $image_overlay_class = in_array( $layout, array( 'sp-smart-post-list-three-layout-three', 'sp-smart-post-list-three-layout-four' ), true ) ? $overlay_type : '';
75 $align_class = $align ? 'align' . esc_attr( $align ) : '';
76 $query_attr_json = wp_json_encode( $query_attr );
77
78 $category_position = $attributes['catTabCategoryPosition'] ?? false;
79
80 $category_position = $category_position ? ' sp-cat-position-' . $category_position : '';
81 $block_location = $attributes['blockLocation'] ?? '';
82
83 $pagination_type = $attributes['paginationTypeParent'] ?? '';
84 $pagination_position = $attributes['paginationPosition'] ?? 'bottom';
85
86 $pagination_class = 'sp-smart-post-block-with-pagination pagination-' . ( 'navigation' === $pagination_type ? $pagination_position : 'bottom' );
87
88 ob_start();
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 . $category_position ); ?> <?php echo esc_attr( $sp_user_additional_class ); ?> <?php echo esc_attr( $pagination_class ); ?>" data-query='<?php echo esc_attr( $query_attr_json ); ?>' 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 ); ?>">
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 id="sp-smart-post-list-wrapper"
100 class="sp-smart-post-list-three <?php echo esc_attr( "$image_overlay_class $layout" ); ?>">
101 <div class="sp-smart-post-list-items sp-smart-post-items">
102 <?php Template::post_list_three( $attributes, $post_query ); ?>
103 </div>
104 </div>
105 <?php
106 if ( ! empty( $attributes['paginationEnable'] ) && $total_pages > 1 && ! empty( $blocks->inner_blocks ) ) {
107 $pagination_attributes = Template::pagination_attributes( $blocks );
108 // 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.
109 echo Template_Part::pagination_html( $pagination_attributes, $query_attr_json, $total_pages, $unique_id );
110 }
111 // Moved modal rendering to footer.
112 add_action(
113 'wp_footer',
114 function () use ( $attributes, $post_query ) {
115 Template_Part::modal_lightbox( $attributes, $post_query );
116 },
117 20
118 );
119 ?>
120 </div>
121 </div>
122 <?php
123 return ob_get_clean();
124 }
125 }
126