| @@ -12,61 +12,206 @@ | ||
| 12 | 12 | * |
| 13 | 13 | * @see https://filtereverything.pro/resources/templates-overriding/ |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if ( ! defined('WPINC') ) { | |
| 17 | - wp_die(); | |
| 16 | +if ( ! defined('ABSPATH') ) { | |
| 17 | + exit; | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | -$noSelectUrl = ( empty( $filter['values'] ) ) ? $url_manager->getResetUrl() : $url_manager->getTermUrl( reset( $filter['values'] ), $filter['e_name'] ); | |
| 20 | +$noSelectUrl = ( empty( $filter['values'] ) ) ? $url_manager->getResetUrl() : $url_manager->getTermUrl( reset( $filter['values'] ), $filter['e_name'], $filter['entity'] ); | |
| 21 | +$show_term_name = true; | |
| 22 | +$is_swatch = false; | |
| 23 | +$is_brand = ( in_array( $filter['e_name'], flrt_brand_filter_entities() ) ); | |
| 24 | +$use_select2 = false; | |
| 25 | +$data_default = ''; | |
| 26 | +$preload_html = ''; | |
| 27 | +$data_color = ''; | |
| 28 | +$hide_for_apply_button_mode = flrt_check_apply_buttom_mode($set); | |
| 29 | +$is_hide_empty_terms = (isset($set['hide_empty']['value']) && $set['hide_empty']['value'] === 'yes'); | |
| 30 | +$empty_parent_filter = !empty($view_args['empty_parent_filter']) && $view_args['empty_parent_filter'] === true; | |
| 21 | 31 | |
| 32 | +$args = [ | |
| 33 | + 'hide_empty' => $set['hide_empty']['value'], | |
| 34 | + 'use_apply_button' => $view_args['use_apply_button'], | |
| 35 | + 'hide_empty_filter' => isset($set['hide_empty_filter']['value']) ? $set['hide_empty_filter']['value'] : '', | |
| 36 | +]; | |
| 37 | + | |
| 38 | +if ( flrt_get_experimental_option( 'select2_dropdowns' ) === 'on' ){ | |
| 39 | + $use_select2 = true; | |
| 40 | +} | |
| 41 | + | |
| 42 | +if ( flrt_get_experimental_option('use_color_swatches') === 'on' ) { | |
| 43 | + $swatch_taxes = flrt_get_experimental_option( 'color_swatches_taxonomies', [] ); | |
| 44 | + $is_swatch = ( in_array( $filter['e_name'], $swatch_taxes ) ); | |
| 45 | +} | |
| 46 | + | |
| 47 | +if ( $is_brand && ! $is_swatch ) { | |
| 48 | + $data_default = ' data-brand='.FLRT_PLUGIN_DIR_URL.'assets/img/no-image.png'; | |
| 49 | +} | |
| 50 | + | |
| 51 | +if ( $is_swatch ){ | |
| 52 | + $data_default = ' data-image='.FLRT_PLUGIN_DIR_URL.'assets/img/no-image.png'; | |
| 53 | +} | |
| 54 | +$rating_slugs = flrt_rating_slugs(); | |
| 55 | +$parent_filter_apply_button_data = flrt_parent_filter_apply_button_data($filter, $view_args); | |
| 56 | +$parent_filter_apply_class = flrt_parent_filter_apply_class($filter, $view_args, $terms); | |
| 57 | + | |
| 58 | +$is_parent_has_terms = false; | |
| 59 | +if(!empty($terms) && $view_args['use_apply_button']){ | |
| 60 | + | |
| 61 | + $first_term = reset($terms); | |
| 62 | + if(!empty($first_term->show_with_parent)){ | |
| 63 | + $filter['hide_until_parent_class'] = false; | |
| 64 | + } | |
| 65 | +} | |
| 22 | 66 | ?> |
| 23 | -<div class="<?php echo flrt_filter_class( $filter ); // Already escaped ?>" data-fid="<?php echo esc_attr( $filter['ID'] ); ?>"> | |
| 67 | +<div class="<?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; ?>> | |
| 24 | 68 | <?php flrt_filter_header( $filter, $terms ); // Safe, escaped ?> |
| 25 | 69 | <div class="<?php echo esc_attr( flrt_filter_content_class( $filter ) ); ?>"> |
| 26 | 70 | <?php if( ! empty( $terms ) || $view_args['ask_to_select_parent'] ): ?> |
| 27 | - <select id="wpc-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-<?php echo esc_attr( $filter['ID'] ); ?>" class="wpc-filters-widget-select"> | |
| 28 | - <?php if( $view_args['ask_to_select_parent'] !== false ) : ?> | |
| 71 | + <select id="wpc-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-<?php echo esc_attr( $filter['ID'] ); ?>" | |
| 72 | + aria-label="wpc-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-<?php echo esc_attr( $filter['ID'] ); ?>" | |
| 73 | + class="wpc-filters-widget-select" style="width: 100%"> | |
| 74 | + <?php if( $view_args['ask_to_select_parent'] !== false && !$view_args['use_apply_button'] ) : ?> | |
| 29 | 75 | <option class="wpc-dropdown-default" value="0" data-wpc-link="<?php echo esc_attr( $noSelectUrl ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-0"><?php |
| 30 | 76 | echo esc_html( $view_args['ask_to_select_parent'] ); |
| 31 | 77 | ?></option> |
| 32 | 78 | <?php else: ?> |
| 33 | - <option class="wpc-dropdown-default" value="0" data-wpc-link="<?php echo esc_attr( $noSelectUrl ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-0"><?php | |
| 34 | - echo esc_html( sprintf( __( '- Select %s -', 'filter-everything' ), $filter['label'] ) ); | |
| 35 | - ?></option> | |
| 36 | - <?php | |
| 79 | + <?php | |
| 80 | + $default_option_text = esc_html( flrt_dropdown_default_option( $filter ) ); | |
| 81 | + if( $view_args['ask_to_select_parent'] !== false && $empty_parent_filter && $view_args['use_apply_button'] ){ | |
| 82 | + $default_option_text = esc_html( $view_args['ask_to_select_parent'] ); | |
| 83 | + }?> | |
| 37 | 84 | |
| 38 | - foreach ( $terms as $id => $term_object ){ | |
| 39 | - $disabled = 0; | |
| 40 | - $selected = ( in_array( $term_object->slug, $filter['values'] ) ) ? 1 : 0; | |
| 85 | + <option<?php echo esc_html( $data_default ); ?> class="wpc-dropdown-default wpc-dropdown-default-<?php echo esc_attr( $filter['e_name'] ); ?>" value="0" data-wpc-link="<?php echo esc_attr( $noSelectUrl ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-0" data-wpc-select-parent-text="<?php echo esc_attr($view_args['ask_to_select_parent']);?>" data-wpc-default-option-text="<?php echo esc_attr(flrt_dropdown_default_option( $filter )); ?>"><?php | |
| 86 | + echo $default_option_text; | |
| 87 | + ?></option> | |
| 88 | + <?php | |
| 41 | 89 | |
| 42 | - if( isset( $term_object->wp_queried ) && $term_object->wp_queried ){ | |
| 43 | - $disabled = 1; | |
| 44 | - } | |
| 90 | + foreach ( $terms as $id => $term_object ) { | |
| 91 | + $disabled = 0; | |
| 92 | + $data_image = ''; | |
| 93 | + $data_color = ''; | |
| 94 | + $selected = ( in_array( $term_object->slug, $filter['values'] ) ) ? 1 : 0; | |
| 95 | + $term_hidden_class = ''; | |
| 96 | + $data_count = ''; | |
| 97 | + $data_rating = ''; | |
| 45 | 98 | |
| 46 | - ?> | |
| 47 | - <option class="wpc-term-count-<?php echo esc_attr( $term_object->cross_count ); ?> wpc-term-id-<?php echo esc_attr($term_object->term_id); ?>" value="<?php echo esc_attr( $term_object->term_id ); ?>" <?php selected( 1, $selected ); ?> <?php disabled( 1, $disabled ); ?> data-wpc-link="<?php echo esc_attr( $url_manager->getTermUrl( $term_object->slug, $filter['e_name'] ) ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr($filter['e_name']); ?>-<?php echo esc_attr( $id ); ?>"><?php | |
| 48 | - echo esc_html( $term_object->name ); | |
| 99 | + if( isset( $term_object->wp_queried ) && $term_object->wp_queried ){ | |
| 100 | + $disabled = 1; | |
| 101 | + } | |
| 49 | 102 | |
| 50 | - if( $set['show_count']['value'] === 'yes' ) { | |
| 51 | - echo esc_html( ' ('.$term_object->cross_count.')' ); | |
| 103 | + if ( $is_brand && ! $is_swatch ) { | |
| 104 | + $src = flrt_get_term_brand_image( $term_object->term_id, $filter ); | |
| 105 | + if ( $src ) { | |
| 106 | + $data_image = ' data-brand="' . esc_url( $src ) . '"'; | |
| 107 | + $preload_html .= '<img class="wpc-preload-img" src="'. esc_url( $src ) .'" />'."\r\n"; | |
| 108 | + } | |
| 109 | + | |
| 110 | + if ( $filter['show_term_names'] === 'no' ) { | |
| 111 | + $term_hidden_class = ' wpc-hidden-term-name'; | |
| 112 | + } | |
| 52 | 113 | } |
| 53 | - ?></option> | |
| 54 | - <?php } ?><!-- end foreach --> | |
| 114 | + | |
| 115 | + if ( $is_swatch ) { | |
| 116 | + $src = flrt_get_term_swatch_image( $term_object->term_id, $filter ); | |
| 117 | + | |
| 118 | + if ( $src ) { | |
| 119 | + $data_image = ' data-image="' . esc_url( $src ) . '"'; | |
| 120 | + $preload_html .= '<img class="wpc-preload-img" src="'. esc_url( $src ) .'" />'."\r\n"; | |
| 121 | + } else { | |
| 122 | + $maybe_color = flrt_get_term_swatch_color( $term_object->term_id, $filter ); | |
| 123 | + if ( $maybe_color ) { | |
| 124 | + $data_color = ' data-color="' . esc_attr( $maybe_color ) . '"'; | |
| 125 | + } else { | |
| 126 | + $data_color = ' data-color="none"'; | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + if ( $filter['show_term_names'] === 'no' ) { | |
| 131 | + $term_hidden_class = ' wpc-hidden-term-name'; | |
| 132 | + } | |
| 133 | + } | |
| 134 | + | |
| 135 | + if( $set['show_count']['value'] === 'yes' && $use_select2 ) { | |
| 136 | + $data_count = ' data-count="' . esc_attr( $term_object->cross_count ) . '"'; | |
| 137 | + } | |
| 138 | + | |
| 139 | + $hidden_class_for_apply_button_mode = ''; | |
| 140 | + if($hide_for_apply_button_mode){ | |
| 141 | + $hidden_class_for_apply_button_mode = ($term_object->cross_count <= 0 && $is_hide_empty_terms) ? esc_attr(' wpc-term-count-hidden-0') : ''; | |
| 142 | + if($term_object->cross_count > 0){ | |
| 143 | + $hidden_class_for_apply_button_mode .= esc_attr(' wpc-has-terms'); | |
| 144 | + } | |
| 145 | + if($selected){ | |
| 146 | + $hidden_class_for_apply_button_mode .= esc_attr(' wpc-term-count-hidden-checked-0'); | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + $rating = 0; | |
| 151 | + if( mb_strpos( $term_object->slug, 'rated-' ) !== false){ | |
| 152 | + $pieces = explode("-", $term_object->slug); | |
| 153 | + $rating = (int) isset( $pieces[1] ) ? $pieces[1] : 0; | |
| 154 | + if ($rating < 1 || $rating > 5) { | |
| 155 | + $rating = 0; | |
| 156 | + } | |
| 157 | + $data_rating = ' data-star-rating="' . (int) $rating . '"'; | |
| 158 | + } | |
| 159 | + $rating_data = (isset($rating_slugs[$term_object->slug])) ? ' data-rating-num="' . esc_attr($rating_slugs[$term_object->slug]) . '" ' : ''; | |
| 160 | + $show_with_parent_class = ''; | |
| 161 | + if(isset($term_object->show_with_parent)) { | |
| 162 | + if($term_object->show_with_parent === true){ | |
| 163 | + $show_with_parent_class = ' wpc-show-with-parent-true'; | |
| 164 | + }else{ | |
| 165 | + $show_with_parent_class = ' wpc-show-with-parent-false'; | |
| 166 | + } | |
| 167 | + } | |
| 168 | + | |
| 169 | + if (!isset($term_object->show_with_parent)) { | |
| 170 | + if ($view_args['ask_to_select_parent'] !== false && $view_args['use_apply_button']) { | |
| 171 | + if ((!$selected)) { | |
| 172 | + $show_with_parent_class = ' wpc-show-with-parent-false'; | |
| 173 | + } | |
| 174 | + } | |
| 175 | + } | |
| 176 | + | |
| 177 | + ?> | |
| 178 | + <option<?php echo $data_image . $data_color . $data_count . $data_rating; // data-* values are esc_attr/esc_url-escaped and quoted above ?> data-wpc-chip="<?php echo esc_attr( $term_object->name ); ?>" class="wpc-term-item wpc-term-count-<?php echo esc_attr( $term_object->cross_count ); ?> wpc-term-id-<?php echo esc_attr($term_object->term_id); echo esc_attr( $term_hidden_class ); ?><?php echo $hidden_class_for_apply_button_mode; ?><?php echo esc_attr($show_with_parent_class); ?>" value="<?php echo esc_attr( $term_object->term_id ); ?>" <?php selected( 1, $selected ); ?> <?php disabled( 1, $disabled ); ?> data-wpc-link="<?php echo esc_attr( $url_manager->getTermUrl( $term_object->slug, $filter['e_name'], $filter['entity'] ) ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr($filter['e_name']); ?>-<?php echo esc_attr( $id ); ?>" data-wpc-e-name="<?php echo esc_attr($filter['e_name']); ?>" data-wpc-slug="<?php echo esc_attr( $term_object->slug ); ?>" data-term-id="<?php echo esc_attr($id); ?>"<?php echo $rating_data; ?>> | |
| 179 | + <?php | |
| 180 | + if ($rating > 0){ | |
| 181 | + if($use_select2){ | |
| 182 | + $rating_html = ''; | |
| 183 | + $i = 1; | |
| 184 | + $label_star = '<span class="flrt-star-label %s">' . flrt_rating_star() . '</span>'; | |
| 185 | + while($i <=5){ | |
| 186 | + $star_class = ''; | |
| 187 | + if($i <= $rating){ | |
| 188 | + $star_class = 'flrt-star-label-hover'; | |
| 189 | + } | |
| 190 | + $rating_html .= sprintf($label_star, $star_class); | |
| 191 | + $i++; | |
| 192 | + } | |
| 193 | + echo $rating_html; | |
| 194 | + }else{ | |
| 195 | + echo sprintf( | |
| 196 | + _n('%d star', '%d stars', $rating, 'filter-everything'), | |
| 197 | + $rating | |
| 198 | + ); | |
| 199 | + } | |
| 200 | + }else{ | |
| 201 | + echo esc_html( $term_object->name ); | |
| 202 | + } | |
| 203 | + | |
| 204 | + if( $set['show_count']['value'] === 'yes' && ! $use_select2 ) { | |
| 205 | + echo esc_html( ' ('.$term_object->cross_count.')' ); | |
| 206 | + } | |
| 207 | + ?></option> | |
| 208 | + <?php } ?><!-- end foreach --> | |
| 209 | + | |
| 55 | 210 | <?php endif; ?> |
| 56 | 211 | </select> |
| 212 | + <?php echo $preload_html; ?> | |
| 57 | 213 | <?php else: |
| 58 | - if( ! flrt_is_filter_request() ){ | |
| 59 | - ?><p><?php esc_html_e('There are no terms yet', 'filter-everything' ); | |
| 60 | - | |
| 61 | - if( flrt_is_debug_mode() ){ | |
| 62 | - echo ' '.flrt_help_tip( | |
| 63 | - esc_html__('Possible reasons: 1) Filter\'s criteria doesn\'t contain any terms yet and you have to add them 2) Terms may be created, but no one post that should be filtered attached to these terms 3) You excluded all possible terms in Filter\'s options.', 'filter-everything') | |
| 64 | - ); | |
| 65 | - } | |
| 66 | - }else{ | |
| 67 | - esc_html_e('N/A', 'filter-everything' ); | |
| 68 | - } | |
| 69 | - ?></p> | |
| 70 | - <?php endif; ?><!-- end if --> | |
| 214 | + flrt_filter_no_terms_message( 'p' ); | |
| 215 | + endif; ?> | |
| 71 | 216 | </div> |
| 72 | 217 | </div> |