1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Calendar Feed Settings Meta Box |
4
|
|
|
* |
5
|
|
|
* @package SimpleCalendar/Admin |
6
|
|
|
*/ |
7
|
|
|
namespace SimpleCalendar\Admin\Metaboxes; |
8
|
|
|
|
9
|
|
|
use SimpleCalendar\Abstracts\Meta_Box; |
10
|
|
|
use SimpleCalendar\Abstracts\Calendar; |
11
|
|
|
use SimpleCalendar\Abstracts\Feed; |
12
|
|
|
use SimpleCalendar\Abstracts\Field; |
13
|
|
|
|
14
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
15
|
|
|
exit; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Calendar feed settings. |
20
|
|
|
* |
21
|
|
|
* Meta box for handling an individual feed settings. |
22
|
|
|
* |
23
|
|
|
* @since 3.0.0 |
24
|
|
|
*/ |
25
|
|
|
class Settings implements Meta_Box { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Output the meta box markup. |
29
|
|
|
* |
30
|
|
|
* @since 3.0.0 |
31
|
|
|
* |
32
|
|
|
* @param \WP_Post $post |
33
|
|
|
*/ |
34
|
|
|
public static function html( $post ) { |
35
|
|
|
|
36
|
|
|
// @see Meta_Boxes::save_meta_boxes() |
37
|
|
|
wp_nonce_field( 'simcal_save_data', 'simcal_meta_nonce' ); |
38
|
|
|
|
39
|
|
|
?> |
40
|
|
|
<div class="simcal-panels-wrap"> |
41
|
|
|
|
42
|
|
|
<span class="simcal-box-handle"> |
43
|
|
|
<?php self::settings_handle( $post ); ?> |
44
|
|
|
</span> |
45
|
|
|
|
46
|
|
|
<ul class="simcal-tabs"> |
47
|
|
|
<?php self::settings_tabs( $post ); ?> |
48
|
|
|
<?php do_action( 'simcal_settings_meta_tabs' ); ?> |
49
|
|
|
</ul> |
50
|
|
|
|
51
|
|
|
<div class="simcal-panels"> |
52
|
|
|
<div id="events-settings-panel" class="simcal-panel"> |
53
|
|
|
<?php self::events_settings_panel( $post ); ?> |
54
|
|
|
<?php do_action( 'simcal_settings_meta_events_panel', $post->ID ); ?> |
55
|
|
|
</div> |
56
|
|
|
<div id="calendar-settings-panel" class="simcal-panel"> |
57
|
|
|
<?php do_action( 'simcal_settings_meta_calendar_panel', $post->ID ); ?> |
58
|
|
|
<?php self::calendar_settings_panel( $post ); ?> |
59
|
|
|
</div> |
60
|
|
|
<?php |
61
|
|
|
// Hook for additional settings panels. |
62
|
|
|
do_action( 'simcal_settings_meta_panels', $post->ID ); |
63
|
|
|
// Thus advanced panel is always the last one: |
64
|
|
|
?> |
65
|
|
|
<div id="advanced-settings-panel" class="simcal-panel"> |
66
|
|
|
<?php self::advanced_settings_panel( $post ) ?> |
67
|
|
|
<?php do_action( 'simcal_settings_meta_advanced_panel', $post->ID ); ?> |
68
|
|
|
</div> |
69
|
|
|
</div> |
70
|
|
|
|
71
|
|
|
<div class="clear"> |
72
|
|
|
</div> |
73
|
|
|
|
74
|
|
|
</div> |
75
|
|
|
<?php |
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Print the meta box settings handle. |
81
|
|
|
* |
82
|
|
|
* @since 3.0.0 |
83
|
|
|
* @access private |
84
|
|
|
* |
85
|
|
|
* @param \WP_Post $post |
86
|
|
|
*/ |
87
|
|
|
private static function settings_handle( $post ) { |
88
|
|
|
|
89
|
|
|
$feed_options = $calendar_options = $calendar_views = array(); |
90
|
|
|
|
91
|
|
|
$feed_types = simcal_get_feed_types(); |
92
|
|
|
foreach ( $feed_types as $feed_type ) { |
93
|
|
|
|
94
|
|
|
$feed = simcal_get_feed( $feed_type ); |
95
|
|
|
|
96
|
|
|
if ( $feed instanceof Feed ) { |
97
|
|
|
$feed_options[ $feed_type ] = $feed->name; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$calendar_types = simcal_get_calendar_types(); |
102
|
|
|
foreach ( $calendar_types as $calendar_type => $views ) { |
103
|
|
|
|
104
|
|
|
$calendar = simcal_get_calendar( $calendar_type ); |
105
|
|
|
|
106
|
|
|
if ( $calendar instanceof Calendar ) { |
107
|
|
|
$calendar_options[ $calendar_type ] = $calendar->name; |
108
|
|
|
$calendar_views[ $calendar_type ] = $calendar->views; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
if ( $feed_options ) { |
113
|
|
|
|
114
|
|
|
if ( $feed_types = wp_get_object_terms( $post->ID, 'calendar_feed' ) ) { |
115
|
|
|
$feed_type = sanitize_title( current( $feed_types )->name ); |
116
|
|
|
} else { |
117
|
|
|
$feed_type = apply_filters( 'simcal_default_feed_type', 'google' ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
?> |
121
|
|
|
<label for="_feed_type"><span><?php _e( 'Event Source', 'google-calendar-events' ); ?></span> |
122
|
|
|
<select name="_feed_type" id="_feed_type"> |
123
|
|
|
<optgroup label="<?php _ex( 'Get events from', 'From which calendar source to load events from', 'google-calendar-events' ) ?>"> |
124
|
|
|
<?php foreach ( $feed_options as $feed => $name ) { ?> |
125
|
|
|
<option value="<?php echo $feed; ?>" <?php selected( $feed, $feed_type, true ); ?>><?php echo $name; ?></option> |
126
|
|
|
<?php } ?> |
127
|
|
|
</optgroup> |
128
|
|
|
</select> |
129
|
|
|
</label> |
130
|
|
|
<?php |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if ( $calendar_options ) { |
135
|
|
|
|
136
|
|
|
if ( $calendar_types = wp_get_object_terms( $post->ID, 'calendar_type' ) ) { |
137
|
|
|
$calendar_type = sanitize_title( current( $calendar_types )->name ); |
138
|
|
|
} else { |
139
|
|
|
$calendar_type = apply_filters( 'simcal_default_calendar_type', 'default-calendar' ); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
?> |
143
|
|
|
<label for="_calendar_type"><span><?php _e( 'Calendar Type', 'google-calendar-events' ); ?></span> |
144
|
|
|
<select name="_calendar_type" id="_calendar_type"> |
145
|
|
|
<optgroup label="<?php _e( 'Calendar to use', 'google-calendar-events' ); ?>"> |
146
|
|
|
<?php foreach ( $calendar_options as $calendar => $name ) { ?> |
147
|
|
|
<option value="<?php echo $calendar; ?>" <?php selected( $calendar, $calendar_type, true ); ?>><?php echo $name; ?></option> |
148
|
|
|
<?php } ?> |
149
|
|
|
</optgroup> |
150
|
|
|
</select> |
151
|
|
|
</label> |
152
|
|
|
<?php |
153
|
|
|
|
154
|
|
|
if ( $calendar_views ) { |
155
|
|
|
|
156
|
|
|
$calendar_view = get_post_meta( $post->ID, '_calendar_view', true ); |
157
|
|
|
|
158
|
|
|
foreach ( $calendar_views as $calendar => $views ) { |
159
|
|
|
|
160
|
|
|
$calendar_type_view = isset( $calendar_view[ $calendar ] ) ? $calendar_view[ $calendar ] : ''; |
161
|
|
|
|
162
|
|
|
?> |
163
|
|
|
<label for="_calendar_view_<?php echo $calendar; ?>"><span><?php _e( 'View', 'google-calendar-events' ); ?></span> |
164
|
|
|
<select name="_calendar_view[<?php echo $calendar; ?>]" id="_calendar_view_<?php echo $calendar; ?>"> |
165
|
|
|
<optgroup label="<?php _e( 'View to display', 'google-calendar-events' ); ?>"> |
166
|
|
|
<?php foreach ( $views as $view => $name ) { ?> |
167
|
|
|
<option value="<?php echo $view; ?>" <?php selected( $view, $calendar_type_view, true ); ?>><?php echo $name; ?></option> |
168
|
|
|
<?php } ?> |
169
|
|
|
</optgroup> |
170
|
|
|
</select> |
171
|
|
|
</label> |
172
|
|
|
<?php |
173
|
|
|
|
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Print settings tabs. |
181
|
|
|
* |
182
|
|
|
* @since 3.0.0 |
183
|
|
|
* @access private |
184
|
|
|
* |
185
|
|
|
* @param \WP_Post $post |
186
|
|
|
*/ |
187
|
|
|
private static function settings_tabs( $post ) { |
188
|
|
|
|
189
|
|
|
// Hook to add more tabs. |
190
|
|
|
$tabs = apply_filters( 'simcal_settings_meta_tabs_li', array( |
191
|
|
|
'events' => array( |
192
|
|
|
'label' => __( 'Events', 'google-calendar-events' ), |
193
|
|
|
'target' => 'events-settings-panel', |
194
|
|
|
'class' => array( 'active' ), |
195
|
|
|
'icon' => 'simcal-icon-event', |
196
|
|
|
), |
197
|
|
|
'calendar' => array( |
198
|
|
|
'label' => __( 'Appearance', 'google-calendar-events' ), |
199
|
|
|
'target' => 'calendar-settings-panel', |
200
|
|
|
'class' => array(), |
201
|
|
|
'icon' => 'simcal-icon-calendar', |
202
|
|
|
), |
203
|
|
|
), $post->ID ); |
204
|
|
|
|
205
|
|
|
// Always keep advanced tab as the last one. |
206
|
|
|
$tabs['advanced'] = array( |
207
|
|
|
'label' => __( 'Advanced', 'google-calendar-events' ), |
208
|
|
|
'target' => 'advanced-settings-panel', |
209
|
|
|
'class' => array(), |
210
|
|
|
'icon' => 'simcal-icon-settings', |
211
|
|
|
); |
212
|
|
|
|
213
|
|
|
// Output the tabs as list items. |
214
|
|
|
foreach ( $tabs as $key => $tab ) { |
215
|
|
|
|
216
|
|
|
if ( isset( $tab['target'] ) && isset( $tab['label'] ) ) { |
217
|
|
|
|
218
|
|
|
$icon = $tab['icon'] ? $tab['icon'] : 'simcal-icon-panel'; |
219
|
|
|
$class = $tab['class'] ? $tab['class'] : array(); |
220
|
|
|
|
221
|
|
|
echo '<li class="' . $key . '-settings ' . $key . '-tab ' . implode( ' ', $class ) . '" data-tab="' . $key . '">'; |
222
|
|
|
echo '<a href="#' . $tab['target'] . '"><i class="' . $icon . '" ></i> <span>' . esc_html( $tab['label'] ) . '</span></a>'; |
223
|
|
|
echo '</li>'; |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Print events settings panel. |
230
|
|
|
* |
231
|
|
|
* @since 3.0.0 |
232
|
|
|
* @access private |
233
|
|
|
* |
234
|
|
|
* @param \WP_Post $post |
235
|
|
|
*/ |
236
|
|
|
private static function events_settings_panel( $post ) { |
237
|
|
|
|
238
|
|
|
?> |
239
|
|
|
<table> |
240
|
|
|
<thead> |
241
|
|
|
<tr><th colspan="2"><?php _e( 'Event Settings', 'google-calendar-events' ); ?></th></tr> |
242
|
|
|
</thead> |
243
|
|
|
<tbody class="simcal-panel-section simcal-panel-section-events-range"> |
244
|
|
|
<tr class="simcal-panel-field"> |
245
|
|
|
<th><label for="_calendar_begins"><?php _e( 'Calendar Start', 'google-calendar-events' ); ?></label></th> |
246
|
|
|
<td> |
247
|
|
|
<?php |
248
|
|
|
|
249
|
|
|
$calendar_begins = esc_attr( get_post_meta( $post->ID, '_calendar_begins', true ) ); |
250
|
|
|
$calendar_begins_nth = max( absint( get_post_meta( $post->ID, '_calendar_begins_nth', true ) ), 1 ); |
251
|
|
|
$calendar_begins_nth_show = in_array( $calendar_begins, array( |
252
|
|
|
'days_before', |
253
|
|
|
'days_after', |
254
|
|
|
'weeks_before', |
255
|
|
|
'weeks_after', |
256
|
|
|
'months_before', |
257
|
|
|
'months_after', |
258
|
|
|
'years_before', |
259
|
|
|
'years_after', |
260
|
|
|
) ); |
261
|
|
|
|
262
|
|
|
simcal_print_field( array( |
263
|
|
|
'type' => 'standard', |
264
|
|
|
'subtype' => 'number', |
265
|
|
|
'name' => '_calendar_begins_nth', |
266
|
|
|
'id' => '_calendar_begins_nth', |
267
|
|
|
'value' => strval( $calendar_begins_nth ), |
268
|
|
|
'attributes' => array( |
269
|
|
|
'min' => '1', |
270
|
|
|
), |
271
|
|
|
'class' => array( |
272
|
|
|
'simcal-field-inline', |
273
|
|
|
'simcal-field-tiny', |
274
|
|
|
), |
275
|
|
|
'style' => ! $calendar_begins_nth_show ? array( 'display' => 'none' ) : '', |
276
|
|
|
) ); |
277
|
|
|
|
278
|
|
|
?> |
279
|
|
|
<select name="_calendar_begins" |
280
|
|
|
id="_calendar_begins" |
281
|
|
|
class="simcal-field simcal-field-select simcal-field-inline simcal-field-switch-other"> |
282
|
|
|
<optgroup label="<?php _e( 'Days', 'google-calendar-events' ); ?>"> |
283
|
|
|
<option value="today" |
284
|
|
|
data-hide-fields="_calendar_begins_custom_date,_calendar_begins_nth" |
285
|
|
|
<?php selected( 'today', $calendar_begins, true ); ?>><?php _e( 'Today', 'google-calendar-events' ); ?></option> |
286
|
|
|
<option value="now" |
287
|
|
|
data-hide-fields="_calendar_begins_custom_date,_calendar_begins_nth" |
288
|
|
|
<?php selected( 'now', $calendar_begins, true ); ?>><?php _e( 'Now', 'google-calendar-events' ); ?></option> |
289
|
|
|
<option value="days_before" |
290
|
|
|
data-hide-field="_calendar_begins_custom_date" |
291
|
|
|
data-show-field="_calendar_begins_nth" <?php selected( 'days_before', $calendar_begins, true ); ?>><?php _e( 'Day(s) before today', 'google-calendar-events' ); ?></option> |
292
|
|
|
<option value="days_after" |
293
|
|
|
data-hide-field="_calendar_begins_custom_date" |
294
|
|
|
data-show-field="_calendar_begins_nth" <?php selected( 'days_after', $calendar_begins, true ); ?>><?php _e( 'Day(s) after today', 'google-calendar-events' ); ?></option> |
295
|
|
|
</optgroup> |
296
|
|
|
<optgroup label="<?php _e( 'Weeks', 'google-calendar-events' ); ?>"> |
297
|
|
|
<option value="this_week" |
298
|
|
|
data-hide-fields="_calendar_begins_custom_date,_calendar_begins_nth" |
299
|
|
|
<?php selected( 'this_week', $calendar_begins, true ); ?>><?php _e( 'This week', 'google-calendar-events' ); ?></option> |
300
|
|
|
<option value="weeks_before" |
301
|
|
|
data-hide-field="_calendar_begins_custom_date" |
302
|
|
|
data-show-field="_calendar_begins_nth" <?php selected( 'weeks_before', $calendar_begins, true ); ?>><?php _e( 'Week(s) before current', 'google-calendar-events' ); ?></option> |
303
|
|
|
<option value="weeks_after" |
304
|
|
|
data-hide-field="_calendar_begins_custom_date" |
305
|
|
|
data-show-field="_calendar_begins_nth" <?php selected( 'weeks_after', $calendar_begins, true ); ?>><?php _e( 'Week(s) after current', 'google-calendar-events' ); ?></option> |
306
|
|
|
</optgroup> |
307
|
|
|
<optgroup label="<?php _e( 'Months', 'google-calendar-events' ); ?>"> |
308
|
|
|
<option value="this_month" |
309
|
|
|
data-hide-fields="_calendar_begins_custom_date,_calendar_begins_nth" |
310
|
|
|
<?php selected( 'this_month', $calendar_begins, true ); ?>><?php _e( 'This month', 'google-calendar-events' ); ?></option> |
311
|
|
|
<option value="months_before" |
312
|
|
|
data-hide-field="_calendar_begins_custom_date" |
313
|
|
|
data-show-field="_calendar_begins_nth" <?php selected( 'months_before', $calendar_begins, true ); ?>><?php _e( 'Month(s) before current', 'google-calendar-events' ); ?></option> |
314
|
|
|
<option value="months_after" |
315
|
|
|
data-hide-field="_calendar_begins_custom_date" |
316
|
|
|
data-show-field="_calendar_begins_nth" <?php selected( 'months_after', $calendar_begins, true ); ?>><?php _e( 'Month(s) after current', 'google-calendar-events' ); ?></option> |
317
|
|
|
</optgroup> |
318
|
|
|
<optgroup label="<?php _e( 'Years', 'google-calendar-events' ); ?>"> |
319
|
|
|
<option value="this_year" |
320
|
|
|
data-hide-fields="_calendar_begins_custom_date,_calendar_begins_nth" |
321
|
|
|
<?php selected( 'this_year', $calendar_begins, true ); ?>><?php _e( 'This year', 'google-calendar-events' ); ?></option> |
322
|
|
|
<option value="years_before" |
323
|
|
|
data-show-field="_calendar_begins_nth" <?php selected( 'years_before', $calendar_begins, true ); ?>><?php _e( 'Year(s) before current', 'google-calendar-events' ); ?></option> |
324
|
|
|
<option value="years_after" |
325
|
|
|
data-hide-field="_calendar_begins_custom_date" |
326
|
|
|
data-show-field="_calendar_begins_nth" <?php selected( 'years_after', $calendar_begins, true ); ?>><?php _e( 'Year(s) after current', 'google-calendar-events' ); ?></option> |
327
|
|
|
</optgroup> |
328
|
|
|
<optgroup label="<?php _e( 'Other', 'google-calendar-events' ); ?>"> |
329
|
|
|
<option value="custom_date" |
330
|
|
|
data-hide-field="_calendar_begins_nth" |
331
|
|
|
data-show-field="_calendar_begins_custom_date" <?php selected( 'custom_date', $calendar_begins, true ); ?>><?php _e( 'Specific date', 'google-calendar-events' ); ?></option> |
332
|
|
|
</optgroup> |
333
|
|
|
</select> |
334
|
|
|
<?php |
335
|
|
|
|
336
|
|
|
simcal_print_field( array( |
337
|
|
|
'type' => 'date-picker', |
338
|
|
|
'name' => '_calendar_begins_custom_date', |
339
|
|
|
'id' => '_calendar_begins_custom_date', |
340
|
|
|
'value' => get_post_meta( $post->ID, '_calendar_begins_custom_date', true ), |
341
|
|
|
'class' => array( |
342
|
|
|
'simcal-field-inline', |
343
|
|
|
), |
344
|
|
|
'style' => 'custom_date' != $calendar_begins ? array( 'display' => 'none' ) : '', |
345
|
|
|
) ); |
346
|
|
|
|
347
|
|
|
?> |
348
|
|
|
<i class="simcal-icon-help simcal-help-tip" |
349
|
|
|
data-tip="<?php _e( 'The calendar default opening date. It will automatically adapt based on the chosen calendar type.', 'google-calendar-events' ); ?>"></i> |
350
|
|
|
</td> |
351
|
|
|
</tr> |
352
|
|
|
<tr class="simcal-panel-field"> |
353
|
|
|
<th><label for="_feed_earliest_event_date"><?php _e( 'Earliest Event', 'google-calendar-events' ); ?></label></th> |
354
|
|
|
<td> |
355
|
|
|
<?php |
356
|
|
|
|
357
|
|
|
$earliest_event_saved = get_post_meta( $post->ID, '_feed_earliest_event_date', true ); |
358
|
|
|
$earliest_event = false == $earliest_event_saved ? 'months_before' : esc_attr( $earliest_event_saved ); |
359
|
|
|
|
360
|
|
|
simcal_print_field( array( |
361
|
|
|
'type' => 'standard', |
362
|
|
|
'subtype' => 'number', |
363
|
|
|
'name' => '_feed_earliest_event_date_range', |
364
|
|
|
'id' => '_feed_earliest_event_date_range', |
365
|
|
|
'value' => strval( max( absint( get_post_meta( $post->ID, '_feed_earliest_event_date_range', true ) ), 1 ) ), |
366
|
|
|
'attributes' => array( |
367
|
|
|
'min' => '1', |
368
|
|
|
), |
369
|
|
|
'class' => array( |
370
|
|
|
'simcal-field-inline', |
371
|
|
|
'simcal-field-tiny', |
372
|
|
|
), |
373
|
|
|
'style' => ( 'now' != $earliest_event ) && ( 'today' != $earliest_event ) ? array( 'display' => 'none' ) : '', |
374
|
|
|
) ); |
375
|
|
|
|
376
|
|
|
?> |
377
|
|
|
<select name="_feed_earliest_event_date" |
378
|
|
|
id="_feed_earliest_event_date" |
379
|
|
|
class="simcal-field simcal-field-select simcal-field-inline simcal-field-switch-other"> |
380
|
|
|
<option value="calendar_start" data-hide-field="_feed_earliest_event_date_range" <?php selected( 'calendar_start', $earliest_event, true ); ?>><?php _e( 'Same as start date', 'google-calendar-events' ); ?></option> |
381
|
|
|
<option value="days_before" data-show-field="_feed_earliest_event_date_range" <?php selected( 'days_before', $earliest_event, true ); ?>><?php _e( 'Day(s) before start date', 'google-calendar-events' ); ?></option> |
382
|
|
|
<option value="weeks_before" data-show-field="_feed_earliest_event_date_range" <?php selected( 'weeks_before', $earliest_event, true ); ?>><?php _e( 'Week(s) before start date', 'google-calendar-events' ); ?></option> |
383
|
|
|
<option value="months_before" data-show-field="_feed_earliest_event_date_range" <?php selected( 'months_before', $earliest_event, true ); ?>><?php _e( 'Month(s) before start date', 'google-calendar-events' ); ?></option> |
384
|
|
|
<option value="years_before" data-show-field="_feed_earliest_event_date_range" <?php selected( 'years_before', $earliest_event, true ); ?>><?php _e( 'Year(s) before start date', 'google-calendar-events' ); ?></option> |
385
|
|
|
</select> |
386
|
|
|
<i class="simcal-icon-help simcal-help-tip" |
387
|
|
|
data-tip="<?php _e( 'Set the date for the earliest possible event to show in calendar. There will not be events before this date.', 'google-calendar-events' ); ?>"></i> |
388
|
|
|
</td> |
389
|
|
|
</tr> |
390
|
|
|
<tr class="simcal-panel-field"> |
391
|
|
|
<th><label for="_feed_latest_event_date"><?php _e( 'Latest Event', 'google-calendar-events' ); ?></label></th> |
392
|
|
|
<td> |
393
|
|
|
<?php |
394
|
|
|
|
395
|
|
|
$latest_event_saved = get_post_meta( $post->ID, '_feed_latest_event_date', true ); |
396
|
|
|
$latest_event = false == $latest_event_saved ? 'years_after' : esc_attr( $latest_event_saved ); |
397
|
|
|
|
398
|
|
|
simcal_print_field( array( |
399
|
|
|
'type' => 'standard', |
400
|
|
|
'subtype' => 'number', |
401
|
|
|
'name' => '_feed_latest_event_date_range', |
402
|
|
|
'id' => '_feed_latest_event_date_range', |
403
|
|
|
'value' => strval( max( absint( get_post_meta( $post->ID, '_feed_latest_event_date_range', true ) ), 1 ) ), |
404
|
|
|
'attributes' => array( |
405
|
|
|
'min' => '1', |
406
|
|
|
), |
407
|
|
|
'class' => array( |
408
|
|
|
'simcal-field-inline', |
409
|
|
|
'simcal-field-tiny', |
410
|
|
|
), |
411
|
|
|
'style' => 'indefinite' != $latest_event ? array( 'display' => 'none' ) : '', |
412
|
|
|
) ); |
413
|
|
|
|
414
|
|
|
?> |
415
|
|
|
<select name="_feed_latest_event_date" |
416
|
|
|
id="_feed_latest_event_date" |
417
|
|
|
class="simcal-field simcal-field-select simcal-field-inline simcal-field-switch-other"> |
418
|
|
|
<option value="calendar_start" data-hide-field="_feed_latest_event_date_range" <?php selected( 'calendar_start', $earliest_event, true ); ?>><?php _e( 'Day end of start date', 'google-calendar-events' ); ?></option> |
419
|
|
|
<option value="days_after" data-show-field="_feed_latest_event_date_range" <?php selected( 'days_after', $latest_event, true ); ?>><?php _e( 'Day(s) after start date', 'google-calendar-events' ); ?></option> |
420
|
|
|
<option value="weeks_after" data-show-field="_feed_latest_event_date_range" <?php selected( 'weeks_after', $latest_event, true ); ?>><?php _e( 'Weeks(s) after start date', 'google-calendar-events' ); ?></option> |
421
|
|
|
<option value="months_after" data-show-field="_feed_latest_event_date_range" <?php selected( 'months_after', $latest_event, true ); ?>><?php _e( 'Month(s) after start date', 'google-calendar-events' ); ?></option> |
422
|
|
|
<option value="years_after" data-show-field="_feed_latest_event_date_range" <?php selected( 'years_after', $latest_event, true ); ?>><?php _e( 'Year(s) after start date', 'google-calendar-events' ); ?></option> |
423
|
|
|
</select> |
424
|
|
|
<i class="simcal-icon-help simcal-help-tip" |
425
|
|
|
data-tip="<?php _e( 'Set the date for the latest possible event to show on calendar. There will not be events after this date.', 'google-calendar-events' ); ?>"></i> |
426
|
|
|
</td> |
427
|
|
|
</tr> |
428
|
|
|
</tbody> |
429
|
|
|
</table> |
430
|
|
|
<?php |
431
|
|
|
|
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Print the calendar settings panel. |
436
|
|
|
* |
437
|
|
|
* @since 3.0.0 |
438
|
|
|
* @access private |
439
|
|
|
* |
440
|
|
|
* @param \WP_Post $post |
441
|
|
|
*/ |
442
|
|
|
private static function calendar_settings_panel( $post ) { |
443
|
|
|
|
444
|
|
|
?> |
445
|
|
|
<table> |
446
|
|
|
<thead> |
447
|
|
|
<tr><th colspan="2"><?php _e( 'Miscellaneous', 'google-calendar-events' ); ?></th></tr> |
448
|
|
|
</thead> |
449
|
|
|
<tbody class="simcal-panel-section"> |
450
|
|
|
<tr class="simcal-panel-field"> |
451
|
|
|
<th><label for="_calendar_is_static"><?php _e( 'Static Calendar', 'google-calendar-events' ); ?></label></th> |
452
|
|
|
<td> |
453
|
|
|
<?php |
454
|
|
|
|
455
|
|
|
$fixed = get_post_meta( $post->ID, '_calendar_is_static', true ); |
456
|
|
|
|
457
|
|
|
simcal_print_field( array( |
458
|
|
|
'type' => 'checkbox', |
459
|
|
|
'name' => '_calendar_is_static', |
460
|
|
|
'id' => '_calendar_is_static', |
461
|
|
|
'tooltip' => __( 'Remove the navigation arrows and fix the calendar view to its initial state.', 'google-calendar-events' ), |
462
|
|
|
'value' => 'yes' == $fixed ? 'yes' : 'no', |
463
|
|
|
'text' => __( 'Yes (hide navigation arrows)', 'google-calendar-events' ), |
464
|
|
|
) ); |
465
|
|
|
|
466
|
|
|
?> |
467
|
|
|
</td> |
468
|
|
|
</tr> |
469
|
|
|
<tr class="simcal-panel-field"> |
470
|
|
|
<th><label for="_no_events_message"><?php _e( 'No Events Message', 'google-calendar-events' ); ?></label></th> |
471
|
|
|
<td> |
472
|
|
|
<?php |
473
|
|
|
|
474
|
|
|
simcal_print_field( array( |
475
|
|
|
'type' => 'textarea', |
476
|
|
|
'name' => '_no_events_message', |
477
|
|
|
'id' => '_no_events_message', |
478
|
|
|
'tooltip' => __( 'Some calendars may display a message when no events are found. You can change the default message here.', 'google-calendar-events' ), |
479
|
|
|
'value' => get_post_meta( $post->ID, '_no_events_message', true ), |
480
|
|
|
) ); |
481
|
|
|
|
482
|
|
|
?> |
483
|
|
|
</td> |
484
|
|
|
</tr> |
485
|
|
|
<tr class="simcal-panel-field"> |
486
|
|
|
<th><label for="_event_formatting"><?php _e( 'Event Formatting', 'google-calendar-events' ); ?></label></th> |
487
|
|
|
<td> |
488
|
|
|
<?php |
489
|
|
|
|
490
|
|
|
$event_formatting = get_post_meta( $post->ID, '_event_formatting', true ); |
491
|
|
|
|
492
|
|
|
simcal_print_field( array( |
493
|
|
|
'type' => 'select', |
494
|
|
|
'name' => '_event_formatting', |
495
|
|
|
'id' => '_event_formatting', |
496
|
|
|
'tooltip' => __( 'How to preserve line breaks and paragraphs in the event template builder.', 'google-calendar-events' ), |
497
|
|
|
'value' => $event_formatting, |
498
|
|
|
'default' => 'preserve_linebreaks', |
499
|
|
|
'options' => array( |
500
|
|
|
'preserve_linebreaks' => __( 'Preserve line breaks, auto paragraphs (default)', 'google-calendar-events' ), |
501
|
|
|
'no_linebreaks' => __( 'No line breaks, auto paragraphs', 'google-calendar-events' ), |
502
|
|
|
'none' => __( 'No line breaks, no auto paragraphs', 'google-calendar-events' ), |
503
|
|
|
), |
504
|
|
|
) ); |
505
|
|
|
|
506
|
|
|
?> |
507
|
|
|
</td> |
508
|
|
|
</tr> |
509
|
|
|
<tr class="simcal-panel-field"> |
510
|
|
|
<th><label for="_poweredby"><?php _e( 'Powered By', 'google-calendar-events' ); ?></label></th> |
511
|
|
|
<td> |
512
|
|
|
<?php |
513
|
|
|
|
514
|
|
|
$poweredby = get_post_meta( $post->ID, '_poweredby', true ); |
515
|
|
|
|
516
|
|
|
simcal_print_field( array( |
517
|
|
|
'type' => 'checkbox', |
518
|
|
|
'name' => '_poweredby', |
519
|
|
|
'id' => '_poweredby', |
520
|
|
|
'value' => 'yes' == $poweredby ? 'yes' : 'no', |
521
|
|
|
'text' => __( 'Yes, Simple Calendar rocks! Show some love with a little link below this calendar.', 'google-calendar-events' ), |
522
|
|
|
) ); |
523
|
|
|
|
524
|
|
|
?> |
525
|
|
|
</td> |
526
|
|
|
</tr> |
527
|
|
|
</tbody> |
528
|
|
|
</table> |
529
|
|
|
<?php |
530
|
|
|
|
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Print the advanced settings panel. |
535
|
|
|
* |
536
|
|
|
* @since 3.0.0 |
537
|
|
|
* @access private |
538
|
|
|
* |
539
|
|
|
* @param \WP_Post $post |
540
|
|
|
*/ |
541
|
|
|
private static function advanced_settings_panel( $post ) { |
542
|
|
|
|
543
|
|
|
?> |
544
|
|
|
<table> |
545
|
|
|
<thead> |
546
|
|
|
<tr><th colspan="2"><?php _e( 'Date and Time', 'google-calendar-events' ); ?></th></tr> |
547
|
|
|
</thead> |
548
|
|
|
<tbody class="simcal-panel-section simcal-panel-datetime-formatting"> |
549
|
|
|
<tr class="simcal-panel-field"> |
550
|
|
|
<th><label for="_calendar_timezone_setting"><?php _e( 'Timezone', 'google-calendar-events' ); ?></label></th> |
551
|
|
|
<td> |
552
|
|
|
<?php |
553
|
|
|
|
554
|
|
|
$timezone_wordpress = simcal_get_wp_timezone(); |
555
|
|
|
$timezone_default = $timezone_wordpress ? $timezone_wordpress : 'UTC'; |
556
|
|
|
$timezone_setting = esc_attr( get_post_meta( $post->ID, '_feed_timezone_setting', true ) ); |
557
|
|
|
$timezone = esc_attr( get_post_meta( $post->ID, '_feed_timezone', true ) ); |
558
|
|
|
$timezone = $timezone ? $timezone : $timezone_default; |
559
|
|
|
$show_use_calendar = isset( simcal_get_feed( $post )->type ); |
560
|
|
|
|
561
|
|
|
if ( $show_use_calendar ) { |
562
|
|
|
$show_use_calendar = ( simcal_get_feed( $post )->type !== 'grouped-calendars' ? 1 : 0 ); |
563
|
|
|
} else { |
564
|
|
|
$show_use_calendar = true; |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
?> |
568
|
|
|
<select name="_feed_timezone_setting" |
569
|
|
|
id="_feed_timezone_setting" |
570
|
|
|
class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-other" |
571
|
|
|
data-show-field-on-choice="true"> |
572
|
|
|
<option value="use_site" <?php selected( 'use_site', $timezone_setting, true ); ?>><?php printf( _x( 'Site default', 'Use this site default setting', 'google-calendar-events' ) . ' (%s)', $timezone_default ); ?></option> |
573
|
|
|
<?php if ( $show_use_calendar ) { ?> |
574
|
|
|
<option id="use_calendar" value="use_calendar" data-show-field="_use_calendar_warning" <?php selected( 'use_calendar', $timezone_setting, true ); ?>><?php _ex( 'Events source default', 'Use the calendar default setting', 'google-calendar-events' ); ?></option> |
575
|
|
|
<?php } ?> |
576
|
|
|
<option value="use_custom" data-show-field="_feed_timezone" <?php selected( 'use_custom', $timezone_setting, true ); ?>><?php _ex( 'Custom', 'Use a custom setting', 'google-calendar-events' ); ?></option> |
577
|
|
|
</select> |
578
|
|
|
<select name="_feed_timezone" |
579
|
|
|
id="_feed_timezone" |
580
|
|
|
class="simcal-field simcal-field-select simcal-field-inline" |
581
|
|
|
<?php echo 'use_custom' != $timezone_setting ? 'style="display: none;"' : ''; ?>> |
582
|
|
|
<?php echo wp_timezone_choice( $timezone ); ?> |
583
|
|
|
</select> |
584
|
|
|
<i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'Using a different timezone may alter the date and time display of your calendar events. It is recommended to keep the calendar default timezone.', 'google-calendar-events' ); ?>"></i> |
585
|
|
|
<p id="_use_calendar_warning" style="display: none;" class="simcal-field"> |
586
|
|
|
<?php printf( __( '<strong>Warning:</strong> Using this option can return unexpected results if you have specified <a href="%s" target="_blank">event level</a> timezones.', 'google-calendar-events' ), 'http://docs.simplecalendar.io/timezone-settings/' ); ?> |
587
|
|
|
</p> |
588
|
|
|
</td> |
589
|
|
|
</tr> |
590
|
|
|
<tr class="simcal-panel-field"> |
591
|
|
|
<th><label for="_calendar_date_format_setting"><?php _e( 'Date Format', 'google-calendar-events' ); ?></label></th> |
592
|
|
|
<td> |
593
|
|
|
<?php |
594
|
|
|
|
595
|
|
|
$date_format_setting = esc_attr( get_post_meta( $post->ID, '_calendar_date_format_setting', true ) ); |
596
|
|
|
$date_format_default = esc_attr( get_option( 'date_format' ) ); |
597
|
|
|
$date_format = esc_attr( get_post_meta( $post->ID, '_calendar_date_format', true ) ); |
598
|
|
|
$date_format_php = esc_attr( get_post_meta( $post->ID, '_calendar_date_format_php', true ) ); |
599
|
|
|
$date_format_php = $date_format_php ? $date_format_php : $date_format_default; |
600
|
|
|
|
601
|
|
|
?> |
602
|
|
|
<select name="_calendar_date_format_setting" |
603
|
|
|
id="_calendar_date_format_setting" |
604
|
|
|
class="simcal-field simcal-field-select simcal-field-show-other"> |
605
|
|
|
<option value="use_site" data-show-field="_calendar_date_format_default" <?php selected( 'use_site', $date_format_setting, true ); ?>><?php _ex( 'Site default', 'Use this site default setting', 'google-calendar-events' ); ?></option> |
606
|
|
|
<option value="use_custom" data-show-field="_calendar_date_format" <?php selected( 'use_custom', $date_format_setting, true ); ?>><?php _ex( 'Custom', 'Use a custom setting', 'google-calendar-events' ); ?></option> |
607
|
|
|
<option value="use_custom_php" data-show-field="_calendar_date_format_php_field" <?php selected( 'use_custom_php', $date_format_setting, true ); ?>><?php _e( 'Custom (PHP format)', 'google-calendar-events' ); ?></option> |
608
|
|
|
</select> |
609
|
|
|
<i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'This option sets how calendars display event dates. It is recommended to keep your site default setting.', 'google-calendar-events' ); ?>"></i> |
610
|
|
|
<p id="_calendar_date_format_default" style="<?php echo $date_format_setting != 'use_site' ? 'display: none;' : ''; ?>"> |
611
|
|
|
<em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em> |
612
|
|
|
<code><?php echo date_i18n( $date_format_default, time() ); ?></code> |
613
|
|
|
</p> |
614
|
|
|
<?php simcal_print_field( array( |
615
|
|
|
'type' => 'datetime-format', |
616
|
|
|
'subtype' => 'date', |
617
|
|
|
'name' => '_calendar_date_format', |
618
|
|
|
'id' => '_calendar_date_format', |
619
|
|
|
'value' => $date_format, |
620
|
|
|
'style' => $date_format_setting != 'use_custom' ? array( 'display' => 'none' ) : '', |
621
|
|
|
) ); ?> |
622
|
|
|
<div class="simcal-field-datetime-format-php" id="_calendar_date_format_php_field" style="<?php echo $date_format_setting != 'use_custom_php' ? 'display: none;' : ''; ?>"> |
623
|
|
|
<br> |
624
|
|
|
<label for="_calendar_date_format_php"> |
625
|
|
|
<input type="text" |
626
|
|
|
name="_calendar_date_format_php" |
627
|
|
|
id="_calendar_date_format_php" |
628
|
|
|
class="simcal-field simcal-field-text simcal-field-small" |
629
|
|
|
value="<?php echo $date_format_php; ?>" /> |
630
|
|
|
<?php printf( __( 'Enter a date format using %s values.', 'google-calendar-events' ), '<a href="//php.net/manual/en/function.date.php" target="_blank">PHP</a>' ); ?> |
631
|
|
|
</label> |
632
|
|
|
<p> |
633
|
|
|
<em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em> |
634
|
|
|
<code><?php echo date_i18n( $date_format_php, time() ); ?></code> |
635
|
|
|
</p> |
636
|
|
|
</div> |
637
|
|
|
</td> |
638
|
|
|
</tr> |
639
|
|
|
<tr class="simcal-panel-field"> |
640
|
|
|
<th><label for="_calendar_datetime_separator"><?php _e( 'Separator', 'google-calendar-events' ); ?></label></th> |
641
|
|
|
<td> |
642
|
|
|
<?php |
643
|
|
|
|
644
|
|
|
$separator = get_post_meta( $post->ID, '_calendar_datetime_separator', true ); |
645
|
|
|
$separator = false == $separator ? '@' : $separator; |
646
|
|
|
|
647
|
|
|
simcal_print_field( array( |
648
|
|
|
'type' => 'standard', |
649
|
|
|
'subtype' => 'text', |
650
|
|
|
'name' => '_calendar_datetime_separator', |
651
|
|
|
'id' => '_calendar_datetime_separator', |
652
|
|
|
'value' => $separator, |
653
|
|
|
'tooltip' => __( 'Used to divide date and time when both are shown.', 'google-calendar-events' ), |
654
|
|
|
'class' => array( |
655
|
|
|
'simcal-field-tiny', |
656
|
|
|
), |
657
|
|
|
) ); |
658
|
|
|
|
659
|
|
|
?> |
660
|
|
|
</td> |
661
|
|
|
</tr> |
662
|
|
|
<tr class="simcal-panel-field"> |
663
|
|
|
<th><label for="_calendar_time_format_setting"><?php _e( 'Time Format', 'google-calendar-events' ); ?></label></th> |
664
|
|
|
<td> |
665
|
|
|
<?php |
666
|
|
|
|
667
|
|
|
$time_format_setting = esc_attr( get_post_meta( $post->ID, '_calendar_time_format_setting', true ) ); |
668
|
|
|
$time_format_default = esc_attr( get_option( 'time_format' ) ); |
669
|
|
|
$time_format = esc_attr( get_post_meta( $post->ID, '_calendar_time_format', true ) ); |
670
|
|
|
$time_format_php = esc_attr( get_post_meta( $post->ID, '_calendar_time_format_php', true ) ); |
671
|
|
|
$time_format_php = $time_format_php ? $time_format_php : $time_format_default; |
672
|
|
|
|
673
|
|
|
?> |
674
|
|
|
<select name="_calendar_time_format_setting" |
675
|
|
|
id="_calendar_time_format_setting" |
676
|
|
|
class="simcal-field simcal-field-select simcal-field-show-other"> |
677
|
|
|
<option value="use_site" data-show-field="_calendar_time_format_default" <?php selected( 'use_site', $time_format_setting, true ); ?>><?php _ex( 'Site default', 'Use this site default setting', 'google-calendar-events' ); ?></option> |
678
|
|
|
<option value="use_custom" data-show-field="_calendar_time_format" <?php selected( 'use_custom', $time_format_setting, true ); ?>><?php _ex( 'Custom', 'Use a custom setting', 'google-calendar-events' ); ?></option> |
679
|
|
|
<option value="use_custom_php" data-show-field="_calendar_time_format_php_field" <?php selected( 'use_custom_php', $time_format_setting, true ); ?>><?php _e( 'Custom (PHP format)', 'google-calendar-events' ); ?></option> |
680
|
|
|
</select> |
681
|
|
|
<i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'This option sets how calendars display event times. It is recommended to keep your site default setting.', 'google-calendar-events' ); ?>"></i> |
682
|
|
|
<p id="_calendar_time_format_default" style="<?php echo $time_format_setting != 'use_site' ? 'display: none;' : ''; ?>"> |
683
|
|
|
<em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em> |
684
|
|
|
<code><?php echo date_i18n( $time_format_default, time() ); ?></code> |
685
|
|
|
</p> |
686
|
|
|
<?php simcal_print_field( array( |
687
|
|
|
'type' => 'datetime-format', |
688
|
|
|
'subtype' => 'time', |
689
|
|
|
'name' => '_calendar_time_format', |
690
|
|
|
'id' => '_calendar_time_format', |
691
|
|
|
'value' => $time_format, |
692
|
|
|
'style' => $time_format_setting != 'use_custom' ? array( 'display' => 'none' ) : '', |
693
|
|
|
) ); ?> |
694
|
|
|
<div class="simcal-field-datetime-format-php" id="_calendar_time_format_php_field" style="<?php echo $time_format_setting != 'use_custom_php' ? 'display: none;' : ''; ?>"> |
695
|
|
|
<br> |
696
|
|
|
<label for="_calendar_date_format_php"> |
697
|
|
|
<input type="text" |
698
|
|
|
name="_calendar_time_format_php" |
699
|
|
|
id="_calendar_time_format_php" |
700
|
|
|
class="simcal-field simcal-field-text simcal-field-small" |
701
|
|
|
value="<?php echo $time_format_php; ?>"/> |
702
|
|
|
<?php printf( __( 'Enter a time format using %s values.', 'google-calendar-events' ), '<a href="//php.net/manual/en/function.date.php" target="_blank">PHP</a>' ); ?> |
703
|
|
|
</label> |
704
|
|
|
<p> |
705
|
|
|
<em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em> |
706
|
|
|
<code><?php echo date_i18n( $time_format_php, time() ); ?></code> |
707
|
|
|
</p> |
708
|
|
|
</div> |
709
|
|
|
</td> |
710
|
|
|
</tr> |
711
|
|
|
<tr class="simcal-panel-field"> |
712
|
|
|
<th><label for="_calendar_week_starts_on_setting"><?php _e( 'Week Starts On', 'google-calendar-events' ); ?></label></th> |
713
|
|
|
<td> |
714
|
|
|
<?php |
715
|
|
|
|
716
|
|
|
$week_starts_setting = esc_attr( get_post_meta( $post->ID, '_calendar_week_starts_on_setting', true ) ); |
717
|
|
|
$week_starts_default = esc_attr( get_option( 'start_of_week' ) ); |
718
|
|
|
$week_starts = intval( get_post_meta( $post->ID, '_calendar_week_starts_on', true ) ); |
719
|
|
|
$week_starts = is_numeric( $week_starts ) ? strval( $week_starts ) : $week_starts_default; |
720
|
|
|
|
721
|
|
|
?> |
722
|
|
|
<select |
723
|
|
|
name="_calendar_week_starts_on_setting" |
724
|
|
|
id="_calendar_week_starts_on_setting" |
725
|
|
|
class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-next" |
726
|
|
|
data-show-next-if-value="use_custom"> |
727
|
|
|
<option value="use_site" <?php selected( 'use_site', $week_starts_setting, true ); ?>><?php printf( _x( 'Site default', 'Use this site default setting', 'google-calendar-events' ) . ' (%s)', date_i18n( 'l', strtotime( "Sunday + $week_starts_default Days" ) ) ); ?></option> |
728
|
|
|
<option value="use_custom" <?php selected( 'use_custom', $week_starts_setting, true ); ?>><?php _ex( 'Custom', 'Use a custom setting', 'google-calendar-events' ); ?></option> |
729
|
|
|
</select> |
730
|
|
|
<select |
731
|
|
|
name="_calendar_week_starts_on" |
732
|
|
|
id="_calendar_week_starts_on" |
733
|
|
|
class="simcal-field simcal-field-select simcal-field-inline" |
734
|
|
|
<?php echo 'use_custom' != $week_starts_setting ? 'style="display: none;"' : ''; ?>> |
735
|
|
|
<?php $day_names = simcal_get_calendar_names_i18n( 'day', 'full' ); ?> |
736
|
|
|
<?php for ( $i = 0; $i <= 6; $i++ ) : ?> |
737
|
|
|
<option value="<?php echo $i; ?>" <?php selected( $i, $week_starts, true ); ?>><?php echo $day_names[ $i ]; ?></option> |
738
|
|
|
<?php endfor; ?> |
739
|
|
|
</select> |
740
|
|
|
<i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'Some calendars may use this setting to display the start of the week. It is recommended to keep the site default setting.', 'google-calendar-events' ); ?>"></i> |
741
|
|
|
</td> |
742
|
|
|
</tr> |
743
|
|
|
</tbody> |
744
|
|
|
</table> |
745
|
|
|
<table> |
746
|
|
|
<thead> |
747
|
|
|
<tr><th colspan="2"><?php _e( 'Cache', 'google-calendar-events' ); ?></th></tr> |
748
|
|
|
</thead> |
749
|
|
|
<tbody class="simcal-panel-section simcal-panel-section-cache"> |
750
|
|
|
<?php |
751
|
|
|
|
752
|
|
|
$cache_freq = esc_attr( get_post_meta( $post->ID, '_feed_cache_user_amount', true ) ); |
753
|
|
|
$cache_unit = esc_attr( get_post_meta( $post->ID, '_feed_cache_user_unit', true ) ); |
754
|
|
|
|
755
|
|
|
$cache_freq = intval( $cache_freq ) && $cache_freq >= 0 ? $cache_freq : 2; |
756
|
|
|
$cache_unit = $cache_unit ? $cache_unit : '3600'; |
757
|
|
|
|
758
|
|
|
?> |
759
|
|
|
<tr class="simcal-panel-field"> |
760
|
|
|
<th><label for="_feed_cache_user_amount"><?php _ex( 'Refresh Interval', 'Cache maximum interval', 'google-calendar-events' ); ?></label></th> |
761
|
|
|
<td> |
762
|
|
|
<input type="number" |
763
|
|
|
name="_feed_cache_user_amount" |
764
|
|
|
id="_feed_cache_user_amount" |
765
|
|
|
class="simcal-field simcal-field-number simcal-field-tiny simcal-field-inline" |
766
|
|
|
value="<?php echo $cache_freq; ?>" |
767
|
|
|
min="0" /> |
768
|
|
|
<select name="_feed_cache_user_unit" |
769
|
|
|
id="_feed_cache_user_unit" |
770
|
|
|
class="simcal-field simcalfield-select simcal-field-inline"> |
771
|
|
|
<option value="60" <?php selected( '60', $cache_unit, true ); ?>><?php _e( 'Minute(s)', 'google-calendar-events' ); ?></option> |
772
|
|
|
<option value="3600" <?php selected( '3600', $cache_unit, true ); ?>><?php _e( 'Hour(s)', 'google-calendar-events' ); ?></option> |
773
|
|
|
<option value="86400" <?php selected( '86400', $cache_unit, true ); ?>><?php _e( 'Day(s)', 'google-calendar-events' ); ?></option> |
774
|
|
|
<option value="604800" <?php selected( '604800', $cache_unit, true ); ?>><?php _e( 'Week(s)', 'google-calendar-events' ); ?></option> |
775
|
|
|
</select> |
776
|
|
|
<i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e( 'If you add, edit or remove events in your calendar very often, you can set a lower interval to refresh the events displayed. Set a higher interval for best performance.', 'google-calendar-events' ); ?>"></i> |
777
|
|
|
</td> |
778
|
|
|
</tr> |
779
|
|
|
</tbody> |
780
|
|
|
</table> |
781
|
|
|
<?php |
782
|
|
|
|
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
/** |
786
|
|
|
* Print fields in a panel. |
787
|
|
|
* |
788
|
|
|
* @since 3.0.0 |
789
|
|
|
* |
790
|
|
|
* @param array $array |
791
|
|
|
* @param int $post_id |
792
|
|
|
* |
793
|
|
|
* @return void |
794
|
|
|
*/ |
795
|
|
|
public static function print_panel_fields( $array, $post_id ) { |
796
|
|
|
|
797
|
|
|
foreach ( $array as $section => $fields ) : |
798
|
|
|
|
799
|
|
|
if ( $fields && is_array( $fields ) ) : |
800
|
|
|
|
801
|
|
|
?> |
802
|
|
|
<tbody class="simcal-panel-section simcal-panel-section-<?php echo esc_attr( $section ); ?>"> |
803
|
|
|
<?php foreach ( $fields as $key => $field ) : |
804
|
|
|
|
805
|
|
|
$value = get_post_meta( $post_id, $key, true ); |
806
|
|
|
$field['value'] = $value ? $value : ( isset( $field['default'] ) ? $field['default'] : '' ); |
807
|
|
|
$the_field = simcal_get_field( $field ); ?> |
808
|
|
|
|
809
|
|
|
<?php if ( $the_field instanceof Field ) : ?> |
810
|
|
|
<tr class="simcal-panel-field"> |
811
|
|
|
<th><label for="<?php echo $the_field->id ?>"><?php echo $the_field->title; ?></label></th> |
812
|
|
|
<td><?php $the_field->html(); ?></td> |
813
|
|
|
</tr> |
814
|
|
|
<?php endif; ?> |
815
|
|
|
|
816
|
|
|
<?php endforeach; ?> |
817
|
|
|
</tbody> |
818
|
|
|
<?php |
819
|
|
|
|
820
|
|
|
endif; |
821
|
|
|
|
822
|
|
|
endforeach; |
823
|
|
|
|
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
/** |
827
|
|
|
* Validate and save the meta box fields. |
828
|
|
|
* |
829
|
|
|
* @since 3.0.0 |
830
|
|
|
* |
831
|
|
|
* @param int $post_id |
832
|
|
|
* @param \WP_Post $post |
833
|
|
|
* |
834
|
|
|
* @return void |
835
|
|
|
*/ |
836
|
|
|
public static function save( $post_id, $post ) { |
837
|
|
|
|
838
|
|
|
/* ====================== * |
839
|
|
|
* Calendar type and view * |
840
|
|
|
* ====================== */ |
841
|
|
|
|
842
|
|
|
// Unlink existing terms for feed type and calendar type. |
843
|
|
|
wp_delete_object_term_relationships( $post_id, array( |
844
|
|
|
'calendar_feed', |
845
|
|
|
'calendar_type', |
846
|
|
|
) ); |
847
|
|
|
|
848
|
|
|
// Set the feed type as term. |
849
|
|
|
$feed_type = isset( $_POST['_feed_type'] ) ? sanitize_title( stripslashes( $_POST['_feed_type'] ) ) : apply_filters( 'simcal_default_feed_type', 'google' ); |
850
|
|
|
wp_set_object_terms( $post_id, $feed_type, 'calendar_feed' ); |
851
|
|
|
|
852
|
|
|
// Set the calendar type as a term. |
853
|
|
|
$calendar_type = isset( $_POST['_calendar_type'] ) ? sanitize_title( stripslashes( $_POST['_calendar_type'] ) ) : apply_filters( 'simcal_default_calendar_type', 'default-calendar' ); |
854
|
|
|
wp_set_object_terms( $post_id, $calendar_type, 'calendar_type' ); |
855
|
|
|
// Set the calendar type view as post meta. |
856
|
|
|
$calendar_view = isset( $_POST['_calendar_view'] ) ? $_POST['_calendar_view'] : ''; |
857
|
|
|
if ( $calendar_view && is_array( $calendar_view ) ) { |
858
|
|
|
$views = array_map( 'sanitize_title', $calendar_view ); |
859
|
|
|
update_post_meta( $post_id, '_calendar_view', $views ); |
860
|
|
|
} |
861
|
|
|
|
862
|
|
|
/* ===================== * |
863
|
|
|
* Events settings panel * |
864
|
|
|
* ===================== */ |
865
|
|
|
|
866
|
|
|
// Calendar opening. |
867
|
|
|
$calendar_begins = isset( $_POST['_calendar_begins'] ) ? sanitize_key( $_POST['_calendar_begins'] ) : 'this_month'; |
868
|
|
|
update_post_meta( $post_id, '_calendar_begins', $calendar_begins ); |
869
|
|
|
$calendar_begins_nth = isset( $_POST['_calendar_begins_nth'] ) ? absint( $_POST['_calendar_begins_nth'] ) : 2; |
870
|
|
|
update_post_meta( $post_id, '_calendar_begins_nth', $calendar_begins_nth ); |
871
|
|
|
$calendar_begins_custom_date = isset( $_POST['_calendar_begins_custom_date'] ) ? sanitize_title( $_POST['_calendar_begins_custom_date'] ) : ''; |
872
|
|
|
update_post_meta( $post_id, '_calendar_begins_custom_date', $calendar_begins_custom_date ); |
873
|
|
|
|
874
|
|
|
// Feed earliest events date. |
875
|
|
|
$earliest_events = isset( $_POST['_feed_earliest_event_date'] ) ? sanitize_key( $_POST['_feed_earliest_event_date'] ) : ''; |
876
|
|
|
update_post_meta( $post_id, '_feed_earliest_event_date', $earliest_events ); |
877
|
|
|
$earliest_events_range = isset( $_POST['_feed_earliest_event_date_range'] ) ? max( absint( $_POST['_feed_earliest_event_date_range'] ), 1 ) : 1; |
878
|
|
|
update_post_meta( $post_id, '_feed_earliest_event_date_range', $earliest_events_range ); |
879
|
|
|
|
880
|
|
|
// Feed latest events date. |
881
|
|
|
$latest_events = isset( $_POST['_feed_latest_event_date'] ) ? sanitize_key( $_POST['_feed_latest_event_date'] ) : ''; |
882
|
|
|
update_post_meta( $post_id, '_feed_latest_event_date', $latest_events ); |
883
|
|
|
$latest_events_range = isset( $_POST['_feed_latest_event_date_range'] ) ? max( absint( $_POST['_feed_latest_event_date_range'] ), 1 ) : 1; |
884
|
|
|
update_post_meta( $post_id, '_feed_latest_event_date_range', $latest_events_range ); |
885
|
|
|
|
886
|
|
|
/* ======================= * |
887
|
|
|
* Calendar settings panel * |
888
|
|
|
* ======================= */ |
889
|
|
|
|
890
|
|
|
// Static calendar. |
891
|
|
|
$static = isset( $_POST['_calendar_is_static'] ) ? 'yes' : 'no'; |
892
|
|
|
update_post_meta( $post_id, '_calendar_is_static', $static ); |
893
|
|
|
|
894
|
|
|
// No events message. |
895
|
|
|
$message = isset( $_POST['_no_events_message'] ) ? wp_kses_post( $_POST['_no_events_message'] ) : ''; |
896
|
|
|
update_post_meta( $post_id, '_no_events_message', $message ); |
897
|
|
|
|
898
|
|
|
// _event_formatting |
899
|
|
|
$event_formatting = isset( $_POST['_event_formatting'] ) ? sanitize_key( $_POST['_event_formatting'] ) : 'preserve_linebreaks'; |
900
|
|
|
update_post_meta( $post_id, '_event_formatting', $event_formatting ); |
901
|
|
|
|
902
|
|
|
// Powered by option |
903
|
|
|
$poweredby = isset( $_POST['_poweredby'] ) ? 'yes' : 'no'; |
904
|
|
|
update_post_meta( $post_id, '_poweredby', $poweredby ); |
905
|
|
|
|
906
|
|
|
/* ======================= * |
907
|
|
|
* Advanced settings panel * |
908
|
|
|
* ======================= */ |
909
|
|
|
|
910
|
|
|
// Timezone. |
911
|
|
|
$feed_timezone_setting = isset( $_POST['_feed_timezone_setting'] ) ? sanitize_key( $_POST['_feed_timezone_setting'] ) : 'use_calendar'; |
912
|
|
|
update_post_meta( $post_id, '_feed_timezone_setting', $feed_timezone_setting ); |
913
|
|
|
$default_timezone = simcal_get_wp_timezone(); |
914
|
|
|
$feed_timezone = $default_timezone ? $default_timezone : 'UTC'; |
915
|
|
|
$feed_timezone = isset( $_POST['_feed_timezone'] ) ? sanitize_text_field( $_POST['_feed_timezone'] ) : $feed_timezone; |
916
|
|
|
update_post_meta( $post_id, '_feed_timezone', $feed_timezone ); |
917
|
|
|
|
918
|
|
|
// Date format. |
919
|
|
|
$date_format_setting = isset( $_POST['_calendar_date_format_setting'] ) ? sanitize_key( $_POST['_calendar_date_format_setting'] ) : 'use_site'; |
920
|
|
|
update_post_meta( $post_id, '_calendar_date_format_setting', $date_format_setting ); |
921
|
|
|
$date_format = isset( $_POST['_calendar_date_format'] ) ? sanitize_text_field( trim( $_POST['_calendar_date_format'] ) ) : get_option( 'date_format' ); |
922
|
|
|
update_post_meta( $post_id, '_calendar_date_format', $date_format ); |
923
|
|
|
$date_format_php = isset( $_POST['_calendar_date_format_php'] ) ? sanitize_text_field( trim( $_POST['_calendar_date_format_php'] ) ) : get_option( 'date_format' ); |
924
|
|
|
update_post_meta( $post_id, '_calendar_date_format_php', $date_format_php ); |
925
|
|
|
|
926
|
|
|
// Time format. |
927
|
|
|
$time_format_setting = isset( $_POST['_calendar_time_format_setting'] ) ? sanitize_key( $_POST['_calendar_time_format_setting'] ) : 'use_site'; |
928
|
|
|
update_post_meta( $post_id, '_calendar_time_format_setting', $time_format_setting ); |
929
|
|
|
$time_format = isset( $_POST['_calendar_time_format'] ) ? sanitize_text_field( trim( $_POST['_calendar_time_format'] ) ) : get_option( 'time_format' ); |
930
|
|
|
update_post_meta( $post_id, '_calendar_time_format', $time_format ); |
931
|
|
|
$time_format_php = isset( $_POST['_calendar_time_format_php'] ) ? sanitize_text_field( trim( $_POST['_calendar_time_format_php'] ) ) : get_option( 'time_format' ); |
932
|
|
|
update_post_meta( $post_id, '_calendar_time_format_php', $time_format_php ); |
933
|
|
|
|
934
|
|
|
// Date-time separator. |
935
|
|
|
$datetime_separator = isset( $_POST['_calendar_datetime_separator'] ) ? sanitize_text_field( $_POST['_calendar_datetime_separator'] ) : ' '; |
936
|
|
|
update_post_meta( $post_id, '_calendar_datetime_separator', $datetime_separator ); |
937
|
|
|
|
938
|
|
|
// Week start. |
939
|
|
|
$week_start_setting = isset( $_POST['_calendar_week_starts_on_setting'] ) ? sanitize_key( $_POST['_calendar_week_starts_on_setting'] ) : 'use_site'; |
940
|
|
|
update_post_meta( $post_id, '_calendar_week_starts_on_setting', $week_start_setting ); |
941
|
|
|
$week_start = isset( $_POST['_calendar_week_starts_on'] ) ? intval( $_POST['_calendar_week_starts_on'] ) : get_option( 'start_of_week' ); |
942
|
|
|
update_post_meta( $post_id, '_calendar_week_starts_on', $week_start ); |
943
|
|
|
|
944
|
|
|
// Cache interval. |
945
|
|
|
$cache = 7200; |
946
|
|
|
if ( isset( $_POST['_feed_cache_user_amount'] ) && isset( $_POST['_feed_cache_user_unit'] ) ) { |
947
|
|
|
$amount = is_numeric( $_POST['_feed_cache_user_amount'] ) || $_POST['_feed_cache_user_amount'] == 0 ? absint( $_POST['_feed_cache_user_amount'] ) : 1; |
948
|
|
|
$unit = is_numeric( $_POST['_feed_cache_user_unit'] ) ? absint( $_POST['_feed_cache_user_unit'] ) : 3600; |
949
|
|
|
update_post_meta( $post_id, '_feed_cache_user_amount', $amount ); |
950
|
|
|
update_post_meta( $post_id, '_feed_cache_user_unit', $unit ); |
951
|
|
|
$cache = ( ( $amount * $unit ) > 0 ) ? $amount * $unit : 1; |
952
|
|
|
} |
953
|
|
|
update_post_meta( $post_id, '_feed_cache', $cache ); |
954
|
|
|
|
955
|
|
|
/* ============= * |
956
|
|
|
* Miscellaneous * |
957
|
|
|
* ============= */ |
958
|
|
|
|
959
|
|
|
// Update version. |
960
|
|
|
update_post_meta( $post_id, '_calendar_version', SIMPLE_CALENDAR_VERSION ); |
961
|
|
|
|
962
|
|
|
// Action hook. |
963
|
|
|
do_action( 'simcal_process_settings_meta', $post_id ); |
964
|
|
|
|
965
|
|
|
// Clear cache. |
966
|
|
|
simcal_delete_feed_transients( $post_id ); |
967
|
|
|
} |
968
|
|
|
|
969
|
|
|
} |
970
|
|
|
|