diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d745761d..93c6bbde0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Introduce limit setting for max number of files to be processed in separate index file-listing [\#1223](https://github.com/torrentpier/torrentpier/pull/1223) ([kovalensky](https://github.com/kovalensky)) - Fixed set auth cookie issue [\#1227](https://github.com/torrentpier/torrentpier/pull/1227) ([belomaxorka](https://github.com/belomaxorka)) - Fixed broken captcha check on login.php [\#1233](https://github.com/torrentpier/torrentpier/pull/1233) ([belomaxorka](https://github.com/belomaxorka)) +- Hide vote button in poll if user already voted [\#1235](https://github.com/torrentpier/torrentpier/pull/1235) ([belomaxorka](https://github.com/belomaxorka)) - New Crowdin updates [\#1203](https://github.com/torrentpier/torrentpier/pull/1203), [\#1222](https://github.com/torrentpier/torrentpier/pull/1222) ([Exileum](https://github.com/Exileum)) ## [v2.4.0-rc2](https://github.com/torrentpier/torrentpier/tree/v2.4.0-rc2) (2023-12-12) diff --git a/poll.php b/poll.php index 98d0e64ff..2397304d6 100644 --- a/poll.php +++ b/poll.php @@ -68,7 +68,7 @@ switch ($mode) { } // Checking that poll has not been finished - if (!\TorrentPier\Legacy\Poll::poll_is_active($t_data)) { + if (!\TorrentPier\Legacy\Poll::pollIsActive($t_data)) { bb_die($lang['NEW_POLL_ENDED']); } @@ -76,7 +76,7 @@ switch ($mode) { bb_die($lang['NO_VOTE_OPTION']); } - if (DB()->fetch_row("SELECT 1 FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']} LIMIT 1")) { + if (\TorrentPier\Legacy\Poll::userIsAlreadyVoted($topic_id, (int)$userdata['user_id'])) { bb_die($lang['ALREADY_VOTED']); } diff --git a/src/Legacy/Poll.php b/src/Legacy/Poll.php index 1477b0cf7..106fa5a94 100644 --- a/src/Legacy/Poll.php +++ b/src/Legacy/Poll.php @@ -142,13 +142,25 @@ class Poll return is_array($topic_id) ? $items : $items[$topic_id]; } + /** + * Checks whether the user has voted in a poll + * + * @param int $topic_id + * @param int $user_id + * @return bool + */ + public static function userIsAlreadyVoted(int $topic_id, int $user_id): bool + { + return (bool)DB()->fetch_row("SELECT user_id FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id AND user_id = $user_id LIMIT 1"); + } + /** * Check whether poll is active * * @param array $t_data * @return bool */ - public static function poll_is_active(array $t_data): bool + public static function pollIsActive(array $t_data): bool { global $bb_cfg; return ($t_data['topic_vote'] == 1 && $t_data['topic_time'] > TIMENOW - $bb_cfg['poll_max_days'] * 86400); diff --git a/styles/templates/default/viewtopic_poll.tpl b/styles/templates/default/viewtopic_poll.tpl index 6c3d51617..13d2e8773 100644 --- a/styles/templates/default/viewtopic_poll.tpl +++ b/styles/templates/default/viewtopic_poll.tpl @@ -126,10 +126,10 @@ function html2text (str)
- +
[ {L_SUBMIT_VOTE} ]
- +
[ {L_NEW_POLL_END} ]
diff --git a/viewtopic.php b/viewtopic.php index 69f444418..ed24fe833 100644 --- a/viewtopic.php +++ b/viewtopic.php @@ -552,7 +552,8 @@ if ($topic_has_poll) { $template->assign_vars(['TOPIC_HAS_POLL' => false]); } else { $template->assign_vars([ - 'SHOW_VOTE_BTN' => \TorrentPier\Legacy\Poll::poll_is_active($t_data), + 'SHOW_VOTE_BTN' => \TorrentPier\Legacy\Poll::pollIsActive($t_data), + 'POLL_ALREADY_VOTED' => \TorrentPier\Legacy\Poll::userIsAlreadyVoted($topic_id, (int)$userdata['user_id']), 'POLL_VOTES_JS' => $poll_votes_js ]); }