110 lines
4.8 KiB
PHP
110 lines
4.8 KiB
PHP
<?php
|
|
/**
|
|
* Journal Stream block render.
|
|
*
|
|
* @package CHRNX
|
|
*/
|
|
|
|
// Read-only filters do not change server state; every value is validated by the query service.
|
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
$chrnx_request = is_array( $_GET ) ? $_GET : array();
|
|
$chrnx_args = chrnx_get_journal_query_args( $chrnx_request );
|
|
$chrnx_query = chrnx_run_eligible_query( $chrnx_args );
|
|
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
|
|
$chrnx_topic = chrnx_validate_editorial_term_slug( $chrnx_request['chrnx_topic'] ?? '', 'chrnx_topic' );
|
|
$chrnx_language = chrnx_validate_editorial_term_slug( $chrnx_request['chrnx_language'] ?? '', 'chrnx_language' );
|
|
$chrnx_search = $chrnx_args['s'] ?? '';
|
|
$chrnx_form_url = chrnx_get_journal_base_url();
|
|
$chrnx_title_id = wp_unique_id( 'chrnx-journal-title-' );
|
|
?>
|
|
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-journal-stream' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> aria-labelledby="<?php echo esc_attr( $chrnx_title_id ); ?>">
|
|
<h<?php echo esc_attr( $chrnx_heading ); ?> id="<?php echo esc_attr( $chrnx_title_id ); ?>"><?php echo esc_html__( 'Journal', 'chrnx' ); ?></h<?php echo esc_attr( $chrnx_heading ); ?>>
|
|
<form class="chrnx-journal-stream__filters" method="get" action="<?php echo esc_url( $chrnx_form_url ); ?>">
|
|
<label>
|
|
<span><?php echo esc_html__( 'Topic', 'chrnx' ); ?></span>
|
|
<select name="chrnx_topic">
|
|
<option value=""><?php echo esc_html__( 'All topics', 'chrnx' ); ?></option>
|
|
<?php
|
|
foreach ( get_terms(
|
|
array(
|
|
'taxonomy' => 'chrnx_topic',
|
|
'hide_empty' => false,
|
|
)
|
|
) as $chrnx_term ) :
|
|
?>
|
|
<option value="<?php echo esc_attr( $chrnx_term->slug ); ?>" <?php selected( $chrnx_topic, $chrnx_term->slug ); ?>><?php echo esc_html( $chrnx_term->name ); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
<span><?php echo esc_html__( 'Language', 'chrnx' ); ?></span>
|
|
<select name="chrnx_language">
|
|
<option value=""><?php echo esc_html__( 'All languages', 'chrnx' ); ?></option>
|
|
<?php
|
|
foreach ( get_terms(
|
|
array(
|
|
'taxonomy' => 'chrnx_language',
|
|
'hide_empty' => false,
|
|
)
|
|
) as $chrnx_term ) :
|
|
?>
|
|
<option value="<?php echo esc_attr( $chrnx_term->slug ); ?>" <?php selected( $chrnx_language, $chrnx_term->slug ); ?>><?php echo esc_html( $chrnx_term->name ); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
<span><?php echo esc_html__( 'Search', 'chrnx' ); ?></span>
|
|
<input type="search" name="s" value="<?php echo esc_attr( $chrnx_search ); ?>">
|
|
</label>
|
|
<button type="submit"><?php echo esc_html__( 'Filter', 'chrnx' ); ?></button>
|
|
</form>
|
|
<?php if ( $chrnx_query->have_posts() ) : ?>
|
|
<ol class="chrnx-journal-stream__list">
|
|
<?php foreach ( $chrnx_query->posts as $chrnx_post ) : ?>
|
|
<?php if ( chrnx_is_eligible_editorial_post( $chrnx_post ) ) : ?>
|
|
<li><?php echo chrnx_get_editorial_card_markup( $chrnx_post->ID, min( 6, $chrnx_heading + 1 ), 'chrnx-journal-card' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></li>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</ol>
|
|
<?php if ( $chrnx_query->max_num_pages > 1 ) : ?>
|
|
<?php
|
|
$chrnx_filter_args = array_filter(
|
|
array(
|
|
'chrnx_topic' => $chrnx_topic,
|
|
'chrnx_language' => $chrnx_language,
|
|
's' => $chrnx_search,
|
|
),
|
|
'strlen'
|
|
);
|
|
$chrnx_pages = array_unique(
|
|
array_filter(
|
|
array( 1, $chrnx_args['paged'] - 1, $chrnx_args['paged'], $chrnx_args['paged'] + 1, (int) $chrnx_query->max_num_pages ),
|
|
static function ( $chrnx_page ) use ( $chrnx_query ) {
|
|
return $chrnx_page >= 1 && $chrnx_page <= $chrnx_query->max_num_pages;
|
|
}
|
|
)
|
|
);
|
|
sort( $chrnx_pages, SORT_NUMERIC );
|
|
?>
|
|
<nav class="chrnx-journal-stream__pagination" aria-label="<?php echo esc_attr__( 'Journal pages', 'chrnx' ); ?>">
|
|
<ul class="page-numbers">
|
|
<?php foreach ( $chrnx_pages as $chrnx_page ) : ?>
|
|
<li>
|
|
<?php if ( $chrnx_page === $chrnx_args['paged'] ) : ?>
|
|
<span class="page-numbers current" aria-current="page"><?php echo esc_html( number_format_i18n( $chrnx_page ) ); ?></span>
|
|
<?php else : ?>
|
|
<a class="page-numbers" href="<?php echo esc_url( chrnx_get_journal_page_url( $chrnx_page, $chrnx_filter_args ) ); ?>"><?php echo esc_html( number_format_i18n( $chrnx_page ) ); ?></a>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</nav>
|
|
<?php endif; ?>
|
|
<?php else : ?>
|
|
<p class="chrnx-journal-stream__empty">
|
|
<?php echo esc_html__( 'No journal entries match these filters yet.', 'chrnx' ); ?>
|
|
<a href="<?php echo esc_url( chrnx_get_full_journal_url() ); ?>"><?php echo esc_html__( 'Browse the full Journal', 'chrnx' ); ?></a>
|
|
</p>
|
|
<?php endif; ?>
|
|
</section>
|