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-grid-five / Post_Grid_Five.php

Post_Grid_Five.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.8, at blocks/includes/post-grid-five/Post_Grid_Five.php

133 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 grid 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 * Post Grid Five Block Class.
20 */
21 class Post_Grid_Five extends Block_Base {
22 /**
23 * Set_block_properties
24 *
25 * @return void
26 */
27 protected function set_block_properties() {
28 $this->block_name = 'post-grid-five';
29 $this->scripts = array( 'sp_smart_post_blocks_script_js' );
30 $this->styles = array(
31 'sp_smart_post_blocks_social_icons_style',
32 'sp_smart_post_blocks_css',
33 'pcp-likes',
34 'sp_smart_post_blocks_google_fonts',
35 );
36 $this->editor_scripts = array( 'sp_smart_post_blocks_index_js' );
37 $this->editor_styles = array( 'sp_smart_post_blocks_editor_style' );
38 $this->keywords = array( 'Smart post', 'Grid', 'Live Filter', 'Pagination', ' Ajax Live Filter' );
39 }
40 /**
41 * Render_block
42 *
43 * @param array $attributes attributes.
44 * @param string $content Content to be rendered.
45 * @param string $blocks Inner blocks.
46 * @return string Rendered HTML content.
47 */
48 public function render_block( $attributes, $content = '', $blocks = array() ) {
49 if ( Helper::is_editor_page() ) {
50 return $content;
51 }
52
53 $attributes['page_id'] = get_the_ID();
54 $sp_user_additional_class = $attributes['additionalCssClass'] ?? '';
55 $sp_block_unique_id = $attributes['uniqueId'] ?? '';
56 $sp_block_id = $attributes['spBlockId'] ?? ''; // Not changeable id.
57 $sp_block_name = $attributes['blockName'] ?? '';
58 $align = $attributes['align'] ?? '';
59
60 unset(
61 $attributes['dynamicCss'],
62 $attributes['fontListsEditPage'],
63 $attributes['fontLists']
64 );
65
66 $unique_id = $attributes['uniqueId'] ?? '';
67 $block_name = $attributes['blockName'] ?? '';
68 $layout = $attributes['postGridLayout'] ?? '';
69
70 $preloader_enable = $attributes['preloaderEnable'] ?? false;
71 $preloader_svg = SP_PC_URL . 'public/assets/img/preloader.svg';
72 $post_not_found = ! empty( $attributes['noResultFoundResult'] ) ? $attributes['noResultFoundResult'] : 'No post found';
73
74 $query_attr = ( ! empty( $attributes['postQuery'] ) && isset( $attributes['postQuery'] ) ) ? (array) json_decode( $attributes['postQuery'] ) : $attributes;
75
76 $category_position = $attributes['catTabCategoryPosition'] ?? false;
77
78 $category_position = $category_position ? ' sp-cat-position-' . $category_position : '';
79
80 $post_query = $this->get_cached_post_query_result( $query_attr, $unique_id, $sp_block_id );
81 $total_pages = $post_query[1];
82 $post_query = $post_query[0];
83 $align_class = isset( $align ) ? 'align' . $align : '';
84 $query_attr = wp_json_encode( $query_attr );
85 $block_location = $attributes['blockLocation'] ?? '';
86
87 $pagination_type = $attributes['paginationTypeParent'] ?? '';
88 $pagination_position = $attributes['paginationPosition'] ?? 'bottom';
89
90 $pagination_class = 'sp-smart-post-block-with-pagination pagination-' . ( 'navigation' === $pagination_type ? $pagination_position : 'bottom' );
91 ob_start();
92 ?>
93 <div class="<?php echo esc_attr( $align_class ); ?>">
94 <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 ); ?>' 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 ); ?>">
95 <div class="sp-smart-post-show-pro-pre-query">
96 <?php if ( empty( $post_query ) ) { ?>
97 <div class="sp-smart-post-no-post sp-d-hidden">
98 <h4><?php echo esc_html( $post_not_found ); ?></h4>
99 </div>
100 <?php } ?>
101 <?php if ( $preloader_enable ) { ?>
102 <div class="sp-smart-post-preloader sp-d-block">
103 <img src="<?php echo esc_url( $preloader_svg ); ?>" alt="smart post preloader" />
104 </div>
105 <?php } ?>
106 </div>
107 <div class="sp-smart-show-pro grid-five-container sp-smart-post-items">
108 <?php
109 Template::post_grid_five( $attributes, $post_query );
110 ?>
111 </div>
112 <?php
113 // Pagination.
114 if ( $attributes['paginationEnable'] && $total_pages > 1 && ! empty( $blocks->inner_blocks ) ) {
115 $pagination_attributes = Template::pagination_attributes( $blocks );
116 // 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.
117 echo Template_Part::pagination_html( $pagination_attributes, $query_attr, $total_pages, $unique_id );
118 }
119 add_action(
120 'wp_footer',
121 function () use ( $attributes, $post_query ) {
122 Template_Part::modal_lightbox( $attributes, $post_query );
123 },
124 20
125 );
126 ?>
127 </div>
128 </div>
129 <?php
130 return ob_get_clean();
131 }
132 }
133