From 24dbd25d9b4fb1fac5df1abd75f6ddb40b580aef Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Wed, 24 Apr 2024 15:01:37 +0700 Subject: [PATCH] Minor improvements (#1452) * Minor improvements * Updated * Create updater.php * Revert "Create updater.php" This reverts commit be2f3d5006455be57405cce83ba9acc386a2ca32. * Revert "Updated" This reverts commit 6aae9339cd82aa3e6af146d28ec0481a6812ae01. * Updated * Update board_maintenance.php * Updated * Updated * Update build_check_updates.php * Updated * Update board_maintenance.php * Update functions.php * Updated * Update defines.php * Updated * Updated * Updater * Updated * Update .gitignore * Update * Update updater.php * Updated * Update tracker.php * Update .htaccess * Update tracker.php * Update tracker.tpl * Update CHANGELOG.md --- .gitignore | 1 + CHANGELOG.md | 5 ++- admin/index.php | 33 +++++--------- library/defines.php | 9 ++-- .../includes/cron/jobs/board_maintenance.php | 3 ++ .../datastore/build_check_updates.php | 45 +++++++++++++++++++ library/includes/functions.php | 25 +++++++++++ library/includes/init_bb.php | 3 ++ library/language/source/main.php | 2 +- src/Legacy/Datastore/Common.php | 1 + styles/templates/default/tracker.tpl | 12 ++--- tracker.php | 10 ++--- 12 files changed, 110 insertions(+), 39 deletions(-) create mode 100644 library/includes/datastore/build_check_updates.php diff --git a/.gitignore b/.gitignore index 4cc22e664..da122430a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ data/uploads internal_data/atom internal_data/cache internal_data/log +internal_data/updater.ver sitemap internal_data/triggers library/config.local.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c69bd53d..fa3faa040 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,9 @@ - Improved app debug [\#1438](https://github.com/torrentpier/torrentpier/pull/1438) ([belomaxorka](https://github.com/belomaxorka)) - Demo mode: Allow registering torrents by default [\#1440](https://github.com/torrentpier/torrentpier/pull/1440) ([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) ([belomaxorka](https://github.com/belomaxorka)) -- New Crowdin updates [\#1444](https://github.com/torrentpier/torrentpier/pull/1444), [\#1447](https://github.com/torrentpier/torrentpier/pull/1447) ([Exileum](https://github.com/Exileum)) +- 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) ([belomaxorka](https://github.com/belomaxorka)) +- Updated deps [\#1454](https://github.com/torrentpier/torrentpier/pull/1454), [\#1455](https://github.com/torrentpier/torrentpier/pull/1455) ([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) ([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 6945202c3..6e1dc782c 100644 --- a/admin/index.php +++ b/admin/index.php @@ -15,6 +15,12 @@ if (!$stats = $datastore->get('stats')) { $stats = $datastore->get('stats'); } +// Check for updates +if (!$update_data = $datastore->get('check_updates')) { + $datastore->update('check_updates'); + $update_data = $datastore->get('check_updates'); +} + // Generate relevant output if (isset($_GET['pane']) && $_GET['pane'] == 'left') { $module = []; @@ -77,27 +83,12 @@ 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'] - ]); - } + $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_link'] + ]); // Get forum statistics $total_posts = $stats['postcount']; diff --git a/library/defines.php b/library/defines.php index 994ee543f..a54b8438d 100644 --- a/library/defines.php +++ b/library/defines.php @@ -11,10 +11,6 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -// System -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) define('ADMIN_DIR', BB_PATH . '/admin'); define('DATA_DIR', BB_PATH . '/data'); @@ -32,6 +28,11 @@ define('SITEMAP_DIR', BB_PATH . '/sitemap'); define('IMAGES_DIR', BB_PATH . '/styles/images'); define('TEMPLATES_DIR', BB_PATH . '/styles/templates'); +// System +define('APP_NAME', 'TorrentPier'); +define('UPDATER_URL', 'https://api.github.com/repos/torrentpier/torrentpier/releases/latest'); +define('UPDATER_FILE', INT_DATA_DIR . '/updater.ver'); + // Templates define('ADMIN_TPL_DIR', TEMPLATES_DIR . '/admin/'); define('XS_USE_ISSET', '1'); diff --git a/library/includes/cron/jobs/board_maintenance.php b/library/includes/cron/jobs/board_maintenance.php index 3915a05a5..2736600ca 100644 --- a/library/includes/cron/jobs/board_maintenance.php +++ b/library/includes/cron/jobs/board_maintenance.php @@ -58,3 +58,6 @@ if (empty($bb_cfg['bt_announce_url'])) { if (IN_DEMO_MODE) { DB()->query("UPDATE " . BB_FORUMS . " SET allow_reg_tracker = 1 WHERE allow_reg_tracker = 0"); } + +// Check for updates +$datastore->rm('check_updates'); diff --git a/library/includes/datastore/build_check_updates.php b/library/includes/datastore/build_check_updates.php new file mode 100644 index 000000000..f9a2dd3f9 --- /dev/null +++ b/library/includes/datastore/build_check_updates.php @@ -0,0 +1,45 @@ + ['header' => 'User-Agent: TorrentPier Updater. With love!']]); +$updater_content = file_get_contents(UPDATER_URL, context: $context); + +$json_response = false; +if ($updater_content !== false) { + $json_response = json_decode(utf8_encode($updater_content), true); +} + +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) { + 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_link' => $json_response['assets'][0]['browser_download_url'] ?? $json_response['html_url'] + ]; +} + +$this->store('check_updates', $data); diff --git a/library/includes/functions.php b/library/includes/functions.php index 7c9441d86..c3e8617b2 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -2132,3 +2132,28 @@ function getBanInfo(int $userId = null): ?array return $bans[$userId] ?? []; } + +/** + * Read updater file + * + * @return array|bool + */ +function readUpdaterFile(): array|bool +{ + $str = []; + + if ($updaterFile = fopen(UPDATER_FILE, 'r')) { + while (!feof($updaterFile)) { + $str[] = trim(fgets($updaterFile)); + } + } + + if (!empty($str)) { + return [ + 'previous_version' => (int)$str[0], + 'latest_version' => (int)$str[1], + ]; + } + + return false; +} diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index e002fbbc0..fe2b47711 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -27,6 +27,9 @@ define('USER_IP', $user_ip); // Initialize demo mode define('IN_DEMO_MODE', env('APP_DEMO_MODE', false)); +// Version code +define('VERSION_CODE', (int)trim(str_replace(['.', 'v', ','], '', strstr($bb_cfg['tp_version'], '-', true)))); + /** * @param $contents * @return string diff --git a/library/language/source/main.php b/library/language/source/main.php index 4ff368aec..a19c9f43b 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -3014,7 +3014,7 @@ $lang['ATOM_GLOBAL_FEED'] = 'Global feed for all forums'; $lang['HASH_INVALID'] = 'Hash %s is invalid'; $lang['HASH_NOT_FOUND'] = 'Release with hash %s not found'; -$lang['TERMS_EMPTY_TEXT'] = '[align=center]The text of this page is edited at: %s. This line can see only administrators.[/align]'; +$lang['TERMS_EMPTY_TEXT'] = '[align=center]The text of this page is edited at: [url]%s[/url]. This line can see only administrators.[/align]'; $lang['TERMS_EXPLAIN'] = 'On this page, you can specify the text of the basic rules of the resource is displayed to users.'; $lang['TR_STATS'] = [ diff --git a/src/Legacy/Datastore/Common.php b/src/Legacy/Datastore/Common.php index 9e3b81fc2..5e2435b11 100644 --- a/src/Legacy/Datastore/Common.php +++ b/src/Legacy/Datastore/Common.php @@ -39,6 +39,7 @@ class Common */ public $known_items = [ 'cat_forums' => 'build_cat_forums.php', + 'check_updates' => 'build_check_updates.php', 'jumpbox' => 'build_cat_forums.php', 'viewtopic_forum_select' => 'build_cat_forums.php', 'latest_news' => 'build_cat_forums.php', diff --git a/styles/templates/default/tracker.tpl b/styles/templates/default/tracker.tpl index fea1e6a4b..cf5e8b5cf 100644 --- a/styles/templates/default/tracker.tpl +++ b/styles/templates/default/tracker.tpl @@ -251,12 +251,12 @@ ajax.callback.view_post = function(data) { - -
- {L_TORRENT_STATUS} -
{TOR_STATUS}
-
- + +
+ {L_TORRENT_STATUS} +
{TOR_STATUS}
+
+
{L_SHOW_COLUMN}
diff --git a/tracker.php b/tracker.php index 7ad87f548..d7714bc91 100644 --- a/tracker.php +++ b/tracker.php @@ -46,7 +46,7 @@ $lastvisit = (!IS_GUEST) ? $userdata['user_lastvisit'] : ''; $search_id = (isset($_GET['search_id']) && is_string($_GET['search_id'])) ? $_GET['search_id'] : ''; $session_id = $userdata['session_id']; -$status = $_POST['status'] ?? false; +$status = is_countable($_POST['status']) ? $_POST['status'] : false; $cat_forum = $tor_to_show = $search_in_forums_ary = []; $title_match_sql = $title_match_q = $search_in_forums_csv = ''; @@ -605,7 +605,7 @@ if ($allowed_forums) { if ($tor_type) { $SQL['WHERE'][] = "tor.tor_type IN(1,2)"; } - if (is_countable($status)) { + if ($status) { $SQL['WHERE'][] = "tor.tor_status IN(" . implode(', ', $status) . ")"; } @@ -819,13 +819,13 @@ $search_all_opt = '