mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 18:48:21 -07:00
Updated
This commit is contained in:
parent
5e39469c56
commit
6aae9339cd
2 changed files with 42 additions and 21 deletions
|
@ -77,27 +77,13 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
|
|||
]);
|
||||
|
||||
// Check for updates
|
||||
if (!$json_response = CACHE('bb_cache')->get('check_for_updates')) {
|
||||
$json_response = false;
|
||||
$context = stream_context_create(['http' => ['header' => 'User-Agent: TorrentPier Updater. With love!']]);
|
||||
$updater_content = file_get_contents(UPDATER_URL, context: $context);
|
||||
if ($updater_content !== false) {
|
||||
$json_response = json_decode(utf8_encode($updater_content), true);
|
||||
CACHE('bb_cache')->set('check_for_updates', $json_response, 1200);
|
||||
}
|
||||
}
|
||||
if (is_array($json_response)) {
|
||||
$get_version = $json_response['tag_name'];
|
||||
$version_code = (int)trim(str_replace(['.', 'v', ','], '', strstr($bb_cfg['tp_version'], '-', true)));
|
||||
$version_code_actual = (int)trim(str_replace(['.', 'v', ','], '', $get_version));
|
||||
|
||||
$template->assign_block_vars('updater', [
|
||||
'UPDATE_AVAILABLE' => $version_code < $version_code_actual,
|
||||
'NEW_VERSION_NUMBER' => $get_version,
|
||||
'NEW_VERSION_SIZE' => isset($json_response['assets'][0]['size']) ? humn_size($json_response['assets'][0]['size']) : false,
|
||||
'NEW_VERSION_DL_LINK' => $json_response['assets'][0]['browser_download_url'] ?? $json_response['html_url']
|
||||
]);
|
||||
}
|
||||
$updater = checkUpdates();
|
||||
$template->assign_block_vars('updater', [
|
||||
'UPDATE_AVAILABLE' => $updater['has_update'],
|
||||
'NEW_VERSION_NUMBER' => $updater['latest_ver'],
|
||||
'NEW_VERSION_SIZE' => $updater['update_size'],
|
||||
'NEW_VERSION_DL_LINK' => $updater['download_link']
|
||||
]);
|
||||
|
||||
// Get forum statistics
|
||||
$total_posts = $stats['postcount'];
|
||||
|
|
|
@ -2132,3 +2132,38 @@ function getBanInfo(int $userId = null): ?array
|
|||
|
||||
return $bans[$userId] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for updates
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function checkUpdates(): array
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
if (!$json_response = CACHE('bb_cache')->get('check_for_updates')) {
|
||||
$context = stream_context_create(['http' => ['header' => 'User-Agent: TorrentPier Updater. With love!']]);
|
||||
$updater_content = file_get_contents(UPDATER_URL, context: $context);
|
||||
if ($updater_content !== false) {
|
||||
$json_response = json_decode(utf8_encode($updater_content), true);
|
||||
CACHE('bb_cache')->set('check_for_updates', $json_response, 1200);
|
||||
} else {
|
||||
return ['error' => 'Could not connect to: ' . UPDATER_URL];
|
||||
}
|
||||
}
|
||||
if (is_array($json_response)) {
|
||||
$get_version = $json_response['tag_name'];
|
||||
$version_code = (int)trim(str_replace(['.', 'v', ','], '', strstr($bb_cfg['tp_version'], '-', true)));
|
||||
$version_code_actual = (int)trim(str_replace(['.', 'v', ','], '', $get_version));
|
||||
|
||||
return [
|
||||
'has_update' => $version_code < $version_code_actual,
|
||||
'latest_ver' => $get_version,
|
||||
'update_size' => isset($json_response['assets'][0]['size']) ? humn_size($json_response['assets'][0]['size']) : false,
|
||||
'download_link' => $json_response['assets'][0]['browser_download_url'] ?? $json_response['html_url']
|
||||
];
|
||||
}
|
||||
|
||||
return ['error' => 'Something went wrong...'];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue