Added updates checker ⚙️ (#1451)

* Added update checker

* Update index.php

* Update index.php

* Updated

* Update index.php

* Update index.php

* Update index.tpl

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2024-04-13 16:58:48 +07:00 committed by GitHub
commit a255640f28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 45 additions and 11 deletions

View file

@ -6,6 +6,7 @@
**Merged pull requests:** **Merged pull requests:**
- Release 2.4.3 🐎 ([belomaxorka](https://github.com/belomaxorka)) - Release 2.4.3 🐎 ([belomaxorka](https://github.com/belomaxorka))
- Added updates checker ⚙️ [\#1451](https://github.com/torrentpier/torrentpier/pull/1451) ([belomaxorka](https://github.com/belomaxorka))
- Added preview for country flags while editing [\#1448](https://github.com/torrentpier/torrentpier/pull/1448) ([belomaxorka](https://github.com/belomaxorka)) - Added preview for country flags while editing [\#1448](https://github.com/torrentpier/torrentpier/pull/1448) ([belomaxorka](https://github.com/belomaxorka))
- Added support for APCu caching method [\#1442](https://github.com/torrentpier/torrentpier/pull/1442) ([belomaxorka](https://github.com/belomaxorka)) - Added support for APCu caching method [\#1442](https://github.com/torrentpier/torrentpier/pull/1442) ([belomaxorka](https://github.com/belomaxorka))
- Some enhancements [\#1445](https://github.com/torrentpier/torrentpier/pull/1445) ([belomaxorka](https://github.com/belomaxorka)) - Some enhancements [\#1445](https://github.com/torrentpier/torrentpier/pull/1445) ([belomaxorka](https://github.com/belomaxorka))

View file

@ -76,6 +76,29 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
'ADMIN_LOCK_CRON' => is_file(BB_DISABLED), 'ADMIN_LOCK_CRON' => is_file(BB_DISABLED),
]); ]);
// 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']
]);
}
// Get forum statistics // Get forum statistics
$total_posts = $stats['postcount']; $total_posts = $stats['postcount'];
$total_topics = $stats['topiccount']; $total_topics = $stats['topiccount'];

View file

@ -13,6 +13,7 @@ if (!defined('BB_ROOT')) {
// System // System
define('APP_NAME', 'TorrentPier'); define('APP_NAME', 'TorrentPier');
define('UPDATER_URL', 'https://api.github.com/repos/torrentpier/torrentpier/releases/latest');
// Path (trailing slash '/' at the end: XX_PATH - without, XX_DIR - with) // Path (trailing slash '/' at the end: XX_PATH - without, XX_DIR - with)
define('ADMIN_DIR', BB_PATH . '/admin'); define('ADMIN_DIR', BB_PATH . '/admin');

View file

@ -2280,6 +2280,7 @@ $lang['CLICK_RETURN_DISALLOWADMIN'] = 'Click %sHere%s to return to Disallow User
// Version Check // Version Check
$lang['VERSION_INFORMATION'] = 'Version Information'; $lang['VERSION_INFORMATION'] = 'Version Information';
$lang['UPDATE_AVAILABLE'] = 'Update available';
// Login attempts configuration // Login attempts configuration
$lang['MAX_LOGIN_ATTEMPTS'] = 'Allowed login attempts'; $lang['MAX_LOGIN_ATTEMPTS'] = 'Allowed login attempts';

View file

@ -146,17 +146,25 @@
<br/> <br/>
<table class="forumline"> <table class="forumline">
<tr> <tr>
<th colspan="2">{L_VERSION_INFORMATION}</th> <th colspan="2">{L_VERSION_INFORMATION}</th>
</tr> </tr>
<tr> <tr>
<td class="row1" nowrap="nowrap" width="25%">{L_TP_VERSION}:</td> <td class="row1" nowrap="nowrap" width="25%">{L_TP_VERSION}:</td>
<td class="row2"><b>{$bb_cfg['tp_release_codename']} ({$bb_cfg['tp_version']})</b></td> <td class="row2"><b>{$bb_cfg['tp_release_codename']} ({$bb_cfg['tp_version']})</b></td>
</tr> </tr>
<tr> <tr>
<td class="row1" nowrap="nowrap" width="25%">{L_TP_RELEASE_DATE}:</td> <td class="row1" nowrap="nowrap" width="25%">{L_TP_RELEASE_DATE}:</td>
<td class="row2"><b>{$bb_cfg['tp_release_date']}</b></td> <td class="row2"><b>{$bb_cfg['tp_release_date']}</b></td>
</tr> </tr>
<!-- BEGIN updater -->
<!-- IF updater.UPDATE_AVAILABLE -->
<tr>
<td class="row1" nowrap="nowrap" width="25%"><b>{L_UPDATE_AVAILABLE}:</b></td>
<td class="row2"><b>{updater.NEW_VERSION_NUMBER}</b><!-- IF updater.NEW_VERSION_SIZE -->&nbsp;({L_SIZE}:&nbsp;{updater.NEW_VERSION_SIZE})<!-- ENDIF -->&nbsp;&middot;&nbsp;<a target="_blank" href="{updater.NEW_VERSION_DL_LINK}">{L_DOWNLOAD}</a></td>
</tr>
<!-- ENDIF -->
<!-- END updater -->
</table> </table>
<br/> <br/>