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