From 57472eab3c7b035392c6a5aa240593ecaa7d1ccf Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Mon, 8 Dec 2025 21:53:36 +0500 Subject: upd: moved all /public/ files to the root folder --- public/emotes/delete.php | 47 ---- public/emotes/index.php | 546 -------------------------------------------- public/emotes/rate.php | 63 ------ public/emotes/setmanip.php | 138 ------------ public/emotes/upload.php | 552 --------------------------------------------- 5 files changed, 1346 deletions(-) delete mode 100644 public/emotes/delete.php delete mode 100644 public/emotes/index.php delete mode 100644 public/emotes/rate.php delete mode 100644 public/emotes/setmanip.php delete mode 100644 public/emotes/upload.php (limited to 'public/emotes') diff --git a/public/emotes/delete.php b/public/emotes/delete.php deleted file mode 100644 index 6252e45..0000000 --- a/public/emotes/delete.php +++ /dev/null @@ -1,47 +0,0 @@ -prepare("SELECT uploaded_by, code FROM emotes WHERE id = ?"); -$stmt->execute([$emote_id]); - -if ($row = $stmt->fetch()) { - if ($row["uploaded_by"] === $user_id) { - $unlink = intval($_POST["unlink"] ?? "0") == 1; - - if ($unlink) { - $stmt = $db->prepare("UPDATE emotes SET uploaded_by = NULL WHERE id = ? AND uploaded_by = ?"); - $stmt->execute([$emote_id, $user_id]); - generate_alert("/emotes/?id=$emote_id", 'Your authorship has been removed for the emote "' . $row["code"] . '"', 200); - } else { - $stmt = $db->prepare("DELETE FROM emotes WHERE id = ? AND uploaded_by = ?"); - $stmt->execute([$emote_id, $user_id]); - - $path = $_SERVER["DOCUMENT_ROOT"] . "/static/userdata/emotes/$emote_id"; - array_map("unlink", glob("$path/*.*")); - rmdir($path); - - generate_alert("/emotes", 'Emote "' . $row["code"] . '" has been removed from the servers', 200); - } - } else { - generate_alert("/emotes", "You don't own the emote \"" . $row["code"] . "\"", 403); - } -} else { - generate_alert("/emotes", "Emote ID $emote_id not found", 404); -} \ No newline at end of file diff --git a/public/emotes/index.php b/public/emotes/index.php deleted file mode 100644 index af14120..0000000 --- a/public/emotes/index.php +++ /dev/null @@ -1,546 +0,0 @@ -prepare("SELECT e.id, e.code, e.created_at, e.source, e.visibility, - COALESCE(COUNT(r.rate), 0) as total_rating, - COALESCE(ROUND(AVG(r.rate), 2), 0) AS average_rating, - CASE WHEN up.private_profile = FALSE OR up.id = ? THEN e.uploaded_by ELSE NULL END AS uploaded_by - FROM emotes e - LEFT JOIN user_preferences up ON up.id = e.uploaded_by - LEFT JOIN ratings AS r ON r.emote_id = e.id - WHERE e.id = ? - LIMIT 1 - "); - $stmt->execute([$user_id, $id]); - - $row = $stmt->fetch(); - - if ($row["id"]) { - // fetching emote tags - $stmt = $db->prepare("SELECT t.code FROM tags t - INNER JOIN tag_assigns ta ON ta.emote_id = ? - WHERE t.id = ta.tag_id - "); - $stmt->execute([$row["id"]]); - $tags = $stmt->fetchAll(PDO::FETCH_ASSOC); - $tags = array_column($tags, "code"); - - $row["tags"] = $tags; - $row["ext"] = "webp"; - $emote = Emote::from_array_with_user($row, $db); - } else { - generate_alert("/404.php", "Emote ID $id does not exists", 404); - exit; - } -} -// fetching all emotes -else { - $sort = $_GET["sort"] ?? "high_ratings"; - $sort = match ($sort) { - "low_ratings" => "rating ASC", - "recent" => "e.created_at DESC", - "oldest" => "e.created_at ASC", - default => "rating DESC" - }; - $page = max(1, intval($_GET["p"] ?? "1")); - $limit = 50; - $offset = ($page - 1) * $limit; - $search = $_GET["q"] ?? ""; - - // fetching emotes - $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 EXISTS ( - SELECT 1 - FROM emote_set_contents ec - INNER JOIN emote_sets es ON es.id = ec.emote_set_id - JOIN acquired_emote_sets aes ON aes.emote_set_id = es.id - WHERE ec.emote_id = e.id AND es.id = ? - ) THEN 1 ELSE 0 END AS is_in_user_set, COALESCE(COUNT(r.rate), 0) AS rating - FROM emotes e - LEFT JOIN user_preferences up ON up.id = e.uploaded_by - LEFT JOIN ratings AS r ON r.emote_id = e.id - LEFT JOIN tag_assigns ta ON ta.emote_id = e.id - LEFT JOIN tags t ON t.id = ta.tag_id - WHERE (t.code = ? OR e.code LIKE ?) AND e.visibility = 1 - GROUP BY - e.id, e.code, e.created_at - ORDER BY $sort - LIMIT ? OFFSET ? - "); - - $sql_search = "%$search%"; - $user_emote_set_id = $_SESSION["user_active_emote_set_id"] ?? ""; - - $stmt->bindParam(1, $user_id, PDO::PARAM_STR); - $stmt->bindParam(2, $user_emote_set_id, PDO::PARAM_STR); - $stmt->bindParam(3, $search, PDO::PARAM_STR); - $stmt->bindParam(4, $sql_search, PDO::PARAM_STR); - $stmt->bindParam(5, $limit, PDO::PARAM_INT); - $stmt->bindParam(6, $offset, PDO::PARAM_INT); - - $stmt->execute(); - - $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); - $emotes = []; - - foreach ($rows as $row) { - array_push($emotes, Emote::from_array_with_user($row, $db)); - } - - $total_emotes = count($emotes); - $total_pages = ceil($total_emotes / $limit); -} - -if (CLIENT_REQUIRES_JSON) { - json_response([ - "status_code" => 200, - "message" => null, - "data" => $emotes ?? $emote - ]); - exit; -} -?> - - - - - <?php - echo ($emote != null ? "Emote " . $emote->get_code() : "Emotes") . ' - ' . INSTANCE_NAME - ?> - - - - - -
-
- - -
- -
- -
- - -
-
- '; - - echo ''; - - $path = $_SERVER["DOCUMENT_ROOT"] . '/static/userdata/emotes/' . $emote->get_id() . "/{$size}x.webp"; - - echo '
'; - - if ($file_size = filesize($path)) { - $kb = sprintf("%.2f", $file_size / 1024); - echo "

{$kb}KB

"; - } - - if ($image_size = getimagesize($path)) { - echo "

$image_size[0]x$image_size[1]

"; - } - - echo '
'; - } - ?> -
-
- -
- -
- prepare("SELECT id, code FROM emote_set_contents WHERE emote_set_id = ? AND emote_id = ?"); - $stmt->execute([$_SESSION["user_active_emote_set_id"], $emote->get_id()]); - - $added = false; - - if ($row = $stmt->fetch()) { - $added = true; - $emote_current_name = $row["code"] ?? $emote->get_code(); - } - } - - if (isset($_SESSION["user_role"]) && $_SESSION["user_role"]["permission_emoteset_own"]) { - echo '' ?> -
- - " style="display: none;"> - - - -
-
- - " style="display: none;"> - - - - - - - -
- - - get_uploaded_by() === $_SESSION["user_id"]): ?> -
- - -
-
- - - -
- -
-
- prepare("SELECT rate FROM ratings WHERE user_id = ? AND emote_id = ?"); - $stmt->execute([$_SESSION["user_id"], $id]); - - if ($row = $stmt->fetch()) { - echo 'You gave '; - } else { - foreach (RATING_NAMES as $key => $value) { - echo '
'; - echo ''; - echo ""; - echo '
'; - } - } - } - if (REPORTS_ENABLE && $_SESSION["user_role"]["permission_report"]) { - echo "Report emote"; - } - } - ?> -
- -

Log in to get additional features...

- -
- -
- - get_tags())): ?> - - - - - - - - - - prepare("SELECT u.id, a.created_at FROM users u - INNER JOIN mod_actions a ON a.emote_id = ? - WHERE u.id = a.user_id"); - $stmt->execute([$emote->get_id()]); - - if ($row = $stmt->fetch()) { - $approver = User::get_user_by_id($db, $row["id"]); - - echo ''; - } - - if (RATING_ENABLE): ?> - - - get_rating()["total"] < RATING_EMOTE_MIN_VOTES) { - echo ''; - } else { - - $rating = $emote->get_rating()["average"]; - - // TODO: make it customizable - list($rating_classname, $rating_name) = match (true) { - in_range($rating, 0.75, 1.0) => [ - "gemerald", - " - - Shiny Gemerald! - - - - " - ], - in_range($rating, 0.25, 0.75) => ["gem", " Gem "], - in_range($rating, -0.25, 0.25) => ["iron", "Iron"], - in_range($rating, -0.75, -0.25) => ["coal", " Coal "], - in_range($rating, -1.0, -0.75) => [ - "brimstone", - " - - - - !!!AVOID THIS CANCER-GIVING BRIMSTONE!!! - - - - " - ] - }; - - echo ''; - } - ?> - - - - - - - get_source()): ?> - - - - - -
Tags - get_tags() as $tag) { - echo "$tag "; - } - ?> -
Uploaderget_uploaded_by()) { - $u = $emote->get_uploaded_by(); - $show_private_badge = $u->private_profile; - - $username = $u->username; - $link = "/users.php?id={$u->id}"; - $badge = $u->role; - $custom_badge = $u->custom_badge; - } - - echo ""; - echo $username; - echo ""; - - if ($show_private_badge) { - echo " (Private)"; - } - - if ($badge && $badge->badge) { - echo " ## {$badge->name}"; - } - - if ($custom_badge) { - echo " "; - } - - echo ', get_created_at()); - echo ' UTC">about ' . format_timestamp(time() - $emote->get_created_at()) . " ago"; - ?>
Approver'; - echo "{$approver->username}"; - - if ($approver->role && $approver->role->badge) { - echo " ## {$approver->role->name}"; - } - - if ($approver->custom_badge) { - echo " "; - } - - echo ', '; - echo format_timestamp(strtotime($row["created_at"]) - $emote->get_created_at()) . ' after upload'; - echo '
RatingNot rated (' . $emote->get_rating()["total"] . ')'; - echo "$rating_name"; - echo ' (' . $emote->get_rating()["total"] . ')'; - echo '
Visibilityget_visibility()) { - case 0: - echo 'Unlisted'; - break; - case 1: - echo 'Public'; - break; - case 2: - echo 'Pending approval (unlisted for a moment)'; - break; - default: - echo 'N/A'; - break; - } - ?>
Source - get_source() ?> -
-
- -
-
- prepare("SELECT users.id, users.username - FROM users - INNER JOIN emote_sets AS es ON es.owner_id = users.id - INNER JOIN emote_set_contents AS ec ON ec.emote_set_id = es.id - INNER JOIN acquired_emote_sets AS aes ON aes.emote_set_id = es.id - WHERE ec.emote_id = ? AND aes.is_default = TRUE"); - - $stmt->execute([$emote->get_id()]); - $count = $stmt->rowCount(); - - $db = null; - - if ($count > 0) { - echo "

Added in $count channels

"; - } else { - echo "No one has added this emote yet... :'("; - } - ?> -
- fetch()) { - echo '' . $row["username"] . ''; - } - ?> -
-
- -
- -
- 1) { - echo '' ?> -
-
- -
- - -
- - - - \ No newline at end of file diff --git a/public/emotes/rate.php b/public/emotes/rate.php deleted file mode 100644 index 1e8eb67..0000000 --- a/public/emotes/rate.php +++ /dev/null @@ -1,63 +0,0 @@ -prepare("SELECT id FROM emotes WHERE id = ?"); -$stmt->execute([$id]); -if ($stmt->rowCount() != 1) { - generate_alert("/emotes", "Emote ID $id does not exist", 404); - exit; -} - -// checking if user has already given a rate -$stmt = $db->prepare("SELECT id FROM ratings WHERE user_id = ? AND emote_id = ?"); -$stmt->execute([$_SESSION["user_id"], $id]); -if ($stmt->rowCount() != 0) { - generate_alert("/emotes?id=$id", "You have already given a rate for this emote!", 403); - exit; -} - -// giving a rate -$stmt = $db->prepare("INSERT INTO ratings(user_id, emote_id, rate) VALUES (?, ?, ?)"); -$stmt->execute([$_SESSION["user_id"], $id, clamp($rate, -2, 2)]); - -if (CLIENT_REQUIRES_JSON) { - $stmt = $db->prepare("SELECT * FROM ratings WHERE id = ?"); - $stmt->execute([$db->lastInsertId()]); - - json_response([ - "status_code" => 200, - "message" => "Rated!", - "data" => $stmt->fetch(PDO::FETCH_ASSOC) - ]); - exit; -} - -generate_alert("/emotes?id=$id", "Rated!", 200); diff --git a/public/emotes/setmanip.php b/public/emotes/setmanip.php deleted file mode 100644 index 129790d..0000000 --- a/public/emotes/setmanip.php +++ /dev/null @@ -1,138 +0,0 @@ -prepare("SELECT id, code, uploaded_by, visibility, created_at FROM emotes WHERE id = ?"); -$stmt->execute([$emote_id]); -if ($stmt->rowCount() == 0) { - generate_alert("/emotes", "Emote not found", 404); - exit; -} -$emote = $stmt->fetch(PDO::FETCH_ASSOC); - -$user_id = $_SESSION["user_id"]; -$emote_set_id = $_POST["emote_set_id"]; - -// checking emote set -$stmt = $db->prepare("SELECT id FROM acquired_emote_sets WHERE emote_set_id = ? AND user_id = ?"); -$stmt->execute([$emote_set_id, $user_id]); - -if ($stmt->rowCount() == 0) { - generate_alert("/404.php", "You don't own emote set ID $emote_set_id", 403); - exit; -} - -// inserting emote -$stmt = $db->prepare("SELECT id FROM emote_set_contents WHERE emote_set_id = ? AND emote_id = ?"); -$stmt->execute([$emote_set_id, $emote_id]); - -$action = $_POST["action"]; -$payload = [ - "emote" => $emote, - "emoteset" => $_SESSION["user_active_emote_set"] -]; - -switch ($action) { - case "add": { - if ($stmt->rowCount() != 0) { - generate_alert("/emotes?id=$emote_id", "This emote has been already added!"); - exit; - } - - $stmt = $db->prepare("INSERT INTO emote_set_contents(emote_set_id, emote_id, added_by) VALUES (?, ?, ?)"); - $stmt->execute([$emote_set_id, $emote_id, $user_id]); - - if (ACCOUNT_LOG_ACTIONS) { - $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)") - ->execute([$user_id, "EMOTESET_ADD", json_encode($payload)]); - } - - $db = null; - - generate_alert("/emotes?id=$emote_id", "This emote has been added to your set. Enjoy!", 200); - break; - } - case "remove": { - if ($row = $stmt->fetch()) { - $stmt = $db->prepare("DELETE FROM emote_set_contents WHERE id = ?"); - $stmt->execute([$row["id"]]); - } else { - generate_alert("/emotes?id=$emote_id", "This emote wasn't added!"); - $db = null; - exit; - } - - if (ACCOUNT_LOG_ACTIONS) { - $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)") - ->execute([$user_id, "EMOTESET_REMOVE", json_encode($payload)]); - } - - $db = null; - - generate_alert("/emotes?id=$emote_id", "This emote has been removed from your set.", 200); - break; - } - case "alias": { - if (!isset($_POST["value"])) { - generate_alert("/emotes?id=$emote_id", "No value field"); - exit; - } - - $value = str_safe($_POST["value"], EMOTE_NAME_MAX_LENGTH); - - $stmt = $db->prepare("SELECT esc.code AS alias_code, e.code FROM emote_set_contents esc - INNER JOIN emotes e ON e.id = esc.emote_id - WHERE esc.emote_set_id = ? AND esc.emote_id = ?"); - $stmt->execute([$emote_set_id, $emote_id]); - - if (empty($value)) { - $value = null; - - if ($row = $stmt->fetch()) { - $payload["emote"]["original_code"] = $row["alias_code"]; - $payload["emote"]["code"] = $row["code"]; - } - } else { - $row = $stmt->fetch(); - $payload["emote"]["original_code"] = $row["alias_code"] ?? $row["code"]; - $payload["emote"]["code"] = $value; - } - - $stmt = $db->prepare("UPDATE emote_set_contents SET code = ? WHERE emote_set_id = ? AND emote_id = ?"); - $stmt->execute([$value, $emote_set_id, $emote_id]); - - if (ACCOUNT_LOG_ACTIONS) { - $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)") - ->execute([$user_id, "EMOTESET_ALIAS", json_encode($payload)]); - } - - $db = null; - - generate_alert("/emotes?id=$emote_id", "Updated emote name!", 200); - break; - } - default: { - generate_alert("/emotes?id=$emote_id", "Unknown action"); - break; - } -} \ No newline at end of file diff --git a/public/emotes/upload.php b/public/emotes/upload.php deleted file mode 100644 index 644e4b6..0000000 --- a/public/emotes/upload.php +++ /dev/null @@ -1,552 +0,0 @@ -prepare("DELETE FROM emotes WHERE id = ?"); - $stmt->execute([$id]); - $db = null; - - array_map("unlink", glob("$path/*.*")); - rmdir($path); -} - -include "../../src/utils.php"; -include "../../src/images.php"; - -$max_width = EMOTE_MAX_SIZE[0]; -$max_height = EMOTE_MAX_SIZE[1]; - -if ($_SERVER['REQUEST_METHOD'] != "POST") { - include "../../src/partials.php"; - - echo '' ?> - - - - Upload an emote - <?php echo INSTANCE_NAME ?> - - - - - -
-
- - - -
-
-
- -
-
-

Image*

- - - - - -
- - -
- -

Emote name*

- - -
- -
-

test

-
- - - - - - - - - - - - - - - -
Emote source: -
Tags [?]: -
- -
- - -
- - -
-
-
- - -
- - -
-
-
- - - - - - - prepare("INSERT INTO emotes(id, code, notes, source, uploaded_by, visibility) VALUES (?, ?, ?, ?, ?, ?)"); -$stmt->execute([$id, $code, $notes, $source, $uploaded_by, $visibility]); - -$path = "../static/userdata/emotes/$id"; - -if (!is_dir($path)) { - mkdir($path, 0777, true); -} - -if ($is_manual) { - $image_1x = $_FILES["file-1x"]; - $image_2x = $_FILES["file-2x"]; - $image_3x = $_FILES["file-3x"]; - - $file_1x = does_file_meet_requirements($image_1x["tmp_name"], $max_width / 4, $max_height / 4); - $file_2x = does_file_meet_requirements($image_2x["tmp_name"], $max_width / 2, $max_height / 2); - $file_3x = does_file_meet_requirements($image_3x["tmp_name"], $max_width, $max_height); - - if (!$file_1x[0] || !$file_2x[0] || !$file_3x[0]) { - generate_alert("/emotes/upload.php", "Files don't meet requirements"); - abort_upload($path, $db, $id); - exit; - } - - if ( - !move_uploaded_file($image_1x["tmp_name"], "$path/1x.$file_1x[1]") || - !move_uploaded_file($image_2x["tmp_name"], "$path/2x.$file_2x[1]") || - !move_uploaded_file($image_3x["tmp_name"], "$path/3x.$file_3x[1]") - ) { - generate_alert("/emotes/upload.php", "Failed to move the uploaded files"); - abort_upload($path, $db, $id); - exit; - } -} else { - $image = $_FILES["file"]; - // resizing the image - if ($err = create_image_bundle($image["tmp_name"], $path, $max_width, $max_height)) { - generate_alert("/emotes/upload.php", "Error occurred while processing images ($err)", 500); - abort_upload($path, $db, $id); - exit; - } - - if (EMOTE_STORE_ORIGINAL) { - $ext = get_file_extension($image["tmp_name"]) ?? ""; - move_uploaded_file($image["tmp_name"], "$path/original.$ext"); - } -} - -$tags = str_safe($_POST["tags"] ?? "", null); -$tags_processed = []; - -if (!empty($tags) && TAGS_ENABLE) { - $tags = explode(" ", $tags); - - $count = 0; - - foreach ($tags as $tag) { - if (TAGS_MAX_COUNT > 0 && $count >= TAGS_MAX_COUNT) { - break; - } - - if (!preg_match(TAGS_CODE_REGEX, $tag)) { - continue; - } - - $tag_id = null; - - $stmt = $db->prepare("SELECT id FROM tags WHERE code = ?"); - $stmt->execute([$tag]); - - if ($row = $stmt->fetch()) { - $tag_id = $row["id"]; - } else { - $tag_id = bin2hex(random_bytes(16)); - $db->prepare("INSERT INTO tags(id, code) VALUES (?, ?)")->execute([$tag_id, $tag]); - } - - $db->prepare("INSERT INTO tag_assigns(tag_id, emote_id) VALUES (?, ?)")->execute([$tag_id, $id]); - - $count++; - array_push($tags_processed, $tag); - } -} - -$emote_data = [ - "id" => $id, - "code" => $code, - "visibility" => $visibility, - "uploaded_by" => match ($uploaded_by == null) { - true => null, - false => [ - "id" => $uploaded_by, - "username" => $uploader_name - ] - }, - "notes" => $notes, - "source" => $source, - "tags" => $tags_processed -]; - -if (ACCOUNT_LOG_ACTIONS && $uploaded_by != null) { - $db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)") - ->execute([ - $uploaded_by, - "EMOTE_CREATE", - json_encode([ - "emote" => $emote_data - ]) - ]); -} - - -$db = null; - -if (CLIENT_REQUIRES_JSON) { - json_response([ - "status_code" => 201, - "message" => null, - "data" => $emote_data - ], 201); - exit; -} - -header("Location: /emotes?id=$id", true, 307); \ No newline at end of file -- cgit v1.2.3