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