PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.8.8
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.8.8
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 / Admin / AdminAjaxController.php
the-post-grid / app / Controllers / Admin Last commit date
Notice 8 months ago AdminAjaxController.php 8 months ago MetaController.php 8 months ago NoticeController.php 8 months ago PostTypeController.php 8 months ago SettingsController.php 8 months ago UpgradeController.php 8 months ago
AdminAjaxController.php
1252 lines
1 <?php
2 /**
3 * Admin Ajax class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers\Admin;
9
10 use RT\ThePostGrid\Helpers\Fns;
11 use RT\ThePostGrid\Helpers\Options;
12
13 //phpcs:disable WordPress.Security.NonceVerification.Recommended
14
15 // Do not allow directly accessing this file.
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit( 'This script cannot be accessed directly.' );
18 }
19
20 /**
21 * Admin Ajax class.
22 */
23 class AdminAjaxController {
24 /**
25 * Layout 4 toggle
26 *
27 * @var boolean
28 */
29 private $l4toggle = false;
30
31 /**
32 * Class Construct
33 */
34 public function __construct() {
35 add_action( 'wp_ajax_tpgPreviewAjaxCall', [ $this, 'tpgPreviewAjaxCall' ] );
36 }
37
38 /**
39 * Preview rendering
40 *
41 * @return void
42 */
43 public function tpgPreviewAjaxCall() {
44 $msg = $data = null;
45 $error = true;
46
47 if ( ! current_user_can( 'edit_posts' ) ) {
48 wp_send_json_success( new WP_Error( 'rttpg_block_user_permission', __( 'User permission error', 'the-post-grid' ) ) );
49 }
50
51 if ( Fns::verifyNonce() ) {
52 $error = false;
53 $rand = wp_rand();
54 $layoutID = 'rt-tpg-container-' . $rand;
55
56 $layout = ( isset( $_REQUEST['layout'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['layout'] ) ) : 'layout1' );
57
58 if ( ! in_array( $layout, array_keys( Options::rtTPGLayouts() ), true ) ) {
59 $layout = 'layout1';
60 }
61
62 $isIsotope = preg_match( '/isotope/', $layout );
63 $isCarousel = preg_match( '/carousel/', $layout );
64 $isGrid = preg_match( '/layout/', $layout );
65 $isWooCom = preg_match( '/wc/', $layout );
66 $isOffset = preg_match( '/offset/', $layout );
67 $isGridHover = preg_match( '/grid_hover/', $layout );
68
69 $dCol = ( isset( $_REQUEST['column'] ) ? absint( $_REQUEST['column'] ) : 3 );
70 $tCol = ( isset( $_REQUEST['tpg_tab_column'] ) ? absint( $_REQUEST['tpg_tab_column'] ) : 2 );
71 $mCol = ( isset( $_REQUEST['tpg_mobile_column'] ) ? absint( $_REQUEST['tpg_mobile_column'] ) : 1 );
72
73 if ( ! in_array( $dCol, array_keys( Options::scColumns() ), true ) ) {
74 $dCol = 3;
75 }
76
77 if ( ! in_array( $tCol, array_keys( Options::scColumns() ), true ) ) {
78 $tCol = 2;
79 }
80
81 if ( ! in_array( $dCol, array_keys( Options::scColumns() ), true ) ) {
82 $mCol = 1;
83 }
84
85 if ( $isOffset ) {
86 $dCol = ( $dCol < 3 ? 2 : $dCol );
87 $tCol = ( $tCol < 3 ? 2 : $tCol );
88 $mCol = ( $mCol < 3 ? 1 : $mCol );
89 }
90
91 $arg = [];
92 $fImg = ! empty( $_REQUEST['feature_image'] );
93 $fImgSize = ( isset( $_REQUEST['featured_image_size'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['featured_image_size'] ) ) : 'medium' );
94 $mediaSource = ( isset( $_REQUEST['media_source'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['media_source'] ) ) : 'feature_image' );
95 $arg['excerpt_type'] = ( isset( $_REQUEST['tgp_excerpt_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_excerpt_type'] ) ) : 'character' );
96 $arg['title_limit_type'] = ( isset( $_REQUEST['tpg_title_limit_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_title_limit_type'] ) ) : 'character' );
97 $arg['excerpt_limit'] = ( isset( $_REQUEST['excerpt_limit'] ) ? absint( $_REQUEST['excerpt_limit'] ) : 0 );
98 $arg['title_limit'] = ( isset( $_REQUEST['tpg_title_limit'] ) ? absint( $_REQUEST['tpg_title_limit'] ) : 0 );
99 $arg['excerpt_more_text'] = ( isset( $_REQUEST['tgp_excerpt_more_text'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_excerpt_more_text'] ) ) : null );
100 $arg['read_more_text'] = ( ! empty( $_REQUEST['tgp_read_more_text'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_read_more_text'] ) ) : esc_html__( 'Read More', 'the-post-grid' ) );
101 $arg['show_all_text'] = ( ! empty( $_REQUEST['tpg_show_all_text'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_show_all_text'] ) ) : esc_html__( 'Show all', 'the-post-grid' ) );
102 $arg['tpg_title_position'] = isset( $_REQUEST['tpg_title_position'] ) && ! empty( $_REQUEST['tpg_title_position'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_title_position'] ) ) : null;
103 $arg['btn_alignment_class'] = isset( $_REQUEST['tpg_read_more_button_alignment'] ) && ! empty( $_REQUEST['tpg_read_more_button_alignment'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_read_more_button_alignment'] ) ) : '';
104 $arg['category_position'] = isset( $_REQUEST['tpg_category_position'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_category_position'] ) ) : null;
105 $arg['category_style'] = ! empty( $_REQUEST['tpg_category_style'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_category_style'] ) ) : '';
106 $arg['catIcon'] = isset( $_REQUEST['tpg_category_icon'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_category_icon'] ) ) : true;
107 $arg['metaPosition'] = isset( $_REQUEST['tpg_meta_position'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_meta_position'] ) ) : null;
108 $arg['metaIcon'] = ! empty( $_REQUEST['tpg_meta_icon'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_meta_icon'] ) ) : true;
109 $arg['metaSeparator'] = ! empty( $_REQUEST['tpg_meta_separator'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_meta_separator'] ) ) : '';
110
111 $args = [];
112 $postType = ( isset( $_REQUEST['tpg_post_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_post_type'] ) ) : null );
113
114 if ( $postType ) {
115 $args['post_type'] = $postType;
116 }
117
118 /* post__in */
119 $post__in = ( isset( $_REQUEST['post__in'] ) ? sanitize_text_field( $_REQUEST['post__in'] ) : null );
120
121 if ( $post__in ) {
122 $post__in = explode( ',', $post__in );
123 $args['post__in'] = $post__in;
124 }
125
126 /* post__not_in */
127 $post__not_in = ( isset( $_REQUEST['post__not_in'] ) ? absint( $_REQUEST['post__not_in'] ) : null );
128
129 if ( $post__not_in ) {
130 $post__not_in = explode( ',', $post__not_in );
131 $args['post__not_in'] = $post__not_in; //phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in
132 }
133
134 /* LIMIT */
135 $limit = ( ( empty( $_REQUEST['limit'] ) || '-1' === $_REQUEST['limit'] ) ? - 1 : absint( $_REQUEST['limit'] ) );
136 $queryOffset = empty( $_REQUEST['offset'] ) ? 0 : absint( $_REQUEST['offset'] );
137 $args['posts_per_page'] = $limit;
138 $pagination = isset( $_REQUEST['pagination'] ) && ! empty( $_REQUEST['pagination'] );
139 $posts_loading_type = ( ! empty( $_REQUEST['posts_loading_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['posts_loading_type'] ) ) : 'pagination' );
140
141 if ( $pagination ) {
142 $posts_per_page = ( isset( $_REQUEST['posts_per_page'] ) ? absint( $_REQUEST['posts_per_page'] ) : $limit );
143
144 if ( $posts_per_page > $limit && $limit != '-1' ) {
145 $posts_per_page = $limit;
146 }
147
148 $args['posts_per_page'] = $posts_per_page;
149
150 $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
151
152 $offset = $posts_per_page * ( (int) $paged - 1 );
153 $args['paged'] = $paged;
154
155 if ( intval( $args['posts_per_page'] ) > $limit - $offset && $limit != '-1' ) {
156 $args['posts_per_page'] = $limit - $offset;
157 }
158 }
159
160 $adv_filter = ( isset( $_REQUEST['post_filter'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['post_filter'] ) ) : [] );
161 $taxFilter = ( ! empty( $_REQUEST['tgp_filter_taxonomy'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_filter_taxonomy'] ) ) : null );
162 $taxHierarchical = ! empty( $_REQUEST['tgp_filter_taxonomy_hierarchical'] );
163 $taxFilterTerms = [];
164 $taxFilterOperator = 'IN';
165
166 $taxQ = [];
167
168 if ( in_array( 'tpg_taxonomy', $adv_filter ) && isset( $_REQUEST['tpg_taxonomy'] ) ) {
169 $tpgTaxonomy = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['tpg_taxonomy'] ) );
170
171 if ( is_array( $tpgTaxonomy ) && ! empty( $tpgTaxonomy ) ) {
172 foreach ( $tpgTaxonomy as $taxonomy ) {
173 $terms = ( isset( $_REQUEST[ 'term_' . $taxonomy ] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST[ 'term_' . $taxonomy ] ) ) : [] );
174
175 if ( $taxonomy == $taxFilter ) {
176 $taxFilterTerms = $terms;
177 }
178
179 if ( is_array( $terms ) && ! empty( $terms ) ) {
180 $operator = ( isset( $_REQUEST[ 'term_operator_' . $taxonomy ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ 'term_operator_' . $taxonomy ] ) ) : 'IN' );
181 $taxQ[] = [
182 'taxonomy' => $taxonomy,
183 'field' => 'term_id',
184 'terms' => $terms,
185 'operator' => $operator,
186 ];
187 }
188 }
189 }
190
191 if ( count( $taxQ ) >= 2 ) {
192 $relation = ( isset( $_REQUEST['taxonomy_relation'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['taxonomy_relation'] ) ) : 'AND' );
193 $taxQ['relation'] = $relation;
194 }
195 }
196
197 if ( ! empty( $taxQ ) ) {
198 $args['tax_query'] = $taxQ; //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
199 }
200
201 if ( in_array( 'order', $adv_filter ) ) {
202 $order_by = ( isset( $_REQUEST['order_by'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['order_by'] ) ) : null );
203 $order = ( isset( $_REQUEST['order'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ) : null );
204
205 if ( $order ) {
206 $args['order'] = $order;
207 }
208
209 if ( $order_by ) {
210 $args['orderby'] = $order_by;
211 $meta_key = ! empty( $_REQUEST['tpg_meta_key'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_meta_key'] ) ) : null;
212
213 if ( in_array( $order_by, array_keys( Options::rtMetaKeyType() ), true ) && $meta_key ) {
214 $args['orderby'] = $order_by;
215 $args['meta_key'] = $meta_key; //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
216 }
217 }
218 }
219
220 if ( isset( $_REQUEST['orderby'] ) ) {
221 $orderby = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) );
222
223 switch ( $orderby ) {
224 case 'menu_order':
225 $args['orderby'] = 'menu_order title';
226 $args['order'] = 'ASC';
227 break;
228 case 'date':
229 $args['orderby'] = 'date';
230 $args['order'] = 'DESC';
231 break;
232 case 'price':
233 $args['orderby'] = 'meta_value_num';
234 $args['meta_key'] = '_price'; //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
235 $args['order'] = 'ASC';
236 break;
237 case 'price-desc':
238 $args['orderby'] = 'meta_value_num';
239 $args['meta_key'] = '_price'; //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
240 $args['order'] = 'DESC';
241 break;
242 case 'rating':
243 // Sorting handled later though a hook.
244 add_filter( 'posts_clauses', [ $this, 'order_by_rating_post_clauses' ] );
245 break;
246 case 'title':
247 $args['orderby'] = 'title';
248 $args['order'] = 'ASC';
249 break;
250 }
251 }
252
253 /* Post status has removed
254
255 * if ( in_array( 'tpg_post_status', $adv_filter ) ) {
256 $post_status = ( isset( $_REQUEST['tpg_post_status'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['tpg_post_status'] ) ) : [] );
257
258 if ( ! empty( $post_status ) ) {
259 $args['post_status'] = $post_status;
260 }
261 } else {
262 $args['post_status'] = 'publish';
263 }*/
264
265 $args['post_status'] = 'publish';
266
267 $filterAuthors = [];
268 $author = ( isset( $_REQUEST['author'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['author'] ) ) : [] );
269
270 if ( in_array( 'author', $adv_filter ) && ! empty( $author ) ) {
271 $filterAuthors = $args['author__in'] = $author;
272 }
273
274 $s = ( isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : [] );
275
276 if ( in_array( 's', $adv_filter ) && ! empty( $s ) ) {
277 $args['s'] = $s;
278 }
279
280 if ( in_array( 'date_range', $adv_filter ) ) {
281 $startDate = ( ! empty( $_REQUEST['date_range_start'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['date_range_start'] ) ) : null );
282 $endDate = ( ! empty( $_REQUEST['date_range_end'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['date_range_end'] ) ) : null );
283 if ( $startDate && $endDate ) {
284 $args['date_query'] = [
285 [
286 'after' => $startDate,
287 'before' => $endDate,
288 'inclusive' => true,
289 ],
290 ];
291 }
292 }
293
294 $settings = get_option( rtTPG()->options['settings'] );
295 $override_items = ! empty( $settings['template_override_items'] ) ? $settings['template_override_items'] : [];
296 $dataArchive = null;
297
298 if ( ( is_archive() || is_search() || is_tag() || is_author() ) && ! empty( $override_items ) ) {
299 unset( $args['post_type'] );
300 unset( $args['tax_query'] );
301 unset( $args['author__in'] );
302 $obj = get_queried_object();
303 $aType = $aValue = null;
304
305 if ( in_array( 'tag-archive', $override_items ) && is_tag() ) {
306 if ( ! empty( $obj->slug ) ) {
307 $aValue = $args['tag'] = $obj->slug;
308 $aType = 'tag';
309 }
310 } elseif ( in_array( 'category-archive', $override_items ) && is_category() ) {
311 if ( ! empty( $obj->slug ) ) {
312 $aValue = $args['category_name'] = $obj->slug;
313 }
314
315 $aType = 'category';
316 } elseif ( in_array( 'author-archive', $override_items ) && is_author() ) {
317 $aValue = $args['author'] = $obj->ID;
318 $aType = 'author';
319 } elseif ( in_array( 'search', $override_items ) && is_search() ) {
320 $aValue = $args['s'] = get_search_query();
321 $aType = 'search';
322 }
323
324 $dataArchive = " data-archive='{$aType}' data-archive-value='{$aValue}'";
325 $args['posts_per_archive_page'] = $args['posts_per_page'];
326 }
327
328 $containerDataAttr = null;
329 $containerDataAttr .= " data-layout='{$layout}' data-desktop-col='{$dCol}' data-tab-col='{$tCol}' data-mobile-col='{$mCol}'";
330
331 $dCol = 5 === $dCol ? '24' : round( 12 / $dCol );
332 $tCol = 5 === $dCol ? '24' : round( 12 / $tCol );
333 $mCol = 5 === $dCol ? '24' : round( 12 / $mCol );
334
335 if ( $isCarousel ) {
336 $dCol = $tCol = $mCol = 12;
337 }
338
339 $arg['grid'] = "rt-col-md-{$dCol} rt-col-sm-{$tCol} rt-col-xs-{$mCol}";
340
341 if ( ( 'layout2' === $layout ) || ( 'layout3' === $layout ) ) {
342 $iCol = ( isset( $_REQUEST['tgp_layout2_image_column'] ) ? absint( $_REQUEST['tgp_layout2_image_column'] ) : 4 );
343 $iCol = $iCol > 12 ? 4 : $iCol;
344 $cCol = 12 - $iCol;
345 $arg['image_area'] = "rt-col-sm-{$iCol} rt-col-xs-12 ";
346 $arg['content_area'] = "rt-col-sm-{$cCol} rt-col-xs-12 ";
347 }
348
349 if ( 'layout4' === $layout ) {
350 $arg['image_area'] = 'rt-col-lg-6 rt-col-md-6 rt-col-sm-12 rt-col-xs-12 ';
351 $arg['content_area'] = 'rt-col-lg-6 rt-col-md-6 rt-col-sm-12 rt-col-xs-12 ';
352 }
353
354 $gridType = ! empty( $_REQUEST['grid_style'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['grid_style'] ) ) : 'even';
355 $arg_class = [];
356 $arg_class[] = ' rt-grid-item';
357
358 if ( ! $isCarousel && ! $isOffset ) {
359 $arg_class[] = $gridType . '-grid-item';
360 }
361
362 if ( $isOffset ) {
363 $arg_class[] = 'rt-offset-item';
364 }
365
366 $catHaveBg = ( isset( $_REQUEST['tpg_category_bg'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_category_bg'] ) ) : '' );
367
368 if ( ! empty( $catHaveBg ) ) {
369 $arg_class[] = 'category-have-bg';
370 }
371
372 $imgAnimationType = isset( $_REQUEST['tpg_image_animation'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_image_animation'] ) ) : '';
373
374 if ( ! empty( $imgAnimationType ) ) {
375 $arg_class[] = $imgAnimationType;
376 }
377
378 $masonryG = null;
379
380 if ( 'even' === $gridType && ! $isIsotope && ! $isCarousel ) {
381 $masonryG = 'tpg-even';
382 } elseif ( 'masonry' === $gridType && ! $isIsotope && ! $isCarousel ) {
383 $masonryG = ' tpg-masonry';
384 }
385
386 $preLoader = $preLoaderHtml = null;
387
388 if ( $isIsotope ) {
389 $arg_class[] = 'isotope-item';
390 $preLoader = 'tpg-pre-loader';
391 }
392
393 if ( $isCarousel ) {
394 $arg_class[] = 'swiper-slide';
395 $preLoader = 'tpg-pre-loader';
396 }
397
398 $arg['class'] = implode( ' ', $arg_class );
399
400 if ( $preLoader ) {
401 $preLoaderHtml = '<div class="rt-loading-overlay"></div><div class="rt-loading rt-ball-clip-rotate"><div></div></div>';
402 }
403
404 $margin = ! empty( $_REQUEST['margin_option'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['margin_option'] ) ) : 'default';
405
406 if ( 'no' === $margin ) {
407 $arg_class[] = 'no-margin';
408 }
409
410 if ( ! empty( $_REQUEST['tpg_image_type'] ) && 'circle' === $_REQUEST['tpg_image_type'] ) {
411 $arg_class[] = 'tpg-img-circle';
412 }
413
414 $arg['anchorClass'] = null;
415 $arg['anchorClass'] = $arg['link_target'] = null;
416 $link = isset( $_REQUEST['link_to_detail_page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['link_to_detail_page'] ) ) : '1';
417 $link = ( 'yes' === $link ) ? '1' : $link;
418 $isSinglePopUp = false;
419 $linkType = ! empty( $_REQUEST['detail_page_link_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['detail_page_link_type'] ) ) : 'popup';
420
421 if ( '1' === $link ) {
422 if ( 'popup' === $linkType && rtTPG()->hasPro() ) {
423 $popupType = ! empty( $_REQUEST['popup_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['popup_type'] ) ) : 'single';
424 if ( 'single' === $popupType ) {
425 $arg['anchorClass'] .= ' tpg-single-popup';
426 $isSinglePopUp = true;
427 } else {
428 $arg['anchorClass'] .= ' tpg-multi-popup';
429 }
430 } else {
431 $arg['link_target'] = ! empty( $_REQUEST['link_target'] ) ? ' target="' . sanitize_text_field( wp_unslash( $_REQUEST['link_target'] ) ) . '"' : null;
432 }
433 } else {
434 $arg['anchorClass'] = ' disabled';
435 }
436
437 $isSinglePopUp = false;
438 $linkType = ! empty( $_REQUEST['detail_page_link_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['detail_page_link_type'] ) ) : 'popup';
439
440 if ( '1' === $link && 'popup' === $linkType && rtTPG()->hasPro() ) {
441 $popupType = ! empty( $_REQUEST['popup_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['popup_type'] ) ) : 'single';
442
443 if ( 'single' === $popupType ) {
444 $arg['anchorClass'] .= ' tpg-single-popup';
445 $isSinglePopUp = true;
446 } else {
447 $arg['anchorClass'] .= ' tpg-multi-popup';
448 }
449 }
450
451 $parentClass = ( ! empty( $_REQUEST['parent_class'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['parent_class'] ) ) : null );
452 $defaultImgId = ( ! empty( $_REQUEST['default_preview_image'] ) ? absint( $_REQUEST['default_preview_image'] ) : null );
453 $customImgSize = ( ! empty( $_REQUEST['custom_image_size'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['custom_image_size'] ) ) : [] );
454 $fSmallImgSize = ( isset( $_REQUEST['featured_small_image_size'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['featured_small_image_size'] ) ) : 'medium' );
455 $customSmallImgSize = ( ! empty( $_REQUEST['custom_small_image_size'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['custom_small_image_size'] ) ) : [] );
456
457 $arg['items'] = isset( $_REQUEST['item_fields'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['item_fields'] ) ) : [];
458 $arg['scID'] = $scID = isset( $_REQUEST['sc_id'] ) ? absint( $_REQUEST['sc_id'] ) : null;
459
460 if ( isset( $arg['excerpt_type'] ) && 'full' === $arg['excerpt_type'] && ( $key = array_search( 'read_more', $arg['items'] ) ) !== false ) {
461 unset( $arg['items'][ $key ] );
462 }
463
464 if ( isset( $_REQUEST['ignore_sticky_posts'] ) ) {
465 $args['ignore_sticky_posts'] = isset( $_REQUEST['ignore_sticky_posts'] );
466 }
467
468 $filters = ! empty( $_REQUEST['tgp_filter'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['tgp_filter'] ) ) : [];
469 $action_term = ! empty( $_REQUEST['tgp_default_filter'] ) ? absint( $_REQUEST['tgp_default_filter'] ) : 0;
470 $hide_all_button = ! empty( $_REQUEST['tpg_hide_all_button'] ) ? true : false;
471
472 if ( $taxHierarchical ) {
473 $terms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, 0 );
474 } else {
475 $terms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true );
476 }
477
478 if ( $hide_all_button && ! $action_term ) {
479 if ( ! empty( $terms ) ) {
480 $allKeys = array_keys( $terms );
481 $action_term = $allKeys[0];
482 }
483 }
484
485 if ( in_array( '_taxonomy_filter', $filters ) && $taxFilter && $action_term ) {
486 //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
487 $args['tax_query'] = [
488 [
489 'taxonomy' => $taxFilter,
490 'field' => 'term_id',
491 'terms' => [ $action_term ],
492 ],
493 ];
494 }
495
496 if ( $limit != - 1 && $pagination ) {
497 $tempArgs = $args;
498 $tempArgs['posts_per_page'] = $limit;
499 $tempArgs['paged'] = 1;
500 $tempArgs['fields'] = 'ids';
501 $tempQ = new \WP_Query( apply_filters( 'tpg_sc_temp_query_args', $tempArgs ) );
502
503 if ( ! empty( $tempQ->posts ) ) {
504 $args['post__in'] = $tempQ->posts;
505 }
506 }
507
508 if ( $pagination && $queryOffset && isset( $args['paged'] ) ) {
509 $queryOffset = ( $posts_per_page * ( $args['paged'] - 1 ) ) + $queryOffset;
510 }
511
512 if ( $queryOffset ) {
513 $args['offset'] = $queryOffset;
514 }
515
516 $arg['title_tag'] = ( ! empty( $_REQUEST['title_tag'] ) && in_array( $_REQUEST['title_tag'], array_keys( Options::getTitleTags() ) ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['title_tag'] ) ) : 'h3';
517
518 $gridQuery = new \WP_Query( apply_filters( 'tpg_sc_query_args', $args ) );
519
520 $styleMeta = [
521 'primary_color' => isset( $_REQUEST['primary_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['primary_color'] ) ) : null,
522 'button_bg_color' => isset( $_REQUEST['button_bg_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_bg_color'] ) ) : null,
523 'button_active_bg_color' => isset( $_REQUEST['button_active_bg_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_active_bg_color'] ) ) : null,
524 'button_hover_bg_color' => isset( $_REQUEST['button_hover_bg_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_hover_bg_color'] ) ) : null,
525 'button_text_color' => isset( $_REQUEST['button_text_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_text_color'] ) ) : null,
526 'button_text_bg_color' => isset( $_REQUEST['button_text_bg_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_text_bg_color'] ) ) : null,
527 'button_border_color' => isset( $_REQUEST['button_border_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_border_color'] ) ) : null,
528 'button_hover_text_color' => isset( $_REQUEST['button_hover_text_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_hover_text_color'] ) ) : null,
529 'overlay_color' => isset( $_REQUEST['overlay_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['overlay_color'] ) ) : null,
530 'overlay_opacity' => isset( $_REQUEST['overlay_opacity'] ) ? absint( $_REQUEST['overlay_opacity'] ) : null,
531 'overlay_padding' => isset( $_REQUEST['overlay_padding'] ) ? absint( $_REQUEST['overlay_padding'] ) : null,
532 'tgp_gutter' => isset( $_REQUEST['tgp_gutter'] ) ? absint( $_REQUEST['tgp_gutter'] ) : null,
533 'tpg_read_more_button_border_radius' => isset( $_REQUEST['tpg_read_more_button_border_radius'] ) ? absint( $_REQUEST['tpg_read_more_button_border_radius'] ) : null,
534 'tpg_full_area_bg' => isset( $_REQUEST['tpg_full_area_bg'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_full_area_bg'] ) ) : null,
535 'tpg_full_area_margin' => isset( $_REQUEST['tpg_full_area_margin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_full_area_margin'] ) ) : null,
536 'tpg_full_area_padding' => isset( $_REQUEST['tpg_full_area_margin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_full_area_margin'] ) ) : null,
537 'tpg_content_wrap_bg' => isset( $_REQUEST['tpg_content_wrap_bg'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_content_wrap_bg'] ) ) : null,
538 'tpg_content_wrap_border' => isset( $_REQUEST['tpg_content_wrap_border'] ) ? absint( $_REQUEST['tpg_content_wrap_border'] ) : null,
539 'tpg_content_wrap_border_color' => isset( $_REQUEST['tpg_content_wrap_border_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_content_wrap_border_color'] ) ) : null,
540 'tpg_content_wrap_border_radius' => isset( $_REQUEST['tpg_content_wrap_border_radius'] ) ? absint( $_REQUEST['tpg_content_wrap_border_radius'] ) : null,
541 'tpg_content_wrap_shadow' => isset( $_REQUEST['tpg_content_wrap_shadow'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_content_wrap_shadow'] ) ) : null,
542 'tpg_box_padding' => isset( $_REQUEST['tpg_box_padding'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_box_padding'] ) ) : null,
543 'tpg_content_padding' => isset( $_REQUEST['tpg_content_padding'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_content_padding'] ) ) : null,
544 'tpg_heading_bg' => isset( $_REQUEST['tpg_heading_bg'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_heading_bg'] ) ) : null,
545 'tpg_heading_color' => isset( $_REQUEST['tpg_heading_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_heading_color'] ) ) : null,
546 'tpg_heading_border_color' => isset( $_REQUEST['tpg_heading_border_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_heading_border_color'] ) ) : null,
547 'tpg_heading_border_size' => isset( $_REQUEST['tpg_heading_border_size'] ) ? absint( $_REQUEST['tpg_heading_border_size'] ) : null,
548 'tpg_heading_margin' => isset( $_REQUEST['tpg_heading_margin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_margin'] ) ) : null,
549 'tpg_heading_padding' => isset( $_REQUEST['tpg_heading_padding'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_padding'] ) ) : null,
550 'tpg_category_bg' => isset( $_REQUEST['tpg_category_bg'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_category_bg'] ) ) : null,
551 'tpg_category_color' => isset( $_REQUEST['tpg_category_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_category_color'] ) ) : null,
552 'tpg_category_border_radius' => isset( $_REQUEST['tpg_category_border_radius'] ) ? absint( $_REQUEST['tpg_category_border_radius'] ) : null,
553 'tpg_category_margin' => isset( $_REQUEST['tpg_category_margin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_category_margin'] ) ) : null,
554 'tpg_category_padding' => isset( $_REQUEST['tpg_category_padding'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_category_padding'] ) ) : null,
555 'rt_tpg_category_font_size' => isset( $_REQUEST['rt_tpg_category_font_size'] ) ? absint( $_REQUEST['rt_tpg_category_font_size'] ) : null,
556 'tpg_image_border_radius' => isset( $_REQUEST['tpg_image_border_radius'] ) ? absint( $_REQUEST['tpg_image_border_radius'] ) : null,
557 'title_color' => isset( $_REQUEST['title_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['title_color'] ) ) : null,
558 'title_size' => isset( $_REQUEST['title_size'] ) ? absint( $_REQUEST['title_size'] ) : null,
559 'title_weight' => isset( $_REQUEST['title_weight'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['title_weight'] ) ) : null,
560 'title_alignment' => isset( $_REQUEST['title_alignment'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['title_alignment'] ) ) : null,
561 'title_hover_color' => isset( $_REQUEST['title_hover_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['title_hover_color'] ) ) : null,
562 'excerpt_color' => isset( $_REQUEST['excerpt_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['excerpt_color'] ) ) : null,
563 'excerpt_size' => isset( $_REQUEST['excerpt_size'] ) ? absint( $_REQUEST['excerpt_size'] ) : null,
564 'excerpt_weight' => isset( $_REQUEST['excerpt_weight'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['excerpt_weight'] ) ) : null,
565 'excerpt_alignment' => isset( $_REQUEST['excerpt_alignment'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['excerpt_alignment'] ) ) : null,
566 'meta_data_color' => isset( $_REQUEST['meta_data_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['meta_data_color'] ) ) : null,
567 'meta_data_size' => isset( $_REQUEST['meta_data_size'] ) ? absint( $_REQUEST['meta_data_size'] ) : null,
568 'meta_data_weight' => isset( $_REQUEST['meta_data_weight'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['meta_data_weight'] ) ) : null,
569 'meta_data_alignment' => isset( $_REQUEST['meta_data_alignment'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['meta_data_alignment'] ) ) : null,
570 ];
571
572 $data .= Fns::layoutStyle( $layoutID, $styleMeta, $layout );
573 $containerDataAttr .= '';
574 $parentClass = esc_attr( $parentClass );
575 $data .= "<div class='rt-container-fluid rt-tpg-container tpg-shortcode-main-wrapper {$parentClass}' id='{$layoutID}' {$dataArchive} {$containerDataAttr}>";
576 // widget heading.
577 $heading_tag = isset( $_REQUEST['tpg_heading_tag'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_tag'] ) ) : 'h2';
578 $heading_style = isset( $_REQUEST['tpg_heading_style'] ) && ! empty( $_REQUEST['tpg_heading_style'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_style'] ) ) : 'style1';
579 $heading_alignment = isset( $_REQUEST['tpg_heading_alignment'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_alignment'] ) ) : '';
580 $heading_link = isset( $_REQUEST['tpg_heading_link'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_link'] ) ) : '';
581
582 if ( ! empty( $arg['items'] ) && in_array( 'heading', $arg['items'] ) ) {
583 $data .= sprintf( '<div class="tpg-widget-heading-wrapper heading-%1$s %2$s">', $heading_style, $heading_alignment );
584 $data .= '<span class="tpg-widget-heading-line line-left"></span>';
585
586 if ( $heading_link ) {
587 $data .= 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( $scID ) );
588 } else {
589 $data .= sprintf( '<%1$s class="tpg-widget-heading">%2$s</%1$s>', $heading_tag, get_the_title( $scID ) );
590 }
591
592 $data .= '<span class="tpg-widget-heading-line"></span>';
593 $data .= '</div>';
594 }
595
596 $filters = ! empty( $_REQUEST['tgp_filter'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['tgp_filter'] ) ) : [];
597
598 if ( ! empty( $filters ) && ( $isGrid || $isOffset || $isWooCom ) ) {
599 $data .= "<div class='rt-layout-filter-container rt-clear'><div class='rt-filter-wrap'>";
600 $allText = apply_filters( 'tpg_filter_all_text', esc_html__( 'All', 'the-post-grid' ), $_REQUEST );
601 $selectedSubTermsForButton = null;
602
603 if ( in_array( '_taxonomy_filter', $filters ) && $taxFilter ) {
604 $filterType = ( ! empty( $_REQUEST['tgp_filter_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_filter_type'] ) ) : null );
605 $post_count = ( ! empty( $_REQUEST['tpg_post_count'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_post_count'] ) ) : null );
606 $postCountClass = ( $post_count ? ' has-post-count' : null );
607
608 $allSelect = ' selected';
609 $isTermSelected = false;
610
611 if ( $action_term && $taxFilter ) {
612 $isTermSelected = true;
613 $allSelect = null;
614 }
615
616 if ( ! $filterType || 'dropdown' === $filterType ) {
617 $data .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-taxonomy='{$taxFilter}'>";
618 $termDefaultText = $allText;
619 $dataTerm = 'all';
620 $htmlButton = '';
621 $selectedSubTerms = null;
622 $pCount = 0;
623
624 if ( ! empty( $terms ) ) {
625 $i = 0;
626
627 foreach ( $terms as $id => $term ) {
628 $pCount = $pCount + $term['count'];
629 $sT = null;
630
631 if ( $taxHierarchical ) {
632 $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id );
633
634 if ( ! empty( $subTerms ) ) {
635 $count = 0;
636 $item = $allCount = null;
637
638 foreach ( $subTerms as $stId => $t ) {
639 $count = $count + absint( $t['count'] );
640 $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null );
641 $item .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$stId}'><span class='rt-text'>{$t['name']}{$sTPostCount}</span></span>";
642 }
643
644 if ( $post_count ) {
645 $allCount = " (<span class='rt-post-count'>{$count}</span>)";
646 }
647
648 $sT .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap sub-dropdown-wrap{$postCountClass}'>";
649 $sT .= "<span class='term-default rt-filter-dropdown-default' data-term='{$id}'>
650 <span class='rt-text'>" . $allText . "{$allCount}</span>
651 <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i>
652 </span>";
653 $sT .= '<span class="term-dropdown rt-filter-dropdown">';
654 $sT .= $item;
655 $sT .= '</span>';
656 $sT .= '</div>';
657 }
658
659 if ( $action_term === $id ) {
660 $selectedSubTerms = $sT;
661 }
662 }
663
664 $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null );
665
666 if ( $action_term && $action_term == $id ) {
667 $termDefaultText = $term['name'] . $postCount;
668 $dataTerm = $id;
669 }
670
671 if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) {
672 if ( 'NOT IN' === $taxFilterOperator ) {
673 if ( ! in_array( $id, $taxFilterTerms ) && $action_term != $id ) {
674 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
675 }
676 } else {
677 if ( in_array( $id, $taxFilterTerms ) && $action_term != $id ) {
678 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
679 }
680 }
681 } else {
682 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
683 }
684
685 $i++;
686 }
687 }
688
689 $pAllCount = null;
690
691 if ( $post_count ) {
692 $pAllCount = " (<span class='rt-post-count'>{$pCount}</span>)";
693 if ( ! $action_term ) {
694 $termDefaultText = $termDefaultText . $pAllCount;
695 }
696 }
697
698 if ( ! $hide_all_button ) {
699 $htmlButton = "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'><span class='rt-text'>" . $allText . "{$pAllCount}</span></span>" . $htmlButton;
700 }
701
702 $htmlButton = sprintf( '<span class="term-dropdown rt-filter-dropdown">%s</span>', $htmlButton );
703 $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataTerm . '">
704 <span class="rt-text">' . $termDefaultText . '</span>
705 <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i>
706 </span>';
707
708 $data .= $showAllhtml . $htmlButton;
709 $data .= '</div>' . $selectedSubTerms;
710 } else {
711 $bCount = 0;
712 $bItems = null;
713 if ( ! empty( $terms ) ) {
714 foreach ( $terms as $id => $term ) {
715 $bCount = $bCount + absint( $term['count'] );
716 $sT = null;
717
718 if ( $taxHierarchical ) {
719 $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id );
720
721 if ( ! empty( $subTerms ) ) {
722 $sT .= "<div class='rt-filter-sub-tax sub-button-group'>";
723
724 foreach ( $subTerms as $stId => $t ) {
725 $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null );
726 $sT .= "<span class='rt-filter-button-item' data-term='{$stId}'>{$t['name']}{$sTPostCount}</span>";
727 }
728
729 $sT .= '</div>';
730
731 if ( $action_term === $id ) {
732 $selectedSubTermsForButton = $sT;
733 }
734 }
735 }
736
737 $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null );
738 $termSelected = null;
739
740 if ( $isTermSelected && $id == $action_term ) {
741 $termSelected = ' selected';
742 }
743
744 if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) {
745 if ( 'NOT IN' === $taxFilterOperator ) {
746 if ( ! in_array( $id, $taxFilterTerms ) ) {
747 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
748 }
749 } else {
750 if ( in_array( $id, $taxFilterTerms ) ) {
751 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
752 }
753 }
754 } else {
755 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
756 }
757 }
758 }
759
760 $data .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-button-wrap{$postCountClass}' data-taxonomy='{$taxFilter}'>";
761
762 if ( ! $hide_all_button ) {
763 $pCountH = ( $post_count ? " (<span class='rt-post-count'>{$bCount}</span>)" : null );
764 $data .= "<span class='term-button-item rt-filter-button-item {$allSelect}' data-term='all'>" . $allText . "{$pCountH}</span>";
765 }
766
767 $data .= $bItems;
768 $data .= '</div>';
769 }
770 }
771
772 // Author filter.
773 if ( in_array( '_author_filter', $filters ) ) {
774 $filterType = ( ! empty( $_REQUEST['tgp_filter_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_filter_type'] ) ) : null );
775 $post_count = ( ! empty( $_REQUEST['tpg_post_count'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_post_count'] ) ) : null );
776 $postCountClass = ( $post_count ? ' has-post-count' : null );
777 $users = get_users( apply_filters( 'tpg_author_arg', [] ) );
778 $allSelect = ' selected';
779 $isTermSelected = false;
780
781 if ( $action_term && $taxFilter ) {
782 $isTermSelected = true;
783 $allSelect = null;
784 }
785
786 if ( ! $filterType || 'dropdown' === $filterType ) {
787 $data .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}'>";
788 $termDefaultText = $allText;
789 $dataAuthor = 'all';
790 $htmlButton = '';
791 $htmlButton .= '<span class="author-dropdown rt-filter-dropdown">';
792
793 if ( ! empty( $users ) ) {
794 foreach ( $users as $user ) {
795 if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) {
796 if ( in_array( $user->ID, $filterAuthors ) ) {
797 if ( $action_term == $user->ID ) {
798 $termDefaultText = $user->display_name;
799 $dataTerm = $user->ID;
800 } else {
801 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'>{$user->display_name}</span>";
802 }
803 }
804 } else {
805 if ( $action_term == $user->ID ) {
806 $termDefaultText = $user->display_name;
807 $dataTerm = $user->ID;
808 } else {
809 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'>{$user->display_name}</span>";
810 }
811 }
812 }
813 }
814
815 if ( $isTermSelected ) {
816 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'>" . $allText . "{$pAllCount}</span>";
817 }
818
819 $htmlButton .= '</span>';
820
821 $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataAuthor . '">
822 <span class="rt-text">' . $termDefaultText . '</span>
823 <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i>
824 </span>';
825
826 $data .= $showAllhtml . $htmlButton;
827 $data .= '</div>';
828 } else {
829 $bCount = 0;
830 $bItems = null;
831
832 if ( ! empty( $users ) ) {
833 foreach ( $users as $user ) {
834 if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) {
835 if ( in_array( $user->ID, $filterAuthors ) ) {
836 $bItems .= "<span class='author-button-item rt-filter-button-item data-author='{$user->ID}'>{$user->display_name}</span>";
837 }
838 } else {
839 $bItems .= "<span class='author-button-item rt-filter-button-item data-author='{$user->ID}'>{$user->display_name}</span>";
840 }
841 }
842 }
843
844 $data .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-button-wrap{$postCountClass}' data-taxonomy='{$taxFilter}'>";
845
846 if ( ! $hide_all_button ) {
847 $pCountH = ( $post_count ? " (<span class='rt-post-count'>{$bCount}</span>)" : null );
848 $data .= "<span class='author-button-item rt-filter-button-item {$allSelect}' data-author='all'>" . $allText . "{$pCountH}</span>";
849 }
850
851 $data .= $bItems;
852 $data .= '</div>';
853 }
854 }
855
856 if ( in_array( '_search', $filters ) ) {
857 $data .= '<div class="rt-filter-item-wrap rt-search-filter-wrap">';
858 $data .= sprintf( '<input type="text" class="rt-search-input" placeholder="%s">', esc_html__( 'Search...', 'the-post-grid' ) );
859 $data .= "<span class='rt-action'>&#128269;</span>";
860 $data .= "<span class='rt-loading'></span>";
861 $data .= '</div>';
862 }
863
864 if ( in_array( '_order_by', $filters ) ) {
865 $wooFeature = ( 'product' === $postType ? true : false );
866 $orders = Options::rtPostOrderBy( $wooFeature );
867 $action_orderby = ( ! empty( $args['orderby'] ) ? trim( $args['orderby'] ) : 'none' );
868
869 if ( 'none' === $action_orderby ) {
870 $action_orderby_label = esc_html__( 'Sort By None', 'the-post-grid' );
871 } elseif ( in_array( $action_orderby, array_keys( Options::rtMetaKeyType() ) ) ) {
872 $action_orderby_label = esc_html__( 'Meta value', 'the-post-grid' );
873 } else {
874 $action_orderby_label = $orders[ $action_orderby ];
875 }
876
877 if ( 'none' !== $action_orderby ) {
878 $orders['none'] = esc_html__( 'Sort By None', 'the-post-grid' );
879 }
880
881 $data .= '<div class="rt-filter-item-wrap rt-order-by-action rt-filter-dropdown-wrap">';
882 $data .= "<span class='order-by-default rt-filter-dropdown-default' data-order-by='{$action_orderby}'>
883 <span class='rt-text-order-by'>{$action_orderby_label}</span>
884 <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i>
885 </span>";
886 $data .= '<span class="order-by-dropdown rt-filter-dropdown">';
887
888 foreach ( $orders as $orderKey => $order ) {
889 $data .= '<span class="order-by-dropdown-item rt-filter-dropdown-item" data-order-by="' . $orderKey . '">' . $order . '</span>';
890 }
891
892 $data .= '</span>';
893 $data .= '</div>';
894 }
895
896 if ( in_array( '_sort_order', $filters ) ) {
897 $action_order = ( ! empty( $args['order'] ) ? strtoupper( trim( $args['order'] ) ) : 'DESC' );
898 $data .= '<div class="rt-filter-item-wrap rt-sort-order-action">';
899 $data .= "<span class='rt-sort-order-action-arrow' data-sort-order='{$action_order}'>&nbsp;<span></span></span>";
900 $data .= '</div>';
901 }
902
903 $data .= "</div>$selectedSubTermsForButton</div>";
904 }
905
906 $data .= "<div data-title='" . esc_html__( 'Loading ...', 'the-post-grid' ) . "' class='rt-row rt-content-loader {$layout} {$masonryG} {$preLoader}'>";
907
908 if ( $gridQuery->have_posts() ) {
909 if ( $isCarousel ) {
910 $cOpt = ! empty( $_REQUEST['carousel_property'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['carousel_property'] ) ) : [];
911 $slider_js_options = apply_filters(
912 'rttpg_slider_js_options',
913 [
914 'speed' => ! empty( $_REQUEST['tpg_carousel_speed'] ) ? absint( $_REQUEST['tpg_carousel_speed'] ) : 250,
915 'autoPlayTimeOut' => ! empty( $_REQUEST['tpg_carousel_autoplay_timeout'] ) ? absint( $_REQUEST['tpg_carousel_autoplay_timeout'] ) : 5000,
916 'autoPlay' => in_array( 'auto_play', $cOpt ) ? true : false,
917 'stopOnHover' => in_array( 'stop_hover', $cOpt ) ? true : false,
918 'nav' => in_array( 'nav_button', $cOpt ) ? true : false,
919 'dots' => in_array( 'pagination', $cOpt ) ? true : false,
920 'loop' => in_array( 'loop', $cOpt ) ? true : false,
921 'lazyLoad' => in_array( 'lazyLoad', $cOpt ) ? true : false,
922 'autoHeight' => in_array( 'auto_height', $cOpt ) ? true : false,
923 'rtl' => in_array( 'rtl', $cOpt ) ? true : false,
924 ]
925 );
926 $data .= sprintf(
927 '<div class="rt-swiper-holder swiper" data-rtowl-options="%s"><div class="swiper-wrapper">',
928 htmlspecialchars( wp_json_encode( $slider_js_options ) )
929 );
930 }
931
932 $isotope_filter = null;
933
934 if ( $isIsotope ) {
935 $isotope_filter = isset( $_REQUEST['isotope_filter'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['isotope_filter'] ) ) : null;
936 $isotope_dropdown_filter = isset( $_REQUEST['isotope_filter_dropdown'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['isotope_filter_dropdown'] ) ) : null;
937 $selectedTerms = [];
938
939 if ( isset( $_REQUEST['post_filter'] ) && in_array( 'tpg_taxonomy', $_REQUEST['post_filter'] ) && isset( $_REQUEST['tpg_taxonomy'] ) && in_array( $isotope_filter, $_REQUEST['tpg_taxonomy'] ) ) {
940 $selectedTerms = ( isset( $_REQUEST[ 'term_' . $isotope_filter ] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST[ 'term_' . $isotope_filter ] ) ) : [] );
941 }
942
943 global $wp_version;
944
945 if ( version_compare( $wp_version, '4.5', '>=' ) ) {
946 //phpcs:ignore WordPress.WP.DeprecatedParameters.Get_termsParam2Found
947 $terms = get_terms(
948 $isotope_filter,
949 [
950 'meta_key' => '_rt_order', //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
951 'orderby' => 'meta_value_num',
952 'order' => 'ASC',
953 'hide_empty' => false,
954 'include' => $selectedTerms,
955 ]
956 );
957 } else {
958 $terms = get_terms(
959 [
960 'taxonomy' => $isotope_filter,
961 'orderby' => 'name',
962 'order' => 'ASC',
963 'hide_empty' => false,
964 'include' => $selectedTerms,
965 ]
966 );
967 }
968
969 $data .= '<div class="tpg-iso-filter">';
970 $htmlButton = $drop = null;
971 $fSelectTrigger = false;
972
973 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
974 foreach ( $terms as $term ) {
975 $tItem = ! empty( $_REQUEST['isotope_default_filter'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['isotope_default_filter'] ) ) : null;
976 $fSelected = null;
977
978 if ( $tItem == $term->term_id ) {
979 $fSelected = 'selected';
980 $fSelectTrigger = true;
981 }
982
983 $htmlButton .= sprintf(
984 '<button class="rt-iso-btn-%s%s" data-filter=".iso_%d">%s</button>',
985 esc_attr( $term->slug ),
986 $fSelected ? ' ' . $fSelected : '',
987 $term->term_id,
988 $term->name
989 );
990 $drop .= "<option value='.iso_{$term->term_id}' {$fSelected}>{$term->name}</option>";
991 }
992 }
993
994 if ( empty( $_REQUEST['isotope_filter_show_all'] ) ) {
995 $fSelect = ( $fSelectTrigger ? null : 'class="selected"' );
996 $htmlButton = "<button data-filter='*' {$fSelect}>" . $arg['show_all_text'] . '</button>' . $htmlButton;
997 $drop = "<option value='*' {$fSelect}>{$arg['show_all_text']}</option>" . $drop;
998 }
999
1000 $filter_count = ! empty( $_REQUEST['isotope_filter_count'] );
1001 $filter_url = ! empty( $_REQUEST['isotope_filter_url'] );
1002
1003 $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>";
1004
1005 if ( $isotope_dropdown_filter ) {
1006 $data .= "<select class='isotope-dropdown-filter'>{$drop}</select>";
1007 } else {
1008 $data .= $htmlButton;
1009 }
1010
1011 if ( ! empty( $_REQUEST['isotope_search_filter'] ) ) {
1012 $data .= "<div class='iso-search'><input type='text' class='iso-search-input' placeholder='" . esc_html__( 'Search', 'the-post-grid' ) . "' /></div>";
1013 }
1014
1015 $data .= '</div>';
1016 $data .= "<div class='rt-tpg-isotope' id='iso-tpg-{$rand}'>";
1017 }
1018
1019 $l = $offLoop = 0;
1020 $offsetBigHtml = $offsetSmallHtml = null;
1021 $tgCol = 2;
1022
1023 if ( 'layout4' === $layout ) {
1024 $tgCol = round( 12 / $dCol );
1025 }
1026
1027 $gridPostCount = 0;
1028 $arg['totalPost'] = $gridQuery->post_count;
1029
1030 while ( $gridQuery->have_posts() ) :
1031 $gridQuery->the_post();
1032
1033 if ( $tgCol == $l ) {
1034 if ( $this->l4toggle ) {
1035 $this->l4toggle = false;
1036 } else {
1037 $this->l4toggle = true;
1038 }
1039 $l = 0;
1040 }
1041
1042 $arg['postCount'] = $gridPostCount++;
1043 $pID = get_the_ID();
1044 $arg['pID'] = $pID;
1045 $arg['title'] = Fns::get_the_title( $pID, $arg );
1046 $arg['pLink'] = get_permalink();
1047 $arg['toggle'] = $this->l4toggle;
1048 $arg['author'] = '<a href="' . get_author_posts_url( get_the_author_meta( 'ID' ) ) . '">' . get_the_author() . '</a>';
1049 $comments_number = get_comments_number( $pID );
1050 $comments_text = sprintf( '(%s)', number_format_i18n( $comments_number ) );
1051 $arg['date'] = get_the_date();
1052 $arg['excerpt'] = Fns::get_the_excerpt( $pID, $arg );
1053 $arg['categories'] = get_the_term_list( $pID, 'category', null, ', ' );
1054 $arg['tags'] = get_the_term_list( $pID, 'post_tag', null, ', ' );
1055 $arg['post_count'] = get_post_meta( $pID, Fns::get_post_view_count_meta_key(), true );
1056 $arg['responsiveCol'] = [ $dCol, $tCol, $mCol ];
1057
1058 if ( $isIsotope ) {
1059 $termAs = wp_get_post_terms( $pID, $isotope_filter, [ 'fields' => 'all' ] );
1060 $isoFilter = [];
1061
1062 if ( ! empty( $termAs ) ) {
1063 foreach ( $termAs as $term ) {
1064 $isoFilter[] = 'iso_' . $term->term_id;
1065 $isoFilter[] = 'rt-item-' . esc_attr( $term->slug );
1066 }
1067 }
1068
1069 $arg['isoFilter'] = ! empty( $isoFilter ) ? implode( ' ', $isoFilter ) : '';
1070 }
1071
1072 $deptClass = null;
1073
1074 if ( ! empty( $deptAs ) ) {
1075 foreach ( $deptAs as $dept ) {
1076 $deptClass .= ' ' . $dept->slug;
1077 }
1078 }
1079
1080 if ( comments_open() ) {
1081 $arg['comment'] = "<a href='" . get_comments_link( $pID ) . "'>{$comments_text} </a>";
1082 } else {
1083 $arg['comment'] = "{$comments_text}";
1084 }
1085
1086 $imgSrc = null;
1087 $arg['smallImgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1088 $pID,
1089 $fSmallImgSize,
1090 $mediaSource,
1091 $defaultImgId,
1092 $customSmallImgSize
1093 ) : null;
1094
1095 if ( $isOffset ) {
1096 if ( 0 === $offLoop ) {
1097 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1098 $pID,
1099 $fImgSize,
1100 $mediaSource,
1101 $defaultImgId,
1102 $customImgSize
1103 ) : null;
1104 $arg['offset'] = 'big';
1105 $offsetBigHtml = Fns::get_template_html( 'layouts/' . $layout, $arg );
1106 } else {
1107 $arg['offset'] = 'small';
1108 $arg['offsetCol'] = [ $dCol, $tCol, $mCol ];
1109 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1110 $pID,
1111 'thumbnail',
1112 $mediaSource,
1113 $defaultImgId,
1114 $customImgSize
1115 ) : null;
1116 $offsetSmallHtml .= Fns::get_template_html( 'layouts/' . $layout, $arg );
1117 }
1118 } else {
1119 $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc(
1120 $pID,
1121 $fImgSize,
1122 $mediaSource,
1123 $defaultImgId,
1124 $customImgSize
1125 ) : null;
1126 $data .= Fns::get_template_html( 'layouts/' . $layout, $arg );
1127 }
1128 $offLoop++;
1129 $l++;
1130 endwhile;
1131
1132 if ( $isOffset ) {
1133 $oDCol = Fns::get_offset_col( $dCol );
1134 $oTCol = Fns::get_offset_col( $tCol );
1135 $oMCol = Fns::get_offset_col( $mCol );
1136
1137 if ( 'offset03' === $layout || 'offset04' === $layout ) {
1138 $oDCol['big'] = $oTCol['big'] = $oDCol['small'] = $oTCol['small'] = 6;
1139 $oMCol['big'] = $oMCol['small'] = 12;
1140 } elseif ( 'offset06' === $layout ) {
1141 $oDCol['big'] = 7;
1142 $oDCol['small'] = 5;
1143 }
1144
1145 $data .= "<div class='rt-col-md-{$oDCol['big']} rt-col-sm-{$oTCol['big']} rt-col-xs-{$oMCol['big']}'><div class='rt-row'>{$offsetBigHtml}</div></div>";
1146 $data .= "<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>";
1147 }
1148
1149 if ( $isIsotope || $isCarousel ) {
1150 $data .= '</div>'; // End isotope / Carousel item holder.
1151
1152 if ( $isCarousel ) {
1153 if ( in_array( 'pagination', $cOpt ) ) {
1154 $data .= '<div class="swiper-pagination"></div>';
1155 }
1156
1157 $data .= '</div>';
1158
1159 if ( in_array( 'nav_button', $cOpt ) ) {
1160 $data .= '<div class="swiper-navigation"><div class="slider-btn swiper-button-prev"></div><div class="slider-btn swiper-button-next"></div></div>';
1161 }
1162 }
1163 }
1164 } else {
1165 $not_found_text = isset( $_REQUEST['tgp_not_found_text'] ) && ! empty( $_REQUEST['tgp_not_found_text'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_not_found_text'] ) ) : esc_html__( 'No post found', 'the-post-grid' );
1166 $data .= '<p>' . $not_found_text . '</p>';
1167 }
1168
1169 $data .= $preLoaderHtml;
1170 $data .= '</div>'; // End row.
1171 $htmlUtility = null;
1172
1173 if ( $pagination && ! $isCarousel ) {
1174 if ( $isOffset || $isGridHover ) {
1175 $posts_loading_type = 'page_prev_next';
1176
1177 $htmlUtility .= "<div class='rt-cb-page-prev-next'>
1178 <span class='rt-cb-prev-btn'><i class='fa fa-angle-left' aria-hidden='true'></i></span>
1179 <span class='rt-cb-next-btn'><i class='fa fa-angle-right' aria-hidden='true'></i></span>
1180 </div>";
1181 } else {
1182 if ( 'pagination' === $posts_loading_type ) {
1183 if ( $isGrid && empty( $filters ) ) {
1184 $htmlUtility .= Fns::rt_pagination( $gridQuery );
1185 }
1186 } elseif ( 'pagination_ajax' === $posts_loading_type && ! $isIsotope ) {
1187 if ( $isGrid ) {
1188 $htmlUtility .= "<div class='rt-page-numbers'></div>";
1189 } else {
1190 $htmlUtility .= Fns::rt_pagination( $gridQuery, '', true );
1191 }
1192 } elseif ( 'load_more' === $posts_loading_type ) {
1193 $load_more_btn_text = ( ! empty( $_REQUEST['load_more_text'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['load_more_text'] ) ) : '' );
1194 $load_more_text = $load_more_btn_text ? $load_more_btn_text : esc_html__( 'Load More', 'the-post-grid' );
1195
1196 if ( $isGrid ) {
1197 $htmlUtility .= "<div class='rt-loadmore-btn rt-loadmore-action rt-loadmore-style'>
1198 <span class='rt-loadmore-text'>" . esc_html( $load_more_text ) . "</span>
1199 <div class='rt-loadmore-loading rt-ball-scale-multiple rt-2x'><div></div><div></div><div></div></div>
1200 </div>";
1201 } else {
1202 $htmlUtility .= "<div class='rt-tpg-load-more'>
1203 <button data-sc-id='' data-paged='2'>" . esc_html( $load_more_text ) . '</button>
1204 </div>';
1205 }
1206 } elseif ( 'load_on_scroll' === $posts_loading_type ) {
1207 if ( $isGrid ) {
1208 $htmlUtility .= "<div class='rt-infinite-action'>
1209 <div class='rt-infinite-loading la-fire la-2x'>
1210 <div></div>
1211 <div></div>
1212 <div></div>
1213 </div>
1214 </div>";
1215 } else {
1216 $htmlUtility .= '<div class="rt-tpg-scroll-load-more" data-trigger="1" data-sc-id="' . absint( $scID ) . '" data-paged="2"></div>';
1217 }
1218 }
1219 }
1220 }
1221
1222 if ( $htmlUtility ) {
1223 $l4toggle = null;
1224
1225 if ( 'layout4' === $layout ) {
1226 $l4toggle = 'data-l4toggle="' . $this->l4toggle . '"';
1227 }
1228
1229 if ( $isGrid || $isOffset || $isWooCom ) {
1230 $data .= '<div class="rt-pagination-wrap" data-total-pages="' . absint( $gridQuery->max_num_pages ) . '" data-posts-per-page="' . absint( $args['posts_per_page'] ) . '" data-type="' . esc_attr( $posts_loading_type ) . '" ' . $l4toggle . ' >' . $htmlUtility . '</div>';
1231 } else {
1232 $data .= '<div class="rt-tpg-utility" ' . $l4toggle . '>' . $htmlUtility . '</div>';
1233 }
1234 }
1235
1236 $data .= '</div>'; // container rt-tpg.
1237
1238 } else {
1239 $msg = esc_html__( 'Session Error !!', 'the-post-grid' );
1240 }
1241
1242 wp_send_json(
1243 [
1244 'error' => $error,
1245 'msg' => $msg,
1246 'data' => $data,
1247 ]
1248 );
1249 die();
1250 }
1251 }
1252