From 8925a9526a1d3eac914030b3069713f56c37e55a Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 9 Dec 2025 16:50:07 +0500 Subject: feat: emoteset editors --- emotesets.php | 164 -------------------------------------- emotesets/addeditor.php | 54 +++++++++++++ emotesets/deleditor.php | 59 ++++++++++++++ emotesets/index.php | 206 ++++++++++++++++++++++++++++++++++++++++++++++++ index.php | 2 +- lib/emote.php | 13 ++- lib/partials.php | 2 +- users.php | 2 +- 8 files changed, 333 insertions(+), 169 deletions(-) delete mode 100644 emotesets.php create mode 100644 emotesets/addeditor.php create mode 100644 emotesets/deleditor.php create mode 100644 emotesets/index.php diff --git a/emotesets.php b/emotesets.php deleted file mode 100644 index 35675ce..0000000 --- a/emotesets.php +++ /dev/null @@ -1,164 +0,0 @@ -query("SELECT * FROM emote_sets WHERE is_global = TRUE LIMIT 1", PDO::FETCH_ASSOC); - - if ($rows->rowCount()) { - $emote_set = $rows->fetch(); - } else { - generate_alert("/404.php", "Global emoteset is not found", 404); - exit; - } -} -// featured emoteset -else if ($id == "featured") { - $rows = $db->query("SELECT * FROM emote_sets WHERE is_featured = TRUE LIMIT 1", PDO::FETCH_ASSOC); - - if ($rows->rowCount()) { - $emote_set = $rows->fetch(); - } else { - generate_alert("/404.php", "Featured emoteset is not found", 404); - exit; - } -} -// connected emoteset -else if (isset($_GET["alias_id"])) { - $alias_id = $_GET["alias_id"]; - $platform = $_GET["platform"] ?? "twitch"; - - $stmt = $db->prepare("SELECT es.* FROM emote_sets es - INNER JOIN connections co ON co.alias_id = ? AND co.platform = ? - INNER JOIN acquired_emote_sets aes ON aes.user_id = co.user_id - WHERE aes.is_default = TRUE - "); - $stmt->execute([$alias_id, $platform]); - - if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { - $emote_set = $row; - } else { - generate_alert("/404.php", "Emoteset is not found for alias ID $alias_id ($platform)", 404); - exit; - } -} -// specified emoteset -else if (!empty($id)) { - $stmt = $db->prepare("SELECT es.* FROM emote_sets es WHERE es.id = ?"); - $stmt->execute([$id]); - - if ($row = $stmt->fetch()) { - $emote_set = $row; - } else { - generate_alert("/404.php", "Emoteset ID $id is not found", 404); - exit; - } -} - -$user_id = $_SESSION["user_id"] ?? ""; -$emote_sets = null; - -// fetching emotes -if ($emote_set) { - $emote_set = Emoteset::from_array_extended($emote_set, $user_id, $db); -} elseif (!CONFIG['emoteset']['public']) { - generate_alert("/404.php", "The public list of emotesets is disabled", 403); - exit; -} else { - $emote_sets = []; - foreach ($db->query("SELECT * FROM emote_sets", PDO::FETCH_ASSOC) as $row) { - array_push($emote_sets, Emoteset::from_array_extended($row, $user_id, $db)); - } -} - -if (CLIENT_REQUIRES_JSON) { - if ($emote_sets != null) { - json_response([ - "status_code" => 200, - "message" => null, - "data" => $emote_sets - ]); - exit; - } else if ($emote_set != null) { - json_response([ - "status_code" => 200, - "message" => null, - "data" => $emote_set - ]); - exit; - } else { - json_response([ - "status_code" => 404, - "message" => "Emoteset(s) not found", - "data" => null - ], 404); - exit; - } -} -?> - - - - - <?php - $title = match ($emote_set == null) { - true => count($emote_sets) . ' emotesets', - false => "Emoteset - {$emote_set->name}", - }; - - echo "$title - " . CONFIG['instance']['name']; - ?> - - - - - - -
-
- -
-
-
- -
- emotes); - } else { - echo 'Nothing found...'; - } - ?> -
-
-
-
-
- - - \ No newline at end of file diff --git a/emotesets/addeditor.php b/emotesets/addeditor.php new file mode 100644 index 0000000..08d1e41 --- /dev/null +++ b/emotesets/addeditor.php @@ -0,0 +1,54 @@ +prepare("SELECT id FROM emote_sets WHERE id = ? AND owner_id = ?"); +$stmt->execute([$emote_set_id, $_SESSION['user_id']]); +if ($stmt->rowCount() == 0) { + generate_alert("/emotes", "Emoteset not found", 404); + exit; +} +$emote_set = $stmt->fetch(PDO::FETCH_ASSOC); + +// get user by username +$user_name = $_POST['username']; +$stmt = $db->prepare("SELECT id FROM users WHERE username = ?"); +$stmt->execute([$user_name]); +if ($stmt->rowCount() == 0) { + generate_alert("/404.php", "Username $user_name does not exist", 403); + exit; +} +$user_id = $stmt->fetch(PDO::FETCH_ASSOC)['id']; + +// checking if user has already acquired emote set +$stmt = $db->prepare("SELECT id FROM acquired_emote_sets WHERE user_id = ? AND emote_set_id = ?"); +$stmt->execute([$user_id, $emote_set_id]); +if ($stmt->rowCount() > 0) { + generate_alert("/404.php", "User $user_name has acquired this emoteset.", 409); + exit; +} + +$db->prepare('INSERT INTO acquired_emote_sets(user_id, emote_set_id) VALUES (?, ?)') + ->execute([$user_id, $emote_set_id]); + +generate_alert("/emotesets/?id=$emote_set_id", "This emoteset has been acquired by $user_name.", 200); \ No newline at end of file diff --git a/emotesets/deleditor.php b/emotesets/deleditor.php new file mode 100644 index 0000000..0476f37 --- /dev/null +++ b/emotesets/deleditor.php @@ -0,0 +1,59 @@ +prepare("SELECT id FROM emote_sets WHERE id = ? AND owner_id = ?"); +$stmt->execute([$emote_set_id, $_SESSION['user_id']]); +if ($stmt->rowCount() == 0) { + generate_alert("/emotes", "Emoteset not found", 404); + exit; +} +$emote_set = $stmt->fetch(PDO::FETCH_ASSOC); + +// get user by username +$user_name = $d['username']; +$stmt = $db->prepare("SELECT id FROM users WHERE username = ?"); +$stmt->execute([$user_name]); +if ($stmt->rowCount() == 0) { + generate_alert("/404.php", "Username $user_name does not exist", 403); + exit; +} +$user_id = $stmt->fetch(PDO::FETCH_ASSOC)['id']; + +// checking if user has already acquired emote set +$stmt = $db->prepare("SELECT id FROM acquired_emote_sets WHERE user_id = ? AND emote_set_id = ?"); +$stmt->execute([$user_id, $emote_set_id]); +if ($stmt->rowCount() == 0) { + generate_alert("/404.php", "User $user_name has not acquired this emoteset.", 404); + exit; +} + +$db->prepare('DELETE FROM acquired_emote_sets WHERE user_id = ? AND emote_set_id = ?') + ->execute([$user_id, $emote_set_id]); + +generate_alert("/emotesets/?id=$emote_set_id", "User $user_name can not edit this emoteset anymore.", 200); \ No newline at end of file diff --git a/emotesets/index.php b/emotesets/index.php new file mode 100644 index 0000000..5be3bda --- /dev/null +++ b/emotesets/index.php @@ -0,0 +1,206 @@ +query("SELECT * FROM emote_sets WHERE is_global = TRUE LIMIT 1", PDO::FETCH_ASSOC); + + if ($rows->rowCount()) { + $emote_set = $rows->fetch(); + } else { + generate_alert("/404.php", "Global emoteset is not found", 404); + exit; + } +} +// featured emoteset +else if ($id == "featured") { + $rows = $db->query("SELECT * FROM emote_sets WHERE is_featured = TRUE LIMIT 1", PDO::FETCH_ASSOC); + + if ($rows->rowCount()) { + $emote_set = $rows->fetch(); + } else { + generate_alert("/404.php", "Featured emoteset is not found", 404); + exit; + } +} +// connected emoteset +else if (isset($_GET["alias_id"])) { + $alias_id = $_GET["alias_id"]; + $platform = $_GET["platform"] ?? "twitch"; + + $stmt = $db->prepare("SELECT es.* FROM emote_sets es + INNER JOIN connections co ON co.alias_id = ? AND co.platform = ? + INNER JOIN acquired_emote_sets aes ON aes.user_id = co.user_id + WHERE aes.is_default = TRUE + "); + $stmt->execute([$alias_id, $platform]); + + if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $emote_set = $row; + } else { + generate_alert("/404.php", "Emoteset is not found for alias ID $alias_id ($platform)", 404); + exit; + } +} +// specified emoteset +else if (!empty($id)) { + $stmt = $db->prepare("SELECT es.* FROM emote_sets es WHERE es.id = ?"); + $stmt->execute([$id]); + + if ($row = $stmt->fetch()) { + $emote_set = $row; + } else { + generate_alert("/404.php", "Emoteset ID $id is not found", 404); + exit; + } +} + +$user_id = $_SESSION["user_id"] ?? ""; +$emote_sets = null; + +// fetching emotes +if ($emote_set) { + $emote_set = Emoteset::from_array_extended($emote_set, $user_id, $db); +} elseif (!CONFIG['emoteset']['public']) { + generate_alert("/404.php", "The public list of emotesets is disabled", 403); + exit; +} else { + $emote_sets = []; + foreach ($db->query("SELECT * FROM emote_sets", PDO::FETCH_ASSOC) as $row) { + array_push($emote_sets, Emoteset::from_array_extended($row, $user_id, $db)); + } +} + +if (CLIENT_REQUIRES_JSON) { + if ($emote_sets != null) { + json_response([ + "status_code" => 200, + "message" => null, + "data" => $emote_sets + ]); + exit; + } else if ($emote_set != null) { + json_response([ + "status_code" => 200, + "message" => null, + "data" => $emote_set + ]); + exit; + } else { + json_response([ + "status_code" => 404, + "message" => "Emoteset(s) not found", + "data" => null + ], 404); + exit; + } +} +?> + + + + + <?php + $title = match ($emote_set == null) { + true => count($emote_sets) . ' emotesets', + false => "Emoteset - {$emote_set->name}", + }; + + echo "$title - " . CONFIG['instance']['name']; + ?> + + + + + + +
+
+ +
+
+ + +
+ +
+ emotes); + } else { + echo 'Nothing found...'; + } + ?> +
+ + +
+ editors)): ?> +

This emoteset does not have any editors.

+ +

+ Editors: + editors as $e): ?> + + + + owner, $_SESSION['user_id']) && $emote_set->owner->id == $_SESSION['user_id'] && $e['id'] !== $emote_set->owner->id): ?> + + + +

+ +
+ owner) && $emote_set->owner->id === $_SESSION['user_id']): ?> +
+ +
+
+

Add editor:

+ + + +
+
+
+ + +
+
+
+
+ + + \ No newline at end of file diff --git a/index.php b/index.php index a538469..6bc0503 100644 --- a/index.php +++ b/index.php @@ -29,7 +29,7 @@ authorize_user(); Emotes - Emotesets + Emotesets diff --git a/lib/emote.php b/lib/emote.php index a724914..38e4f01 100644 --- a/lib/emote.php +++ b/lib/emote.php @@ -107,7 +107,7 @@ class Emoteset public string $id; public string $name; public User|null $owner; - public array $emotes; + public array $emotes, $editors; public bool $is_default; @@ -119,6 +119,7 @@ class Emoteset $s->name = $arr["name"]; $s->owner = $arr["owner_id"]; $s->emotes = $arr["emotes"] ?? []; + $s->editors = $arr["editors"] ?? []; $s->is_default = $arr["is_default"] ?? false; return $s; @@ -132,6 +133,14 @@ class Emoteset $arr["emotes"] = fetch_all_emotes_from_emoteset($db, $arr["id"], $user_id); + $stmt = $db->prepare('SELECT u.id, u.username FROM users u + INNER JOIN emote_sets es ON es.id = ? + INNER JOIN acquired_emote_sets aes ON aes.emote_set_id = es.id + WHERE aes.user_id = u.id + '); + $stmt->execute([$arr["id"]]); + $arr["editors"] = $stmt->fetchAll(PDO::FETCH_ASSOC); + return Emoteset::from_array($arr); } @@ -281,7 +290,7 @@ function html_display_emotes(array $emotes, int $scale = 3) function html_display_emoteset(array $emotesets) { foreach ($emotesets as $es) { - echo ""; + echo ""; echo '
'; echo "

$es->name

"; diff --git a/lib/partials.php b/lib/partials.php index 60d1325..71a429a 100644 --- a/lib/partials.php +++ b/lib/partials.php @@ -13,7 +13,7 @@ function html_navigation_bar()
Emotes - Emotesets + Emotesets diff --git a/users.php b/users.php index 7aa0439..359056a 100644 --- a/users.php +++ b/users.php @@ -514,7 +514,7 @@ if ($is_json) { echo " $preposition rowCount() == 1) { - echo '/emotesets.php?id=' . $payload["emoteset"]["id"]; + echo '/emotesets/?id=' . $payload["emoteset"]["id"]; } echo '">' . $payload["emoteset"]["name"] . ''; -- cgit v1.2.3