mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-20 05:13:54 -07:00
Vote button code improvements (#1140)
* Vote button code improvements * Update thanks.php
This commit is contained in:
parent
cfb80987d4
commit
c046e8a8c1
3 changed files with 55 additions and 39 deletions
53
library/ajax/thanks.php
Normal file
53
library/ajax/thanks.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2005-2023 TorrentPier (https://torrentpier.com)
|
||||||
|
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||||||
|
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('IN_AJAX')) {
|
||||||
|
die(basename(__FILE__));
|
||||||
|
}
|
||||||
|
|
||||||
|
global $bb_cfg, $lang, $userdata;
|
||||||
|
|
||||||
|
if (!$bb_cfg['tor_thank']) {
|
||||||
|
$this->ajax_die($lang['DISABLED']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mode = (string)$this->request['mode'];
|
||||||
|
$topic_id = (int)$this->request['topic_id'];
|
||||||
|
|
||||||
|
switch ($mode) {
|
||||||
|
case 'add':
|
||||||
|
if (DB()->fetch_row('SELECT * FROM ' . BB_THX . " WHERE topic_id = $topic_id AND user_id = " . $userdata['user_id'])) {
|
||||||
|
$this->ajax_die($lang['LIKE_ALREADY']);
|
||||||
|
}
|
||||||
|
|
||||||
|
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']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$columns = 'topic_id, user_id, time';
|
||||||
|
$values = "$topic_id, {$userdata['user_id']}, " . TIMENOW;
|
||||||
|
DB()->query('INSERT IGNORE INTO ' . BB_THX . " ($columns) VALUES ($values)");
|
||||||
|
|
||||||
|
$this->response['html'] = '<b>' . profile_url($userdata) . ' <i>(' . bb_date(TIMENOW) . ')</i></b>';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'get':
|
||||||
|
$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');
|
||||||
|
}
|
|
@ -38,7 +38,7 @@ if ($delete_dlstat_sql = implode(') OR (', $delete_dlstat_sql)) {
|
||||||
// Save the last 50 votes for topics
|
// Save the last 50 votes for topics
|
||||||
DB()->query('
|
DB()->query('
|
||||||
DELETE t1
|
DELETE t1
|
||||||
FROM' . BB_THX . ' t1
|
FROM ' . BB_THX . ' t1
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT topic_id, MAX(time) as max_time
|
SELECT topic_id, MAX(time) as max_time
|
||||||
FROM ' . BB_THX . '
|
FROM ' . BB_THX . '
|
||||||
|
|
39
src/Ajax.php
39
src/Ajax.php
|
@ -520,48 +520,11 @@ class Ajax
|
||||||
/**
|
/**
|
||||||
* Get / Set votes
|
* Get / Set votes
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function thx()
|
public function thx()
|
||||||
{
|
{
|
||||||
global $bb_cfg, $lang, $userdata;
|
require AJAX_DIR . '/thanks.php';
|
||||||
|
|
||||||
if (!$bb_cfg['tor_thank']) {
|
|
||||||
$this->ajax_die($lang['DISABLED']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$mode = (string) $this->request['mode'];
|
|
||||||
$topic_id = (int) $this->request['topic_id'];
|
|
||||||
|
|
||||||
switch($mode) {
|
|
||||||
case 'add':
|
|
||||||
$row = DB()->fetch_row('SELECT * FROM '. BB_THX ." WHERE topic_id = $topic_id AND user_id = ". $userdata['user_id']);
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
$this->ajax_die($lang['LIKE_ALREADY']);
|
|
||||||
}
|
|
||||||
|
|
||||||
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']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$columns = 'topic_id, user_id, time';
|
|
||||||
$values = "$topic_id, {$userdata['user_id']}, " . TIMENOW;
|
|
||||||
DB()->query('INSERT IGNORE INTO ' . BB_THX . " ($columns) VALUES ($values)");
|
|
||||||
$this->response['html'] = '<b>' . profile_url($userdata) . ' <i>('. bb_date(TIMENOW) . ')</i></b>';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'get':
|
|
||||||
$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>';
|
|
||||||
}
|
|
||||||
$thx_list = join(' ', $user_list);
|
|
||||||
$this->response['html'] = ($thx_list) ? $thx_list : $lang['NO_LIKES'];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue