feat: Replace Twig with native PHP templates
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>
This commit is contained in:
2026-02-02 22:48:10 +01:00
parent 6e45b0b6f1
commit 379fd23be0
57 changed files with 1928 additions and 1559 deletions

126
templates/single/album.php Normal file
View File

@@ -0,0 +1,126 @@
<?php
/**
* Single album template.
*
* @package WP_FediStream
*
* @var array $post Album data array.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<article class="fedistream-single fedistream-single--album">
<header class="fedistream-single__header fedistream-single__header--album">
<div class="fedistream-single__artwork">
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" class="fedistream-single__image fedistream-single__image--album">
<?php else : ?>
<div class="fedistream-single__placeholder fedistream-single__placeholder--album">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 14.5c-2.49 0-4.5-2.01-4.5-4.5S9.51 7.5 12 7.5s4.5 2.01 4.5 4.5-2.01 4.5-4.5 4.5zm0-5.5c-.55 0-1 .45-1 1s.45 1 1 1 1-.45 1-1-.45-1-1-1z"/></svg>
</div>
<?php endif; ?>
</div>
<div class="fedistream-single__info">
<span class="fedistream-single__type-badge"><?php echo esc_html( $post['album_type_label'] ?? __( 'Album', 'wp-fedistream' ) ); ?></span>
<h1 class="fedistream-single__title"><?php echo esc_html( $post['title'] ?? '' ); ?></h1>
<?php if ( ! empty( $post['artist_name'] ) ) : ?>
<p class="fedistream-single__artist">
<a href="<?php echo esc_url( $post['artist_url'] ?? '#' ); ?>"><?php echo esc_html( $post['artist_name'] ); ?></a>
</p>
<?php endif; ?>
<div class="fedistream-single__meta">
<?php if ( ! empty( $post['release_date'] ) ) : ?>
<span class="fedistream-single__date"><?php echo esc_html( $post['release_date'] ); ?></span>
<?php endif; ?>
<?php if ( ! empty( $post['total_tracks'] ) ) : ?>
<span class="fedistream-single__tracks">
<?php
printf(
/* translators: %d: number of tracks */
esc_html( _n( '%d track', '%d tracks', $post['total_tracks'], 'wp-fedistream' ) ),
(int) $post['total_tracks']
);
?>
</span>
<?php endif; ?>
<?php if ( ! empty( $post['duration_formatted'] ) ) : ?>
<span class="fedistream-single__duration"><?php echo esc_html( $post['duration_formatted'] ); ?></span>
<?php endif; ?>
</div>
<?php if ( ! empty( $post['genres'] ) && is_array( $post['genres'] ) ) : ?>
<div class="fedistream-single__genres">
<?php foreach ( $post['genres'] as $genre ) : ?>
<a href="<?php echo esc_url( $genre['url'] ?? '#' ); ?>" class="fedistream-tag"><?php echo esc_html( $genre['name'] ?? '' ); ?></a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="fedistream-single__actions">
<button type="button" class="fedistream-btn fedistream-btn--primary fedistream-btn--play-all" data-album-id="<?php echo esc_attr( $post['id'] ?? '' ); ?>">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
<?php esc_html_e( 'Play All', 'wp-fedistream' ); ?>
</button>
<button type="button" class="fedistream-btn fedistream-btn--secondary fedistream-btn--shuffle" data-album-id="<?php echo esc_attr( $post['id'] ?? '' ); ?>">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M10.59 9.17L5.41 4 4 5.41l5.17 5.17 1.42-1.41zM14.5 4l2.04 2.04L4 18.59 5.41 20 17.96 7.46 20 9.5V4h-5.5zm.33 9.41l-1.41 1.41 3.13 3.13L14.5 20H20v-5.5l-2.04 2.04-3.13-3.13z"/></svg>
<?php esc_html_e( 'Shuffle', 'wp-fedistream' ); ?>
</button>
</div>
</div>
</header>
<?php if ( ! empty( $post['tracks'] ) && is_array( $post['tracks'] ) ) : ?>
<section class="fedistream-single__tracklist">
<div class="fedistream-tracklist fedistream-tracklist--album">
<?php foreach ( $post['tracks'] as $index => $track ) : ?>
<div class="fedistream-tracklist__item" data-track-id="<?php echo esc_attr( $track['id'] ?? '' ); ?>">
<span class="fedistream-tracklist__number"><?php echo esc_html( $track['track_number'] ?? ( $index + 1 ) ); ?></span>
<div class="fedistream-tracklist__info">
<a href="<?php echo esc_url( $track['permalink'] ?? '#' ); ?>" class="fedistream-tracklist__title"><?php echo esc_html( $track['title'] ?? '' ); ?></a>
<?php if ( ! empty( $track['featured_artists'] ) ) : ?>
<span class="fedistream-tracklist__featuring"><?php esc_html_e( 'feat.', 'wp-fedistream' ); ?> <?php echo esc_html( $track['featured_artists'] ); ?></span>
<?php endif; ?>
</div>
<?php if ( ! empty( $track['explicit'] ) ) : ?>
<span class="fedistream-badge fedistream-badge--explicit">E</span>
<?php endif; ?>
<?php if ( ! empty( $track['duration_formatted'] ) ) : ?>
<span class="fedistream-tracklist__duration"><?php echo esc_html( $track['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>
</section>
<?php endif; ?>
<?php if ( ! empty( $post['content'] ) ) : ?>
<section class="fedistream-single__content">
<h2 class="fedistream-section__title"><?php esc_html_e( 'About This Album', 'wp-fedistream' ); ?></h2>
<div class="fedistream-single__description">
<?php echo wp_kses_post( $post['content'] ); ?>
</div>
</section>
<?php endif; ?>
<?php if ( ! empty( $post['credits'] ) ) : ?>
<section class="fedistream-single__credits">
<h2 class="fedistream-section__title"><?php esc_html_e( 'Credits', 'wp-fedistream' ); ?></h2>
<div class="fedistream-credits">
<?php echo wp_kses_post( $post['credits'] ); ?>
</div>
</section>
<?php endif; ?>
<?php if ( ! empty( $post['license'] ) ) : ?>
<section class="fedistream-single__license">
<p class="fedistream-license">
<strong><?php esc_html_e( 'License:', 'wp-fedistream' ); ?></strong>
<a href="<?php echo esc_url( $post['license']['link'] ?? '#' ); ?>"><?php echo esc_html( $post['license']['name'] ?? '' ); ?></a>
</p>
</section>
<?php endif; ?>
</article>