42 lines
1.6 KiB
PHP
Executable File
42 lines
1.6 KiB
PHP
Executable File
<?php
|
|
// Returns the recently played list for live.php as table rows. Polled alongside now_playing.php.
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
require __DIR__ . '/includes/db.php';
|
|
require __DIR__ . '/includes/broadcasts.php';
|
|
|
|
function e(string $s): string {
|
|
return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
|
}
|
|
|
|
try {
|
|
$tracks = recentTracks(getDB());
|
|
} catch (Throwable $e) {
|
|
echo '<tr><td colspan="5">Unable to load recently played tracks.</td></tr>';
|
|
exit;
|
|
}
|
|
|
|
if (!$tracks) {
|
|
echo '<tr><td colspan="5">Nothing played yet. Tracks will appear here once the show is under way.</td></tr>';
|
|
exit;
|
|
}
|
|
|
|
foreach ($tracks as $t) {
|
|
// Album art and album title link to the album on Last.fm
|
|
$albumUrl = ($t['artist'] !== '' && $t['album'] !== '') ? lastfmAlbumUrl($t['artist'], $t['album']) : '';
|
|
$openLink = $albumUrl !== '' ? '<a href="' . e($albumUrl) . '" target="_blank" rel="noopener">' : '';
|
|
$closeLink = $albumUrl !== '' ? '</a>' : '';
|
|
|
|
// Stored in UTC; live.php reformats this in the listener's local time
|
|
$iso = str_replace(' ', 'T', $t['played_at']) . 'Z';
|
|
$fallback = substr($t['played_at'], 11, 5) . ' UTC';
|
|
|
|
echo '<tr>';
|
|
echo '<td class="track-art">' . ($t['art_url'] !== '' ? $openLink . '<img src="' . e($t['art_url']) . '" alt="Album art for ' . e($t['album']) . '">' . $closeLink : '') . '</td>';
|
|
echo '<td><time datetime="' . e($iso) . '">' . e($fallback) . '</time></td>';
|
|
echo '<td>' . e($t['title']) . '</td>';
|
|
echo '<td>' . e($t['artist']) . '</td>';
|
|
echo '<td>' . $openLink . e($t['album']) . $closeLink . '</td>';
|
|
echo '</tr>';
|
|
}
|