PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.7.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.7.0
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Controllers / Blocks / GridLayout.php
the-post-grid / app / Controllers / Blocks Last commit date
BlockController 2 years ago BlockBase.php 2 years ago GridHoverLayout.php 2 years ago GridLayout.php 2 years ago ListLayout.php 2 years ago RttpgRow.php 2 years ago SectionTitle.php 2 years ago
GridLayout.php
201 lines
1 <?php
2
3 namespace RT\ThePostGrid\Controllers\Blocks;
4
5 use RT\ThePostGrid\Controllers\Blocks\BlockController\SettingsTabController;
6 use RT\ThePostGrid\Controllers\Blocks\BlockController\StyleTabController;
7 use RT\ThePostGrid\Controllers\Blocks\BlockController\ContentTabController;
8 use RT\ThePostGrid\Helpers\Fns;
9
10 /**
11 * GridLayout Class
12 */
13 class GridLayout extends BlockBase {
14
15 private $prefix;
16 private $attribute_args;
17 private $block_type;
18
19 public function __construct() {
20 add_action( 'init', [ $this, 'register_blocks' ] );
21 $this->prefix = 'grid';
22 $this->block_type = 'rttpg/tpg-' . $this->prefix . '-layout';
23 $this->attribute_args = [
24 'prefix' => $this->prefix,
25 'default_layout' => 'grid-layout1',
26 ];
27 }
28
29 /**
30 * Register Block
31 *
32 * @return void
33 */
34 public function register_blocks() {
35 if ( ! function_exists( 'register_block_type' ) ) {
36 return;
37 }
38 register_block_type(
39 $this->block_type,
40 [
41 'attributes' => $this->get_attributes(),
42 'render_callback' => [ $this, 'render_block' ],
43 ]
44 );
45 }
46
47 /**
48 * Get attributes
49 *
50 * @param bool $default
51 *
52 * @return array
53 */
54 public function get_attributes() {
55
56 /**
57 * All Attribute
58 * Content Tab | Settings Tab | Style Tab
59 */
60 $content_attribute = ContentTabController::get_controller( $this->attribute_args );
61 $settings_attribute = SettingsTabController::get_controller();
62 $style_attribute = StyleTabController::get_controller();
63
64 return array_merge( $content_attribute, $settings_attribute, $style_attribute );
65 }
66
67 /**
68 * @param array $data
69 *
70 * @return false|string
71 */
72 public function render_block( $data ) {
73
74 $this->get_script_depends( $data );
75
76 $_prefix = $data['prefix'];
77
78 if ( ! rtTPG()->hasPro() && ! in_array( $data[ $_prefix . '_layout' ], [ 'grid-layout1', 'grid-layout4', 'grid-layout3' ] ) ) {
79 $data[ $_prefix . '_layout' ] = 'grid-layout1';
80 }
81
82 // Query
83 $query_args = $this->post_query_guten( $data, $_prefix );
84 $query = new \WP_Query( $query_args );
85 $rand = wp_rand();
86 $layoutID = 'rt-tpg-container-' . $rand;
87 $posts_per_page = $data['display_per_page'] ?? $data['post_limit'];
88 /**
89 * Get Post Data for render post
90 */
91
92 $post_data = Fns::get_render_data_set( $data, $query->max_num_pages, $posts_per_page, $_prefix, 'yes' );
93
94 /**
95 * Post type render
96 */
97
98 // Category Source if exists
99 if ( isset( $data['category_source'] ) ) {
100 $post_data[ $data['post_type'] . '_taxonomy' ] = $data['category_source'];
101 }
102 // Tag source
103 if ( isset( $data['tag_source'] ) ) {
104 $post_data[ $data['post_type'] . '_tags' ] = $data['tag_source'];
105 }
106
107 $template_path = Fns::tpg_template_path( $post_data, 'gutenberg' );
108 $_layout = $data[ $_prefix . '_layout' ];
109 $_layout_style = $data['grid_layout_style'];
110 $dynamicClass = Fns::get_dynamic_class_gutenberg( $data );
111
112 ob_start();
113 ?>
114 <div class="<?php echo esc_attr( $dynamicClass ); ?>">
115 <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper clearfix <?php echo esc_attr( $_layout . '-main' ); ?>"
116 id="<?php echo esc_attr( $layoutID ); ?>"
117 data-layout="<?php echo esc_attr( $data[ $_prefix . '_layout' ] ); ?>"
118 data-grid-style="<?php echo esc_attr( $data['grid_layout_style'] ); ?>" data-sc-id="elementor"
119 data-el-settings='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( htmlspecialchars( wp_json_encode( $post_data ) ) ) : ''; ?>'
120 data-el-query='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( htmlspecialchars( wp_json_encode( $query_args ) ) ) : ''; ?>'
121 data-el-path='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( $template_path ) : ''; ?>'>
122 <?php
123
124 $settings = get_option( rtTPG()->options['settings'] );
125 if ( isset( $settings['tpg_load_script'] ) || isset( $settings['tpg_enable_preloader'] ) ) {
126 ?>
127 <div id="bottom-script-loader" class="bottom-script-loader">
128 <div class="rt-ball-clip-rotate">
129 <div></div>
130 </div>
131 </div>
132 <?php
133 }
134
135 $wrapper_class = [];
136 $wrapper_class[] = str_replace( '-2', '', $_layout );
137 $wrapper_class[] = 'grid-behaviour';
138 $wrapper_class[] = ( in_array( $_layout, [ 'grid-layout2' ] ) ) ? 'tpg-even' : $_layout_style;
139 $wrapper_class[] = $_prefix . '_layout_wrapper';
140 if ( 'masonry' === $_layout_style && in_array(
141 $_layout,
142 [
143 'grid-layout1',
144 'grid-layout3',
145 'grid-layout4',
146 ]
147 ) ) {
148 $wrapper_class[] = 'tpg-masonry';
149 }
150
151 if ( in_array( $_layout, [ 'grid-layout6', 'grid-layout6-2' ] ) && $data['middle_border'] === 'no' ) {
152 $wrapper_class[] = 'disable-middle-border';
153 }
154
155 // Section title settings.
156 $is_carousel = '';
157 if ( rtTPG()->hasPro() && 'carousel' == $data['filter_btn_style'] && 'button' == $data['filter_type'] ) {
158 $is_carousel = 'carousel';
159 }
160
161 ?>
162 <div class='tpg-header-wrapper <?php echo esc_attr( $is_carousel ); ?>'>
163 <?php
164 Fns::get_section_title( $data );
165 Fns::print_html( Fns::get_frontend_filter_markup( $data, true ) );
166 ?>
167 </div>
168
169 <div class="rt-row rt-content-loader gutenberg-inner <?php echo esc_attr( implode( ' ', $wrapper_class ) ); ?>">
170 <?php
171 if ( $query->have_posts() ) {
172 $pCount = 1;
173 while ( $query->have_posts() ) {
174 $query->the_post();
175 set_query_var( 'tpg_post_count', $pCount );
176 set_query_var( 'tpg_total_posts', $query->post_count );
177 Fns::tpg_template( $post_data, 'gutenberg' );
178 $pCount++;
179 }
180 } else {
181 if ( $data['no_posts_found_text'] ) {
182 printf( "<div class='no_posts_found_text'>%s</div>", esc_html( $data['no_posts_found_text'] ) );
183 } else {
184 printf( "<div class='no_posts_found_text'>%s</div>", esc_html__( 'No post found', 'the-post-grid' ) );
185 }
186 }
187 wp_reset_postdata();
188 ?>
189 </div>
190
191 <?php Fns::print_html( Fns::get_pagination_markup( $query, $data ) ); ?>
192
193 </div>
194 </div>
195 <?php
196
197 do_action( 'tpg_elementor_script' );
198
199 return ob_get_clean();
200 }
201 }