1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
<?php
class Papi_Property_Datetime extends Papi_Property {
public function get_default_settings() {
return [
'format' => 'YYYY-MM-DD hh:mm:ss',
'show_seconds' => false,
'show_time' => true,
'show_week_number' => false,
'use_24_hours' => get_locale() === 'sv_SE'
];
}
public function html() {
$settings = $this->get_settings();
$value = $this->get_value();
$settings_json = [
'i18n' => [
'previousMonth' => __( 'Previous Month', 'papi' ),
'nextMonth' => __( 'Next Month', 'papi' ),
'midnight' => __( 'Midnight', 'papi' ),
'months' => [
__( 'January', 'papi' ),
__( 'February', 'papi' ),
__( 'March', 'papi' ),
__( 'April', 'papi' ),
__( 'May', 'papi' ),
__( 'June', 'papi' ),
__( 'July', 'papi' ),
__( 'August', 'papi' ),
__( 'September', 'papi' ),
__( 'October', 'papi' ),
__( 'November', 'papi' ),
__( 'December', 'papi' )
],
'noon' => __( 'Noon', 'papi' ),
'weekdays' => [
__( 'Sunday', 'papi' ),
__( 'Monday', 'papi' ),
__( 'Tuesday', 'papi' ),
__( 'Wednesday', 'papi' ),
__( 'Thursday', 'papi' ),
__( 'Friday', 'papi' ),
__( 'Saturday', 'papi' )
],
'weekdaysShort' => [
__( 'Sun', 'papi' ),
__( 'Mon', 'papi' ),
__( 'Tue', 'papi' ),
__( 'Wed', 'papi' ),
__( 'Thu', 'papi' ),
__( 'Fri', 'papi' ),
__( 'Sat', 'papi' )
]
]
];
if ( isset( $settings->i18n ) ) {
unset( $settings->i18n );
}
if ( isset( $settings->show_time ) && ! $settings->show_time && isset( $settings->format ) ) {
$settings->format = trim(
str_replace( 'hh:mm:ss', '', $settings->format )
);
}
foreach ( (array) $settings as $key => $val ) {
if ( ! is_string( $key ) ) {
continue;
}
$settings_json[papi_camel_case( $key )] = $val;
}
if ( isset( $settings_json['use24Hours'] ) ) {
$settings_json['use24hour'] = $settings_json['use24Hours'];
unset( $settings_json['use24Hours'] );
}
papi_render_html_tag( 'input', [
'class' => 'papi-property-datetime',
'data-settings' => (object) $settings_json,
'id' => $this->html_id(),
'name' => $this->html_name(),
'type' => 'text',
'value' => $value
] );
}
}