PluginProbe
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.4.1
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.4.1
7.9.4 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 All 87 releases
the-post-grid / app / Controllers / ShortcodeController.php

ShortcodeController.php in The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid 7.4.1, at app/Controllers/ShortcodeController.php

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