summaryrefslogtreecommitdiff
path: root/includes/session.php
blob: 8427fc24d9cb88151138175020fef963607596b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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 }