1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Date Picker Field |
4
|
|
|
* |
5
|
|
|
* @package SimpleCalendar/Admin |
6
|
|
|
*/ |
7
|
|
|
namespace SimpleCalendar\Admin\Fields; |
8
|
|
|
|
9
|
|
|
use SimpleCalendar\Abstracts\Field; |
10
|
|
|
|
11
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
12
|
|
|
exit; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Date Picker input field. |
17
|
|
|
* |
18
|
|
|
* A special field to choose dates or date ranges. |
19
|
|
|
* Holds a date value in 'yy-mm-dd' format. |
20
|
|
|
* |
21
|
|
|
* @since 3.0.0 |
22
|
|
|
*/ |
23
|
|
|
class Date_Picker extends Field { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Select a date range. |
27
|
|
|
* |
28
|
|
|
* @access public |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
public $range = false; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Use an inline picker. |
35
|
|
|
* |
36
|
|
|
* @access public |
37
|
|
|
* @var bool |
38
|
|
|
*/ |
39
|
|
|
public $inline = true; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Construct. |
43
|
|
|
* |
44
|
|
|
* @since 3.0.0 |
45
|
|
|
* |
46
|
|
|
* @param array $field |
47
|
|
|
*/ |
48
|
|
|
public function __construct( $field ) { |
49
|
|
|
|
50
|
|
|
$this->range = isset( $field['range'] ) ? ( $field['range'] === true ? true : false ) : false; |
51
|
|
|
$this->inline = isset( $field['inline'] ) ? ( $field['inline'] === true ? true : false ) : true; |
52
|
|
|
|
53
|
|
|
$subtype = $this->range === true ? 'simcal-field-date-picker-range ' : ''; |
54
|
|
|
$this->type_class = 'simcal-field-date-picker ' . $subtype; |
55
|
|
|
|
56
|
|
|
$data = array( |
57
|
|
|
'data-inline' => $this->inline === true ? 'true' : 'false', |
58
|
|
|
); |
59
|
|
|
$field['attributes'] = isset( $field['attributes'] ) ? array_merge( $field['attributes'], $data ) : $data; |
60
|
|
|
|
61
|
|
|
parent::__construct( $field ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Output the field markup |
66
|
|
|
* |
67
|
|
|
* @since 3.0.0 |
68
|
|
|
*/ |
69
|
|
|
public function html() { |
70
|
|
|
|
71
|
|
|
if ( ! empty( $this->description ) ) { |
72
|
|
|
echo '<p class="description">' . wp_kses_post( $this->description ) . '</p>'; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
?> |
76
|
|
|
<div id="<?php echo $this->id; ?>" |
77
|
|
|
class="<?php echo $this->class; ?>" |
78
|
|
|
<?php echo $this->style ? 'style="' . $this->style . '"' : ''; ?> |
79
|
|
|
<?php echo $this->attributes ?>> |
80
|
|
|
<?php |
81
|
|
|
|
82
|
|
|
if ( false === $this->range ) { |
83
|
|
|
|
84
|
|
|
?> |
85
|
|
|
<i class="simcal-icon-calendar"></i> |
86
|
|
|
<input type="<?php echo $this->inline === true ? 'text' : 'hidden'; ?>" |
87
|
|
|
name="<?php echo $this->name; ?>" |
88
|
|
|
value="<?php echo $this->value; ?>" |
89
|
|
|
placeholder="..." |
90
|
|
|
readonly="readonly" /> |
91
|
|
|
<?php |
92
|
|
|
|
93
|
|
|
if ( true === $this->inline ) { |
94
|
|
|
echo $this->tooltip; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} else { |
|
|
|
|
98
|
|
|
// @todo eventually if a date range picker is needed, this can be extended |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
?> |
102
|
|
|
</div> |
103
|
|
|
<?php |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
This check looks for the
else
branches ofif
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
else
branches can be removed.could be turned into
This is much more concise to read.