Hide vote button in topic if guest (#1507)

* Hide vote button in topic if guest

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2024-06-13 16:08:23 +07:00 committed by GitHub
commit 75c9f34a73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 26 deletions

View file

@ -27,37 +27,36 @@ if (!$topic_id = (int)$this->request['topic_id']) {
switch ($mode) {
case 'add':
if (!IS_GUEST) {
if (DB()->fetch_row('SELECT poster_id FROM ' . BB_BT_TORRENTS . " WHERE topic_id = $topic_id AND poster_id = " . $userdata['user_id'])) {
$this->ajax_die($lang['LIKE_OWN_POST']);
}
if (DB()->fetch_row('SELECT topic_id FROM ' . BB_THX . " WHERE topic_id = $topic_id AND user_id = " . $userdata['user_id'])) {
$this->ajax_die($lang['LIKE_ALREADY']);
}
$columns = 'topic_id, user_id, time';
$values = "$topic_id, {$userdata['user_id']}, " . TIMENOW;
DB()->query('INSERT IGNORE INTO ' . BB_THX . " ($columns) VALUES ($values)");
break;
} else {
if (IS_GUEST) {
$this->ajax_die($lang['NEED_TO_LOGIN_FIRST']);
}
if (DB()->fetch_row('SELECT poster_id FROM ' . BB_BT_TORRENTS . " WHERE topic_id = $topic_id AND poster_id = " . $userdata['user_id'])) {
$this->ajax_die($lang['LIKE_OWN_POST']);
}
if (DB()->fetch_row('SELECT topic_id FROM ' . BB_THX . " WHERE topic_id = $topic_id AND user_id = " . $userdata['user_id'])) {
$this->ajax_die($lang['LIKE_ALREADY']);
}
$columns = 'topic_id, user_id, time';
$values = "$topic_id, {$userdata['user_id']}, " . TIMENOW;
DB()->query('INSERT IGNORE INTO ' . BB_THX . " ($columns) VALUES ($values)");
break;
case 'get':
if (!IS_GUEST || $bb_cfg['tor_thanks_list_guests']) {
$sql = DB()->fetch_rowset('SELECT u.username, u.user_rank, u.user_id, t.* FROM ' . BB_THX . ' t, ' . BB_USERS . " u WHERE t.topic_id = $topic_id AND t.user_id = u.user_id");
$user_list = [];
foreach ($sql as $row) {
$user_list[] = '<b>' . profile_url($row) . ' <i>(' . bb_date($row['time']) . ')</i></b>';
}
$this->response['html'] = join(', ', $user_list) ?: $lang['NO_LIKES'];
break;
} else {
if (IS_GUEST && !$bb_cfg['tor_thanks_list_guests']) {
$this->ajax_die($lang['NEED_TO_LOGIN_FIRST']);
}
$sql = DB()->fetch_rowset('SELECT u.username, u.user_rank, u.user_id, t.* FROM ' . BB_THX . ' t, ' . BB_USERS . " u WHERE t.topic_id = $topic_id AND t.user_id = u.user_id");
$user_list = [];
foreach ($sql as $row) {
$user_list[] = '<b>' . profile_url($row) . ' <i>(' . bb_date($row['time']) . ')</i></b>';
}
$this->response['html'] = join(', ', $user_list) ?: $lang['NO_LIKES'];
break;
default:
$this->ajax_die('Invalid mode: ' . $mode);
}