diff options
| author | ilotterytea <iltsu@alright.party> | 2025-05-03 01:39:13 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-05-03 01:39:13 +0500 |
| commit | 64f0533dc1779e7cca5f2678f7ae560df8d922bb (patch) | |
| tree | be319637f1a6ae6839b3685d6348a528025a7248 /public/emotes | |
| parent | 0c25e3dd54225b126ad8e48e10f4fbde8ce26ec5 (diff) | |
feat: config sample and more config options
Diffstat (limited to 'public/emotes')
| -rw-r--r-- | public/emotes/index.php | 62 | ||||
| -rw-r--r-- | public/emotes/rate.php | 5 | ||||
| -rw-r--r-- | public/emotes/upload.php | 30 |
3 files changed, 54 insertions, 43 deletions
diff --git a/public/emotes/index.php b/public/emotes/index.php index 2102aba..3c165be 100644 --- a/public/emotes/index.php +++ b/public/emotes/index.php @@ -154,8 +154,8 @@ if (CLIENT_REQUIRES_JSON) { <head> <title><?php - echo empty($emotes) ? "Emote " . $emote->get_code() : "Emotes" - ?> - alright.party</title> + echo (empty($emotes) ? "Emote " . $emote->get_code() : "Emotes") . ' - ' . INSTANCE_NAME + ?></title> <link rel="stylesheet" href="/static/style.css"> </head> @@ -309,33 +309,34 @@ if (CLIENT_REQUIRES_JSON) { echo ' UTC">about ' . format_timestamp(time() - $emote->get_created_at()) . " ago</span>"; ?></td> </tr> - <tr> - <th>Rating</th> - <?php - if ($emote->get_rating()["total"] < 10) { - echo '<td>Not rated (' . $emote->get_rating()["total"] . ')</td>'; - } else { + <?php if (RATING_ENABLE): ?> + <tr> + <th>Rating</th> + <?php + if ($emote->get_rating()["total"] < 10) { + echo '<td>Not rated (' . $emote->get_rating()["total"] . ')</td>'; + } else { - $rating = $emote->get_rating()["average"]; + $rating = $emote->get_rating()["average"]; - // TODO: make it customizable - list($rating_classname, $rating_name) = match (true) { - in_range($rating, 0.75, 1.0) => [ - "gemerald", - "<img src='/static/img/icons/ratings/1.png'> + // TODO: make it customizable + list($rating_classname, $rating_name) = match (true) { + in_range($rating, 0.75, 1.0) => [ + "gemerald", + "<img src='/static/img/icons/ratings/1.png'> <img src='/static/img/icons/ratings/1.png'> <img src='/static/img/icons/ratings/1.png'> Shiny Gemerald! <img src='/static/img/icons/ratings/1.png'> <img src='/static/img/icons/ratings/1.png'> <img src='/static/img/icons/ratings/1.png'> " - ], - in_range($rating, 0.25, 0.75) => ["gem", "<img src='/static/img/icons/ratings/1.png'> Gem <img src='/static/img/icons/ratings/1.png'>"], - in_range($rating, -0.25, 0.25) => ["iron", "Iron"], - in_range($rating, -0.75, -0.25) => ["coal", "<img src='/static/img/icons/ratings/-1.png'> Coal <img src='/static/img/icons/ratings/-1.png'>"], - in_range($rating, -1.0, -0.75) => [ - "brimstone", - " + ], + in_range($rating, 0.25, 0.75) => ["gem", "<img src='/static/img/icons/ratings/1.png'> Gem <img src='/static/img/icons/ratings/1.png'>"], + in_range($rating, -0.25, 0.25) => ["iron", "Iron"], + in_range($rating, -0.75, -0.25) => ["coal", "<img src='/static/img/icons/ratings/-1.png'> Coal <img src='/static/img/icons/ratings/-1.png'>"], + in_range($rating, -1.0, -0.75) => [ + "brimstone", + " <img src='/static/img/icons/ratings/brimstone.webp'> <img src='/static/img/icons/ratings/-1.png'> <img src='/static/img/icons/ratings/brimstone.webp'> @@ -344,16 +345,17 @@ if (CLIENT_REQUIRES_JSON) { <img src='/static/img/icons/ratings/-1.png'> <img src='/static/img/icons/ratings/brimstone.webp'> " - ] - }; + ] + }; - echo '<td>'; - echo "<span class=\"rating $rating_classname\">$rating_name</span>"; - echo ' (' . $emote->get_rating()["total"] . ')'; - echo '</td>'; - } - ?> - </tr> + echo '<td>'; + echo "<span class=\"rating $rating_classname\">$rating_name</span>"; + echo ' (' . $emote->get_rating()["total"] . ')'; + echo '</td>'; + } + ?> + </tr> + <?php endif; ?> <tr> <th>Visibility</th> <td><?php diff --git a/public/emotes/rate.php b/public/emotes/rate.php index bf26bcd..2f63d7c 100644 --- a/public/emotes/rate.php +++ b/public/emotes/rate.php @@ -4,6 +4,11 @@ include_once "../../src/utils.php"; include_once "../../src/config.php"; include_once "../../src/accounts.php"; +if (!RATING_ENABLE) { + generate_alert("/404.php", "Emote ratings are disabled", 403); + exit; +} + if (!authorize_user(true)) { exit; } diff --git a/public/emotes/upload.php b/public/emotes/upload.php index 50a8d15..fc8de71 100644 --- a/public/emotes/upload.php +++ b/public/emotes/upload.php @@ -3,6 +3,11 @@ include "../../src/accounts.php"; include_once "../../src/config.php"; include_once "../../src/alert.php"; +if (!EMOTE_UPLOAD) { + generate_alert("/404.php", "Emote upload is disabled", 403); + exit; +} + authorize_user(); if (!ANONYMOUS_UPLOAD && isset($_SESSION["user_role"]) && !$_SESSION["user_role"]["permission_upload"]) { @@ -33,9 +38,8 @@ function abort_upload(string $path, PDO $db, string $id, string $response_text, include "../../src/utils.php"; include "../../src/images.php"; -// TODO: make it configurable later -$max_width = max(128, 1); -$max_height = max(128, 1); +$max_width = EMOTE_MAX_SIZE[0]; +$max_height = EMOTE_MAX_SIZE[1]; if ($_SERVER['REQUEST_METHOD'] != "POST") { include "../../src/partials.php"; @@ -44,7 +48,7 @@ if ($_SERVER['REQUEST_METHOD'] != "POST") { <html> <head> - <title>Upload an emote at alright.party</title> + <title>Upload an emote - <?php echo INSTANCE_NAME ?></title> <link rel="stylesheet" href="/static/style.css"> </head> @@ -58,14 +62,14 @@ if ($_SERVER['REQUEST_METHOD'] != "POST") { <div class="box navtab"> <div> <b>Upload a new emote</b> - <p style="font-size:8px;">Btw, you can upload anything. Anything you want.</p> + <p style="font-size:8px;">You can just upload, btw. Anything you want.</p> </div> </div> <div class="box content"> <form action="/emotes/upload.php" method="POST" enctype="multipart/form-data"> <h3>Emote name</h3> <input type="text" name="code" id="code" required> - <h3>Image </h3> + <h3>Image</h3> <input type="file" name="file" id="file" accept=".gif,.jpg,.jpeg,.png,.webp" required> <div> @@ -123,8 +127,8 @@ if ($_SERVER['REQUEST_METHOD'] != "POST") { image.src = e.target.result; image.onload = () => { let m = 1; - let max_width = 128; - let max_height = 128; + let max_width = <?php echo EMOTE_MAX_SIZE[0] ?>; + let max_height = <?php echo EMOTE_MAX_SIZE[1] ?>; isImage = true; for (let i = 3; i > 0; i--) { @@ -153,9 +157,9 @@ if ($_SERVER['REQUEST_METHOD'] != "POST") { let validCode = ""; code.addEventListener("input", (e) => { - const regex = /^[a-zA-Z0-9]*$/; + const regex = <?php echo EMOTE_NAME_REGEX ?>; - if (regex.test(e.target.value) && e.target.value.length <= 100) { + if (regex.test(e.target.value) && e.target.value.length <= <?php echo EMOTE_NAME_MAX_LENGTH ?>) { validCode = e.target.value; } else { e.target.value = validCode; @@ -196,9 +200,9 @@ if (!isset($_FILES["file"])) { exit; } -$code = str_safe($_POST["code"] ?? "", 500); +$code = str_safe($_POST["code"] ?? "", EMOTE_NAME_MAX_LENGTH); -if ($code == "") { +if ($code == "" || !preg_match(EMOTE_NAME_REGEX, $code)) { http_response_code(400); echo json_encode([ "status_code" => 400, @@ -273,7 +277,7 @@ if ($resized_image) { $db = null; -if (isset($_SERVER["HTTP_ACCEPT"]) && $_SERVER["HTTP_ACCEPT"] == "application/json") { +if (CLIENT_REQUIRES_JSON) { http_response_code(201); echo json_encode([ "status_code" => 201, |
