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.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Controllers / ShortcodeController.php
the-post-grid / app / Controllers Last commit date
Admin 3 years ago Hooks 3 years ago AjaxController.php 3 years ago ElementorController.php 3 years ago GutenBergController.php 3 years ago ScriptController.php 3 years ago ShortcodeController.php 3 years ago WidgetController.php 3 years ago
ShortcodeController.php
1327 lines
1 <?php
2 /**
3 * Shortcode Controller class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers;
9
10 use RT\ThePostGrid\Helpers\Fns;
11 use RT\ThePostGrid\Helpers\Options;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Shortcode Controller class.
20 */
21 class ShortcodeController {
22 private $scA = [];
23 private $l4toggle = false;
24
25 public function __construct() {
26 add_shortcode( 'the-post-grid', [ $this, 'the_post_grid_short_code' ] );
27 add_action( 'pre_get_posts', [ $this, 'make_sticky_work' ] );
28 }
29
30 public function make_sticky_work( $q ) {
31 if ( true === $q->get( 'wp_tpg_is_home' ) ) {
32 $q->is_home = true;
33 }
34 }
35
36 public function register_sc_scripts() {
37 $settings = get_option( rtTPG()->options['settings'] );
38 $caro = $isSinglePopUp = false;
39 $ajaxurl = '';
40
41 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
42 $ajaxurl .= admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
43 } else {
44 $ajaxurl .= admin_url( 'admin-ajax.php' );
45 }
46
47 $variables = [
48 'nonceID' => esc_attr( rtTPG()->nonceId() ),
49 'nonce' => esc_attr( wp_create_nonce( rtTPG()->nonceText() ) ),
50 'ajaxurl' => esc_url( $ajaxurl ),
51 ];
52
53 foreach ( $this->scA as $sc ) {
54 if ( isset( $sc ) && is_array( $sc ) ) {
55 if ( $sc['isSinglePopUp'] ) {
56 $isSinglePopUp = true;
57 }
58
59 if ( $sc['isWooCom'] ) {
60 $variables['woocommerce_enable_ajax_add_to_cart'] = get_option( 'woocommerce_enable_ajax_add_to_cart' );
61 $variables['woocommerce_cart_redirect_after_add'] = get_option( 'woocommerce_cart_redirect_after_add' );
62 }
63 }
64 }
65 if ( count( $this->scA ) ) {
66 wp_localize_script( 'rt-tpg', 'rttpg', $variables );
67
68 do_action( 'tpg_after_script', $isSinglePopUp );
69 }
70
71 if ( $isSinglePopUp && rtTPG()->hasPro() ) {
72 $html = null;
73 $html .= '<div class="md-modal rt-md-effect" id="rt-modal">
74 <div class="md-content">
75 <div class="rt-md-content-holder">
76
77 </div>
78 <div class="md-cls-btn">
79 <button class="md-close"><i class="fa fa-times" aria-hidden="true"></i></button>
80 </div>
81 </div>
82 </div>';
83 $html .= "<div class='md-overlay'></div>";
84
85 Fns::print_html( $html );
86 }
87 }
88
89 public function the_post_grid_short_code( $atts, $content = null ) {
90 $rand = wp_rand();
91 $layoutID = 'rt-tpg-container-' . $rand;
92 $html = null;
93 $arg = [];
94 $atts = shortcode_atts(
95 [
96 'id' => null,
97 ],
98 $atts,
99 'the-post-grid'
100 );
101 $scID = $atts['id'];
102
103 if ( $scID && ! is_null( get_post( $scID ) ) ) {
104 $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 }
1327