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