Files
chrnx-dev-wp/blocks/release-detail/render.php
T
2026-08-15 15:34:37 -05:00

69 lines
3.7 KiB
PHP

<?php
/**
* Release Detail block render.
*
* @package CHRNX
*/
$chrnx_term = get_queried_object();
if ( ! $chrnx_term instanceof WP_Term || 'chrnx_release' !== $chrnx_term->taxonomy ) {
return;
}
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_release_status', true );
$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_release_cover', true ) );
$chrnx_links = chrnx_get_release_links( $chrnx_term->term_id );
$chrnx_cover_markup = $chrnx_cover > 0 ? wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-release-detail__cover' ) ) : '';
$chrnx_tracks = chrnx_get_release_track_ids( $chrnx_term->slug );
$chrnx_track_h = min( 6, $chrnx_heading + 1 );
// Without status, description or links there is no second column to fill.
$chrnx_has_intro = '' !== $chrnx_status || '' !== $chrnx_term->description || ! empty( $chrnx_links );
$chrnx_head_class = 'chrnx-release-detail__head' . ( $chrnx_has_intro ? '' : ' is-bare' );
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-release-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<div class="<?php echo esc_attr( $chrnx_head_class ); ?>">
<div class="chrnx-release-detail__art">
<?php if ( '' !== $chrnx_cover_markup ) : ?>
<?php echo $chrnx_cover_markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?>
<?php echo chrnx_get_topic_portrait_markup( 'placeholder-release', '', 'chrnx-release-detail__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php endif; ?>
</div>
<div class="chrnx-release-detail__intro">
<?php if ( '' !== $chrnx_status ) : ?>
<p class="chrnx-release-detail__status"><?php echo esc_html( $chrnx_status ); ?></p>
<?php endif; ?>
<?php if ( '' !== $chrnx_term->description ) : ?>
<p class="chrnx-release-detail__description"><?php echo esc_html( $chrnx_term->description ); ?></p>
<?php endif; ?>
<?php echo chrnx_get_platform_links_markup( $chrnx_links, 'chrnx-platform-links' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
</div>
<?php if ( empty( $chrnx_tracks ) ) : ?>
<p class="chrnx-release-detail__empty"><?php echo esc_html__( 'No published tracks yet.', 'chrnx' ); ?></p>
<?php else : ?>
<ol class="chrnx-tracklist">
<?php
foreach ( $chrnx_tracks as $chrnx_index => $chrnx_track_id ) :
$chrnx_number = absint( get_post_meta( $chrnx_track_id, 'chrnx_track_number', true ) );
$chrnx_player = chrnx_get_track_player_markup( $chrnx_track_id );
?>
<li class="chrnx-tracklist__item">
<span class="chrnx-tracklist__number" aria-hidden="true"><?php echo esc_html( str_pad( (string) ( $chrnx_number > 0 ? $chrnx_number : $chrnx_index + 1 ), 2, '0', STR_PAD_LEFT ) ); ?></span>
<?php if ( '' !== $chrnx_player ) : ?>
<div class="chrnx-tracklist__player"><?php echo $chrnx_player; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php endif; ?>
<div class="chrnx-tracklist__body">
<h<?php echo esc_attr( $chrnx_track_h ); ?> class="chrnx-tracklist__title">
<a href="<?php echo esc_url( get_permalink( $chrnx_track_id ) ); ?>"><?php echo esc_html( get_the_title( $chrnx_track_id ) ); ?></a>
</h<?php echo esc_attr( $chrnx_track_h ); ?>>
<?php echo chrnx_get_platform_links_markup( chrnx_get_track_links( $chrnx_track_id ), 'chrnx-platform-links' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
</section>