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