summaryrefslogtreecommitdiff
path: root/app/ui/listing.php
blob: fdef67452490a69b383df3cd2b32131d9e3b543b (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php header("X-Frame-Options: SAMEORIGIN"); require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $_PROFILE; global $library;

if (isset($list)) {
    $presetList = true;
} else {
    $presetList = false;
}

if (!$presetList) {
    global $albums; global $songs; global $favorites;

    if (isset($_GET["a"]) && isset($albums[$_GET["a"]])) {
        $hasAlbum = true;
        $list = [];

        foreach ($albums[$_GET["a"]]["tracks"] as $id) {
            $list[$id] = $songs[$id];
        }
    } else {
        $hasAlbum = false;
        $list = $songs;

        foreach ($albums as $id => $album) {
            foreach ($album["tracks"] as $track) {
                $list[$track]["_albumID"] = $id;
            }
        }

        uasort($list, function ($a, $b) {
            return strcmp($a["title"], $b["title"]);
        });

        $list = array_filter($list, function ($i) {
            global $library;
            return in_array($i["_albumID"], $library);
        });
    }
}

if (!isset($onlyStella)) $onlyStella = 0;

if ($onlyStella === 1) {
    $hasAlbum = false;
    $list = $songs;

    foreach ($albums as $id => $album) {
        foreach ($album["tracks"] as $track) {
            $list[$track]["_albumID"] = $id;
        }
    }

    uasort($list, function ($a, $b) {
        return strcmp($a["title"], $b["title"]);
    });

    $list = array_filter($list, function ($i) {
        return file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/content/" . $i . ".stella");
    }, ARRAY_FILTER_USE_KEY);
} elseif ($onlyStella === 2) {
    $hasAlbum = false;
    $list = $songs;

    foreach ($albums as $id => $album) {
        foreach ($album["tracks"] as $track) {
            $list[$track]["_albumID"] = $id;
        }
    }

    uasort($list, function ($a, $b) {
        return strcmp($a["title"], $b["title"]);
    });

    $list = array_filter($list, function ($i) {
        return file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/content/" . $i . ".webm");
    }, ARRAY_FILTER_USE_KEY);
}

?>
<!doctype html>
<html lang="en">
<head>
    <script>
        if (typeof window.parent.openModal === "undefined") {
            location.href = "/app/#/songs";
        }
    </script>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>
        <?php if (isset($favoritesList) && !$hasAlbum): ?>
            Favorites
        <?php elseif ($hasAlbum): ?>
            <?= $albums[$_GET["a"]]["title"] ?>
        <?php elseif ($onlyStella === 1): ?>
            Mist Stella
        <?php elseif ($onlyStella === 2): ?>
            Music videos
        <?php else: ?>
            Songs
        <?php endif; ?>
    </title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="/assets/dark.css" rel="stylesheet">
    <link href="/assets/styles.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
    <script src="/assets/localforage.min.js"></script>
    <script src="/assets/js/shortcuts.js"></script>
    <script src="/assets/fuse.min.js"></script>
    <link id="native-css" href="/assets/native.css" rel="stylesheet" disabled>
</head>
<body class="crossplatform has-navigation">
    <div id="ui-navigation" style="z-index: 999; background-color: rgba(255, 255, 255, .75); position: fixed; top: 0; left: 0; right: 0; height: 32px; backdrop-filter: blur(50px); -webkit-backdrop-filter: blur(50px);">
        <div style="display: grid; grid-template-columns: max-content 1fr max-content; height: 100%;" class="container">
            <div id="ui-back-button" onclick="history.back();" style="display: flex; align-items: center; justify-content: center; text-align: center;<?php if (!$hasAlbum): ?>pointer-events: none; opacity: 0;<?php endif; ?>">
                <img src="/assets/icons/back.svg" alt="Back" class="icon">
            </div>
            <div style="display: flex; align-items: center; justify-content: center; text-align: center;"><b><?php if (!$hasAlbum && !isset($favoritesList) && $onlyStella === 0): ?>Songs<?php elseif ($onlyStella === 1): ?>Mist Stella<?php elseif ($onlyStella === 2): ?>Music videos<?php endif; ?></b></div>
            <?php if (!$hasAlbum): ?>
            <div>
                <input placeholder="Filter" id="filter" class="form-control" style="width: 256px;height: 32px;border-top: none;" onchange="updateFilter();" onkeyup="updateFilter();">
            </div>
            <?php endif; ?>
        </div>
    </div>
    <script src="/assets/js/common.js"></script>
    <?php if ($hasAlbum): ?>
    <script>
        window.parent.location.hash = "#/albums/<?= $_GET["a"] ?>";
    </script>
    <?php endif; if (isset($favoritesList)): global $userId; ?>
    <script>
        window.parent.location.hash = "#/favorites/<?= $userId ?>";
    </script>
    <?php endif; ?>
    <div class="container">
        <br>
        <?php if (isset($favoritesList) && !$hasAlbum): global $userId; ?>
            <div id="album-info" style="display: grid; grid-template-columns: 20vw 1fr; margin-top: 10px; margin-left: 10px; grid-gap: 30px;">
                <img id="album-info-art" alt="" src="/assets/favorites.svg" style="height: 20vw; width: 20vw; border-radius: .75vw;">
                <div id="album-info-text" style="padding: 30px 0; display: grid; grid-template-rows: 1fr max-content;">
                    <div><h2>Favorites</h2>
                        <h2 style="opacity: .5;">
                            <select onchange="changeView();" id="favorites-user-select" class="form-select" style="width: max-content;font-size: inherit;margin: -0.375rem 0 -0.375rem -0.75rem;">
                                <option <?= $userId === $_PROFILE["id"] ? "selected" : "" ?> value="<?= $_PROFILE["id"] ?>"><?= $_PROFILE["name"] ?></option>
                                <?php foreach (scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/users") as $user):
                                    if (str_ends_with($user, "-privacy.json")):
                                        $userPrivacy = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . $user), true);
                                        $userProfile = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/users/" . substr($user, 0, -13) . "-profile.json"), true);
                                        if ($userPrivacy["listen"] >= 1 && $userProfile["id"] !== $_PROFILE["id"]): ?>
                                <option <?= $userId === $userProfile["id"] ? "selected" : "" ?> value="<?= $userProfile["id"] ?>"><?= $userProfile["name"] ?></option>
                                <?php endif; endif; endforeach; ?>
                            </select>
                        </h2>
                        <div style="opacity: .5;">
                            Click on the heart icon near a song to add it to this list.
                        </div>
                    </div>
                    <div id="album-info-buttons">
                        <a class="btn btn-primary <?= count(array_keys($list)) <= 0 || $userId !== $_PROFILE["id"] ? "disabled" : "" ?>" onclick="window.parent.playSong('<?= array_keys($list)[0] ?? '' ?>', 'favorites');" style="width: 100px;">Play</a>
                        <a class="btn btn-outline-primary <?= count(array_keys($list)) <= 0 || $userId !== $_PROFILE["id"] ? "disabled" : "" ?>" style="width: 100px;" onclick="window.parent.shuffleList('favorites');">Shuffle</a>
                    </div>
                </div>
            </div>
        <?php elseif ($hasAlbum):

        $albums[$_GET["a"]]["stella"] = false;

        foreach ($albums[$_GET["a"]]["tracks"] as $track) {
            if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/content/" . $track . ".stella")) {
                $albums[$_GET["a"]]["stella"] = true;
            }
        }

        ?>
            <div id="album-info" style="display: grid; grid-template-columns: 20vw 1fr; margin-top: 10px; margin-left: 10px; grid-gap: 30px;">
                <img id="album-info-art" alt="" src="/assets/content/<?= $_GET["a"] ?>.jpg" style="height: 20vw; width: 20vw; border-radius: .75vw;">
                <div id="album-info-text" style="padding: 30px 0; display: grid; grid-template-rows: 1fr max-content;">
                    <div><h2><?= $albums[$_GET["a"]]["title"] ?></h2>
                        <h2 style="opacity: .5;"><?= $albums[$_GET["a"]]["artist"] ?></h2>
                        <div style="opacity: .5;">
                            <?php if (isset($albums[$_GET["a"]]["date"]) && $albums[$_GET["a"]]["date"] > 0): ?>
                                <?= $albums[$_GET["a"]]["date"] ?>
                                <?php if ($albums[$_GET["a"]]["hiRes"] || $albums[$_GET["a"]]["stella"]): ?> · <?php endif; ?>
                            <?php endif; if ($albums[$_GET["a"]]["hiRes"]): ?>
                                <img src='/assets/icons/lossless.svg' alt='' class='icon player-badge-icon'>Hi-Res Lossless
                                <?php if ($albums[$_GET["a"]]["stella"]): ?><span class="mist-stella"> · </span><?php endif; ?>
                            <?php endif; if ($albums[$_GET["a"]]["stella"]): ?>
                                <span class="mist-stella"><img src='/assets/icons/stella.svg' alt='' style="height: 14.4px !important; width: 14.4px !important;" class='icon player-badge-icon'><img src='/assets/icons/stella-full.svg' alt='' class='mist-stella-text icon player-badge-icon'></span>
                            <?php endif; ?>
                        </div>
                        <style>
                            .mist-stella-text {
                                width: 68px !important;
                                position: relative !important;
                                top: -1px !important;
                            }
                        </style>
                    </div>
                    <div id="album-info-buttons" <?php if (!in_array($_GET["a"], $library)): ?>class="nolibrary"<?php endif; ?>>
                        <?php if (in_array($_GET["a"], $library)): ?>
                        <a class="btn btn-primary" onclick="window.parent.playSong('<?= array_keys($list)[0] ?>', 'album:<?= $_GET["a"] ?>');" style="width: 100px;">Play</a>
                        <a class="btn btn-outline-primary" style="width: 100px;" onclick="window.parent.shuffleList('album:<?= $_GET["a"] ?>');">Shuffle</a>
                        <?php else: ?>
                        <a class="btn btn-primary" onclick="window.addToLibrary();" id="library-button" style="width: 200px;">Add to library</a>
                        <?php endif ?>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        <?php displayList($list, $hasAlbum); ?>
        <div class="list-group" style="margin-left: 10px; margin-top: 20px; display: none;" id="search-results"></div>
        <?php if (count($list) === 0 && !isset($favoritesList)): ?>
            <div class="text-muted" style="position: fixed; display: flex; inset: 0; align-items: center; justify-content: center;">
                <div style="text-align: center;">
                    <img class="icon" src="/assets/logo-transparent.svg" style="filter: grayscale(1) invert(1); width: 96px; height: 96px;" alt="">
                    <h4 style="opacity: .75;">Add music to your library</h4>
                    <p style="max-width: 300px; margin-left: auto; margin-right: auto;">Browse millions of songs and collect your favorites here.</p>
                    <div class="btn btn-primary" onclick="window.parent.openUI('home');">Browse Mist</div>
                </div>
            </div>
        <?php endif; ?>
        <br>
        <div style="margin-left: 10px;">
        <?php if ($hasAlbum && trim($albums[$_GET["a"]]["copyright"]) !== ""): ?>
        <div class="text-muted"><?= $albums[$_GET["a"]]["copyright"] ?></div>
        <?php endif; if ($hasAlbum && in_array($_GET["a"], $library)): ?><a class="link" id="library-button" href="#" onclick="removeFromLibrary();">Remove from library</a>
        <?php endif; ?>
        </div>
    </div>

    <script>
        <?php if ($hasAlbum): ?>
        async function addToLibrary() {
            document.getElementById("library-button").classList.add("disabled");
            await fetch("/api/addLibrary.php?i=<?= $_GET["a"] ?>");
            window.parent.redownloadLibrary();
            location.reload();
        }

        async function removeFromLibrary() {
            document.getElementById("library-button").classList.add("disabled");
            await fetch("/api/removeLibrary.php?i=<?= $_GET["a"] ?>");
            window.parent.redownloadLibrary();
            location.reload();
        }
        <?php endif; ?>

        let items = Array.from(document.getElementsByClassName("track")).map(i => { return { title: i.getAttribute("data-item-track").toLowerCase().replace(/[^a-z\d ]/mg, " ").replace(/ +/mg, " "), artist: i.getAttribute("data-item-artist").toLowerCase().replace(/[^a-z\d ]/mg, " ").replace(/ +/mg, " "), id: i.id } });

        function updateFilter() {
            let query = document.getElementById("filter").value.trim().toLowerCase().replace(/[^a-z\d ]/mg, " ").replace(/ +/mg, " ");

            if (query !== "") {
                document.getElementById("search-results").style.display = "flex";
                document.getElementById("main-list").style.display = "none";

                let results = items.filter(i => i.title.includes(query) || i.artist.includes(query)).slice(0, 50);
                document.getElementById("search-results").innerHTML = "";

                for (let result of results) {
                    document.getElementById("search-results").innerHTML += document.getElementById(result.id).outerHTML;
                }
            } else {
                document.getElementById("search-results").style.display = "none";
                document.getElementById("main-list").style.display = "flex";
            }
        }

        function changeView() {
            location.href = "favorites.php?u=" + document.getElementById("favorites-user-select").value;
        }
    </script>

    <style>
        #favorites-user-select {
            background-color: transparent;
            border-color: transparent;
        }

        #favorites-user-select:hover, #favorites-user-select:active, #favorites-user-select:focus {
            background-color: var(--bs-body-bg);
            border-color: var(--bs-border-color);
        }
    </style>

    <br><br>
</body>
</html>