PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.0.2
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.0.2
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Controllers / ShortcodeController.php
the-post-grid / app / Controllers Last commit date
Admin 3 years ago Api 3 years ago Blocks 3 years ago Hooks 3 years ago AjaxController.php 3 years ago BlocksController.php 3 years ago ElementorController.php 3 years ago GutenBergController.php 3 years ago PageTemplateController.php 3 years ago ScriptController.php 3 years ago ShortcodeController.php 3 years ago WidgetController.php 3 years ago
ShortcodeController.php
1335 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 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
1053 $arg['postCount'] = $gridPostCount ++;
1054 $pID = get_the_ID();
1055 $arg['pID'] = $pID;
1056 $arg['title'] = Fns::get_the_title( $pID, $arg );
1057 $arg['pLink'] = 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 $arg['categories'] = Fns::rt_get_the_term_list( $pID, 'category', null, '<span class="rt-separator">,</span>' );
1070 $arg['tags'] = get_the_term_list( $pID, 'post_tag', null, '<span class="rt-separator">,</span>' );
1071 $arg['post_count'] = get_post_meta( $pID, Fns::get_post_view_count_meta_key(), true );
1072 $arg['responsiveCol'] = [ $dCol, $tCol, $mCol ];
1073
1074 if ( $isIsotope ) {
1075 $termAs = wp_get_post_terms( $pID, $isotope_filter, [ 'fields' => 'all' ] );
1076 $isoFilter = [];
1077
1078 if ( ! empty( $termAs ) ) {
1079 foreach ( $termAs as $term ) {
1080 $isoFilter[] = 'iso_' . $term->term_id;
1081 $isoFilter[] = 'rt-item-' . esc_attr( $term->slug );
1082 }
1083 }
1084
1085 $arg['isoFilter'] = ! empty( $isoFilter ) ? implode( ' ', $isoFilter ) : '';
1086 }
1087
1088 if ( comments_open() ) {
1089 $arg['comment'] = "<a href='" . get_comments_link( $pID ) . "'>{$comments_text} </a>";
1090 } else {
1091 $arg['comment'] = "{$comments_text}";
1092 }
1093
1094 $imgSrc = null;
1095
1096 // TODO: Image Thumbnail.
1097 $arg['smallImgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1098 $pID,
1099 $fSmallImgSize,
1100 $mediaSource,
1101 $defaultImgId,
1102 $customSmallImgSize,
1103 $is_lazy_load
1104 ) : null;
1105 if ( $isOffset ) {
1106 if ( $offLoop == 0 ) {
1107 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1108 $pID,
1109 $fImgSize,
1110 $mediaSource,
1111 $defaultImgId,
1112 $customImgSize
1113 ) : null;
1114 $arg['offset'] = 'big';
1115 $offsetBigHtml = Fns::get_template_html( 'layouts/' . $layout, $arg );
1116 } else {
1117 $arg['offset'] = 'small';
1118 $arg['offsetCol'] = [ $dCol, $tCol, $mCol ];
1119 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1120 $pID,
1121 'thumbnail',
1122 $mediaSource,
1123 $defaultImgId,
1124 $customImgSize
1125 ) : null;
1126 $offsetSmallHtml .= Fns::get_template_html( 'layouts/' . $layout, $arg );
1127 }
1128 } else {
1129 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1130 $pID,
1131 $fImgSize,
1132 $mediaSource,
1133 $defaultImgId,
1134 $customImgSize,
1135 $is_lazy_load
1136 ) : null;
1137 $html .= Fns::get_template_html( 'layouts/' . $layout, $arg );
1138 }
1139
1140 $offLoop ++;
1141 $l ++;
1142 endwhile;
1143
1144 if ( $isOffset ) {
1145 $oDCol = Fns::get_offset_col( $dCol );
1146 $oTCol = Fns::get_offset_col( $tCol );
1147 $oMCol = Fns::get_offset_col( $mCol );
1148
1149 if ( $layout == 'offset03' || $layout == 'offset04' ) {
1150 $oDCol['big'] = $oTCol['big'] = $oDCol['small'] = $oTCol['small'] = 6;
1151 $oMCol['big'] = $oMCol['small'] = 12;
1152 } else if ( $layout == 'offset06' ) {
1153 $oDCol['big'] = 7;
1154 $oDCol['small'] = 5;
1155 }
1156
1157 $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>";
1158 $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>";
1159 }
1160
1161 if ( $isIsotope || $isCarousel ) {
1162 $html .= '</div>'; // End isotope / Carousel item holder.
1163
1164 if ( $isIsotope ) {
1165 $html .= '<div class="isotope-term-no-post"><p>' . $not_found_text . '</p></div>';
1166 }
1167
1168 if ( $isCarousel ) {
1169 $html .= '</div>';
1170
1171 if ( in_array( 'pagination', $cOpt ) ) {
1172 $html .= '<div class="swiper-pagination"></div>';
1173 }
1174
1175 if ( in_array( 'nav_button', $cOpt ) ) {
1176 $html .= '<div class="swiper-navigation"><div class="slider-btn swiper-button-prev"></div><div class="slider-btn swiper-button-next"></div></div>';
1177 }
1178 }
1179 }
1180 } else {
1181 $html .= sprintf(
1182 '<p>%s</p>',
1183 apply_filters( 'tpg_not_found_text', $not_found_text, $args, $scMeta )
1184 );
1185 }
1186
1187 $html .= $preLoaderHtml;
1188 $html .= '</div>'; // End row.
1189 $htmlUtility = null;
1190
1191 if ( $pagination && ! $isCarousel ) {
1192 if ( $isOffset || $isGridHover ) {
1193 $posts_loading_type = 'page_prev_next';
1194 $htmlUtility .= "<div class='rt-cb-page-prev-next'>
1195 <span class='rt-cb-prev-btn'><i class='fa fa-angle-left' aria-hidden='true'></i></span>
1196 <span class='rt-cb-next-btn'><i class='fa fa-angle-right' aria-hidden='true'></i></span>
1197 </div>";
1198 } else {
1199 $hide = ( $gridQuery->max_num_pages < 2 ? ' rt-hidden-elm' : null );
1200 if ( $posts_loading_type == 'pagination' ) {
1201 if ( ( $isGrid || $isWooCom || $isEdd ) && empty( $filters ) ) {
1202 $htmlUtility .= Fns::rt_pagination(
1203 $gridQuery,
1204 $args['posts_per_page']
1205 );
1206 }
1207 } else if ( $posts_loading_type == 'pagination_ajax' && ! $isIsotope ) {
1208 $htmlUtility .= "<div class='rt-page-numbers'></div>";
1209 } else if ( $posts_loading_type == 'load_more' && rtTPG()->hasPro() ) {
1210 $load_more_btn_text = ( ! empty( $scMeta['load_more_text'][0] ) ? $scMeta['load_more_text'][0] : '' );
1211 $load_more_text = $load_more_btn_text ? esc_html( $load_more_btn_text ) : esc_html__( 'Load More', 'the-post-grid' );
1212
1213 $htmlUtility .= "<div class='rt-loadmore-btn rt-loadmore-action rt-loadmore-style{$hide}'>
1214 <span class='rt-loadmore-text'>" . $load_more_text . "</span>
1215 <div class='rt-loadmore-loading rt-ball-scale-multiple rt-2x'><div></div><div></div><div></div></div>
1216 </div>";
1217 } else if ( $posts_loading_type == 'load_on_scroll' && rtTPG()->hasPro() ) {
1218 $htmlUtility .= "<div class='rt-infinite-action'>
1219 <div class='rt-infinite-loading la-fire la-2x'>
1220 <div></div>
1221 <div></div>
1222 <div></div>
1223 </div>
1224 </div>";
1225 }
1226 }
1227 }
1228
1229 if ( $htmlUtility ) {
1230 $l4toggle = null;
1231 if ( $layout == 'layout4' ) {
1232 $l4toggle = "data-l4toggle='{$this->l4toggle}'";
1233 }
1234 $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>';
1235 }
1236
1237 $html .= '</div>'; // container rt-tpg.
1238
1239 wp_reset_postdata();
1240
1241 $scriptGenerator = [];
1242 $scriptGenerator['layout'] = $layoutID;
1243 $scriptGenerator['rand'] = $rand;
1244 $scriptGenerator['scMeta'] = $scMeta;
1245 $scriptGenerator['isCarousel'] = $isCarousel;
1246 $scriptGenerator['isSinglePopUp'] = $isSinglePopUp;
1247 $scriptGenerator['isWooCom'] = $isWooCom;
1248 $this->scA[] = $scriptGenerator;
1249
1250 add_action( 'wp_footer', [ $this, 'register_sc_scripts' ] );
1251
1252 // Script Load Conditionally
1253 $script = [];
1254 $style = [];
1255
1256 array_push( $script, 'jquery' );
1257 array_push( $style, 'rt-fontawsome' );
1258 array_push( $style, 'rt-flaticon' );
1259
1260 if ( 'masonry' == $gridType || $isIsotope ) {
1261 array_push( $script, 'rt-isotope-js' );
1262 }
1263
1264 array_push( $script, 'imagesloaded' );
1265 array_push( $script, 'rt-tpg' );
1266
1267 // Pro Scripts and Styles.
1268 if ( rtTPG()->hasPro() ) {
1269
1270 if ( isset( $posts_loading_type ) && 'pagination_ajax' == $posts_loading_type ) {
1271 array_push( $script, 'rt-pagination' );
1272 }
1273
1274 if ( $layout == 'layout17' || 'popup' == $linkType ) {
1275 array_push( $style, 'rt-magnific-popup' );
1276 array_push( $script, 'rt-magnific-popup' );
1277 }
1278
1279 if ( 'popup' == $linkType ) {
1280 array_push( $script, 'rt-scrollbar' );
1281 }
1282
1283 if ( class_exists( 'WooCommerce' ) ) {
1284 array_push( $script, 'rt-jzoom' );
1285 }
1286 }
1287
1288 array_push( $style, 'rt-tpg-shortcode' );
1289
1290 if ( ( $isCarousel && rtTPG()->hasPro() ) || $isWooCom ) {
1291 array_push( $style, 'swiper' );
1292 array_push( $script, 'swiper' );
1293 }
1294
1295 if ( rtTPG()->hasPro() ) {
1296 array_push( $script, 'rt-tpg-pro' );
1297 }
1298
1299 if ( isset( $settings['tpg_load_script'] ) ) {
1300 wp_enqueue_style( $style );
1301 }
1302
1303 wp_enqueue_script( $script );
1304
1305 } else {
1306 $html .= '<p>' . esc_html__( 'No shortCode found', 'the-post-grid' ) . '</p>';
1307 }
1308
1309 // restriction issue.
1310 $restriction = ( ! empty( $scMeta['restriction_user_role'] ) ? $scMeta['restriction_user_role'] : [] );
1311 if ( ! empty( $restriction ) ) {
1312 if ( is_user_logged_in() ) {
1313 $currentUserRoles = Fns::getCurrentUserRoles();
1314
1315 if ( in_array( 'administrator', $currentUserRoles ) ) {
1316 $html = $html;
1317 } else {
1318 if ( count( array_intersect( $restriction, $currentUserRoles ) ) ) {
1319 $html = $html;
1320 } else {
1321 $html = '<p>' . esc_html__(
1322 'You are not permitted to view this content.',
1323 'the-post-grid'
1324 ) . '</p>';
1325 }
1326 }
1327 } else {
1328 $html = '<p>' . esc_html__( 'This is a restricted content, you need to logged in to view this content.', 'the-post-grid' ) . '</p>';
1329 }
1330 }
1331
1332 return $html;
1333 }
1334 }
1335