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 / ListLayout.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
ListLayout.php
185 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
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 /**
90 * Get Post Data for render post
91 */
92
93 $post_data = Fns::get_render_data_set( $data, $query->max_num_pages, $posts_per_page, $_prefix, 'yes' );
94
95 // Category Source if exists
96 if ( isset( $data['category_source'] ) ) {
97 $post_data[ $data['post_type'] . '_taxonomy' ] = $data['category_source'];
98 }
99 // Tag source
100 if ( isset( $data['tag_source'] ) ) {
101 $post_data[ $data['post_type'] . '_tags' ] = $data['tag_source'];
102 }
103
104 $template_path = Fns::tpg_template_path( $post_data, 'gutenberg' );
105 $_layout = $data[ $_prefix . '_layout' ];
106 $_layout_style = $data['grid_layout_style'];
107 $dynamicClass = Fns::get_dynamic_class_gutenberg( $data );
108
109 ob_start();
110 ?>
111 <div class="<?php echo esc_attr( $dynamicClass ); ?>">
112 <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper clearfix <?php echo esc_attr( $_layout . '-main' ); ?>"
113 id="<?php echo esc_attr( $layoutID ); ?>"
114 data-layout="<?php echo esc_attr( $data[ $_prefix . '_layout' ] ); ?>"
115 data-grid-style="<?php echo esc_attr( $data['grid_layout_style'] ); ?>" data-sc-id="elementor"
116 data-el-settings='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( htmlspecialchars( wp_json_encode( $post_data ) ) ) : ''; ?>'
117 data-el-query='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( htmlspecialchars( wp_json_encode( $query_args ) ) ) : ''; ?>'
118 data-el-path='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( $template_path ) : ''; ?>'>
119 <?php
120
121 $settings = get_option( rtTPG()->options['settings'] );
122 if ( isset( $settings['tpg_load_script'] ) || isset( $settings['tpg_enable_preloader'] ) ) {
123 ?>
124 <div id="bottom-script-loader" class="bottom-script-loader">
125 <div class="rt-ball-clip-rotate">
126 <div></div>
127 </div>
128 </div>
129 <?php
130 }
131
132 $wrapper_class = [];
133 $wrapper_class[] = str_replace( '-2', '', $_layout );
134 $wrapper_class[] = 'tpg-even list-behaviour';
135 $wrapper_class[] = $_prefix . '-layout-wrapper';
136
137 if ( 'masonry' === $_layout_style && ! in_array( $_layout, [ 'list-layout2', 'list-layout3' ] ) ) {
138 $wrapper_class[] = 'tpg-masonry';
139 }
140
141 // section title settings
142 $is_carousel = '';
143 if ( rtTPG()->hasPro() && 'carousel' == $data['filter_btn_style'] && 'button' == $data['filter_type'] ) {
144 $is_carousel = 'carousel';
145 }
146 ?>
147 <div class='tpg-header-wrapper <?php echo esc_attr( $is_carousel ); ?>'>
148 <?php
149 Fns::get_section_title( $data );
150 Fns::print_html( Fns::get_frontend_filter_markup( $data, true ) );
151 ?>
152 </div>
153 <div class="rt-row rt-content-loader gutenberg-inner <?php echo esc_attr( implode( ' ', $wrapper_class ) ); ?>">
154 <?php
155 if ( $query->have_posts() ) {
156 $pCount = 1;
157 while ( $query->have_posts() ) {
158 $query->the_post();
159 set_query_var( 'tpg_post_count', $pCount );
160 set_query_var( 'tpg_total_posts', $query->post_count );
161 Fns::tpg_template( $post_data, 'gutenberg' );
162 $pCount++;
163 }
164 } else {
165 if ( $data['no_posts_found_text'] ) {
166 printf( "<div class='no_posts_found_text'>%s</div>", esc_html( $data['no_posts_found_text'] ) );
167 } else {
168 printf( "<div class='no_posts_found_text'>%s</div>", esc_html__( 'No post found', 'the-post-grid' ) );
169 }
170 }
171 wp_reset_postdata();
172 ?>
173 </div>
174
175 <?php Fns::print_html( Fns::get_pagination_markup( $query, $data ) ); ?>
176
177 </div>
178 </div>
179 <?php
180
181 do_action( 'tpg_elementor_script' );
182
183 return ob_get_clean();
184 }
185 }