From 7086111ad4dd997e12a3220e1ee60c9b9bcf0bb8 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 7 Jan 2020 13:06:14 +0100 Subject: Added wordpress --- .../class-wp-customize-date-time-control.php | 282 +++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 srcs/wordpress/wp-includes/customize/class-wp-customize-date-time-control.php (limited to 'srcs/wordpress/wp-includes/customize/class-wp-customize-date-time-control.php') diff --git a/srcs/wordpress/wp-includes/customize/class-wp-customize-date-time-control.php b/srcs/wordpress/wp-includes/customize/class-wp-customize-date-time-control.php new file mode 100644 index 0000000..36bd192 --- /dev/null +++ b/srcs/wordpress/wp-includes/customize/class-wp-customize-date-time-control.php @@ -0,0 +1,282 @@ +max_year ); + $data['minYear'] = intval( $this->min_year ); + $data['allowPastDate'] = (bool) $this->allow_past_date; + $data['twelveHourFormat'] = (bool) $this->twelve_hour_format; + $data['includeTime'] = (bool) $this->include_time; + + return $data; + } + + /** + * Renders a JS template for the content of date time control. + * + * @since 4.9.0 + */ + public function content_template() { + $data = array_merge( $this->json(), $this->get_month_choices() ); + $timezone_info = $this->get_timezone_info(); + + $date_format = get_option( 'date_format' ); + $date_format = preg_replace( '/(? + + <# _.defaults( data, ); #> + <# var idPrefix = _.uniqueId( 'el' ) + '-'; #> + + <# if ( data.label ) { #> + + {{ data.label }} + + <# } #> +
+ <# if ( data.description ) { #> + {{ data.description }} + <# } #> +
+
+ +
+ + + + + + + + + + + + + + + + +
+
+ <# if ( data.includeTime ) { #> +
+ +
+ + <# var maxHour = data.twelveHourFormat ? 12 : 23; #> + <# var minHour = data.twelveHourFormat ? 1 : 0; #> + + : + + + <# if ( data.twelveHourFormat ) { #> + + + <# } #> +

+
+
+ <# } #> +
+ get_month_abbrev( $wp_locale->get_month( $i ) ); + + /* translators: 1: Month number (01, 02, etc.), 2: Month abbreviation. */ + $months[ $i ]['text'] = sprintf( __( '%1$s-%2$s' ), $i, $month_text ); + $months[ $i ]['value'] = $i; + } + return array( + 'month_choices' => $months, + ); + } + + /** + * Get timezone info. + * + * @since 4.9.0 + * + * @return array abbr and description. + */ + public function get_timezone_info() { + $tz_string = get_option( 'timezone_string' ); + $timezone_info = array(); + + if ( $tz_string ) { + try { + $tz = new DateTimezone( $tz_string ); + } catch ( Exception $e ) { + $tz = ''; + } + + if ( $tz ) { + $now = new DateTime( 'now', $tz ); + $formatted_gmt_offset = $this->format_gmt_offset( $tz->getOffset( $now ) / 3600 ); + $tz_name = str_replace( '_', ' ', $tz->getName() ); + $timezone_info['abbr'] = $now->format( 'T' ); + + $timezone_info['description'] = sprintf( + /* translators: 1: Timezone name, 2: Timezone abbreviation, 3: UTC abbreviation and offset, 4: UTC offset. */ + __( 'Your timezone is set to %1$s (%2$s), currently %3$s (Coordinated Universal Time %4$s).' ), + $tz_name, + '' . $timezone_info['abbr'] . '', + 'UTC' . $formatted_gmt_offset, + $formatted_gmt_offset + ); + } else { + $timezone_info['description'] = ''; + } + } else { + $formatted_gmt_offset = $this->format_gmt_offset( intval( get_option( 'gmt_offset', 0 ) ) ); + + $timezone_info['description'] = sprintf( + /* translators: 1: UTC abbreviation and offset, 2: UTC offset. */ + __( 'Your timezone is set to %1$s (Coordinated Universal Time %2$s).' ), + 'UTC' . $formatted_gmt_offset, + $formatted_gmt_offset + ); + } + + return $timezone_info; + } + + /** + * Format GMT Offset. + * + * @since 4.9.0 + * @see wp_timezone_choice() + * + * @param float $offset Offset in hours. + * @return string Formatted offset. + */ + public function format_gmt_offset( $offset ) { + if ( 0 <= $offset ) { + $formatted_offset = '+' . (string) $offset; + } else { + $formatted_offset = (string) $offset; + } + $formatted_offset = str_replace( + array( '.25', '.5', '.75' ), + array( ':15', ':30', ':45' ), + $formatted_offset + ); + return $formatted_offset; + } +} -- cgit