v1.0.0
This commit is contained in:
commit
06153e387d
47 changed files with 5116 additions and 0 deletions
47
templates/current.php
Normal file
47
templates/current.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* Current conditions template.
|
||||
*
|
||||
* @var array<string,mixed> $data Normalized current conditions.
|
||||
*
|
||||
* @package FontdelboscEltemps
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$fontdelbosc_night = Fontdelbosc_Conditions::is_night( (int) wp_date( 'G', (int) ( $data['time'] ?? time() ) ) );
|
||||
$fontdelbosc_show_attribution = ! empty( Fontdelbosc_Plugin::get_options()['display_attribution'] );
|
||||
?>
|
||||
<div class="fdb-weather fdb-current">
|
||||
<div class="fdb-current__main">
|
||||
<?php if ( ! empty( $data['condition'] ) ) : ?>
|
||||
<img class="fdb-icon fdb-icon--lg" src="<?php echo esc_url( Fontdelbosc_Conditions::icon( (string) $data['condition'], $fontdelbosc_night ) ); ?>" alt="" width="96" height="96" loading="lazy" />
|
||||
<?php endif; ?>
|
||||
<?php if ( null !== $data['temperature'] ) : ?>
|
||||
<span class="fdb-current__temp"><?php echo esc_html( number_format_i18n( round( (float) $data['temperature'] ) ) ); ?>°C</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if ( ! empty( $data['condition'] ) ) : ?>
|
||||
<p class="fdb-current__label"><?php echo esc_html( Fontdelbosc_Conditions::label( (string) $data['condition'] ) ); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<ul class="fdb-current__meta">
|
||||
<?php if ( null !== $data['apparent'] ) : ?>
|
||||
<li><?php echo esc_html__( 'Feels like', 'fontdelbosc-eltemps' ); ?>: <?php echo esc_html( number_format_i18n( round( (float) $data['apparent'] ) ) ); ?>°C</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( null !== $data['humidity'] ) : ?>
|
||||
<li><?php echo esc_html__( 'Humidity', 'fontdelbosc-eltemps' ); ?>: <?php echo esc_html( number_format_i18n( (float) $data['humidity'] ) ); ?>%</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( null !== $data['wind_speed'] ) : ?>
|
||||
<li><?php echo esc_html__( 'Wind', 'fontdelbosc-eltemps' ); ?>: <?php echo esc_html( number_format_i18n( round( (float) $data['wind_speed'] ) ) ); ?> km/h</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( null !== $data['precipitation'] ) : ?>
|
||||
<li><?php echo esc_html__( 'Precipitation', 'fontdelbosc-eltemps' ); ?>: <?php echo esc_html( number_format_i18n( (float) $data['precipitation'], 1 ) ); ?> mm</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
|
||||
<?php if ( $fontdelbosc_show_attribution ) : ?>
|
||||
<p class="fdb-attribution"><?php echo esc_html( Fontdelbosc_Data_Manager::attribution( (string) $data['source'] ) ); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
68
templates/forecast-daily.php
Normal file
68
templates/forecast-daily.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?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>
|
||||
43
templates/forecast-hourly.php
Normal file
43
templates/forecast-hourly.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
* Hourly forecast template (horizontally scrollable strip).
|
||||
*
|
||||
* @var array<string,mixed> $data Normalized hourly forecast.
|
||||
*
|
||||
* @package FontdelboscEltemps
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$fontdelbosc_show_attribution = ! empty( Fontdelbosc_Plugin::get_options()['display_attribution'] );
|
||||
?>
|
||||
<div class="fdb-weather fdb-hourly">
|
||||
<h3 class="fdb-weather__title"><?php esc_html_e( 'Forecast', 'fontdelbosc-eltemps' ); ?></h3>
|
||||
|
||||
<div class="fdb-hourly__scroll">
|
||||
<?php foreach ( $data['hours'] as $fontdelbosc_hour ) : ?>
|
||||
<?php $fontdelbosc_night = Fontdelbosc_Conditions::is_night( (int) $fontdelbosc_hour['hour'] ); ?>
|
||||
<div class="fdb-hourly__item">
|
||||
<span class="fdb-hourly__time"><?php echo esc_html( sprintf( '%02d:00', (int) $fontdelbosc_hour['hour'] ) ); ?></span>
|
||||
<?php if ( ! empty( $fontdelbosc_hour['condition'] ) ) : ?>
|
||||
<img class="fdb-icon" src="<?php echo esc_url( Fontdelbosc_Conditions::icon( (string) $fontdelbosc_hour['condition'], $fontdelbosc_night ) ); ?>" alt="" width="48" height="48" loading="lazy" />
|
||||
<?php else : ?>
|
||||
<span class="fdb-hourly__icon-placeholder"></span>
|
||||
<?php endif; ?>
|
||||
<?php if ( null !== $fontdelbosc_hour['temperature'] ) : ?>
|
||||
<span class="fdb-hourly__temp"><?php echo esc_html( number_format_i18n( round( (float) $fontdelbosc_hour['temperature'] ) ) ); ?>°</span>
|
||||
<?php endif; ?>
|
||||
<?php if ( null !== $fontdelbosc_hour['pop'] ) : ?>
|
||||
<span class="fdb-hourly__pop"><?php echo esc_html( number_format_i18n( (float) $fontdelbosc_hour['pop'] ) ); ?>%</span>
|
||||
<?php endif; ?>
|
||||
<?php if ( null !== $fontdelbosc_hour['wind'] ) : ?>
|
||||
<span class="fdb-hourly__wind"><?php echo esc_html( number_format_i18n( round( (float) $fontdelbosc_hour['wind'] ) ) ); ?> km/h</span>
|
||||
<?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>
|
||||
86
templates/historical.php
Normal file
86
templates/historical.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/**
|
||||
* Historical data template: monthly stats plus a pure-CSS bar chart
|
||||
* (daily max/min temperatures, precipitation in tooltips).
|
||||
*
|
||||
* @var array<string,mixed> $data Normalized monthly history.
|
||||
*
|
||||
* @package FontdelboscEltemps
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$fontdelbosc_show_attribution = ! empty( Fontdelbosc_Plugin::get_options()['display_attribution'] );
|
||||
$fontdelbosc_maxes = array();
|
||||
$fontdelbosc_mins = array();
|
||||
|
||||
foreach ( $data['days'] as $fontdelbosc_day ) {
|
||||
if ( is_numeric( $fontdelbosc_day['temp_max'] ?? null ) ) {
|
||||
$fontdelbosc_maxes[] = (float) $fontdelbosc_day['temp_max'];
|
||||
}
|
||||
|
||||
if ( is_numeric( $fontdelbosc_day['temp_min'] ?? null ) ) {
|
||||
$fontdelbosc_mins[] = (float) $fontdelbosc_day['temp_min'];
|
||||
}
|
||||
}
|
||||
|
||||
$fontdelbosc_scale_min = array() === $fontdelbosc_mins ? 0 : floor( min( $fontdelbosc_mins ) );
|
||||
$fontdelbosc_scale_max = array() === $fontdelbosc_maxes ? 1 : ceil( max( $fontdelbosc_maxes ) );
|
||||
|
||||
if ( $fontdelbosc_scale_max <= $fontdelbosc_scale_min ) {
|
||||
$fontdelbosc_scale_max = $fontdelbosc_scale_min + 1;
|
||||
}
|
||||
|
||||
$fontdelbosc_range = $fontdelbosc_scale_max - $fontdelbosc_scale_min;
|
||||
?>
|
||||
<div class="fdb-weather fdb-historical">
|
||||
<h3 class="fdb-weather__title"><?php echo esc_html__( 'Historical data', 'fontdelbosc-eltemps' ); ?> — <?php echo esc_html( Fontdelbosc_Conditions::month( (int) $data['month'] ) . ' ' . (string) $data['year'] ); ?></h3>
|
||||
|
||||
<ul class="fdb-historical__stats">
|
||||
<?php if ( null !== ( $data['stats']['avg_max'] ?? null ) ) : ?>
|
||||
<li><?php esc_html_e( 'Average max.', 'fontdelbosc-eltemps' ); ?> <?php echo esc_html( number_format_i18n( (float) $data['stats']['avg_max'], 1 ) ); ?>°C</li>
|
||||
<?php endif; ?>
|
||||
<?php if ( null !== ( $data['stats']['avg_min'] ?? null ) ) : ?>
|
||||
<li><?php esc_html_e( 'Average min.', 'fontdelbosc-eltemps' ); ?> <?php echo esc_html( number_format_i18n( (float) $data['stats']['avg_min'], 1 ) ); ?>°C</li>
|
||||
<?php endif; ?>
|
||||
<li><?php esc_html_e( 'Total precipitation', 'fontdelbosc-eltemps' ); ?> <?php echo esc_html( number_format_i18n( (float) $data['stats']['total_precip'], 1 ) ); ?> mm</li>
|
||||
</ul>
|
||||
|
||||
<div class="fdb-historical__chart" aria-hidden="true">
|
||||
<?php foreach ( $data['days'] as $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_height_max = is_numeric( $fontdelbosc_day['temp_max'] ?? null ) ? round( ( ( (float) $fontdelbosc_day['temp_max'] - $fontdelbosc_scale_min ) / $fontdelbosc_range ) * 100, 1 ) : 0;
|
||||
$fontdelbosc_height_min = is_numeric( $fontdelbosc_day['temp_min'] ?? null ) ? round( ( ( (float) $fontdelbosc_day['temp_min'] - $fontdelbosc_scale_min ) / $fontdelbosc_range ) * 100, 1 ) : 0;
|
||||
|
||||
$fontdelbosc_title_parts = array( wp_date( 'j/n', $fontdelbosc_timestamp ) );
|
||||
|
||||
if ( is_numeric( $fontdelbosc_day['temp_max'] ?? null ) ) {
|
||||
$fontdelbosc_title_parts[] = number_format_i18n( round( (float) $fontdelbosc_day['temp_max'] ) ) . '° / ' . number_format_i18n( round( (float) $fontdelbosc_day['temp_min'] ) ) . '°';
|
||||
}
|
||||
|
||||
if ( is_numeric( $fontdelbosc_day['precipitation'] ?? null ) ) {
|
||||
$fontdelbosc_title_parts[] = number_format_i18n( (float) $fontdelbosc_day['precipitation'], 1 ) . ' mm';
|
||||
}
|
||||
?>
|
||||
<div class="fdb-historical__col" title="<?php echo esc_attr( implode( ' · ', $fontdelbosc_title_parts ) ); ?>">
|
||||
<div class="fdb-historical__bars">
|
||||
<div class="fdb-historical__bar fdb-historical__bar--max" style="height:<?php echo esc_attr( (string) $fontdelbosc_height_max ); ?>%"></div>
|
||||
<div class="fdb-historical__bar fdb-historical__bar--min" style="height:<?php echo esc_attr( (string) $fontdelbosc_height_min ); ?>%"></div>
|
||||
</div>
|
||||
<span class="fdb-historical__day"><?php echo esc_html( wp_date( 'j', $fontdelbosc_timestamp ) ); ?></span>
|
||||
</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>
|
||||
Loading…
Reference in a new issue