summaryrefslogtreecommitdiff
path: root/public/system/emotes/index.php
blob: c80641c016b6a4e5a6813a00a248564344569d1d (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
<?php
include_once "../../../src/partials.php";
include_once "../../../src/accounts.php";
include_once "../../../src/alert.php";
include_once "../../../src/config.php";
include_once "../../../src/utils.php";

if (!MOD_EMOTES_APPROVE) {
    generate_alert("/404.php", "Manual emote approval is disabled", 405);
    exit;
}

if (!authorize_user(true) || !$_SESSION["user_role"]["permission_approve_emotes"]) {
    generate_alert("/404.php", "Not enough permissions", 403);
    exit;
}

$current_user_id = $_SESSION["user_id"] ?? "";

$db = new PDO(DB_URL, DB_USER, DB_PASS);
$emote_results = $db->prepare("SELECT e.*,
CASE WHEN up.private_profile = FALSE OR up.id = ? THEN e.uploaded_by ELSE NULL END AS uploaded_by,
CASE WHEN up.private_profile = FALSE OR up.id = ? THEN u.username ELSE NULL END AS uploader_name
FROM emotes e
LEFT JOIN users u ON u.id = e.uploaded_by
LEFT JOIN user_preferences up ON up.id = u.id
WHERE e.visibility = 2
ORDER BY e.created_at DESC
LIMIT 25
");
$emote_results->execute([$current_user_id, $current_user_id]);

$emote_results = $emote_results->fetchAll(PDO::FETCH_ASSOC);

$emote = $emote_results[0] ?? null;

if (isset($_GET["id"])) {
    $stmt = $db->prepare("SELECT e.*,
        CASE WHEN up.private_profile = FALSE OR up.id = ? THEN e.uploaded_by ELSE NULL END AS uploaded_by,
        CASE WHEN up.private_profile = FALSE OR up.id = ? THEN u.username ELSE NULL END AS uploader_name
        FROM emotes e
        LEFT JOIN user_preferences up ON up.id = u.id
        LEFT JOIN users u ON u.id = e.uploaded_by
        WHERE e.visibility = 2 AND e.id = ?
        LIMIT 1");

    $stmt->execute([$current_user_id, $current_user_id, $_GET["id"]]);
    $emote = $stmt->fetch(PDO::FETCH_ASSOC) ?? null;
}

?>

<html>

<head>
    <title>System panel - <?php echo INSTANCE_NAME ?></title>
    <link rel="stylesheet" href="/static/style.css">
    <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
</head>

<body>
    <div class="container">
        <div class="wrapper">
            <?php html_navigation_bar() ?>
            <?php display_alert() ?>
            <section class="content row">
                <section class="box">
                    <div class="box navtab">System panel - Emote approval section</div>
                    <div class="box content">
                        <?php
                        foreach ($emote_results as $row) {
                            echo '<a href="/system/emotes?id=' . $row["id"] . '">';
                            echo '<img src="/static/userdata/emotes/' . $row["id"] . '/1x.webp">';
                            echo '<b>' . $row["code"] . '</b>';
                            echo '<span style="font-size:10px;"> by ';

                            if ($row["uploader_name"] == null) {
                                echo ANONYMOUS_DEFAULT_NAME . '*';
                            } else {
                                echo $row["uploader_name"];
                            }

                            echo '</span></a>';
                        }

                        if (empty($emote_results)) {
                            echo 'Everything is clear. Good job!';
                        }
                        ?>
                    </div>
                </section>
                <?php if ($emote != null): ?>
                    <section class="content">
                        <!-- Emote showcase -->
                        <section class="box">
                            <div class="box navtab">Emote - <?php echo $emote["code"] ?></div>
                            <div class="box content">
                                <div class="emote-showcase">
                                    <img src="/static/userdata/emotes/<?php echo $emote["id"] ?>/1x.webp"
                                        alt="<?php echo $emote["id"] ?>">
                                    <img src="/static/userdata/emotes/<?php echo $emote["id"] ?>/2x.webp"
                                        alt="<?php echo $emote["id"] ?>">
                                    <img src="/static/userdata/emotes/<?php echo $emote["id"] ?>/3x.webp"
                                        alt="<?php echo $emote["id"] ?>">
                                </div>
                            </div>
                        </section>
                        <!-- Emote actions -->
                        <section class="box items center row">
                            <form action="/system/emotes/manip.php" method="post">
                                <input type="text" name="id" value="<?php echo $emote["id"] ?>" style="display: none;">
                                <input type="text" name="action" value="approve" style="display: none;">
                                <button type="submit" class="green">Approve</button>
                            </form>
                            <form action="/system/emotes/manip.php" method="post">
                                <input type="text" name="id" value="<?php echo $emote["id"] ?>" style="display: none;">
                                <input type="text" name="action" value="reject" style="display: none;">
                                <button type="submit" class="red">Reject</button>
                            </form>
                        </section>
                        <!-- Emote information -->
                        <section class="box">
                            <table class="vertical">
                                <tr>
                                    <th>Uploader</th>
                                    <td><?php
                                    $username = ANONYMOUS_DEFAULT_NAME;
                                    $link = "#";

                                    if ($emote["uploader_name"] != null) {
                                        $username = $emote["uploader_name"];
                                        $link = '/users.php?id=' . $emote["uploaded_by"];
                                    }

                                    echo "<a href=\"$link\">";
                                    echo $username;
                                    echo "</a>";

                                    echo ', <span title="';
                                    echo date("M d, Y H:i:s", strtotime($emote["created_at"]));
                                    echo ' UTC">about ' . format_timestamp(time() - strtotime($emote["created_at"])) . " ago</span>";
                                    ?></td>
                                </tr>
                                <tr>
                                    <th>Notes</th>
                                    <td><?php echo isset($emote["notes"]) == true ? $emote["notes"] : '<i>Empty</i>' ?></td>
                                </tr>
                            </table>
                        </section>
                        <!-- Mod actions on emote -->
                        <section class="box">
                            <div class="box navtab">
                                Mod actions
                            </div>
                            <div class="box content">
                                <p>No one has done anything on this emote...</p>
                            </div>
                        </section>
                    </section>
                <?php endif; ?>
            </section>
        </div>
    </div>
</body>

</html>