dj_mix_hosting_software/mix.php

341 lines
No EOL
18 KiB
PHP

<?php
require 'includes/globals.php';
require_once 'classes/Database.php';
require_once 'classes/Mix.php';
require_once 'classes/Mixshow.php';
$db = new Database($config);
$mixFound = false;
if (isset($_GET['mix']) && $_GET['mix'] != "") {
$mix = new Mix($_GET['mix'], $db);
if ($mix->get_name() != "") {
$mixFound = true;
$title = $mix->get_name();
} else {
$title = $locale['notfound'];
}
} else {
$title = $locale['notfound'];
}
require 'includes/header.php'; ?>
<section style="background-color: #eee;">
<div class="container py-5">
<div class="row">
<div class="col">
<nav aria-label="breadcrumb" class="bg-body-tertiary rounded-3 p-3 mb-4">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item"><a href="/"><?php echo $locale['home']; ?></a></li>
<li class="breadcrumb-item"><a href="/mixes.php"><?php echo $locale['mixes']; ?></a></li>
<li class="breadcrumb-item active"
aria-current="page"><?php
if (isset($mix) && $mix->get_name() != "") {
echo $mix->get_name();
} else {
echo $locale['notfound'];
}
?></li>
</ol>
</nav>
</div>
</div>
<?php if ($mixFound): ?>
<div class="row">
<div class="col-lg-4">
<div class="card mb-4">
<div class="card-body text-center">
<?php
if ($mix->get_img() != "") {
echo "<img src='" . $mix->get_img() . "' alt='avatar' class='img-fluid' style='width: 150px;'>";
} ?>
<h1 class="my-3 fs-4"><?php echo $mix->get_name();
?></h1>
<?php
if ($mix->get_description() != "") {
echo "<h2 class='text-muted mb-4 fs-6'>" . $mix->get_description() . "</h2>";
}
?>
</p>
</div>
</div>
<div class="card mb-4">
<div class="card-body text-center">
<?php
if ($mix->is_download_only()) {
echo "<a href='" . $mix->get_url() . "' class='btn btn-primary'>" . $locale['download'] . "</a>";
} else {
echo "<audio controls controlsList='nodownload'>";
$url = $mix->get_url();
// if $url starts with /djs/, cut that.
if (substr($url, 0, 4) == "/djs") {
$url = substr($url, 4);
}
echo "<source src='https://cdn.utahsdjs.com" . $url . "' type='audio/mpeg'>";
echo $locale['audioNotSupported'];
echo "</audio>";
}
?>
</div>
</div>
</div>
<div class="col-lg-8">
<div class="card mb-4">
<div class="card-body">
<div class="row">
<div class="col-sm-3">
<p class="mb-0"><?php echo $locale['mixname'] ?></p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0"><?php echo $mix->get_name(); ?></p>
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0"><?php echo $locale['djs'] ?></p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0">
<?php
// loop through the $mix['djs'] array and output them in comma separated format
$djs = $mix->get_djs();
$djCount = count($djs);
$i = 0;
foreach ($djs as $dj) {
echo "<a href='/dj.php?dj=";
echo $dj->get_slug();
echo "'>" . $dj->get_name() . "</a>";
if ($i < $djCount - 1) {
echo ", ";
}
$i++;
}
?>
</p>
</div>
</div>
<?php
$genres = $mix->get_genres();
$genreCount = count($genres);
if ($genreCount > 0) {
?>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0"><?php echo $locale['genres'] ?></p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0">
<?php
$i = 0;
require_once 'classes/Genre.php';
foreach ($genres as $genre) {
$genre = new Genre($genre, $db);
echo "<a href='/genre.php?genre=";
echo $genre->get_slug();
echo "'>" . $genre->get_name() . "</a>";
if ($i < $genreCount - 1) {
echo ", ";
}
$i++;
}
?>
</div>
</div><?php } ?>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0"><?php echo $locale['duration'] ?></p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0">
<?php
$time = $mix->get_duration();
// Decide the correct singular or plural term
$hour_text = $time['h'] == 1 ? $locale['hour'] : $locale['hours'];
$minute_text = $time['m'] == 1 ? $locale['minute'] : $locale['minutes'];
$second_text = $time['s'] == 1 ? $locale['second'] : $locale['seconds'];
// Output the time, skipping hours if it is less than one hour
if ($time['h'] > 0) {
// If there are hours, always show hours.
echo $time['h'] . " " . $hour_text;
if ($time['m'] > 0) {
// Show minutes only if they are greater than 0.
echo ", " . $time['m'] . " " . $minute_text;
}
// Always show seconds, regardless of minutes.
echo ", " . $time['s'] . " " . $second_text;
} else {
// No hours, check minutes.
if ($time['m'] != 0) {
echo $time['m'] . " " . $minute_text . ", " . $time['s'] . " " . $second_text;
} else {
// Only seconds to show.
echo $time['s'] . " " . $second_text;
}
}
echo " (" . $time['t'] . ")";
?>
</div>
</div>
<?php if ($mix->get_recorded() != ""): ?>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0"><?php echo $locale['recorded'] ?></p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0">
<?php echo $mix->get_recorded(); ?>
</div>
</div>
<?php endif; ?>
<?php if ($mix->get_created() != ""): ?>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0"><?php echo $locale['added'] ?></p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0">
<?php echo $mix->get_created(); ?>
</div>
</div>
<?php endif; ?>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0"><?php echo $locale['downloads'] ?></p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0">
<?php echo $mix->get_downloads(); ?>
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0"><?php echo $locale['plays'] ?></p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0">
<?php echo $mix->get_plays(); ?>
</div>
</div>
<?php if ($mix->get_updated() != ""): ?>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0"><?php echo $locale['lastupdated'] ?></p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0">
<?php echo $mix->get_updated(); ?>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const audioElement = document.querySelector('audio');
if ('mediaSession' in navigator) {
navigator.mediaSession.metadata = new MediaMetadata({
title: '<?php echo addslashes($mix->get_name()); ?>',
artist: '<?php
$djs = $mix->get_djs();
$djCount = count($djs);
$i = 0;
$djnamelist = [];
foreach ($djs as $dj) {
$djnamelist[] = $dj->get_name();
$i++;
}
echo addslashes(implode(", ", $djnamelist));?>',
album: '<?php echo addslashes($mix->get_name()); ?>',
artwork: [
{
src: '<?php echo $mix->get_cover('small'); ?>',
sizes: '96x96',
type: 'image/jpeg'
},
{
src: '<?php echo $mix->get_cover('large'); ?>',
sizes: '128x128',
type: 'image/jpeg'
}
]
});
// Define action handlers
navigator.mediaSession.setActionHandler('play', function () {
audioElement.play();
});
navigator.mediaSession.setActionHandler('pause', function () {
audioElement.pause();
});
audioElement.addEventListener('timeupdate', () => {
// Update the position state
navigator.mediaSession.setPositionState({
duration: audioElement.duration,
playbackRate: audioElement.playbackRate,
position: audioElement.currentTime
});
});
}
});
</script>
<?php endif; ?>
</div>
</div>
<?php
if ($mix->get_tracklist() != []) {
echo "<div class='card mb-4'>";
echo "<div class='card-body'>";
echo "<p class='mb-4'><span class='text-primary font-italic me-1'>" . $locale['tracklist'] . "</span></p>";
echo "<ul class='list-group list-group-flush rounded-3'>";
$tracklist = $mix->get_tracklist();
foreach ($tracklist as $track) {
echo "<li class='list-group-item d-flex justify-content-between align-items-center'>";
echo $track;
echo "</li>";
}
echo "</ul>";
echo "</div>";
echo "</div>";
}
?>
</div>
</div>
</div>
<?php else: ?>
<div class="row">
<div class="col">
<div class="alert alert-danger" role="alert">
<?php echo $locale['mixNotFound']; ?>
</div>
</div>
</div>
<?php endif;
?>
</div>
</section>
<?php require 'includes/footer.php'; ?>