This repository has been archived by the owner on Mar 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjalapeno.widgets.php
144 lines (129 loc) · 5.29 KB
/
jalapeno.widgets.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* Declares a sidebar widget with an action form
*
* @author Andrew Marcus
*/
class NSJalapenoActionWidget extends WP_Widget {
function NSJalapenoActionWidget() {
parent::WP_Widget(false, $name = 'Jalapeño Action', array(
'description' => 'A Salsa action',
));
}
function form($instance) {
$action_KEY = esc_attr($instance['action_KEY']);
$title = esc_attr($instance['title']);
$actions = the_jalapeno_actions();
?>
<p>
<label for="<?php echo $this->get_field_id('action_KEY'); ?>"><?php _e('Action Key:'); ?></label>
<select id="<?php echo $this->get_field_id('action_KEY'); ?>" name="<?php echo $this->get_field_name('action_KEY'); ?>">
<option value="">- Select an action -</option>
<?php foreach ($actions as $key => $action) { ?>
<?php $name = $action['name']; ?>
<?php $selected = ($key == $action_KEY ? 'selected="selected"': ''); ?>
<option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo $key?> - <?php echo $name; ?></option>
<?php } ?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<?php
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$action_KEY = (int)($new_instance['action_KEY']);
$instance['action_KEY'] = $action_KEY;
$instance['title'] = strip_tags($new_instance['title']);
// Use the default title if it was not overridden
if (empty($instance['title'])) {
$action = the_jalapeno_actions($action_KEY);
if (!empty($action['name'])) {
$instance['title'] = $action['name'];
}
}
return $instance;
}
function widget($args, $instance) {
extract( $args );
$action_KEY = $instance['action_KEY'];
$title = apply_filters('widget_title', $instance['title']);
echo $before_widget;
if ( !empty($title) ) {
echo $before_title . $title . $after_title;
}
the_jalapeno_action($action_KEY);
echo $after_widget;
}
}
/**
* Declares a sidebar widget with an action form
*
* @author Andrew Marcus
*/
class NSJalapenoActionSignersWidget extends WP_Widget {
function NSJalapenoActionSignersWidget() {
parent::WP_Widget(false, $name = 'Jalapeño Action Signatures', array(
'description' => 'The most recent Salsa signatures',
));
}
function form($instance) {
$action_KEY = esc_attr($instance['action_KEY']);
$title = esc_attr($instance['title']);
$number = esc_attr($instance['number']);
if (empty($number)) {
$number = 10;
}
$actions = the_jalapeno_actions();
?>
<p>
<label for="<?php echo $this->get_field_id('action_KEY'); ?>"><?php _e('Action Key:'); ?></label>
<select id="<?php echo $this->get_field_id('action_KEY'); ?>" name="<?php echo $this->get_field_name('action_KEY'); ?>">
<option value="">- Select an action -</option>
<?php foreach ($actions as $key => $action) { ?>
<?php $name = $action['name']; ?>
<?php $selected = ($key == $action_KEY ? 'selected="selected"': ''); ?>
<option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo $key?> - <?php echo $name; ?></option>
<?php } ?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Number to show:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" />
</p>
<?php
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$action_KEY = (int)($new_instance['action_KEY']);
$instance['action_KEY'] = $action_KEY;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int)strip_tags($new_instance['number']);
// Use the default title if it was not overridden
if (empty($instance['title'])) {
$action = the_jalapeno_actions($action_KEY);
if (!empty($action['name'])) {
$instance['title'] = $action['name'];
}
}
return $instance;
}
function widget($args, $instance) {
extract( $args );
$action_KEY = $instance['action_KEY'];
$title = apply_filters('widget_title', $instance['title']);
$number = $instance['number'];
echo $before_widget;
if ( !empty($title) ) {
echo $before_title . $title . $after_title;
}
the_jalapeno_action_signatures($action_KEY, $number);
echo $after_widget;
}
}