This commit is contained in:
Cody Cook 2024-05-19 20:01:13 -07:00
commit 70c8a87e15
25 changed files with 508 additions and 187 deletions

176
mix.php
View file

@ -2,10 +2,12 @@
require_once 'includes/globals.php';
require_once 'vendor/autoload.php';
use DJMixHosting\Database;
use DJMixHosting\Genre;
use DJMixHosting\Mix;
use DJMixHosting\Mixshow;
use DJMixHosting\Genre;
use DJMixHosting\Playcount;
$db = new Database($config);
@ -22,6 +24,15 @@ if (isset($_GET['mix']) && $_GET['mix'] != "") {
$title = $locale['notfound'];
}
// if this is a playcount PUT request, update the playcount
if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
$data = json_decode(file_get_contents('php://input'), true);
if (isset($data['mix']) && $data['mix'] != "") {
$playcount = new Playcount($data['mix'], $db);
$playcount->updatePlaycount();
}
}
require_once 'includes/header.php'; ?>
<section>
@ -68,15 +79,11 @@ require_once 'includes/header.php'; ?>
<div class="card-body bg-body-secondary text-center">
<?php
if ($mix->is_download_only()) {
echo "<a href='" . $mix->get_url() . "' class='btn btn-primary'>" . $locale['download'] . "</a>";
echo "<a href='/mix/" . $mix->get_slug() . "/download" . "' 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 "<source src='" . $url . "' type='audio/mpeg'>";
echo $locale['audioNotSupported'];
echo "</audio>";
@ -85,7 +92,22 @@ require_once 'includes/header.php'; ?>
?>
</div>
</div>
<div class="card mb-4">
<div class="card-body bg-body-secondary text-center">
<a href="#" class="btn btn-secondary w-100 mb-2"
id="shareBtn"><?php echo $locale['share']; ?></a>
<?php if (!$mix->is_download_only()) : ?>
<a href="<?php
echo "/mix/" . $mix->get_slug() . "/download";
?>"
class="btn btn-primary w-100 mb-2"><?php echo $locale['download']; ?></a>
<?php endif; ?>
</div>
</div>
</div>
<div class="col-lg-8">
<div class="card mb-4">
<div class="card-body bg-body-secondary">
@ -111,9 +133,9 @@ require_once 'includes/header.php'; ?>
$djCount = count($djs);
$i = 0;
foreach ($djs as $dj) {
echo "<a href='/dj.php?dj=";
echo $dj->get_slug();
echo "'>" . $dj->get_name() . "</a>";
echo "<a href='/dj/";
echo $dj->getSlug();
echo "'>" . $dj->getName() . "</a>";
if ($i < $djCount - 1) {
echo ", ";
}
@ -139,10 +161,9 @@ require_once 'includes/header.php'; ?>
<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 "<a href='/genre/";
echo $genre->get_slug();
echo "'>" . $genre->get_name() . "</a>";
if ($i < $genreCount - 1) {
@ -158,9 +179,9 @@ require_once 'includes/header.php'; ?>
$mixshows = $mix->get_mixshow();
$mixshowsCount = count($mixshows);
if ($mixshowsCount > 0) {
?>
<hr>
<div class="row">
?>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0"><?php echo $locale['mixshow'] ?></p>
</div>
@ -170,7 +191,7 @@ require_once 'includes/header.php'; ?>
$i = 0;
foreach ($mixshows as $mixshow) {
$mixshow = new Mixshow($mixshow, $db);
echo "<a href='/mixshow.php?mixshow=";
echo "<a href='/mixshow/";
echo $mixshow->get_slug();
echo "'>" . $mixshow->get_name() . "</a>";
if ($i < $mixshowsCount - 1) {
@ -180,7 +201,7 @@ require_once 'includes/header.php'; ?>
}
?>
</div>
</div><?php } ?>
</div><?php } ?>
<hr>
<div class="row">
<div class="col-sm-3">
@ -288,7 +309,7 @@ require_once 'includes/header.php'; ?>
$i = 0;
$djnamelist = [];
foreach ($djs as $dj) {
$djnamelist[] = $dj->get_name();
$djnamelist[] = $dj->getName();
$i++;
}
@ -331,29 +352,84 @@ require_once 'includes/header.php'; ?>
<?php endif; ?>
</div>
</div>
<?php
if ($mix->get_tracklist() != []) {
echo "<div class='card mb-4 bg-body-secondary'>";
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 bg-body-secondary'>";
$tracklist = $mix->get_tracklist();
foreach ($tracklist as $track) {
echo "<li class='list-group-item bg-body-secondary d-flex justify-content-between align-items-center'>";
echo $track;
echo "</li>";
}
echo "</ul>";
echo "</div>";
echo "</div>";
}
?>
</div>
<?php
if ($mix->get_tracklist() != []) {
echo "<div class='card mb-4 bg-body-secondary'>";
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 bg-body-secondary'>";
$tracklist = $mix->get_tracklist();
foreach ($tracklist as $track) {
echo "<li class='list-group-item bg-body-secondary d-flex justify-content-between align-items-center'>";
echo $track;
echo "</li>";
}
echo "</ul>";
echo "</div>";
echo "</div>";
}
?>
</div>
</div>
</div>
<div id="shareModal" class="modal">
<div class="modal-content">
<span class="close">&times;</span>
<h2><?php echo $locale['share']; ?></h2>
<a href="#" id="copyLinkBtn" class="btn btn-secondary w-100 mb-2">Copy URL</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode('https://utahsdjs.com/mix/' . $_GET['mix']); ?>"
target="_blank" class="btn btn-primary w-100 mb-2">Share to Facebook</a>
<a href="https://twitter.com/intent/tweet?url=<?php echo urlencode('https://utahsdjs.com/mix/' . $_GET['mix']); ?>"
target="_blank" class="btn btn-info w-100 mb-2">Share to X (Twitter)</a>
<a href="https://www.instagram.com/" target="_blank" class="btn btn-danger w-100">Share to Instagram</a>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById("shareModal");
// Get the button that opens the modal
var btn = document.getElementById("shareBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// Get the copy link button
var copyLinkBtn = document.getElementById("copyLinkBtn");
// Get the URL to be copied
var urlToCopy = window.location.href;
// When the user clicks the button, open the modal
btn.onclick = function () {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function () {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
// When the user clicks the copy link button, copy the URL to the clipboard
copyLinkBtn.onclick = function () {
navigator.clipboard.writeText(urlToCopy).then(function () {
alert('URL copied to clipboard');
}, function (err) {
alert('Failed to copy URL: ', err);
});
}
</script>
<?php else: ?>
<div class="row">
<div class="col">
@ -362,6 +438,7 @@ require_once 'includes/header.php'; ?>
</div>
</div>
</div>
<?php endif;
?>
@ -369,4 +446,27 @@ require_once 'includes/header.php'; ?>
</div>
</section>
<script>
// when the audio is played, send a PUT request to the page to update the playcount
document.addEventListener('DOMContentLoaded', function () {
const audioElement = document.querySelector('audio');
audioElement.addEventListener('play', function () {
fetch(window.location.href, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({mix: '<?php echo $mix->get_id(); ?>'}),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
});
});
</script>
<?php require_once 'includes/footer.php'; ?>