From f251d18bcbbe6379296aacc28558ec636cbd728b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Sat, 27 Apr 2024 10:43:58 +0200 Subject: [PATCH] Test meme voting --- lib/meme.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/meme.php b/lib/meme.php index 40a7e53..e356cb8 100644 --- a/lib/meme.php +++ b/lib/meme.php @@ -28,8 +28,8 @@ function renderMeme(int $id, int $authorId, string $title, string $textContent, $meme_out = str_replace('__TEMPLATE_MEME_DELETE_BUTTON__', (isModerator() || $_SESSION['ID'] == $authorId) ? "" : '', $meme_out); $meme_votes = calculateNetVotes($id); - $meme_upvote = isLoggedIn() ? "" : ''; - $meme_downvote = isLoggedIn() ? "" : ''; + $meme_upvote = isLoggedIn() ? "" : ''; + $meme_downvote = isLoggedIn() ? "" : ''; $meme_out = str_replace('__TEMPLATE_MEME_VOTES_NUMBER__', $meme_votes, $meme_out); $meme_out = str_replace('__TEMPLATE_MEME_UPVOTE__', $meme_upvote, $meme_out); @@ -99,13 +99,15 @@ function deleteMeme(int $memeID): array return $out; } -function voteMeme(int $memeID, bool $isUpvote): array +function voteMeme(int $memeID, int $isUpvote): array { global $mysqli; $out = ["Status" => "Fail"]; - $vote = $isUpvote ? 1 : 0; + if ($isUpvote != 1) { + $isUpvote = 0; + } $memeVoteConn = $mysqli->prepare('INSERT INTO MemeVotes (MemeID, UserID, isUpvote) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE isUpvote = VALUES(isUpvote)'); - $memeVoteConn->bind_param('iii', $memeID, $_SESSION['ID'], $vote); + $memeVoteConn->bind_param('iii', $memeID, $_SESSION['ID'], $isUpvote); $memeVoteConn->execute(); if ($memeVoteConn->affected_rows > 0) { $out['Status'] = 'Success';