widgets
3 years ago
base.php
3 years ago
rtTPGElementorHelper.php
3 years ago
rtTPGElementorQuery.php
3 years ago
base.php
844 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Base Abstract Class |
| 4 | * |
| 5 | * @package RT_TPG |
| 6 | */ |
| 7 | |
| 8 | use Elementor\Widget_Base; |
| 9 | use RT\ThePostGrid\Helpers\Fns; |
| 10 | use RT\ThePostGrid\Helpers\Options; |
| 11 | |
| 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 | * Base Abstract Class |
| 20 | */ |
| 21 | abstract class Custom_Widget_Base extends Widget_Base { |
| 22 | public $tpg_name; |
| 23 | public $tpg_base; |
| 24 | public $tpg_category; |
| 25 | public $tpg_archive_category; |
| 26 | public $tpg_icon; |
| 27 | public $tpg_dir; |
| 28 | public $tpg_pro_dir; |
| 29 | public $is_post_layout; |
| 30 | public $pro_label; |
| 31 | public $get_pro_message; |
| 32 | public $prefix; |
| 33 | public $last_post_id; |
| 34 | |
| 35 | public function __construct( $data = [], $args = null ) { |
| 36 | $this->tpg_category = RT_THE_POST_GRID_PLUGIN_SLUG . '-elements'; // Category /@dev |
| 37 | $this->tpg_archive_category = 'tpg-block-builder-widgets'; |
| 38 | $this->tpg_icon = 'eicon-gallery-grid tpg-grid-icon'; |
| 39 | $this->tpg_dir = dirname( ( new ReflectionClass( $this ) )->getFileName() ); |
| 40 | $this->tpg_pro_dir = null; |
| 41 | $this->pro_label = null; |
| 42 | $this->is_post_layout = null; |
| 43 | $this->get_pro_message = null; |
| 44 | $this->last_post_id = $this->get_last_post_id(); |
| 45 | |
| 46 | if ( ! rtTPG()->hasPro() ) { |
| 47 | $this->pro_label = __( '<span class="tpg-pro-label">Pro</span>', 'the-post-grid' ); |
| 48 | $this->is_post_layout = ' the-post-grid-pro-needed'; |
| 49 | $this->get_pro_message = 'Please <a target="_blank" href="' . esc_url( rtTpg()->proLink() ) . '">upgrade</a> to pro for more options'; |
| 50 | } |
| 51 | |
| 52 | parent::__construct( $data, $args ); |
| 53 | } |
| 54 | |
| 55 | public function get_pro_message( $message = 'more options.' ) { |
| 56 | if ( rtTPG()->hasPro() ) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | return 'Please <a target="_blank" href="' . esc_url( rtTpg()->proLink() ) . '">upgrade</a> to pro for ' . esc_html( $message ); |
| 61 | } |
| 62 | |
| 63 | public function get_name() { |
| 64 | return $this->tpg_base; |
| 65 | } |
| 66 | |
| 67 | public function get_title() { |
| 68 | return $this->tpg_name; |
| 69 | } |
| 70 | |
| 71 | public function get_icon() { |
| 72 | return $this->tpg_icon; |
| 73 | } |
| 74 | |
| 75 | public function get_categories() { |
| 76 | return [ $this->tpg_category ]; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * |
| 81 | * Get last post id |
| 82 | * |
| 83 | * @param string $post_type |
| 84 | * @param false $all_content |
| 85 | * |
| 86 | * @return int |
| 87 | */ |
| 88 | public function get_last_post_id( $post_type = 'post' ): int { |
| 89 | if ( is_singular( $post_type ) ) { |
| 90 | return get_the_ID(); |
| 91 | } |
| 92 | |
| 93 | global $wpdb; |
| 94 | $cache_key = 'tpg_last_post_id'; |
| 95 | $_post_id = get_transient( $cache_key ); |
| 96 | |
| 97 | if ( false === $_post_id || 'publish' !== get_post_status( $_post_id ) ) { |
| 98 | delete_transient( $cache_key ); |
| 99 | $_post_id = $wpdb->get_var( |
| 100 | $wpdb->prepare( "SELECT MAX(ID) FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_status = %s", $post_type, 'publish' ) |
| 101 | ); |
| 102 | set_transient( $cache_key, $_post_id, 12 * HOUR_IN_SECONDS ); |
| 103 | } |
| 104 | |
| 105 | return absint( $_post_id ); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | |
| 110 | //post category list |
| 111 | function tpg_category_list() { |
| 112 | $categories = get_categories( [ 'hide_empty' => false ] ); |
| 113 | $lists = []; |
| 114 | foreach ( $categories as $category ) { |
| 115 | $lists[ $category->cat_ID ] = $category->name; |
| 116 | } |
| 117 | |
| 118 | return $lists; |
| 119 | } |
| 120 | |
| 121 | // post tags lists. |
| 122 | public function tpg_tag_list() { |
| 123 | $tags = get_tags( [ 'hide_empty' => false ] ); |
| 124 | $tag_list = []; |
| 125 | foreach ( $tags as $tag ) { |
| 126 | $tag_list[ $tag->slug ] = $tag->name; |
| 127 | } |
| 128 | |
| 129 | return $tag_list; |
| 130 | } |
| 131 | |
| 132 | // Get Custom post category:. |
| 133 | protected function tpg_get_categories_by_slug( $cat ) { |
| 134 | $terms = get_terms( |
| 135 | [ |
| 136 | 'taxonomy' => $cat, |
| 137 | 'hide_empty' => true, |
| 138 | ] |
| 139 | ); |
| 140 | $options = [ '0' => esc_html__( 'All Categories', 'the-post-grid' ) ]; |
| 141 | |
| 142 | if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { |
| 143 | foreach ( $terms as $term ) { |
| 144 | $options[ $term->slug ] = $term->name; |
| 145 | } |
| 146 | } |
| 147 | return $options; |
| 148 | } |
| 149 | |
| 150 | |
| 151 | public function get_all_post_type() { |
| 152 | $post_types = get_post_types( [], 'objects' ); |
| 153 | $pt_list = []; |
| 154 | |
| 155 | foreach ( $post_types as $type ) { |
| 156 | if ( isset( $type->rewrite->slug ) ) { |
| 157 | $pt_list[ $type->rewrite->slug ] = $type->rewrite->name; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | return $pt_list; |
| 162 | } |
| 163 | |
| 164 | public static function get_post_types() { |
| 165 | $post_types = get_post_types( |
| 166 | [ |
| 167 | 'public' => true, |
| 168 | 'show_in_nav_menus' => true, |
| 169 | ], |
| 170 | 'objects' |
| 171 | ); |
| 172 | $post_types = wp_list_pluck( $post_types, 'label', 'name' ); |
| 173 | |
| 174 | return array_diff_key( $post_types, [ 'elementor_library', 'attachment' ] ); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Get Excluded Taxonomy |
| 179 | * |
| 180 | * @return string[] |
| 181 | */ |
| 182 | public static function get_excluded_taxonomy() { |
| 183 | return [ |
| 184 | 'post_format', |
| 185 | 'nav_menu', |
| 186 | 'link_category', |
| 187 | 'wp_theme', |
| 188 | 'elementor_library_type', |
| 189 | 'elementor_library_type', |
| 190 | 'elementor_library_category', |
| 191 | 'product_visibility', |
| 192 | 'product_shipping_class', |
| 193 | ]; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Get Filter markup |
| 198 | * |
| 199 | * @param $data |
| 200 | * |
| 201 | * @return string |
| 202 | */ |
| 203 | public function get_frontend_filter_markup( $data ) { |
| 204 | if ( ! rtTPG()->hasPro() |
| 205 | || ! ( $data['show_taxonomy_filter'] == 'show' || $data['show_author_filter'] == 'show' || $data['show_order_by'] == 'show' |
| 206 | || $data['show_sort_order'] == 'show' |
| 207 | || $data['show_search'] == 'show' ) |
| 208 | ) { |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | $html = null; |
| 213 | $wrapperContainer = $wrapperClass = $itemClass = $filter_btn_item_per_page = ''; |
| 214 | |
| 215 | if ( 'carousel' === $data['filter_btn_style'] ) { |
| 216 | $wrapperContainer = 'swiper'; |
| 217 | $wrapperClass = 'swiper-wrapper'; |
| 218 | $itemClass = 'swiper-slide'; |
| 219 | $filter_btn_mobile = isset( $data['filter_btn_item_per_page_mobile'] ) ? $data['filter_btn_item_per_page_mobile'] : 'auto'; |
| 220 | $filter_btn_tablet = isset( $data['filter_btn_item_per_page_tablet'] ) ? $data['filter_btn_item_per_page_tablet'] : 'auto'; |
| 221 | $filter_btn_item_per_page = "data-per-page = '{$data['filter_btn_item_per_page']}' data-per-page-mobile = '{$filter_btn_mobile}' data-per-tablet = '{$filter_btn_tablet}'"; |
| 222 | } |
| 223 | |
| 224 | $html .= "<div class='rt-layout-filter-container rt-clear'><div class='rt-filter-wrap'>"; |
| 225 | |
| 226 | if ( 'show' == $data['show_author_filter'] || 'show' == $data['show_taxonomy_filter'] ) { |
| 227 | $html .= "<div class='filter-left-wrapper {$wrapperContainer}' {$filter_btn_item_per_page}>"; |
| 228 | } |
| 229 | |
| 230 | $selectedSubTermsForButton = null; |
| 231 | |
| 232 | $filterType = $data['filter_type']; |
| 233 | $post_count = ( 'yes' == $data['filter_post_count'] ) ? true : false; |
| 234 | |
| 235 | if ( 'show' == $data['show_taxonomy_filter'] ) { |
| 236 | $postCountClass = ( $post_count ? ' has-post-count' : null ); |
| 237 | $allSelect = ' selected'; |
| 238 | $isTermSelected = false; |
| 239 | |
| 240 | $taxFilterOperator = $data['relation']; |
| 241 | |
| 242 | $section_term_key = $data['post_type'] . '_filter_taxonomy'; |
| 243 | $taxFilter = $data[ $section_term_key ]; |
| 244 | |
| 245 | $taxonomy_label = ''; |
| 246 | |
| 247 | if ( $taxFilter ) { |
| 248 | $taxonomy_details = get_taxonomy( $taxFilter ); |
| 249 | $taxonomy_label = $taxonomy_details->label; |
| 250 | } |
| 251 | |
| 252 | $default_term_key = $taxFilter . '_default_terms'; |
| 253 | $default_term = $data[ $default_term_key ]; |
| 254 | |
| 255 | $allText = $data['tax_filter_all_text'] ? $data['tax_filter_all_text'] : esc_html__( 'All ', 'the-post-grid' ) . $taxonomy_label; |
| 256 | |
| 257 | $_taxonomies = get_object_taxonomies( $data['post_type'], 'objects' ); |
| 258 | $terms = []; |
| 259 | |
| 260 | foreach ( $_taxonomies as $index => $object ) { |
| 261 | if ( $object->name != $taxFilter ) { |
| 262 | continue; |
| 263 | } |
| 264 | |
| 265 | $setting_key = $object->name . '_ids'; |
| 266 | |
| 267 | if ( ! empty( $data[ $setting_key ] ) ) { |
| 268 | $terms = $data[ $setting_key ]; |
| 269 | } else { |
| 270 | $terms = get_terms( |
| 271 | [ |
| 272 | 'taxonomy' => $taxFilter, |
| 273 | 'fields' => 'ids', |
| 274 | ] |
| 275 | ); |
| 276 | } |
| 277 | } |
| 278 | $taxFilterTerms = $terms; |
| 279 | |
| 280 | if ( $default_term && $taxFilter ) { |
| 281 | $isTermSelected = true; |
| 282 | $allSelect = null; |
| 283 | } |
| 284 | |
| 285 | if ( $filterType == 'dropdown' ) { |
| 286 | $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-taxonomy='{$taxFilter}' data-filter='taxonomy'>"; |
| 287 | $termDefaultText = $allText; |
| 288 | $dataTerm = 'all'; |
| 289 | $htmlButton = ''; |
| 290 | $selectedSubTerms = null; |
| 291 | $pCount = 0; |
| 292 | |
| 293 | if ( ! empty( $terms ) ) { |
| 294 | $i = 0; |
| 295 | |
| 296 | foreach ( $terms as $term_id ) { |
| 297 | $term = get_term( $term_id, $taxFilter, ARRAY_A ); |
| 298 | $id = $term['term_id']; |
| 299 | $pCount = $pCount + $term['count']; |
| 300 | $sT = null; |
| 301 | |
| 302 | if ( $data['tgp_filter_taxonomy_hierarchical'] == 'yes' ) { |
| 303 | $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id ); |
| 304 | |
| 305 | if ( ! empty( $subTerms ) ) { |
| 306 | $count = 0; |
| 307 | $item = $allCount = null; |
| 308 | |
| 309 | foreach ( $subTerms as $stId => $t ) { |
| 310 | $count = $count + absint( $t['count'] ); |
| 311 | $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null ); |
| 312 | $item .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$stId}'><span class='rt-text'>{$t['name']}{$sTPostCount}</span></span>"; |
| 313 | } |
| 314 | |
| 315 | if ( $post_count ) { |
| 316 | $allCount = " (<span class='rt-post-count'>{$count}</span>)"; |
| 317 | } |
| 318 | |
| 319 | $sT .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap sub-dropdown-wrap{$postCountClass}'>"; |
| 320 | $sT .= "<span class='term-default rt-filter-dropdown-default' data-term='{$id}'> |
| 321 | <span class='rt-text'>" . $allText . "</span> |
| 322 | <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i> |
| 323 | </span>"; |
| 324 | $sT .= '<span class="term-dropdown rt-filter-dropdown">'; |
| 325 | $sT .= $item; |
| 326 | $sT .= '</span>'; |
| 327 | $sT .= '</div>'; |
| 328 | } |
| 329 | |
| 330 | if ( $default_term === $id ) { |
| 331 | $selectedSubTerms = $sT; |
| 332 | } |
| 333 | } |
| 334 | $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null ); |
| 335 | |
| 336 | if ( $default_term && $default_term == $id ) { |
| 337 | $termDefaultText = $term['name'] . $postCount; |
| 338 | $dataTerm = $id; |
| 339 | } |
| 340 | |
| 341 | if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) { |
| 342 | if ( in_array( $id, $taxFilterTerms ) ) { |
| 343 | $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>"; |
| 344 | } |
| 345 | } else { |
| 346 | $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>"; |
| 347 | } |
| 348 | |
| 349 | $i ++; |
| 350 | } |
| 351 | } |
| 352 | $pAllCount = null; |
| 353 | |
| 354 | if ( $post_count ) { |
| 355 | $pAllCount = " (<span class='rt-post-count'>{$pCount}</span>)"; |
| 356 | |
| 357 | if ( ! $default_term ) { |
| 358 | $termDefaultText = $termDefaultText; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | if ( 'yes' == $data['tpg_hide_all_button'] ) { |
| 363 | $htmlButton = "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'><span class='rt-text'>" . $allText . '</span></span>' . $htmlButton; |
| 364 | } |
| 365 | |
| 366 | $htmlButton = sprintf( '<span class="term-dropdown rt-filter-dropdown">%s</span>', $htmlButton ); |
| 367 | |
| 368 | $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataTerm . '"> |
| 369 | <span class="rt-text">' . $termDefaultText . '</span> |
| 370 | <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i> |
| 371 | </span>'; |
| 372 | |
| 373 | $html .= $showAllhtml . $htmlButton; |
| 374 | $html .= '</div>' . $selectedSubTerms; |
| 375 | } else { |
| 376 | // if Button the execute. |
| 377 | // $termDefaultText = $allText; |
| 378 | |
| 379 | $bCount = 0; |
| 380 | $bItems = null; |
| 381 | |
| 382 | if ( ! empty( $terms ) ) { |
| 383 | foreach ( $terms as $term_id ) { |
| 384 | $term = get_term( $term_id, $taxFilter, ARRAY_A ); |
| 385 | $id = $term['term_id']; |
| 386 | $bCount = $bCount + absint( $term['count'] ); |
| 387 | $sT = null; |
| 388 | |
| 389 | if ( $data['tgp_filter_taxonomy_hierarchical'] == 'yes' && $data['filter_btn_style'] === 'default' && $data['filter_type'] == 'button' ) { |
| 390 | $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id ); |
| 391 | |
| 392 | if ( ! empty( $subTerms ) ) { |
| 393 | $sT .= "<div class='rt-filter-sub-tax sub-button-group '>"; |
| 394 | |
| 395 | foreach ( $subTerms as $stId => $t ) { |
| 396 | $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null ); |
| 397 | $sT .= "<span class='term-button-item rt-filter-button-item ' data-term='{$stId}'>{$t['name']}{$sTPostCount}</span>"; |
| 398 | } |
| 399 | |
| 400 | $sT .= '</div>'; |
| 401 | |
| 402 | if ( $default_term === $id ) { |
| 403 | $selectedSubTermsForButton = $sT; |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null ); |
| 408 | $termSelected = null; |
| 409 | |
| 410 | if ( $isTermSelected && $id == $default_term ) { |
| 411 | $termSelected = ' selected'; |
| 412 | } |
| 413 | |
| 414 | if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) { |
| 415 | if ( in_array( $id, $taxFilterTerms ) ) { |
| 416 | $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected} {$itemClass}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>"; |
| 417 | } |
| 418 | } else { |
| 419 | $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected} {$itemClass}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>"; |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-button-wrap{$postCountClass} {$wrapperClass}' data-taxonomy='{$taxFilter}' data-filter='taxonomy'>"; |
| 424 | |
| 425 | if ( 'yes' == $data['tpg_hide_all_button'] ) { |
| 426 | $html .= "<span class='term-button-item rt-filter-button-item {$allSelect} {$itemClass}' data-term='all'>" . $allText . '</span>'; |
| 427 | } |
| 428 | |
| 429 | $html .= $bItems; |
| 430 | |
| 431 | $html .= '</div>'; |
| 432 | |
| 433 | if ( 'carousel' === $data['filter_btn_style'] ) { |
| 434 | $html .= '<div class="swiper-navigation"><div class="swiper-button-prev slider-btn"></div><div class="swiper-button-next slider-btn"></div></div>'; |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | // TODO: Author filter. |
| 440 | if ( 'show' == $data['show_author_filter'] ) { |
| 441 | $user_el = $data['author']; |
| 442 | |
| 443 | $filterAuthors = $user_el; |
| 444 | |
| 445 | if ( ! empty( $user_el ) ) { |
| 446 | $users = get_users( apply_filters( 'tpg_author_arg', [ 'include' => $user_el ] ) ); |
| 447 | } else { |
| 448 | $users = get_users( apply_filters( 'tpg_author_arg', [] ) ); |
| 449 | } |
| 450 | |
| 451 | $allText = $allText = $data['author_filter_all_text'] ? $data['author_filter_all_text'] : esc_html__( 'All Users', 'the-post-grid' ); |
| 452 | $allSelect = ' selected'; |
| 453 | $isTermSelected = true; |
| 454 | |
| 455 | if ( $filterType == 'dropdown' ) { |
| 456 | $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-filter='author'>"; |
| 457 | $termDefaultText = $allText; |
| 458 | $dataAuthor = 'all'; |
| 459 | $htmlButton = ''; |
| 460 | $htmlButton .= '<span class="author-dropdown rt-filter-dropdown">'; |
| 461 | $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'>" . $allText . '</span>'; |
| 462 | |
| 463 | if ( ! empty( $users ) ) { |
| 464 | foreach ( $users as $user ) { |
| 465 | $user_post_count = false; |
| 466 | $post_count ? '(' . count_user_posts( $user->ID, $data['post_type'] ) . ')' : null; |
| 467 | |
| 468 | if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) { |
| 469 | if ( in_array( $user->ID, $filterAuthors ) ) { |
| 470 | if ( $default_term == $user->ID ) { |
| 471 | $termDefaultText = $user->display_name; |
| 472 | $dataTerm = $user->ID; |
| 473 | } else { |
| 474 | $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'>{$user->display_name} <span class='rt-text'>{$user_post_count}</span></span>"; |
| 475 | } |
| 476 | } |
| 477 | } else { |
| 478 | if ( $default_term == $user->ID ) { |
| 479 | $termDefaultText = $user->display_name; |
| 480 | $dataTerm = $user->ID; |
| 481 | } else { |
| 482 | $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'><span class='rt-text'>{$user->display_name} {$user_post_count}</span></span>"; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | $htmlButton .= '</span>'; |
| 489 | |
| 490 | $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataAuthor . '"> |
| 491 | <span class="rt-text">' . $termDefaultText . '</span> |
| 492 | <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i> |
| 493 | </span>'; |
| 494 | |
| 495 | $html .= $showAllhtml . $htmlButton; |
| 496 | $html .= '</div>'; |
| 497 | } else { |
| 498 | $bCount = 0; |
| 499 | $bItems = null; |
| 500 | |
| 501 | if ( ! empty( $users ) ) { |
| 502 | foreach ( $users as $user ) { |
| 503 | if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) { |
| 504 | if ( in_array( $user->ID, $filterAuthors ) ) { |
| 505 | $bItems .= "<span class='author-button-item rt-filter-button-item' data-term='{$user->ID}'>{$user->display_name}</span>"; |
| 506 | } |
| 507 | } else { |
| 508 | $bItems .= "<span class='author-button-item rt-filter-button-item' data-term='{$user->ID}'>{$user->display_name}</span>"; |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-button-wrap{$postCountClass}' data-filter='author'>"; |
| 514 | $html .= "<span class='author-button-item rt-filter-button-item {$allSelect}' data-author='all'>" . $allText . '</span>'; |
| 515 | $html .= $bItems; |
| 516 | $html .= '</div>'; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | if ( 'show' == $data['show_author_filter'] || 'show' == $data['show_taxonomy_filter'] ) { |
| 521 | $html .= '</div>'; |
| 522 | } |
| 523 | |
| 524 | if ( 'show' == $data['show_order_by'] || 'show' == $data['show_sort_order'] || 'show' == $data['show_search'] ) { |
| 525 | $html .= "<div class='filter-right-wrapper'>"; |
| 526 | } |
| 527 | |
| 528 | // TODO: Order Filter. |
| 529 | if ( 'show' == $data['show_sort_order'] ) { |
| 530 | $action_order = ( $data['order'] ? strtoupper( $data['order'] ) : 'DESC' ); |
| 531 | $html .= '<div class="rt-filter-item-wrap rt-sort-order-action" data-filter="order">'; |
| 532 | $html .= "<span class='rt-sort-order-action-arrow' data-sort-order='{$action_order}'> <span></span></span>"; |
| 533 | $html .= '</div>'; |
| 534 | } |
| 535 | |
| 536 | // TODO: Orderby Filter. |
| 537 | if ( 'show' == $data['show_order_by'] ) { |
| 538 | $wooFeature = ( $data['post_type'] == 'product' ? true : false ); |
| 539 | $orders = Options::rtPostOrderBy( $wooFeature ); |
| 540 | $action_orderby = ( ! empty( $data['orderby'] ) ? $data['orderby'] : 'none' ); |
| 541 | |
| 542 | if ( $action_orderby == 'none' ) { |
| 543 | $action_orderby_label = esc_html__( 'Sort By', 'the-post-grid' ); |
| 544 | } elseif ( in_array( $action_orderby, array_keys( Options::rtMetaKeyType() ) ) ) { |
| 545 | $action_orderby_label = esc_html__( 'Meta value', 'the-post-grid' ); |
| 546 | } else { |
| 547 | $action_orderby_label = esc_html__( 'By ', 'the-post-grid' ) . $action_orderby; |
| 548 | } |
| 549 | |
| 550 | if ( $action_orderby !== 'none' ) { |
| 551 | $orders['none'] = esc_html__( 'Sort By', 'the-post-grid' ); |
| 552 | } |
| 553 | |
| 554 | $html .= '<div class="rt-filter-item-wrap rt-order-by-action rt-filter-dropdown-wrap" data-filter="orderby">'; |
| 555 | $html .= "<span class='order-by-default rt-filter-dropdown-default' data-order-by='{$action_orderby}'> |
| 556 | <span class='rt-text-order-by'>{$action_orderby_label}</span> |
| 557 | <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i> |
| 558 | </span>"; |
| 559 | $html .= '<span class="order-by-dropdown rt-filter-dropdown">'; |
| 560 | |
| 561 | foreach ( $orders as $orderKey => $order ) { |
| 562 | $html .= '<span class="order-by-dropdown-item rt-filter-dropdown-item" data-order-by="' . $orderKey . '">' . $order . '</span>'; |
| 563 | } |
| 564 | |
| 565 | $html .= '</span>'; |
| 566 | $html .= '</div>'; |
| 567 | } |
| 568 | |
| 569 | // TODO: Search Filter. |
| 570 | if ( 'show' == $data['show_search'] ) { |
| 571 | $html .= '<div class="rt-filter-item-wrap rt-search-filter-wrap" data-filter="search">'; |
| 572 | $html .= sprintf( '<input type="text" class="rt-search-input" placeholder="%s">', esc_html__( 'Search...', 'the-post-grid' ) ); |
| 573 | $html .= "<span class='rt-action'>🔍</span>"; |
| 574 | $html .= "<span class='rt-loading'></span>"; |
| 575 | $html .= '</div>'; |
| 576 | } |
| 577 | |
| 578 | if ( 'show' == $data['show_order_by'] || 'show' == $data['show_sort_order'] || 'show' == $data['show_search'] ) { |
| 579 | $html .= '</div>'; |
| 580 | } |
| 581 | |
| 582 | $html .= "</div>$selectedSubTermsForButton</div>"; |
| 583 | |
| 584 | return $html; |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * Get Post Pagination, Load more & Scroll markup |
| 589 | * |
| 590 | * @param $query |
| 591 | * @param $data |
| 592 | * |
| 593 | * @return false|string|void |
| 594 | */ |
| 595 | public function get_pagination_markup( $query, $data ) { |
| 596 | if ( 'show' !== $data['show_pagination'] ) { |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | $htmlUtility = null; |
| 601 | |
| 602 | $posts_loading_type = $data['pagination_type']; |
| 603 | $posts_per_page = ( isset( $data['display_per_page'] ) && $data['display_per_page'] ) ? $data['display_per_page'] |
| 604 | : ( $data['post_limit'] ? $data['post_limit'] : get_option( 'posts_per_page' ) ); |
| 605 | $hide = ( $query->max_num_pages < 2 ? ' rt-hidden-elm' : null ); |
| 606 | |
| 607 | if ( $posts_loading_type == 'pagination' ) { |
| 608 | $htmlUtility .= Fns::rt_pagination( $query, $posts_per_page ); |
| 609 | } elseif ( rtTPG()->hasPro() && $posts_loading_type == 'pagination_ajax' ) { // && ! $isIsotope |
| 610 | $htmlUtility .= "<div class='rt-page-numbers'></div>"; |
| 611 | } elseif ( rtTPG()->hasPro() && $posts_loading_type == 'load_more' ) { |
| 612 | $load_more_btn_text = $data['load_more_button_text'] ? esc_html( $data['load_more_button_text'] ) : esc_html__( 'Load More', 'the-post-grid' ); |
| 613 | $htmlUtility .= "<div class='rt-loadmore-btn rt-loadmore-action rt-loadmore-style{$hide}'> |
| 614 | <span class='rt-loadmore-text'>" . $load_more_btn_text . "</span> |
| 615 | <div class='rt-loadmore-loading rt-ball-scale-multiple rt-2x'><div></div><div></div><div></div></div> |
| 616 | </div>"; |
| 617 | } elseif ( rtTPG()->hasPro() && $posts_loading_type == 'load_on_scroll' ) { |
| 618 | $htmlUtility .= "<div class='rt-infinite-action'> |
| 619 | <div class='rt-infinite-loading la-fire la-2x'> |
| 620 | <div></div><div></div><div></div> |
| 621 | </div> |
| 622 | </div>"; |
| 623 | } |
| 624 | |
| 625 | if ( $htmlUtility ) { |
| 626 | $html = "<div class='rt-pagination-wrap' data-total-pages='{$query->max_num_pages}' data-posts-per-page='{$posts_per_page}' data-type='{$posts_loading_type}' >" . $htmlUtility . '</div>'; |
| 627 | |
| 628 | return $html; |
| 629 | } |
| 630 | |
| 631 | return false; |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Get Popup Modal Markup |
| 636 | */ |
| 637 | public function get_modal_markup() { |
| 638 | $html = null; |
| 639 | $html .= '<div class="md-modal rt-md-effect" id="rt-modal"> |
| 640 | <div class="md-content"> |
| 641 | <div class="rt-md-content-holder"></div> |
| 642 | <div class="md-cls-btn"> |
| 643 | <button class="md-close"><i class="fa fa-times" aria-hidden="true"></i></button> |
| 644 | </div> |
| 645 | </div> |
| 646 | </div>'; |
| 647 | $html .= "<div class='md-overlay'></div>"; |
| 648 | |
| 649 | Fns::print_html( $html ); |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Get Archive page title |
| 654 | */ |
| 655 | public function get_archive_title() { |
| 656 | $queried_obj = get_queried_object(); |
| 657 | |
| 658 | if ( is_tag() || is_category() ) { |
| 659 | echo esc_html( $queried_obj->name ); |
| 660 | } elseif ( is_author() ) { |
| 661 | echo esc_html( $queried_obj->display_name ); |
| 662 | } elseif ( is_date() ) { |
| 663 | $year = get_query_var( 'year' ); |
| 664 | $monthnum = get_query_var( 'monthnum' ); |
| 665 | $day = get_query_var( 'day' ); |
| 666 | $time_string = $year . '/' . $monthnum . '/' . $day; |
| 667 | $time_stamp = strtotime( $time_string ); |
| 668 | Fns::print_html( date( get_option( 'date_format' ), $time_stamp ) ); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | /** |
| 673 | * Get Section Title |
| 674 | * |
| 675 | * @param $data |
| 676 | */ |
| 677 | public function get_section_title( $data ) { |
| 678 | if ( 'show' != $data['show_section_title'] ) { |
| 679 | return; |
| 680 | } |
| 681 | |
| 682 | $_is_link = false; |
| 683 | |
| 684 | if ( ! empty( $data['section_title_link']['url'] ) ) { |
| 685 | $this->add_link_attributes( 'section_title_link', $data['section_title_link'] ); |
| 686 | $_is_link = true; |
| 687 | } |
| 688 | |
| 689 | $this->add_inline_editing_attributes( 'section_title_text', 'none' ); |
| 690 | ob_start(); |
| 691 | ?> |
| 692 | |
| 693 | <div class="tpg-widget-heading-wrapper rt-clear heading-<?php echo esc_attr( $data['section_title_style'] ); ?> "> |
| 694 | <span class="tpg-widget-heading-line line-left"></span> |
| 695 | |
| 696 | <?php printf( "<%s class='tpg-widget-heading'>", esc_attr( $data['section_title_tag'] ) ); ?> |
| 697 | |
| 698 | <?php |
| 699 | if ( $_is_link ) : |
| 700 | ?> |
| 701 | <a <?php Fns::print_html( $this->get_render_attribute_string( 'section_title_link' ), true ); ?>> |
| 702 | <?php endif; ?> |
| 703 | |
| 704 | <?php |
| 705 | if ( 'page_title' == $data['section_title_source'] ) { |
| 706 | $archive_prefix = $data['title_prefix'] ? $data['title_prefix'] . ' ' : null; |
| 707 | $archive_suffix = $data['title_suffix'] ? ' ' . $data['title_suffix'] : null; |
| 708 | printf( "<span class='prefix-text'>%s</span>", esc_html( $archive_prefix ) ); |
| 709 | |
| 710 | if ( is_archive() ) { |
| 711 | Fns::get_archive_title(); |
| 712 | } elseif ( is_search() ) { |
| 713 | echo get_query_var( 's' ); |
| 714 | } else { |
| 715 | the_title(); |
| 716 | } |
| 717 | |
| 718 | printf( "<span class='suffix-text'>%s</span>", esc_html( $archive_suffix ) ); |
| 719 | } else { |
| 720 | ?> |
| 721 | <span <?php $this->print_render_attribute_string( 'section_title_text' ); ?>> |
| 722 | <?php $this->print_unescaped_setting( 'section_title_text' ); ?> |
| 723 | </span> |
| 724 | <?php |
| 725 | } |
| 726 | ?> |
| 727 | |
| 728 | <?php if ( $_is_link ) : ?> |
| 729 | </a> |
| 730 | |
| 731 | <?php endif; ?> |
| 732 | <?php printf( '</%s>', $data['section_title_tag'] ); ?> |
| 733 | <span class="tpg-widget-heading-line line-right"></span> |
| 734 | </div> |
| 735 | |
| 736 | <?php if ( isset( $data['show_cat_desc'] ) && $data['show_cat_desc'] == 'yes' && category_description( Fns::get_last_category_id() ) ) : ?> |
| 737 | <div class="tpg-category-description"> |
| 738 | <?php echo category_description( Fns::get_last_category_id() ); ?> |
| 739 | </div> |
| 740 | |
| 741 | <?php endif; ?> |
| 742 | |
| 743 | <?php |
| 744 | Fns::print_html( ob_get_clean() ); |
| 745 | } |
| 746 | |
| 747 | |
| 748 | /** |
| 749 | * Get Post Data for render post |
| 750 | * |
| 751 | * @param $data |
| 752 | * @param $total_pages |
| 753 | * @param $posts_per_page |
| 754 | * |
| 755 | * @return array |
| 756 | */ |
| 757 | public function get_render_data_set( $data, $total_pages, $posts_per_page ) { |
| 758 | $_prefix = $this->prefix; |
| 759 | |
| 760 | $data_set = [ |
| 761 | 'block_type' => 'elementor', |
| 762 | 'prefix' => $_prefix, |
| 763 | 'grid_column' => $data[ $_prefix . '_column' ], |
| 764 | 'grid_column_tablet' => isset( $data[ $_prefix . '_column_tablet' ] ) ? $data[ $_prefix . '_column_tablet' ] : '0', |
| 765 | 'grid_column_mobile' => isset( $data[ $_prefix . '_column_mobile' ] ) ? $data[ $_prefix . '_column_mobile' ] : '0', |
| 766 | 'layout' => $data[ $_prefix . '_layout' ], |
| 767 | 'pagination_type' => 'slider' === $_prefix ? 'slider' : $data['pagination_type'], |
| 768 | 'total_pages' => $total_pages, |
| 769 | 'posts_per_page' => $posts_per_page, |
| 770 | 'layout_style' => isset( $data[ $_prefix . '_layout_style' ] ) ? $data[ $_prefix . '_layout_style' ] : '', |
| 771 | 'show_title' => $data['show_title'], |
| 772 | 'excerpt_type' => $data['excerpt_type'], |
| 773 | 'excerpt_limit' => $data['excerpt_limit'], |
| 774 | 'excerpt_more_text' => $data['excerpt_more_text'], |
| 775 | 'title_limit' => $data['title_limit'], |
| 776 | 'title_limit_type' => $data['title_limit_type'], |
| 777 | 'title_visibility_style' => $data['title_visibility_style'], |
| 778 | 'post_link_type' => $data['post_link_type'], |
| 779 | 'link_target' => $data['link_target'], |
| 780 | 'hover_animation' => isset( $data['hover_animation'] ) ? $data['hover_animation'] : '', |
| 781 | 'show_thumb' => $data['show_thumb'], |
| 782 | 'show_meta' => $data['show_meta'], |
| 783 | 'show_author' => $data['show_author'], |
| 784 | 'show_author_image' => $data['show_author_image'], |
| 785 | 'show_meta_icon' => $data['show_meta_icon'], |
| 786 | 'show_category' => $data['show_category'], |
| 787 | 'show_date' => $data['show_date'], |
| 788 | 'show_tags' => $data['show_tags'], |
| 789 | 'show_comment_count' => $data['show_comment_count'], |
| 790 | 'show_comment_count_label' => isset( $data['show_comment_count_label'] ) ? $data['show_comment_count_label'] : '', |
| 791 | 'comment_count_label_singular' => isset( $data['comment_count_label_singular'] ) ? $data['comment_count_label_singular'] : '', |
| 792 | 'comment_count_label_plural' => isset( $data['comment_count_label_plural'] ) ? $data['comment_count_label_plural'] : '', |
| 793 | 'show_post_count' => $data['show_post_count'], |
| 794 | 'post_count_icon' => $data['post_count_icon'], |
| 795 | 'show_excerpt' => $data['show_excerpt'], |
| 796 | 'show_read_more' => $data['show_read_more'], |
| 797 | 'show_btn_icon' => $data['show_btn_icon'], |
| 798 | 'show_social_share' => $data['show_social_share'], |
| 799 | 'show_cat_icon' => isset( $data['show_cat_icon'] ) ? $data['show_cat_icon'] : '', |
| 800 | 'is_thumb_linked' => $data['is_thumb_linked'], |
| 801 | 'media_source' => $data['media_source'], |
| 802 | 'no_posts_found_text' => isset( $data['no_posts_found_text'] ) ? $data['no_posts_found_text'] : '', |
| 803 | 'image_size' => $data['image_size'], |
| 804 | 'image_offset' => $data['image_offset_size'], |
| 805 | 'is_default_img' => $data['is_default_img'], |
| 806 | 'default_image' => $data['default_image'], |
| 807 | 'thumb_overlay_visibility' => isset( $data['thumb_overlay_visibility'] ) ? $data['thumb_overlay_visibility'] : '', |
| 808 | 'overlay_type' => isset( $data['overlay_type'] ) ? $data['overlay_type'] : '', |
| 809 | 'title_tag' => $data['title_tag'], |
| 810 | 'post_type' => $data['post_type'], |
| 811 | 'meta_separator' => $data['meta_separator'], |
| 812 | 'readmore_icon_position' => $data['readmore_icon_position'], |
| 813 | 'read_more_label' => $data['read_more_label'], |
| 814 | 'readmore_btn_icon' => $data['readmore_btn_icon'], |
| 815 | 'category_position' => $data['category_position'], |
| 816 | 'title_position' => $data['title_position'], |
| 817 | 'category_style' => $data['category_style'], |
| 818 | 'is_thumb_lightbox' => $data['is_thumb_lightbox'], |
| 819 | 'light_box_icon' => $data['light_box_icon'], |
| 820 | 'author_prefix' => $data['author_prefix'], |
| 821 | 'cat_icon' => $data['cat_icon'], |
| 822 | 'tag_icon' => $data['tag_icon'], |
| 823 | 'date_icon' => $data['date_icon'], |
| 824 | 'user_icon' => $data['user_icon'], |
| 825 | 'meta_ordering' => $data['meta_ordering'], |
| 826 | 'comment_icon' => $data['comment_icon'], |
| 827 | 'image_custom_dimension' => ( $data['image_size'] == 'custom' && isset( $data['image_custom_dimension'] ) ) ? $data['image_custom_dimension'] : '', |
| 828 | 'img_crop_style' => ( $data['image_size'] == 'custom' && isset( $data['img_crop_style'] ) ) ? $data['img_crop_style'] : '', |
| 829 | 'show_acf' => isset( $data['show_acf'] ) ? $data['show_acf'] : '', |
| 830 | ]; |
| 831 | |
| 832 | $cf = Fns::is_acf(); |
| 833 | if ( $cf && rtTPG()->hasPro() ) { |
| 834 | $post_type = $data['post_type']; |
| 835 | $data_set['cf_group'] = $data[ $post_type . '_cf_group' ]; |
| 836 | $data_set['cf_hide_empty_value'] = $data['cf_hide_empty_value']; |
| 837 | $data_set['cf_show_only_value'] = $data['cf_show_only_value']; |
| 838 | $data_set['cf_hide_group_title'] = $data['cf_hide_group_title']; |
| 839 | } |
| 840 | |
| 841 | return $data_set; |
| 842 | } |
| 843 | } |
| 844 |