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