PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.8.8
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.8.8
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 8 months ago BlockBase.php 8 months ago GridHoverLayout.php 8 months ago GridLayout.php 8 months ago ListLayout.php 8 months ago RttpgRow.php 8 months ago SectionTitle.php 8 months ago
ListLayout.php
190 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 *
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 // Get - Content Tab | Settings Tab | Style Tab (Attributes)
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 * Render callback function
66 *
67 * @param array $att Block attributes
68 *
69 * @return string
70 */
71 public function render_block( $data ) {
72
73 $this->get_script_depends( $data );
74
75 $_prefix = $data['prefix'];
76
77 if ( ! rtTPG()->hasPro() && ! in_array( $data[ $_prefix . '_layout' ], [ 'list-layout1', 'list-layout2', 'list-layout2-2' ] ) ) {
78 $data[ $_prefix . '_layout' ] = 'list-layout1';
79 }
80
81 // Query
82 $query_args = $this->post_query_guten( $data, $_prefix );
83 if ( 'current_query' == $data['post_type'] && is_archive() ) {
84 global $wp_query;
85 $query = $wp_query;
86 } else {
87 $query = new \WP_Query( $query_args );
88 }
89
90 $rand = wp_rand();
91 $layoutID = 'rt-tpg-container-' . $rand;
92 $posts_per_page = $data['display_per_page'] ?? $data['post_limit'];
93
94 /**
95 * Get Post Data for render post
96 */
97
98 $post_data = Fns::get_render_data_set( $data, $query->max_num_pages, $posts_per_page, $_prefix, 'yes' );
99
100 // Category Source if exists
101 if ( isset( $data['category_source'] ) ) {
102 $post_data[ $data['post_type'] . '_taxonomy' ] = $data['category_source'];
103 }
104 // Tag source
105 if ( isset( $data['tag_source'] ) ) {
106 $post_data[ $data['post_type'] . '_tags' ] = $data['tag_source'];
107 }
108
109 $template_path = Fns::tpg_template_path( $post_data, 'gutenberg' );
110 $_layout = $data[ $_prefix . '_layout' ];
111 $_layout_style = $data['grid_layout_style'];
112 $dynamicClass = Fns::get_dynamic_class_gutenberg( $data );
113
114 ob_start();
115 ?>
116 <div class="<?php echo esc_attr( $dynamicClass ); ?>">
117 <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper tpg-gutenberg clearfix <?php echo esc_attr( $_layout . '-main' ); ?>"
118 id="<?php echo esc_attr( $layoutID ); ?>"
119 data-layout="<?php echo esc_attr( $data[ $_prefix . '_layout' ] ); ?>"
120 data-grid-style="<?php echo esc_attr( $data['grid_layout_style'] ); ?>" data-sc-id="elementor"
121 data-el-settings='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( htmlspecialchars( wp_json_encode( $post_data ) ) ) : ''; ?>'
122 data-el-query='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( htmlspecialchars( wp_json_encode( $query_args ) ) ) : ''; ?>'
123 data-el-path='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( $template_path ) : ''; ?>'>
124 <?php
125
126 $settings = get_option( rtTPG()->options['settings'] );
127 if ( isset( $settings['tpg_load_script'] ) || isset( $settings['tpg_enable_preloader'] ) ) {
128 ?>
129 <div id="bottom-script-loader" class="bottom-script-loader">
130 <div class="rt-ball-clip-rotate">
131 <div></div>
132 </div>
133 </div>
134 <?php
135 }
136
137 $wrapper_class = [];
138 $wrapper_class[] = str_replace( '-2', '', $_layout );
139 $wrapper_class[] = 'tpg-even list-behaviour';
140 $wrapper_class[] = $_prefix . '-layout-wrapper';
141
142 if ( 'masonry' === $_layout_style && ! in_array( $_layout, [ 'list-layout2', 'list-layout3' ] ) ) {
143 $wrapper_class[] = 'tpg-masonry';
144 }
145
146 // section title settings
147 $is_carousel = '';
148 if ( rtTPG()->hasPro() && 'carousel' == $data['filter_btn_style'] && 'button' == $data['filter_type'] ) {
149 $is_carousel = 'carousel';
150 }
151 ?>
152 <div class='tpg-header-wrapper <?php echo esc_attr( $is_carousel ); ?>'>
153 <?php
154 Fns::get_section_title( $data, true );
155 Fns::print_html( Fns::get_frontend_filter_markup( $data, 'guten' ) );
156 ?>
157 </div>
158 <div class="rt-row rt-content-loader gutenberg-inner <?php echo esc_attr( implode( ' ', $wrapper_class ) ); ?>">
159 <?php
160 if ( $query->have_posts() ) {
161 $pCount = 1;
162 while ( $query->have_posts() ) {
163 $query->the_post();
164 set_query_var( 'tpg_post_count', $pCount );
165 set_query_var( 'tpg_total_posts', $query->post_count );
166 Fns::tpg_template( $post_data, 'gutenberg' );
167 $pCount++;
168 }
169 } else {
170 if ( $data['no_posts_found_text'] ) {
171 printf( "<div class='no_posts_found_text'>%s</div>", esc_html( $data['no_posts_found_text'] ) );
172 } else {
173 printf( "<div class='no_posts_found_text'>%s</div>", esc_html__( 'No post found', 'the-post-grid' ) );
174 }
175 }
176 wp_reset_postdata();
177 ?>
178 </div>
179
180 <?php Fns::print_html( Fns::get_pagination_markup( $query, $data ) ); ?>
181
182 </div>
183 </div>
184 <?php
185
186 do_action( 'tpg_elementor_script' );
187
188 return ob_get_clean();
189 }
190 }