PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / trunk
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid vtrunk
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 / Divi / Render / GridLayoutRenderer.php
the-post-grid / app / Divi / Render Last commit date
GridHoverLayoutRenderer.php 1 year ago GridLayoutRenderer.php 1 year ago ListLayoutRender.php 1 year ago
GridLayoutRenderer.php
176 lines
1 <?php
2
3 namespace RT\ThePostGrid\Divi\Render;
4
5 use WP_Query;
6 use RT\ThePostGrid\Helpers\Fns;
7 use RT\ThePostGrid\Helpers\DiviFns;
8
9 class GridLayoutRenderer {
10
11 protected $settings;
12 protected $prefix;
13 protected $query;
14 protected $query_args;
15 protected $layoutID;
16 protected $post_data;
17 protected $template_path;
18 protected $layout;
19 protected $layout_style;
20 protected $primary_color;
21 protected $secondary_color;
22 protected $dynamic_class;
23
24 public function __construct( array $settings, string $prefix ) {
25 $this->settings = $settings;
26 $this->prefix = $prefix;
27
28 $this->normalize_settings();
29 $this->setup_query();
30 $this->prepare_render_data();
31
32 DiviFns::get_script_depends( $settings, $prefix );
33 }
34
35 protected function normalize_settings() {
36 if ( ! rtTPG()->hasPro() && ! in_array( $this->settings[ $this->prefix . '_layout' ], [ 'grid-layout1', 'grid-layout4', 'grid-layout3' ] ) ) {
37 $this->settings[ $this->prefix . '_layout' ] = 'grid-layout1';
38 }
39
40 $this->layout = $this->settings[ $this->prefix . '_layout' ] ?? 'grid-layout1';
41 $this->layout_style = $this->settings['grid_layout_style'] ?? 'default';
42 $this->layoutID = 'rt-tpg-container-' . wp_rand();
43 $this->primary_color = ! empty( $this->settings['layout_primary_color'] ) ? $this->settings['layout_primary_color'] : '';
44 $this->secondary_color = ! empty( $this->settings['layout_secondary_color'] ) ? $this->settings['layout_secondary_color'] : '';
45 }
46
47 protected function setup_query() {
48 $this->query_args = DiviFns::get_post_query( $this->settings, $this->prefix );
49 $this->query = new WP_Query( $this->query_args );
50 }
51
52 protected function prepare_render_data() {
53 $posts_per_page = $this->settings['display_per_page'] ?? $this->settings['post_limit'];
54 $this->post_data = DiviFns::get_data_set( $this->settings, $this->query->max_num_pages, $posts_per_page, $this->prefix, 'divi' );
55
56 if ( isset( $this->settings['category_source'] ) ) {
57 $this->post_data[ $this->settings['post_type'] . '_taxonomy' ] = $this->settings['category_source'];
58 }
59 if ( isset( $this->settings['tag_source'] ) ) {
60 $this->post_data[ $this->settings['post_type'] . '_tags' ] = $this->settings['tag_source'];
61 }
62
63 $this->template_path = Fns::tpg_template_path( $this->post_data, 'divi' );
64 $this->dynamic_class = Fns::get_dynamic_class_gutenberg( $this->settings, 'divi' );
65 }
66
67 protected function get_wrapper_classes(): array {
68 $classes = [];
69 $layout = $this->layout;
70 $style = $this->layout_style;
71 $classes[] = str_replace( '-2', '', $layout );
72 $classes[] = 'grid-behaviour';
73 $classes[] = ( in_array( $layout, [ 'grid-layout2' ] ) ) ? 'tpg-even' : $style;
74 $classes[] = $this->prefix . '_layout_wrapper';
75
76 if ( 'masonry' === $style && in_array( $layout, [ 'grid-layout1', 'grid-layout3', 'grid-layout4' ] ) ) {
77 $classes[] = 'tpg-masonry';
78 }
79 if ( in_array( $layout, [ 'grid-layout6', 'grid-layout6-2' ] ) && ( $this->settings['middle_border'] ?? 'yes' ) === 'no' ) {
80 $classes[] = 'disable-middle-border';
81 }
82
83 return $classes;
84 }
85
86 protected function get_header_markup(): string {
87 ob_start();
88 $is_carousel = '';
89
90 if ( rtTPG()->hasPro() && 'carousel' === ( $this->settings['filter_btn_style'] ?? '' ) && 'button' === ( $this->settings['filter_type'] ?? '' ) ) {
91 $is_carousel = 'carousel';
92 }
93 ?>
94 <div class='tpg-header-wrapper <?php echo esc_attr( $is_carousel ); ?>'>
95 <?php
96 Fns::get_section_title( $this->settings, true );
97 Fns::print_html( Fns::get_frontend_filter_markup( $this->settings, 'divi' ) );
98 ?>
99 </div>
100 <?php
101 return ob_get_clean();
102 }
103
104 public function block_css() {
105 $css = '';
106 if ( ! empty( $this->primary_color ) ) {
107 $css .= "--tpg-primary-color: $this->primary_color;";
108 }
109 if ( ! empty( $this->secondary_color ) ) {
110 $css .= "--tpg-secondary-color: $this->secondary_color;";
111 }
112
113 return $css;
114 }
115
116 protected function get_posts_markup(): string {
117 ob_start();
118
119 if ( 'current_query' == $this->settings['post_type'] && ( is_archive() || is_home() ) ) {
120 global $wp_query;
121 $this->query = $wp_query;
122 }
123
124 if ( $this->query->have_posts() ) {
125 $pCount = 1;
126 while ( $this->query->have_posts() ) {
127 $this->query->the_post();
128 set_query_var( 'tpg_post_count', $pCount );
129 set_query_var( 'tpg_total_posts', $this->query->post_count );
130 Fns::tpg_template( $this->post_data, 'divi' );
131 $pCount ++;
132 }
133 } else {
134 printf(
135 "<div class='no_posts_found_text'>%s</div>",
136 esc_html( $this->settings['no_posts_found_text'] ?? __( 'No post found', 'the-post-grid' ) )
137 );
138 }
139 wp_reset_postdata();
140
141 return ob_get_clean();
142 }
143
144 public function render(): string {
145 ob_start();
146 ?>
147 <div class="<?php echo esc_attr( $this->dynamic_class ); ?>" style='<?php echo esc_attr( $this->block_css() ) ?>'>
148 <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper tpg-divi clearfix <?php echo esc_attr( $this->layout . '-main' ); ?>"
149 id="<?php echo esc_attr( $this->layoutID ); ?>"
150 data-layout="<?php echo esc_attr( $this->layout ); ?>"
151 data-grid-style="<?php echo esc_attr( $this->layout_style ); ?>"
152 data-sc-id="elementor"
153 data-el-settings='<?php echo Fns::is_filter_enable( $this->settings ) ? esc_attr( htmlspecialchars( wp_json_encode( $this->post_data ) ) ) : ''; ?>'
154 data-el-query='<?php echo Fns::is_filter_enable( $this->settings ) ? esc_attr( htmlspecialchars( wp_json_encode( $this->query_args ) ) ) : ''; ?>'
155 data-el-path='<?php echo Fns::is_filter_enable( $this->settings ) ? esc_attr( $this->template_path ) : ''; ?>'>
156
157 <?php
158 Fns::render_loader_spinner();
159 echo $this->get_header_markup();
160 ?>
161
162 <div class="rt-row rt-content-loader gutenberg-inner <?php echo esc_attr( implode( ' ', $this->get_wrapper_classes() ) ); ?>">
163 <?php echo $this->get_posts_markup(); ?>
164 </div>
165
166 <?php Fns::print_html( Fns::get_pagination_markup( $this->query, $this->settings ) ); ?>
167 </div>
168 </div>
169 <?php
170
171 do_action( 'tpg_divi_script' );
172
173 return ob_get_clean();
174 }
175
176 }