Minor improvements (#1542)

* Minor improvements

* Update Updater.php

* Update Updater.php

* Update Updater.php

* Updated

* Updated

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2024-07-16 18:34:43 +07:00 committed by GitHub
commit 5e4eca2c3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 43 additions and 41 deletions

View file

@ -20,7 +20,7 @@
- Hide in topic: Added country hiding [\#1535](https://github.com/torrentpier/torrentpier/pull/1535) ([belomaxorka](https://github.com/belomaxorka)) - 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)) - 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)) - 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)) - 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) ## [v2.4.3](https://github.com/torrentpier/torrentpier/tree/v2.4.3) (2024-06-09)

View file

@ -46,18 +46,12 @@ switch ($mode) {
$columns = 'topic_id, user_id, time'; $columns = 'topic_id, user_id, time';
$values = "$topic_id, {$userdata['user_id']}, " . TIMENOW; $values = "$topic_id, {$userdata['user_id']}, " . TIMENOW;
DB()->query('INSERT IGNORE INTO ' . BB_THX . " ($columns) VALUES ($values)"); DB()->query('INSERT IGNORE INTO ' . BB_THX . " ($columns) VALUES ($values)");
DB()->query("
DELETE FROM " . BB_THX . " // Limit voters per topic
WHERE user_id IN ( $thanks_count = DB()->fetch_row('SELECT COUNT(*) FROM ' . BB_THX . " WHERE topic_id = $topic_id");
SELECT user_id FROM ( if ($thanks_count > (int)$bb_cfg['tor_thank_limit_per_topic']) {
SELECT user_id DB()->query('DELETE FROM ' . BB_THX . " WHERE topic_id = $topic_id ORDER BY time ASC LIMIT 1");
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;
");
break; break;
case 'get': case 'get':
if (IS_GUEST && !$bb_cfg['tor_thanks_list_guests']) { if (IS_GUEST && !$bb_cfg['tor_thanks_list_guests']) {

View file

@ -548,6 +548,7 @@ $bb_cfg['user_not_active_days_keep'] = 180; // After how many days should I dele
// Vote for torrents // Vote for torrents
$bb_cfg['tor_thank'] = true; $bb_cfg['tor_thank'] = true;
$bb_cfg['tor_thanks_list_guests'] = true; // Show voters to guests $bb_cfg['tor_thanks_list_guests'] = true; // Show voters to guests
$bb_cfg['tor_thank_limit_per_topic'] = 50;
// Groups // Groups
$bb_cfg['group_members_per_page'] = 50; // How many groups will be displayed in a page $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['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['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['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'] = [ $bb_cfg['allow_change'] = [
'language' => true, // Allow user to change language 'language' => true, // Allow user to change language

View file

@ -1240,10 +1240,8 @@ $lang['COUNTRIES'] = [
'YT' => 'Mayotte', 'YT' => 'Mayotte',
'ZA' => 'South Africa', 'ZA' => 'South Africa',
'ZM' => 'Zambia', 'ZM' => 'Zambia',
'ZW' => 'Zimbabwe' 'ZW' => 'Zimbabwe',
]; // Additional flags
$lang['ADDITIONAL_FLAGS'] = [
'WBW' => 'Wonderful Russia of the Future', 'WBW' => 'Wonderful Russia of the Future',
'PACE' => 'Peace flag', 'PACE' => 'Peace flag',
'LGBT' => 'Pride flag' 'LGBT' => 'Pride flag'

View file

@ -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; return $this->data;
} }

View file

@ -38,6 +38,19 @@ class Updater
*/ */
public string $savePath; public string $savePath;
/**
* Stream context
*
* @var array
*/
private const STREAM_CONTEXT = [
'http' => [
'header' => 'User-Agent: ' . APP_NAME,
'timeout' => 10,
'ignore_errors' => true
]
];
/** /**
* Updater constructor * Updater constructor
* *
@ -45,7 +58,7 @@ class Updater
*/ */
public function __construct() 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); $response = file_get_contents(UPDATER_URL, context: $context);
if ($response !== false) { if ($response !== false) {
@ -54,15 +67,13 @@ class Updater
// Empty JSON result // Empty JSON result
if (empty($this->jsonResponse)) { if (empty($this->jsonResponse)) {
return false; throw new Exception('Empty JSON response');
} }
// Response message from GitHub // Response message from GitHub
if (isset($json_response['message'])) { if (isset($this->jsonResponse['message'])) {
throw new Exception($json_response['message']); throw new Exception($this->jsonResponse['message']);
} }
return $this->jsonResponse;
} }
/** /**
@ -70,10 +81,11 @@ class Updater
* *
* @param string $path * @param string $path
* @param string $targetVersion * @param string $targetVersion
* @param bool $force
* @return bool * @return bool
* @throws Exception * @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; $this->targetVersion = $targetVersion;
@ -85,21 +97,24 @@ class Updater
} }
if (empty($versionInfo)) { if (empty($versionInfo)) {
return false; throw new Exception('No version info');
} }
$downloadLink = $versionInfo['assets'][0]['browser_download_url']; $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']; $this->savePath = $path . $versionInfo['assets'][0]['name'];
file_put_contents($this->savePath, $getFile);
if (!is_file($this->savePath)) { if (!is_file($this->savePath) || $force) {
throw new Exception("Can't save TorrentPier build file"); $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 // Get MD5 checksums