forked from thecity/thecity-plaza-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
the_city_plaza.php
287 lines (240 loc) · 10.6 KB
/
the_city_plaza.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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
/*
Plugin Name: The City Plaza Widget
Plugin URI: http://developer.onthecity.org/thecity-plugins/wordpress/
Description: This widget allows you to pull your OnTheCity.org plaza information into your WordPress website.
Author: Wes Hays
Version: 0.8.6
Author URI: http://www.OnTheCity.org
*/
include_once 'plaza_scripts.php';
require_once 'lib/plaza-php/lib/the_city.php';
require_once 'lib/plaza_wordpress_cache.php';
class The_City_Plaza_Widget extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'the_city_plaza_widget',
'description' => 'Pulls information from your church\'s OnTheCity.org Plaza page.' );
$this->WP_Widget('the-city-plaza-widget', 'The City Plaza', $widget_ops);
}
function form($instance) {
/* Set up some default widget settings. */
$defaults = array( 'subdomain_key' => '',
'title_link' => '1',
'group_nickname' => '',
'plaza_display' => 'prayers',
'items_to_display' => '10',
'show_dates' => '0',
'show_type' => '0',
'cache_duration' => '86400');
$instance = wp_parse_args( (array) $instance, $defaults );
$title = strip_tags($instance['title']);
$subdomain_key = strip_tags($instance['subdomain_key']);
$title_link = strip_tags($instance['title_link']);
$group_nickname = strip_tags($instance['group_nickname']);
$plaza_display = strip_tags($instance['plaza_display']);
$items_to_display = strip_tags($instance['items_to_display']);
$show_dates = strip_tags($instance['show_dates']);
$show_type = strip_tags($instance['show_type']);
$cache_duration = strip_tags($instance['cache_duration']);
$clear_cache_msg = '';
if (isset($_POST['clear_cache_now'])) {
global $wpdb;
$cacher = new PlazaWordPressCache( $subdomain_key );
$cacher->set_db_connection($wpdb);
$cacher->clear_cache();
$clear_cache_msg = 'Cache cleared';
}
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">
Widget Title:
<input class="widefat"
id="<?php echo $this->get_field_id('title'); ?>"
name="<?php echo $this->get_field_name('title'); ?>"
type="text"
value="<?php echo attribute_escape($title); ?>" />
</label>
<i>The title to display at the top of the widget</i>
<br>
<?php
$title_link_checked = empty($title_link) ? '' : 'checked="checked"';
?>
<label for="<?php echo $this->get_field_id('title_link'); ?>">
<input type="checkbox"
id="<?php echo $this->get_field_id('title_link'); ?>"
name="<?php echo $this->get_field_name('title_link'); ?>"
<?php echo $title_link_checked ?> /> Title links to main plaza page
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('subdomain_key'); ?>">
Subdomain:
<input class="widefat"
id="<?php echo $this->get_field_id('subdomain_key'); ?>"
name="<?php echo $this->get_field_name('subdomain_key'); ?>"
type="text"
value="<?php echo attribute_escape($subdomain_key); ?>" />
</label>
<i>Ex: https://[subdomain].OnTheCity.org</i>
</p>
<p>
<label for="<?php echo $this->get_field_id('group_nickname'); ?>">
Group Nickname (optional):
<input class="widefat"
id="<?php echo $this->get_field_id('group_nickname'); ?>"
name="<?php echo $this->get_field_name('group_nickname'); ?>"
type="text"
value="<?php echo attribute_escape($group_nickname); ?>" />
</label>
<i>Only items for this group will be pulled.</i>
</p>
<p>
<?php
$topics_s = $events_s = $prayers_s = $needs_s = $album_s = '';
switch($instance['plaza_display']) {
case 'all':
$all_s = 'selected="selected"';
break;
case 'topics':
$topics_s = 'selected="selected"';
break;
case 'events':
$events_s = 'selected="selected"';
break;
case 'prayers':
$prayers_s = 'selected="selected"';
break;
case 'needs':
$needs_s = 'selected="selected"';
break;
case 'albums':
$album_s = 'selected="selected"';
break;
}
?>
<label for="<?php echo $this->get_field_id('plaza_display'); ?>">
Display:
<select class="widefat"
id="<?php echo $this->get_field_id('plaza_display'); ?>"
name="<?php echo $this->get_field_name('plaza_display'); ?>">
<option value="all" <?php echo $all_s; ?> >Show All</option>
<option value="topics" <?php echo $topics_s; ?> >Topics</option>
<option value="events" <?php echo $events_s; ?> >Events</option>
<option value="prayers" <?php echo $prayers_s; ?> >Prayers</option>
<option value="needs" <?php echo $needs_s; ?> >Needs</option>
<option value="albums" <?php echo $album_s; ?> >Albums</option>
</select>
</label>
<?php
$show_dates_checked = empty($show_dates) ? '' : 'checked="checked"';
?>
<label for="<?php echo $this->get_field_id('show_dates'); ?>">
<input type="checkbox"
id="<?php echo $this->get_field_id('show_dates'); ?>"
name="<?php echo $this->get_field_name('show_dates'); ?>"
<?php echo $show_dates_checked ?> /> Show Dates
</label>
<br>
<?php
$show_type_checked = empty($show_type) ? '' : 'checked="checked"';
?>
<label for="<?php echo $this->get_field_id('show_type'); ?>">
<input type="checkbox"
id="<?php echo $this->get_field_id('show_type'); ?>"
name="<?php echo $this->get_field_name('show_type'); ?>"
<?php echo $show_type_checked ?> /> Show Plaza item type above title
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('items_to_display'); ?>">
Items to display:
<select class="widefat"
id="<?php echo $this->get_field_id('items_to_display'); ?>"
name="<?php echo $this->get_field_name('items_to_display'); ?>">
<?php
$item_count_selected = '';
for($i=1; $i<=15; $i++) {
$item_count_selected = $items_to_display == $i ? 'selected="selected"' : '';
echo "<option value=\"$i\" $item_count_selected>$i</option>";
}
?>
</select>
</label>
</p>
<p>
<?php
$one_hour = $one_day = $one_week = $one_month = '';
switch($instance['cache_duration']) {
case '3600': // One Hour
$one_hour = 'selected="selected"';
break;
case '86400': // One Day
$one_day = 'selected="selected"';
break;
case '604800': // One Week
$one_week = 'selected="selected"';
break;
case '2592000': // One Month (30 days)
$one_month = 'selected="selected"';
}
?>
<label for="<?php echo $this->get_field_id('cache_duration'); ?>">
Cache data for:
<select class="widefat"
id="<?php echo $this->get_field_id('cache_duration'); ?>"
name="<?php echo $this->get_field_name('cache_duration'); ?>">
<option value="3600" <?php echo $one_hour; ?> >One Hour</option>
<option value="86400" <?php echo $one_day; ?> >One Day</option>
<option value="604800" <?php echo $one_week; ?> >One Week</option>
<option value="2592000" <?php echo $one_month; ?> >One Month (30 days)</option>
</select>
</label>
<label for="clear_cache_now">
<input type="checkbox" id="clear_cache_now" name="clear_cache_now" /> Clear cache on save
</label>
<?php if(!empty($clear_cache_msg)) { echo '<div style="color:#990000">'.$clear_cache_msg.'</div>'; } ?>
</p>
<?php
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
// This is done this way for older versions of PHP otherwise I would combine them all into one line.
$nickname = strip_tags($new_instance['group_nickname']);
$nickname = strtolower($nickname);
$nickname = trim($nickname);
$instance['title'] = strip_tags($new_instance['title']);
$instance['title_link'] = strip_tags($new_instance['title_link']);
$instance['subdomain_key'] = strip_tags($new_instance['subdomain_key']);
$instance['group_nickname'] = $nickname;
$instance['plaza_display'] = strip_tags($new_instance['plaza_display']);
$instance['items_to_display'] = strip_tags($new_instance['items_to_display']);
$instance['show_dates'] = strip_tags($new_instance['show_dates']);
$instance['show_type'] = strip_tags($new_instance['show_type']);
$instance['cache_duration'] = strip_tags($new_instance['cache_duration']);
return $instance;
}
function widget($args, $instance) {
extract($args);
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
$title_link = empty($instance['title_link']) ? '' : $instance['title_link'];
$subdomain_key = empty($instance['subdomain_key']) ? ' ' : $instance['subdomain_key'];
$group_nickname = empty($instance['group_nickname']) ? '' : $instance['group_nickname'];
$plaza_display = empty($instance['plaza_display']) ? ' ' : $instance['plaza_display'];
$items_to_display = empty($instance['items_to_display']) ? '10' : $instance['items_to_display'];
$show_dates = empty($instance['show_dates']) ? ' ' : $instance['show_dates'];
$show_type = empty($instance['show_type']) ? ' ' : $instance['show_type'];
$cache_duration = empty($instance['cache_duration']) ? ' ' : $instance['cache_duration'];
echo $before_widget;
if (!empty( $title )) {
$display_title = $title;
if(!empty($title_link)) {
$display_title = '<a href="http://'.$subdomain_key.'.onthecity.org/plaza" target="_blank">'.$title.'</a>';
}
echo $before_title . $display_title . $after_title;
};
include dirname(__FILE__).'/widget_info.php';
echo $after_widget;
}
}
add_action('widgets_init', create_function('', 'return register_widget("The_City_Plaza_Widget");'));
?>