PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.4
Pods – Custom Content Types and Fields v3.3.4
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 years ago boolean.php 3 years ago code.php 2 years ago color.php 1 year ago comment.php 4 years ago currency.php 9 months ago date.php 2 years ago datetime.php 1 year ago email.php 1 year ago file.php 11 months ago heading.php 1 year ago html.php 2 years ago link.php 1 year ago number.php 9 months ago oembed.php 1 year ago paragraph.php 2 years ago password.php 1 year ago phone.php 1 year ago pick.php 11 months ago slug.php 3 years ago taxonomy.php 4 years ago text.php 2 years ago time.php 2 years ago website.php 11 months ago wysiwyg.php 1 year 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