Files
wp-fedistream/templates/shortcodes/tracks-list.php

74 lines
3.8 KiB
PHP
Raw Normal View History

<?php
/**
* Tracks list shortcode template.
*
* @package WP_FediStream
*
* @var array $posts Array of track data.
* @var int $columns Number of columns.
* @var string $title Section title.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$columns = $columns ?? 1;
?>
<div class="fedistream-shortcode fedistream-shortcode--tracks">
<?php if ( ! empty( $title ) ) : ?>
<h3 class="fedistream-shortcode__title"><?php echo esc_html( $title ); ?></h3>
<?php endif; ?>
<?php if ( ! empty( $posts ) && is_array( $posts ) ) : ?>
<div class="fedistream-tracklist fedistream-tracklist--numbered">
<?php foreach ( $posts as $index => $post ) : ?>
<div class="fedistream-tracklist__item" data-track-id="<?php echo esc_attr( $post['id'] ?? '' ); ?>">
<span class="fedistream-tracklist__rank"><?php echo esc_html( $index + 1 ); ?></span>
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="" class="fedistream-tracklist__artwork">
<?php else : ?>
<div class="fedistream-tracklist__artwork fedistream-tracklist__artwork--placeholder">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/></svg>
</div>
<?php endif; ?>
<div class="fedistream-tracklist__info">
<a href="<?php echo esc_url( $post['permalink'] ?? '#' ); ?>" class="fedistream-tracklist__title"><?php echo esc_html( $post['title'] ?? '' ); ?></a>
<span class="fedistream-tracklist__artist">
<?php if ( ! empty( $post['artists'] ) && is_array( $post['artists'] ) ) : ?>
<?php
$artist_links = array();
foreach ( $post['artists'] as $artist ) {
$artist_links[] = sprintf(
'<a href="%s">%s</a>',
esc_url( $artist['url'] ?? '#' ),
esc_html( $artist['name'] ?? '' )
);
}
echo implode( ', ', $artist_links ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
<?php elseif ( ! empty( $post['artist'] ) ) : ?>
<?php echo esc_html( $post['artist'] ); ?>
<?php endif; ?>
</span>
</div>
<?php if ( ! empty( $post['play_count'] ) ) : ?>
<span class="fedistream-tracklist__plays"><?php echo esc_html( number_format( $post['play_count'] ) ); ?></span>
<?php endif; ?>
<?php if ( ! empty( $post['duration_formatted'] ) ) : ?>
<span class="fedistream-tracklist__duration"><?php echo esc_html( $post['duration_formatted'] ); ?></span>
<?php endif; ?>
<button type="button" class="fedistream-tracklist__play" aria-label="<?php esc_attr_e( 'Play', 'wp-fedistream' ); ?>">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
</button>
</div>
<?php endforeach; ?>
</div>
<?php else : ?>
<div class="fedistream-empty">
<p><?php esc_html_e( 'No tracks found.', 'wp-fedistream' ); ?></p>
</div>
<?php endif; ?>
</div>