68 lines
3.3 KiB
PHP
68 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* Daily forecast template (grid of day cards).
|
|
*
|
|
* @var array<string,mixed> $data Normalized daily forecast.
|
|
*
|
|
* @package FontdelboscEltemps
|
|
*/
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
$fontdelbosc_show_attribution = ! empty( Fontdelbosc_Plugin::get_options()['display_attribution'] );
|
|
?>
|
|
<div class="fdb-weather fdb-daily">
|
|
<h3 class="fdb-weather__title"><?php esc_html_e( 'Forecast', 'fontdelbosc-eltemps' ); ?></h3>
|
|
|
|
<div class="fdb-daily__grid">
|
|
<?php foreach ( $data['days'] as $fontdelbosc_index => $fontdelbosc_day ) : ?>
|
|
<?php
|
|
try {
|
|
$fontdelbosc_date = DateTimeImmutable::createFromFormat( 'Y-m-d', (string) $fontdelbosc_day['date'], new DateTimeZone( FONTDELBOSC_ELTEMPS_TIMEZONE ) );
|
|
} catch ( Exception ) {
|
|
$fontdelbosc_date = false;
|
|
}
|
|
|
|
$fontdelbosc_timestamp = $fontdelbosc_date instanceof DateTimeImmutable ? $fontdelbosc_date->getTimestamp() : time();
|
|
$fontdelbosc_weekday = (int) wp_date( 'N', $fontdelbosc_timestamp );
|
|
|
|
if ( 0 === $fontdelbosc_index ) {
|
|
$fontdelbosc_label = __( 'Today', 'fontdelbosc-eltemps' );
|
|
} elseif ( 1 === $fontdelbosc_index ) {
|
|
$fontdelbosc_label = __( 'Tomorrow', 'fontdelbosc-eltemps' );
|
|
} else {
|
|
$fontdelbosc_label = Fontdelbosc_Conditions::weekday( $fontdelbosc_weekday );
|
|
}
|
|
?>
|
|
<div class="fdb-daily__day">
|
|
<span class="fdb-daily__name"><?php echo esc_html( $fontdelbosc_label ); ?></span>
|
|
<span class="fdb-daily__date"><?php echo esc_html( wp_date( 'j/n', $fontdelbosc_timestamp ) ); ?></span>
|
|
<?php if ( ! empty( $fontdelbosc_day['condition'] ) ) : ?>
|
|
<img class="fdb-icon" src="<?php echo esc_url( Fontdelbosc_Conditions::icon( (string) $fontdelbosc_day['condition'] ) ); ?>" alt="" width="48" height="48" loading="lazy" />
|
|
<?php endif; ?>
|
|
<?php if ( null !== $fontdelbosc_day['temp_max'] || null !== $fontdelbosc_day['temp_min'] ) : ?>
|
|
<p class="fdb-daily__temps">
|
|
<?php if ( null !== $fontdelbosc_day['temp_max'] ) : ?>
|
|
<span class="fdb-daily__max"><span class="screen-reader-text"><?php esc_html_e( 'Max', 'fontdelbosc-eltemps' ); ?> </span><?php echo esc_html( number_format_i18n( round( (float) $fontdelbosc_day['temp_max'] ) ) ); ?>°</span>
|
|
<?php endif; ?>
|
|
<?php if ( null !== $fontdelbosc_day['temp_min'] ) : ?>
|
|
<span class="fdb-daily__min"><span class="screen-reader-text"><?php esc_html_e( 'Min', 'fontdelbosc-eltemps' ); ?> </span><?php echo esc_html( number_format_i18n( round( (float) $fontdelbosc_day['temp_min'] ) ) ); ?>°</span>
|
|
<?php endif; ?>
|
|
</p>
|
|
<?php endif; ?>
|
|
<?php if ( null !== $fontdelbosc_day['pop'] ) : ?>
|
|
<p class="fdb-daily__pop"><?php echo esc_html( number_format_i18n( (float) $fontdelbosc_day['pop'] ) ); ?>%</p>
|
|
<?php elseif ( null !== $fontdelbosc_day['precipitation'] ) : ?>
|
|
<p class="fdb-daily__pop"><?php echo esc_html( number_format_i18n( (float) $fontdelbosc_day['precipitation'], 1 ) ); ?> mm</p>
|
|
<?php endif; ?>
|
|
<?php if ( null !== $fontdelbosc_day['wind_max'] ) : ?>
|
|
<p class="fdb-daily__wind"><?php echo esc_html( number_format_i18n( round( (float) $fontdelbosc_day['wind_max'] ) ) ); ?> km/h</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<?php if ( $fontdelbosc_show_attribution ) : ?>
|
|
<p class="fdb-attribution"><?php echo esc_html( Fontdelbosc_Data_Manager::attribution( (string) $data['source'] ) ); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|