PluginProbe ʕ •ᴥ•ʔ
Slider Ultimate / 2.0.8
Slider Ultimate v2.0.8
trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9
ultimate-slider / lib / simple-admin-pages / classes / AdminPageSetting.Scheduler.class.php
ultimate-slider / lib / simple-admin-pages / classes Last commit date
AdminPage.Menu.class.php 4 years ago AdminPage.Submenu.class.php 4 years ago AdminPage.Themes.class.php 4 years ago AdminPage.class.php 4 years ago AdminPageSection.class.php 4 years ago AdminPageSetting.Address.class.php 4 years ago AdminPageSetting.Checkbox.class.php 4 years ago AdminPageSetting.ColorPicker.class.php 4 years ago AdminPageSetting.Count.class.php 4 years ago AdminPageSetting.Editor.class.php 4 years ago AdminPageSetting.FileUpload.class.php 4 years ago AdminPageSetting.HTML.class.php 4 years ago AdminPageSetting.Image.class.php 4 years ago AdminPageSetting.InfiniteTable.class.php 4 years ago AdminPageSetting.McApiKey.class.php 4 years ago AdminPageSetting.McListMerge.class.php 4 years ago AdminPageSetting.Number.class.php 4 years ago AdminPageSetting.OpeningHours.class.php 4 years ago AdminPageSetting.Ordering.class.php 4 years ago AdminPageSetting.Radio.class.php 4 years ago AdminPageSetting.Scheduler.class.php 4 years ago AdminPageSetting.Select.class.php 4 years ago AdminPageSetting.SelectMenu.class.php 4 years ago AdminPageSetting.SelectPost.class.php 4 years ago AdminPageSetting.SelectTaxonomy.class.php 4 years ago AdminPageSetting.Text.class.php 4 years ago AdminPageSetting.Textarea.class.php 4 years ago AdminPageSetting.Time.class.php 4 years ago AdminPageSetting.Toggle.class.php 4 years ago AdminPageSetting.WarningTip.class.php 4 years ago AdminPageSetting.class.php 4 years ago Library.class.php 4 years ago
AdminPageSetting.Scheduler.class.php
708 lines
1 <?php
2
3 /**
4 * Register, display and save a schedule of dates and times.
5 *
6 * This is designed for use for opening hours, a booking schedule or anything
7 * that requires recurring dates and times.
8 *
9 * @since 2.0
10 * @package Simple Admin Pages
11 */
12
13 class sapAdminPageSettingScheduler_2_6_1 extends sapAdminPageSetting_2_6_1 {
14
15 public $sanitize_callback = 'sanitize_text_field';
16
17 /**
18 * Scripts that must be loaded for this component
19 * @since 2.0.a.4
20 */
21 public $scripts = array(
22 'pickadate' => array(
23 'path' => 'lib/pickadate/picker.js',
24 'dependencies' => array( 'jquery' ),
25 'version' => '3.6.1',
26 'footer' => true,
27 ),
28 'pickadate-date' => array(
29 'path' => 'lib/pickadate/picker.date.js',
30 'dependencies' => array( 'jquery' ),
31 'version' => '3.6.1',
32 'footer' => true,
33 ),
34 'pickadate-time' => array(
35 'path' => 'lib/pickadate/picker.time.js',
36 'dependencies' => array( 'jquery' ),
37 'version' => '3.6.1',
38 'footer' => true,
39 ),
40 'pickadate-legacy' => array(
41 'path' => 'lib/pickadate/legacy.js',
42 'dependencies' => array( 'jquery' ),
43 'version' => '3.6.1',
44 'footer' => true,
45 ),
46 'sap-scheduler' => array(
47 'path' => 'js/scheduler.js',
48 'dependencies' => array( 'jquery' ),
49 'version' => SAP_VERSION,
50 'footer' => true,
51 ),
52 // @todo there should be some way to load alternate language .js files
53 // and RTL CSS scripts
54 );
55
56 /**
57 * Styles that must be loaded for this component
58 * @since 2.0.a.4
59 */
60 public $styles = array(
61 'pickadate-default' => array(
62 'path' => 'lib/pickadate/themes/default.css',
63 'dependencies' => '',
64 'version' => '3.6.1',
65 'media' => null,
66 ),
67 'pickadate-date' => array(
68 'path' => 'lib/pickadate/themes/default.date.css',
69 'dependencies' => '',
70 'version' => '3.6.1',
71 'media' => null,
72 ),
73 'pickadate-time' => array(
74 'path' => 'lib/pickadate/themes/default.time.css',
75 'dependencies' => '',
76 'version' => '3.6.1',
77 'media' => null,
78 ),
79 );
80
81 /**
82 * Used for data storage. Not translated
83 */
84 public $weekdays = array(
85 'monday' => 'Mo',
86 'tuesday' => 'Tu',
87 'wednesday' => 'We',
88 'thursday' => 'Th',
89 'friday' => 'Fr',
90 'saturday' => 'Sa',
91 'sunday' => 'Su',
92 );
93
94 /**
95 * Used for data storage. Not translated
96 */
97 public $weeks = array(
98 'first' => '1st',
99 'second' => '2nd',
100 'third' => '3rd',
101 'fourth' => '4th',
102 'last' => 'last',
103 );
104
105 /**
106 * Translateable strings required for this component
107 * @since 2.0.a.8
108 */
109 public $strings = array(
110 'add_rule' => null, // __( 'Add new scheduling rule', 'textdomain' ),
111 'weekly' => null, // _x( 'Weekly', 'Format of a scheduling rule', 'textdomain' ),
112 'monthly' => null, // _x( 'Monthly', 'Format of a scheduling rule', 'textdomain' ),
113 'date' => null, // _x( 'Date', 'Format of a scheduling rule', 'textdomain' ),
114 'weekdays' => null, // _x( 'Days of the week', 'Label for selecting days of the week in a scheduling rule', 'textdomain' ),
115 'month_weeks' => null, // _x( 'Weeks of the month', 'Label for selecting weeks of the month in a scheduling rule', 'textdomain' ),
116 'date_label' => null, // _x( 'Date', 'Label to select a date for a scheduling rule', 'textdomain' ),
117 'time_label' => null, // _x( 'Time', 'Label to select a time slot for a scheduling rule', 'textdomain' ),
118 'allday' => null, // _x( 'All day', 'Label to set a scheduling rule to last all day', 'textdomain' ),
119 'start' => null, // _x( 'Start', 'Label for the starting time of a scheduling rule', 'textdomain' ),
120 'end' => null, // _x( 'End', 'Label for the ending time of a scheduling rule', 'textdomain' ),
121 'set_time_prompt' => null, // _x( 'All day long. Want to %sset a time slot%s?', 'Prompt displayed when a scheduling rule is set without any time restrictions', 'textdomain' ),
122 'toggle' => null, // _x( 'Open and close this rule', 'Toggle a scheduling rule open and closed', 'textdomain' ),
123 'delete' => null, // _x( 'Delete rule', 'Delete a scheduling rule', 'textdomain' ),
124 'delete_schedule' => null, // __( 'Delete scheduling rule', 'textdomain' ),
125 'never' => null, // _x( 'Never', 'Brief default description of a scheduling rule when no weekdays or weeks are included in the rule', 'textdomain' ),
126 'weekly_always' => null, // _x( 'Every day', 'Brief default description of a scheduling rule when all the weekdays/weeks are included in the rule', 'textdomain' ),
127 'monthly_weekdays' => null, // _x( '%s on the %s week of the month', 'Brief default description of a scheduling rule when some weekdays are included on only some weeks of the month. %s should be left alone and will be replaced by a comma-separated list of days and weeks in the following format: M, T, W on the first, second week of the month', 'textdomain' ),
128 'monthly_weeks' => null, // _x( '%s week of the month', 'Brief default description of a scheduling rule when some weeks of the month are included but all or no weekdays are selected. %s should be left alone and will be replaced by a comma-separated list of weeks in the following format: First, second week of the month', 'textdomain' ),
129 'all_day' => null, // _x( 'All day', 'Brief default description of a scheduling rule when no times are set', 'textdomain' ),
130 'before' => null, // _x( 'Ends at', 'Brief default description of a scheduling rule when an end time is set but no start time. If the end time is 6pm, it will read: Ends at 6pm', 'textdomain' ),
131 'after' => null, // _x( 'Starts at', 'Brief default description of a scheduling rule when a start time is set but no end time. If the start time is 6pm, it will read: Starts at 6pm', 'textdomain' ),
132 'separator' => null, // _x( '&mdash;', 'Separator between times of a scheduling rule', 'textdomain' ),
133 );
134
135 /**
136 * Number of minutes between time selection intervals
137 */
138 public $time_interval = 15;
139
140 /**
141 * Display format for time selection
142 * See http://amsul.ca/pickadate.js/ for formatting options
143 */
144 public $time_format = 'h:i A';
145
146 /**
147 * Display format for date selection
148 * See http://amsul.ca/pickadate.js/ for formatting options
149 */
150 public $date_format = 'd mmmm, yyyy';
151
152 /**
153 * Boolean to disable the weekday selection option
154 */
155 public $disable_weekdays = false;
156
157 /**
158 * Boolean to disable the weeks selection option
159 */
160 public $disable_weeks = false;
161
162 /**
163 * Boolean to disable the date selection option
164 */
165 public $disable_date = false;
166
167 /**
168 * Boolean to disable the time selection option
169 */
170 public $disable_time = false;
171
172 /**
173 * Boolean to disable the end time selection option
174 */
175 public $disable_end_time = false;
176
177 /**
178 * Boolean to disable multiple rules per component
179 */
180 public $disable_multiple = false;
181
182 /**
183 * Escape the value to display it in text fields and other input fields
184 * @since 2.0
185 */
186 public function esc_value( $val ) {
187
188 $value = array();
189
190 if ( empty( $val ) ) {
191 return $value;
192 }
193
194 foreach ( $val as $i => $rule ) {
195
196 if ( !empty( $rule['weekdays'] ) ) {
197 $value[$i]['weekdays'] = array();
198 foreach ( $rule['weekdays'] as $day => $flag ) {
199 if ( $flag !== '1' ) {
200 continue;
201 }
202
203 $value[$i]['weekdays'][$day] = $flag;
204 }
205 }
206
207 if ( !empty( $rule['weeks'] ) ) {
208 $value[$i]['weeks'] = array();
209 foreach ( $rule['weeks'] as $week => $flag ) {
210 if ( $flag !== '1' ) {
211 continue;
212 }
213
214 $value[$i]['weeks'][$week] = $flag;
215 }
216 }
217
218 if ( !empty( $rule['date'] ) ) {
219 $value[$i]['date'] = esc_attr( $rule['date'] );
220 }
221
222 if ( !empty( $rule['time']['start'] ) ) {
223 $value[$i]['time']['start'] = esc_attr( $rule['time']['start'] );
224 }
225 if ( !empty( $rule['time']['end'] ) ) {
226 $value[$i]['time']['end'] = esc_attr( $rule['time']['end'] );
227 }
228 }
229
230 return $value;
231 }
232
233 /**
234 * Compile and pass configurable variables to the javascript file, so they
235 * can be used when we initialize the pickadate components
236 * @since 2.0
237 */
238 public function pass_to_scripts() {
239
240 // Create a global variable containing settings for all schedulers
241 // that are being rendered on the page. This allows us to pass different
242 // settings for different schedulers on the same page.
243 global $sap_scheduler_settings;
244
245 if ( !isset( $sap_scheduler_settings ) ) {
246 $sap_scheduler_settings = array();
247 }
248
249 $sap_scheduler_settings[ $this->id ] = array(
250 'time_interval' => $this->time_interval,
251 'time_format' => $this->time_format,
252 'date_format' => $this->date_format,
253 'template' => $this->get_template(),
254 'weekdays' => $this->weekdays,
255 'weeks' => $this->weeks,
256 'disable_weekdays' => $this->disable_weekdays,
257 'disable_weeks' => $this->disable_weeks,
258 'disable_date' => $this->disable_date,
259 'disable_time' => $this->disable_time,
260 'disable_multiple' => $this->disable_multiple,
261 'summaries' => $this->schedule_summaries,
262 );
263
264 // This gets called multiple times, but only the last call is actually
265 // pushed to the script.
266 wp_localize_script(
267 'sap-scheduler',
268 'sap_scheduler',
269 array(
270 'settings' => $sap_scheduler_settings
271 )
272 );
273
274 }
275
276 /**
277 * Display this setting
278 * @since 2.0
279 */
280 public function display_setting() {
281
282 $this->display_description();
283
284 // Define summary text to use when a rule is displayed in brief
285 $this->set_schedule_summaries();
286
287 // Pass data to the script files to handle js interactions
288 $this->pass_to_scripts();
289
290 ?>
291
292 <fieldset <?php $this->print_conditional_data(); ?>>
293
294 <div class="sap-scheduler <?php echo ( $this->disabled ? 'disabled' : ''); ?>" id="<?php echo $this->id; ?>">
295 <?php
296 foreach ( $this->value as $id => $rule ) {
297 echo $this->get_template( $id, $rule, true );
298 }
299 ?>
300 </div>
301
302 <div class="sap-add-scheduler<?php if ( $this->disable_multiple && count( $this->value ) ) : ?> disabled<?php endif; ?> <?php echo ( $this->disabled ? 'disabled' : ''); ?>">
303 <a href="#" class="button">
304 <?php echo $this->strings['add_rule']; ?>
305 </a>
306 </div>
307
308 <?php $this->display_disabled(); ?>
309
310 </fieldset>
311
312 <?php
313 }
314
315 /**
316 * Retrieve the template for a scheduling rule
317 * @since 2.0
318 */
319 public function get_template( $id = 0, $values = array(), $list = false ) {
320
321 $date_format = $this->get_date_format( $values );
322 $time_format = $this->get_time_format( $values );
323
324 ob_start();
325 ?>
326
327 <div class="sap-scheduler-rule clearfix<?php echo $list ? ' list' : ''; ?>">
328 <div class="sap-scheduler-date <?php echo $date_format; echo $this->disable_time === true ? ' full-width' : ''; ?>">
329 <ul class="sap-selector">
330
331 <?php if ( !$this->has_multiple_date_formats() ) : ?>
332 <li>
333 <div class="dashicons dashicons-calendar"></div>
334 <?php if ( $date_format == 'weekly' ) : ?>
335 <?php echo $this->strings['weekly']; ?>
336 <?php elseif ( $date_format == 'monthly' ) : ?>
337 <?php echo $this->strings['monthly']; ?>
338 <?php elseif ( $date_format == 'date' ) : ?>
339 <?php echo $this->strings['date']; ?>
340 <?php endif; ?>
341 </li>
342 <?php else : ?>
343
344 <?php if ( $this->disable_weekdays === false ) : ?>
345 <li>
346 <div class="dashicons dashicons-calendar"></div>
347 <a href="#" data-format="weekly"<?php echo $date_format == 'weekly' ? ' class="selected"' : ''; ?>>
348 <?php echo $this->strings['weekly']; ?>
349 </a>
350 </li>
351 <?php endif; ?>
352
353 <?php if ( $this->disable_weeks === false ) : ?>
354 <li>
355 <a href="#" data-format="monthly"<?php echo $date_format == 'monthly' ? ' class="selected"' : ''; ?>>
356 <?php echo $this->strings['monthly']; ?>
357 </a>
358 </li>
359 <?php endif; ?>
360
361 <?php if ( $this->disable_date === false ) : ?>
362 <li>
363 <a href="#" data-format="date"<?php echo $date_format == 'date' ? ' class="selected"' : ''; ?>>
364 <?php echo $this->strings['date']; ?>
365 </a>
366 </li>
367 <?php endif; ?>
368
369 <?php endif; ?>
370 </ul>
371
372 <?php if ( $this->disable_weekdays === false ) : ?>
373 <ul class="sap-scheduler-weekdays">
374 <li class="label">
375 <?php echo $this->strings['weekdays']; ?>
376 </li>
377 <?php
378 foreach ( $this->weekdays as $slug => $label ) :
379 $input_name = $this->get_input_name() . '[' . $id . '][weekdays][' . esc_attr( $slug ) . ']';
380 ?>
381 <li>
382 &nbsp;<input type="checkbox" name="<?php echo $input_name; ?>" id="<?php echo $input_name; ?>" value="1"<?php echo empty( $values['weekdays'][$slug] ) ? '' : ' checked="checked"'; ?> data-day="<?php echo esc_attr( $slug ); ?>"><label for="<?php echo $input_name; ?>"><?php echo ucfirst( $label ); ?></label>
383 </li>
384 <?php endforeach; ?>
385 </ul>
386 <?php endif; ?>
387
388 <?php if ( $this->disable_weeks === false ) : ?>
389 <ul class="sap-scheduler-weeks">
390 <li class="label">
391 <?php echo $this->strings['month_weeks']; ?>
392 </li>
393 <?php
394 foreach ( $this->weeks as $slug => $label ) :
395 $input_name = $this->get_input_name() . '[' . $id . '][weeks][' . esc_attr( $slug ) . ']';
396 ?>
397 <li>
398 &nbsp;<input type="checkbox" name="<?php echo $input_name; ?>" id="<?php echo $input_name; ?>" value="1"<?php echo empty( $values['weeks'][$slug] ) ? '' : ' checked="checked"'; ?> data-week="<?php echo esc_attr( $slug ); ?>"><label for="<?php echo $input_name; ?>"><?php echo ucfirst( $label ); ?></label>
399 </li>
400 <?php endforeach; ?>
401 </ul>
402 <?php endif; ?>
403
404 <?php if ( $this->disable_date === false ) : ?>
405 <div class="sap-scheduler-date-input">
406 <label for="<?php echo $this->get_input_name(); ?>[<?php echo $id; ?>][date]">
407 <?php echo $this->strings['date_label']; ?>
408 </label>
409 <input type="text" name="<?php echo $this->get_input_name(); ?>[<?php echo $id; ?>][date]" id="<?php echo $this->get_input_name(); ?>[<?php echo $id; ?>][date]" value="<?php echo empty( $values['date'] ) ? '' : $values['date']; ?>">
410 </div>
411 <?php endif; ?>
412
413 </div>
414
415 <?php if ( $this->disable_time === false ) : ?>
416 <div class="sap-scheduler-time <?php echo $time_format; ?>">
417
418 <ul class="sap-selector">
419 <li>
420 <div class="dashicons dashicons-clock"></div>
421 <a href="#" data-format="time-slot"<?php echo $time_format == 'time-slot' ? ' class="selected"' : ''; ?>>
422 <?php echo $this->strings['time_label']; ?>
423 </a>
424 </li>
425 <li>
426 <a href="#" data-format="all-day"<?php echo $time_format == 'all-day' ? ' class="selected"' : ''; ?>>
427 <?php echo $this->strings['allday']; ?>
428 </a>
429 </li>
430 </ul>
431
432 <div class="sap-scheduler-time-input clearfix">
433
434 <div class="start">
435 <label for="<?php echo $this->get_input_name(); ?>[<?php echo $id; ?>][time][start]">
436 <?php echo $this->strings['start']; ?>
437 </label>
438 <input type="text" name="<?php echo $this->get_input_name() . '[' . $id . '][time][start]'; ?>" id="<?php echo $this->get_input_name() . '[' . $id . '][time][start]'; ?>" value="<?php echo empty( $values['time']['start'] ) ? '' : $values['time']['start']; ?>">
439 </div>
440
441 <?php if ( $this->disable_end_time === false ) : ?>
442 <div class="end">
443 <label for="<?php echo $this->get_input_name(); ?>[<?php echo $id; ?>][time][end]">
444 <?php echo $this->strings['end']; ?>
445 </label>
446 <input type="text" name="<?php echo $this->get_input_name() . '[' . $id . '][time][end]'; ?>" id="<?php echo $this->get_input_name() . '[' . $id . '][time][end]'; ?>" value="<?php echo empty( $values['time']['end'] ) ? '' : $values['time']['end']; ?>">
447 </div>
448 <?php endif; ?>
449
450 </div>
451
452 <div class="sap-scheduler-all-day">
453 <?php printf( $this->strings['set_time_prompt'], '<a href="#" data-format="time-slot">', '</a>' ); ?>
454 </div>
455
456 </div>
457 <?php endif; ?>
458
459 <div class="sap-scheduler-brief">
460 <div class="date">
461 <div class="dashicons dashicons-calendar"></div>
462 <span class="value"><?php echo $this->get_date_summary( $values ); ?></span>
463 </div>
464 <?php if ( $this->disable_time === false ) : ?>
465 <div class="time">
466 <div class="dashicons dashicons-clock"></div>
467 <span class="value"><?php echo $this->get_time_summary( $values ); ?></span>
468 </div>
469 <?php endif; ?>
470 </div>
471 <div class="sap-scheduler-control">
472 <a href="#" class="toggle" title="<?php echo $this->strings['toggle']; ?>">
473 <div class="dashicons dashicons-<?php echo $list ? 'edit' : 'arrow-up-alt2'; ?>"></div>
474 <span class="screen-reader-text">
475 <?php echo $this->strings['toggle']; ?>
476 </span>
477 </a>
478 <a href="#" class="delete" title="<?php echo $this->strings['delete']; ?>">
479 <div class="dashicons dashicons-dismiss"></div>
480 <span class="screen-reader-text">
481 <?php echo $this->strings['delete_schedule']; ?>
482 </span>
483 </a>
484 </div>
485 </div>
486
487 <?php
488 $output = ob_get_clean();
489
490 return $output;
491 }
492
493 /**
494 * Determine the date format of a rule (weeky/monthly/date)
495 * @since 2.0
496 */
497 public function get_date_format( $values ) {
498
499 if ( !empty( $values['date'] ) ) {
500 return 'date';
501 } elseif ( !empty( $values['weeks'] ) ) {
502 return 'monthly';
503 } elseif ( !empty( $values['weekdays'] ) ) {
504 return 'weekly';
505 }
506
507 if ( $this->disable_weekdays === false ) {
508 return 'weekly';
509 }
510 if ( $this->disable_weeks === false ) {
511 return 'monthly';
512 }
513 if ( $this->disable_date === false ) {
514 return 'date';
515 }
516 }
517
518 /**
519 * Determine the time format of a rule (time-slot/all-day)
520 * @since 2.0
521 */
522 public function get_time_format( $values ) {
523 if ( empty( $values['time']['start'] ) && empty( $values['time']['end'] ) ) {
524 return 'all-day';
525 }
526
527 return 'time-slot';
528 }
529
530 /**
531 * Determine if multiple date formats are enabled
532 * @since 2.0
533 */
534 public function has_multiple_date_formats() {
535 $i = 0;
536 if ( $this->disable_weekdays === false ) {
537 $i++;
538 }
539 if ( $this->disable_weeks === false ) {
540 $i++;
541 }
542 if ( $this->disable_date === false ) {
543 $i++;
544 }
545
546 if ( $i > 1 ) {
547 return true;
548 } else {
549 return false;
550 }
551 }
552
553 /**
554 * Set some default summary strings that can be used when the scheduler
555 * rule is shown in brief
556 * @since 2.0
557 */
558 public function set_schedule_summaries() {
559
560 if ( !empty( $this->schedule_summaries ) ) {
561 return;
562 }
563
564 $this->schedule_summaries = array(
565 'never' => $this->strings['never'],
566 'weekly_always' => $this->strings['weekly_always'],
567 'monthly_weekdays' => sprintf( $this->strings['monthly_weekdays'], '{days}', '{weeks}' ),
568 'monthly_weeks' => sprintf( $this->strings['monthly_weeks'], '{weeks}' ),
569 'all_day' => $this->strings['all_day'],
570 'before' => $this->strings['before'],
571 'after' => $this->strings['after'],
572 'separator' => $this->strings['separator'],
573 );
574 }
575
576 /**
577 * Print the date phrase, a brief description of the date settings
578 * @since 2.0
579 */
580 public function get_date_summary( $values = array() ) {
581
582 if ( !empty( $values['date'] ) ) {
583 return $values['date'];
584 }
585
586 if ( empty( $values['weekdays'] ) && $this->disable_weekdays === false ) {
587 return $this->schedule_summaries['never'];
588 }
589
590 if ( empty( $values['weekdays'] ) ) {
591 $weekdays = '';
592 } elseif ( count( $values['weekdays'] ) == 7 ) {
593 $weekdays = $this->schedule_summaries['weekly_always'];
594 } else {
595 $arr = array();
596 foreach ( $values['weekdays'] as $weekday => $state ) {
597 $arr[] = $this->weekdays[$weekday];
598 }
599 $weekdays = join( ', ', $arr );
600 }
601
602 if ( ( empty( $values['weeks'] ) || count( $values['weeks'] ) == 5 ) && $this->disable_weekdays === false ) {
603 return $weekdays;
604 }
605
606 if ( empty( $values['weeks'] ) ) {
607 return $this->schedule_summaries['never'];
608 }
609
610 $arr = array();
611 foreach ( $values['weeks'] as $weeks => $state ) {
612 $arr[] = $this->weeks[$weeks];
613 }
614 $weeks = join( ', ', $arr );
615
616 if ( !empty( $weekdays ) ) {
617 return str_replace( array( '{days}', '{weeks}' ), array( $weekdays, $weeks ), $this->schedule_summaries['monthly_weekdays'] );
618 } else {
619 return str_replace( '{weeks}', ucfirst( $weeks ), $this->schedule_summaries['monthly_weeks'] );
620 }
621
622 }
623
624 /**
625 * Print the time phrase, a brief description of the time settings
626 * @since 2.0
627 */
628 public function get_time_summary( $values = array() ) {
629
630 if ( empty( $values['time']['start'] ) && empty( $values['time']['end'] ) ) {
631 return $this->schedule_summaries['all_day'];
632 }
633
634 if ( empty( $values['time']['start'] ) ) {
635 return $this->schedule_summaries['before'] . ' ' . $values['time']['end'];
636 }
637
638 if ( empty( $values['time']['end'] ) ) {
639 return $this->schedule_summaries['after'] . ' ' . $values['time']['start'];
640 }
641
642 return $values['time']['start'] . $this->schedule_summaries['separator'] . $values['time']['end'];
643
644 }
645
646 /**
647 * Sanitize the array of text inputs for this setting
648 * @since 2.0
649 */
650 public function sanitize_callback_wrapper( $values ) {
651
652 $output = array();
653
654 if ( !is_array( $values ) || !count( $values ) ) {
655 return $output;
656 }
657
658 foreach ( $values as $i => $rule ) {
659
660 if ( !empty( $rule['weekdays'] ) ) {
661 $output[$i]['weekdays'] = array();
662 foreach ( $rule['weekdays'] as $day => $flag ) {
663 if ( $flag !== '1' ||
664 ( $day !== 'monday' && $day !== 'tuesday' && $day !== 'wednesday' && $day !== 'thursday' && $day !== 'friday' && $day !== 'saturday' && $day !== 'sunday' ) ) {
665 continue;
666 }
667
668 $output[$i]['weekdays'][$day] = $flag;
669 }
670 }
671
672 if ( !empty( $rule['weeks'] ) ) {
673 $output[$i]['weeks'] = array();
674 foreach ( $rule['weeks'] as $week => $flag ) {
675 if ( $flag !== '1' ||
676 ( $week !== 'first' && $week !== 'second' && $week !== 'third' && $week !== 'fourth' && $week !== 'last' ) ) {
677 continue;
678 }
679
680 $output[$i]['weeks'][$week] = $flag;
681 }
682 }
683
684 if ( !empty( $rule['date'] ) ) {
685 $date = new DateTime( $rule['date'] );
686 if ( checkdate( $date->format( 'n' ), $date->format( 'j' ), $date->format( 'Y' ) ) ) {
687 $output[$i]['date'] = call_user_func( $this->sanitize_callback, $rule['date'] );
688 }
689 }
690
691 if ( !empty( $rule['time']['start'] ) ) {
692 $output[$i]['time']['start'] = call_user_func( $this->sanitize_callback, $rule['time']['start'] );
693 }
694 if ( !empty( $rule['time']['end'] ) ) {
695 $output[$i]['time']['end'] = call_user_func( $this->sanitize_callback, $rule['time']['end'] );
696 }
697 }
698
699 // Only return the first rule if multiple rules are disabled
700 if ( $this->disable_multiple && count( $output ) > 1 ) {
701 $output = array( array_shift( $output ) );
702 }
703
704 return $output;
705 }
706
707 }
708