diff options
Diffstat (limited to 'includes/session.php')
-rw-r--r-- | includes/session.php | 85 |
1 files changed, 78 insertions, 7 deletions
diff --git a/includes/session.php b/includes/session.php index 8427fc2..36c5216 100644 --- a/includes/session.php +++ b/includes/session.php @@ -28,11 +28,18 @@ global $albums; global $songs; if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/users")) mkdir($_SERVER['DOCUMENT_ROOT'] . "/includes/users"); if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . $_PROFILE["id"] . "-favorites.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . $_PROFILE["id"] . "-favorites.json", "[]"); if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . $_PROFILE["id"] . "-library.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . $_PROFILE["id"] . "-library.json", "[]"); +if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . $_PROFILE["id"] . "-history.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . $_PROFILE["id"] . "-history.json", "[]"); $albums = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/assets/content/albums.json"), true); $songs = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/assets/content/songs.json"), true); $favorites = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . $_PROFILE["id"] . "-favorites.json"), true); $library = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . $_PROFILE["id"] . "-library.json"), true); +$history = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . $_PROFILE["id"] . "-history.json"), true); + +$albums = array_map(function ($i) { + $i["artist"] = str_replace(";", ", ", $i["artist"]); + return $i; +}, $albums); function displayList($list, $hasAlbum = false) { global $albums; global $favorites; ?> <div class="list-group" style="margin-left: 10px; margin-top: 20px;" id="main-list"> @@ -42,26 +49,90 @@ function displayList($list, $hasAlbum = false) { global $albums; global $favorit <?php if (!$hasAlbum): ?> <div style="display: grid; grid-template-columns: 48px 1fr; grid-gap: 10px;"> <img src="/assets/content/<?= $id ?>.jpg" style="width: 48px; height: 48px;"> - <?php endif; ?> - <div style="height: 3em; display: flex; align-items: center; justify-content: left;"> + <?php endif; ?> + <div style="width: <?php if (!$hasAlbum): ?>50<?php else: ?>55<?php endif; ?>vw; height: 3em; display: flex; align-items: center; justify-content: left;"> <?php if ($hasAlbum && $song["artist"] === $albums[$_GET["a"]]["artist"]): ?> - <div><?= $song["title"] ?></div> + <div style="max-width: 100%;"><div style="max-width: 100%; white-space: nowrap; overflow: hidden !important; text-overflow: ellipsis;"><?= $song["title"] ?></div></div> <?php else: ?> - <div><?= $song["title"] ?><br><span style="opacity: .5;"><?= $song["artist"] ?></span></div> + <div style="max-width: 100%;"><div style="max-width: 100%; white-space: nowrap; overflow: hidden !important; text-overflow: ellipsis;"><?= $song["title"] ?></div><div style="max-width: 100%; white-space: nowrap; overflow: hidden !important; text-overflow: ellipsis; opacity: .5;"><?= $song["artist"] ?></div></div> <?php endif; ?> </div> - <?php if (!$hasAlbum): ?> + <?php if (!$hasAlbum): ?> </div> <?php endif; ?> <div class="list-actions"> - <span onclick="<?= in_array($id, $favorites) ? "un" : "" ?>favoriteSong('<?= $id ?>');" class="player-btn" style="border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; height: 48px; width: 48px;" id="btn-favorite-<?= $id ?>"> + <!--<span onclick="<?= in_array($id, $favorites) ? "un" : "" ?>favoriteSong('<?= $id ?>');" class="player-btn" style="border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; height: 48px; width: 48px;" id="btn-favorite-<?= $id ?>"> <img class="icon" alt="" src="/assets/icons/favorite-<?= in_array($id, $favorites) ? "on" : "off" ?>.svg" style="pointer-events: none; width: 32px; height: 32px;" id="btn-favorite-<?= $id ?>-icon"> - </span> + </span>--> <span onclick="window.parent.playSong('<?= $id ?>'<?php if ($hasAlbum): ?>, 'album:<?= $_GET["a"] ?>'<?php endif; ?>);" class="player-btn" style="border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; height: 48px; width: 48px;" id="btn-play-<?= $id ?>"> <img class="icon" alt="" src="/assets/icons/play.svg" style="pointer-events: none; width: 32px; height: 32px;" id="btn-play-<?= $id ?>-icon"> </span> + <span class="dropdown"> + <span class="player-btn" style="border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; height: 48px; width: 48px;" id="btn-menu-<?= $id ?>" data-bs-toggle="dropdown"> + <img class="icon" alt="" src="/assets/icons/menu.svg" style="pointer-events: none; width: 32px; height: 32px;" id="btn-menu-<?= $id ?>-icon"> + </span> + <ul class="dropdown-menu"> + <li><a onclick="playNext('<?= $id ?>');" class="dropdown-item" href="#"><img alt="" src="/assets/icons/playnext.svg" style="pointer-events: none; width: 24px; height: 24px; margin-right: 5px;">Play next</a></li> + <li><a onclick="enqueue('<?= $id ?>');" class="dropdown-item" href="#"><img alt="" src="/assets/icons/add.svg" style="pointer-events: none; width: 24px; height: 24px; margin-right: 5px;">Add to queue</a></li> + <li><hr class="dropdown-divider"></hr></li> + <li><a id="btn-favorite-<?= $id ?>" onclick="<?= in_array($id, $favorites) ? "un" : "" ?>favoriteSong('<?= $id ?>');" class="dropdown-item" href="#"><img id="btn-favorite-<?= $id ?>-icon" alt="" src="/assets/icons/favorite-<?= in_array($id, $favorites) ? "on" : "off" ?>.svg" style="pointer-events: none; width: 24px; height: 24px; margin-right: 5px;"><span id="btn-favorite-<?= $id ?>-text"><?= in_array($id, $favorites) ? "Remove from favorites" : "Add to favorites" ?></span></a></li> + <li><a onclick="downloadSong('<?= $id ?>');" class="dropdown-item" href="#"><img alt="" src="/assets/icons/download.svg" style="pointer-events: none; width: 24px; height: 24px; margin-right: 5px;">Download</a></li> + <li><a onclick="getInfo('<?= $id ?>');" class="dropdown-item" href="#"><img alt="" src="/assets/icons/info.svg" style="pointer-events: none; width: 24px; height: 24px; margin-right: 5px;">Get info</a></li> + </ul> + </span> </div> </div> <?php endforeach; ?> </div> + <script> + async function favoriteSong(id) { + document.getElementById("btn-favorite-" + id + "-icon").src = "/assets/icons/favorite-on.svg"; + document.getElementById("btn-favorite-" + id + "-text").innerText = "Remove from favorites"; + document.getElementById("btn-favorite-" + id).onclick = () => { + unfavoriteSong(id); + } + await fetch("/api/addFavorite.php?i=" + id); + + window.parent.redownloadFavorites(); + } + + function playNext(id) { + if (window.parent.playlist.length === 0) { + window.parent.playSong(id); + } else { + window.parent.playlist.splice(window.parent.currentPlaylistPosition, 0, id); + } + } + + function downloadSong(id) { + window.parent.openModal("Download song", "download.php?i=" + id); + } + + function getInfo(id) { + window.parent.openModal((window.parent.songs[id]?.artist ?? "Unknown artist") + " - " + (window.parent.songs[id]?.title ?? "Unknown song"), "info.php?i=" + id); + } + + function enqueue(id) { + if (window.parent.playlist.length === 0) { + window.parent.playSong(id); + } else { + window.parent.playlist.push(id); + } + } + + async function unfavoriteSong(id) { + document.getElementById("btn-favorite-" + id + "-icon").src = "/assets/icons/favorite-off.svg"; + document.getElementById("btn-favorite-" + id + "-text").innerText = "Add to favorites"; + document.getElementById("btn-favorite-" + id).onclick = () => { + favoriteSong(id); + } + await fetch("/api/removeFavorite.php?i=" + id); + + <?php if (isset($favoritesList)): ?> + location.reload(); + <?php endif; ?> + + window.parent.redownloadFavorites(); + } + </script> <?php }
\ No newline at end of file |