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