diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/includes/class-wp-community-events.php --- a/wp/wp-admin/includes/class-wp-community-events.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/includes/class-wp-community-events.php Tue Dec 15 13:49:49 2020 +0100 @@ -92,8 +92,8 @@ return $cached_events; } - // include an unmodified $wp_version - include( ABSPATH . WPINC . '/version.php' ); + // Include an unmodified $wp_version. + require ABSPATH . WPINC . '/version.php'; $api_url = 'http://api.wordpress.org/events/1.0/'; $request_args = $this->get_request_args( $location_search, $timezone ); @@ -113,8 +113,8 @@ } elseif ( 200 !== $response_code ) { $response_error = new WP_Error( 'api-error', - /* translators: %d: numeric HTTP status code, e.g. 400, 403, 500, 504, etc. */ - sprintf( __( 'Invalid API response code (%d)' ), $response_code ) + /* translators: %d: Numeric HTTP status code, e.g. 400, 403, 500, 504, etc. */ + sprintf( __( 'Invalid API response code (%d).' ), $response_code ) ); } elseif ( ! isset( $response_body['location'], $response_body['events'] ) ) { $response_error = new WP_Error( @@ -229,7 +229,7 @@ * * @since 4.8.0 * - * @return false|string The anonymized address on success; the given address + * @return string|false The anonymized address on success; the given address * or false on failure. */ public static function get_unsafe_client_ip() { @@ -300,7 +300,7 @@ * * @since 4.8.0 * - * @param array $location Should contain 'latitude' and 'longitude' indexes. + * @param array $location Should contain 'latitude' and 'longitude' indexes. * @return bool|string false on failure, or a string on success. */ protected function get_events_transient_key( $location ) { @@ -341,8 +341,8 @@ * * @since 4.8.0 * - * @return false|array false on failure; an array containing `location` - * and `events` items on success. + * @return array|false An array containing `location` and `events` items + * on success, false on failure. */ public function get_cached_events() { $cached_response = get_site_transient( $this->get_events_transient_key( $this->user_location ) ); @@ -361,7 +361,7 @@ * * @since 4.8.0 * - * @param array $response_body The response which contains the events. + * @param array $response_body The response which contains the events. * @return array The response with dates and times formatted. */ protected function format_event_data_time( $response_body ) { @@ -375,9 +375,48 @@ * so that users can tell at a glance if the event is on a day they * are available, without having to open the link. */ - /* translators: Date format for upcoming events on the dashboard. Include the day of the week. See https://secure.php.net/date. */ - $response_body['events'][ $key ]['formatted_date'] = date_i18n( __( 'l, M j, Y' ), $timestamp ); - $response_body['events'][ $key ]['formatted_time'] = date_i18n( get_option( 'time_format' ), $timestamp ); + /* translators: Date format for upcoming events on the dashboard. Include the day of the week. See https://www.php.net/date */ + $formatted_date = date_i18n( __( 'l, M j, Y' ), $timestamp ); + $formatted_time = date_i18n( get_option( 'time_format' ), $timestamp ); + + if ( isset( $event['end_date'] ) ) { + $end_timestamp = strtotime( $event['end_date'] ); + $formatted_end_date = date_i18n( __( 'l, M j, Y' ), $end_timestamp ); + + if ( 'meetup' !== $event['type'] && $formatted_end_date !== $formatted_date ) { + /* translators: Upcoming events month format. See https://www.php.net/date */ + $start_month = date_i18n( _x( 'F', 'upcoming events month format' ), $timestamp ); + $end_month = date_i18n( _x( 'F', 'upcoming events month format' ), $end_timestamp ); + + if ( $start_month === $end_month ) { + $formatted_date = sprintf( + /* translators: Date string for upcoming events. 1: Month, 2: Starting day, 3: Ending day, 4: Year. */ + __( '%1$s %2$d–%3$d, %4$d' ), + $start_month, + /* translators: Upcoming events day format. See https://www.php.net/date */ + date_i18n( _x( 'j', 'upcoming events day format' ), $timestamp ), + date_i18n( _x( 'j', 'upcoming events day format' ), $end_timestamp ), + /* translators: Upcoming events year format. See https://www.php.net/date */ + date_i18n( _x( 'Y', 'upcoming events year format' ), $timestamp ) + ); + } else { + $formatted_date = sprintf( + /* translators: Date string for upcoming events. 1: Starting month, 2: Starting day, 3: Ending month, 4: Ending day, 5: Year. */ + __( '%1$s %2$d – %3$s %4$d, %5$d' ), + $start_month, + date_i18n( _x( 'j', 'upcoming events day format' ), $timestamp ), + $end_month, + date_i18n( _x( 'j', 'upcoming events day format' ), $end_timestamp ), + date_i18n( _x( 'Y', 'upcoming events year format' ), $timestamp ) + ); + } + + $formatted_date = wp_maybe_decline_date( $formatted_date, 'F j, Y' ); + } + } + + $response_body['events'][ $key ]['formatted_date'] = $formatted_date; + $response_body['events'][ $key ]['formatted_time'] = $formatted_time; } } @@ -397,13 +436,13 @@ * @since 4.8.0 * @since 4.9.7 Stick a WordCamp to the final list. * - * @param array $response_body The response body which contains the events. + * @param array $response_body The response body which contains the events. * @return array The response body with events trimmed. */ protected function trim_events( $response_body ) { if ( isset( $response_body['events'] ) ) { - $wordcamps = array(); - $current_timestamp = current_time( 'timestamp' ); + $wordcamps = array(); + $today = current_time( 'Y-m-d' ); foreach ( $response_body['events'] as $key => $event ) { /* @@ -415,9 +454,10 @@ continue; } - $event_timestamp = strtotime( $event['date'] ); + // We don't get accurate time with timezone from API, so we only take the date part (Y-m-d). + $event_date = substr( $event['date'], 0, 10 ); - if ( $current_timestamp > $event_timestamp && ( $current_timestamp - $event_timestamp ) > DAY_IN_SECONDS ) { + if ( $today > $event_date ) { unset( $response_body['events'][ $key ] ); } } @@ -426,7 +466,7 @@ $trimmed_event_types = wp_list_pluck( $response_body['events'], 'type' ); // Make sure the soonest upcoming WordCamp is pinned in the list. - if ( ! in_array( 'wordcamp', $trimmed_event_types ) && $wordcamps ) { + if ( ! in_array( 'wordcamp', $trimmed_event_types, true ) && $wordcamps ) { array_pop( $response_body['events'] ); array_push( $response_body['events'], $wordcamps[0] ); }