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