aboutsummaryrefslogtreecommitdiff
path: root/admin/pluralkit/index.php
blob: c976882a40e5a0d6a4781020d47c489808920e56 (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
<?php require_once $_SERVER["DOCUMENT_ROOT"] . "/includes/admin/session.php"; global $_USER; ?>
<?php

if (isset($_GET['submit'])) {
    if (isset($_GET["system-id"])) {
        file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/data/pluralkit.json", json_encode([
                "system" => $_GET['system-id']
        ], JSON_PRETTY_PRINT));
        header("Location: /admin/pluralkit");
        die();
    }
}

?>
<?php require_once $_SERVER["DOCUMENT_ROOT"] . "/includes/admin/header.php"; ?>

<br>
<div class="container">
    <h1>PluralKit Configuration</h1>

    <p><b>Current System:</b> <?php

        $config = json_decode(file_get_contents($_SERVER["DOCUMENT_ROOT"] . "/data/pluralkit.json"), true);
        $data = @file_get_contents("https://api.pluralkit.me/v2/systems/$config[system]");

        if (isset($data) && $data !== false):
            $parsed = json_decode($data, true);
        ?>
        <img src="<?= $parsed["avatar_url"] ?>" id="system-icon"><?= $parsed["name"] ?> (<code><?= $parsed["id"] ?></code>)
            <?php else: ?>
        <span class="text-danger">Not found, please make sure the ID is entered correctly</span>
            <?php endif; ?></p>
    <form class="input-group mb-3" style="max-width: 500px;">
        <input name="system-id" value="<?= $config['system'] ?>" type="text" class="form-control" placeholder="System ID">
        <input type="hidden" name="submit">
        <button class="btn btn-primary" type="submit">Save and apply</button>
    </form>
</div>

<style>
    #system-icon {
        border-radius: 999px;
        width: 24px;
        vertical-align: middle;
        background: lightgray;
        margin-right: 5px;
    }
</style>

<?php require_once $_SERVER["DOCUMENT_ROOT"] . "/includes/admin/footer.php"; ?>