-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrsvpmaker-widgets.php
More file actions
273 lines (228 loc) · 11.9 KB
/
rsvpmaker-widgets.php
File metadata and controls
273 lines (228 loc) · 11.9 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
/*
RSVPMaker Widgets
*/
/**
* CPEventsWidget Class
*/
class CPEventsWidget extends WP_Widget {
function __construct() {
parent::__construct( false, $name = 'RSVPMaker Events' );
}
function widget( $args, $instance ) {
extract( $args );
global $rsvpwidget;
$rsvpwidget = true;
$title = ( isset( $instance['title'] ) ) ? sanitize_text_field( $instance['title'] ) : __( 'Events', 'rsvpmaker' );
$title = apply_filters( 'widget_title', $title );
$atts['limit'] = ( isset( $instance['limit'] ) ) ? (int) $instance['limit'] : 10;
if ( ! empty( $instance['event_type'] ) ) {
$atts['type'] = ( isset( $instance['event_type'] ) ) ? sanitize_text_field( $instance['event_type'] ) : null;
}
$dateformat = ( isset( $instance['dateformat'] ) ) ? sanitize_text_field( $instance['dateformat'] ) : 'M. j';
$break = empty( $instance['break'] ) ? ' - ' : '<br />';
global $rsvp_options;?>
<?php echo $before_widget; ?>
<?php
if ( $title ) {
echo $before_title . esc_html( $title ) . $after_title;}
?>
<?php
$events = rsvpmaker_upcoming_data( $atts );
if ( ! empty( $events ) ) {
echo "\n<ul>\n";
foreach ( $events as $event ) {
if(empty($event->ts_start)) {
$ev = get_rsvpmaker_event($event->ID);
$event->ts_start = $ev->ts_start;
}
$date = rsvpmaker_date( $dateformat, $event->ts_start );
printf( '<li class="rsvpmaker-widget-li"><span class="rsvpmaker-widget-title"><a href="%s">%s</a></span>%s<span class="rsvpmaker-widget-date">%s</span></li>', get_permalink( $event->ID ), esc_html( $event->post_title ), $break, esc_html( $date ) );
}
if ( ! empty( $rsvp_options['eventpage'] ) ) {
echo '<li><a href="' . esc_attr( $rsvp_options['eventpage'] ) . '">' . __( 'Go to Events Page', 'rsvpmaker' ) . '</a></li>';
}
echo "\n</ul>\n";
}
echo $after_widget;
?>
<?php
$rsvpwidget = false;
}
/** @see WP_Widget::update */
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = sanitize_text_field( strip_tags( $new_instance['title'] ) );
$instance['dateformat'] = sanitize_text_field( strip_tags( $new_instance['dateformat'] ) );
$instance['limit'] = (int) $new_instance['limit'];
$instance['event_type'] = sanitize_text_field( $new_instance['event_type'] );
$instance['break'] = wp_kses_post( $new_instance['break'] );
return $instance;
}
/** @see WP_Widget::form */
function form( $instance ) {
$title = ( isset( $instance['title'] ) ) ? esc_attr( $instance['title'] ) : __( 'Events', 'rsvpmaker' );
$limit = ( isset( $instance['limit'] ) ) ? $instance['limit'] : 10;
$dateformat = ( isset( $instance['dateformat'] ) ) ? $instance['dateformat'] : 'M. j';
$event_type = ( ! empty( $instance['event_type'] ) ) ? $instance['event_type'] : '';
$break = ! empty( $instance['break'] );
?>
<p><label for="<?php echo esc_attr($this->get_field_id( 'title' )); ?>"><?php esc_html_e( 'Title:', 'rsvpmaker' ); ?> <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 ); ?>" /></label></p>
<p><label for="<?php echo esc_attr($this->get_field_id( 'limit' )); ?>"><?php esc_html_e( 'Number to Show:', 'rsvpmaker' ); ?> <input class="widefat" id="<?php echo esc_attr($this->get_field_id( 'limit' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'limit' )); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" /></label></p>
<p><label for="<?php echo esc_attr($this->get_field_id( 'dateformat' )); ?>"><?php esc_html_e( 'Date Format:', 'rsvpmaker' ); ?> <input class="widefat" id="<?php echo esc_attr($this->get_field_id( 'dateformat' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'dateformat' )); ?>" type="text" value="<?php echo esc_attr( $dateformat ); ?>" /></label> (PHP <a target="_blank" href="http://us2.php.net/manual/en/function.date.php">date</a> format string)</p>
<p><label for="<?php echo esc_attr($this->get_field_id( 'break' )); ?>"><?php esc_html_e( 'Date on Separate Line:', 'rsvpmaker' ); ?> <select id="<?php echo esc_attr($this->get_field_id( 'break' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'break' )); ?>" ><option value="0" ><?php esc_html_e( 'No', 'rsvpmaker' ); ?></option><option value="1"
<?php
if ( $break ) {
echo 'selected="selected"';}
?>
><?php esc_html_e( 'Yes', 'rsvpmaker' ); ?></option> </select></label></p>
<p><label for="<?php echo esc_attr($this->get_field_id( 'event_type' )); ?>"><?php esc_html_e( 'Event Type:', 'rsvpmaker' ); ?>
<?php
$tax_terms = get_terms( 'rsvpmaker-type' );
?>
<select class="widefat" id="<?php echo esc_attr($this->get_field_id( 'event_type' )); ?>" name="<?php echo esc_attr( $this->get_field_name( 'event_type' ) ); ?>" ><option value=""><?php esc_html_e( 'All', 'rsvpmaker' ); ?></option>
<?php
if ( is_array( $tax_terms ) ) {
foreach ( $tax_terms as $tax_term ) {
$s = ( $tax_term->name == $event_type ) ? ' selected="selected" ' : '';
echo '<option value="' . esc_attr( $tax_term->name ) . '" ' . $s . '>' . esc_html( $tax_term->name ) . '</option>';
}
}
?>
</select>
</p>
<p>CSS classes:
<br />rsvpmaker-widget-li event
<br />rsvpmaker-widget-title event post title
<br />rsvpmaker-widget-date event date
</p>
<?php
}
} // class CPEventsWidget
/**
* RSVPTypeWidget Class
*/
class RSVPTypeWidget extends WP_Widget {
/** constructor */
function __construct() {
parent::__construct( 'rsvpmaker_type_widget', $name = 'RSVPMaker Events by Type' );
}
/** @see WP_Widget::widget */
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
if ( empty( $title ) ) {
$title = __( 'Events by Type', 'rsvpmaker' );
}
$atts['limit'] = ( $instance['limit'] ) ? (int) $instance['limit'] : 10;
if ( ! empty( $instance['event_type'] ) ) {
global $rsvp_options;
}
?>
<?php echo $before_widget; ?>
<?php
if ( $title ) {
echo $before_title . esc_html( $title ) . $after_title;}
?>
<?php
$args = array( 'hide_empty=0' );
$terms = get_terms( 'rsvpmaker-type', $args );
echo '<ul>';
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$count = count( $terms );
$i = 0;
foreach ( $terms as $term ) {
$i++;
$atts['type'] = $term->name;
$events = rsvpmaker_upcoming_data( $atts );
$count = sizeof( $events );
$countstr = ( $count ) ? '(' . $count . ')' : '';
printf( '<li><a href="%s">%s</a> %s</li>', esc_url( get_term_link( $term ) ), esc_html( $term->name ), $countstr );
}
}
echo "\n</ul>\n";
echo $after_widget;
?>
<?php
}
/** @see WP_Widget::update */
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = sanitize_text_field( strip_tags( $new_instance['title'] ) );
$instance['limit'] = (int) $new_instance['limit'];
return $instance;
}
/** @see WP_Widget::form */
function form( $instance ) {
$title = ( isset( $instance['title'] ) ) ? esc_attr( $instance['title'] ) : '';
$limit = ( isset( $instance['limit'] ) ) ? (int) $instance['limit'] : 10;
?>
<p><label for="<?php echo esc_attr($this->get_field_id( 'title' )); ?>"><?php esc_html_e( 'Title:', 'rsvpmaker' ); ?> <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 ); ?>" /></label></p>
<p><label for="<?php echo esc_attr($this->get_field_id( 'limit' )); ?>"><?php esc_html_e( 'Number to Show:', 'rsvpmaker' ); ?> <input class="widefat" id="<?php echo esc_attr($this->get_field_id( 'limit' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'limit' )); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" /></label></p>
<?php
}
}
class RSVPMakerByJSON extends WP_Widget {
/** constructor */
function __construct() {
parent::__construct( 'rsvpmaker_by_json', $name = 'RSVPMaker Events (API)' );
}
/** @see WP_Widget::widget */
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
if ( empty( $title ) ) {
$title = __( 'Events', 'rsvpmaker' );
}
$slug = strtolower( preg_replace( '/[^a-zA-Z0-9]/', '', $title ) );
$url = ( $instance['url'] ) ? $instance['url'] : site_url( '/wp-json/rsvpmaker/v1/future' );
$limit = ( $instance['limit'] ) ? $instance['limit'] : 0;
$morelink = ( $instance['morelink'] ) ? $instance['morelink'] : '';
global $rsvp_options;
?>
<?php echo $before_widget; ?>
<?php
if ( $title ) {
echo $before_title . esc_html( $title ) . $after_title;}
?>
<div id="rsvpjsonwidget-<?php echo esc_attr( $slug ); ?>"><?php esc_html_e( 'Loading', 'rsvpmaker' ); ?> ...</div>
<script>
jQuery(document).ready(function($) {
var jsonwidget<?php echo esc_attr( $slug ); ?> = new RSVPJsonWidget('rsvpjsonwidget-<?php echo esc_attr( $slug ); ?>','<?php echo esc_attr( $url ); ?>',<?php echo esc_attr( $limit ); ?>,'<?php echo esc_attr( $morelink ); ?>');
});
</script>
<?php
echo $after_widget;
?>
<?php
}
/** @see WP_Widget::update */
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = sanitize_text_field( strip_tags( $new_instance['title'] ) );
$instance['url'] = sanitize_text_field( trim( $new_instance['url'] ) );
$instance['limit'] = (int) $new_instance['limit'];
$instance['morelink'] = sanitize_text_field( trim( $new_instance['morelink'] ) );
return $instance;
}
/** @see WP_Widget::form */
function form( $instance ) {
$title = ( isset( $instance['title'] ) ) ? esc_attr( $instance['title'] ) : '';
if ( function_exists( 'rsvpmaker_upcoming' ) ) {
$url = ( isset( $instance['url'] ) ) ? $instance['url'] : site_url( '/wp-json/rsvpmaker/v1/future' );
} else {
$url = ( isset( $instance['url'] ) ) ? $instance['url'] : 'rsvpmaker.com/wp-json/rsvpmaker/v1/future';
}
$limit = ( isset( $instance['limit'] ) ) ? $instance['limit'] : 10;
$morelink = ( isset( $instance['morelink'] ) ) ? $instance['morelink'] : '';
?>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'rsvpmaker' ); ?> <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 ); ?>" /></label></p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'url' ) ); ?>"><?php esc_html_e( 'JSON URL:', 'rsvpmaker' ); ?> <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'url' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'url' ) ); ?>" type="text" value="<?php echo esc_attr( $url ); ?>" /></label>
<br />Examples from rsvpmaker.com demo:
<br /><a target="_blank" href="https://rsvpmaker.com/wp-json/rsvpmaker/v1/future">all future events</a>
<br /><a target="_blank" href="https://rsvpmaker.com/wp-json/rsvpmaker/v1/type/featured">events tagged type/featured</a></p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php esc_html_e( 'Maximum # Displayed:', 'rsvpmaker' ); ?> <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" /></label><br /><em>Use 0 for no limit</em></p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'morelink' ) ); ?>"><?php esc_html_e( 'URL for more events:', 'rsvpmaker' ); ?> <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'morelink' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'morelink' ) ); ?>" type="text" value="<?php echo esc_attr( $morelink ); ?>" /></label></p>
<?php
}
}