diff options
| author | ilotterytea <iltsu@alright.party> | 2025-05-07 18:57:32 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-05-07 18:57:32 +0500 |
| commit | ada4748a25c39b226534ff0475569a8bd25e17ab (patch) | |
| tree | befc462938025044429643dbceec7466e0160997 /public | |
| parent | 73a329d1e620e719932ad8c860f85289c3547ab3 (diff) | |
feat: user actions
Diffstat (limited to 'public')
| -rw-r--r-- | public/emotes/setmanip.php | 30 | ||||
| -rw-r--r-- | public/emotes/upload.php | 15 | ||||
| -rw-r--r-- | public/static/img/icons/new_emote.png | bin | 0 -> 963 bytes | |||
| -rw-r--r-- | public/users.php | 99 |
4 files changed, 139 insertions, 5 deletions
diff --git a/public/emotes/setmanip.php b/public/emotes/setmanip.php index 8b0f085..71d922b 100644 --- a/public/emotes/setmanip.php +++ b/public/emotes/setmanip.php @@ -22,12 +22,13 @@ $db = new PDO(DB_URL, DB_USER, DB_PASS); // checking emote $emote_id = $_POST["id"]; -$stmt = $db->prepare("SELECT id FROM emotes WHERE id = ?"); +$stmt = $db->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"]; @@ -66,6 +67,10 @@ $stmt = $db->prepare("SELECT id FROM emote_set_contents WHERE emote_set_id = ? A $stmt->execute([$emote_set_id, $emote_id]); $action = $_POST["action"]; +$payload = [ + "emote" => $emote, + "emoteset" => $_SESSION["user_active_emote_set"] +]; switch ($action) { case "add": { @@ -77,6 +82,9 @@ switch ($action) { $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]); + $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); @@ -92,6 +100,9 @@ switch ($action) { exit; } + $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); @@ -105,13 +116,30 @@ switch ($action) { $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]); + $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); diff --git a/public/emotes/upload.php b/public/emotes/upload.php index 0b79b5c..42e58c6 100644 --- a/public/emotes/upload.php +++ b/public/emotes/upload.php @@ -389,6 +389,21 @@ if ($is_manual) { } } +$db->prepare("INSERT INTO actions(user_id, action_type, action_payload) VALUES (?, ?, ?)") + ->execute([ + $uploaded_by, + "EMOTE_CREATE", + json_encode([ + "emote" => [ + "id" => $id, + "code" => $code, + "visibility" => $visibility, + "uploaded_by" => $uploaded_by, + ] + ]) + ]); + + $db = null; if (CLIENT_REQUIRES_JSON) { diff --git a/public/static/img/icons/new_emote.png b/public/static/img/icons/new_emote.png Binary files differnew file mode 100644 index 0000000..82d263e --- /dev/null +++ b/public/static/img/icons/new_emote.png diff --git a/public/users.php b/public/users.php index f1aa3e7..ccdb193 100644 --- a/public/users.php +++ b/public/users.php @@ -226,8 +226,10 @@ $stmt->execute([$user->id(), $user->id()]); $uploaded_emotes = $stmt->fetchAll(PDO::FETCH_ASSOC); // gathering actions -// TODO: update it when we will have action logs -$actions = []; +$stmt = $db->prepare("SELECT a.* FROM actions a WHERE a.user_id = ? ORDER BY a.created_at DESC LIMIT 15"); +$stmt->execute([$user->id()]); + +$actions = $stmt->fetchAll(PDO::FETCH_ASSOC); // TODO: add functionality @@ -514,10 +516,99 @@ if ($is_json) { </div> <div class="box content"> <?php - if (!empty($actions)) { - } else { + if (empty($actions)) { echo "<p>This user has done nothing bad or good...</p>"; } + + foreach ($actions as $action) { + echo '<div class="row">'; + + list($action_name, $preposition, $icon_name) = match ($action["action_type"]) { + "EMOTESET_ADD" => ["added", "to", "yes.png"], + "EMOTESET_REMOVE" => ["removed", "from", "no.png"], + "EMOTESET_ALIAS" => ["renamed", "in", "pencil.png"], + "EMOTE_CREATE" => ["created", null, "new_emote.png"], + "EMOTE_DELETE" => ["deleted", null, "deleted_emote.png"], + "EMOTE_RENAME" => ["renamed", null, "renamed_emote.png"] + }; + + echo "<div><img src='/static/img/icons/$icon_name' width='16' /></div>"; + + echo '<div class="column">'; + echo '<p>'; + echo '<i>' . $user->username() . '</i> '; + + $payload = json_decode($action["action_payload"], true); + + list($action_root, $action_sub) = explode("_", $action["action_type"]); + + switch ($action_root) { + case "EMOTESET": { + $e_stmt = $db->prepare("SELECT COUNT(*) FROM emotes WHERE id = ?"); + $e_stmt->execute([$payload["emote"]["id"]]); + + echo "$action_name emote <a href=\""; + + if ($e_stmt->rowCount() == 1) { + echo '/emotes?id=' . $payload["emote"]["id"] . '">'; + echo '<img src="/static/userdata/emotes/' . $payload["emote"]["id"] . '/1x.webp" height="16" /> '; + } else { + echo '">'; + } + + if (isset($payload["emote"]["original_code"])) { + echo $payload["emote"]["original_code"] . '</a> to '; + echo "<a href=\""; + + if ($e_stmt->rowCount() == 1) { + echo '/emotes?id=' . $payload["emote"]["id"] . '">'; + echo '<img src="/static/userdata/emotes/' . $payload["emote"]["id"] . '/1x.webp" height="16" /> '; + } else { + echo '">'; + } + + echo $payload["emote"]["code"] . '</a>'; + } else { + echo $payload["emote"]["code"] . '</a>'; + } + + $es_stmt = $db->prepare("SELECT COUNT(*) FROM emote_sets WHERE id = ?"); + $es_stmt->execute([$payload["emoteset"]["id"]]); + + echo " $preposition <a href=\""; + if ($es_stmt->rowCount() == 1) { + echo '/emotesets.php?id=' . $payload["emoteset"]["id"]; + } + + echo '">' . $payload["emoteset"]["name"] . '</a>'; + break; + } + case "EMOTE": { + $e_stmt = $db->prepare("SELECT COUNT(*) FROM emotes WHERE id = ?"); + $e_stmt->execute([$payload["emote"]["id"]]); + + echo "$action_name emote <a href=\""; + + if ($e_stmt->rowCount() == 1) { + echo '/emotes?id=' . $payload["emote"]["id"] . '">'; + echo '<img src="/static/userdata/emotes/' . $payload["emote"]["id"] . '/1x.webp" height="16" /> '; + } else { + echo '">'; + } + + echo $payload["emote"]["code"] . '</a>'; + break; + } + default: { + echo "something that we don't know"; + break; + } + } + + echo '</p>'; + echo '<span class="font-small" style="color: gray;">[' . format_timestamp(time() - strtotime($action["created_at"])) . ' ago]</span> '; + echo '</div></div>'; + } ?> </div> </section> |
