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 | |
| parent | 6e27fb9de11843b7bb605fe85cb628b6e4882787 (diff) | |
feat: emote visibility
| -rw-r--r-- | database.sql | 3 | ||||
| -rw-r--r-- | public/emotes/index.php | 38 | ||||
| -rw-r--r-- | public/emotes/upload.php | 34 | ||||
| -rw-r--r-- | src/emote.php | 9 |
4 files changed, 62 insertions, 22 deletions
diff --git a/database.sql b/database.sql index bc352de..a2df999 100644 --- a/database.sql +++ b/database.sql @@ -22,7 +22,8 @@ CREATE TABLE IF NOT EXISTS emotes ( mime TEXT NOT NULL, ext TEXT NOT NULL, uploaded_by INTEGER REFERENCES users(id), - created_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP + created_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP, + visibility INTEGER NOT NULL ); CREATE TABLE IF NOT EXISTS emote_sets ( 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(); diff --git a/src/emote.php b/src/emote.php index b10fbeb..63d5746 100644 --- a/src/emote.php +++ b/src/emote.php @@ -8,8 +8,9 @@ class Emote public int $created_at; public mixed $rating; public bool $is_in_user_set; + public int $visibility; - function __construct($id, $code, $ext, $created_at, $uploaded_by, $is_in_user_set, $rating) + function __construct($id, $code, $ext, $created_at, $uploaded_by, $is_in_user_set, $rating, $visibility) { $this->id = $id; $this->code = $code; @@ -18,6 +19,7 @@ class Emote $this->uploaded_by = $uploaded_by; $this->is_in_user_set = $is_in_user_set; $this->rating = $rating; + $this->visibility = $visibility; } function get_id() @@ -54,4 +56,9 @@ class Emote { return $this->rating; } + + function get_visibility() + { + return $this->visibility; + } } |
