PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.0.10.5
Pods – Custom Content Types and Fields v3.0.10.5
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 days ago boolean.php 2 days ago code.php 2 days ago color.php 2 days ago comment.php 2 days ago currency.php 2 days ago date.php 2 days ago datetime.php 2 days ago email.php 2 days ago file.php 2 days ago heading.php 2 days ago html.php 2 days ago link.php 2 days ago number.php 2 days ago oembed.php 2 days ago paragraph.php 2 days ago password.php 2 days ago phone.php 2 days ago pick.php 2 days ago slug.php 2 days ago taxonomy.php 2 days ago text.php 2 days ago time.php 2 days ago website.php 2 days ago wysiwyg.php 2 days ago
time.php
243 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 . '_type' => array(
60 'label' => __( 'Time Format Type', 'pods' ),
61 'default' => '12',
62 // Backwards compatibility
63 'type' => 'pick',
64 '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' ),
65 'data' => array(
66 'wp' => __( 'WordPress default', 'pods' ) . ': ' . date_i18n( get_option( 'time_format' ) ),
67 '12' => __( '12 hour', 'pods' ),
68 '24' => __( '24 hour', 'pods' ),
69 'custom' => __( 'Custom format', 'pods' ),
70 ),
71 'pick_format_single' => 'dropdown',
72 'pick_show_select_text' => 0,
73 'dependency' => true,
74 ),
75 static::$type . '_format_custom' => array(
76 'label' => __( 'Time format for display', 'pods' ),
77 'depends-on' => array( static::$type . '_type' => 'custom' ),
78 'default' => '',
79 'type' => 'text',
80 'help' => sprintf(
81 '<a href="http://php.net/manual/function.date.php" target="_blank" rel="noopener noreferrer">%s</a>',
82 esc_html__( 'PHP date documentation', 'pods' )
83 ),
84 ),
85 static::$type . '_format_custom_js' => array(
86 'label' => __( 'Time format for input', 'pods' ),
87 'depends-on' => array( static::$type . '_type' => 'custom' ),
88 'default' => '',
89 'type' => 'text',
90 'help' => sprintf(
91 '<a href="http://trentrichardson.com/examples/timepicker/#tp-formatting" target="_blank" rel="noopener noreferrer">%1$s</a><br />%2$s',
92 esc_html__( 'jQuery UI timepicker documentation', 'pods' ),
93 esc_html__( 'Leave empty to auto-generate from PHP format.', 'pods' )
94 ),
95 ),
96 static::$type . '_format' => array(
97 'label' => __( 'Time Format', 'pods' ),
98 'depends-on' => array( static::$type . '_type' => '12' ),
99 'default' => 'h_mma',
100 'type' => 'pick',
101 'data' => array(
102 'h_mm_A' => date_i18n( 'g:i A' ),
103 'h_mm_ss_A' => date_i18n( 'g:i:s A' ),
104 'hh_mm_A' => date_i18n( 'h:i A' ),
105 'hh_mm_ss_A' => date_i18n( 'h:i:s A' ),
106 'h_mma' => date_i18n( 'g:ia' ),
107 'hh_mma' => date_i18n( 'h:ia' ),
108 'h_mm' => date_i18n( 'g:i' ),
109 'h_mm_ss' => date_i18n( 'g:i:s' ),
110 'hh_mm' => date_i18n( 'h:i' ),
111 'hh_mm_ss' => date_i18n( 'h:i:s' ),
112 ),
113 'pick_format_single' => 'dropdown',
114 'pick_show_select_text' => 0,
115 'dependency' => true,
116 ),
117 static::$type . '_format_24' => array(
118 'label' => __( 'Time Format', 'pods' ),
119 'depends-on' => array( static::$type . '_type' => '24' ),
120 'default' => 'hh_mm',
121 'type' => 'pick',
122 'data' => array(
123 'hh_mm' => date_i18n( 'H:i' ),
124 'hh_mm_ss' => date_i18n( 'H:i:s' ),
125 ),
126 'pick_format_single' => 'dropdown',
127 'pick_show_select_text' => 0,
128 ),
129 static::$type . '_allow_empty' => array(
130 'label' => __( 'Allow empty value', 'pods' ),
131 'default' => 1,
132 'type' => 'boolean',
133 ),
134 static::$type . '_html5' => array(
135 'label' => __( 'Enable HTML5 Input Field', 'pods' ),
136 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
137 'type' => 'boolean',
138 ),
139 );
140
141 $options[ static::$type . '_type' ]['default'] = apply_filters( 'pods_form_ui_field_time_format_type_default', $options[ static::$type . '_type' ]['default'] );
142 $options[ static::$type . '_format' ]['data'] = apply_filters( 'pods_form_ui_field_time_format_options', $options[ static::$type . '_format' ]['data'] );
143 $options[ static::$type . '_format' ]['default'] = apply_filters( 'pods_form_ui_field_time_format_default', $options[ static::$type . '_format' ]['default'] );
144 $options[ static::$type . '_format_24' ]['data'] = apply_filters( 'pods_form_ui_field_time_format_24_options', $options[ static::$type . '_format_24' ]['data'] );
145 $options[ static::$type . '_format_24' ]['default'] = apply_filters( 'pods_form_ui_field_time_format_24_default', $options[ static::$type . '_format_24' ]['default'] );
146
147 return $options;
148 }
149
150 /**
151 * {@inheritdoc}
152 */
153 public function schema( $options = null ) {
154
155 $schema = 'TIME NOT NULL default "00:00:00"';
156
157 return $schema;
158 }
159
160 /**
161 * {@inheritdoc}
162 */
163 public function is_empty( $value = null ) {
164
165 $value = trim ( $value );
166 return empty( $value );
167 }
168
169 /**
170 * {@inheritdoc}
171 */
172 public function format_display( $options, $js = false ) {
173
174 if ( $js && 'custom' === pods_v( static::$type . '_type', $options, 'format' ) ) {
175 $format = $this->format_datetime( $options, $js );
176 return $this->convert_format( $format, array( 'source' => 'jquery_ui', 'type' => 'time' ) );
177 }
178
179 return parent::format_display( $options, $js );
180 }
181
182 /**
183 * {@inheritdoc}
184 */
185 public function format_datetime( $options, $js = false ) {
186
187 return $this->format_time( $options, $js );
188 }
189
190 /**
191 * Build time format string based on options
192 *
193 * @param array $options Field options.
194 * @param bool $js Return formatted from jQuery UI format? (only for custom formats).
195 *
196 * @return string
197 * @since 2.7.0
198 */
199 public function format_time( $options, $js = false ) {
200
201 switch ( (string) pods_v( static::$type . '_type', $options, '12', true ) ) {
202 case '12':
203 $time_format = $this->get_time_formats( $js );
204
205 $format = $time_format[ pods_v( static::$type . '_format', $options, 'hh_mm', true ) ];
206
207 break;
208 case '24':
209 $time_format_24 = $this->get_time_formats_24( $js );
210
211 $format = $time_format_24[ pods_v( static::$type . '_format_24', $options, 'hh_mm', true ) ];
212
213 break;
214 case 'custom':
215 if ( ! $js ) {
216 $format = pods_v( static::$type . '_format_custom', $options, '' );
217 } else {
218 $format = pods_v( static::$type . '_format_custom_js', $options, '' );
219
220 if ( empty( $format ) ) {
221 $format = pods_v( static::$type . '_format_custom', $options, '' );
222
223 if ( $js ) {
224 $format = $this->convert_format( $format, array( 'source' => 'php', 'type' => 'time' ) );
225 }
226 }
227 }
228
229 break;
230 default:
231 $format = get_option( 'time_format' );
232
233 if ( $js ) {
234 $format = $this->convert_format( $format, array( 'source' => 'php', 'type' => 'time' ) );
235 }
236
237 break;
238 }//end switch
239
240 return $format;
241 }
242 }
243