PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / classes / fields / time.php
pods / classes / fields Last commit date
avatar.php 3 days ago boolean.php 3 days ago code.php 3 days ago color.php 3 days ago comment.php 3 days ago currency.php 3 days ago date.php 3 days ago datetime.php 3 days ago email.php 3 days ago file.php 3 days ago html.php 3 days ago link.php 3 days ago number.php 3 days ago oembed.php 3 days ago paragraph.php 3 days ago password.php 3 days ago phone.php 3 days ago pick.php 3 days ago slug.php 3 days ago taxonomy.php 3 days ago text.php 3 days ago time.php 3 days ago website.php 3 days ago wysiwyg.php 3 days ago
time.php
246 lines
1 <?php
2 require_once PODS_DIR . 'classes/fields/datetime.php';
3
4 /**
5 * @package Pods\Fields
6 */
7 class PodsField_Time extends PodsField_DateTime {
8
9 /**
10 * {@inheritdoc}
11 */
12 public static $group = 'Date / Time';
13
14 /**
15 * {@inheritdoc}
16 */
17 public static $type = 'time';
18
19 /**
20 * {@inheritdoc}
21 */
22 public static $label = 'Time';
23
24 /**
25 * {@inheritdoc}
26 */
27 public static $prepare = '%s';
28
29 /**
30 * Storage format.
31 *
32 * @var string
33 * @since 2.7.0
34 */
35 public static $storage_format = 'H:i:s';
36
37 /**
38 * The default empty value (database)
39 *
40 * @var string
41 * @since 2.7.0
42 */
43 public static $empty_value = '';
44
45 /**
46 * {@inheritdoc}
47 */
48 public function setup() {
49
50 static::$label = __( 'Time', 'pods' );
51 }
52
53 /**
54 * {@inheritdoc}
55 */
56 public function options() {
57
58 $options = array(
59 static::$type . '_repeatable' => array(
60 'label' => __( 'Repeatable Field', 'pods' ),
61 'default' => 0,
62 'type' => 'boolean',
63 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
64 'boolean_yes_label' => '',
65 'dependency' => true,
66 'developer_mode' => true,
67 ),
68 static::$type . '_type' => array(
69 'label' => __( 'Time Format Type', 'pods' ),
70 'default' => '12',
71 // Backwards compatibility
72 'type' => 'pick',
73 'help' => __( 'WordPress Default is the format used in Settings, General under "Time Format".', 'pods' ) . '<br>' . __( '12/24 hour will allow you to select from a list of commonly used time formats.', 'pods' ) . '<br>' . __( 'Custom will allow you to enter your own using PHP Date/Time Strings.', 'pods' ),
74 'data' => array(
75 'wp' => __( 'WordPress default', 'pods' ) . ': ' . date_i18n( get_option( 'time_format' ) ),
76 '12' => __( '12 hour', 'pods' ),
77 '24' => __( '24 hour', 'pods' ),
78 'custom' => __( 'Custom format', 'pods' ),
79 ),
80 'dependency' => true,
81 ),
82 static::$type . '_format_custom' => array(
83 'label' => __( 'Time format for display', 'pods' ),
84 'depends-on' => array( static::$type . '_type' => 'custom' ),
85 'default' => '',
86 'type' => 'text',
87 'help' => sprintf(
88 '<a href="http://php.net/manual/function.date.php" target="_blank" rel="noopener noreferrer">%s</a>',
89 esc_html__( 'PHP date documentation', 'pods' )
90 ),
91 ),
92 static::$type . '_format_custom_js' => array(
93 'label' => __( 'Time format for input', 'pods' ),
94 'depends-on' => array( static::$type . '_type' => 'custom' ),
95 'default' => '',
96 'type' => 'text',
97 'help' => sprintf(
98 '<a href="http://trentrichardson.com/examples/timepicker/#tp-formatting" target="_blank" rel="noopener noreferrer">%1$s</a><br />%2$s',
99 esc_html__( 'jQuery UI timepicker documentation', 'pods' ),
100 esc_html__( 'Leave empty to auto-generate from PHP format.', 'pods' )
101 ),
102 ),
103 static::$type . '_format' => array(
104 'label' => __( 'Time Format', 'pods' ),
105 'depends-on' => array( static::$type . '_type' => '12' ),
106 'default' => 'h_mma',
107 'type' => 'pick',
108 'data' => array(
109 'h_mm_A' => date_i18n( 'g:i A' ),
110 'h_mm_ss_A' => date_i18n( 'g:i:s A' ),
111 'hh_mm_A' => date_i18n( 'h:i A' ),
112 'hh_mm_ss_A' => date_i18n( 'h:i:s A' ),
113 'h_mma' => date_i18n( 'g:ia' ),
114 'hh_mma' => date_i18n( 'h:ia' ),
115 'h_mm' => date_i18n( 'g:i' ),
116 'h_mm_ss' => date_i18n( 'g:i:s' ),
117 'hh_mm' => date_i18n( 'h:i' ),
118 'hh_mm_ss' => date_i18n( 'h:i:s' ),
119 ),
120 'dependency' => true,
121 ),
122 static::$type . '_format_24' => array(
123 'label' => __( 'Time Format', 'pods' ),
124 'depends-on' => array( static::$type . '_type' => '24' ),
125 'default' => 'hh_mm',
126 'type' => 'pick',
127 'data' => array(
128 'hh_mm' => date_i18n( 'H:i' ),
129 'hh_mm_ss' => date_i18n( 'H:i:s' ),
130 ),
131 ),
132 static::$type . '_allow_empty' => array(
133 'label' => __( 'Allow empty value?', 'pods' ),
134 'default' => 1,
135 'type' => 'boolean',
136 ),
137 static::$type . '_html5' => array(
138 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
139 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
140 'type' => 'boolean',
141 ),
142 );
143
144 $options[ static::$type . '_type' ]['default'] = apply_filters( 'pods_form_ui_field_time_format_type_default', $options[ static::$type . '_type' ]['default'] );
145 $options[ static::$type . '_format' ]['data'] = apply_filters( 'pods_form_ui_field_time_format_options', $options[ static::$type . '_format' ]['data'] );
146 $options[ static::$type . '_format' ]['default'] = apply_filters( 'pods_form_ui_field_time_format_default', $options[ static::$type . '_format' ]['default'] );
147 $options[ static::$type . '_format_24' ]['data'] = apply_filters( 'pods_form_ui_field_time_format_24_options', $options[ static::$type . '_format_24' ]['data'] );
148 $options[ static::$type . '_format_24' ]['default'] = apply_filters( 'pods_form_ui_field_time_format_24_default', $options[ static::$type . '_format_24' ]['default'] );
149
150 return $options;
151 }
152
153 /**
154 * {@inheritdoc}
155 */
156 public function schema( $options = null ) {
157
158 $schema = 'TIME NOT NULL default "00:00:00"';
159
160 return $schema;
161 }
162
163 /**
164 * {@inheritdoc}
165 */
166 public function is_empty( $value = null ) {
167
168 $value = trim ( $value );
169 return empty( $value );
170 }
171
172 /**
173 * {@inheritdoc}
174 */
175 public function format_display( $options, $js = false ) {
176
177 if ( $js && 'custom' === pods_v( static::$type . '_type', $options, 'format' ) ) {
178 $format = $this->format_datetime( $options, $js );
179 return $this->convert_format( $format, array( 'source' => 'jquery_ui', 'type' => 'time' ) );
180 }
181
182 return parent::format_display( $options, $js );
183 }
184
185 /**
186 * {@inheritdoc}
187 */
188 public function format_datetime( $options, $js = false ) {
189
190 return $this->format_time( $options, $js );
191 }
192
193 /**
194 * Build time format string based on options
195 *
196 * @param array $options Field options.
197 * @param bool $js Return formatted from jQuery UI format? (only for custom formats).
198 *
199 * @return string
200 * @since 2.7.0
201 */
202 public function format_time( $options, $js = false ) {
203
204 switch ( (string) pods_v( static::$type . '_type', $options, '12', true ) ) {
205 case '12':
206 $time_format = $this->get_time_formats( $js );
207
208 $format = $time_format[ pods_v( static::$type . '_format', $options, 'hh_mm', true ) ];
209
210 break;
211 case '24':
212 $time_format_24 = $this->get_time_formats_24( $js );
213
214 $format = $time_format_24[ pods_v( static::$type . '_format_24', $options, 'hh_mm', true ) ];
215
216 break;
217 case 'custom':
218 if ( ! $js ) {
219 $format = pods_v( static::$type . '_format_custom', $options, '' );
220 } else {
221 $format = pods_v( static::$type . '_format_custom_js', $options, '' );
222
223 if ( empty( $format ) ) {
224 $format = pods_v( static::$type . '_format_custom', $options, '' );
225
226 if ( $js ) {
227 $format = $this->convert_format( $format, array( 'source' => 'php', 'type' => 'time' ) );
228 }
229 }
230 }
231
232 break;
233 default:
234 $format = get_option( 'time_format' );
235
236 if ( $js ) {
237 $format = $this->convert_format( $format, array( 'source' => 'php', 'type' => 'time' ) );
238 }
239
240 break;
241 }//end switch
242
243 return $format;
244 }
245 }
246