diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-30 00:49:05 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-30 00:49:05 +0500 |
| commit | 8c148952a95ee756038bc0e7afbf52f63249227f (patch) | |
| tree | c1dd07ee6c7fbd40437a9c754831968ada6004e8 /public/emotes | |
| parent | 6e27fb9de11843b7bb605fe85cb628b6e4882787 (diff) | |
feat: emote visibility
Diffstat (limited to 'public/emotes')
| -rw-r--r-- | public/emotes/index.php | 38 | ||||
| -rw-r--r-- | public/emotes/upload.php | 34 |
2 files changed, 52 insertions, 20 deletions
diff --git a/public/emotes/index.php b/public/emotes/index.php index b6308a5..dc406f5 100644 --- a/public/emotes/index.php +++ b/public/emotes/index.php @@ -31,7 +31,7 @@ function display_list_emotes(PDO &$db, string $search, string $sort_by, int $pag ) THEN 1 ELSE 0 END AS is_in_user_set, COALESCE(COUNT(r.rate), 0) AS rating FROM emotes e LEFT JOIN ratings AS r ON r.emote_id = e.id - WHERE e.code LIKE ? + WHERE e.code LIKE ? AND e.visibility = 1 GROUP BY e.id, e.code, e.created_at ORDER BY $sort @@ -65,7 +65,8 @@ function display_list_emotes(PDO &$db, string $search, string $sort_by, int $pag intval(strtotime($row["created_at"])), $uploader, $row["is_in_user_set"], - $row["rating"] + $row["rating"], + $row["visibility"] )); } @@ -84,15 +85,18 @@ function display_emote(PDO &$db, int $id) $emote = null; if ($row = $stmt->fetch()) { - $emote = new Emote( - $row["id"], - $row["code"], - $row["ext"], - intval(strtotime($row["created_at"])), - $row["uploaded_by"], - false, - ["total" => $row["total_rating"], "average" => $row["average_rating"]] - ); + if ($row["id"] != null) { + $emote = new Emote( + $row["id"], + $row["code"], + $row["ext"], + intval(strtotime($row["created_at"])), + $row["uploaded_by"], + false, + ["total" => $row["total_rating"], "average" => $row["average_rating"]], + $row["visibility"] + ); + } } if ($emote == null) { @@ -128,7 +132,7 @@ $sort_by = $_GET["sort_by"] ?? ""; if ($id == "" || !is_numeric($id)) { $emotes = display_list_emotes($db, $search, $sort_by, $page, $limit); - $stmt = $db->prepare("SELECT COUNT(*) FROM emotes WHERE code LIKE ?"); + $stmt = $db->prepare("SELECT COUNT(*) FROM emotes WHERE code LIKE ? AND visibility = 1"); $stmt->execute([$search]); $total_emotes = $stmt->fetch()[0]; $total_pages = ceil($total_emotes / $limit); @@ -329,6 +333,16 @@ if (CLIENT_REQUIRES_JSON) { } ?> </tr> + <tr> + <th>Visibility</th> + <td><?php + if ($emote->get_visibility() == 1) { + echo 'Public'; + } else { + echo 'Unlisted'; + } + ?></td> + </tr> </table> </section> diff --git a/public/emotes/upload.php b/public/emotes/upload.php index 4e90632..5563323 100644 --- a/public/emotes/upload.php +++ b/public/emotes/upload.php @@ -70,16 +70,15 @@ if ($_SERVER['REQUEST_METHOD'] != "POST") { <div> <label for="visibility">Emote visibility: </label> - <select name="visibility"> - <option value="0">Public</option> - <option value="1">Unlisted</option> - <option value="0">Private</option> + <select name="visibility" id="form-visibility"> + <option value="1">Public</option> + <option value="0">Unlisted</option> </select><br> - <label for="visibility">Do you accept <a href="/rules">the rules</a>?</label> + <p id="form-visibility-description" style="font-size: 10px;">test</p> + <label for="tos">Do you accept <a href="/rules">the rules</a>?</label> <input type="checkbox" name="tos" required> </div> - <button type="submit" id="upload-button">Upload as <?php echo $uploader_name ?></button> </form> @@ -162,6 +161,23 @@ if ($_SERVER['REQUEST_METHOD'] != "POST") { e.target.value = validCode; } }); + + const visibility = document.getElementById("form-visibility"); + visibility.addEventListener("change", (e) => { + set_form_visibility_description(visibility.value); + }); + + function set_form_visibility_description(visibility) { + const p = document.getElementById("form-visibility-description"); + + if (visibility == 1) { + p.innerHTML = "Emote won't appear on the public list until it passes a moderator's review. It still can be added to chats."; + } else { + p.innerHTML = "Emote doesn't appear on the public list and won't be subject to moderation checks. It still can be added to chats."; + } + } + + set_form_visibility_description(visibility.value); </script> </html> @@ -204,11 +220,13 @@ if (is_null(list($mime, $ext) = get_mime_and_ext($image["tmp_name"]))) { exit; } +$visibility = intval($_GET["visibility"], "0"); + // creating a new emote record $db = new PDO(DB_URL, DB_USER, DB_PASS); -$stmt = $db->prepare("INSERT INTO emotes(code, mime, ext, uploaded_by) VALUES (?, ?, ?, ?)"); -$stmt->execute([$code, $mime, $ext, $uploaded_by]); +$stmt = $db->prepare("INSERT INTO emotes(code, mime, ext, uploaded_by, visibility) VALUES (?, ?, ?, ?, ?)"); +$stmt->execute([$code, $mime, $ext, $uploaded_by, $visibility]); $id = $db->lastInsertId(); |
