diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f86398b4..bf3c82834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ - Hide in topic: Added country hiding [\#1535](https://github.com/torrentpier/torrentpier/pull/1535) ([belomaxorka](https://github.com/belomaxorka)) - Hide vote button in topic for guests [\#1507](https://github.com/torrentpier/torrentpier/pull/1507) ([belomaxorka](https://github.com/belomaxorka)) - Word censor code optimization [\#1537](https://github.com/torrentpier/torrentpier/pull/1537) ([belomaxorka](https://github.com/belomaxorka)) -- Minor improvements [\#1502](https://github.com/torrentpier/torrentpier/pull/1502), [\#1506](https://github.com/torrentpier/torrentpier/pull/1506), [\#1509](https://github.com/torrentpier/torrentpier/pull/1509), [\#1511](https://github.com/torrentpier/torrentpier/pull/1511), [\#1515](https://github.com/torrentpier/torrentpier/pull/1515), [\#1516](https://github.com/torrentpier/torrentpier/pull/1516), [\#1517](https://github.com/torrentpier/torrentpier/pull/1517), [\#1519](https://github.com/torrentpier/torrentpier/pull/1519), [\#1523](https://github.com/torrentpier/torrentpier/pull/1523), [\#1525](https://github.com/torrentpier/torrentpier/pull/1525), [\#1530](https://github.com/torrentpier/torrentpier/pull/1530), [\#1532](https://github.com/torrentpier/torrentpier/pull/1532), [\#1536](https://github.com/torrentpier/torrentpier/pull/1536), [\#1539](https://github.com/torrentpier/torrentpier/pull/1539) ([belomaxorka](https://github.com/belomaxorka)) +- Minor improvements [\#1502](https://github.com/torrentpier/torrentpier/pull/1502), [\#1506](https://github.com/torrentpier/torrentpier/pull/1506), [\#1509](https://github.com/torrentpier/torrentpier/pull/1509), [\#1511](https://github.com/torrentpier/torrentpier/pull/1511), [\#1515](https://github.com/torrentpier/torrentpier/pull/1515), [\#1516](https://github.com/torrentpier/torrentpier/pull/1516), [\#1517](https://github.com/torrentpier/torrentpier/pull/1517), [\#1519](https://github.com/torrentpier/torrentpier/pull/1519), [\#1523](https://github.com/torrentpier/torrentpier/pull/1523), [\#1525](https://github.com/torrentpier/torrentpier/pull/1525), [\#1530](https://github.com/torrentpier/torrentpier/pull/1530), [\#1532](https://github.com/torrentpier/torrentpier/pull/1532), [\#1536](https://github.com/torrentpier/torrentpier/pull/1536), [\#1539](https://github.com/torrentpier/torrentpier/pull/1539), [\#1542](https://github.com/torrentpier/torrentpier/pull/1542) ([belomaxorka](https://github.com/belomaxorka)) - New Crowdin updates [\#1504](https://github.com/torrentpier/torrentpier/pull/1504), [\#1513](https://github.com/torrentpier/torrentpier/pull/1513) ([Exileum](https://github.com/Exileum)) ## [v2.4.3](https://github.com/torrentpier/torrentpier/tree/v2.4.3) (2024-06-09) diff --git a/library/ajax/thanks.php b/library/ajax/thanks.php index a93ae953d..3f55f1c4f 100644 --- a/library/ajax/thanks.php +++ b/library/ajax/thanks.php @@ -46,18 +46,12 @@ switch ($mode) { $columns = 'topic_id, user_id, time'; $values = "$topic_id, {$userdata['user_id']}, " . TIMENOW; DB()->query('INSERT IGNORE INTO ' . BB_THX . " ($columns) VALUES ($values)"); - DB()->query(" - DELETE FROM " . BB_THX . " - WHERE user_id IN ( - SELECT user_id FROM ( - SELECT user_id - FROM " . BB_THX . " - WHERE topic_id = $topic_id - ORDER BY time ASC - LIMIT 1 - ) AS subquery - ) AND (SELECT COUNT(*) FROM " . BB_THX . " WHERE topic_id = $topic_id) > 50; - "); + + // Limit voters per topic + $thanks_count = DB()->fetch_row('SELECT COUNT(*) FROM ' . BB_THX . " WHERE topic_id = $topic_id"); + if ($thanks_count > (int)$bb_cfg['tor_thank_limit_per_topic']) { + DB()->query('DELETE FROM ' . BB_THX . " WHERE topic_id = $topic_id ORDER BY time ASC LIMIT 1"); + } break; case 'get': if (IS_GUEST && !$bb_cfg['tor_thanks_list_guests']) { diff --git a/library/config.php b/library/config.php index a9aff668a..5f27741ef 100644 --- a/library/config.php +++ b/library/config.php @@ -548,6 +548,7 @@ $bb_cfg['user_not_active_days_keep'] = 180; // After how many days should I dele // Vote for torrents $bb_cfg['tor_thank'] = true; $bb_cfg['tor_thanks_list_guests'] = true; // Show voters to guests +$bb_cfg['tor_thank_limit_per_topic'] = 50; // Groups $bb_cfg['group_members_per_page'] = 50; // How many groups will be displayed in a page @@ -566,7 +567,6 @@ $bb_cfg['last_visit_date_format'] = 'd-M H:i'; $bb_cfg['last_post_date_format'] = 'd-M-y H:i'; $bb_cfg['poll_max_days'] = 180; // How many days will the poll be active $bb_cfg['integrity_check'] = true; // TorrentPier files integrity check (Not recommended to disable!) -$bb_cfg['enable_additional_flags'] = true; // Enables ability to select additional flags in "Country select" $bb_cfg['allow_change'] = [ 'language' => true, // Allow user to change language diff --git a/library/language/source/main.php b/library/language/source/main.php index 624940880..600b251e8 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -1240,10 +1240,8 @@ $lang['COUNTRIES'] = [ 'YT' => 'Mayotte', 'ZA' => 'South Africa', 'ZM' => 'Zambia', - 'ZW' => 'Zimbabwe' -]; - -$lang['ADDITIONAL_FLAGS'] = [ + 'ZW' => 'Zimbabwe', + // Additional flags 'WBW' => 'Wonderful Russia of the Future', 'PACE' => 'Peace flag', 'LGBT' => 'Pride flag' diff --git a/src/Legacy/Common/User.php b/src/Legacy/Common/User.php index 8fffaaf38..718e6f1ae 100644 --- a/src/Legacy/Common/User.php +++ b/src/Legacy/Common/User.php @@ -231,11 +231,6 @@ class User } } - // Merge additional flags with country flags - if ($bb_cfg['enable_additional_flags']) { - $lang['COUNTRIES'] = array_merge($lang['COUNTRIES'], $lang['ADDITIONAL_FLAGS']); - } - return $this->data; } diff --git a/src/Updater.php b/src/Updater.php index d5653cfed..636f6c2da 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -38,6 +38,19 @@ class Updater */ public string $savePath; + /** + * Stream context + * + * @var array + */ + private const STREAM_CONTEXT = [ + 'http' => [ + 'header' => 'User-Agent: ' . APP_NAME, + 'timeout' => 10, + 'ignore_errors' => true + ] + ]; + /** * Updater constructor * @@ -45,7 +58,7 @@ class Updater */ public function __construct() { - $context = stream_context_create(['http' => ['header' => 'User-Agent: ' . APP_NAME, 'timeout' => 10, 'ignore_errors' => true]]); + $context = stream_context_create(self::STREAM_CONTEXT); $response = file_get_contents(UPDATER_URL, context: $context); if ($response !== false) { @@ -54,15 +67,13 @@ class Updater // Empty JSON result if (empty($this->jsonResponse)) { - return false; + throw new Exception('Empty JSON response'); } // Response message from GitHub - if (isset($json_response['message'])) { - throw new Exception($json_response['message']); + if (isset($this->jsonResponse['message'])) { + throw new Exception($this->jsonResponse['message']); } - - return $this->jsonResponse; } /** @@ -70,10 +81,11 @@ class Updater * * @param string $path * @param string $targetVersion + * @param bool $force * @return bool * @throws Exception */ - public function download(string $path, string $targetVersion = 'latest'): bool + public function download(string $path, string $targetVersion = 'latest', bool $force = false): bool { $this->targetVersion = $targetVersion; @@ -85,21 +97,24 @@ class Updater } if (empty($versionInfo)) { - return false; + throw new Exception('No version info'); } $downloadLink = $versionInfo['assets'][0]['browser_download_url']; - - $getFile = file_get_contents($downloadLink); - if ($getFile === false) { - return false; - } - - // Save build file $this->savePath = $path . $versionInfo['assets'][0]['name']; - file_put_contents($this->savePath, $getFile); - if (!is_file($this->savePath)) { - throw new Exception("Can't save TorrentPier build file"); + + if (!is_file($this->savePath) || $force) { + $context = stream_context_create(self::STREAM_CONTEXT); + $getFile = file_get_contents($downloadLink, context: $context); + if ($getFile === false) { + return false; + } + + // Save build file + file_put_contents($this->savePath, $getFile); + if (!is_file($this->savePath)) { + throw new Exception("Can't save TorrentPier build file"); + } } // Get MD5 checksums