From 3db9095b78f1a750531b06bfe7938e5e73321f1e Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Fri, 7 Jun 2024 21:05:54 +0700 Subject: [PATCH] Minor improvements (#1490) * Minor improvements * Update CHANGELOG.md * Update functions.php * Update build_check_updates.php * Update index.php * Updated --- CHANGELOG.md | 4 +-- admin/index.php | 17 ++++++---- .../includes/cron/jobs/board_maintenance.php | 2 +- .../datastore/build_check_updates.php | 33 ++++++++++++------- library/includes/functions.php | 15 +++++---- styles/templates/admin/index.tpl | 2 +- 6 files changed, 43 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d2810fe1..abf63d5e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,9 +20,9 @@ - Demo mode: Allow registering torrents by default [\#1440](https://github.com/torrentpier/torrentpier/pull/1440) ([belomaxorka](https://github.com/belomaxorka)) - Temp: Removed showing forum description in `viewforum.php` [\#1465](https://github.com/torrentpier/torrentpier/pull/1465) ([belomaxorka](https://github.com/belomaxorka)) - Code refactoring [\#1441](https://github.com/torrentpier/torrentpier/pull/1441) ([belomaxorka](https://github.com/belomaxorka)) -- Minor improvements [\#1435](https://github.com/torrentpier/torrentpier/pull/1435), [\#1443](https://github.com/torrentpier/torrentpier/pull/1443), [\#1446](https://github.com/torrentpier/torrentpier/pull/1446), [\#1450](https://github.com/torrentpier/torrentpier/pull/1450), [\#1452](https://github.com/torrentpier/torrentpier/pull/1452), [\#1458](https://github.com/torrentpier/torrentpier/pull/1458), [\#1461](https://github.com/torrentpier/torrentpier/pull/1461), [\#1462](https://github.com/torrentpier/torrentpier/pull/1462), [\#1467](https://github.com/torrentpier/torrentpier/pull/1467), [\#1469](https://github.com/torrentpier/torrentpier/pull/1469), [\#1472](https://github.com/torrentpier/torrentpier/pull/1472), [\#1477](https://github.com/torrentpier/torrentpier/pull/1477), [\#1480](https://github.com/torrentpier/torrentpier/pull/1480), [\#1481](https://github.com/torrentpier/torrentpier/pull/1481), [\#1482](https://github.com/torrentpier/torrentpier/pull/1482), [\#1484](https://github.com/torrentpier/torrentpier/pull/1484) ([belomaxorka](https://github.com/belomaxorka)) +- Minor improvements [\#1435](https://github.com/torrentpier/torrentpier/pull/1435), [\#1443](https://github.com/torrentpier/torrentpier/pull/1443), [\#1446](https://github.com/torrentpier/torrentpier/pull/1446), [\#1450](https://github.com/torrentpier/torrentpier/pull/1450), [\#1452](https://github.com/torrentpier/torrentpier/pull/1452), [\#1458](https://github.com/torrentpier/torrentpier/pull/1458), [\#1461](https://github.com/torrentpier/torrentpier/pull/1461), [\#1462](https://github.com/torrentpier/torrentpier/pull/1462), [\#1467](https://github.com/torrentpier/torrentpier/pull/1467), [\#1469](https://github.com/torrentpier/torrentpier/pull/1469), [\#1472](https://github.com/torrentpier/torrentpier/pull/1472), [\#1477](https://github.com/torrentpier/torrentpier/pull/1477), [\#1480](https://github.com/torrentpier/torrentpier/pull/1480), [\#1481](https://github.com/torrentpier/torrentpier/pull/1481), [\#1482](https://github.com/torrentpier/torrentpier/pull/1482), [\#1484](https://github.com/torrentpier/torrentpier/pull/1484), [\#1490](https://github.com/torrentpier/torrentpier/pull/1490) ([belomaxorka](https://github.com/belomaxorka)) - Updated deps [\#1454](https://github.com/torrentpier/torrentpier/pull/1454), [\#1455](https://github.com/torrentpier/torrentpier/pull/1455), [\#1459](https://github.com/torrentpier/torrentpier/pull/1459), [\#1460](https://github.com/torrentpier/torrentpier/pull/1460), [\#1485](https://github.com/torrentpier/torrentpier/pull/1485), [\#1486](https://github.com/torrentpier/torrentpier/pull/1486) ([belomaxorka](https://github.com/belomaxorka)) -- New Crowdin updates [\#1444](https://github.com/torrentpier/torrentpier/pull/1444), [\#1447](https://github.com/torrentpier/torrentpier/pull/1447), [\#1453](https://github.com/torrentpier/torrentpier/pull/1453), [\#1468](https://github.com/torrentpier/torrentpier/pull/1468), [\#1473](https://github.com/torrentpier/torrentpier/pull/1473), [\#1476](https://github.com/torrentpier/torrentpier/pull/1476), [\#1479](https://github.com/torrentpier/torrentpier/pull/1479), [\#1487](https://github.com/torrentpier/torrentpier/pull/1487) ([Exileum](https://github.com/Exileum)) +- New Crowdin updates [\#1444](https://github.com/torrentpier/torrentpier/pull/1444), [\#1447](https://github.com/torrentpier/torrentpier/pull/1447), [\#1453](https://github.com/torrentpier/torrentpier/pull/1453), [\#1468](https://github.com/torrentpier/torrentpier/pull/1468), [\#1473](https://github.com/torrentpier/torrentpier/pull/1473), [\#1476](https://github.com/torrentpier/torrentpier/pull/1476), [\#1479](https://github.com/torrentpier/torrentpier/pull/1479), [\#1487](https://github.com/torrentpier/torrentpier/pull/1487), [\#1489](https://github.com/torrentpier/torrentpier/pull/1489) ([Exileum](https://github.com/Exileum)) ## [v2.4.2](https://github.com/torrentpier/torrentpier/tree/v2.4.2) (2024-03-30) [Full Changelog](https://github.com/torrentpier/torrentpier/compare/v2.4.1...v2.4.2) diff --git a/admin/index.php b/admin/index.php index 894ff61b2..1533395a2 100644 --- a/admin/index.php +++ b/admin/index.php @@ -83,13 +83,16 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { ]); // Check for updates - $template->assign_block_vars('updater', [ - 'UPDATE_AVAILABLE' => $update_data['available_update'], - 'NEW_VERSION_NUMBER' => $update_data['latest_version'], - 'NEW_VERSION_SIZE' => $update_data['latest_version_size'], - 'NEW_VERSION_DL_LINK' => $update_data['latest_version_dl_link'], - 'NEW_VERSION_LINK' => $update_data['latest_version_link'], - ]); + if (!empty($update_data)) { + $template->assign_block_vars('updater', [ + 'UPDATE_AVAILABLE' => $update_data['available_update'], + 'NEW_VERSION_NUMBER' => $update_data['latest_version'], + 'NEW_VERSION_SIZE' => $update_data['latest_version_size'], + 'NEW_VERSION_DL_LINK' => $update_data['latest_version_dl_link'], + 'NEW_VERSION_LINK' => $update_data['latest_version_link'], + 'NEW_VERSION_MD5' => $update_data['latest_version_checksum'] + ]); + } // Get forum statistics $total_posts = $stats['postcount']; diff --git a/library/includes/cron/jobs/board_maintenance.php b/library/includes/cron/jobs/board_maintenance.php index b89cc4904..1715ab295 100644 --- a/library/includes/cron/jobs/board_maintenance.php +++ b/library/includes/cron/jobs/board_maintenance.php @@ -60,4 +60,4 @@ if (IN_DEMO_MODE) { } // Check for updates -$datastore->rm('check_updates'); +$datastore->update('check_updates'); diff --git a/library/includes/datastore/build_check_updates.php b/library/includes/datastore/build_check_updates.php index 6f72f72e1..9ecb4f1aa 100644 --- a/library/includes/datastore/build_check_updates.php +++ b/library/includes/datastore/build_check_updates.php @@ -26,21 +26,30 @@ if ($updater_content !== false) { if (is_array($json_response) && !empty($json_response)) { $get_version = $json_response['tag_name']; $version_code_actual = (int)trim(str_replace(['.', 'v'], '', $get_version)); - $has_update = VERSION_CODE < $version_code_actual; - // Save current version & latest available - if ($has_update) { + // Has update! + if (VERSION_CODE < $version_code_actual) { + $latest_release_file = $json_response['assets'][0]['browser_download_url']; + + // Save current version & latest available file_write(VERSION_CODE . "\n" . $version_code_actual, UPDATER_FILE, replace_content: true); - } - // Build data array - $data = [ - 'available_update' => $has_update, - 'latest_version' => $get_version, - 'latest_version_size' => isset($json_response['assets'][0]['size']) ? humn_size($json_response['assets'][0]['size']) : false, - 'latest_version_dl_link' => $json_response['assets'][0]['browser_download_url'] ?? $json_response['html_url'], - 'latest_version_link' => $json_response['html_url'] - ]; + // Get MD5 checksum + $md5_file_checksum = ''; + if (isset($latest_release_file)) { + $md5_file_checksum = strtoupper(md5_file($latest_release_file)); + } + + // Build data array + $data = [ + 'available_update' => true, + 'latest_version' => $get_version, + 'latest_version_size' => isset($json_response['assets'][0]['size']) ? humn_size($json_response['assets'][0]['size']) : false, + 'latest_version_dl_link' => $latest_release_file ?? $json_response['html_url'], + 'latest_version_checksum' => $md5_file_checksum, + 'latest_version_link' => $json_response['html_url'] + ]; + } } $this->store('check_updates', $data); diff --git a/library/includes/functions.php b/library/includes/functions.php index 679dbfa6f..5a02439a1 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -2152,16 +2152,17 @@ function readUpdaterFile(): array|bool return false; } - $str = []; - if ($updaterFile = fopen(UPDATER_FILE, 'r')) { - while (!feof($updaterFile)) { - $str[] = trim(fgets($updaterFile)); - } + $updaterFile = new SplFileObject(UPDATER_FILE, 'r'); + $updaterFile->setFlags(SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE); + + $lines = []; + foreach ($updaterFile as $line) { + $lines[] = is_numeric($line) ? (int)$line : 0; } return [ - 'previous_version' => is_numeric($str[0]) ? (int)$str[0] : 0, - 'latest_version' => is_numeric($str[1]) ? (int)$str[1] : 0 + 'previous_version' => $lines[0], + 'latest_version' => $lines[1] ]; } diff --git a/styles/templates/admin/index.tpl b/styles/templates/admin/index.tpl index fd31ea8f6..a9e014470 100644 --- a/styles/templates/admin/index.tpl +++ b/styles/templates/admin/index.tpl @@ -161,7 +161,7 @@ {L_UPDATE_AVAILABLE}: - {updater.NEW_VERSION_NUMBER} ({L_SIZE}: {updater.NEW_VERSION_SIZE}) · {L_DOWNLOAD} · {L_CHANGELOG} + {updater.NEW_VERSION_NUMBER} ({L_SIZE}: {updater.NEW_VERSION_SIZE}) · {L_DOWNLOAD} · {L_CHANGELOG} · MD5: {updater.NEW_VERSION_MD5}