PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.4
Pods – Custom Content Types and Fields v2.8.23.4
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 / ui / fields / datetime.php
pods / ui / fields Last commit date
_comment.php 2 weeks ago _db.php 2 weeks ago _hidden.php 2 weeks ago _label.php 2 weeks ago _row.php 2 weeks ago attachment.php 2 weeks ago checkbox.php 2 weeks ago cleditor.php 2 weeks ago codemirror.php 2 weeks ago color.php 2 weeks ago currency.php 2 weeks ago date.php 2 weeks ago datetime.php 2 weeks ago email.php 2 weeks ago link.php 2 weeks ago number.php 2 weeks ago oembed.php 2 weeks ago password.php 2 weeks ago phone.php 2 weeks ago radio.php 2 weeks ago select.php 2 weeks ago slider.php 2 weeks ago slug.php 2 weeks ago text.php 2 weeks ago textarea.php 2 weeks ago time.php 2 weeks ago tinymce.php 2 weeks ago website.php 2 weeks ago
datetime.php
209 lines
1 <?php
2 // Don't load directly.
3 if ( ! defined( 'ABSPATH' ) ) {
4 die( '-1' );
5 }
6
7 /**
8 * @var string $form_field_type
9 * @var array $options
10 * @var $value
11 */
12
13 $use_time = ( 'time' === $form_field_type || 'datetime' === $form_field_type );
14 $use_date = ( 'date' === $form_field_type || 'datetime' === $form_field_type );
15
16 wp_enqueue_script( 'jquery-ui-datepicker' );
17 pods_form_enqueue_style( 'pods-styles' );
18
19 if ( $use_time ) {
20 wp_enqueue_script( 'jquery-ui-timepicker' );
21 wp_enqueue_style( 'jquery-ui-timepicker' );
22 }
23
24 PodsForm::field_method( $form_field_type, 'enqueue_jquery_ui_i18n' );
25
26 $attributes = array();
27
28 $html5 = false;
29 $type = 'text';
30
31 if ( pods_v( $form_field_type . '_html5', $options, false ) ) {
32 $html5 = true;
33 $type = $form_field_type;
34 }
35
36 $attributes['type'] = $type;
37 $attributes['tabindex'] = 2;
38
39 $format = PodsForm::field_method( $form_field_type, 'format_' . $form_field_type, $options );
40
41 $method = $form_field_type . 'picker';
42
43 $mysql_date_format = 'Y-m-d';
44 $mysql_time_format = 'H:i:s';
45
46 $args = array(
47 'altField' => '', // Done with JS.
48 'altFieldTimeOnly' => false,
49 );
50
51 if ( $use_date ) {
52 $args['dateFormat'] = PodsForm::field_method( $form_field_type, 'format_date', $options, true );
53 $args['altFormat'] = PodsForm::field_method( $form_field_type, 'convert_format', $mysql_date_format, array( 'type' => 'date' ) );
54 $args['changeMonth'] = true;
55 $args['changeYear'] = true;
56 $args['firstDay'] = (int) get_option( 'start_of_week', 0 );
57
58 $year_range = pods_v( $form_field_type . '_year_range_custom', $options, '' );
59 if ( $year_range ) {
60 $args['yearRange'] = $year_range;
61 }
62 }
63 if ( $use_time ) {
64 $args['timeFormat'] = PodsForm::field_method( $form_field_type, 'format_time', $options, true );
65 $args['altTimeFormat'] = PodsForm::field_method( $form_field_type, 'convert_format', $mysql_time_format, array( 'type' => 'time' ) );
66 $args['ampm'] = ( false !== stripos( $args['timeFormat'], 'tt' ) );
67 $args['parse'] = 'loose';
68 }
69
70 $mysql_format = '';
71
72 switch ( $form_field_type ) {
73 case 'datetime':
74 $mysql_format = $mysql_date_format . ' ' . $mysql_time_format;
75
76 $format_value = pods_v( $form_field_type . '_format', $options, 'mdy', true );
77
78 if ( 'format' === pods_v( $form_field_type . '_type', $options, 'format', true ) && 'c' === $format_value ) {
79 $args['ampm'] = false;
80 $args['separator'] = 'T';
81 $args['timeFormat'] = 'HH:mm:ssz';
82
83 // $args[ 'showTimezone' ] = true;
84 $timezone = (int) get_option( 'gmt_offset' );
85 $timezone *= 60;
86
87 if ( 0 <= $timezone ) {
88 $timezone = '+' . (string) $timezone;
89 }
90
91 $args['timezone'] = (string) $timezone;
92 }
93
94 break;
95 case 'date':
96 $mysql_format = $mysql_date_format;
97 break;
98 case 'time':
99 $mysql_format = $mysql_time_format;
100 break;
101 }
102
103 $date = PodsForm::field_method( $form_field_type, 'createFromFormat', $format, (string) $value );
104 $date_default = PodsForm::field_method( $form_field_type, 'createFromFormat', $mysql_format, (string) $value );
105
106 $formatted_value = PodsForm::field_method( $form_field_type, 'format_value_display', $value, $options, true );
107 $mysql_value = $value;
108
109 if (
110 pods_v( $form_field_type . '_allow_empty', $options, true )
111 && PodsForm::field_method( $form_field_type, 'is_empty', $value )
112 ) {
113 $formatted_value = '';
114 $value = '';
115 } else {
116
117 if ( false !== $date ) {
118 $mysql_value = $date->format( $mysql_format );
119 } elseif ( false !== $date_default ) {
120 $mysql_value = $date_default->format( $mysql_format );
121 } elseif ( ! empty( $value ) ) {
122 $mysql_value = date_i18n( $mysql_format, strtotime( (string) $value ) );
123 } else {
124 $mysql_value = date_i18n( $mysql_format );
125 }
126
127 if ( $html5 ) {
128 /**
129 * HTML5 uses mysql date format separated with a T.
130 * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local
131 */
132 $value = str_replace( ' ', 'T', $mysql_value );
133 } else {
134 $value = $formatted_value;
135 }
136 }
137
138 $args = apply_filters( 'pods_form_ui_field_' . $form_field_type . '_args', $args, $type, $options, $attributes, $name, $form_field_type );
139
140 $attributes['value'] = $value;
141
142 if ( $html5 && 'datetime' === $type ) {
143 // Fix deprecated `datetime` input type.
144 $type = 'datetime-local';
145 $attributes['type'] = 'datetime-local';
146 }
147
148 $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options );
149 ?>
150 <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?> />
151
152 <script>
153 jQuery( function ( $ ) {
154 var $container = $( '<div>' ).appendTo( 'body' ).addClass( 'pods-compat-container' ),
155 $element = $( 'input#<?php echo esc_js( $attributes['id'] ); ?>' ),
156 $alt = null,
157 args = <?php echo wp_json_encode( $args ); ?>;
158
159 <?php
160 if ( 'text' !== $type ) {
161 ?>
162 // Test whether or not the browser supports date inputs
163 function podsCheckHtml5 () {
164 var input = document.createElement('input');
165 input.setAttribute( 'type', '<?php echo $type; ?>' );
166
167 var notADateValue = 'not-a-date';
168 input.setAttribute( 'value', notADateValue );
169
170 return ( input.value !== notADateValue );
171 }
172
173 if ( ! podsCheckHtml5() ) {
174 $element.val( '<?php echo esc_js( $formatted_value ); ?>' );
175 jQueryField();
176 }
177 <?php
178 } else {
179 ?>
180 jQueryField();
181 <?php
182 } //end if
183 ?>
184 function jQueryField() {
185
186 // Create alt field.
187 $alt = $element.clone();
188 $alt.attr( 'type', 'hidden' );
189 $alt.val( '<?php echo esc_attr( $mysql_value ) ?>' );
190 $element.after( $alt );
191 $element.attr( 'name', $element.attr( 'name' ) + '__ui' );
192 $element.attr( 'id', $element.attr( 'id' ) + '__ui' );
193
194 // Add alt field option.
195 args.altField = 'input#' + $alt.attr( 'id' );
196 // Fix manual user input changes.
197 args.onClose = function() {
198 $element.<?php echo esc_js( $method ); ?>( 'setDate', $element.val() );
199 };
200 // Wrapper.
201 args.beforeShow = function( textbox, instance ) {
202 $( '#ui-datepicker-div' ).appendTo( $container );
203 };
204
205 $element.<?php echo esc_js( $method ); ?>( args );
206 }
207 } );
208 </script>
209