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 / ShortcodeController.php
the-post-grid / app / Controllers Last commit date
Admin 8 months ago Api 8 months ago Blocks 8 months ago Hooks 8 months ago AjaxController.php 8 months ago BlocksController.php 8 months ago DiviController.php 8 months ago ElementorController.php 8 months ago GutenBergController.php 8 months ago PageTemplateController.php 8 months ago ScriptController.php 8 months ago ShortcodeController.php 8 months ago WidgetController.php 8 months ago
ShortcodeController.php
1370 lines
1 <?php
2 /**
3 * Shortcode Controller class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers;
9
10 use RT\ThePostGrid\Helpers\Fns;
11 use RT\ThePostGrid\Helpers\Options;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Shortcode Controller class.
20 */
21 class ShortcodeController {
22
23 private $scA = [];
24 private $l4toggle = false;
25
26 public function __construct() {
27 add_shortcode( 'the-post-grid', [ $this, 'the_post_grid_short_code' ] );
28 add_action( 'pre_get_posts', [ $this, 'make_sticky_work' ] );
29 }
30
31 public function make_sticky_work( $q ) {
32 if ( true === $q->get( 'wp_tpg_is_home' ) ) {
33 $q->is_home = true;
34 }
35 }
36
37 public function register_sc_scripts() {
38 $settings = get_option( rtTPG()->options['settings'] );
39 $caro = $isSinglePopUp = false;
40 $ajaxurl = '';
41
42 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
43 $ajaxurl .= admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
44 } else {
45 $ajaxurl .= admin_url( 'admin-ajax.php' );
46 }
47
48 $variables = [
49 'nonceID' => esc_attr( rtTPG()->nonceId() ),
50 'nonce' => esc_attr( wp_create_nonce( rtTPG()->nonceText() ) ),
51 'ajaxurl' => esc_url( $ajaxurl ),
52 'uid' => get_current_user_id(),
53 ];
54
55 foreach ( $this->scA as $sc ) {
56 if ( isset( $sc ) && is_array( $sc ) ) {
57 if ( $sc['isSinglePopUp'] ) {
58 $isSinglePopUp = true;
59 }
60
61 if ( $sc['isWooCom'] ) {
62 $variables['woocommerce_enable_ajax_add_to_cart'] = get_option( 'woocommerce_enable_ajax_add_to_cart' );
63 $variables['woocommerce_cart_redirect_after_add'] = get_option( 'woocommerce_cart_redirect_after_add' );
64 }
65 }
66 }
67 if ( count( $this->scA ) ) {
68 wp_localize_script( 'rt-tpg', 'rttpg', $variables );
69
70 do_action( 'tpg_after_script', $isSinglePopUp );
71 }
72
73 if ( $isSinglePopUp && rtTPG()->hasPro() ) {
74 $html = null;
75 $html .= '<div class="md-modal rt-md-effect" id="rt-modal">
76 <div class="md-content">
77 <div class="rt-md-content-holder">
78
79 </div>
80 <div class="md-cls-btn">
81 <button class="md-close"><i class="fa fa-times" aria-hidden="true"></i></button>
82 </div>
83 </div>
84 </div>';
85 $html .= "<div class='md-overlay'></div>";
86
87 Fns::print_html( $html );
88 }
89 }
90
91 public function the_post_grid_short_code( $atts, $content = null ) {
92 $rand = wp_rand();
93 $layoutID = 'rt-tpg-container-' . $rand;
94 $html = null;
95 $arg = [];
96 $atts = shortcode_atts(
97 [
98 'id' => null,
99 ],
100 $atts,
101 'the-post-grid'
102 );
103 $scID = $atts['id'];
104
105 if ( $scID && ! is_null( get_post( $scID ) ) ) {
106 $scMeta = get_post_meta( $scID );
107 $layout = ( isset( $scMeta['layout'][0] ) ? $scMeta['layout'][0] : 'layout1' );
108 $gridStyle = ( isset( $scMeta['grid_style'][0] ) ? $scMeta['grid_style'][0] : 'even' );
109
110 if ( ! in_array( $layout, array_keys( Options::rtTPGLayouts() ) ) ) {
111 $layout = 'layout1';
112 }
113
114 $isIsotope = preg_match( '/isotope/', $layout );
115 $isCarousel = preg_match( '/carousel/', $layout );
116 $isGrid = preg_match( '/layout/', $layout );
117 $isWooCom = preg_match( '/wc/', $layout );
118 $isEdd = preg_match( '/edd/', $layout );
119 $isOffset = preg_match( '/offset/', $layout );
120 $isGridHover = preg_match( '/grid_hover/', $layout );
121
122 $colStore = $dCol = ( isset( $scMeta['column'][0] ) ? absint( $scMeta['column'][0] ) : 3 );
123 $tCol = ( isset( $scMeta['tpg_tab_column'][0] ) ? absint( $scMeta['tpg_tab_column'][0] ) : 2 );
124 $mCol = ( isset( $scMeta['tpg_mobile_column'][0] ) ? absint( $scMeta['tpg_mobile_column'][0] ) : 1 );
125
126 if ( ! in_array( $dCol, array_keys( Options::scColumns() ) ) ) {
127 $dCol = 3;
128 }
129
130 if ( ! in_array( $tCol, array_keys( Options::scColumns() ) ) ) {
131 $tCol = 2;
132 }
133
134 if ( ! in_array( $dCol, array_keys( Options::scColumns() ) ) ) {
135 $mCol = 1;
136 }
137
138 if ( $isOffset ) {
139 $dCol = ( $dCol < 3 ? 2 : $dCol );
140 $tCol = ( $tCol < 3 ? 2 : $tCol );
141 $mCol = ( $mCol < 3 ? 1 : $mCol );
142 }
143
144 $arg = [];
145 $fImg = ( ! empty( $scMeta['feature_image'][0] ) ? true : false );
146 $fImgSize = ( isset( $scMeta['featured_image_size'][0] ) ? $scMeta['featured_image_size'][0] : 'medium' );
147 $mediaSource = ( isset( $scMeta['media_source'][0] ) ? $scMeta['media_source'][0] : 'feature_image' );
148 $arg['excerpt_type'] = ( isset( $scMeta['tgp_excerpt_type'][0] ) ? $scMeta['tgp_excerpt_type'][0] : 'character' );
149 $arg['title_limit_type'] = ( isset( $scMeta['tpg_title_limit_type'][0] ) ? $scMeta['tpg_title_limit_type'][0] : 'character' );
150 $arg['excerpt_limit'] = ( isset( $scMeta['excerpt_limit'][0] ) ? absint( $scMeta['excerpt_limit'][0] ) : 0 );
151 $arg['title_limit'] = ( isset( $scMeta['tpg_title_limit'][0] ) ? absint( $scMeta['tpg_title_limit'][0] ) : 0 );
152 $arg['excerpt_more_text'] = ( isset( $scMeta['tgp_excerpt_more_text'][0] ) ? $scMeta['tgp_excerpt_more_text'][0] : null );
153 $arg['read_more_text'] = ( ! empty( $scMeta['tgp_read_more_text'][0] ) ? $scMeta['tgp_read_more_text'][0] : esc_html__( 'Read More', 'the-post-grid' ) );
154 $arg['show_all_text'] = ( ! empty( $scMeta['tpg_show_all_text'][0] ) ? $scMeta['tpg_show_all_text'][0] : esc_html__( 'Show all', 'the-post-grid' ) );
155 $arg['tpg_title_position'] = isset( $scMeta['tpg_title_position'][0] ) && ! empty( $scMeta['tpg_title_position'][0] ) ? $scMeta['tpg_title_position'][0] : null;
156 $arg['btn_alignment_class'] = isset( $scMeta['tpg_read_more_button_alignment'][0] ) && ! empty( $scMeta['tpg_read_more_button_alignment'][0] )
157 ? $scMeta['tpg_read_more_button_alignment'][0] : '';
158 // Category Settings.
159 $arg['category_position'] = isset( $scMeta['tpg_category_position'][0] ) ? $scMeta['tpg_category_position'][0] : null;
160 $arg['category_style'] = ! empty( $scMeta['tpg_category_style'][0] ) ? $scMeta['tpg_category_style'][0] : '';
161 $arg['catIcon'] = isset( $scMeta['tpg_category_icon'][0] ) ? $scMeta['tpg_category_icon'][0] : true;
162 // Meta Settings.
163 $arg['metaPosition'] = isset( $scMeta['tpg_meta_position'][0] ) ? $scMeta['tpg_meta_position'][0] : null;
164 $arg['metaIcon'] = isset( $scMeta['tpg_meta_icon'][0] ) ? $scMeta['tpg_meta_icon'][0] : true;
165 $arg['metaSeparator'] = ! empty( $scMeta['tpg_meta_separator'][0] ) ? $scMeta['tpg_meta_separator'][0] : '';
166 /* Argument create */
167 $args = [];
168 $postType = ( isset( $scMeta['tpg_post_type'][0] ) ? $scMeta['tpg_post_type'][0] : 'post' );
169
170 if ( $postType ) {
171 $args['post_type'] = Fns::available_post_type( $postType );
172 }
173
174 // Common filters.
175 /* post__in */
176 $post__in = ( isset( $scMeta['post__in'][0] ) ? $scMeta['post__in'][0] : null );
177
178 if ( $post__in ) {
179 $post__in = explode( ',', $post__in );
180 $args['post__in'] = $post__in;
181 }
182
183 /* post__not_in */
184 $post__not_in = ( isset( $scMeta['post__not_in'][0] ) ? $scMeta['post__not_in'][0] : null ); //phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in
185
186 if ( $post__not_in ) {
187 $post__not_in = explode( ',', $post__not_in );
188 $args['post__not_in'] = $post__not_in; //phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in
189 }
190
191 /* LIMIT */
192 $limit = ( ( empty( $scMeta['limit'][0] ) || $scMeta['limit'][0] === '-1' ) ? - 1 : absint( $scMeta['limit'][0] ) );
193 $queryOffset = empty( $scMeta['offset'][0] ) ? 0 : absint( $scMeta['offset'][0] );
194 $args['posts_per_page'] = $limit;
195 $pagination = ! empty( $scMeta['pagination'][0] );
196 $posts_loading_type = ( ! empty( $scMeta['posts_loading_type'][0] ) ? $scMeta['posts_loading_type'][0] : 'pagination' );
197
198 if ( ! $isCarousel ) {
199 $posts_per_page = ( isset( $scMeta['posts_per_page'][0] ) ? intval( $scMeta['posts_per_page'][0] ) : $limit );
200 $args['posts_per_page'] = $posts_per_page;
201 }
202
203 if ( $isIsotope && ! $pagination ) {
204 $args['posts_per_page'] = $limit;
205 }
206
207 if ( empty( $posts_per_page ) || ( $posts_per_page == '-1' && $limit ) ) {
208 $args['posts_per_page'] = $limit;
209 }
210
211 if ( $pagination && ! $isCarousel ) {
212 $args['paged'] = get_query_var( 'page' ) ? get_query_var( 'page' ) : ( get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1 );
213 }
214
215 // Advanced Filters.
216 $adv_filter = get_post_meta( $scID, 'post_filter' );
217 $taxFilter = get_post_meta( $scID, 'tgp_filter_taxonomy', true );
218 $taxHierarchical = get_post_meta( $scID, 'tgp_filter_taxonomy_hierarchical', true );
219 $taxFilterTerms = [];
220 $taxFilterOperator = 'IN';
221 // Taxonomy.
222 $taxQ = [];
223
224 if ( in_array( 'tpg_taxonomy', $adv_filter ) && isset( $scMeta['tpg_taxonomy'] ) ) {
225 if ( is_array( $scMeta['tpg_taxonomy'] ) && ! empty( $scMeta['tpg_taxonomy'] ) ) {
226 foreach ( $scMeta['tpg_taxonomy'] as $taxonomy ) {
227 $terms = ( isset( $scMeta[ 'term_' . $taxonomy ] ) ? $scMeta[ 'term_' . $taxonomy ] : [] );
228
229 if ( is_array( $terms ) && ! empty( $terms ) ) {
230 $operator = ( isset( $scMeta[ 'term_operator_' . $taxonomy ][0] ) ? $scMeta[ 'term_operator_' . $taxonomy ][0] : 'IN' );
231 $taxQ[] = [
232 'taxonomy' => $taxonomy,
233 'field' => 'term_id',
234 'terms' => $terms,
235 'operator' => $operator,
236 ];
237
238 if ( $taxonomy == $taxFilter ) {
239 $taxFilterOperator = $operator;
240 }
241 }
242
243 if ( $taxonomy == $taxFilter ) {
244 $taxFilterTerms = $terms;
245 }
246 }
247 }
248
249 if ( count( $taxQ ) >= 2 ) {
250 $relation = ( isset( $scMeta['taxonomy_relation'][0] ) ? $scMeta['taxonomy_relation'][0] : 'AND' );
251 $taxQ['relation'] = $relation;
252 }
253 }
254
255 if ( ! empty( $taxQ ) ) {
256 $args['tax_query'] = $taxQ; //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
257 }
258
259 // Order.
260 if ( in_array( 'order', $adv_filter ) ) {
261 $order_by = ( isset( $scMeta['order_by'][0] ) ? $scMeta['order_by'][0] : null );
262 $order = ( isset( $scMeta['order'][0] ) ? $scMeta['order'][0] : null );
263
264 if ( $order ) {
265 $args['order'] = $order;
266 }
267
268 if ( $order_by ) {
269 $args['orderby'] = $order_by;
270 $meta_key = ! empty( $scMeta['tpg_meta_key'][0] ) ? trim( $scMeta['tpg_meta_key'][0] ) : null;
271
272 if ( in_array( $order_by, array_keys( Options::rtMetaKeyType() ) ) && $meta_key ) {
273 $args['orderby'] = $order_by;
274 $args['meta_key'] = $meta_key; //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
275
276 if ( $order_by === 'meta_value_datetime' ) {
277 $args['orderby'] = 'meta_value_num';
278 }
279 }
280 }
281 }
282
283 // The below code should remove later
284 /*if ( in_array( 'tpg_post_status', $adv_filter ) ) {
285 $post_status = ( isset( $scMeta['tpg_post_status'] ) ? $scMeta['tpg_post_status'] : [] );
286
287 if ( ! empty( $post_status ) ) {
288 $args['post_status'] = $post_status;
289 }
290 } else {
291 $args['post_status'] = 'publish';
292 }*/
293
294 $args['post_status'] = 'publish';
295
296 // Author.
297 $author = ( isset( $scMeta['author'] ) ? $scMeta['author'] : [] );
298 $filterAuthors = [];
299
300 if ( in_array( 'author', $adv_filter ) && ! empty( $author ) ) {
301 $filterAuthors = $args['author__in'] = $author;
302 }
303
304 // Search.
305 $s = ( isset( $scMeta['s'][0] ) ? $scMeta['s'][0] : [] );
306 if ( in_array( 's', $adv_filter ) && ! empty( $s ) ) {
307 $args['s'] = $s;
308 }
309
310 // Date query.
311 if ( in_array( 'date_range', $adv_filter ) ) {
312 $startDate = ( ! empty( $scMeta['date_range_start'][0] ) ? $scMeta['date_range_start'][0] : null );
313 $endDate = ( ! empty( $scMeta['date_range_end'][0] ) ? $scMeta['date_range_end'][0] : null );
314
315 if ( $startDate && $endDate ) {
316 $args['date_query'] = [
317 [
318 'after' => $startDate,
319 'before' => $endDate,
320 'inclusive' => true,
321 ],
322 ];
323 }
324 }
325
326 $settings = get_option( rtTPG()->options['settings'] );
327 $oLayoutTag = ! empty( $settings['template_tag'] ) ? absint( $settings['template_tag'] ) : null;
328 $oLayoutAuthor = ! empty( $settings['template_author'] ) ? $settings['template_author'] : null;
329 $oLayoutCategory = ! empty( $settings['template_category'] ) ? $settings['template_category'] : null;
330 $oLayoutSearch = ! empty( $settings['template_search'] ) ? $settings['template_search'] : null;
331 $dataArchive = null;
332
333 if ( ( is_category() && $oLayoutCategory ) || ( is_search() && $oLayoutSearch ) || ( is_tag() && $oLayoutTag ) || ( is_author() && $oLayoutAuthor ) ) {
334 unset( $args['post_type'] );
335 unset( $args['tax_query'] );
336 unset( $args['author__in'] );
337 $obj = get_queried_object();
338 $aType = $aValue = null;
339
340 if ( $oLayoutTag && is_tag() ) {
341 if ( ! empty( $obj->slug ) ) {
342 $aValue = $args['tag'] = $obj->slug;
343 $aType = 'tag';
344 }
345 } elseif ( $oLayoutCategory && is_category() ) {
346 if ( ! empty( $obj->slug ) ) {
347 $aValue = $args['category_name'] = $obj->slug;
348 }
349 $aType = 'category';
350 } elseif ( $oLayoutAuthor && is_author() ) {
351 $aValue = $args['author'] = $obj->ID;
352 $aType = 'author';
353 } elseif ( $oLayoutSearch && is_search() ) {
354 $aValue = $args['s'] = get_search_query();
355 $aType = 'search';
356 }
357
358 $dataArchive = " data-archive='{$aType}' data-archive-value='{$aValue}'";
359 $args['posts_per_archive_page'] = $args['posts_per_page'];
360 }
361
362 // Validation.
363 $containerDataAttr = null;
364 $containerDataAttr .= " data-layout='{$layout}' data-grid-style='{$gridStyle}' data-desktop-col='{$dCol}' data-tab-col='{$tCol}' data-mobile-col='{$mCol}'";
365
366 $dCol = $dCol == 5 ? '24' : round( 12 / $dCol );
367 $tCol = $dCol == 5 ? '24' : round( 12 / $tCol );
368 $mCol = $dCol == 5 ? '24' : round( 12 / $mCol );
369
370 if ( $isCarousel ) {
371 $dCol = $tCol = $mCol = 12;
372 }
373
374 $arg['grid'] = "rt-col-md-{$dCol} rt-col-sm-{$tCol} rt-col-xs-{$mCol}";
375
376 if ( $layout == 'layout2' || $layout == 'layout3' ) {
377 $iCol = ( isset( $scMeta['tgp_layout2_image_column'][0] ) ? absint( $scMeta['tgp_layout2_image_column'][0] ) : 4 );
378 $iCol = $iCol > 12 ? 4 : $iCol;
379 $cCol = 12 - $iCol;
380 $arg['image_area'] = "rt-col-sm-{$iCol} rt-col-xs-12 ";
381 $arg['content_area'] = "rt-col-sm-{$cCol} rt-col-xs-12 ";
382 } elseif ( $layout == 'layout4' ) {
383 $arg['image_area'] = 'rt-col-md-6 rt-col-sm-12 rt-col-xs-12 ';
384 $arg['content_area'] = 'rt-col-md-6 rt-col-sm-12 rt-col-xs-12 ';
385 }
386
387 $arg_class = [];
388 $gridType = ! empty( $scMeta['grid_style'][0] ) ? $scMeta['grid_style'][0] : 'even';
389
390 if ( $isIsotope && ! rtTPG()->hasPro() ) {
391 $arg_class[] = 'masonry-grid-item';
392 } elseif ( ! $isCarousel && ! $isOffset ) {
393 $arg_class[] = $gridType . '-grid-item';
394 }
395
396 $arg_class[] = 'rt-grid-item';
397
398 if ( $isOffset ) {
399 $arg_class[] = 'rt-offset-item';
400 }
401
402 // Category class.
403 $catHaveBg = ( isset( $scMeta['tpg_category_bg'][0] ) ? $scMeta['tpg_category_bg'][0] : '' );
404
405 if ( ! empty( $catHaveBg ) ) {
406 $arg_class[] = 'category-have-bg';
407 }
408
409 // Image animation type.
410 $imgAnimationType = isset( $scMeta['tpg_image_animation'][0] ) ? $scMeta['tpg_image_animation'][0] : '';
411
412 if ( ! empty( $imgAnimationType ) ) {
413 $arg_class[] = $imgAnimationType;
414 }
415
416 $masonryG = null;
417
418 if ( $gridType == 'even' && ! $isIsotope && ! $isCarousel ) {
419 $masonryG = ' tpg-even';
420 } elseif ( $gridType == 'masonry' && ! $isIsotope && ! $isCarousel ) {
421 $masonryG = ' tpg-masonry';
422 }
423
424 $preLoader = $preLoaderHtml = null;
425
426 if ( $isIsotope ) {
427 $arg_class[] = 'isotope-item';
428 $preLoader = 'tpg-pre-loader';
429 }
430
431 if ( $isCarousel ) {
432 $arg_class[] = 'swiper-slide';
433 $preLoader = 'tpg-pre-loader';
434 }
435
436 if ( $preLoader && rtTPG()->hasPro() ) {
437 $preLoaderHtml = '<div class="rt-loading-overlay"></div><div class="rt-loading rt-ball-clip-rotate"><div></div></div>';
438 }
439
440 $margin = ! empty( $scMeta['margin_option'][0] ) ? $scMeta['margin_option'][0] : 'default';
441
442 if ( $margin == 'no' ) {
443 $arg_class[] = 'no-margin';
444 }
445
446 if ( ! empty( $scMeta['tpg_image_type'][0] ) && $scMeta['tpg_image_type'][0] == 'circle' ) {
447 $arg_class[] = 'tpg-img-circle';
448 }
449
450 $arg['class'] = implode( ' ', $arg_class );
451 $arg['anchorClass'] = $arg['link_target'] = null;
452 $link = isset( $scMeta['link_to_detail_page'][0] ) ? $scMeta['link_to_detail_page'][0] : '1';
453 $link = ( $link == 'yes' ) ? '1' : $link;
454
455 if ( ! $link ) {
456 $arg['anchorClass'] = ' disabled';
457 }
458
459 $isSinglePopUp = false;
460 $linkType = ! empty( $scMeta['detail_page_link_type'][0] ) ? $scMeta['detail_page_link_type'][0] : 'popup';
461
462 if ( $link == '1' ) {
463 if ( $linkType == 'popup' && rtTPG()->hasPro() ) {
464 $popupType = ! empty( $scMeta['popup_type'][0] ) ? $scMeta['popup_type'][0] : 'single';
465
466 if ( $popupType == 'single' ) {
467 $arg['anchorClass'] .= ' tpg-single-popup';
468 $isSinglePopUp = true;
469 } else {
470 $arg['anchorClass'] .= ' tpg-multi-popup';
471 }
472 } else {
473 $arg['link_target'] = ! empty( $scMeta['link_target'][0] ) ? " target='{$scMeta['link_target'][0]}'" : null;
474 }
475 }
476
477 $parentClass = ( ! empty( $scMeta['parent_class'][0] ) ? trim( $scMeta['parent_class'][0] ) : null );
478 $defaultImgId = ( ! empty( $scMeta['default_preview_image'][0] ) ? absint( $scMeta['default_preview_image'][0] ) : null );
479 $customImgSize = ( ! empty( $scMeta['custom_image_size'] ) ? $scMeta['custom_image_size'] : [] );
480 // Grid Hover Layout.
481 $fSmallImgSize = ( isset( $scMeta['featured_small_image_size'][0] ) ? $scMeta['featured_small_image_size'][0] : 'medium' );
482 $customSmallImgSize = ( ! empty( $scMeta['custom_small_image_size'] ) ? $scMeta['custom_small_image_size'] : [] );
483
484 $arg['scID'] = $scID;
485 $arg['items'] = isset( $scMeta['item_fields'] ) ? ( $scMeta['item_fields'] ? $scMeta['item_fields'] : [] ) : [];
486
487 if ( in_array( 'cf', $arg['items'] ) ) {
488 $arg['cf_group'] = [];
489 $arg['cf_group'] = get_post_meta( $scID, 'cf_group' );
490 $arg['format'] = [
491 'hide_empty' => get_post_meta( $scID, 'cf_hide_empty_value', true ),
492 'show_value' => get_post_meta( $scID, 'cf_show_only_value', true ),
493 'hide_group_title' => get_post_meta( $scID, 'cf_hide_group_title', true ),
494 ];
495 }
496
497 // Set readmore false if excerpt type = full content.
498 if ( isset( $arg['excerpt_type'] ) && $arg['excerpt_type'] === 'full' && ( $key = array_search( 'read_more', $arg['items'] ) ) !== false ) {
499 unset( $arg['items'][ $key ] );
500 }
501
502 if ( empty( $scMeta['ignore_sticky_posts'][0] ) ) {
503 $args['ignore_sticky_posts'] = true;
504 } else {
505 $args['wp_tpg_is_home'] = true;
506 }
507
508 $filters = ! empty( $scMeta['tgp_filter'] ) ? $scMeta['tgp_filter'] : [];
509 $action_term = ! empty( $scMeta['tgp_default_filter'][0] ) ? absint( $scMeta['tgp_default_filter'][0] ) : 0;
510 $hide_all_button = ! empty( $scMeta['tpg_hide_all_button'][0] ) ? true : false;
511
512 if ( $taxHierarchical ) {
513 $terms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, 0 );
514 } else {
515 $terms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true );
516 }
517
518 if ( $hide_all_button && ! $action_term ) {
519 if ( ! empty( $terms ) ) {
520 $allKeys = array_keys( $terms );
521 $action_term = $allKeys[0];
522 }
523 }
524
525 if ( in_array( '_taxonomy_filter', $filters ) && $taxFilter && $action_term ) {
526 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
527 $args['tax_query'] = [
528 [
529 'taxonomy' => $taxFilter,
530 'field' => 'term_id',
531 'terms' => [ $action_term ],
532 ],
533 ];
534 }
535
536 if ( $limit != - 1 && $pagination ) {
537 $tempArgs = $args;
538 $tempArgs['posts_per_page'] = $limit;
539 $tempArgs['paged'] = 1;
540 $tempArgs['fields'] = 'ids';
541 $tempQ = new \WP_Query( apply_filters( 'tpg_sc_temp_query_args', $tempArgs ) );
542
543 if ( ! empty( $tempQ->posts ) ) {
544 $args['post__in'] = $tempQ->posts;
545 }
546 }
547
548 if ( $pagination && $queryOffset && isset( $args['paged'] ) ) {
549 $queryOffset = ( $posts_per_page * ( $args['paged'] - 1 ) ) + $queryOffset;
550 }
551
552 if ( $queryOffset ) {
553 $args['offset'] = $queryOffset;
554 }
555
556 $arg['title_tag'] = ( ! empty( $scMeta['title_tag'][0] ) && in_array( $scMeta['title_tag'][0], array_keys( Options::getTitleTags() ) ) ) ? esc_attr( $scMeta['title_tag'][0] ) : 'h3';
557
558 $gridQuery = new \WP_Query( apply_filters( 'tpg_sc_query_args', $args, $scMeta ) );
559
560 // Start layout.
561 $html .= Fns::layoutStyle( $layoutID, $scMeta, $layout, $scID );
562
563 $containerDataAttr .= " data-sc-id='{$scID}'";
564
565 if ( isset( $settings['tpg_load_script'] ) ) {
566 $parentClass .= ' loading';
567 }
568
569 $carousel_nav = ! empty( $scMeta['carousel_property'] ) ? $scMeta['carousel_property'] : [];
570 $is_nav = in_array( 'nav_button', $carousel_nav );
571
572 if ( $isCarousel ) {
573 $parentClass .= ' tpg-carousel-main';
574
575 if ( $is_nav ) {
576 $parentClass .= ' tpg-has-nav';
577 }
578
579 $cOptMeta = ! empty( $scMeta['carousel_property'] ) ? $scMeta['carousel_property'] : [];
580
581 if ( in_array( 'lazy_load', $cOptMeta ) ) {
582 $parentClass .= ' is-lazy-load-yes';
583 }
584
585 if ( in_array( 'auto_height', $cOptMeta ) ) {
586 $parentClass .= ' is-auto-height-yes';
587 }
588 }
589
590 $parentClass = esc_attr( $parentClass );
591
592 $html .= "<div class='rt-container-fluid rt-tpg-container tpg-shortcode-main-wrapper {$parentClass}' id='{$layoutID}' {$dataArchive} {$containerDataAttr}>";
593
594 // widget heading.
595 $heading_tag = isset( $scMeta['tpg_heading_tag'][0] ) ? esc_attr( $scMeta['tpg_heading_tag'][0] ) : 'h2';
596 $heading_style = isset( $scMeta['tpg_heading_style'][0] ) && ! empty( $scMeta['tpg_heading_style'][0] ) ? esc_attr( $scMeta['tpg_heading_style'][0] ) : 'style1';
597 $heading_alignment = isset( $scMeta['tpg_heading_alignment'][0] ) ? esc_attr( $scMeta['tpg_heading_alignment'][0] ) : '';
598 $heading_link = isset( $scMeta['tpg_heading_link'][0] ) ? esc_attr( $scMeta['tpg_heading_link'][0] ) : '';
599
600 if ( ! empty( $arg['items'] ) && in_array( 'heading', $arg['items'] ) ) {
601 $html .= sprintf( '<div class="tpg-widget-heading-wrapper heading-%1$s %2$s">', $heading_style, $heading_alignment );
602 $html .= '<span class="tpg-widget-heading-line line-left"></span>';
603
604 if ( $heading_link ) {
605 $html .= sprintf( '<%1$s class="tpg-widget-heading"><a href="%2$s" title="%3$s">%3$s</a></%1$s>', esc_attr( Fns::print_validated_html_tag( $heading_tag ) ), $heading_link, esc_html( get_the_title() ) );
606 } else {
607 $html .= sprintf( '<%1$s class="tpg-widget-heading">%2$s</%1$s>', esc_attr( Fns::print_validated_html_tag( $heading_tag ) ), esc_html( get_the_title( $scID ) ) );
608 }
609
610 $html .= '<span class="tpg-widget-heading-line"></span>';
611 $html .= '</div>';
612 }
613
614 if ( ! $isCarousel && isset( $settings['tpg_enable_preloader'] ) ) {
615 $html .= '<div id="bottom-script-loader" class="bottom-script-loader"><div class="rt-ball-clip-rotate"><div></div></div></div>';
616 }
617
618 if ( rtTPG()->hasPro() && ! empty( $filters ) && ( $isGrid || $isOffset || $isWooCom || $isEdd || $isGridHover ) ) {
619 $html .= "<div class='rt-layout-filter-container rt-clear'><div class='rt-filter-wrap'>";
620 $selectedSubTermsForButton = null;
621 $allText = apply_filters( 'tpg_filter_all_text', esc_html__( 'All', 'the-post-grid' ), $scMeta );
622
623 if ( in_array( '_taxonomy_filter', $filters ) && $taxFilter ) {
624 $filterType = ( ! empty( $scMeta['tgp_filter_type'][0] ) ? $scMeta['tgp_filter_type'][0] : null );
625 $post_count = ( ! empty( $scMeta['tpg_post_count'][0] ) ? $scMeta['tpg_post_count'][0] : null );
626 $postCountClass = ( $post_count ? ' has-post-count' : null );
627 $allSelect = ' selected';
628 $isTermSelected = false;
629
630 if ( $action_term && $taxFilter ) {
631 $isTermSelected = true;
632 $allSelect = null;
633 }
634
635 if ( ! $filterType || $filterType == 'dropdown' ) {
636 $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-taxonomy='{$taxFilter}'>";
637 $termDefaultText = $allText;
638 $dataTerm = 'all';
639 $htmlButton = '';
640 $selectedSubTerms = null;
641 $pCount = 0;
642
643 if ( ! empty( $terms ) ) {
644 $i = 0;
645
646 foreach ( $terms as $id => $term ) {
647 $pCount = $pCount + $term['count'];
648 $sT = null;
649
650 if ( $taxHierarchical ) {
651 $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id );
652
653 if ( ! empty( $subTerms ) ) {
654 $count = 0;
655 $item = $allCount = null;
656
657 foreach ( $subTerms as $stId => $t ) {
658 $count = $count + absint( $t['count'] );
659 $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null );
660 $item .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$stId}'><span class='rt-text'>{$t['name']}{$sTPostCount}</span></span>";
661 }
662
663 if ( $post_count ) {
664 $allCount = " (<span class='rt-post-count'>{$count}</span>)";
665 }
666
667 $sT .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap sub-dropdown-wrap{$postCountClass}'>";
668 $sT .= "<span class='term-default rt-filter-dropdown-default' data-term='{$id}'>
669 <span class='rt-text'>" . $allText . "{$allCount}</span>
670 <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i>
671 </span>";
672 $sT .= '<span class="term-dropdown rt-filter-dropdown">';
673 $sT .= $item;
674 $sT .= '</span>';
675 $sT .= '</div>';
676 }
677
678 if ( $action_term === $id ) {
679 $selectedSubTerms = $sT;
680 }
681 }
682
683 $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null );
684
685 if ( $action_term && $action_term == $id ) {
686 $termDefaultText = $term['name'] . $postCount;
687 $dataTerm = $id;
688 }
689
690 if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) {
691 if ( $taxFilterOperator == 'NOT IN' ) {
692 if ( ! in_array( $id, $taxFilterTerms ) && $action_term != $id ) {
693 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
694 }
695 } else {
696 if ( in_array( $id, $taxFilterTerms ) && $action_term != $id ) {
697 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
698 }
699 }
700 } else {
701 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
702 }
703
704 $i ++;
705 }
706 }
707 $pAllCount = null;
708
709 if ( $post_count ) {
710 $pAllCount = " (<span class='rt-post-count'>{$pCount}</span>)";
711 if ( ! $action_term ) {
712 $termDefaultText = $termDefaultText . $pAllCount;
713 }
714 }
715
716 if ( ! $hide_all_button ) {
717 $htmlButton = "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'><span class='rt-text'>" . $allText . "{$pAllCount}</span></span>" . $htmlButton;
718 }
719 $htmlButton = sprintf( '<span class="term-dropdown rt-filter-dropdown">%s</span>', $htmlButton );
720
721 $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataTerm . '">
722 <span class="rt-text">' . $termDefaultText . '</span>
723 <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i>
724 </span>';
725
726 $html .= $showAllhtml . $htmlButton;
727 $html .= '</div>' . $selectedSubTerms;
728 } else {
729 $termDefaultText = $allText;
730 $bCount = 0;
731 $bItems = null;
732
733 if ( ! empty( $terms ) ) {
734 foreach ( $terms as $id => $term ) {
735 $bCount = $bCount + absint( $term['count'] );
736 $sT = null;
737
738 if ( $taxHierarchical ) {
739 $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id );
740 if ( ! empty( $subTerms ) ) {
741 $sT .= "<div class='rt-filter-sub-tax sub-button-group'>";
742
743 foreach ( $subTerms as $stId => $t ) {
744 $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null );
745 $sT .= "<span class='rt-filter-button-item' data-term='{$stId}'>{$t['name']}{$sTPostCount}</span>";
746 }
747
748 $sT .= '</div>';
749
750 if ( $action_term === $id ) {
751 $selectedSubTermsForButton = $sT;
752 }
753 }
754 }
755
756 $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null );
757 $termSelected = null;
758
759 if ( $isTermSelected && $id == $action_term ) {
760 $termSelected = ' selected';
761 }
762
763 if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) {
764 if ( $taxFilterOperator == 'NOT IN' ) {
765 if ( ! in_array( $id, $taxFilterTerms ) ) {
766 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
767 }
768 } else {
769 if ( in_array( $id, $taxFilterTerms ) ) {
770 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
771 }
772 }
773 } else {
774 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
775 }
776 }
777 }
778
779 $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-button-wrap{$postCountClass}' data-taxonomy='{$taxFilter}'>";
780
781 if ( ! $hide_all_button ) {
782 $pCountH = ( $post_count ? " (<span class='rt-post-count'>{$bCount}</span>)" : null );
783 $html .= "<span class='term-button-item rt-filter-button-item {$allSelect}' data-term='all'>" . $allText . "{$pCountH}</span>";
784 }
785
786 $html .= $bItems;
787 $html .= '</div>';
788 }
789 }
790
791 // Author filter.
792 if ( in_array( '_author_filter', $filters ) ) {
793 $filterType = ( ! empty( $scMeta['tgp_filter_type'][0] ) ? $scMeta['tgp_filter_type'][0] : null );
794 $post_count = ( ! empty( $scMeta['tpg_post_count'][0] ) ? $scMeta['tpg_post_count'][0] : null );
795 $users = get_users( apply_filters( 'tpg_author_arg', [] ) );
796
797 $allSelect = ' selected';
798 $isTermSelected = false;
799
800 if ( $action_term && $taxFilter ) {
801 $isTermSelected = true;
802 $allSelect = null;
803 }
804
805 $postCountClass = $postCountClass ?? '';
806 if ( ! $filterType || $filterType == 'dropdown' ) {
807 $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}'>";
808 $termDefaultText = $allText;
809 $dataAuthor = 'all';
810 $htmlButton = '';
811 $htmlButton .= '<span class="author-dropdown rt-filter-dropdown">';
812
813 if ( ! empty( $users ) ) {
814 foreach ( $users as $user ) {
815 if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) {
816 if ( in_array( $user->ID, $filterAuthors ) ) {
817 if ( $action_term == $user->ID ) {
818 $termDefaultText = $user->display_name;
819 $dataTerm = $user->ID;
820 } else {
821 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'>{$user->display_name}</span>";
822 }
823 }
824 } else {
825 if ( $action_term == $user->ID ) {
826 $termDefaultText = $user->display_name;
827 $dataTerm = $user->ID;
828 } else {
829 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'>{$user->display_name}</span>";
830 }
831 }
832 }
833 }
834
835 if ( $isTermSelected ) {
836 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'>" . $allText . "{$pAllCount}</span>";
837 }
838 $htmlButton .= '</span>';
839
840 $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataAuthor . '">
841 <span class="rt-text">' . $termDefaultText . '</span>
842 <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i>
843 </span>';
844
845 $html .= $showAllhtml . $htmlButton;
846 $html .= '</div>';
847 } else {
848 $bCount = 0;
849 $bItems = null;
850 if ( ! empty( $users ) ) {
851 foreach ( $users as $user ) {
852 if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) {
853 if ( in_array( $user->ID, $filterAuthors ) ) {
854 $bItems .= "<span class='author-button-item rt-filter-button-item data-author='{$user->ID}'>{$user->display_name}</span>";
855 }
856 } else {
857 $bItems .= "<span class='author-button-item rt-filter-button-item data-author='{$user->ID}'>{$user->display_name}</span>";
858 }
859 }
860 }
861
862 $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-button-wrap{$postCountClass}' data-taxonomy='{$taxFilter}'>";
863
864 if ( ! $hide_all_button ) {
865 $pCountH = ( $post_count ? " (<span class='rt-post-count'>{$bCount}</span>)" : null );
866 $html .= "<span class='author-button-item rt-filter-button-item {$allSelect}' data-author='all'>" . $allText . "{$pCountH}</span>";
867 }
868
869 $html .= $bItems;
870 $html .= '</div>';
871 }
872 }
873
874 if ( in_array( '_search', $filters ) ) {
875 $html .= '<div class="rt-filter-item-wrap rt-search-filter-wrap">';
876 $html .= sprintf( '<input type="text" class="rt-search-input" placeholder="%s">', esc_html__( 'Search...', 'the-post-grid' ) );
877 $html .= "<span class='rt-action'>&#128269;</span>";
878 $html .= "<span class='rt-loading'></span>";
879 $html .= '</div>';
880 }
881
882 if ( in_array( '_order_by', $filters ) ) {
883 $wooFeature = ( $postType == 'product' ? true : false );
884 $orders = Options::rtPostOrderBy( $wooFeature );
885 $action_orderby = ( ! empty( $args['orderby'] ) ? trim( $args['orderby'] ) : 'none' );
886
887 if ( $action_orderby == 'ID' ) {
888 $action_orderby = 'title';
889 }
890
891 if ( $action_orderby == 'none' ) {
892 $action_orderby_label = esc_html__( 'Sort By None', 'the-post-grid' );
893 } elseif ( in_array( $action_orderby, array_keys( Options::rtMetaKeyType() ) ) ) {
894 $action_orderby_label = esc_html__( 'Meta value', 'the-post-grid' );
895 } else {
896 $action_orderby_label = isset( $orders[ $action_orderby ] ) ? $orders[ $action_orderby ] : '';
897 }
898
899 if ( $action_orderby !== 'none' ) {
900 $orders['none'] = esc_html__( 'Sort By None', 'the-post-grid' );
901 }
902 $html .= '<div class="rt-filter-item-wrap rt-order-by-action rt-filter-dropdown-wrap">';
903 $html .= "<span class='order-by-default rt-filter-dropdown-default' data-order-by='{$action_orderby}'>
904 <span class='rt-text-order-by'>{$action_orderby_label}</span>
905 <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i>
906 </span>";
907 $html .= '<span class="order-by-dropdown rt-filter-dropdown">';
908
909 foreach ( $orders as $orderKey => $order ) {
910 $html .= '<span class="order-by-dropdown-item rt-filter-dropdown-item" data-order-by="' . $orderKey . '">' . $order . '</span>';
911 }
912
913 $html .= '</span>';
914 $html .= '</div>';
915 }
916
917 if ( in_array( '_sort_order', $filters ) ) {
918 $action_order = ( ! empty( $args['order'] ) ? strtoupper( trim( $args['order'] ) ) : 'DESC' );
919 $html .= '<div class="rt-filter-item-wrap rt-sort-order-action">';
920 $html .= "<span class='rt-sort-order-action-arrow' data-sort-order='{$action_order}'>&nbsp;<span></span></span>";
921 $html .= '</div>';
922 }
923
924 $html .= "</div>$selectedSubTermsForButton</div>";
925 }
926 $is_gallery_layout = ' ';
927 if ( $layout === 'layout17' ) {
928 $is_gallery_layout = 'grid-layout7';
929 }
930 $html .= "<div data-title='" . esc_html__( 'Loading ...', 'the-post-grid' ) . "' class='rt-row rt-content-loader {$is_gallery_layout} {$layout}{$masonryG} {$preLoader}'>";
931
932 $not_found_text = isset( $scMeta['tgp_not_found_text'][0] ) && ! empty( $scMeta['tgp_not_found_text'][0] ) ? esc_html( $scMeta['tgp_not_found_text'][0] ) : esc_html__( 'No post found', 'the-post-grid' );
933
934 if ( $gridQuery->have_posts() ) {
935 $is_lazy_load = '';
936
937 if ( $isCarousel ) {
938 $cOpt = ! empty( $scMeta['carousel_property'] ) ? $scMeta['carousel_property'] : [];
939 $slider_js_options = apply_filters(
940 'rttpg_slider_js_options',
941 [
942 'speed' => ! empty( $scMeta['tpg_carousel_speed'][0] ) ? absint( $scMeta['tpg_carousel_speed'][0] ) : 250,
943 'autoPlayTimeOut' => ! empty( $scMeta['tpg_carousel_autoplay_timeout'][0] ) ? absint( $scMeta['tpg_carousel_autoplay_timeout'][0] ) : 5000,
944 'autoPlay' => in_array( 'auto_play', $cOpt ),
945 'stopOnHover' => in_array( 'stop_hover', $cOpt ),
946 'nav' => in_array( 'nav_button', $cOpt ),
947 'dots' => in_array( 'pagination', $cOpt ),
948 'loop' => in_array( 'loop', $cOpt ),
949 'lazy' => in_array( 'lazy_load', $cOpt ),
950 'autoHeight' => in_array( 'auto_height', $cOpt ),
951 'rtl' => in_array( 'rtl', $cOpt ) ? 'rtl' : 'ltr',
952 ],
953 $scMeta
954 );
955 $html .= sprintf(
956 '<div class="rt-swiper-holder swiper" data-rtowl-options="%s" dir="%s"><div class="swiper-wrapper">',
957 htmlspecialchars( wp_json_encode( $slider_js_options ) ),
958 esc_attr( $slider_js_options['rtl'] )
959 );
960
961 if ( in_array( 'lazy_load', $cOpt ) ) {
962 $is_lazy_load = 'swiper-lazy';
963 }
964 }
965
966 $isotope_filter = null;
967
968 //Isotope Filter
969 //================
970
971 if ( $isIsotope ) {
972 $isotope_filter = isset( $scMeta['isotope_filter'][0] ) ? $scMeta['isotope_filter'][0] : null;
973 $isotope_dropdown_filter = isset( $scMeta['isotope_filter_dropdown'][0] ) ? $scMeta['isotope_filter_dropdown'][0] : null;
974 $selectedTerms = [];
975
976 if ( isset( $scMeta['post_filter'] )
977 && in_array(
978 'tpg_taxonomy',
979 $scMeta['post_filter']
980 )
981 && isset( $scMeta['tpg_taxonomy'] )
982 && in_array(
983 $isotope_filter,
984 $scMeta['tpg_taxonomy']
985 )
986 ) {
987 $selectedTerms = ( isset( $scMeta[ 'term_' . $isotope_filter ] ) ? $scMeta[ 'term_' . $isotope_filter ] : [] );
988 }
989 $termArgs = [
990 'taxonomy' => $isotope_filter,
991 'orderby' => 'meta_value_num',
992 'order' => 'ASC',
993 'hide_empty' => false,
994 'include' => $selectedTerms,
995 ];
996
997 if ( rtTPG()->hasPro() ) {
998 $termArgs['meta_key'] = '_rt_order'; //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
999 }
1000
1001 $terms = get_terms( $termArgs );
1002
1003 $html .= '<div class="tpg-iso-filter">';
1004 $htmlButton = $drop = null;
1005 $fSelectTrigger = false;
1006
1007 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
1008 foreach ( $terms as $term ) {
1009 $tItem = ! empty( $scMeta['isotope_default_filter'][0] ) ? $scMeta['isotope_default_filter'][0] : null;
1010 $fSelected = null;
1011
1012 if ( $tItem == $term->term_id ) {
1013 $fSelected = 'selected';
1014 $fSelectTrigger = true;
1015 }
1016
1017 $htmlButton .= sprintf(
1018 '<button class="rt-iso-btn-%s%s" data-filter=".iso_%d">%s</button>',
1019 esc_attr( $term->slug ),
1020 $fSelected ? ' ' . $fSelected : '',
1021 $term->term_id,
1022 $term->name
1023 );
1024 $drop .= "<option value='.iso_{$term->term_id}' {$fSelected}>{$term->name}</option>";
1025 }
1026 }
1027
1028 if ( empty( $scMeta['isotope_filter_show_all'][0] ) ) {
1029 $is_select_iso_term = ! empty( $scMeta['isotope_default_filter'][0] ) ? '' : 'selected';
1030 $fSelect = ( $fSelectTrigger ? null : 'class="selected"' );
1031 $htmlButton = "<button class='rt-iso-btn-all " . $is_select_iso_term . "' data-filter='*'>" . $arg['show_all_text'] . '</button>' . $htmlButton;
1032 $drop = "<option value='*' {$fSelect}>{$arg['show_all_text']}</option>" . $drop;
1033 }
1034
1035 $filter_count = ! empty( $scMeta['isotope_filter_count'][0] ) ? true : false;
1036 $filter_url = ! empty( $scMeta['isotope_filter_url'][0] ) ? true : false;
1037 $htmlButton = "<div id='iso-button-{$rand}' class='rt-tpg-isotope-buttons button-group filter-button-group option-set' data-url='{$filter_url}' data-count='{$filter_count}'>{$htmlButton}</div>";
1038
1039 if ( $isotope_dropdown_filter ) {
1040 $html .= "<select class='isotope-dropdown-filter' data-url='{$filter_url}'>{$drop}</select>";
1041 } else {
1042 $html .= $htmlButton;
1043 }
1044
1045 if ( ! empty( $scMeta['isotope_search_filter'][0] ) ) {
1046 $html .= "<div class='iso-search'><input type='text' class='iso-search-input' placeholder='" . esc_html__( 'Search', 'the-post-grid' ) . "' /></div>";
1047 }
1048
1049 $html .= '</div>';
1050 $html .= "<div class='rt-tpg-isotope' id='iso-tpg-{$rand}'>";
1051 }
1052
1053 $l = $offLoop = 0;
1054 $offsetBigHtml = $offsetSmallHtml = null;
1055 $gridPostCount = 0;
1056 $arg['totalPost'] = $gridQuery->post_count;
1057
1058 while ( $gridQuery->have_posts() ) :
1059 $gridQuery->the_post();
1060
1061 if ( $colStore == $l ) {
1062 if ( $this->l4toggle ) {
1063 $this->l4toggle = false;
1064 } else {
1065 $this->l4toggle = true;
1066 }
1067
1068 $l = 0;
1069 }
1070 $pID = get_the_ID();
1071 $external_link = get_post_meta( $pID, 'tpg_read_more', true );
1072 $arg['postCount'] = $gridPostCount ++;
1073 $arg['pID'] = $pID;
1074 $arg['title'] = Fns::get_the_title( $pID, $arg );
1075 $arg['pLink'] = ! empty($external_link['url']) ? $external_link['url'] : get_permalink();
1076 $arg['toggle'] = $this->l4toggle;
1077 $arg['layoutID'] = $layoutID;
1078 $arg['author'] = apply_filters(
1079 'rttpg_author_link',
1080 sprintf( '<a href="%s">%s</a>', get_author_posts_url( get_the_author_meta( 'ID' ) ), get_the_author() )
1081 );
1082 $comments_number = get_comments_number( $pID );
1083 $comments_text = sprintf( '(%s)', number_format_i18n( $comments_number ) );
1084
1085 $arg['date'] = get_the_date();
1086 $arg['excerpt'] = Fns::get_the_excerpt( $pID, $arg );
1087 $default_taxonomy = 'category';
1088 $_all_post_types = array_keys( Fns::get_post_types() );
1089
1090 if ( $postType && ! in_array(
1091 $postType,
1092 [
1093 'post',
1094 'page',
1095 ]
1096 ) && in_array( $postType, $_all_post_types ) ) {
1097 $taxonomies = get_object_taxonomies( $postType );
1098
1099 if ( in_array( '_taxonomy_filter', $filters ) && $taxFilter ) {
1100 $default_taxonomy = $taxFilter;
1101 } elseif ( ! empty( $scMeta['tpg_taxonomy'] ) ) {
1102 $default_taxonomy = $scMeta['tpg_taxonomy'][0];
1103 } elseif ( ! empty( $taxonomies ) ) {
1104 $default_taxonomy = $taxonomies[0];
1105 }
1106 }
1107
1108 $arg['categories'] = Fns::rt_get_the_term_list( $pID, $default_taxonomy, null, '<span class="rt-separator">,</span>' );
1109 $arg['tags'] = get_the_term_list( $pID, 'post_tag', null, '<span class="rt-separator">,</span>' );
1110 $arg['post_count'] = get_post_meta( $pID, Fns::get_post_view_count_meta_key(), true );
1111 $arg['responsiveCol'] = [ $dCol, $tCol, $mCol ];
1112
1113 if ( $isIsotope ) {
1114 $termAs = wp_get_post_terms( $pID, $isotope_filter, [ 'fields' => 'all' ] );
1115 $isoFilter = [];
1116
1117 if ( ! empty( $termAs ) ) {
1118 foreach ( $termAs as $term ) {
1119 $isoFilter[] = 'iso_' . $term->term_id;
1120 $isoFilter[] = 'rt-item-' . esc_attr( $term->slug );
1121 }
1122 }
1123
1124 $arg['isoFilter'] = ! empty( $isoFilter ) ? implode( ' ', $isoFilter ) : '';
1125 }
1126
1127 if ( comments_open() ) {
1128 $arg['comment'] = "<a href='" . get_comments_link( $pID ) . "'>{$comments_text} </a>";
1129 } else {
1130 $arg['comment'] = "{$comments_text}";
1131 }
1132
1133 $imgSrc = null;
1134
1135 // Image Thumbnail.
1136 $arg['smallImgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1137 $pID,
1138 $fSmallImgSize,
1139 $mediaSource,
1140 $defaultImgId,
1141 $customSmallImgSize,
1142 $is_lazy_load
1143 ) : null;
1144 if ( $isOffset ) {
1145 if ( $offLoop == 0 ) {
1146 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1147 $pID,
1148 $fImgSize,
1149 $mediaSource,
1150 $defaultImgId,
1151 $customImgSize
1152 ) : null;
1153 $arg['offset'] = 'big';
1154 $offsetBigHtml = Fns::get_template_html( 'layouts/' . $layout, $arg );
1155 } else {
1156 $arg['offset'] = 'small';
1157 $arg['offsetCol'] = [ $dCol, $tCol, $mCol ];
1158 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1159 $pID,
1160 'thumbnail',
1161 $mediaSource,
1162 $defaultImgId,
1163 $customImgSize
1164 ) : null;
1165 $offsetSmallHtml .= Fns::get_template_html( 'layouts/' . $layout, $arg );
1166 }
1167 } else {
1168 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1169 $pID,
1170 $fImgSize,
1171 $mediaSource,
1172 $defaultImgId,
1173 $customImgSize,
1174 $is_lazy_load
1175 ) : null;
1176 $html .= Fns::get_template_html( 'layouts/' . $layout, $arg );
1177 }
1178
1179 $offLoop ++;
1180 $l ++;
1181 endwhile;
1182
1183 if ( $isOffset ) {
1184 $oDCol = Fns::get_offset_col( $dCol );
1185 $oTCol = Fns::get_offset_col( $tCol );
1186 $oMCol = Fns::get_offset_col( $mCol );
1187
1188 if ( $layout == 'offset03' || $layout == 'offset04' ) {
1189 $oDCol['big'] = $oTCol['big'] = $oDCol['small'] = $oTCol['small'] = 6;
1190 $oMCol['big'] = $oMCol['small'] = 12;
1191 } elseif ( $layout == 'offset06' ) {
1192 $oDCol['big'] = 7;
1193 $oDCol['small'] = 5;
1194 }
1195
1196 $html .= "<div class='rt-col-md-{$oDCol['big']} rt-col-sm-{$oTCol['big']} rt-col-xs-{$oMCol['big']}'><div class='rt-row'>{$offsetBigHtml}</div></div>";
1197 $html .= "<div class='rt-col-md-{$oDCol['small']} rt-col-sm-{$oTCol['small']} rt-col-xs-{$oMCol['small']}'><div class='rt-row offset-small-wrap'>{$offsetSmallHtml}</div></div>";
1198 }
1199
1200 if ( $isIsotope || $isCarousel ) {
1201 $html .= '</div>'; // End isotope / Carousel item holder.
1202
1203 if ( $isIsotope ) {
1204 $html .= '<div class="isotope-term-no-post"><p>' . $not_found_text . '</p></div>';
1205 }
1206
1207 if ( $isCarousel ) {
1208 $html .= '</div>';
1209
1210 if ( in_array( 'pagination', $cOpt ) ) {
1211 $html .= '<div class="swiper-pagination"></div>';
1212 }
1213
1214 if ( in_array( 'nav_button', $cOpt ) ) {
1215 $html .= '<div class="swiper-navigation"><div class="slider-btn swiper-button-prev"></div><div class="slider-btn swiper-button-next"></div></div>';
1216 }
1217 }
1218 }
1219 } else {
1220 $html .= sprintf(
1221 '<p>%s</p>',
1222 apply_filters( 'tpg_not_found_text', $not_found_text, $args, $scMeta )
1223 );
1224 }
1225
1226 $html .= $preLoaderHtml;
1227 $html .= '</div>'; // End row.
1228 $htmlUtility = null;
1229
1230 if ( $pagination && ! $isCarousel ) {
1231 if ( $isOffset || $isGridHover ) {
1232 $posts_loading_type = 'page_prev_next';
1233 $htmlUtility .= "<div class='rt-cb-page-prev-next'>
1234 <span class='rt-cb-prev-btn'><i class='fa fa-angle-left' aria-hidden='true'></i></span>
1235 <span class='rt-cb-next-btn'><i class='fa fa-angle-right' aria-hidden='true'></i></span>
1236 </div>";
1237 } else {
1238 $hide = ( $gridQuery->max_num_pages < 2 ? ' rt-hidden-elm' : null );
1239 if ( $posts_loading_type == 'pagination' ) {
1240 if ( ( $isGrid || $isWooCom || $isEdd ) && empty( $filters ) ) {
1241 $htmlUtility .= Fns::rt_pagination( $gridQuery );
1242 }
1243 } elseif ( $posts_loading_type == 'pagination_ajax' && ! $isIsotope ) {
1244 $htmlUtility .= "<div class='rt-page-numbers'></div>";
1245 } elseif ( $posts_loading_type == 'load_more' && rtTPG()->hasPro() ) {
1246 $load_more_btn_text = ( ! empty( $scMeta['load_more_text'][0] ) ? $scMeta['load_more_text'][0] : '' );
1247 $load_more_text = $load_more_btn_text ? esc_html( $load_more_btn_text ) : esc_html__( 'Load More', 'the-post-grid' );
1248
1249 $htmlUtility .= "<div class='rt-loadmore-btn rt-loadmore-action rt-loadmore-style{$hide}'>
1250 <span class='rt-loadmore-text'>" . $load_more_text . "</span>
1251 <div class='rt-loadmore-loading rt-ball-scale-multiple rt-2x'><div></div><div></div><div></div></div>
1252 </div>";
1253 } elseif ( $posts_loading_type == 'load_on_scroll' && rtTPG()->hasPro() ) {
1254 $htmlUtility .= "<div class='rt-infinite-action'>
1255 <div class='rt-infinite-loading la-fire la-2x'>
1256 <div></div>
1257 <div></div>
1258 <div></div>
1259 </div>
1260 </div>";
1261 }
1262 }
1263 }
1264
1265 if ( $htmlUtility ) {
1266 $l4toggle = null;
1267 if ( $layout == 'layout4' ) {
1268 $l4toggle = "data-l4toggle='{$this->l4toggle}'";
1269 }
1270 $html .= "<div class='rt-pagination-wrap' data-total-pages='{$gridQuery->max_num_pages}' data-posts-per-page='{$args['posts_per_page']}' data-type='{$posts_loading_type}' {$l4toggle} >" . $htmlUtility . '</div>';
1271 }
1272
1273 $html .= '</div>'; // container rt-tpg.
1274
1275 wp_reset_postdata();
1276
1277 $scriptGenerator = [];
1278 $scriptGenerator['layout'] = $layoutID;
1279 $scriptGenerator['rand'] = $rand;
1280 $scriptGenerator['scMeta'] = $scMeta;
1281 $scriptGenerator['isCarousel'] = $isCarousel;
1282 $scriptGenerator['isSinglePopUp'] = $isSinglePopUp;
1283 $scriptGenerator['isWooCom'] = $isWooCom;
1284 $this->scA[] = $scriptGenerator;
1285
1286 add_action( 'wp_footer', [ $this, 'register_sc_scripts' ] );
1287
1288 // Script Load Conditionally
1289 $script = [];
1290 $style = [];
1291
1292 array_push( $script, 'jquery' );
1293 array_push( $style, 'rt-fontawsome' );
1294 array_push( $style, 'rt-flaticon' );
1295
1296 if ( 'masonry' == $gridType || $isIsotope ) {
1297 array_push( $script, 'rt-isotope-js' );
1298 }
1299
1300 array_push( $script, 'imagesloaded' );
1301 array_push( $script, 'rt-tpg' );
1302
1303 // Pro Scripts and Styles.
1304 if ( rtTPG()->hasPro() ) {
1305 if ( isset( $posts_loading_type ) && 'pagination_ajax' == $posts_loading_type ) {
1306 array_push( $script, 'rt-pagination' );
1307 }
1308
1309 if ( $layout == 'layout17' || 'popup' == $linkType ) {
1310 array_push( $style, 'rt-magnific-popup' );
1311 array_push( $script, 'rt-magnific-popup' );
1312 }
1313
1314 if ( 'popup' == $linkType ) {
1315 array_push( $script, 'rt-scrollbar' );
1316 }
1317
1318 if ( class_exists( 'WooCommerce' ) ) {
1319 array_push( $script, 'rt-jzoom' );
1320 }
1321 }
1322
1323 array_push( $style, 'rt-tpg-shortcode' );
1324
1325 if ( ( $isCarousel && rtTPG()->hasPro() ) || $isWooCom ) {
1326 array_push( $style, 'swiper' );
1327 array_push( $script, 'swiper' );
1328 }
1329
1330 if ( rtTPG()->hasPro() ) {
1331 array_push( $script, 'rt-tpg-pro' );
1332 }
1333
1334 if ( isset( $settings['tpg_load_script'] ) ) {
1335 wp_enqueue_style( $style );
1336 }
1337
1338 wp_enqueue_script( $script );
1339 } else {
1340 $html .= '<p>' . esc_html__( 'No shortCode found', 'the-post-grid' ) . '</p>';
1341 }
1342
1343 // restriction issue.
1344 $restriction = ( ! empty( $scMeta['restriction_user_role'] ) ? $scMeta['restriction_user_role'] : [] );
1345 if ( ! empty( $restriction ) ) {
1346 if ( is_user_logged_in() ) {
1347 $currentUserRoles = Fns::getCurrentUserRoles();
1348
1349 if ( in_array( 'administrator', $currentUserRoles ) ) {
1350 $html = $html;
1351 } else {
1352 if ( count( array_intersect( $restriction, $currentUserRoles ) ) ) {
1353 $html = $html;
1354 } else {
1355 $html = '<p>' . esc_html__(
1356 'You are not permitted to view this content.',
1357 'the-post-grid'
1358 ) . '</p>';
1359 }
1360 }
1361 } else {
1362 $html = '<p>' . esc_html__( 'This is a restricted content, you need to logged in to view this content.', 'the-post-grid' ) . '</p>';
1363 }
1364 }
1365
1366 return $html;
1367 }
1368
1369 }
1370