PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 4.2.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v4.2.0
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
1320 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 if ( $order ) {
251 $args['order'] = $order;
252 }
253
254 if ( $order_by ) {
255 $args['orderby'] = $order_by;
256 $meta_key = ! empty( $scMeta['tpg_meta_key'][0] ) ? trim( $scMeta['tpg_meta_key'][0] ) : null;
257
258 if ( in_array( $order_by, array_keys( Options::rtMetaKeyType() ) ) && $meta_key ) {
259 $args['orderby'] = $order_by;
260 $args['meta_key'] = $meta_key;
261 }
262 }
263 }
264
265 // Status.
266 if ( in_array( 'tpg_post_status', $adv_filter ) ) {
267 $post_status = ( isset( $scMeta['tpg_post_status'] ) ? $scMeta['tpg_post_status'] : [] );
268
269 if ( ! empty( $post_status ) ) {
270 $args['post_status'] = $post_status;
271 }
272 } else {
273 $args['post_status'] = 'publish';
274 }
275
276 // Author.
277 $author = ( isset( $scMeta['author'] ) ? $scMeta['author'] : [] );
278 $filterAuthors = [];
279
280 if ( in_array( 'author', $adv_filter ) && ! empty( $author ) ) {
281 $filterAuthors = $args['author__in'] = $author;
282 }
283
284 // Search.
285 $s = ( isset( $scMeta['s'][0] ) ? $scMeta['s'][0] : [] );
286 if ( in_array( 's', $adv_filter ) && ! empty( $s ) ) {
287 $args['s'] = $s;
288 }
289
290 // Date query.
291 if ( in_array( 'date_range', $adv_filter ) ) {
292 $startDate = ( ! empty( $scMeta['date_range_start'][0] ) ? $scMeta['date_range_start'][0] : null );
293 $endDate = ( ! empty( $scMeta['date_range_end'][0] ) ? $scMeta['date_range_end'][0] : null );
294
295 if ( $startDate && $endDate ) {
296 $args['date_query'] = [
297 [
298 'after' => $startDate,
299 'before' => $endDate,
300 'inclusive' => true,
301 ],
302 ];
303 }
304 }
305
306 $settings = get_option( rtTPG()->options['settings'] );
307 $oLayoutTag = ! empty( $settings['template_tag'] ) ? absint( $settings['template_tag'] ) : null;
308 $oLayoutAuthor = ! empty( $settings['template_author'] ) ? $settings['template_author'] : null;
309 $oLayoutCategory = ! empty( $settings['template_category'] ) ? $settings['template_category'] : null;
310 $oLayoutSearch = ! empty( $settings['template_search'] ) ? $settings['template_search'] : null;
311 $dataArchive = null;
312
313 if ( ( is_category() && $oLayoutCategory ) || ( is_search() && $oLayoutSearch ) || ( is_tag() && $oLayoutTag ) || ( is_author() && $oLayoutAuthor ) ) {
314 unset( $args['post_type'] );
315 unset( $args['tax_query'] );
316 unset( $args['author__in'] );
317 $obj = get_queried_object();
318 $aType = $aValue = null;
319
320 if ( $oLayoutTag && is_tag() ) {
321 if ( ! empty( $obj->slug ) ) {
322 $aValue = $args['tag'] = $obj->slug;
323 $aType = 'tag';
324 }
325 } elseif ( $oLayoutCategory && is_category() ) {
326 if ( ! empty( $obj->slug ) ) {
327 $aValue = $args['category_name'] = $obj->slug;
328 }
329 $aType = 'category';
330 } elseif ( $oLayoutAuthor && is_author() ) {
331 $aValue = $args['author'] = $obj->ID;
332 $aType = 'author';
333 } elseif ( $oLayoutSearch && is_search() ) {
334 $aValue = $args['s'] = get_search_query();
335 $aType = 'search';
336 }
337
338 $dataArchive = " data-archive='{$aType}' data-archive-value='{$aValue}'";
339 $args['posts_per_archive_page'] = $args['posts_per_page'];
340 }
341
342 // Validation.
343 $containerDataAttr = null;
344 $containerDataAttr .= " data-layout='{$layout}' data-grid-style='{$gridStyle}' data-desktop-col='{$dCol}' data-tab-col='{$tCol}' data-mobile-col='{$mCol}'";
345
346 $dCol = $dCol == 5 ? '24' : round( 12 / $dCol );
347 $tCol = $dCol == 5 ? '24' : round( 12 / $tCol );
348 $mCol = $dCol == 5 ? '24' : round( 12 / $mCol );
349
350 if ( $isCarousel ) {
351 $dCol = $tCol = $mCol = 12;
352 }
353
354 $arg['grid'] = "rt-col-md-{$dCol} rt-col-sm-{$tCol} rt-col-xs-{$mCol}";
355
356 if ( $layout == 'layout2' || $layout == 'layout3' ) {
357 $iCol = ( isset( $scMeta['tgp_layout2_image_column'][0] ) ? absint( $scMeta['tgp_layout2_image_column'][0] ) : 4 );
358 $iCol = $iCol > 12 ? 4 : $iCol;
359 $cCol = 12 - $iCol;
360 $arg['image_area'] = "rt-col-sm-{$iCol} rt-col-xs-12 ";
361 $arg['content_area'] = "rt-col-sm-{$cCol} rt-col-xs-12 ";
362 } elseif ( $layout == 'layout4' ) {
363 $arg['image_area'] = 'rt-col-md-6 rt-col-sm-12 rt-col-xs-12 ';
364 $arg['content_area'] = 'rt-col-md-6 rt-col-sm-12 rt-col-xs-12 ';
365 }
366
367 $arg_class = [];
368 $gridType = ! empty( $scMeta['grid_style'][0] ) ? $scMeta['grid_style'][0] : 'even';
369
370 if ( $isIsotope && ! rtTPG()->hasPro() ) {
371 $arg_class[] = 'masonry-grid-item';
372 } elseif ( ! $isCarousel && ! $isOffset ) {
373 $arg_class[] = $gridType . '-grid-item';
374 }
375
376 $arg_class[] = 'rt-grid-item';
377
378 if ( $isOffset ) {
379 $arg_class[] = 'rt-offset-item';
380 }
381
382 // Category class.
383 $catHaveBg = ( isset( $scMeta['tpg_category_bg'][0] ) ? $scMeta['tpg_category_bg'][0] : '' );
384
385 if ( ! empty( $catHaveBg ) ) {
386 $arg_class[] = 'category-have-bg';
387 }
388
389 // Image animation type.
390 $imgAnimationType = isset( $scMeta['tpg_image_animation'][0] ) ? $scMeta['tpg_image_animation'][0] : '';
391
392 if ( ! empty( $imgAnimationType ) ) {
393 $arg_class[] = $imgAnimationType;
394 }
395
396 $masonryG = null;
397
398 if ( $gridType == 'even' && ! $isIsotope && ! $isCarousel ) {
399 $masonryG = ' tpg-even';
400 } elseif ( $gridType == 'masonry' && ! $isIsotope && ! $isCarousel ) {
401 $masonryG = ' tpg-masonry';
402 }
403
404 $preLoader = $preLoaderHtml = null;
405
406 if ( $isIsotope ) {
407 $arg_class[] = 'isotope-item';
408 $preLoader = 'tpg-pre-loader';
409 }
410
411 if ( $isCarousel ) {
412 $arg_class[] = 'swiper-slide';
413 $preLoader = 'tpg-pre-loader';
414 }
415
416 if ( $preLoader && rtTPG()->hasPro() ) {
417 $preLoaderHtml = '<div class="rt-loading-overlay"></div><div class="rt-loading rt-ball-clip-rotate"><div></div></div>';
418 }
419
420 $margin = ! empty( $scMeta['margin_option'][0] ) ? $scMeta['margin_option'][0] : 'default';
421
422 if ( $margin == 'no' ) {
423 $arg_class[] = 'no-margin';
424 }
425
426 if ( ! empty( $scMeta['tpg_image_type'][0] ) && $scMeta['tpg_image_type'][0] == 'circle' ) {
427 $arg_class[] = 'tpg-img-circle';
428 }
429
430 $arg['class'] = implode( ' ', $arg_class );
431 $arg['anchorClass'] = $arg['link_target'] = null;
432 $link = isset( $scMeta['link_to_detail_page'][0] ) ? $scMeta['link_to_detail_page'][0] : '1';
433 $link = ( $link == 'yes' ) ? '1' : $link;
434
435 if ( ! $link ) {
436 $arg['anchorClass'] = ' disabled';
437 }
438
439 $isSinglePopUp = false;
440 $linkType = ! empty( $scMeta['detail_page_link_type'][0] ) ? $scMeta['detail_page_link_type'][0] : 'popup';
441
442 if ( $link == '1' ) {
443 if ( $linkType == 'popup' && rtTPG()->hasPro() ) {
444 $popupType = ! empty( $scMeta['popup_type'][0] ) ? $scMeta['popup_type'][0] : 'single';
445
446 if ( $popupType == 'single' ) {
447 $arg['anchorClass'] .= ' tpg-single-popup';
448 $isSinglePopUp = true;
449 } else {
450 $arg['anchorClass'] .= ' tpg-multi-popup';
451 }
452 } else {
453 $arg['link_target'] = ! empty( $scMeta['link_target'][0] ) ? " target='{$scMeta['link_target'][0]}'" : null;
454 }
455 }
456
457 $parentClass = ( ! empty( $scMeta['parent_class'][0] ) ? trim( $scMeta['parent_class'][0] ) : null );
458 $defaultImgId = ( ! empty( $scMeta['default_preview_image'][0] ) ? absint( $scMeta['default_preview_image'][0] ) : null );
459 $customImgSize = ( ! empty( $scMeta['custom_image_size'] ) ? $scMeta['custom_image_size'] : [] );
460 // Grid Hover Layout.
461 $fSmallImgSize = ( isset( $scMeta['featured_small_image_size'][0] ) ? $scMeta['featured_small_image_size'][0] : 'medium' );
462 $customSmallImgSize = ( ! empty( $scMeta['custom_small_image_size'] ) ? $scMeta['custom_small_image_size'] : [] );
463
464 $arg['scID'] = $scID;
465 $arg['items'] = isset( $scMeta['item_fields'] ) ? ( $scMeta['item_fields'] ? $scMeta['item_fields'] : [] ) : [];
466
467 if ( in_array( 'cf', $arg['items'] ) ) {
468 $arg['cf_group'] = [];
469 $arg['cf_group'] = get_post_meta( $scID, 'cf_group' );
470 $arg['format'] = [
471 'hide_empty' => get_post_meta( $scID, 'cf_hide_empty_value', true ),
472 'show_value' => get_post_meta( $scID, 'cf_show_only_value', true ),
473 'hide_group_title' => get_post_meta( $scID, 'cf_hide_group_title', true ),
474 ];
475 }
476
477 // Set readmore false if excerpt type = full content.
478 if ( isset( $arg['excerpt_type'] ) && $arg['excerpt_type'] === 'full' && ( $key = array_search( 'read_more', $arg['items'] ) ) !== false ) {
479 unset( $arg['items'][ $key ] );
480 }
481
482 if ( empty( $scMeta['ignore_sticky_posts'][0] ) ) {
483 $args['ignore_sticky_posts'] = true;
484 } else {
485 $args['wp_tpg_is_home'] = true;
486 }
487
488 $filters = ! empty( $scMeta['tgp_filter'] ) ? $scMeta['tgp_filter'] : [];
489 $action_term = ! empty( $scMeta['tgp_default_filter'][0] ) ? absint( $scMeta['tgp_default_filter'][0] ) : 0;
490 $hide_all_button = ! empty( $scMeta['tpg_hide_all_button'][0] ) ? true : false;
491
492 if ( $taxHierarchical ) {
493 $terms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, 0 );
494 } else {
495 $terms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true );
496 }
497
498 if ( $hide_all_button && ! $action_term ) {
499 if ( ! empty( $terms ) ) {
500 $allKeys = array_keys( $terms );
501 $action_term = $allKeys[0];
502 }
503 }
504
505 if ( in_array( '_taxonomy_filter', $filters ) && $taxFilter && $action_term ) {
506 $args['tax_query'] = [
507 [
508 'taxonomy' => $taxFilter,
509 'field' => 'term_id',
510 'terms' => [ $action_term ],
511 ],
512 ];
513 }
514
515 if ( $limit != - 1 && $pagination ) {
516 $tempArgs = $args;
517 $tempArgs['posts_per_page'] = $limit;
518 $tempArgs['paged'] = 1;
519 $tempArgs['fields'] = 'ids';
520 $tempQ = new \WP_Query( $tempArgs );
521
522 if ( ! empty( $tempQ->posts ) ) {
523 $args['post__in'] = $tempQ->posts;
524 }
525 }
526
527 if ( $pagination && $queryOffset && isset( $args['paged'] ) ) {
528 $queryOffset = ( $posts_per_page * ( $args['paged'] - 1 ) ) + $queryOffset;
529 }
530
531 if ( $queryOffset ) {
532 $args['offset'] = $queryOffset;
533 }
534
535 $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';
536
537 $gridQuery = new \WP_Query( apply_filters( 'tpg_sc_query_args', $args, $scMeta ) );
538
539 // Start layout.
540 $html .= Fns::layoutStyle( $layoutID, $scMeta, $layout, $scID );
541 $containerDataAttr .= " data-sc-id='{$scID}'";
542
543 if ( isset( $settings['tpg_load_script'] ) ) {
544 $parentClass .= ' loading';
545 }
546
547 $carousel_nav = ! empty( $scMeta['carousel_property'] ) ? $scMeta['carousel_property'] : [];
548 $is_nav = in_array( 'nav_button', $carousel_nav );
549
550 if ( $isCarousel ) {
551 $parentClass .= ' tpg-carousel-main';
552
553 if ( $is_nav ) {
554 $parentClass .= ' tpg-has-nav';
555 }
556
557 $cOptMeta = ! empty( $scMeta['carousel_property'] ) ? $scMeta['carousel_property'] : [];
558
559 if ( in_array( 'lazy_load', $cOptMeta ) ) {
560 $parentClass .= ' is-lazy-load-yes';
561 }
562
563 if ( in_array( 'auto_height', $cOptMeta ) ) {
564 $parentClass .= ' is-auto-height-yes';
565 }
566 }
567
568 $html .= "<div class='rt-container-fluid rt-tpg-container tpg-shortcode-main-wrapper {$parentClass}' id='{$layoutID}' {$dataArchive} {$containerDataAttr}>";
569
570 // widget heading.
571 $heading_tag = isset( $scMeta['tpg_heading_tag'][0] ) ? $scMeta['tpg_heading_tag'][0] : 'h2';
572 $heading_style = isset( $scMeta['tpg_heading_style'][0] ) && ! empty( $scMeta['tpg_heading_style'][0] ) ? $scMeta['tpg_heading_style'][0] : 'style1';
573 $heading_alignment = isset( $scMeta['tpg_heading_alignment'][0] ) ? $scMeta['tpg_heading_alignment'][0] : '';
574 $heading_link = isset( $scMeta['tpg_heading_link'][0] ) ? $scMeta['tpg_heading_link'][0] : '';
575
576 if ( ! empty( $arg['items'] ) && in_array( 'heading', $arg['items'] ) ) {
577 $html .= sprintf( '<div class="tpg-widget-heading-wrapper heading-%1$s %2$s">', $heading_style, $heading_alignment );
578 $html .= '<span class="tpg-widget-heading-line line-left"></span>';
579
580 if ( $heading_link ) {
581 $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() );
582 } else {
583 $html .= sprintf( '<%1$s class="tpg-widget-heading">%2$s</%1$s>', $heading_tag, get_the_title( $scID ) );
584 }
585
586 $html .= '<span class="tpg-widget-heading-line"></span>';
587 $html .= '</div>';
588 }
589
590 if ( ! $isCarousel && isset( $settings['tpg_enable_preloader'] ) ) {
591 $html .= '<div id="bottom-script-loader" class="bottom-script-loader"><div class="rt-ball-clip-rotate"><div></div></div></div>';
592 }
593
594 if ( ! empty( $filters ) && ( $isGrid || $isOffset || $isWooCom || $isEdd ) ) {
595 $html .= "<div class='rt-layout-filter-container rt-clear'><div class='rt-filter-wrap'>";
596 $selectedSubTermsForButton = null;
597 $allText = apply_filters( 'tpg_filter_all_text', esc_html__( 'All', 'the-post-grid' ), $scMeta );
598
599 if ( in_array( '_taxonomy_filter', $filters ) && $taxFilter ) {
600 $filterType = ( ! empty( $scMeta['tgp_filter_type'][0] ) ? $scMeta['tgp_filter_type'][0] : null );
601 $post_count = ( ! empty( $scMeta['tpg_post_count'][0] ) ? $scMeta['tpg_post_count'][0] : null );
602 $postCountClass = ( $post_count ? ' has-post-count' : null );
603 $allSelect = ' selected';
604 $isTermSelected = false;
605
606 if ( $action_term && $taxFilter ) {
607 $isTermSelected = true;
608 $allSelect = null;
609 }
610
611 if ( ! $filterType || $filterType == 'dropdown' ) {
612 $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-taxonomy='{$taxFilter}'>";
613 $termDefaultText = $allText;
614 $dataTerm = 'all';
615 $htmlButton = '';
616 $selectedSubTerms = null;
617 $pCount = 0;
618
619 if ( ! empty( $terms ) ) {
620 $i = 0;
621
622 foreach ( $terms as $id => $term ) {
623 $pCount = $pCount + $term['count'];
624 $sT = null;
625
626 if ( $taxHierarchical ) {
627 $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id );
628
629 if ( ! empty( $subTerms ) ) {
630 $count = 0;
631 $item = $allCount = null;
632
633 foreach ( $subTerms as $stId => $t ) {
634 $count = $count + absint( $t['count'] );
635 $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null );
636 $item .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$stId}'><span class='rt-text'>{$t['name']}{$sTPostCount}</span></span>";
637 }
638
639 if ( $post_count ) {
640 $allCount = " (<span class='rt-post-count'>{$count}</span>)";
641 }
642
643 $sT .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap sub-dropdown-wrap{$postCountClass}'>";
644 $sT .= "<span class='term-default rt-filter-dropdown-default' data-term='{$id}'>
645 <span class='rt-text'>" . $allText . "{$allCount}</span>
646 <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i>
647 </span>";
648 $sT .= '<span class="term-dropdown rt-filter-dropdown">';
649 $sT .= $item;
650 $sT .= '</span>';
651 $sT .= '</div>';
652 }
653
654 if ( $action_term === $id ) {
655 $selectedSubTerms = $sT;
656 }
657 }
658
659 $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null );
660
661 if ( $action_term && $action_term == $id ) {
662 $termDefaultText = $term['name'] . $postCount;
663 $dataTerm = $id;
664 }
665
666 if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) {
667 if ( $taxFilterOperator == 'NOT IN' ) {
668 if ( ! in_array( $id, $taxFilterTerms ) && $action_term != $id ) {
669 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
670 }
671 } else {
672 if ( in_array( $id, $taxFilterTerms ) && $action_term != $id ) {
673 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
674 }
675 }
676 } else {
677 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
678 }
679
680 $i ++;
681 }
682 }
683 $pAllCount = null;
684
685 if ( $post_count ) {
686 $pAllCount = " (<span class='rt-post-count'>{$pCount}</span>)";
687 if ( ! $action_term ) {
688 $termDefaultText = $termDefaultText . $pAllCount;
689 }
690 }
691
692 if ( ! $hide_all_button ) {
693 $htmlButton = "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'><span class='rt-text'>" . $allText . "{$pAllCount}</span></span>" . $htmlButton;
694 }
695 $htmlButton = sprintf( '<span class="term-dropdown rt-filter-dropdown">%s</span>', $htmlButton );
696
697 $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataTerm . '">
698 <span class="rt-text">' . $termDefaultText . '</span>
699 <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i>
700 </span>';
701
702 $html .= $showAllhtml . $htmlButton;
703 $html .= '</div>' . $selectedSubTerms;
704 } else {
705 $termDefaultText = $allText;
706 $bCount = 0;
707 $bItems = null;
708
709 if ( ! empty( $terms ) ) {
710 foreach ( $terms as $id => $term ) {
711 $bCount = $bCount + absint( $term['count'] );
712 $sT = null;
713
714 if ( $taxHierarchical ) {
715 $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id );
716 if ( ! empty( $subTerms ) ) {
717 $sT .= "<div class='rt-filter-sub-tax sub-button-group'>";
718
719 foreach ( $subTerms as $stId => $t ) {
720 $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null );
721 $sT .= "<span class='rt-filter-button-item' data-term='{$stId}'>{$t['name']}{$sTPostCount}</span>";
722 }
723
724 $sT .= '</div>';
725
726 if ( $action_term === $id ) {
727 $selectedSubTermsForButton = $sT;
728 }
729 }
730 }
731
732 $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null );
733 $termSelected = null;
734
735 if ( $isTermSelected && $id == $action_term ) {
736 $termSelected = ' selected';
737 }
738
739 if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) {
740 if ( $taxFilterOperator == 'NOT IN' ) {
741 if ( ! in_array( $id, $taxFilterTerms ) ) {
742 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
743 }
744 } else {
745 if ( in_array( $id, $taxFilterTerms ) ) {
746 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
747 }
748 }
749 } else {
750 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
751 }
752 }
753 }
754
755 $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-button-wrap{$postCountClass}' data-taxonomy='{$taxFilter}'>";
756
757 if ( ! $hide_all_button ) {
758 $pCountH = ( $post_count ? " (<span class='rt-post-count'>{$bCount}</span>)" : null );
759 $html .= "<span class='term-button-item rt-filter-button-item {$allSelect}' data-term='all'>" . $allText . "{$pCountH}</span>";
760 }
761
762 $html .= $bItems;
763 $html .= '</div>';
764 }
765 }
766
767 // Author filter.
768 if ( in_array( '_author_filter', $filters ) ) {
769 $filterType = ( ! empty( $scMeta['tgp_filter_type'][0] ) ? $scMeta['tgp_filter_type'][0] : null );
770 $post_count = ( ! empty( $scMeta['tpg_post_count'][0] ) ? $scMeta['tpg_post_count'][0] : null );
771 $users = get_users( apply_filters( 'tpg_author_arg', [] ) );
772
773 $allSelect = ' selected';
774 $isTermSelected = false;
775
776 if ( $action_term && $taxFilter ) {
777 $isTermSelected = true;
778 $allSelect = null;
779 }
780
781 if ( ! $filterType || $filterType == 'dropdown' ) {
782 $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}'>";
783 $termDefaultText = $allText;
784 $dataAuthor = 'all';
785 $htmlButton = '';
786 $htmlButton .= '<span class="author-dropdown rt-filter-dropdown">';
787
788 if ( ! empty( $users ) ) {
789 foreach ( $users as $user ) {
790 if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) {
791 if ( in_array( $user->ID, $filterAuthors ) ) {
792 if ( $action_term == $user->ID ) {
793 $termDefaultText = $user->display_name;
794 $dataTerm = $user->ID;
795 } else {
796 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'>{$user->display_name}</span>";
797 }
798 }
799 } else {
800 if ( $action_term == $user->ID ) {
801 $termDefaultText = $user->display_name;
802 $dataTerm = $user->ID;
803 } else {
804 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'>{$user->display_name}</span>";
805 }
806 }
807 }
808 }
809
810 if ( $isTermSelected ) {
811 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'>" . $allText . "{$pAllCount}</span>";
812 }
813 $htmlButton .= '</span>';
814
815 $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataAuthor . '">
816 <span class="rt-text">' . $termDefaultText . '</span>
817 <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i>
818 </span>';
819
820 $html .= $showAllhtml . $htmlButton;
821 $html .= '</div>';
822 } else {
823 $bCount = 0;
824 $bItems = null;
825 if ( ! empty( $users ) ) {
826 foreach ( $users as $user ) {
827 if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) {
828 if ( in_array( $user->ID, $filterAuthors ) ) {
829 $bItems .= "<span class='author-button-item rt-filter-button-item data-author='{$user->ID}'>{$user->display_name}</span>";
830 }
831 } else {
832 $bItems .= "<span class='author-button-item rt-filter-button-item data-author='{$user->ID}'>{$user->display_name}</span>";
833 }
834 }
835 }
836
837 $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-button-wrap{$postCountClass}' data-taxonomy='{$taxFilter}'>";
838
839 if ( ! $hide_all_button ) {
840 $pCountH = ( $post_count ? " (<span class='rt-post-count'>{$bCount}</span>)" : null );
841 $html .= "<span class='author-button-item rt-filter-button-item {$allSelect}' data-author='all'>" . $allText . "{$pCountH}</span>";
842 }
843
844 $html .= $bItems;
845 $html .= '</div>';
846 }
847 }
848
849 if ( in_array( '_search', $filters ) ) {
850 $html .= '<div class="rt-filter-item-wrap rt-search-filter-wrap">';
851 $html .= sprintf( '<input type="text" class="rt-search-input" placeholder="%s">', esc_html__( 'Search...', 'the-post-grid' ) );
852 $html .= "<span class='rt-action'>&#128269;</span>";
853 $html .= "<span class='rt-loading'></span>";
854 $html .= '</div>';
855 }
856
857 if ( in_array( '_order_by', $filters ) ) {
858 $wooFeature = ( $postType == 'product' ? true : false );
859 $orders = Options::rtPostOrderBy( $wooFeature );
860 $action_orderby = ( ! empty( $args['orderby'] ) ? trim( $args['orderby'] ) : 'none' );
861
862 if ( $action_orderby == 'ID' ) {
863 $action_orderby = 'title';
864 }
865
866 if ( $action_orderby == 'none' ) {
867 $action_orderby_label = esc_html__( 'Sort By None', 'the-post-grid' );
868 } elseif ( in_array( $action_orderby, array_keys( Options::rtMetaKeyType() ) ) ) {
869 $action_orderby_label = esc_html__( 'Meta value', 'the-post-grid' );
870 } else {
871 $action_orderby_label = $orders[ $action_orderby ];
872 }
873
874 if ( $action_orderby !== 'none' ) {
875 $orders['none'] = esc_html__( 'Sort By None', 'the-post-grid' );
876 }
877 $html .= '<div class="rt-filter-item-wrap rt-order-by-action rt-filter-dropdown-wrap">';
878 $html .= "<span class='order-by-default rt-filter-dropdown-default' data-order-by='{$action_orderby}'>
879 <span class='rt-text-order-by'>{$action_orderby_label}</span>
880 <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i>
881 </span>";
882 $html .= '<span class="order-by-dropdown rt-filter-dropdown">';
883
884 foreach ( $orders as $orderKey => $order ) {
885 $html .= '<span class="order-by-dropdown-item rt-filter-dropdown-item" data-order-by="' . $orderKey . '">' . $order . '</span>';
886 }
887
888 $html .= '</span>';
889 $html .= '</div>';
890 }
891
892 if ( in_array( '_sort_order', $filters ) ) {
893 $action_order = ( ! empty( $args['order'] ) ? strtoupper( trim( $args['order'] ) ) : 'DESC' );
894 $html .= '<div class="rt-filter-item-wrap rt-sort-order-action">';
895 $html .= "<span class='rt-sort-order-action-arrow' data-sort-order='{$action_order}'>&nbsp;<span></span></span>";
896 $html .= '</div>';
897 }
898
899 $html .= "</div>$selectedSubTermsForButton</div>";
900 }
901
902 $html .= "<div data-title='" . esc_html__( 'Loading ...', 'the-post-grid' ) . "' class='rt-row rt-content-loader {$layout}{$masonryG} {$preLoader}'>";
903
904 $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' );
905
906 if ( $gridQuery->have_posts() ) {
907 $is_lazy_load = '';
908
909 if ( $isCarousel ) {
910 $cOpt = ! empty( $scMeta['carousel_property'] ) ? $scMeta['carousel_property'] : [];
911 $slider_js_options = apply_filters(
912 'rttpg_slider_js_options',
913 [
914 'speed' => ! empty( $scMeta['tpg_carousel_speed'][0] ) ? absint( $scMeta['tpg_carousel_speed'][0] ) : 250,
915 'autoPlayTimeOut' => ! empty( $scMeta['tpg_carousel_autoplay_timeout'][0] ) ? absint( $scMeta['tpg_carousel_autoplay_timeout'][0] ) : 5000,
916 'autoPlay' => in_array( 'auto_play', $cOpt ),
917 'stopOnHover' => in_array( 'stop_hover', $cOpt ),
918 'nav' => in_array( 'nav_button', $cOpt ),
919 'dots' => in_array( 'pagination', $cOpt ),
920 'loop' => in_array( 'loop', $cOpt ),
921 'lazy' => in_array( 'lazy_load', $cOpt ),
922 'autoHeight' => in_array( 'auto_height', $cOpt ),
923 'rtl' => in_array( 'rtl', $cOpt ) ? 'rtl' : 'ltr',
924 ],
925 $scMeta
926 );
927 $html .= sprintf(
928 '<div class="rt-swiper-holder swiper" data-rtowl-options="%s" dir="%s"><div class="swiper-wrapper">',
929 htmlspecialchars( wp_json_encode( $slider_js_options ) ),
930 $slider_js_options['rtl']
931 );
932
933 if ( in_array( 'lazy_load', $cOpt ) ) {
934 $is_lazy_load = 'swiper-lazy';
935 }
936 }
937
938 $isotope_filter = null;
939
940 if ( $isIsotope ) {
941 $isotope_filter = isset( $scMeta['isotope_filter'][0] ) ? $scMeta['isotope_filter'][0] : null;
942 $isotope_dropdown_filter = isset( $scMeta['isotope_filter_dropdown'][0] ) ? $scMeta['isotope_filter_dropdown'][0] : null;
943 $selectedTerms = [];
944
945 if ( isset( $scMeta['post_filter'] )
946 && in_array(
947 'tpg_taxonomy',
948 $scMeta['post_filter']
949 )
950 && isset( $scMeta['tpg_taxonomy'] )
951 && in_array(
952 $isotope_filter,
953 $scMeta['tpg_taxonomy']
954 )
955 ) {
956 $selectedTerms = ( isset( $scMeta[ 'term_' . $isotope_filter ] ) ? $scMeta[ 'term_' . $isotope_filter ] : [] );
957 }
958 $termArgs = [
959 'taxonomy' => $isotope_filter,
960 'orderby' => 'meta_value_num',
961 'order' => 'ASC',
962 'hide_empty' => false,
963 'include' => $selectedTerms,
964 ];
965
966 if ( rtTPG()->hasPro() ) {
967 $termArgs['meta_key'] = '_rt_order';
968 }
969
970 $terms = get_terms( $termArgs );
971
972 $html .= '<div class="tpg-iso-filter">';
973 $htmlButton = $drop = null;
974 $fSelectTrigger = false;
975
976 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
977 foreach ( $terms as $term ) {
978 $tItem = ! empty( $scMeta['isotope_default_filter'][0] ) ? $scMeta['isotope_default_filter'][0] : null;
979 $fSelected = null;
980
981 if ( $tItem == $term->term_id ) {
982 $fSelected = 'selected';
983 $fSelectTrigger = true;
984 }
985
986 $htmlButton .= sprintf(
987 '<button class="rt-iso-btn-%s%s" data-filter=".iso_%d">%s</button>',
988 esc_attr( $term->slug ),
989 $fSelected ? ' ' . $fSelected : '',
990 $term->term_id,
991 $term->name
992 );
993 $drop .= "<option value='.iso_{$term->term_id}' {$fSelected}>{$term->name}</option>";
994 }
995 }
996
997 if ( empty( $scMeta['isotope_filter_show_all'][0] ) ) {
998 $fSelect = ( $fSelectTrigger ? null : 'class="selected"' );
999 $htmlButton = "<button class='rt-iso-btn-all selected' data-filter='*'>" . $arg['show_all_text'] . '</button>' . $htmlButton;
1000 $drop = "<option value='*' {$fSelect}>{$arg['show_all_text']}</option>" . $drop;
1001 }
1002
1003 $filter_count = ! empty( $scMeta['isotope_filter_count'][0] ) ? true : false;
1004 $filter_url = ! empty( $scMeta['isotope_filter_url'][0] ) ? true : false;
1005 $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>";
1006
1007 if ( $isotope_dropdown_filter ) {
1008 $html .= "<select class='isotope-dropdown-filter'>{$drop}</select>";
1009 } else {
1010 $html .= $htmlButton;
1011 }
1012
1013 if ( ! empty( $scMeta['isotope_search_filter'][0] ) ) {
1014 $html .= "<div class='iso-search'><input type='text' class='iso-search-input' placeholder='" . esc_html__( 'Search', 'the-post-grid' ) . "' /></div>";
1015 }
1016
1017 $html .= '</div>';
1018 $html .= "<div class='rt-tpg-isotope' id='iso-tpg-{$rand}'>";
1019 }
1020
1021 $l = $offLoop = 0;
1022 $offsetBigHtml = $offsetSmallHtml = null;
1023 $gridPostCount = 0;
1024 $arg['totalPost'] = $gridQuery->post_count;
1025
1026 while ( $gridQuery->have_posts() ) :
1027 $gridQuery->the_post();
1028
1029 if ( $colStore == $l ) {
1030 if ( $this->l4toggle ) {
1031 $this->l4toggle = false;
1032 } else {
1033 $this->l4toggle = true;
1034 }
1035
1036 $l = 0;
1037 }
1038
1039 $arg['postCount'] = $gridPostCount ++;
1040 $pID = get_the_ID();
1041 $arg['pID'] = $pID;
1042 $arg['title'] = Fns::get_the_title( $pID, $arg );
1043 $arg['pLink'] = get_permalink();
1044 $arg['toggle'] = $this->l4toggle;
1045 $arg['layoutID'] = $layoutID;
1046 $arg['author'] = apply_filters(
1047 'rttpg_author_link',
1048 sprintf( '<a href="%s">%s</a>', get_author_posts_url( get_the_author_meta( 'ID' ) ), get_the_author() )
1049 );
1050 $comments_number = get_comments_number( $pID );
1051 $comments_text = sprintf( '(%s)', number_format_i18n( $comments_number ) );
1052
1053 $arg['date'] = get_the_date();
1054 $arg['excerpt'] = Fns::get_the_excerpt( $pID, $arg );
1055 $arg['categories'] = get_the_term_list( $pID, 'category', null, '<span class="rt-separator">,</span>' );
1056 $arg['tags'] = get_the_term_list( $pID, 'post_tag', null, '<span class="rt-separator">,</span>' );
1057 $arg['post_count'] = get_post_meta( $pID, Fns::get_post_view_count_meta_key(), true );
1058 $arg['responsiveCol'] = [ $dCol, $tCol, $mCol ];
1059
1060 if ( $isIsotope ) {
1061 $termAs = wp_get_post_terms( $pID, $isotope_filter, [ 'fields' => 'all' ] );
1062 $isoFilter = [];
1063
1064 if ( ! empty( $termAs ) ) {
1065 foreach ( $termAs as $term ) {
1066 $isoFilter[] = 'iso_' . $term->term_id;
1067 $isoFilter[] = 'rt-item-' . esc_attr( $term->slug );
1068 }
1069 }
1070
1071 $arg['isoFilter'] = ! empty( $isoFilter ) ? implode( ' ', $isoFilter ) : '';
1072 }
1073
1074 if ( comments_open() ) {
1075 $arg['comment'] = "<a href='" . get_comments_link( $pID ) . "'>{$comments_text} </a>";
1076 } else {
1077 $arg['comment'] = "{$comments_text}";
1078 }
1079
1080 $imgSrc = null;
1081
1082 // TODO: Image Thumbnail.
1083 $arg['smallImgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1084 $pID,
1085 $fSmallImgSize,
1086 $mediaSource,
1087 $defaultImgId,
1088 $customSmallImgSize,
1089 $is_lazy_load
1090 ) : null;
1091 if ( $isOffset ) {
1092 if ( $offLoop == 0 ) {
1093 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1094 $pID,
1095 $fImgSize,
1096 $mediaSource,
1097 $defaultImgId,
1098 $customImgSize
1099 ) : null;
1100 $arg['offset'] = 'big';
1101 $offsetBigHtml = Fns::get_template_html( 'layouts/' . $layout, $arg );
1102 } else {
1103 $arg['offset'] = 'small';
1104 $arg['offsetCol'] = [ $dCol, $tCol, $mCol ];
1105 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1106 $pID,
1107 'thumbnail',
1108 $mediaSource,
1109 $defaultImgId,
1110 $customImgSize
1111 ) : null;
1112 $offsetSmallHtml .= Fns::get_template_html( 'layouts/' . $layout, $arg );
1113 }
1114 } else {
1115 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1116 $pID,
1117 $fImgSize,
1118 $mediaSource,
1119 $defaultImgId,
1120 $customImgSize,
1121 $is_lazy_load
1122 ) : null;
1123 $html .= Fns::get_template_html( 'layouts/' . $layout, $arg );
1124 }
1125
1126 $offLoop ++;
1127 $l ++;
1128 endwhile;
1129
1130 if ( $isOffset ) {
1131 $oDCol = Fns::get_offset_col( $dCol );
1132 $oTCol = Fns::get_offset_col( $tCol );
1133 $oMCol = Fns::get_offset_col( $mCol );
1134
1135 if ( $layout == 'offset03' || $layout == 'offset04' ) {
1136 $oDCol['big'] = $oTCol['big'] = $oDCol['small'] = $oTCol['small'] = 6;
1137 $oMCol['big'] = $oMCol['small'] = 12;
1138 } elseif ( $layout == 'offset06' ) {
1139 $oDCol['big'] = 7;
1140 $oDCol['small'] = 5;
1141 }
1142
1143 $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>";
1144 $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>";
1145 }
1146
1147 if ( $isIsotope || $isCarousel ) {
1148 $html .= '</div>'; // End isotope / Carousel item holder.
1149
1150 if ( $isIsotope ) {
1151 $html .= '<div class="isotope-term-no-post"><p>' . $not_found_text . '</p></div>';
1152 }
1153
1154 if ( $isCarousel ) {
1155 $html .= '</div>';
1156
1157 if ( in_array( 'pagination', $cOpt ) ) {
1158 $html .= '<div class="swiper-pagination"></div>';
1159 }
1160
1161 if ( in_array( 'nav_button', $cOpt ) ) {
1162 $html .= '<div class="swiper-navigation"><div class="slider-btn swiper-button-prev"></div><div class="slider-btn swiper-button-next"></div></div>';
1163 }
1164 }
1165 }
1166 } else {
1167 $html .= sprintf(
1168 '<p>%s</p>',
1169 apply_filters( 'tpg_not_found_text', $not_found_text, $args, $scMeta )
1170 );
1171 }
1172
1173 $html .= $preLoaderHtml;
1174 $html .= '</div>'; // End row.
1175 $htmlUtility = null;
1176
1177 if ( $pagination && ! $isCarousel ) {
1178 if ( $isOffset || $isGridHover ) {
1179 $posts_loading_type = 'page_prev_next';
1180 $htmlUtility .= "<div class='rt-cb-page-prev-next'>
1181 <span class='rt-cb-prev-btn'><i class='fa fa-angle-left' aria-hidden='true'></i></span>
1182 <span class='rt-cb-next-btn'><i class='fa fa-angle-right' aria-hidden='true'></i></span>
1183 </div>";
1184 } else {
1185 $hide = ( $gridQuery->max_num_pages < 2 ? ' rt-hidden-elm' : null );
1186 if ( $posts_loading_type == 'pagination' ) {
1187 if ( ( $isGrid || $isWooCom || $isEdd ) && empty( $filters ) ) {
1188 $htmlUtility .= Fns::rt_pagination(
1189 $gridQuery,
1190 $args['posts_per_page']
1191 );
1192 }
1193 } elseif ( $posts_loading_type == 'pagination_ajax' && ! $isIsotope ) {
1194 $htmlUtility .= "<div class='rt-page-numbers'></div>";
1195 } elseif ( $posts_loading_type == 'load_more' && rtTPG()->hasPro() ) {
1196 $load_more_btn_text = ( ! empty( $scMeta['load_more_text'][0] ) ? $scMeta['load_more_text'][0] : '' );
1197 $load_more_text = $load_more_btn_text ? esc_html( $load_more_btn_text ) : esc_html__( 'Load More', 'the-post-grid' );
1198
1199 $htmlUtility .= "<div class='rt-loadmore-btn rt-loadmore-action rt-loadmore-style{$hide}'>
1200 <span class='rt-loadmore-text'>" . $load_more_text . "</span>
1201 <div class='rt-loadmore-loading rt-ball-scale-multiple rt-2x'><div></div><div></div><div></div></div>
1202 </div>";
1203 } elseif ( $posts_loading_type == 'load_on_scroll' && rtTPG()->hasPro() ) {
1204 $htmlUtility .= "<div class='rt-infinite-action'>
1205 <div class='rt-infinite-loading la-fire la-2x'>
1206 <div></div>
1207 <div></div>
1208 <div></div>
1209 </div>
1210 </div>";
1211 }
1212 }
1213 }
1214
1215 if ( $htmlUtility ) {
1216 $l4toggle = null;
1217 if ( $layout == 'layout4' ) {
1218 $l4toggle = "data-l4toggle='{$this->l4toggle}'";
1219 }
1220 $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>';
1221 }
1222
1223 $html .= '</div>'; // container rt-tpg.
1224
1225 wp_reset_postdata();
1226
1227 $scriptGenerator = [];
1228 $scriptGenerator['layout'] = $layoutID;
1229 $scriptGenerator['rand'] = $rand;
1230 $scriptGenerator['scMeta'] = $scMeta;
1231 $scriptGenerator['isCarousel'] = $isCarousel;
1232 $scriptGenerator['isSinglePopUp'] = $isSinglePopUp;
1233 $scriptGenerator['isWooCom'] = $isWooCom;
1234 $this->scA[] = $scriptGenerator;
1235
1236 add_action( 'wp_footer', [ $this, 'register_sc_scripts' ] );
1237
1238 // Script Load Conditionally
1239 $script = [];
1240 $style = [];
1241
1242 array_push( $script, 'jquery' );
1243 array_push( $style, 'rt-fontawsome' );
1244
1245 if ( 'masonry' == $gridType || $isIsotope ) {
1246 array_push( $script, 'rt-isotope-js' );
1247 }
1248
1249 array_push( $script, 'imagesloaded' );
1250 array_push( $script, 'rt-tpg' );
1251
1252 // Pro Scripts and Styles.
1253 if ( rtTPG()->hasPro() ) {
1254
1255 if ( isset( $posts_loading_type ) && 'pagination_ajax' == $posts_loading_type ) {
1256 array_push( $script, 'rt-pagination' );
1257 }
1258
1259 if ( $layout == 'layout17' || 'popup' == $linkType ) {
1260 array_push( $style, 'rt-magnific-popup' );
1261 array_push( $script, 'rt-magnific-popup' );
1262 }
1263
1264 if ( 'popup' == $linkType ) {
1265 array_push( $script, 'rt-scrollbar' );
1266 }
1267
1268 if ( class_exists( 'WooCommerce' ) ) {
1269 array_push( $script, 'rt-jzoom' );
1270 }
1271 }
1272
1273 array_push( $style, 'rt-tpg-shortcode' );
1274
1275 if ( ( $isCarousel && rtTPG()->hasPro() ) || $isWooCom ) {
1276 array_push( $style, 'swiper' );
1277 array_push( $script, 'swiper' );
1278 }
1279
1280 if ( rtTPG()->hasPro() ) {
1281 array_push( $script, 'rt-tpg-pro' );
1282 }
1283
1284 if ( isset( $settings['tpg_load_script'] ) ) {
1285 wp_enqueue_style( $style );
1286 }
1287
1288 wp_enqueue_script( $script );
1289
1290 } else {
1291 $html .= '<p>' . esc_html__( 'No shortCode found', 'the-post-grid' ) . '</p>';
1292 }
1293
1294 // restriction issue.
1295 $restriction = ( ! empty( $scMeta['restriction_user_role'] ) ? $scMeta['restriction_user_role'] : [] );
1296 if ( ! empty( $restriction ) ) {
1297 if ( is_user_logged_in() ) {
1298 $currentUserRoles = Fns::getCurrentUserRoles();
1299
1300 if ( in_array( 'administrator', $currentUserRoles ) ) {
1301 $html = $html;
1302 } else {
1303 if ( count( array_intersect( $restriction, $currentUserRoles ) ) ) {
1304 $html = $html;
1305 } else {
1306 $html = '<p>' . esc_html__(
1307 'You are not permitted to view this content.',
1308 'the-post-grid'
1309 ) . '</p>';
1310 }
1311 }
1312 } else {
1313 $html = '<p>' . esc_html__( 'This is a restricted content, you need to logged in to view this content.', 'the-post-grid' ) . '</p>';
1314 }
1315 }
1316
1317 return $html;
1318 }
1319 }
1320