From 6ddfe7a27bc3cad94294642716ef58c158cad3e5 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 10 May 2025 21:27:08 +0500 Subject: feat: private profiles --- public/users.php | 77 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 33 deletions(-) (limited to 'public/users.php') diff --git a/public/users.php b/public/users.php index 430fda5..1d803e7 100644 --- a/public/users.php +++ b/public/users.php @@ -155,6 +155,14 @@ if ($user == null) { exit; } +// User preferences +$stmt = $db->prepare("SELECT * FROM user_preferences WHERE id = ?"); +$stmt->execute([$user->id()]); + +$user_preferences = $stmt->fetch(PDO::FETCH_ASSOC); + +$public_profile = !$user_preferences["private_profile"] || $user->id() == ($_SESSION["user_id"] ?? ""); + // --- EMOTE SETS --- // TODO: OPTIMIZE IT ASAP!!! $emote_sets = []; @@ -172,7 +180,8 @@ while ($row = $stmt->fetch()) { // getting info about emote set content $em_stmt = $db->prepare( - "SELECT e.id, e.created_at, e.uploaded_by, + "SELECT e.id, e.created_at, + CASE WHEN up.private_profile = FALSE OR up.id = ? THEN e.uploaded_by ELSE NULL END AS uploaded_by, CASE WHEN esc.code IS NOT NULL THEN esc.code ELSE e.code @@ -182,12 +191,13 @@ while ($row = $stmt->fetch()) { ELSE NULL END AS original_code FROM emotes e + LEFT JOIN user_preferences up ON up.id = e.uploaded_by INNER JOIN emote_set_contents AS esc ON esc.emote_set_id = ? WHERE esc.emote_id = e.id " . ($row["is_default"] ? '' : ' LIMIT 5') ); - $em_stmt->execute([$row["emote_set_id"]]); + $em_stmt->execute([$_SESSION["user_id"] ?? "", $row["emote_set_id"]]); $emote_set_emotes = $em_stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($emote_set_emotes as &$e) { @@ -215,7 +225,10 @@ while ($row = $stmt->fetch()) { $active_emote_set = &$emote_sets[$active_emote_set]; // gathering uploaded emotes -$stmt = $db->prepare("SELECT e.*, +$uploaded_emotes = []; + +if ($public_profile) { + $stmt = $db->prepare("SELECT e.*, CASE WHEN EXISTS ( SELECT 1 FROM emote_set_contents ec @@ -226,14 +239,15 @@ $stmt = $db->prepare("SELECT e.*, WHERE e.uploaded_by = ? ORDER BY e.created_at ASC "); -$stmt->execute([$user->id(), $user->id()]); + $stmt->execute([$user->id(), $user->id()]); -$uploaded_emotes = $stmt->fetchAll(PDO::FETCH_ASSOC); + $uploaded_emotes = $stmt->fetchAll(PDO::FETCH_ASSOC); +} // gathering actions $actions = []; -if (ACCOUNT_LOG_ACTIONS) { +if ($public_profile) { $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); @@ -266,12 +280,6 @@ $fav_reactions = $stmt->fetchAll(PDO::FETCH_ASSOC); // getting favorite emote $fav_emote = 1; -// User preferences -$stmt = $db->prepare("SELECT * FROM user_preferences WHERE id = ?"); -$stmt->execute([$user->id()]); - -$user_preferences = $stmt->fetch(PDO::FETCH_ASSOC) ?? null; - if ($is_json) { header("Content-type: application/json"); echo json_encode([ @@ -422,13 +430,13 @@ if ($is_json) { - + + -
@@ -489,11 +497,12 @@ if ($is_json) { ?>
- +
+ + +
+ +
+ '; + echo '' . $emote_row['; + echo '

' . $emote_row["code"] . '

'; + echo ''; + } + ?> +
+
- -
- -
- '; - echo '' . $emote_row['; - echo '

' . $emote_row["code"] . '

'; - echo ''; - } - ?> -
-
-- cgit v1.2.3