| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FilterEverything\Filter; |
| 4 | 4 | |
| 5 | -if ( ! defined('WPINC') ) { | |
| 6 | - wp_die(); | |
| 5 | +if ( ! defined('ABSPATH') ) { | |
| 6 | + exit; | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | class WalkerCheckbox extends \Walker |
| @@ -86,15 +86,22 @@ | ||
| 86 | 86 | * @param array $args Optional. An array of arguments. See wp_list_categories(). Default empty array. |
| 87 | 87 | * @param int $id Optional. ID of the current category. Default 0. |
| 88 | 88 | */ |
| 89 | 89 | public function start_el( &$output, $term, $depth = 0, $args = array(), $id = 0 ) { |
| 90 | - | |
| 91 | 90 | $term_name = esc_attr( $term->name ); |
| 92 | 91 | $url_manager = $args['url_manager']; |
| 93 | 92 | $filter = $args['filter']; |
| 94 | 93 | $checked = ( in_array( $term->slug, $filter['values'] ) ) ? 1 : 0; |
| 94 | + $disabled = 0; | |
| 95 | + | |
| 96 | + if( isset( $term->wp_queried ) && $term->wp_queried ){ | |
| 97 | + $checked = 1; | |
| 98 | + $disabled = 1; | |
| 99 | + } | |
| 100 | + | |
| 95 | 101 | $id = $id ? $id : $term->term_id; |
| 96 | 102 | $toggleButton = ''; |
| 103 | + $visibility_class = ''; | |
| 97 | 104 | |
| 98 | 105 | // Don't generate an element if the term name is empty. |
| 99 | 106 | if ( '' === $term_name ) { |
| 100 | 107 | return; |
| @@ -100,10 +107,12 @@ | ||
| 100 | 107 | return; |
| 101 | 108 | } |
| 102 | 109 | |
| 103 | 110 | $atts = array(); |
| 104 | - $atts['href'] = $url_manager->getTermUrl( $term->slug, $filter['e_name'] ); | |
| 111 | + $atts['href'] = flrt_get_filtered_term_url($term, $filter, $url_manager); | |
| 105 | 112 | |
| 113 | + $atts['class'] = 'wpc-filter-link'; | |
| 114 | + | |
| 106 | 115 | $attributes = ''; |
| 107 | 116 | foreach ( $atts as $attr => $value ) { |
| 108 | 117 | if ( is_scalar( $value ) && '' !== $value && false !== $value ) { |
| 109 | 118 | $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
| @@ -112,31 +121,96 @@ | ||
| 112 | 121 | } |
| 113 | 122 | |
| 114 | 123 | $link = apply_filters( 'wpc_filters_checkbox_term_html', '<a'.$attributes.'>'.$term->name.'</a>', $attributes, $term, $filter ); |
| 115 | 124 | |
| 116 | - if ( ! empty( $args['show_count'] ) && $args['show_count'] === 'yes' ) { | |
| 117 | - $link .= ' '. flrt_get_count( $term ); | |
| 125 | + if ( isset( $args['set']['show_count']['value'] ) && $args['set']['show_count']['value'] === 'yes' ) { | |
| 126 | + $link .= flrt_filter_get_count( $term ); | |
| 118 | 127 | } |
| 128 | + $is_hide_empty_terms = (isset($args['set']['hide_empty']['value']) && $args['set']['hide_empty']['value'] === 'yes'); | |
| 129 | + $hide_for_apply_button_mode = flrt_check_apply_buttom_mode($args['set']); | |
| 119 | 130 | |
| 131 | + $show_with_parent_class = ''; | |
| 132 | + $isShowWithParentClass = false; | |
| 133 | + if(isset($term->show_with_parent)) { | |
| 134 | + if($term->show_with_parent === true){ | |
| 135 | + $isShowWithParentClass = true; | |
| 136 | + $show_with_parent_class = 'wpc-show-with-parent-true'; | |
| 137 | + }else{ | |
| 138 | + $show_with_parent_class = 'wpc-show-with-parent-false'; | |
| 139 | + } | |
| 140 | + } | |
| 141 | + | |
| 142 | + if (!isset($term->show_with_parent)) { | |
| 143 | + if ($args['ask_to_select_parent'] !== false && $args['use_apply_button']) { | |
| 144 | + if ((!$checked)) { | |
| 145 | + $show_with_parent_class = 'wpc-show-with-parent-false'; | |
| 146 | + } | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + | |
| 151 | + $hidden_class_for_apply_button_mode = ''; | |
| 152 | + $more_less_hidden_class = ''; | |
| 153 | + if ($args['isMoreLess']) { | |
| 154 | + if (!empty($term->apply_button_style) && $term->apply_button_style === true) { | |
| 155 | + $more_less_hidden_class = 'wpc-not-hidden-term'; | |
| 156 | + } | |
| 157 | + } | |
| 158 | + if($hide_for_apply_button_mode){ | |
| 159 | + $hidden_class_for_apply_button_mode = ($term->cross_count <= 0 && $is_hide_empty_terms) ? esc_attr(' wpc-term-count-hidden-0') : ''; | |
| 160 | + if($checked){ | |
| 161 | + $hidden_class_for_apply_button_mode .= esc_attr('wpc-term-count-hidden-checked-0'); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + | |
| 120 | 165 | $output .= "\t<li"; |
| 121 | 166 | $cross_count = isset( $term->cross_count ) ? esc_attr( $term->cross_count ) : ''; |
| 167 | + | |
| 122 | 168 | $css_classes = array( |
| 123 | 169 | 0 => 'wpc-checkbox-item', |
| 124 | 170 | 1 => 'wpc-term-item', |
| 125 | 171 | 3 => 'wpc-term-count-' . $cross_count, |
| 126 | - 4 => 'wpc-term-id-'.$id | |
| 172 | + 4 => 'wpc-term-id-'.$id, | |
| 173 | + 5 => $hidden_class_for_apply_button_mode, | |
| 174 | + 6 => $more_less_hidden_class, | |
| 175 | + 7 => esc_attr($show_with_parent_class), | |
| 127 | 176 | ); |
| 128 | 177 | |
| 178 | + if( $this->max_depth > 0 ) { | |
| 179 | + $visibility_class = flrt_get_status_css_class( $id, FLRT_HIERARCHY_LIST_COOKIE_NAME ); | |
| 180 | + // If has already saved visibility class | |
| 181 | + if ( $visibility_class === '' ) { | |
| 182 | + // If there is no saved visibility class | |
| 183 | + $parent_opened_elements_flipped = array_flip( $this->parent_opened_elements ); | |
| 184 | + | |
| 185 | + if ( isset( $parent_opened_elements_flipped[$id] ) ) { | |
| 186 | + $visibility_class = 'wpc-opened'; | |
| 187 | + } | |
| 188 | + | |
| 189 | + if ( $this->has_children && $checked && $visibility_class === '' ) { | |
| 190 | + $visibility_class = 'wpc-opened'; | |
| 191 | + } | |
| 192 | + } | |
| 193 | + | |
| 194 | + $css_classes[] = $visibility_class; | |
| 195 | + } | |
| 196 | + | |
| 197 | + | |
| 129 | 198 | if( $checked ){ |
| 130 | 199 | $css_classes[2] = 'wpc-term-selected'; |
| 131 | 200 | } |
| 132 | 201 | |
| 202 | + if( $disabled ){ | |
| 203 | + $css_classes[] = 'wpc-term-disabled'; | |
| 204 | + } | |
| 205 | + | |
| 133 | 206 | if( $this->has_children ){ |
| 134 | 207 | $css_classes[] = 'wpc-has-children'; |
| 135 | 208 | $toggleButton = '<i class="wpc-toggle-children-list" data-tid="'.esc_attr($term->term_id).'"></i>'; |
| 136 | 209 | } |
| 137 | 210 | |
| 138 | - if( in_array( $id, $this->has_not_empty_children ) ){ | |
| 211 | + $has_not_empty_children_flipped = array_flip( $this->has_not_empty_children ); | |
| 212 | + if( isset( $has_not_empty_children_flipped[$id] ) ){ | |
| 139 | 213 | $css_classes[] = 'wpc-has-not-empty-children'; |
| 140 | 214 | } |
| 141 | 215 | |
| 142 | 216 | $css_classes = implode( ' ', $css_classes ); |
| @@ -141,22 +215,16 @@ | ||
| 141 | 215 | |
| 142 | 216 | $css_classes = implode( ' ', $css_classes ); |
| 143 | 217 | $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : ''; |
| 144 | 218 | |
| 145 | - $visibility_class = ''; | |
| 219 | + $rating_slugs = flrt_rating_slugs(); | |
| 146 | 220 | |
| 147 | - if( $this->max_depth > 0) { | |
| 148 | - $visibility_class = ' '. flrt_get_status_css_class( $id, FLRT_HIERARCHY_LIST_COOKIE_NAME ); | |
| 149 | - } | |
| 221 | + $rating_data = (isset($rating_slugs[$term->slug])) ? ' data-rating-num="' . esc_attr($rating_slugs[$term->slug]) . '" ' : ''; | |
| 150 | 222 | |
| 151 | - if( in_array( $id, $this->parent_opened_elements ) ){ | |
| 152 | - $visibility_class = ' wpc-opened'; | |
| 153 | - } | |
| 154 | - | |
| 155 | 223 | $output .= $css_classes; |
| 156 | 224 | $output .= ' id="'.flrt_term_id('term', $filter, $id, false).'">'; |
| 157 | - $output .= '<div class="wpc-term-item-content-wrapper'.esc_attr( $visibility_class ).'"><input '.checked( 1, $checked, false ).' type="checkbox" data-wpc-link="'.esc_url($atts['href']).'"'; | |
| 158 | - $output .= ' id="'.flrt_term_id('checkbox', $filter, $id, false).'" />'."\n"; | |
| 225 | + $output .= '<div class="wpc-term-item-content-wrapper"><input '.checked( 1, $checked, false ).' '.disabled( 1, $disabled, false ).' type="checkbox" data-wpc-link="'.esc_url($atts['href']).'" data-wpc-e-name="'.esc_attr($filter['e_name']).'" data-wpc-slug="'.esc_attr($term->slug).'" data-term-id="' . esc_attr($id) . '"'; | |
| 226 | + $output .= ' id="'.flrt_term_id('checkbox', $filter, $id, false).'"' . $rating_data .' />'."\n"; | |
| 159 | 227 | $output .= '<label for="'.flrt_term_id('checkbox', $filter, $id, false).'">'; |
| 160 | 228 | $output .= "$link\n"; |
| 161 | 229 | $output .= "</label>\n"; |
| 162 | 230 | $output .= $toggleButton; |
| @@ -193,11 +261,28 @@ | ||
| 193 | 261 | |
| 194 | 262 | $parent_field = $this->db_fields['parent']; |
| 195 | 263 | |
| 196 | 264 | // Flat display. |
| 265 | + $flrt_more_less_count = flrt_more_less_count(); | |
| 266 | + $isParentFilter = flrtParentFilter($args[0]['filter']); | |
| 267 | + $hidden_terms_count = 1; | |
| 197 | 268 | if ( -1 == $max_depth ) { |
| 198 | 269 | $empty_array = array(); |
| 270 | + | |
| 199 | 271 | foreach ( $elements as $e ) { |
| 272 | + if ( $args[0]['isMoreLess'] ) { | |
| 273 | + | |
| 274 | + $is_visible = !$isParentFilter || ( isset( $e->show_with_parent ) && $e->show_with_parent === true ) || !isset( $e->show_with_parent ); | |
| 275 | + $has_results = !$args[0]['is_hide_empty_terms'] || $e->cross_count > 0; | |
| 276 | + | |
| 277 | + if ( $is_visible && $has_results ) { | |
| 278 | + if ( $hidden_terms_count <= $flrt_more_less_count ) { | |
| 279 | + $e->apply_button_style = true; | |
| 280 | + } | |
| 281 | + $hidden_terms_count++; | |
| 282 | + } | |
| 283 | + } | |
| 284 | + | |
| 200 | 285 | $this->display_element( $e, $empty_array, 1, 0, $args, $output ); |
| 201 | 286 | } |
| 202 | 287 | return $output; |
| 203 | 288 | } |
| @@ -246,8 +331,31 @@ | ||
| 246 | 331 | if ( $root->$parent_field == $e->$parent_field ) { |
| 247 | 332 | $top_level_elements[] = $e; |
| 248 | 333 | } else { |
| 249 | 334 | $children_elements[ $e->$parent_field ][] = $e; |
| 335 | + } | |
| 336 | + } | |
| 337 | + } | |
| 338 | + | |
| 339 | + /* | |
| 340 | + * Same More/Less marking as in the flat branch above. Only top-level terms | |
| 341 | + * are counted: the reveal CSS (.wpc-filters-ul-list > li.wpc-not-hidden-term) | |
| 342 | + * targets direct children of the list, nested children follow their parent. | |
| 343 | + * Without this, a hierarchical More/Less list renders with all terms hidden | |
| 344 | + * until JS re-marks them. | |
| 345 | + */ | |
| 346 | + if ( $args[0]['isMoreLess'] ) { | |
| 347 | + $has_not_empty_children_flipped = array_flip( $this->has_not_empty_children ); | |
| 348 | + | |
| 349 | + foreach ( $top_level_elements as $e ) { | |
| 350 | + $is_visible = !$isParentFilter || ( isset( $e->show_with_parent ) && $e->show_with_parent === true ) || !isset( $e->show_with_parent ); | |
| 351 | + $has_results = !$args[0]['is_hide_empty_terms'] || $e->cross_count > 0 || isset( $has_not_empty_children_flipped[ $e->term_id ] ); | |
| 352 | + | |
| 353 | + if ( $is_visible && $has_results ) { | |
| 354 | + if ( $hidden_terms_count <= $flrt_more_less_count ) { | |
| 355 | + $e->apply_button_style = true; | |
| 356 | + } | |
| 357 | + $hidden_terms_count++; | |
| 250 | 358 | } |
| 251 | 359 | } |
| 252 | 360 | } |
| 253 | 361 | |