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