119 lines
5.3 KiB
PHP
119 lines
5.3 KiB
PHP
<?php
|
|
/**
|
|
* Incident card partial.
|
|
*
|
|
* @package Fontdelbosc_Transit
|
|
*
|
|
* @var array<string, mixed> $fontdelbosc_incident Normalized incident.
|
|
*/
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
$fontdelbosc_incident = isset( $fontdelbosc_incident ) ? $fontdelbosc_incident : array();
|
|
$fontdelbosc_is_c15 = Fontdelbosc_Transit_Maps::is_c15( $fontdelbosc_incident );
|
|
$fontdelbosc_type = (string) ( $fontdelbosc_incident['type'] ?? '' );
|
|
$fontdelbosc_key = Fontdelbosc_Transit_Maps::type_key( $fontdelbosc_type );
|
|
$fontdelbosc_title = (string) ( $fontdelbosc_incident['title'] ?? '' );
|
|
|
|
if ( '' === $fontdelbosc_title ) {
|
|
$fontdelbosc_title = Fontdelbosc_Transit_Maps::type_label( $fontdelbosc_type );
|
|
}
|
|
|
|
// The RSS title ends with the incident type in parentheses; redundant here.
|
|
$fontdelbosc_title = trim( (string) preg_replace( '/\s*\([^)]*\)$/', '', $fontdelbosc_title ) );
|
|
|
|
$fontdelbosc_meta_items = array();
|
|
|
|
if ( '' !== (string) ( $fontdelbosc_incident['direction'] ?? '' ) ) {
|
|
$fontdelbosc_meta_items[] = array(
|
|
'label' => Fontdelbosc_Transit_Maps::direction_label( (string) $fontdelbosc_incident['direction'] ),
|
|
'icon' => '',
|
|
);
|
|
}
|
|
|
|
if ( '' !== (string) ( $fontdelbosc_incident['start_time'] ?? '' ) ) {
|
|
$fontdelbosc_time = sprintf(
|
|
/* translators: %s: start date and time. */
|
|
__( 'Start: %s', 'fontdelbosc-transit' ),
|
|
Fontdelbosc_Transit_Maps::format_time( (string) $fontdelbosc_incident['start_time'] )
|
|
);
|
|
|
|
if ( '' !== (string) ( $fontdelbosc_incident['end_time'] ?? '' ) ) {
|
|
$fontdelbosc_time .= sprintf(
|
|
/* translators: %s: end date and time. */
|
|
' — ' . __( 'End: %s', 'fontdelbosc-transit' ),
|
|
Fontdelbosc_Transit_Maps::format_time( (string) $fontdelbosc_incident['end_time'] )
|
|
);
|
|
}
|
|
|
|
$fontdelbosc_meta_items[] = array(
|
|
'label' => $fontdelbosc_time,
|
|
'icon' => 'clock',
|
|
);
|
|
}
|
|
|
|
if ( '' !== (string) ( $fontdelbosc_incident['impact'] ?? '' ) ) {
|
|
$fontdelbosc_meta_items[] = array(
|
|
'label' => Fontdelbosc_Transit_Maps::impact_label( (string) $fontdelbosc_incident['impact'] ),
|
|
'icon' => '',
|
|
'impact' => true,
|
|
);
|
|
}
|
|
?>
|
|
<article class="fdbt-card fdbt-card--<?php echo esc_attr( $fontdelbosc_key ); ?><?php echo $fontdelbosc_is_c15 ? ' fdbt-card--c15' : ''; ?>">
|
|
<header class="fdbt-card__head">
|
|
<span class="fdbt-card__type fdbt-type--<?php echo esc_attr( $fontdelbosc_key ); ?>">
|
|
<span class="fdbt-icon fdbt-icon--<?php echo esc_attr( $fontdelbosc_key ); ?>" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( $fontdelbosc_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
|
<?php echo esc_html( Fontdelbosc_Transit_Maps::type_label( $fontdelbosc_type ) ); ?>
|
|
</span>
|
|
<?php if ( '' !== (string) ( $fontdelbosc_incident['status'] ?? '' ) ) : ?>
|
|
<span class="fdbt-card__status"><span class="fdbt-dot" aria-hidden="true"></span><?php echo esc_html( Fontdelbosc_Transit_Maps::status_label( (string) $fontdelbosc_incident['status'] ) ); ?></span>
|
|
<?php endif; ?>
|
|
</header>
|
|
|
|
<p class="fdbt-card__title"><?php echo esc_html( $fontdelbosc_title ); ?></p>
|
|
|
|
<?php if ( '' !== (string) ( $fontdelbosc_incident['road_name'] ?? '' ) || '' !== (string) ( $fontdelbosc_incident['town'] ?? '' ) || '' !== (string) ( $fontdelbosc_incident['km'] ?? '' ) ) : ?>
|
|
<p class="fdbt-card__place">
|
|
<?php
|
|
$fontdelbosc_place = array();
|
|
|
|
if ( '' !== (string) $fontdelbosc_incident['road_name'] ) {
|
|
$fontdelbosc_place[] = '<strong>' . esc_html( (string) $fontdelbosc_incident['road_name'] ) . '</strong>';
|
|
}
|
|
|
|
if ( '' !== (string) $fontdelbosc_incident['town'] ) {
|
|
$fontdelbosc_place[] = esc_html( (string) $fontdelbosc_incident['town'] );
|
|
}
|
|
|
|
if ( '' !== (string) $fontdelbosc_incident['km'] ) {
|
|
$fontdelbosc_place[] = esc_html( sprintf( /* translators: %s: kilometre point. */ __( 'km %s', 'fontdelbosc-transit' ), (string) $fontdelbosc_incident['km'] ) );
|
|
}
|
|
|
|
echo implode( ' · ', $fontdelbosc_place ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- parts escaped above.
|
|
?>
|
|
</p>
|
|
<?php endif; ?>
|
|
|
|
<?php if ( array() !== $fontdelbosc_meta_items ) : ?>
|
|
<ul class="fdbt-card__meta">
|
|
<?php foreach ( $fontdelbosc_meta_items as $fontdelbosc_meta_item ) : ?>
|
|
<li class="fdbt-card__meta-item<?php echo ! empty( $fontdelbosc_meta_item['impact'] ) ? ' fdbt-card__meta-item--impact' : ''; ?>">
|
|
<?php if ( 'clock' === $fontdelbosc_meta_item['icon'] ) : ?>
|
|
<span class="fdbt-meta__icon" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'clock' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
|
<?php endif; ?>
|
|
<?php echo esc_html( $fontdelbosc_meta_item['label'] ); ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
|
|
<?php if ( '' !== (string) ( $fontdelbosc_incident['link'] ?? '' ) ) : ?>
|
|
<p class="fdbt-card__link">
|
|
<a href="<?php echo esc_url( (string) $fontdelbosc_incident['link'] ); ?>" target="_blank" rel="nofollow noopener">
|
|
<?php esc_html_e( 'View at the SCT information centre', 'fontdelbosc-transit' ); ?>
|
|
<span class="fdbt-link__icon" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'external' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
|
</a>
|
|
</p>
|
|
<?php endif; ?>
|
|
</article>
|