PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 5.0.3
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v5.0.3
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 3 years ago BlockBase.php 3 years ago GridHoverLayout.php 3 years ago GridLayout.php 3 years ago ListLayout.php 3 years ago
GridLayout.php
200 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 class GridLayout extends BlockBase {
11
12 private $prefix;
13 private $attribute_args;
14 private $block_type;
15
16 public function __construct() {
17 add_action( 'init', [ $this, 'register_blocks' ] );
18 $this->prefix = 'grid';
19 $this->block_type = 'rttpg/tpg-' . $this->prefix . '-layout';
20 $this->attribute_args = [
21 'prefix' => $this->prefix,
22 'default_layout' => 'grid-layout1'
23 ];
24
25 }
26
27 /**
28 * Register Block
29 * @return void
30 */
31 public function register_blocks() {
32 if ( ! function_exists( 'register_block_type' ) ) {
33 return;
34 }
35 register_block_type(
36 $this->block_type,
37 [
38 'attributes' => $this->get_attributes(),
39 'render_callback' => [ $this, 'render_block' ],
40 ]
41 );
42 }
43
44 /**
45 * Get attributes
46 *
47 * @param bool $default
48 *
49 * @return array
50 */
51 public function get_attributes() {
52
53 /**
54 * All Attribute
55 * Content Tab | Settings Tab | Style Tab
56 */
57 $content_attribute = ContentTabController::get_controller( $this->attribute_args );
58 $settings_attribute = SettingsTabController::get_controller();
59 $style_attribute = StyleTabController::get_controller();
60
61 return array_merge( $content_attribute, $settings_attribute, $style_attribute );
62 }
63
64 /**
65 * @param array $data
66 *
67 * @return false|string
68 */
69 public function render_block( $data ) {
70
71 $this->get_script_depends( $data );
72
73 $_prefix = $data['prefix'];
74
75 if ( ! rtTPG()->hasPro() && ! in_array( $data[ $_prefix . '_layout' ], [ 'grid-layout1', 'grid-layout4', 'grid-layout3' ] ) ) {
76 $data[ $_prefix . '_layout' ] = 'grid-layout1';
77 }
78
79 //Query
80 $query_args = $this->post_query_guten( $data, $_prefix );
81 $query = new \WP_Query( $query_args );
82 $rand = mt_rand();
83 $layoutID = "rt-tpg-container-" . $rand;
84 $posts_per_page = $data['display_per_page'] ? $data['display_per_page'] : $data['post_limit'];
85
86 /**
87 * TODO: Get Post Data for render post
88 */
89
90 $post_data = Fns::get_render_data_set( $data, $query->max_num_pages, $posts_per_page, $_prefix, 'yes' );
91
92 /**
93 * Post type render
94 */
95
96 //TODO: Taxonomy filter ================================================
97 /*
98 $post_types = Fns::get_post_types();
99 foreach ( $post_types as $post_type => $label ) {
100 $_taxonomies = get_object_taxonomies( $post_type, 'object' );
101 if ( empty( $_taxonomies ) ) {
102 continue;
103 }
104 $post_data[ $data['post_type'] . '_taxonomy' ] = $data[ $data['post_type'] . '_taxonomy' ];
105 $post_data[ $data['post_type'] . '_tags' ] = $data[ $data['post_type'] . '_tags' ];
106 }
107 */
108
109
110 $template_path = Fns::tpg_template_path( $post_data, 'gutenberg' );
111 $_layout = $data[ $_prefix . '_layout' ];
112 $_layout_style = $data['grid_layout_style'];
113 $dynamicClass = Fns::get_dynamic_class_gutenberg( $data );
114
115
116 ob_start();
117 ?>
118 <div class="<?php echo esc_attr( $dynamicClass ) ?>">
119 <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper clearfix <?php echo esc_attr( $_layout . '-main' ); ?>"
120 id="<?php echo esc_attr( $layoutID ); ?>"
121 data-layout="<?php echo esc_attr( $data[ $_prefix . '_layout' ] ); ?>"
122 data-grid-style="<?php echo esc_attr( $data['grid_layout_style'] ); ?>" data-sc-id="elementor"
123 data-el-settings='<?php echo Fns::is_filter_enable( $data ) ? htmlspecialchars( wp_json_encode( $post_data ) ) : ''; ?>'
124 data-el-query='<?php echo Fns::is_filter_enable( $data ) ? htmlspecialchars( wp_json_encode( $query_args ) ) : ''; ?>'
125 data-el-path='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( $template_path ) : ''; ?>'>
126 <?php
127
128 $settings = get_option( rtTPG()->options['settings'] );
129 if ( isset( $settings['tpg_load_script'] ) && isset( $settings['tpg_enable_preloader'] ) ) {
130 ?>
131 <div id="bottom-script-loader" class="bottom-script-loader">
132 <div class="rt-ball-clip-rotate">
133 <div></div>
134 </div>
135 </div>
136 <?php
137 }
138
139 $wrapper_class = [];
140 $wrapper_class[] = str_replace( '-2', '', $_layout );
141 $wrapper_class[] = 'grid-behaviour';
142 $wrapper_class[] = ( in_array( $_layout, [ 'grid-layout2' ] ) ) ? "tpg-even" : $_layout_style;
143 $wrapper_class[] = $_prefix . '_layout_wrapper';
144 if ( 'masonry' === $_layout_style && in_array( $_layout, [
145 'grid-layout1',
146 'grid-layout3',
147 'grid-layout4'
148 ] ) ) {
149 $wrapper_class[] = 'tpg-masonry';
150 }
151
152 if ( in_array( $_layout, [ 'grid-layout6', 'grid-layout6-2' ] ) && $data['middle_border'] === 'no' ) {
153 $wrapper_class[] = 'disable-middle-border';
154 }
155
156 //section title settings
157 $is_carousel = '';
158 if ( rtTPG()->hasPro() && 'carousel' == $data['filter_btn_style'] && 'button' == $data['filter_type'] ) {
159 $is_carousel = 'carousel';
160 }
161
162 echo "<div class='tpg-header-wrapper {$is_carousel}'>";
163 Fns::get_section_title( $data );
164 Fns::print_html( Fns::get_frontend_filter_markup( $data, true ) );
165 echo "</div>";
166 ?>
167
168 <div class="rt-row rt-content-loader gutenberg-inner <?php echo esc_attr( implode( ' ', $wrapper_class ) ) ?>">
169 <?php
170 if ( $query->have_posts() ) {
171 $pCount = 1;
172 while ( $query->have_posts() ) {
173 $query->the_post();
174 set_query_var( 'tpg_post_count', $pCount );
175 set_query_var( 'tpg_total_posts', $query->post_count );
176 Fns::tpg_template( $post_data, 'gutenberg' );
177 $pCount ++;
178 }
179 } else {
180 if ( $data['no_posts_found_text'] ) {
181 printf( "<div class='no_posts_found_text'>%s</div>", esc_html( $data['no_posts_found_text'] ) );
182 } else {
183 printf( "<div class='no_posts_found_text'>%s</div>", esc_html__( 'No post found', 'the-post-grid' ) );
184 }
185 }
186 wp_reset_postdata();
187 ?>
188 </div>
189
190 <?php echo Fns::get_pagination_markup( $query, $data ); ?>
191
192 </div>
193 </div>
194 <?php
195
196 do_action( 'tpg_elementor_script' );
197
198 return ob_get_clean();
199 }
200 }