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