PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / trunk
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid vtrunk
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Controllers / ShortcodeController.php
the-post-grid / app / Controllers Last commit date
Admin 1 month ago Api 1 month ago Blocks 2 months ago Hooks 1 month ago AjaxController.php 1 month ago BlocksController.php 1 month ago DiviController.php 1 year ago ElementorController.php 1 year ago GutenBergController.php 1 month ago PageTemplateController.php 2 years ago ScriptController.php 1 month ago ShortcodeController.php 5 months ago WidgetController.php 2 years ago
ShortcodeController.php
1369 lines
1 <?php
2 /**
3 * Shortcode Controller class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers;
9
10 use RT\ThePostGrid\Helpers\Fns;
11 use RT\ThePostGrid\Helpers\Options;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Shortcode Controller class.
20 */
21 class ShortcodeController {
22
23 private $scA = [];
24 private $l4toggle = false;
25
26 public function __construct() {
27 add_shortcode( 'the-post-grid', [ $this, 'the_post_grid_short_code' ] );
28 add_action( 'pre_get_posts', [ $this, 'make_sticky_work' ] );
29 }
30
31 public function make_sticky_work( $q ) {
32 if ( true === $q->get( 'wp_tpg_is_home' ) ) {
33 $q->is_home = true;
34 }
35 }
36
37 public function register_sc_scripts() {
38 $settings = get_option( rtTPG()->options['settings'] );
39 $caro = $isSinglePopUp = false;
40 $ajaxurl = '';
41
42 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
43 $ajaxurl .= admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
44 } else {
45 $ajaxurl .= admin_url( 'admin-ajax.php' );
46 }
47
48 $variables = [
49 'nonceID' => esc_attr( rtTPG()->nonceId() ),
50 'nonce' => esc_attr( wp_create_nonce( rtTPG()->nonceText() ) ),
51 'ajaxurl' => esc_url( $ajaxurl ),
52 'uid' => get_current_user_id(),
53 ];
54
55 foreach ( $this->scA as $sc ) {
56 if ( isset( $sc ) && is_array( $sc ) ) {
57 if ( $sc['isSinglePopUp'] ) {
58 $isSinglePopUp = true;
59 }
60
61 if ( $sc['isWooCom'] ) {
62 $variables['woocommerce_enable_ajax_add_to_cart'] = get_option( 'woocommerce_enable_ajax_add_to_cart' );
63 $variables['woocommerce_cart_redirect_after_add'] = get_option( 'woocommerce_cart_redirect_after_add' );
64 }
65 }
66 }
67 if ( count( $this->scA ) ) {
68 wp_localize_script( 'rt-tpg', 'rttpg', $variables );
69
70 do_action( 'tpg_after_script', $isSinglePopUp );
71 }
72
73 if ( $isSinglePopUp && rtTPG()->hasPro() ) {
74 $html = null;
75 $html .= '<div class="md-modal rt-md-effect" id="rt-modal">
76 <div class="md-content">
77 <div class="rt-md-content-holder">
78
79 </div>
80 <div class="md-cls-btn">
81 <button class="md-close"><i class="fa fa-times" aria-hidden="true"></i></button>
82 </div>
83 </div>
84 </div>';
85 $html .= "<div class='md-overlay'></div>";
86
87 Fns::print_html( $html );
88 }
89 }
90
91 public function the_post_grid_short_code( $atts, $content = null ) {
92 $rand = wp_rand();
93 $layoutID = 'rt-tpg-container-' . $rand;
94 $html = null;
95 $arg = [];
96 $atts = shortcode_atts(
97 [
98 'id' => null,
99 ],
100 $atts,
101 'the-post-grid'
102 );
103 $scID = $atts['id'];
104
105 if ( $scID && ! is_null( get_post( $scID ) ) ) {
106 $scMeta = get_post_meta( $scID );
107 $layout = ( isset( $scMeta['layout'][0] ) ? $scMeta['layout'][0] : 'layout1' );
108 $gridStyle = ( isset( $scMeta['grid_style'][0] ) ? $scMeta['grid_style'][0] : 'even' );
109
110 if ( ! in_array( $layout, array_keys( Options::rtTPGLayouts() ) ) ) {
111 $layout = 'layout1';
112 }
113
114 $isIsotope = preg_match( '/isotope/', $layout );
115 $isCarousel = preg_match( '/carousel/', $layout );
116 $isGrid = preg_match( '/layout/', $layout );
117 $isWooCom = preg_match( '/wc/', $layout );
118 $isEdd = preg_match( '/edd/', $layout );
119 $isOffset = preg_match( '/offset/', $layout );
120 $isGridHover = preg_match( '/grid_hover/', $layout );
121
122 $colStore = $dCol = ( isset( $scMeta['column'][0] ) ? absint( $scMeta['column'][0] ) : 3 );
123 $tCol = ( isset( $scMeta['tpg_tab_column'][0] ) ? absint( $scMeta['tpg_tab_column'][0] ) : 2 );
124 $mCol = ( isset( $scMeta['tpg_mobile_column'][0] ) ? absint( $scMeta['tpg_mobile_column'][0] ) : 1 );
125
126 if ( ! in_array( $dCol, array_keys( Options::scColumns() ) ) ) {
127 $dCol = 3;
128 }
129
130 if ( ! in_array( $tCol, array_keys( Options::scColumns() ) ) ) {
131 $tCol = 2;
132 }
133
134 if ( ! in_array( $dCol, array_keys( Options::scColumns() ) ) ) {
135 $mCol = 1;
136 }
137
138 if ( $isOffset ) {
139 $dCol = ( $dCol < 3 ? 2 : $dCol );
140 $tCol = ( $tCol < 3 ? 2 : $tCol );
141 $mCol = ( $mCol < 3 ? 1 : $mCol );
142 }
143
144 $arg = [];
145 $fImg = ( ! empty( $scMeta['feature_image'][0] ) ? true : false );
146 $fImgSize = ( isset( $scMeta['featured_image_size'][0] ) ? $scMeta['featured_image_size'][0] : 'medium' );
147 $mediaSource = ( isset( $scMeta['media_source'][0] ) ? $scMeta['media_source'][0] : 'feature_image' );
148 $arg['excerpt_type'] = ( isset( $scMeta['tgp_excerpt_type'][0] ) ? $scMeta['tgp_excerpt_type'][0] : 'character' );
149 $arg['title_limit_type'] = ( isset( $scMeta['tpg_title_limit_type'][0] ) ? $scMeta['tpg_title_limit_type'][0] : 'character' );
150 $arg['excerpt_limit'] = ( isset( $scMeta['excerpt_limit'][0] ) ? absint( $scMeta['excerpt_limit'][0] ) : 0 );
151 $arg['title_limit'] = ( isset( $scMeta['tpg_title_limit'][0] ) ? absint( $scMeta['tpg_title_limit'][0] ) : 0 );
152 $arg['excerpt_more_text'] = ( isset( $scMeta['tgp_excerpt_more_text'][0] ) ? $scMeta['tgp_excerpt_more_text'][0] : null );
153 $arg['read_more_text'] = ( ! empty( $scMeta['tgp_read_more_text'][0] ) ? $scMeta['tgp_read_more_text'][0] : esc_html__( 'Read More', 'the-post-grid' ) );
154 $arg['show_all_text'] = ( ! empty( $scMeta['tpg_show_all_text'][0] ) ? $scMeta['tpg_show_all_text'][0] : esc_html__( 'Show all', 'the-post-grid' ) );
155 $arg['tpg_title_position'] = isset( $scMeta['tpg_title_position'][0] ) && ! empty( $scMeta['tpg_title_position'][0] ) ? $scMeta['tpg_title_position'][0] : null;
156 $arg['btn_alignment_class'] = isset( $scMeta['tpg_read_more_button_alignment'][0] ) && ! empty( $scMeta['tpg_read_more_button_alignment'][0] )
157 ? $scMeta['tpg_read_more_button_alignment'][0] : '';
158 // Category Settings.
159 $arg['category_position'] = isset( $scMeta['tpg_category_position'][0] ) ? $scMeta['tpg_category_position'][0] : null;
160 $arg['category_style'] = ! empty( $scMeta['tpg_category_style'][0] ) ? $scMeta['tpg_category_style'][0] : '';
161 $arg['catIcon'] = isset( $scMeta['tpg_category_icon'][0] ) ? $scMeta['tpg_category_icon'][0] : true;
162 // Meta Settings.
163 $arg['metaPosition'] = isset( $scMeta['tpg_meta_position'][0] ) ? $scMeta['tpg_meta_position'][0] : null;
164 $arg['metaIcon'] = isset( $scMeta['tpg_meta_icon'][0] ) ? $scMeta['tpg_meta_icon'][0] : true;
165 $arg['metaSeparator'] = ! empty( $scMeta['tpg_meta_separator'][0] ) ? $scMeta['tpg_meta_separator'][0] : '';
166 /* Argument create */
167 $args = [];
168 $postType = ( isset( $scMeta['tpg_post_type'][0] ) ? $scMeta['tpg_post_type'][0] : 'post' );
169
170 if ( $postType ) {
171 $args['post_type'] = Fns::available_post_type( $postType );
172 }
173
174 // Common filters.
175 /* post__in */
176 $post__in = ( isset( $scMeta['post__in'][0] ) ? $scMeta['post__in'][0] : null );
177
178 if ( $post__in ) {
179 $post__in = explode( ',', $post__in );
180 $args['post__in'] = $post__in;
181 }
182
183 /* post__not_in */
184 $post__not_in = ( isset( $scMeta['post__not_in'][0] ) ? $scMeta['post__not_in'][0] : null ); //phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in
185
186 if ( $post__not_in ) {
187 $post__not_in = explode( ',', $post__not_in );
188 $args['post__not_in'] = $post__not_in; //phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in
189 }
190
191 /* LIMIT */
192 $limit = ( ( empty( $scMeta['limit'][0] ) || $scMeta['limit'][0] === '-1' ) ? - 1 : absint( $scMeta['limit'][0] ) );
193 $queryOffset = empty( $scMeta['offset'][0] ) ? 0 : absint( $scMeta['offset'][0] );
194 $args['posts_per_page'] = $limit;
195 $pagination = ! empty( $scMeta['pagination'][0] );
196 $posts_loading_type = ( ! empty( $scMeta['posts_loading_type'][0] ) ? $scMeta['posts_loading_type'][0] : 'pagination' );
197
198 if ( ! $isCarousel ) {
199 $posts_per_page = ( isset( $scMeta['posts_per_page'][0] ) ? intval( $scMeta['posts_per_page'][0] ) : $limit );
200 $args['posts_per_page'] = $posts_per_page;
201 }
202
203 if ( $isIsotope && ! $pagination ) {
204 $args['posts_per_page'] = $limit;
205 }
206
207 if ( empty( $posts_per_page ) || ( $posts_per_page == '-1' && $limit ) ) {
208 $args['posts_per_page'] = $limit;
209 }
210
211 if ( $pagination && ! $isCarousel ) {
212 $args['paged'] = get_query_var( 'page' ) ? get_query_var( 'page' ) : ( get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1 );
213 }
214
215 // Advanced Filters.
216 $adv_filter = get_post_meta( $scID, 'post_filter' );
217 $taxFilter = get_post_meta( $scID, 'tgp_filter_taxonomy', true );
218 $taxHierarchical = get_post_meta( $scID, 'tgp_filter_taxonomy_hierarchical', true );
219 $taxFilterTerms = [];
220 $taxFilterOperator = 'IN';
221 // Taxonomy.
222 $taxQ = [];
223
224 if ( in_array( 'tpg_taxonomy', $adv_filter ) && isset( $scMeta['tpg_taxonomy'] ) ) {
225 if ( is_array( $scMeta['tpg_taxonomy'] ) && ! empty( $scMeta['tpg_taxonomy'] ) ) {
226 foreach ( $scMeta['tpg_taxonomy'] as $taxonomy ) {
227 $terms = ( isset( $scMeta[ 'term_' . $taxonomy ] ) ? $scMeta[ 'term_' . $taxonomy ] : [] );
228
229 if ( is_array( $terms ) && ! empty( $terms ) ) {
230 $operator = ( isset( $scMeta[ 'term_operator_' . $taxonomy ][0] ) ? $scMeta[ 'term_operator_' . $taxonomy ][0] : 'IN' );
231 $taxQ[] = [
232 'taxonomy' => $taxonomy,
233 'field' => 'term_id',
234 'terms' => $terms,
235 'operator' => $operator,
236 ];
237
238 if ( $taxonomy == $taxFilter ) {
239 $taxFilterOperator = $operator;
240 }
241 }
242
243 if ( $taxonomy == $taxFilter ) {
244 $taxFilterTerms = $terms;
245 }
246 }
247 }
248
249 if ( count( $taxQ ) >= 2 ) {
250 $relation = ( isset( $scMeta['taxonomy_relation'][0] ) ? $scMeta['taxonomy_relation'][0] : 'AND' );
251 $taxQ['relation'] = $relation;
252 }
253 }
254
255 if ( ! empty( $taxQ ) ) {
256 $args['tax_query'] = $taxQ; //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
257 }
258
259 // Order.
260 if ( in_array( 'order', $adv_filter ) ) {
261 $order_by = ( isset( $scMeta['order_by'][0] ) ? $scMeta['order_by'][0] : null );
262 $order = ( isset( $scMeta['order'][0] ) ? $scMeta['order'][0] : null );
263
264 if ( $order ) {
265 $args['order'] = $order;
266 }
267
268 if ( $order_by ) {
269 $args['orderby'] = $order_by;
270 $meta_key = ! empty( $scMeta['tpg_meta_key'][0] ) ? trim( $scMeta['tpg_meta_key'][0] ) : null;
271
272 if ( in_array( $order_by, array_keys( Options::rtMetaKeyType() ) ) && $meta_key ) {
273 $args['orderby'] = $order_by;
274 $args['meta_key'] = $meta_key; //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
275
276 if ( $order_by === 'meta_value_datetime' ) {
277 $args['orderby'] = 'meta_value_num';
278 }
279 }
280 }
281 }
282
283 // The below code should remove later
284 /*if ( in_array( 'tpg_post_status', $adv_filter ) ) {
285 $post_status = ( isset( $scMeta['tpg_post_status'] ) ? $scMeta['tpg_post_status'] : [] );
286
287 if ( ! empty( $post_status ) ) {
288 $args['post_status'] = $post_status;
289 }
290 } else {
291 $args['post_status'] = 'publish';
292 }*/
293
294 $args['post_status'] = 'publish';
295
296 // Author.
297 $author = ( isset( $scMeta['author'] ) ? $scMeta['author'] : [] );
298 $filterAuthors = [];
299
300 if ( in_array( 'author', $adv_filter ) && ! empty( $author ) ) {
301 $filterAuthors = $args['author__in'] = $author;
302 }
303
304 // Search.
305 $s = ( isset( $scMeta['s'][0] ) ? $scMeta['s'][0] : [] );
306 if ( in_array( 's', $adv_filter ) && ! empty( $s ) ) {
307 $args['s'] = $s;
308 }
309
310 // Date query.
311 if ( in_array( 'date_range', $adv_filter ) ) {
312 $startDate = ( ! empty( $scMeta['date_range_start'][0] ) ? $scMeta['date_range_start'][0] : null );
313 $endDate = ( ! empty( $scMeta['date_range_end'][0] ) ? $scMeta['date_range_end'][0] : null );
314
315 if ( $startDate && $endDate ) {
316 $args['date_query'] = [
317 [
318 'after' => $startDate,
319 'before' => $endDate,
320 'inclusive' => true,
321 ],
322 ];
323 }
324 }
325
326 $settings = get_option( rtTPG()->options['settings'] );
327 $oLayoutTag = ! empty( $settings['template_tag'] ) ? absint( $settings['template_tag'] ) : null;
328 $oLayoutAuthor = ! empty( $settings['template_author'] ) ? $settings['template_author'] : null;
329 $oLayoutCategory = ! empty( $settings['template_category'] ) ? $settings['template_category'] : null;
330 $oLayoutSearch = ! empty( $settings['template_search'] ) ? $settings['template_search'] : null;
331 $dataArchive = null;
332
333 if ( ( is_category() && $oLayoutCategory ) || ( is_search() && $oLayoutSearch ) || ( is_tag() && $oLayoutTag ) || ( is_author() && $oLayoutAuthor ) ) {
334 unset( $args['post_type'] );
335 unset( $args['tax_query'] );
336 unset( $args['author__in'] );
337 $obj = get_queried_object();
338 $aType = $aValue = null;
339
340 if ( $oLayoutTag && is_tag() ) {
341 if ( ! empty( $obj->slug ) ) {
342 $aValue = $args['tag'] = $obj->slug;
343 $aType = 'tag';
344 }
345 } elseif ( $oLayoutCategory && is_category() ) {
346 if ( ! empty( $obj->slug ) ) {
347 $aValue = $args['category_name'] = $obj->slug;
348 }
349 $aType = 'category';
350 } elseif ( $oLayoutAuthor && is_author() ) {
351 $aValue = $args['author'] = $obj->ID;
352 $aType = 'author';
353 } elseif ( $oLayoutSearch && is_search() ) {
354 $aValue = $args['s'] = get_search_query();
355 $aType = 'search';
356 }
357
358 $dataArchive = " data-archive='{$aType}' data-archive-value='{$aValue}'";
359 $args['posts_per_archive_page'] = $args['posts_per_page'];
360 }
361
362 // Validation.
363 $containerDataAttr = null;
364 $containerDataAttr .= " data-layout='{$layout}' data-grid-style='{$gridStyle}' data-desktop-col='{$dCol}' data-tab-col='{$tCol}' data-mobile-col='{$mCol}'";
365
366 $dCol = $dCol == 5 ? '24' : round( 12 / $dCol );
367 $tCol = $dCol == 5 ? '24' : round( 12 / $tCol );
368 $mCol = $dCol == 5 ? '24' : round( 12 / $mCol );
369
370 if ( $isCarousel ) {
371 $dCol = $tCol = $mCol = 12;
372 }
373
374 $arg['grid'] = "rt-col-md-{$dCol} rt-col-sm-{$tCol} rt-col-xs-{$mCol}";
375
376 if ( $layout == 'layout2' || $layout == 'layout3' ) {
377 $iCol = ( isset( $scMeta['tgp_layout2_image_column'][0] ) ? absint( $scMeta['tgp_layout2_image_column'][0] ) : 4 );
378 $iCol = $iCol > 12 ? 4 : $iCol;
379 $cCol = 12 - $iCol;
380 $arg['image_area'] = "rt-col-sm-{$iCol} rt-col-xs-12 ";
381 $arg['content_area'] = "rt-col-sm-{$cCol} rt-col-xs-12 ";
382 } elseif ( $layout == 'layout4' ) {
383 $arg['image_area'] = 'rt-col-md-6 rt-col-sm-12 rt-col-xs-12 ';
384 $arg['content_area'] = 'rt-col-md-6 rt-col-sm-12 rt-col-xs-12 ';
385 }
386
387 $arg_class = [];
388 $gridType = ! empty( $scMeta['grid_style'][0] ) ? $scMeta['grid_style'][0] : 'even';
389
390 if ( $isIsotope && ! rtTPG()->hasPro() ) {
391 $arg_class[] = 'masonry-grid-item';
392 } elseif ( ! $isCarousel && ! $isOffset ) {
393 $arg_class[] = $gridType . '-grid-item';
394 }
395
396 $arg_class[] = 'rt-grid-item';
397
398 if ( $isOffset ) {
399 $arg_class[] = 'rt-offset-item';
400 }
401
402 // Category class.
403 $catHaveBg = ( isset( $scMeta['tpg_category_bg'][0] ) ? $scMeta['tpg_category_bg'][0] : '' );
404
405 if ( ! empty( $catHaveBg ) ) {
406 $arg_class[] = 'category-have-bg';
407 }
408
409 // Image animation type.
410 $imgAnimationType = isset( $scMeta['tpg_image_animation'][0] ) ? $scMeta['tpg_image_animation'][0] : '';
411
412 if ( ! empty( $imgAnimationType ) ) {
413 $arg_class[] = $imgAnimationType;
414 }
415
416 $masonryG = null;
417
418 if ( $gridType == 'even' && ! $isIsotope && ! $isCarousel ) {
419 $masonryG = ' tpg-even';
420 } elseif ( $gridType == 'masonry' && ! $isIsotope && ! $isCarousel ) {
421 $masonryG = ' tpg-masonry';
422 }
423
424 $preLoader = $preLoaderHtml = null;
425
426 if ( $isIsotope ) {
427 $arg_class[] = 'isotope-item';
428 $preLoader = 'tpg-pre-loader';
429 }
430
431 if ( $isCarousel ) {
432 $arg_class[] = 'swiper-slide';
433 $preLoader = 'tpg-pre-loader';
434 }
435
436 if ( $preLoader && rtTPG()->hasPro() ) {
437 $preLoaderHtml = '<div class="rt-loading-overlay"></div><div class="rt-loading rt-ball-clip-rotate"><div></div></div>';
438 }
439
440 $margin = ! empty( $scMeta['margin_option'][0] ) ? $scMeta['margin_option'][0] : 'default';
441
442 if ( $margin == 'no' ) {
443 $arg_class[] = 'no-margin';
444 }
445
446 if ( ! empty( $scMeta['tpg_image_type'][0] ) && $scMeta['tpg_image_type'][0] == 'circle' ) {
447 $arg_class[] = 'tpg-img-circle';
448 }
449
450 $arg['class'] = implode( ' ', $arg_class );
451 $arg['anchorClass'] = $arg['link_target'] = null;
452 $link = isset( $scMeta['link_to_detail_page'][0] ) ? $scMeta['link_to_detail_page'][0] : '1';
453 $link = ( $link == 'yes' ) ? '1' : $link;
454
455 if ( ! $link ) {
456 $arg['anchorClass'] = ' disabled';
457 }
458
459 $isSinglePopUp = false;
460 $linkType = ! empty( $scMeta['detail_page_link_type'][0] ) ? $scMeta['detail_page_link_type'][0] : 'popup';
461
462 if ( $link == '1' ) {
463 if ( $linkType == 'popup' && rtTPG()->hasPro() ) {
464 $popupType = ! empty( $scMeta['popup_type'][0] ) ? $scMeta['popup_type'][0] : 'single';
465
466 if ( $popupType == 'single' ) {
467 $arg['anchorClass'] .= ' tpg-single-popup';
468 $isSinglePopUp = true;
469 } else {
470 $arg['anchorClass'] .= ' tpg-multi-popup';
471 }
472 } else {
473 $arg['link_target'] = ! empty( $scMeta['link_target'][0] ) ? " target='{$scMeta['link_target'][0]}'" : null;
474 }
475 }
476
477 $parentClass = ( ! empty( $scMeta['parent_class'][0] ) ? trim( $scMeta['parent_class'][0] ) : null );
478 $defaultImgId = ( ! empty( $scMeta['default_preview_image'][0] ) ? absint( $scMeta['default_preview_image'][0] ) : null );
479 $customImgSize = ( ! empty( $scMeta['custom_image_size'] ) ? $scMeta['custom_image_size'] : [] );
480 // Grid Hover Layout.
481 $fSmallImgSize = ( isset( $scMeta['featured_small_image_size'][0] ) ? $scMeta['featured_small_image_size'][0] : 'medium' );
482 $customSmallImgSize = ( ! empty( $scMeta['custom_small_image_size'] ) ? $scMeta['custom_small_image_size'] : [] );
483
484 $arg['scID'] = $scID;
485 $arg['items'] = isset( $scMeta['item_fields'] ) ? ( $scMeta['item_fields'] ? $scMeta['item_fields'] : [] ) : [];
486
487 if ( in_array( 'cf', $arg['items'] ) ) {
488 $arg['cf_group'] = [];
489 $arg['cf_group'] = get_post_meta( $scID, 'cf_group' );
490 $arg['format'] = [
491 'hide_empty' => get_post_meta( $scID, 'cf_hide_empty_value', true ),
492 'show_value' => get_post_meta( $scID, 'cf_show_only_value', true ),
493 'hide_group_title' => get_post_meta( $scID, 'cf_hide_group_title', true ),
494 ];
495 }
496
497 // Set readmore false if excerpt type = full content.
498 if ( isset( $arg['excerpt_type'] ) && $arg['excerpt_type'] === 'full' && ( $key = array_search( 'read_more', $arg['items'] ) ) !== false ) {
499 unset( $arg['items'][ $key ] );
500 }
501
502 if ( ! empty( $scMeta['ignore_sticky_posts'][0] ) && 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 }
1369