From 3dedb7e33d9610b0d459c2ab1aa3c172ad583aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B8nstantine=20Kovalensky?= <45331093+kovalensky@users.noreply.github.com> Date: Mon, 20 Nov 2023 21:05:13 +0400 Subject: [PATCH] Vote button and v2 file list topic url display (#1138) --- install/sql/mysql.sql | 18 +++++ library/config.php | 3 + library/includes/cron/jobs/clean_dlstat.php | 13 ++++ library/includes/file_list_v2.php | 4 +- library/includes/init_bb.php | 1 + library/language/source/main.php | 8 +++ src/Ajax.php | 48 +++++++++++++ styles/templates/default/viewtopic_attach.tpl | 70 +++++++++++++++++++ 8 files changed, 163 insertions(+), 2 deletions(-) diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 701443d34..05e53e17e 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -1467,6 +1467,24 @@ CREATE TABLE IF NOT EXISTS `buf_last_seeder` -- Records of buf_last_seeder -- ---------------------------- +-- ---------------------------- +-- Table structure for `bb_thx` +-- ---------------------------- +DROP TABLE IF EXISTS `bb_thx`; +CREATE TABLE IF NOT EXISTS `bb_thx` +( + `topic_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', + `user_id` MEDIUMINT(8) NOT NULL DEFAULT '0', + `time` INT(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`topic_id`) +) + ENGINE = MyISAM + DEFAULT CHARSET = utf8; + +-- ---------------------------- +-- Records of bb_thx +-- ---------------------------- + -- ---------------------------- -- Table structure for `buf_topic_view` -- ---------------------------- diff --git a/library/config.php b/library/config.php index 6204d3433..3f17a7f62 100644 --- a/library/config.php +++ b/library/config.php @@ -505,6 +505,9 @@ $bb_cfg['color_nick'] = true; // Colour user names in accordance with user_rank $bb_cfg['user_not_activated_days_keep'] = 7; // "not activated" == "not finished registration" $bb_cfg['user_not_active_days_keep'] = 180; // inactive users but only with no posts +// Vote for torrents +$bb_cfg['tor_thank'] = true; + // Groups $bb_cfg['group_members_per_page'] = 50; // How many groups will be displayed in a page diff --git a/library/includes/cron/jobs/clean_dlstat.php b/library/includes/cron/jobs/clean_dlstat.php index 40827fa60..b7d97726b 100644 --- a/library/includes/cron/jobs/clean_dlstat.php +++ b/library/includes/cron/jobs/clean_dlstat.php @@ -35,6 +35,19 @@ if ($delete_dlstat_sql = implode(') OR (', $delete_dlstat_sql)) { DB()->query("DELETE QUICK FROM " . BB_BT_DLSTATUS . " WHERE ($delete_dlstat_sql)"); } +// Save the last 50 votes for topics +DB()->query(' + DELETE t1 + FROM' . BB_THX . ' t1 + JOIN ( + SELECT topic_id, MAX(time) as max_time + FROM ' . BB_THX . ' + GROUP BY topic_id + HAVING COUNT(*) > 50 + ) t2 + ON t1.topic_id = t2.topic_id AND t1.time = t2.max_time; +'); + // Delete orphans DB()->query(" DELETE QUICK dl diff --git a/library/includes/file_list_v2.php b/library/includes/file_list_v2.php index 1b382c5fe..17ce90cd5 100644 --- a/library/includes/file_list_v2.php +++ b/library/includes/file_list_v2.php @@ -66,7 +66,6 @@ $data = [ 'name' => htmlCHR($tor['info']['name'] ?? ''), 'client' => htmlCHR(substr($tor['created by'] ?? 'unknown client', 0, 20)), 'size' => humn_size($files['size']), - 'hash' => bin2hex($row['info_hash_v2']), 'date' => (isset($tor['creation date']) && is_numeric($tor['creation date'])) ? delta_time($tor['creation date']) : 'unknown', 'site_url' => FULL_URL ]; @@ -81,7 +80,7 @@ echo << -{$data['name']} ({$data['size']}) | {$data['hash']} | {$bb_cfg['sitename']} +{$data['name']} ({$data['size']}) | {$bb_cfg['sitename']} +🠔 Back to the topic

Name: {$data['name']} | Age: ({$data['date']}) | Size: {$data['size']}

diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index 96d6c906d..eef500b2b 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -251,6 +251,7 @@ define('BB_TOPICS_WATCH', 'bb_topics_watch'); define('BB_USER_GROUP', 'bb_user_group'); define('BB_USERS', 'bb_users'); define('BB_WORDS', 'bb_words'); +define('BB_THX', 'bb_thx'); define('TORRENT_EXT', 'torrent'); diff --git a/library/language/source/main.php b/library/language/source/main.php index f3c4952b3..5fa9f81b7 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -680,6 +680,14 @@ $lang['ASC'] = 'Ascending'; $lang['DESC'] = 'Descending'; $lang['ORDER'] = 'Order'; +// Thanks +$lang['THANK_TOPIC'] = 'Vote for this topic'; +$lang['THANKS_GRATITUDE'] = 'We appreciate your gratitude'; +$lang['LAST_LIKES'] = 'Last votes'; +$lang['LIKE_OWN_POST'] = 'You can\'t vote for your own topic'; +$lang['NO_LIKES'] = 'Nobody gave a vote yet'; +$lang['LIKE_ALREADY'] = 'You already voted this topic'; + // Group control panel $lang['GROUP_CONTROL_PANEL'] = 'User Groups'; $lang['GROUP_CONFIGURATION'] = 'Group Configuration'; diff --git a/src/Ajax.php b/src/Ajax.php index df34a1e81..d9ff9a125 100644 --- a/src/Ajax.php +++ b/src/Ajax.php @@ -38,6 +38,7 @@ class Ajax 'passkey' => ['user'], 'change_torrent' => ['user'], 'change_tor_status' => ['user'], + 'thx' => ['user'], 'manage_group' => ['user'], 'callseed' => ['user'], @@ -515,4 +516,51 @@ class Ajax { require AJAX_DIR . '/callseed.php'; } + + /** + * Get / Set votes + * + * + * @return void + */ + + public function thx() + { + 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': + $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'] = '' . profile_url($userdata) . ' ('. bb_date(TIMENOW) . ')'; + 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[] = '' . profile_url($row) . ' (' . bb_date($row['time']) . ')'; + } + $thx_list = join(' ', $user_list); + $this->response['html'] = ($thx_list) ? $thx_list : $lang['NO_LIKES']; + break; + } + } } diff --git a/styles/templates/default/viewtopic_attach.tpl b/styles/templates/default/viewtopic_attach.tpl index ab0039dda..716ac4cc3 100644 --- a/styles/templates/default/viewtopic_attach.tpl +++ b/styles/templates/default/viewtopic_attach.tpl @@ -364,6 +364,76 @@ $('#tor-filelist-btn').click(function(){ + + + + +

+
+ +
+
+
+
+
+ + +