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
|
|
|
'placeholder' => __( 'There are no upcoming events.', 'google-calendar-events' ), |
481
|
|
|
) ); |
482
|
|
|
|
483
|
|
|
?> |
484
|
|
|
</td> |
485
|
|
|
</tr> |
486
|
|
|
<tr class="simcal-panel-field"> |
487
|
|
|
<th><label for="_event_formatting"><?php _e( 'Event Formatting', 'google-calendar-events' ); ?></label></th> |
488
|
|
|
<td> |
489
|
|
|
<?php |
490
|
|
|
|
491
|
|
|
$event_formatting = get_post_meta( $post->ID, '_event_formatting', true ); |
492
|
|
|
|
493
|
|
|
simcal_print_field( array( |
494
|
|
|
'type' => 'select', |
495
|
|
|
'name' => '_event_formatting', |
496
|
|
|
'id' => '_event_formatting', |
497
|
|
|
'tooltip' => __( 'How to preserve line breaks and paragraphs in the event template builder.', 'google-calendar-events' ), |
498
|
|
|
'value' => $event_formatting, |
499
|
|
|
'default' => 'preserve_linebreaks', |
500
|
|
|
'options' => array( |
501
|
|
|
'preserve_linebreaks' => __( 'Preserve line breaks, auto paragraphs (default)', 'google-calendar-events' ), |
502
|
|
|
'no_linebreaks' => __( 'No line breaks, auto paragraphs', 'google-calendar-events' ), |
503
|
|
|
'none' => __( 'No line breaks, no auto paragraphs', 'google-calendar-events' ), |
504
|
|
|
), |
505
|
|
|
) ); |
506
|
|
|
|
507
|
|
|
?> |
508
|
|
|
</td> |
509
|
|
|
</tr> |
510
|
|
|
<tr class="simcal-panel-field"> |
511
|
|
|
<th><label for="_poweredby"><?php _e( 'Powered By', 'google-calendar-events' ); ?></label></th> |
512
|
|
|
<td> |
513
|
|
|
<?php |
514
|
|
|
|
515
|
|
|
$poweredby = get_post_meta( $post->ID, '_poweredby', true ); |
516
|
|
|
|
517
|
|
|
simcal_print_field( array( |
518
|
|
|
'type' => 'checkbox', |
519
|
|
|
'name' => '_poweredby', |
520
|
|
|
'id' => '_poweredby', |
521
|
|
|
'value' => 'yes' == $poweredby ? 'yes' : 'no', |
522
|
|
|
'text' => __( 'Yes, Simple Calendar rocks! Show some love with a little link below this calendar.', 'google-calendar-events' ), |
523
|
|
|
) ); |
524
|
|
|
|
525
|
|
|
?> |
526
|
|
|
</td> |
527
|
|
|
</tr> |
528
|
|
|
</tbody> |
529
|
|
|
</table> |
530
|
|
|
<?php |
531
|
|
|
|
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* Print the advanced settings panel. |
536
|
|
|
* |
537
|
|
|
* @since 3.0.0 |
538
|
|
|
* @access private |
539
|
|
|
* |
540
|
|
|
* @param \WP_Post $post |
541
|
|
|
*/ |
542
|
|
|
private static function advanced_settings_panel( $post ) { |
543
|
|
|
|
544
|
|
|
?> |
545
|
|
|
<table> |
546
|
|
|
<thead> |
547
|
|
|
<tr><th colspan="2"><?php _e( 'Date and Time', 'google-calendar-events' ); ?></th></tr> |
548
|
|
|
</thead> |
549
|
|
|
<tbody class="simcal-panel-section simcal-panel-datetime-formatting"> |
550
|
|
|
<tr class="simcal-panel-field"> |
551
|
|
|
<th><label for="_calendar_timezone_setting"><?php _e( 'Timezone', 'google-calendar-events' ); ?></label></th> |
552
|
|
|
<td> |
553
|
|
|
<?php |
554
|
|
|
|
555
|
|
|
$timezone_wordpress = simcal_get_wp_timezone(); |
556
|
|
|
$timezone_default = $timezone_wordpress ? $timezone_wordpress : 'UTC'; |
557
|
|
|
$timezone_setting = esc_attr( get_post_meta( $post->ID, '_feed_timezone_setting', true ) ); |
558
|
|
|
$timezone = esc_attr( get_post_meta( $post->ID, '_feed_timezone', true ) ); |
559
|
|
|
$timezone = $timezone ? $timezone : $timezone_default; |
560
|
|
|
$show_use_calendar = isset( simcal_get_feed( $post )->type ); |
561
|
|
|
|
562
|
|
|
if ( $show_use_calendar ) { |
563
|
|
|
$show_use_calendar = ( simcal_get_feed( $post )->type !== 'grouped-calendars' ? 1 : 0 ); |
564
|
|
|
} else { |
565
|
|
|
$show_use_calendar = true; |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
?> |
569
|
|
|
<select name="_feed_timezone_setting" |
570
|
|
|
id="_feed_timezone_setting" |
571
|
|
|
class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-other" |
572
|
|
|
data-show-field-on-choice="true"> |
573
|
|
|
<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> |
574
|
|
|
<?php if ( $show_use_calendar ) { ?> |
575
|
|
|
<option id="use_calendar" value="use_calendar" data-show-field="_use_calendar_warning" <?php selected( 'use_calendar', $timezone_setting, true ); ?>><?php _ex( 'Event source default', 'Use the calendar default setting', 'google-calendar-events' ); ?></option> |
576
|
|
|
<?php } ?> |
577
|
|
|
<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> |
578
|
|
|
</select> |
579
|
|
|
<select name="_feed_timezone" |
580
|
|
|
id="_feed_timezone" |
581
|
|
|
class="simcal-field simcal-field-select simcal-field-inline" |
582
|
|
|
<?php echo 'use_custom' != $timezone_setting ? 'style="display: none;"' : ''; ?>> |
583
|
|
|
<?php echo wp_timezone_choice( $timezone ); ?> |
584
|
|
|
</select> |
585
|
|
|
<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. We recommended using the site default timezone.', 'google-calendar-events' ); ?>"></i> |
586
|
|
|
<p id="_use_calendar_warning" style="display: none;" class="simcal-field"> |
587
|
|
|
<span class="attention"><?php _e( 'Warning', 'google-calendar-events' ); ?>:</span> |
588
|
|
|
<?php _e( 'Setting this to <code>Event source default</code> can at times cause unexpected results. Please test thoroughly.', 'google-calendar-events' ); ?> |
589
|
|
|
<a href="http://docs.simplecalendar.io/timezone-settings/" target="_blank"><?php _e( 'See details.', 'google-calendar-events' ); ?></a> |
590
|
|
|
</p> |
591
|
|
|
</td> |
592
|
|
|
</tr> |
593
|
|
|
<tr class="simcal-panel-field"> |
594
|
|
|
<th><label for="_calendar_date_format_setting"><?php _e( 'Date Format', 'google-calendar-events' ); ?></label></th> |
595
|
|
|
<td> |
596
|
|
|
<?php |
597
|
|
|
|
598
|
|
|
$date_format_setting = esc_attr( get_post_meta( $post->ID, '_calendar_date_format_setting', true ) ); |
599
|
|
|
$date_format_default = esc_attr( get_option( 'date_format' ) ); |
600
|
|
|
$date_format = esc_attr( get_post_meta( $post->ID, '_calendar_date_format', true ) ); |
601
|
|
|
$date_format_php = esc_attr( get_post_meta( $post->ID, '_calendar_date_format_php', true ) ); |
602
|
|
|
$date_format_php = $date_format_php ? $date_format_php : $date_format_default; |
603
|
|
|
|
604
|
|
|
?> |
605
|
|
|
<select name="_calendar_date_format_setting" |
606
|
|
|
id="_calendar_date_format_setting" |
607
|
|
|
class="simcal-field simcal-field-select simcal-field-show-other"> |
608
|
|
|
<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> |
609
|
|
|
<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> |
610
|
|
|
<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> |
611
|
|
|
</select> |
612
|
|
|
<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> |
613
|
|
|
<p id="_calendar_date_format_default" style="<?php echo $date_format_setting != 'use_site' ? 'display: none;' : ''; ?>"> |
614
|
|
|
<em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em> |
615
|
|
|
<code><?php echo date_i18n( $date_format_default, time() ); ?></code> |
616
|
|
|
</p> |
617
|
|
|
<?php simcal_print_field( array( |
618
|
|
|
'type' => 'datetime-format', |
619
|
|
|
'subtype' => 'date', |
620
|
|
|
'name' => '_calendar_date_format', |
621
|
|
|
'id' => '_calendar_date_format', |
622
|
|
|
'value' => $date_format, |
623
|
|
|
'style' => $date_format_setting != 'use_custom' ? array( 'display' => 'none' ) : '', |
624
|
|
|
) ); ?> |
625
|
|
|
<div class="simcal-field-datetime-format-php" id="_calendar_date_format_php_field" style="<?php echo $date_format_setting != 'use_custom_php' ? 'display: none;' : ''; ?>"> |
626
|
|
|
<br> |
627
|
|
|
<label for="_calendar_date_format_php"> |
628
|
|
|
<input type="text" |
629
|
|
|
name="_calendar_date_format_php" |
630
|
|
|
id="_calendar_date_format_php" |
631
|
|
|
class="simcal-field simcal-field-text simcal-field-small" |
632
|
|
|
value="<?php echo $date_format_php; ?>" /> |
633
|
|
|
<?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>' ); ?> |
634
|
|
|
</label> |
635
|
|
|
<p> |
636
|
|
|
<em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em> |
637
|
|
|
<code><?php echo date_i18n( $date_format_php, time() ); ?></code> |
638
|
|
|
</p> |
639
|
|
|
</div> |
640
|
|
|
</td> |
641
|
|
|
</tr> |
642
|
|
|
<tr class="simcal-panel-field"> |
643
|
|
|
<th><label for="_calendar_datetime_separator"><?php _e( 'Separator', 'google-calendar-events' ); ?></label></th> |
644
|
|
|
<td> |
645
|
|
|
<?php |
646
|
|
|
|
647
|
|
|
$separator = get_post_meta( $post->ID, '_calendar_datetime_separator', true ); |
648
|
|
|
$separator = false == $separator ? '@' : $separator; |
649
|
|
|
|
650
|
|
|
simcal_print_field( array( |
651
|
|
|
'type' => 'standard', |
652
|
|
|
'subtype' => 'text', |
653
|
|
|
'name' => '_calendar_datetime_separator', |
654
|
|
|
'id' => '_calendar_datetime_separator', |
655
|
|
|
'value' => $separator, |
656
|
|
|
'tooltip' => __( 'Used to divide date and time when both are shown.', 'google-calendar-events' ), |
657
|
|
|
'class' => array( |
658
|
|
|
'simcal-field-tiny', |
659
|
|
|
), |
660
|
|
|
) ); |
661
|
|
|
|
662
|
|
|
?> |
663
|
|
|
</td> |
664
|
|
|
</tr> |
665
|
|
|
<tr class="simcal-panel-field"> |
666
|
|
|
<th><label for="_calendar_time_format_setting"><?php _e( 'Time Format', 'google-calendar-events' ); ?></label></th> |
667
|
|
|
<td> |
668
|
|
|
<?php |
669
|
|
|
|
670
|
|
|
$time_format_setting = esc_attr( get_post_meta( $post->ID, '_calendar_time_format_setting', true ) ); |
671
|
|
|
$time_format_default = esc_attr( get_option( 'time_format' ) ); |
672
|
|
|
$time_format = esc_attr( get_post_meta( $post->ID, '_calendar_time_format', true ) ); |
673
|
|
|
$time_format_php = esc_attr( get_post_meta( $post->ID, '_calendar_time_format_php', true ) ); |
674
|
|
|
$time_format_php = $time_format_php ? $time_format_php : $time_format_default; |
675
|
|
|
|
676
|
|
|
?> |
677
|
|
|
<select name="_calendar_time_format_setting" |
678
|
|
|
id="_calendar_time_format_setting" |
679
|
|
|
class="simcal-field simcal-field-select simcal-field-show-other"> |
680
|
|
|
<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> |
681
|
|
|
<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> |
682
|
|
|
<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> |
683
|
|
|
</select> |
684
|
|
|
<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> |
685
|
|
|
<p id="_calendar_time_format_default" style="<?php echo $time_format_setting != 'use_site' ? 'display: none;' : ''; ?>"> |
686
|
|
|
<em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em> |
687
|
|
|
<code><?php echo date_i18n( $time_format_default, time() ); ?></code> |
688
|
|
|
</p> |
689
|
|
|
<?php simcal_print_field( array( |
690
|
|
|
'type' => 'datetime-format', |
691
|
|
|
'subtype' => 'time', |
692
|
|
|
'name' => '_calendar_time_format', |
693
|
|
|
'id' => '_calendar_time_format', |
694
|
|
|
'value' => $time_format, |
695
|
|
|
'style' => $time_format_setting != 'use_custom' ? array( 'display' => 'none' ) : '', |
696
|
|
|
) ); ?> |
697
|
|
|
<div class="simcal-field-datetime-format-php" id="_calendar_time_format_php_field" style="<?php echo $time_format_setting != 'use_custom_php' ? 'display: none;' : ''; ?>"> |
698
|
|
|
<br> |
699
|
|
|
<label for="_calendar_date_format_php"> |
700
|
|
|
<input type="text" |
701
|
|
|
name="_calendar_time_format_php" |
702
|
|
|
id="_calendar_time_format_php" |
703
|
|
|
class="simcal-field simcal-field-text simcal-field-small" |
704
|
|
|
value="<?php echo $time_format_php; ?>"/> |
705
|
|
|
<?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>' ); ?> |
706
|
|
|
</label> |
707
|
|
|
<p> |
708
|
|
|
<em><?php _e( 'Preview', 'google-calendar-events' ) ?>:</em> |
709
|
|
|
<code><?php echo date_i18n( $time_format_php, time() ); ?></code> |
710
|
|
|
</p> |
711
|
|
|
</div> |
712
|
|
|
</td> |
713
|
|
|
</tr> |
714
|
|
|
<tr class="simcal-panel-field"> |
715
|
|
|
<th><label for="_calendar_week_starts_on_setting"><?php _e( 'Week Starts On', 'google-calendar-events' ); ?></label></th> |
716
|
|
|
<td> |
717
|
|
|
<?php |
718
|
|
|
|
719
|
|
|
$week_starts_setting = esc_attr( get_post_meta( $post->ID, '_calendar_week_starts_on_setting', true ) ); |
720
|
|
|
$week_starts_default = esc_attr( get_option( 'start_of_week' ) ); |
721
|
|
|
$week_starts = intval( get_post_meta( $post->ID, '_calendar_week_starts_on', true ) ); |
722
|
|
|
$week_starts = is_numeric( $week_starts ) ? strval( $week_starts ) : $week_starts_default; |
723
|
|
|
|
724
|
|
|
?> |
725
|
|
|
<select |
726
|
|
|
name="_calendar_week_starts_on_setting" |
727
|
|
|
id="_calendar_week_starts_on_setting" |
728
|
|
|
class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-next" |
729
|
|
|
data-show-next-if-value="use_custom"> |
730
|
|
|
<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> |
731
|
|
|
<option value="use_custom" <?php selected( 'use_custom', $week_starts_setting, true ); ?>><?php _ex( 'Custom', 'Use a custom setting', 'google-calendar-events' ); ?></option> |
732
|
|
|
</select> |
733
|
|
|
<select |
734
|
|
|
name="_calendar_week_starts_on" |
735
|
|
|
id="_calendar_week_starts_on" |
736
|
|
|
class="simcal-field simcal-field-select simcal-field-inline" |
737
|
|
|
<?php echo 'use_custom' != $week_starts_setting ? 'style="display: none;"' : ''; ?>> |
738
|
|
|
<?php $day_names = simcal_get_calendar_names_i18n( 'day', 'full' ); ?> |
739
|
|
|
<?php for ( $i = 0; $i <= 6; $i++ ) : ?> |
740
|
|
|
<option value="<?php echo $i; ?>" <?php selected( $i, $week_starts, true ); ?>><?php echo $day_names[ $i ]; ?></option> |
741
|
|
|
<?php endfor; ?> |
742
|
|
|
</select> |
743
|
|
|
<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> |
744
|
|
|
</td> |
745
|
|
|
</tr> |
746
|
|
|
</tbody> |
747
|
|
|
</table> |
748
|
|
|
<table> |
749
|
|
|
<thead> |
750
|
|
|
<tr><th colspan="2"><?php _e( 'Cache', 'google-calendar-events' ); ?></th></tr> |
751
|
|
|
</thead> |
752
|
|
|
<tbody class="simcal-panel-section simcal-panel-section-cache"> |
753
|
|
|
<?php |
754
|
|
|
|
755
|
|
|
$cache_freq = esc_attr( get_post_meta( $post->ID, '_feed_cache_user_amount', true ) ); |
756
|
|
|
$cache_unit = esc_attr( get_post_meta( $post->ID, '_feed_cache_user_unit', true ) ); |
757
|
|
|
|
758
|
|
|
$cache_freq = intval( $cache_freq ) && $cache_freq >= 0 ? $cache_freq : 2; |
759
|
|
|
$cache_unit = $cache_unit ? $cache_unit : '3600'; |
760
|
|
|
|
761
|
|
|
?> |
762
|
|
|
<tr class="simcal-panel-field"> |
763
|
|
|
<th><label for="_feed_cache_user_amount"><?php _ex( 'Refresh Interval', 'Cache maximum interval', 'google-calendar-events' ); ?></label></th> |
764
|
|
|
<td> |
765
|
|
|
<input type="number" |
766
|
|
|
name="_feed_cache_user_amount" |
767
|
|
|
id="_feed_cache_user_amount" |
768
|
|
|
class="simcal-field simcal-field-number simcal-field-tiny simcal-field-inline" |
769
|
|
|
value="<?php echo $cache_freq; ?>" |
770
|
|
|
min="0" /> |
771
|
|
|
<select name="_feed_cache_user_unit" |
772
|
|
|
id="_feed_cache_user_unit" |
773
|
|
|
class="simcal-field simcalfield-select simcal-field-inline"> |
774
|
|
|
<option value="60" <?php selected( '60', $cache_unit, true ); ?>><?php _e( 'Minute(s)', 'google-calendar-events' ); ?></option> |
775
|
|
|
<option value="3600" <?php selected( '3600', $cache_unit, true ); ?>><?php _e( 'Hour(s)', 'google-calendar-events' ); ?></option> |
776
|
|
|
<option value="86400" <?php selected( '86400', $cache_unit, true ); ?>><?php _e( 'Day(s)', 'google-calendar-events' ); ?></option> |
777
|
|
|
<option value="604800" <?php selected( '604800', $cache_unit, true ); ?>><?php _e( 'Week(s)', 'google-calendar-events' ); ?></option> |
778
|
|
|
</select> |
779
|
|
|
<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> |
780
|
|
|
</td> |
781
|
|
|
</tr> |
782
|
|
|
</tbody> |
783
|
|
|
</table> |
784
|
|
|
<?php |
785
|
|
|
|
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
/** |
789
|
|
|
* Print fields in a panel. |
790
|
|
|
* |
791
|
|
|
* @since 3.0.0 |
792
|
|
|
* |
793
|
|
|
* @param array $array |
794
|
|
|
* @param int $post_id |
795
|
|
|
* |
796
|
|
|
* @return void |
797
|
|
|
*/ |
798
|
|
|
public static function print_panel_fields( $array, $post_id ) { |
799
|
|
|
|
800
|
|
|
foreach ( $array as $section => $fields ) : |
801
|
|
|
|
802
|
|
|
if ( $fields && is_array( $fields ) ) : |
803
|
|
|
|
804
|
|
|
?> |
805
|
|
|
<tbody class="simcal-panel-section simcal-panel-section-<?php echo esc_attr( $section ); ?>"> |
806
|
|
|
<?php foreach ( $fields as $key => $field ) : |
807
|
|
|
|
808
|
|
|
$value = get_post_meta( $post_id, $key, true ); |
809
|
|
|
$field['value'] = $value ? $value : ( isset( $field['default'] ) ? $field['default'] : '' ); |
810
|
|
|
$the_field = simcal_get_field( $field ); ?> |
811
|
|
|
|
812
|
|
|
<?php if ( $the_field instanceof Field ) : ?> |
813
|
|
|
<tr class="simcal-panel-field"> |
814
|
|
|
<th><label for="<?php echo $the_field->id ?>"><?php echo $the_field->title; ?></label></th> |
815
|
|
|
<td><?php $the_field->html(); ?></td> |
816
|
|
|
</tr> |
817
|
|
|
<?php endif; ?> |
818
|
|
|
|
819
|
|
|
<?php endforeach; ?> |
820
|
|
|
</tbody> |
821
|
|
|
<?php |
822
|
|
|
|
823
|
|
|
endif; |
824
|
|
|
|
825
|
|
|
endforeach; |
826
|
|
|
|
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
/** |
830
|
|
|
* Validate and save the meta box fields. |
831
|
|
|
* |
832
|
|
|
* @since 3.0.0 |
833
|
|
|
* |
834
|
|
|
* @param int $post_id |
835
|
|
|
* @param \WP_Post $post |
836
|
|
|
* |
837
|
|
|
* @return void |
838
|
|
|
*/ |
839
|
|
|
public static function save( $post_id, $post ) { |
|
|
|
|
840
|
|
|
|
841
|
|
|
/* ====================== * |
842
|
|
|
* Calendar type and view * |
843
|
|
|
* ====================== */ |
844
|
|
|
|
845
|
|
|
// Unlink existing terms for feed type and calendar type. |
846
|
|
|
wp_delete_object_term_relationships( $post_id, array( |
847
|
|
|
'calendar_feed', |
848
|
|
|
'calendar_type', |
849
|
|
|
) ); |
850
|
|
|
|
851
|
|
|
// Set the feed type as term. |
852
|
|
|
$feed_type = isset( $_POST['_feed_type'] ) ? sanitize_title( stripslashes( $_POST['_feed_type'] ) ) : apply_filters( 'simcal_default_feed_type', 'google' ); |
853
|
|
|
wp_set_object_terms( $post_id, $feed_type, 'calendar_feed' ); |
854
|
|
|
|
855
|
|
|
// Set the calendar type as a term. |
856
|
|
|
$calendar_type = isset( $_POST['_calendar_type'] ) ? sanitize_title( stripslashes( $_POST['_calendar_type'] ) ) : apply_filters( 'simcal_default_calendar_type', 'default-calendar' ); |
857
|
|
|
wp_set_object_terms( $post_id, $calendar_type, 'calendar_type' ); |
858
|
|
|
// Set the calendar type view as post meta. |
859
|
|
|
$calendar_view = isset( $_POST['_calendar_view'] ) ? $_POST['_calendar_view'] : ''; |
860
|
|
|
if ( $calendar_view && is_array( $calendar_view ) ) { |
861
|
|
|
$views = array_map( 'sanitize_title', $calendar_view ); |
862
|
|
|
update_post_meta( $post_id, '_calendar_view', $views ); |
863
|
|
|
} |
864
|
|
|
|
865
|
|
|
/* ===================== * |
866
|
|
|
* Events settings panel * |
867
|
|
|
* ===================== */ |
868
|
|
|
|
869
|
|
|
// Calendar opening. |
870
|
|
|
$calendar_begins = isset( $_POST['_calendar_begins'] ) ? sanitize_key( $_POST['_calendar_begins'] ) : 'this_month'; |
871
|
|
|
update_post_meta( $post_id, '_calendar_begins', $calendar_begins ); |
872
|
|
|
$calendar_begins_nth = isset( $_POST['_calendar_begins_nth'] ) ? absint( $_POST['_calendar_begins_nth'] ) : 2; |
873
|
|
|
update_post_meta( $post_id, '_calendar_begins_nth', $calendar_begins_nth ); |
874
|
|
|
$calendar_begins_custom_date = isset( $_POST['_calendar_begins_custom_date'] ) ? sanitize_title( $_POST['_calendar_begins_custom_date'] ) : ''; |
875
|
|
|
update_post_meta( $post_id, '_calendar_begins_custom_date', $calendar_begins_custom_date ); |
876
|
|
|
|
877
|
|
|
// Feed earliest events date. |
878
|
|
|
$earliest_events = isset( $_POST['_feed_earliest_event_date'] ) ? sanitize_key( $_POST['_feed_earliest_event_date'] ) : ''; |
879
|
|
|
update_post_meta( $post_id, '_feed_earliest_event_date', $earliest_events ); |
880
|
|
|
$earliest_events_range = isset( $_POST['_feed_earliest_event_date_range'] ) ? max( absint( $_POST['_feed_earliest_event_date_range'] ), 1 ) : 1; |
881
|
|
|
update_post_meta( $post_id, '_feed_earliest_event_date_range', $earliest_events_range ); |
882
|
|
|
|
883
|
|
|
// Feed latest events date. |
884
|
|
|
$latest_events = isset( $_POST['_feed_latest_event_date'] ) ? sanitize_key( $_POST['_feed_latest_event_date'] ) : ''; |
885
|
|
|
update_post_meta( $post_id, '_feed_latest_event_date', $latest_events ); |
886
|
|
|
$latest_events_range = isset( $_POST['_feed_latest_event_date_range'] ) ? max( absint( $_POST['_feed_latest_event_date_range'] ), 1 ) : 1; |
887
|
|
|
update_post_meta( $post_id, '_feed_latest_event_date_range', $latest_events_range ); |
888
|
|
|
|
889
|
|
|
/* ======================= * |
890
|
|
|
* Calendar settings panel * |
891
|
|
|
* ======================= */ |
892
|
|
|
|
893
|
|
|
// Static calendar. |
894
|
|
|
$static = isset( $_POST['_calendar_is_static'] ) ? 'yes' : 'no'; |
895
|
|
|
update_post_meta( $post_id, '_calendar_is_static', $static ); |
896
|
|
|
|
897
|
|
|
// No events message. |
898
|
|
|
$message = isset( $_POST['_no_events_message'] ) ? wp_kses_post( $_POST['_no_events_message'] ) : ''; |
899
|
|
|
update_post_meta( $post_id, '_no_events_message', $message ); |
900
|
|
|
|
901
|
|
|
// _event_formatting |
902
|
|
|
$event_formatting = isset( $_POST['_event_formatting'] ) ? sanitize_key( $_POST['_event_formatting'] ) : 'preserve_linebreaks'; |
903
|
|
|
update_post_meta( $post_id, '_event_formatting', $event_formatting ); |
904
|
|
|
|
905
|
|
|
// Powered by option |
906
|
|
|
$poweredby = isset( $_POST['_poweredby'] ) ? 'yes' : 'no'; |
907
|
|
|
update_post_meta( $post_id, '_poweredby', $poweredby ); |
908
|
|
|
|
909
|
|
|
/* ======================= * |
910
|
|
|
* Advanced settings panel * |
911
|
|
|
* ======================= */ |
912
|
|
|
|
913
|
|
|
// Timezone. |
914
|
|
|
$feed_timezone_setting = isset( $_POST['_feed_timezone_setting'] ) ? sanitize_key( $_POST['_feed_timezone_setting'] ) : 'use_calendar'; |
915
|
|
|
update_post_meta( $post_id, '_feed_timezone_setting', $feed_timezone_setting ); |
916
|
|
|
$default_timezone = simcal_get_wp_timezone(); |
917
|
|
|
$feed_timezone = $default_timezone ? $default_timezone : 'UTC'; |
918
|
|
|
$feed_timezone = isset( $_POST['_feed_timezone'] ) ? sanitize_text_field( $_POST['_feed_timezone'] ) : $feed_timezone; |
919
|
|
|
update_post_meta( $post_id, '_feed_timezone', $feed_timezone ); |
920
|
|
|
|
921
|
|
|
// Date format. |
922
|
|
|
$date_format_setting = isset( $_POST['_calendar_date_format_setting'] ) ? sanitize_key( $_POST['_calendar_date_format_setting'] ) : 'use_site'; |
923
|
|
|
update_post_meta( $post_id, '_calendar_date_format_setting', $date_format_setting ); |
924
|
|
|
$date_format = isset( $_POST['_calendar_date_format'] ) ? sanitize_text_field( trim( $_POST['_calendar_date_format'] ) ) : get_option( 'date_format' ); |
925
|
|
|
update_post_meta( $post_id, '_calendar_date_format', $date_format ); |
926
|
|
|
$date_format_php = isset( $_POST['_calendar_date_format_php'] ) ? sanitize_text_field( trim( $_POST['_calendar_date_format_php'] ) ) : get_option( 'date_format' ); |
927
|
|
|
update_post_meta( $post_id, '_calendar_date_format_php', $date_format_php ); |
928
|
|
|
|
929
|
|
|
// Time format. |
930
|
|
|
$time_format_setting = isset( $_POST['_calendar_time_format_setting'] ) ? sanitize_key( $_POST['_calendar_time_format_setting'] ) : 'use_site'; |
931
|
|
|
update_post_meta( $post_id, '_calendar_time_format_setting', $time_format_setting ); |
932
|
|
|
$time_format = isset( $_POST['_calendar_time_format'] ) ? sanitize_text_field( trim( $_POST['_calendar_time_format'] ) ) : get_option( 'time_format' ); |
933
|
|
|
update_post_meta( $post_id, '_calendar_time_format', $time_format ); |
934
|
|
|
$time_format_php = isset( $_POST['_calendar_time_format_php'] ) ? sanitize_text_field( trim( $_POST['_calendar_time_format_php'] ) ) : get_option( 'time_format' ); |
935
|
|
|
update_post_meta( $post_id, '_calendar_time_format_php', $time_format_php ); |
936
|
|
|
|
937
|
|
|
// Date-time separator. |
938
|
|
|
$datetime_separator = isset( $_POST['_calendar_datetime_separator'] ) ? sanitize_text_field( $_POST['_calendar_datetime_separator'] ) : ' '; |
939
|
|
|
update_post_meta( $post_id, '_calendar_datetime_separator', $datetime_separator ); |
940
|
|
|
|
941
|
|
|
// Week start. |
942
|
|
|
$week_start_setting = isset( $_POST['_calendar_week_starts_on_setting'] ) ? sanitize_key( $_POST['_calendar_week_starts_on_setting'] ) : 'use_site'; |
943
|
|
|
update_post_meta( $post_id, '_calendar_week_starts_on_setting', $week_start_setting ); |
944
|
|
|
$week_start = isset( $_POST['_calendar_week_starts_on'] ) ? intval( $_POST['_calendar_week_starts_on'] ) : get_option( 'start_of_week' ); |
945
|
|
|
update_post_meta( $post_id, '_calendar_week_starts_on', $week_start ); |
946
|
|
|
|
947
|
|
|
// Cache interval. |
948
|
|
|
$cache = 7200; |
949
|
|
|
if ( isset( $_POST['_feed_cache_user_amount'] ) && isset( $_POST['_feed_cache_user_unit'] ) ) { |
950
|
|
|
$amount = is_numeric( $_POST['_feed_cache_user_amount'] ) || $_POST['_feed_cache_user_amount'] == 0 ? absint( $_POST['_feed_cache_user_amount'] ) : 1; |
951
|
|
|
$unit = is_numeric( $_POST['_feed_cache_user_unit'] ) ? absint( $_POST['_feed_cache_user_unit'] ) : 3600; |
952
|
|
|
update_post_meta( $post_id, '_feed_cache_user_amount', $amount ); |
953
|
|
|
update_post_meta( $post_id, '_feed_cache_user_unit', $unit ); |
954
|
|
|
$cache = ( ( $amount * $unit ) > 0 ) ? $amount * $unit : 1; |
955
|
|
|
} |
956
|
|
|
update_post_meta( $post_id, '_feed_cache', $cache ); |
957
|
|
|
|
958
|
|
|
/* ============= * |
959
|
|
|
* Miscellaneous * |
960
|
|
|
* ============= */ |
961
|
|
|
|
962
|
|
|
// Update version. |
963
|
|
|
update_post_meta( $post_id, '_calendar_version', SIMPLE_CALENDAR_VERSION ); |
964
|
|
|
|
965
|
|
|
// Action hook. |
966
|
|
|
do_action( 'simcal_process_settings_meta', $post_id ); |
967
|
|
|
|
968
|
|
|
// Clear cache. |
969
|
|
|
simcal_delete_feed_transients( $post_id ); |
970
|
|
|
} |
971
|
|
|
|
972
|
|
|
} |
973
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.