PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.4
Pods – Custom Content Types and Fields v2.8.23.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 2 weeks ago boolean.php 2 weeks ago code.php 2 weeks ago color.php 2 weeks ago comment.php 2 weeks ago currency.php 2 weeks ago date.php 2 weeks ago datetime.php 2 weeks ago email.php 2 weeks ago file.php 2 weeks ago heading.php 2 weeks ago html.php 2 weeks ago link.php 2 weeks ago number.php 2 weeks ago oembed.php 2 weeks ago paragraph.php 2 weeks ago password.php 2 weeks ago phone.php 2 weeks ago pick.php 2 weeks ago slug.php 2 weeks ago taxonomy.php 2 weeks ago text.php 2 weeks ago time.php 2 weeks ago website.php 2 weeks ago wysiwyg.php 2 weeks ago
time.php
249 lines
1 <?php
2
3 /**
4 * @package Pods\Fields
5 */
6 class PodsField_Time extends PodsField_DateTime {
7
8 /**
9 * {@inheritdoc}
10 */
11 public static $group = 'Date / Time';
12
13 /**
14 * {@inheritdoc}
15 */
16 public static $type = 'time';
17
18 /**
19 * {@inheritdoc}
20 */
21 public static $label = 'Time';
22
23 /**
24 * {@inheritdoc}
25 */
26 public static $prepare = '%s';
27
28 /**
29 * Storage format.
30 *
31 * @var string
32 * @since 2.7.0
33 */
34 public static $storage_format = 'H:i:s';
35
36 /**
37 * The default empty value (database)
38 *
39 * @var string
40 * @since 2.7.0
41 */
42 public static $empty_value = '';
43
44 /**
45 * {@inheritdoc}
46 */
47 public function setup() {
48
49 static::$group = __( 'Date / Time', 'pods' );
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 'pick_show_select_text' => 0,
81 'dependency' => true,
82 ),
83 static::$type . '_format_custom' => array(
84 'label' => __( 'Time format for display', 'pods' ),
85 'depends-on' => array( static::$type . '_type' => 'custom' ),
86 'default' => '',
87 'type' => 'text',
88 'help' => sprintf(
89 '<a href="http://php.net/manual/function.date.php" target="_blank" rel="noopener noreferrer">%s</a>',
90 esc_html__( 'PHP date documentation', 'pods' )
91 ),
92 ),
93 static::$type . '_format_custom_js' => array(
94 'label' => __( 'Time format for input', 'pods' ),
95 'depends-on' => array( static::$type . '_type' => 'custom' ),
96 'default' => '',
97 'type' => 'text',
98 'help' => sprintf(
99 '<a href="http://trentrichardson.com/examples/timepicker/#tp-formatting" target="_blank" rel="noopener noreferrer">%1$s</a><br />%2$s',
100 esc_html__( 'jQuery UI timepicker documentation', 'pods' ),
101 esc_html__( 'Leave empty to auto-generate from PHP format.', 'pods' )
102 ),
103 ),
104 static::$type . '_format' => array(
105 'label' => __( 'Time Format', 'pods' ),
106 'depends-on' => array( static::$type . '_type' => '12' ),
107 'default' => 'h_mma',
108 'type' => 'pick',
109 'data' => array(
110 'h_mm_A' => date_i18n( 'g:i A' ),
111 'h_mm_ss_A' => date_i18n( 'g:i:s A' ),
112 'hh_mm_A' => date_i18n( 'h:i A' ),
113 'hh_mm_ss_A' => date_i18n( 'h:i:s A' ),
114 'h_mma' => date_i18n( 'g:ia' ),
115 'hh_mma' => date_i18n( 'h:ia' ),
116 'h_mm' => date_i18n( 'g:i' ),
117 'h_mm_ss' => date_i18n( 'g:i:s' ),
118 'hh_mm' => date_i18n( 'h:i' ),
119 'hh_mm_ss' => date_i18n( 'h:i:s' ),
120 ),
121 'pick_show_select_text' => 0,
122 'dependency' => true,
123 ),
124 static::$type . '_format_24' => array(
125 'label' => __( 'Time Format', 'pods' ),
126 'depends-on' => array( static::$type . '_type' => '24' ),
127 'default' => 'hh_mm',
128 'type' => 'pick',
129 'data' => array(
130 'hh_mm' => date_i18n( 'H:i' ),
131 'hh_mm_ss' => date_i18n( 'H:i:s' ),
132 ),
133 'pick_show_select_text' => 0,
134 ),
135 static::$type . '_allow_empty' => array(
136 'label' => __( 'Allow empty value', 'pods' ),
137 'default' => 1,
138 'type' => 'boolean',
139 ),
140 static::$type . '_html5' => array(
141 'label' => __( 'Enable HTML5 Input Field', 'pods' ),
142 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
143 'type' => 'boolean',
144 ),
145 );
146
147 $options[ static::$type . '_type' ]['default'] = apply_filters( 'pods_form_ui_field_time_format_type_default', $options[ static::$type . '_type' ]['default'] );
148 $options[ static::$type . '_format' ]['data'] = apply_filters( 'pods_form_ui_field_time_format_options', $options[ static::$type . '_format' ]['data'] );
149 $options[ static::$type . '_format' ]['default'] = apply_filters( 'pods_form_ui_field_time_format_default', $options[ static::$type . '_format' ]['default'] );
150 $options[ static::$type . '_format_24' ]['data'] = apply_filters( 'pods_form_ui_field_time_format_24_options', $options[ static::$type . '_format_24' ]['data'] );
151 $options[ static::$type . '_format_24' ]['default'] = apply_filters( 'pods_form_ui_field_time_format_24_default', $options[ static::$type . '_format_24' ]['default'] );
152
153 return $options;
154 }
155
156 /**
157 * {@inheritdoc}
158 */
159 public function schema( $options = null ) {
160
161 $schema = 'TIME NOT NULL default "00:00:00"';
162
163 return $schema;
164 }
165
166 /**
167 * {@inheritdoc}
168 */
169 public function is_empty( $value = null ) {
170
171 $value = trim ( $value );
172 return empty( $value );
173 }
174
175 /**
176 * {@inheritdoc}
177 */
178 public function format_display( $options, $js = false ) {
179
180 if ( $js && 'custom' === pods_v( static::$type . '_type', $options, 'format' ) ) {
181 $format = $this->format_datetime( $options, $js );
182 return $this->convert_format( $format, array( 'source' => 'jquery_ui', 'type' => 'time' ) );
183 }
184
185 return parent::format_display( $options, $js );
186 }
187
188 /**
189 * {@inheritdoc}
190 */
191 public function format_datetime( $options, $js = false ) {
192
193 return $this->format_time( $options, $js );
194 }
195
196 /**
197 * Build time format string based on options
198 *
199 * @param array $options Field options.
200 * @param bool $js Return formatted from jQuery UI format? (only for custom formats).
201 *
202 * @return string
203 * @since 2.7.0
204 */
205 public function format_time( $options, $js = false ) {
206
207 switch ( (string) pods_v( static::$type . '_type', $options, '12', true ) ) {
208 case '12':
209 $time_format = $this->get_time_formats( $js );
210
211 $format = $time_format[ pods_v( static::$type . '_format', $options, 'hh_mm', true ) ];
212
213 break;
214 case '24':
215 $time_format_24 = $this->get_time_formats_24( $js );
216
217 $format = $time_format_24[ pods_v( static::$type . '_format_24', $options, 'hh_mm', true ) ];
218
219 break;
220 case 'custom':
221 if ( ! $js ) {
222 $format = pods_v( static::$type . '_format_custom', $options, '' );
223 } else {
224 $format = pods_v( static::$type . '_format_custom_js', $options, '' );
225
226 if ( empty( $format ) ) {
227 $format = pods_v( static::$type . '_format_custom', $options, '' );
228
229 if ( $js ) {
230 $format = $this->convert_format( $format, array( 'source' => 'php', 'type' => 'time' ) );
231 }
232 }
233 }
234
235 break;
236 default:
237 $format = get_option( 'time_format' );
238
239 if ( $js ) {
240 $format = $this->convert_format( $format, array( 'source' => 'php', 'type' => 'time' ) );
241 }
242
243 break;
244 }//end switch
245
246 return $format;
247 }
248 }
249