You've already forked wp-fedistream
All checks were successful
Create Release Package / build-release (push) Successful in 55s
- Remove twig/twig dependency from composer.json - Convert all 25 Twig templates to native PHP templates - New render() method in Plugin.php using PHP include with output buffering - New render_partial() helper method for including partials - Templates support theme overrides via fedistream/ directory - Reduced plugin size by eliminating Twig and its dependencies Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
98 lines
5.3 KiB
PHP
98 lines
5.3 KiB
PHP
<?php
|
|
/**
|
|
* Track shortcode template.
|
|
*
|
|
* @package WP_FediStream
|
|
*
|
|
* @var array $post Track data array.
|
|
* @var string $layout Layout style (full, card, compact).
|
|
* @var bool $show_player Whether to show the player.
|
|
*/
|
|
|
|
// Prevent direct file access.
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
$layout = $layout ?? 'full';
|
|
?>
|
|
<div class="fedistream-shortcode fedistream-shortcode--track fedistream-shortcode--<?php echo esc_attr( $layout ); ?>">
|
|
<div class="fedistream-track">
|
|
<div class="fedistream-track__header">
|
|
<div class="fedistream-track__artwork">
|
|
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
|
|
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" class="fedistream-track__image">
|
|
<?php else : ?>
|
|
<div class="fedistream-track__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; ?>
|
|
<?php if ( ! empty( $show_player ) ) : ?>
|
|
<button type="button" class="fedistream-track__play-overlay" data-track-id="<?php echo esc_attr( $post['id'] ?? '' ); ?>" aria-label="<?php esc_attr_e( 'Play', 'wp-fedistream' ); ?>">
|
|
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
|
|
</button>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="fedistream-track__info">
|
|
<h3 class="fedistream-track__title">
|
|
<a href="<?php echo esc_url( $post['permalink'] ?? '#' ); ?>"><?php echo esc_html( $post['title'] ?? '' ); ?></a>
|
|
</h3>
|
|
<?php if ( ! empty( $post['artists'] ) && is_array( $post['artists'] ) ) : ?>
|
|
<p class="fedistream-track__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
|
|
?>
|
|
</p>
|
|
<?php endif; ?>
|
|
<?php if ( ! empty( $post['album_title'] ) ) : ?>
|
|
<p class="fedistream-track__album">
|
|
<?php esc_html_e( 'From', 'wp-fedistream' ); ?> <a href="<?php echo esc_url( $post['album_url'] ?? '#' ); ?>"><?php echo esc_html( $post['album_title'] ); ?></a>
|
|
</p>
|
|
<?php endif; ?>
|
|
<div class="fedistream-track__meta">
|
|
<?php if ( ! empty( $post['duration_formatted'] ) ) : ?>
|
|
<span class="fedistream-track__duration"><?php echo esc_html( $post['duration_formatted'] ); ?></span>
|
|
<?php endif; ?>
|
|
<?php if ( ! empty( $post['play_count'] ) ) : ?>
|
|
<span class="fedistream-track__plays">
|
|
<?php
|
|
printf(
|
|
/* translators: %d: number of plays */
|
|
esc_html( _n( '%d play', '%d plays', $post['play_count'], 'wp-fedistream' ) ),
|
|
(int) $post['play_count']
|
|
);
|
|
?>
|
|
</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ( ! empty( $show_player ) && ! empty( $post['audio_url'] ) ) : ?>
|
|
<div class="fedistream-track__player">
|
|
<div class="fedistream-player fedistream-player--inline" data-track-id="<?php echo esc_attr( $post['id'] ?? '' ); ?>" data-audio-url="<?php echo esc_url( $post['audio_url'] ); ?>">
|
|
<button type="button" class="fedistream-player__btn fedistream-player__btn--play" aria-label="<?php esc_attr_e( 'Play', 'wp-fedistream' ); ?>">
|
|
<svg class="fedistream-player__icon fedistream-player__icon--play" viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
|
|
<svg class="fedistream-player__icon fedistream-player__icon--pause" viewBox="0 0 24 24" fill="currentColor"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>
|
|
</button>
|
|
<div class="fedistream-player__progress">
|
|
<div class="fedistream-player__bar">
|
|
<div class="fedistream-player__bar-progress"></div>
|
|
<input type="range" class="fedistream-player__seek" min="0" max="100" value="0" aria-label="<?php esc_attr_e( 'Seek', 'wp-fedistream' ); ?>">
|
|
</div>
|
|
</div>
|
|
<span class="fedistream-player__time"><?php echo esc_html( $post['duration_formatted'] ?? '0:00' ); ?></span>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|