| 1 |
<?php |
| 2 |
/** |
| 3 |
* The Template for displaying filter radio buttons. |
| 4 |
* |
| 5 |
* This template can be overridden by copying it to yourtheme/filters/rating.php |
| 6 |
* |
| 7 |
* $set - array, with the Filter Set parameters |
| 8 |
* $filter - array, with the Filter parameters |
| 9 |
* $url_manager - object, of the UrlManager PHP class |
| 10 |
* $terms - array, with objects of all filter terms except excluded |
| 11 |
* |
| 12 |
* @see https://filtereverything.pro/resources/templates-overriding/ |
| 13 |
*/ |
| 14 |
|
| 15 |
if ( ! defined('ABSPATH') ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
$args = [ |
| 19 |
'hide' => $view_args['ask_to_select_parent'], |
| 20 |
'use_apply_button' => $view_args['use_apply_button'], |
| 21 |
'hide_empty' => $set['hide_empty']['value'], |
| 22 |
'hide_empty_filter' => isset($set['hide_empty_filter']['value']) ? $set['hide_empty_filter']['value'] : '', |
| 23 |
]; |
| 24 |
$selected_and_above_status = (isset($filter['selected_and_above']) && $filter['selected_and_above'] === 'yes') ? true : false; |
| 25 |
$parent_filter_apply_button_data = flrt_parent_filter_apply_button_data($filter, $view_args); |
| 26 |
$parent_filter_apply_class = flrt_parent_filter_apply_class($filter, $view_args, $terms); |
| 27 |
?> |
| 28 |
<div class="wpc-stars-rating-block <?php echo flrt_filter_class( $filter, [], $terms, $args ); // Already escaped ?><?php echo $parent_filter_apply_class; ?>" data-fid="<?php echo esc_attr( $filter['ID'] ); ?>" data-filter-e-name="<?php echo esc_attr($filter['e_name']); ?>"<?php echo $parent_filter_apply_button_data; ?>> |
| 29 |
<?php flrt_filter_header( $filter, $terms ); // Safe, escaped ?> |
| 30 |
<div class="flrt-stars-wpc-filter-content <?php echo esc_attr( flrt_filter_content_class( $filter ) ); ?>" data-selected-and-above="<?php echo $selected_and_above_status; ?>" data-show-term-count="<?php echo ( $set['show_count']['value'] === 'yes' ) ? true : false; ?>"> |
| 31 |
<ul class="flrt-stars-filter wpc-filters-ul-list wpc-filters-radio wpc-filters-list-<?php echo esc_attr( $filter['ID'] ); ?>"> |
| 32 |
<?php if( ! empty( $terms ) || $view_args['ask_to_select_parent']) : |
| 33 |
|
| 34 |
if( $view_args['ask_to_select_parent'] !== false && !$view_args['use_apply_button'] ) { ?> |
| 35 |
<li><?php echo esc_html( $view_args['ask_to_select_parent']); ?></li> |
| 36 |
<?php } else { |
| 37 |
if( $view_args['ask_to_select_parent'] !== false && $view_args['use_apply_button'] ) { ?> |
| 38 |
<li class="wpc-ask-to-parent-display"><?php echo esc_html( $view_args['ask_to_select_parent']); ?></li> |
| 39 |
<?php } |
| 40 |
$flrt_rating_slug = []; |
| 41 |
if($selected_and_above_status){ |
| 42 |
$i = 1; |
| 43 |
foreach ($terms as $id => $term_object){ |
| 44 |
$flrt_rating_slug[$i] = $term_object->slug; |
| 45 |
$i++; |
| 46 |
} |
| 47 |
} |
| 48 |
$cross_count = 0; |
| 49 |
$rating_num = 1;//rating stars |
| 50 |
$products_checked_sum = []; |
| 51 |
$star_switch = ($selected_and_above_status) ? false : true; |
| 52 |
$switch_engaged = false; |
| 53 |
foreach ( $terms as $id => $term_object ) { |
| 54 |
if(mb_strpos($term_object->slug, 'rated') !== false){ |
| 55 |
$disabled = 0; |
| 56 |
$checked = ( in_array( $term_object->slug, $filter['values'] ) ) ? 1 : 0; |
| 57 |
|
| 58 |
if ($checked){ |
| 59 |
$products_checked_sum[] = $term_object->cross_count; |
| 60 |
} |
| 61 |
if ( isset( $term_object->wp_queried ) && $term_object->wp_queried ) { |
| 62 |
$checked = 1; |
| 63 |
$disabled = 1; |
| 64 |
} |
| 65 |
|
| 66 |
if(empty($filter['values'])){ |
| 67 |
$star_switch = false; |
| 68 |
} |
| 69 |
if(!$switch_engaged){ |
| 70 |
if($checked){ |
| 71 |
$switch_engaged = true; |
| 72 |
$star_switch = ($selected_and_above_status) ? true : false; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
$slug = $term_object->slug; |
| 77 |
|
| 78 |
$link = flrt_get_filtered_term_url($term_object, $filter, $url_manager); |
| 79 |
if($selected_and_above_status){ |
| 80 |
if(isset($filter['values'][0])){ |
| 81 |
if($filter['values'][0] === $slug) $link = $url_manager->getTermUrl($slug, $filter['e_name'], $filter['entity'], '', ['rating_slug' => $slug]); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
$link_attributes = 'href="'.esc_url($link).'"'; |
| 86 |
$link_attributes .= ' class="wpc-filter-link"'; |
| 87 |
if ($selected_and_above_status){ |
| 88 |
$link_title = ($rating_num < 5) ? |
| 89 |
sprintf(esc_html__("Show products rated %d+ stars", 'filter-everything' ), $rating_num) : |
| 90 |
sprintf(esc_html__("Show products rated %d stars", 'filter-everything' ), $rating_num); |
| 91 |
} else { |
| 92 |
$link_title = sprintf(esc_html__("Show products with %d star rating", 'filter-everything' ), $rating_num); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
$link_attributes .= ' title="' . esc_attr($link_title) . '"'; |
| 97 |
$name = ( $disabled > 0 ) ? $filter['e_name'] . '-disabled' : $filter['e_name']; |
| 98 |
$data_wpc_term_count = ( $set['show_count']['value'] === 'yes' ) ? $term_object->cross_count : 0; |
| 99 |
|
| 100 |
?> |
| 101 |
<li class="wpc-radio-item wpc-term-item wpc-term-count-<?php echo esc_attr( $term_object->cross_count ); ?> wpc-term-id-<?php echo esc_attr($id); ?>" id="<?php flrt_term_id('term', $filter, $id); ?>"> |
| 102 |
<div class="wpc-term-item-content-wrapper"> |
| 103 |
<input <?php checked( 1, $checked ); disabled( 1, $disabled ) ?> type="radio" data-wpc-link="<?php echo esc_url( $link ); ?>" name="<?php echo esc_attr( $name ); ?>" id="<?php flrt_term_id('radio', $filter, $id); ?>" data-wpc-e-name="<?php echo esc_attr($filter['e_name']); ?>" data-wpc-slug="<?php echo esc_attr($term_object->slug); ?>" class="flrt-star-input" data-term-id="<?php echo esc_attr($id); ?>" data-rating-num="<?php echo $rating_num;?>"<?php echo ($checked) ? ' data-wpc-was-checked="true"' : ''; ?>/> |
| 104 |
<label class="flrt-star-label flrt-rating-numb-<?php echo $rating_num;?> <?php echo ($star_switch) ? ' flrt-star-label-hover' : '';?><?php echo ($checked) ? ' flrt-star-label-checked flrt-star-label-hover' : '';?><?php echo ($selected_and_above_status && !$checked) ? ' flrt-star-label-not-checked flrt-remove-star-check' : '';?>" data-rating-num="<?php echo $rating_num;?>" for="<?php flrt_term_id('radio', $filter, $id); ?>" data-wpc-term-count="<?php echo $data_wpc_term_count; ?>" data-star-rating-index="<?php echo $rating_num;?>"> |
| 105 |
<?php echo apply_filters( 'wpc_filters_rating_term_html', '<a '.$link_attributes.'>'.flrt_rating_star().'</a>', $link_attributes, $term_object, $filter ); ?> |
| 106 |
</label></div></li> |
| 107 |
<?php $rating_num++; |
| 108 |
} |
| 109 |
} /* end foreach */ |
| 110 |
|
| 111 |
} ?> |
| 112 |
<?php else : |
| 113 |
flrt_filter_no_terms_message(); |
| 114 |
endif; |
| 115 |
?></ul> |
| 116 |
<span id="flrt-wpc-term-count" class="wpc-term-count-value wpc-term-count-value wpc-term-count"> |
| 117 |
<?php echo (!empty($products_checked_sum) && $set['show_count']['value'] === 'yes') ? array_sum($products_checked_sum) : ''; ?> |
| 118 |
</span> |
| 119 |
</div> |
| 120 |
</div> |