| @@ -14,26 +14,42 @@ | ||
| 14 | 14 | if ( ! defined('ABSPATH') ) { |
| 15 | 15 | exit; |
| 16 | 16 | } |
| 17 | 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 | + | |
| 25 | +$hide_empty = ($set['hide_empty']['value'] === 'yes'); | |
| 26 | +$parent_filter_apply_button_data = flrt_parent_filter_apply_button_data($filter, $view_args); | |
| 27 | +$parent_filter_apply_class = flrt_parent_filter_apply_class($filter, $view_args, $terms); | |
| 28 | +$set_id = isset( $set['ID'] ) ? esc_html( $set['ID'] ) : 0; | |
| 29 | + | |
| 18 | 30 | ?> |
| 19 | -<div class="<?php echo flrt_filter_class( $filter ); // Already escaped ?>" data-fid="<?php echo esc_attr( $filter['ID'] ); ?>"> | |
| 31 | +<div class="<?php echo esc_attr('wpc-range-filter'); ?> <?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; ?>> | |
| 20 | 32 | <?php flrt_filter_header( $filter, $terms ); // Safe, escaped ?> |
| 21 | 33 | <div class="<?php echo esc_attr( flrt_filter_content_class( $filter ) ); ?>"> |
| 22 | 34 | <div class="wpc-filters-range-inputs"> |
| 23 | - <?php if( ! empty( $terms ) || $view_args['ask_to_select_parent'] ): | |
| 35 | + <?php if( ! empty( $terms ) || $view_args['ask_to_select_parent'] || ( empty( $terms ) && $view_args['use_apply_button']) ): | |
| 24 | 36 | |
| 25 | - if( $view_args['ask_to_select_parent'] !== false ) { ?> | |
| 37 | + if( $view_args['ask_to_select_parent'] !== false && !$view_args['use_apply_button']) { ?> | |
| 26 | 38 | <div><?php echo esc_html( $view_args['ask_to_select_parent'] ); ?></div> |
| 27 | 39 | <?php } else { |
| 28 | - | |
| 40 | + if( $view_args['ask_to_select_parent'] !== false && $view_args['use_apply_button'] ) { ?> | |
| 41 | + <div class="wpc-ask-to-parent-display"><?php echo esc_html( $view_args['ask_to_select_parent'] ); ?></div> | |
| 42 | + <?php } | |
| 29 | 43 | $minName = flrt_range_input_name( $filter['slug'] ); |
| 30 | 44 | $maxName = flrt_range_input_name( $filter['slug'], 'max' ); |
| 45 | + $e_name_min = flrt_range_input_name( $filter['e_name'], 'min'); | |
| 46 | + $e_name_max = flrt_range_input_name( $filter['e_name'], 'max'); | |
| 31 | 47 | $absMin = $absMax = 0; |
| 32 | 48 | $hasSliderClass = ( $filter['range_slider'] === 'yes' ) ? 'wpc-form-has-slider' : 'wpc-form-without-slider'; |
| 49 | + $allPostsAbsMin = $allPostsAbsMax = 0; | |
| 33 | 50 | |
| 34 | 51 | foreach ( $terms as $term ) { |
| 35 | - | |
| 36 | 52 | foreach( $terms as $term ) { |
| 37 | 53 | if( isset($term->min) ) { |
| 38 | 54 | $absMin = $term->min; |
| 39 | 55 | } |
| @@ -39,27 +55,157 @@ | ||
| 39 | 55 | } |
| 40 | 56 | if( isset( $term->max ) ) { |
| 41 | 57 | $absMax = $term->max; |
| 42 | 58 | } |
| 59 | + | |
| 60 | + if( isset($term->abs_values['abs_min']) ) { | |
| 61 | + $allPostsAbsMin = $term->abs_values['abs_min']; | |
| 62 | + } | |
| 63 | + | |
| 64 | + if( isset($term->abs_values['abs_max']) ) { | |
| 65 | + $allPostsAbsMax = $term->abs_values['abs_max']; | |
| 66 | + } | |
| 43 | 67 | } |
| 44 | 68 | } |
| 45 | 69 | |
| 70 | + if($allPostsAbsMax < $allPostsAbsMin){ | |
| 71 | + $allPostsAbsMax = $allPostsAbsMin; | |
| 72 | + } | |
| 73 | + | |
| 46 | 74 | $max = isset( $filter['values']['max'] ) ? $filter['values']['max'] : $absMax; |
| 47 | 75 | $min = isset( $filter['values']['min'] ) ? $filter['values']['min'] : $absMin; |
| 76 | + $link = $url_manager->getFormActionOrFullPageUrl(); | |
| 77 | + $range_link = $url_manager->getFormActionOrFullPageUrl(true); | |
| 78 | + $checked_min = ''; | |
| 79 | + $checked_max = ''; | |
| 80 | + if(!empty($filter['values']['min'])){ | |
| 81 | + $checked_min = $filter['values']['min']; | |
| 82 | + } | |
| 83 | + if(!empty($filter['values']['max'])){ | |
| 84 | + $checked_max = $filter['values']['max']; | |
| 85 | + } | |
| 48 | 86 | |
| 87 | + $name = $filter['e_name']; | |
| 88 | + | |
| 49 | 89 | ?> |
| 50 | - <form action="<?php echo esc_url( $url_manager->getFormActionOrFullPageUrl() ); ?>" method="GET" class="wpc-filter-range-form <?php echo esc_attr( $hasSliderClass ); ?>" id="wpc-filter-range-form-<?php echo esc_attr($filter['ID']); ?>"> | |
| 90 | + <?php if (!empty($filter['show_range_list']) && $filter['show_range_list'] === 'yes') { ?> | |
| 91 | + <?php if (!empty($filter['range_list_input'])) { ?> | |
| 92 | + <ul class="wpc-filters-ul-list wpc-filters-radio wpc-filters-list-<?php echo esc_attr($filter['ID']); ?>"> | |
| 93 | + <?php foreach ($filter['range_list_input'] as $id => $range_list_input) { | |
| 94 | + $label_text = $range_list_input['range_list_range_text']; | |
| 95 | + if(empty($label_text)){ | |
| 96 | + $label_text = $range_list_input['range_list_min_val'] . ' — ' . $range_list_input['range_list_max_val']; | |
| 97 | + } | |
| 98 | + | |
| 99 | + $temp_min = $range_list_input['range_list_min_val']; | |
| 100 | + $temp_max = $range_list_input['range_list_max_val']; | |
| 101 | + | |
| 102 | + if(empty($temp_min) && $id == count($filter['range_list_input'])){ | |
| 103 | + $temp_min = round($allPostsAbsMin); | |
| 104 | + } | |
| 105 | + | |
| 106 | + if(empty($temp_max) && $id == count($filter['range_list_input'])){ | |
| 107 | + $temp_max = round($allPostsAbsMax); | |
| 108 | + } | |
| 109 | + | |
| 110 | + | |
| 111 | + $checked = false; | |
| 112 | + if(isset($range_list_input['range_list_min_val']) && isset($range_list_input['range_list_max_val'])){ | |
| 113 | + if(empty($range_list_input['range_list_min_val'])){ | |
| 114 | + $range_list_input['range_list_min_val'] = ''; | |
| 115 | + } | |
| 116 | + if(empty($range_list_input['range_list_max_val'])){ | |
| 117 | + $range_list_input['range_list_max_val'] = ''; | |
| 118 | + } | |
| 119 | + if($range_list_input['range_list_min_val'] === $checked_min && $range_list_input['range_list_max_val'] === $checked_max){ | |
| 120 | + $checked = true; | |
| 121 | + } | |
| 122 | + } | |
| 123 | + $link_args = []; | |
| 124 | + if(!empty($range_list_input['range_list_min_val'])){ | |
| 125 | + $link_args[$minName] = $range_list_input['range_list_min_val']; | |
| 126 | + } | |
| 127 | + | |
| 128 | + if(!empty($range_list_input['range_list_max_val'])){ | |
| 129 | + $link_args[$maxName] = $range_list_input['range_list_max_val']; | |
| 130 | + } | |
| 131 | + | |
| 132 | + $range_link = remove_query_arg( array( $minName, $maxName ), $range_link ); | |
| 133 | + | |
| 134 | + if(!empty($link_args) && !$checked){ | |
| 135 | + $range_link = add_query_arg( $link_args, $range_link ); | |
| 136 | + } | |
| 137 | + | |
| 138 | + if(!empty($terms[$e_name_min]->name)){ | |
| 139 | + $terms[$e_name_min]->name = $label_text; | |
| 140 | + } | |
| 141 | + | |
| 142 | + if(!empty($terms[$e_name_min]->cross_count)){ | |
| 143 | + $terms[$e_name_min]->cross_count = 0; | |
| 144 | + } | |
| 145 | + | |
| 146 | + if(!empty($terms[$e_name_min]->range_list_input[$id])){ | |
| 147 | + $terms[$e_name_min]->cross_count = $terms[$e_name_min]->range_list_input[$id]; | |
| 148 | + } | |
| 149 | + $link_attributes = 'href="'.esc_url($range_link).'"'; | |
| 150 | + $link_attributes .= ' class="wpc-filter-link"'; | |
| 151 | + $disabled = 0; | |
| 152 | + if($terms[$e_name_min]->cross_count <= 0){ | |
| 153 | + $disabled = 1; | |
| 154 | + } | |
| 155 | + $disabled_class = $disabled ? ' wpc-term-disabled' : ''; | |
| 156 | + $active_class = $checked ? ' wpc-term-selected' : ''; | |
| 157 | + $apply_botton_class = ''; | |
| 158 | + if($hide_empty && $disabled){ | |
| 159 | + $apply_botton_class = ' wpc-term-count-hidden-0'; | |
| 160 | + } | |
| 161 | + ?> | |
| 162 | + | |
| 163 | + <li class="wpc-radio-item wpc-term-item<?php echo esc_attr( $active_class ); ?> wpc-term-count-<?php echo esc_attr( $terms[$e_name_min]->cross_count ); ?> wpc-term-id-<?php echo esc_attr($id); ?><?php echo esc_attr($apply_botton_class); ?>" id="<?php flrt_term_id('term', $filter, $id); ?>"> | |
| 164 | + <div class="wpc-term-item-content-wrapper"> | |
| 165 | + <input type="radio" name="<?php echo esc_attr($name . '-' . $set_id); ?>" id="<?php flrt_term_id('radio', $filter, $id); ?>" class="wpc-range-list-item" data-wpc-link="<?php echo esc_url( $range_link ); ?>" data-wpc-e-name="<?php echo esc_attr($filter['e_name']); ?>" | |
| 166 | + data-wpc-slug-min="<?php echo esc_attr($terms[$e_name_min]->slug); ?>" | |
| 167 | + data-wpc-slug-max="<?php echo esc_attr($terms[$e_name_max]->slug); ?>" | |
| 168 | + data-min="<?php echo esc_attr($temp_min); ?>" | |
| 169 | + data-max="<?php echo esc_attr($temp_max); ?>" | |
| 170 | + data-term-id="<?php echo esc_attr($id); ?>" | |
| 171 | + <?php checked( 1, $checked ); ?><?php echo ($checked) ? ' data-wpc-was-checked="true"' : ''; ?> | |
| 172 | + /> | |
| 173 | + <label for="<?php flrt_term_id('radio', $filter, $id); ?>"> | |
| 174 | + <?php | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * Allow developers to change filter terms html | |
| 178 | + */ | |
| 179 | + echo apply_filters( 'wpc_filters_radio_term_html', '<a '.$link_attributes.'>'.$terms[$e_name_min]->name.'</a>', $link_attributes, $terms[$e_name_min], $filter ); | |
| 180 | + | |
| 181 | + ?> | |
| 182 | + <?php flrt_filter_count($terms[$e_name_min], $set['show_count']['value'] ); ?> | |
| 183 | + </label> | |
| 184 | + </div> | |
| 185 | + </li> | |
| 186 | + <?php } ?> | |
| 187 | + </ul> | |
| 188 | + <?php } ?> | |
| 189 | + <?php }?> | |
| 190 | + <form action="<?php echo esc_url( $link ); ?>" method="GET" class="wpc-filter-range-form <?php echo esc_attr( $hasSliderClass ); ?>" id="wpc-filter-range-form-<?php echo esc_attr($filter['ID']); ?>"> | |
| 51 | 191 | <div class="wpc-filters-range-wrapper"> |
| 52 | 192 | <div class="wpc-filters-range-column wpc-filters-range-min-column"> |
| 53 | 193 | <?php // if there are value in $_GET we have to put it into field ?> |
| 54 | 194 | <?php // attr step should be configured in options ?> |
| 55 | - <input type="number" class="wpc-filters-range-min" name="<?php echo esc_attr( $minName ); ?>" value="<?php echo esc_attr( $min ); ?>" step="<?php echo esc_attr( $filter['step'] ); ?>" data-min="<?php echo esc_attr( $absMin ); ?>" /> | |
| 195 | + <input type="number" class="wpc-filters-range-min" name="<?php echo esc_attr( $minName ); ?>" value="<?php echo esc_attr( $min ); ?>" step="<?php echo esc_attr( $filter['step'] ); ?>" data-min="<?php echo esc_attr( $absMin ); ?>" data-abs-min="<?php echo esc_attr( round($allPostsAbsMin) ); ?>" data-wpc-e-name="<?php echo esc_attr($filter['e_name']); ?>" data-wpc-slug="<?php echo esc_attr( $minName ); ?>" | |
| 196 | + data-wpc-chips-text="<?php echo esc_attr( esc_html__(flrt_ucfirst_term_slug_name('min'), 'filter-everything') ); ?>" | |
| 197 | + data-wpc-chip-label="<?php echo esc_attr( isset( $filter['min_num_label'] ) ? $filter['min_num_label'] : '' ); ?>" | |
| 198 | + data-fid="<?php echo esc_attr( $filter['ID'] ); ?>"/> | |
| 56 | 199 | <button class="wpc-range-clear" type="button" title="<?php esc_html_e('Reset', 'filter-everything' ) ?>"> |
| 57 | 200 | <span class="wpc-search-clear-icon">×</span> |
| 58 | 201 | </button> |
| 59 | 202 | </div> |
| 60 | 203 | <div class="wpc-filters-range-column wpc-filters-range-max-column"> |
| 61 | - <input type="number" class="wpc-filters-range-max" name="<?php echo esc_attr( $maxName ); ?>" value="<?php echo esc_attr( $max ); ?>" step="<?php echo esc_attr( $filter['step'] ); ?>" data-max="<?php echo esc_attr( $absMax ); ?>" /> | |
| 204 | + <input type="number" class="wpc-filters-range-max" name="<?php echo esc_attr( $maxName ); ?>" value="<?php echo esc_attr( $max ); ?>" step="<?php echo esc_attr( $filter['step'] ); ?>" data-max="<?php echo esc_attr( $absMax ); ?>" data-abs-max="<?php echo esc_attr( round($allPostsAbsMax) ); ?>" data-wpc-e-name="<?php echo esc_attr($filter['e_name']); ?>" data-wpc-slug="<?php echo esc_attr( $maxName ); ?>" | |
| 205 | + data-wpc-chips-text="<?php echo esc_attr( esc_html__(flrt_ucfirst_term_slug_name('max'), 'filter-everything') ); ?>" | |
| 206 | + data-wpc-chip-label="<?php echo esc_attr( isset( $filter['max_num_label'] ) ? $filter['max_num_label'] : '' ); ?>" | |
| 207 | + data-fid="<?php echo esc_attr( $filter['ID'] ); ?>"/> | |
| 62 | 208 | <button class="wpc-range-clear" type="button" title="<?php esc_html_e('Reset', 'filter-everything' ) ?>"> |
| 63 | 209 | <span class="wpc-search-clear-icon">×</span> |
| 64 | 210 | </button> |
| 65 | 211 | </div> |