summaryrefslogtreecommitdiff
path: root/admin/requests/index.php
blob: 3ee2b796954e220279338dabf8149afbc614b412 (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
<?php

$title = "Pending requests · Admin";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/header.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/navigation.php";

?>

<div class="container">
    <br><br>
    <a href="/admin"> Delta Admin</a>
    <h1>Pending requests</h1>

    <?php

    $requestsNonPlus = array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests"), function ($i) { return !str_starts_with($i, "."); });

    $requestsNonPlus = array_values(array_filter($requestsNonPlus, function ($i) {
        $request = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/$i")), true);
        $adata = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/profiles/" . $request["author"] . ".json")), true);
        return !$adata["plus"];
    }));

    usort($requestsNonPlus, function ($a, $b) {
        return strtotime(json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/$a")), true)["date"]) - strtotime(json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/$b")), true)["date"]);
    });

    $requestsPlus = array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests"), function ($i) { return !str_starts_with($i, "."); });

    $requestsPlus = array_values(array_filter($requestsPlus, function ($i) {
        $request = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/$i")), true);
        $adata = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/profiles/" . $request["author"] . ".json")), true);
        return $adata["plus"];
    }));

    usort($requestsPlus, function ($a, $b) {
        return strtotime(json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/$a")), true)["date"]) - strtotime(json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/$b")), true)["date"]);
    });

    $requests = [...array_map(function ($i) {
        $id = $i;
        $i = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/$i")), true);
        $i["_id"] = explode(".", $id)[0];
        $i["_plus"] = true;
        return $i;
    }, $requestsPlus), ...array_map(function ($i) {
        $id = $i;
        $i = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/$i")), true);
        $i["_id"] = explode(".", $id)[0];
        $i["_plus"] = false;
        return $i;
    }, $requestsNonPlus)];

    ?>

    <div class="list-group">
        <?php foreach ($requests as $request): ?>
        <details class="list-group-item list-group-item-action <?= $request["_plus"] ? "list-group-item-warning" : "" ?>">
            <summary><?= json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/lang/en.json"), true)["request"]["types"][$request["type"]] ?> (<?php if (isset($request["id"]) && trim($request["id"]) !== "" && $request["id"] !== $request["author"]): ?>on <a href="/<?= str_starts_with("gallery", $request["type"]) ? "gallery" : ($request["type"] === "userpage" ? "people" : ($request["type"] === "userreport" ? "profile" : "articles")) ?>/<?= $request["id"] ?>" target="_blank"><?= getNameFromId($request["id"]) ?></a>; <?php endif; ?>from <a href="/profile/<?= $request["author"] ?>" target="_blank"><?php $adata = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/profiles/" . $request["author"] . ".json")), true); ?> <?= isset($adata["nick_name"]) && trim($adata["nick_name"]) !== "" ? $adata["nick_name"] : $adata["first_name"] . " " . $adata["last_name"] ?></a>; <?= timeAgo($request["date"]) ?>)</summary>

            <div class="list-group-item" style="margin-top: 10px;">
                <p>
                    <b>ID:</b> <?= $request["_id"] ?><br>
                    <b>Publish date:</b> <?= date('r', strtotime($request["date"])) ?><br>
                    <b>User:</b> <?php $adata = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/profiles/" . $request["author"] . ".json")), true); ?> <?= isset($adata["nick_name"]) && trim($adata["nick_name"]) !== "" ? $adata["nick_name"] : $adata["first_name"] . " " . $adata["last_name"] ?> (<?= $request["author"] ?>)<br>
                    <b>Target:</b> <?= isset($request["id"]) && trim($request["id"]) !== "" && $request["id"] !== $request["author"] ? getNameFromId($request["id"]) . " (" . $request["id"] . ")" : "<span class='text-muted'>Not applicable</span>" ?><br>
                    <b>Summary:</b> <?= isset($request["summary"]) && trim($request["summary"]) !== "" ? strip_tags($request["summary"]) : "<span class='text-muted'>Not applicable</span>" ?>
                </p>

                <details style="margin-bottom: 1rem;">
                    <summary>View full request object</summary>
                    <pre style="margin-bottom: 0;"><?= str_replace(">", "&gt;", str_replace("<", "&lt;", json_encode($request, JSON_PRETTY_PRINT))) ?></pre>
                </details>

                <?php if ($request["type"] === "galleryupload"): ?>
                <p><img src="/uploads/<?= $request["_id"] ?>.jpg" style="max-width: 30vw; max-height: 30vh;"></p>
                <?php elseif(isset($request["contents"]) && trim($request["contents"]) !== ""): ?>
                <iframe style="width: 100%; background: white;" src="data:text/html;base64,<?= base64_encode("<html><head><meta charset='utf-8'></head><body>" . $request["contents"] . "</body></html>") ?>"></iframe>
                <?php else: ?>
                <pre>[No contents provided]</pre>
                <?php endif; ?>

                <a class="btn btn-outline-success" href="/admin/approve/?id=<?= $request["_id"] ?>"><?php if ($request["type"] !== "article" && $request["type"] !== "gallerymeta" && $request["type"] !== "galleryupload" && $request["type"] !== "userpage"): ?>Mark as approved<?php else: ?>Approve and merge<?php endif; ?></a><?php if (!($request["type"] !== "article" && $request["type"] !== "gallerymeta" && $request["type"] !== "galleryupload" && $request["type"] !== "userpage")): ?> <a href="/admin/approve/?id=<?= $request["_id"] ?>&mark" class="btn btn-outline-warning">Mark as approved</a><?php endif; ?> <a href="/admin/reject/?id=<?= $request["_id"] ?>" class="btn btn-outline-danger">Reject</a><br>
                <small class="text-muted">*Author will be notified of the decision taken<?php if ($request["type"] !== "article" && $request["type"] !== "gallerymeta" && $request["type"] !== "galleryupload" && $request["type"] !== "userpage"): ?> <span class="text-warning">*Manual changes required</span><?php endif; ?></small>
            </div>
        </details>
        <?php endforeach; ?>
    </div>

    <?php if (count($requests) === 0): ?>
    <div class="text-muted">There are no pending requests for now.</div>
    <?php endif; ?>

    <br><br>
</div>

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