-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacet-widget.php
81 lines (71 loc) · 3.55 KB
/
facet-widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
class Facet_Widget extends WP_Widget {
function Facet_Widget() {
parent::WP_Widget(false, 'Facet Widget');
}
public function form($instance) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
$filters = isset($instance['facet']) ? $instance['facet'] : '';
$show_reset = isset($instance['reset']) ? $instance['reset'] : '';
$reset_title = isset($instance['reset_title']) ? $instance['reset_title'] : '';
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'facet'); ?></label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('facet') ?>"><?php _e('Show facet:', 'facet') ?></label>
<?php
global $wpdb;
//var_dump($wpdb->base_prefix);
//$table = ;
$facets = $wpdb->get_col('SELECT DISTINCT(facet_name) AS Name FROM ' . $wpdb->base_prefix . 'facetwp_index ORDER BY Name ASC');
//var_dump($res);
?>
<select name="<?php echo $this->get_field_name('facet') ?>">
<option value=""><?php _e('Choose facet', 'facet') ?></option>
<?php foreach ($facets as $facet) : ?>
<option value="<?php echo $facet ?>" <?php selected($facet, $filters) ?>><?php echo $facet ?></option>
<?php endforeach ?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('reset') ?>"><?php _e('Show reset button:', 'facet') ?></label>
<input id="<?php echo esc_attr($this->get_field_id('reset')) ?>" type="checkbox" name="<?php echo esc_attr($this->get_field_name('reset')); ?>" <?php checked($show_reset) ?>>
</p>
<p>
<label for="<?php echo $this->get_field_id('reset_title'); ?>"><?php _e('Reset button text:', 'facet'); ?></label>
<input id="<?php echo esc_attr($this->get_field_id('reset_title')); ?>" name="<?php echo esc_attr($this->get_field_name('reset_title')); ?>" type="text" value="<?php echo esc_attr($reset_title); ?>" size="15" />
</p>
<?php
}
public function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['facet'] = $new_instance['facet'];
$instance['reset'] = isset($new_instance['reset']) ? true : false;
$instance['reset_title'] = $new_instance['reset_title'];
return $instance;
}
public function widget($args, $instance) {
extract($args);
echo $before_widget;
// Title, with default
$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
if ($title)
echo $before_title . $title . $after_title;
if ($instance['facet']) {
echo do_shortcode('[facetwp facet="' . $instance['facet'] . '"]');
}
if ($instance['reset_title']) {
$reset_button = $instance['reset_title'];
} else {
$reset_button = __('Reset', 'facet');
}
//var_dump($instance['reset_title']);
if (isset( $instance['reset'] ) && $instance['reset']) {
echo '<a onclick="FWP.reset()" class="button green">' . $reset_button . '</a>';
}
echo $after_widget;
}
}