summaryrefslogtreecommitdiff
path: root/includes/session.php
diff options
context:
space:
mode:
authorRaindropsSys <raindrops@equestria.dev>2023-10-24 17:43:37 +0200
committerRaindropsSys <raindrops@equestria.dev>2023-10-24 17:43:37 +0200
commitae187b6d75c8079da0be1dc288613bad8466fe61 (patch)
tree5ea0d34185a2270f29ffaa65e1f5258028d7d5d0 /includes/session.php
downloadmist-ae187b6d75c8079da0be1dc288613bad8466fe61.tar.gz
mist-ae187b6d75c8079da0be1dc288613bad8466fe61.tar.bz2
mist-ae187b6d75c8079da0be1dc288613bad8466fe61.zip
Initial commit
Diffstat (limited to 'includes/session.php')
-rw-r--r--includes/session.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/includes/session.php b/includes/session.php
new file mode 100644
index 0000000..8427fc2
--- /dev/null
+++ b/includes/session.php
@@ -0,0 +1,67 @@
+<?php
+
+global $_PROFILE;
+$_PROFILE = null;
+
+if (isset($_COOKIE["WAVY_SESSION_TOKEN"])) {
+ if (!str_contains($_COOKIE["WAVY_SESSION_TOKEN"], ".") && !str_contains($_COOKIE["WAVY_SESSION_TOKEN"], "/")) {
+ if (str_starts_with($_COOKIE["WAVY_SESSION_TOKEN"], "wv_")) {
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . $_COOKIE["WAVY_SESSION_TOKEN"])) {
+ $_PROFILE = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . $_COOKIE["WAVY_SESSION_TOKEN"]), true);
+ }
+ }
+ }
+}
+
+if (!isset($_PROFILE)) {
+ if (str_contains($_SERVER['HTTP_USER_AGENT'], "MistNative/")) {
+ header("Location: /oauth/needs-native/");
+ } else {
+ header("Location: /oauth/init/");
+ }
+
+ die();
+}
+
+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", "[]");
+
+$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);
+
+function displayList($list, $hasAlbum = false) { global $albums; global $favorites; ?>
+ <div class="list-group" style="margin-left: 10px; margin-top: 20px;" id="main-list">
+ <?php foreach ($list as $id => $song): ?>
+ <div data-item-track="<?= $song["title"] ?>" data-item-artist="<?= $song["artist"] ?>" id="item-<?= $id ?>" class="list-group-item track" style="display: grid; grid-template-columns: 32px 1fr max-content;">
+ <div style="opacity: .5; display: flex; align-items: center; justify-content: left;"><?= $hasAlbum && $song["track"] > 0 ? $song["track"] : "" ?></div>
+ <?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 if ($hasAlbum && $song["artist"] === $albums[$_GET["a"]]["artist"]): ?>
+ <div><?= $song["title"] ?></div>
+ <?php else: ?>
+ <div><?= $song["title"] ?><br><span style="opacity: .5;"><?= $song["artist"] ?></span></div>
+ <?php endif; ?>
+ </div>
+ <?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 ?>">
+ <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 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>
+ </div>
+ </div>
+ <?php endforeach; ?>
+ </div>
+<?php } \ No newline at end of file