From b37f2d36661865f7e140e43a74ae03d6dc0f22a9 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Sat, 22 Jun 2024 11:39:33 +0700 Subject: [PATCH] Minor improvements (#1523) * Minor improvements * Update CHANGELOG.md * Update composer.lock * Update User.php * Updated * Update Torrent.php * Update Template.php * Updated * Update SqlDb.php * Update Select.php * Updated * Updated * Update viewtopic.tpl * Updated * Update viewforum.tpl --- CHANGELOG.md | 2 +- admin/stats/tracker.php | 4 +- composer.lock | 105 ++++++------------------- library/config.php | 1 + library/language/source/main.php | 1 + src/Helpers/IPHelper.php | 2 - src/Legacy/Cache/APCu.php | 2 - src/Legacy/Cache/Common.php | 2 - src/Legacy/Cache/File.php | 2 - src/Legacy/Cache/Memcache.php | 2 - src/Legacy/Cache/Redis.php | 2 - src/Legacy/Cache/SqliteCommon.php | 1 - src/Legacy/Common/User.php | 47 +++++------ src/Legacy/Datastore/APCu.php | 2 - src/Legacy/Datastore/Common.php | 2 - src/Legacy/Datastore/File.php | 2 - src/Legacy/Datastore/Memcache.php | 2 - src/Legacy/Datastore/Redis.php | 2 - src/Legacy/Datastore/SqliteCommon.php | 1 - src/Legacy/Select.php | 12 +-- src/Legacy/SqlDb.php | 76 +++--------------- src/Legacy/Template.php | 36 ++++----- src/Legacy/Torrent.php | 26 +++--- src/Legacy/TorrentFileList.php | 8 +- src/Legacy/WordsRate.php | 2 +- styles/templates/default/tracker.tpl | 4 +- styles/templates/default/viewforum.tpl | 3 + styles/templates/default/viewtopic.tpl | 3 + tracker.php | 2 +- 29 files changed, 116 insertions(+), 240 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5283f3a44..a87b7503a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - Some security enhancements (Part 2) [\#1505](https://github.com/torrentpier/torrentpier/pull/1505) ([belomaxorka](https://github.com/belomaxorka)) - Some improvements for integrity checker [\#1501](https://github.com/torrentpier/torrentpier/pull/1501) ([belomaxorka](https://github.com/belomaxorka)) - Hide vote button in topic if guest [\#1507](https://github.com/torrentpier/torrentpier/pull/1507) ([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) ([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) ([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)) ## [v2.4.3](https://github.com/torrentpier/torrentpier/tree/v2.4.3) (2024-06-09) diff --git a/admin/stats/tracker.php b/admin/stats/tracker.php index 0f9bcd098..08130ee70 100644 --- a/admin/stats/tracker.php +++ b/admin/stats/tracker.php @@ -52,7 +52,7 @@ $stat += DB()->fetch_row('SELECT COUNT(DISTINCT user_id) AS u_bt_active FROM ' . // All bt-users $stat += DB()->fetch_row('SELECT COUNT(*) AS u_bt_all FROM ' . BB_BT_USERS); // All bb-users -$stat += DB()->fetch_row('SELECT COUNT(*) AS u_bb_all FROM ' . BB_USERS); +$stat += DB()->fetch_row('SELECT COUNT(*) AS u_bb_all FROM ' . BB_USERS . ' WHERE user_id != ' . BOT_UID); // Active torrents $stat += DB()->fetch_row('SELECT COUNT(DISTINCT topic_id) AS tor_active FROM ' . TMP_TRACKER_TABLE); // With seeder @@ -70,7 +70,7 @@ foreach ($peers_in_last_minutes as $t) { } // Last xx seconds $peers_in_last_sec = []; -$rowset = DB()->fetch_rowset('SELECT COUNT(*) AS peers FROM ' . TMP_TRACKER_TABLE . ' GROUP BY update_time ORDER BY update_time DESC LIMIT ' . $peers_in_last_sec_limit); +$rowset = DB()->fetch_rowset('SELECT COUNT(*) AS peers FROM ' . TMP_TRACKER_TABLE . ' ORDER BY update_time DESC LIMIT ' . $peers_in_last_sec_limit); foreach ($rowset as $cnt => $row) { $peers_in_last_sec[] = sprintf('%3s', $row['peers']) . (($cnt && !(++$cnt % 15)) ? " \n" : ''); } diff --git a/composer.lock b/composer.lock index 85036aec4..91ea2998b 100644 --- a/composer.lock +++ b/composer.lock @@ -1521,16 +1521,16 @@ }, { "name": "nikic/iter", - "version": "v2.4.0", + "version": "v2.4.1", "source": { "type": "git", "url": "https://github.com/nikic/iter.git", - "reference": "09cd930fa9ff55747f34c7184532a5a1bd2385b1" + "reference": "3f031ae08d82c4394410e76b88b441331a6fa15f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/iter/zipball/09cd930fa9ff55747f34c7184532a5a1bd2385b1", - "reference": "09cd930fa9ff55747f34c7184532a5a1bd2385b1", + "url": "https://api.github.com/repos/nikic/iter/zipball/3f031ae08d82c4394410e76b88b441331a6fa15f", + "reference": "3f031ae08d82c4394410e76b88b441331a6fa15f", "shasum": "" }, "require": { @@ -1567,9 +1567,9 @@ ], "support": { "issues": "https://github.com/nikic/iter/issues", - "source": "https://github.com/nikic/iter/tree/v2.4.0" + "source": "https://github.com/nikic/iter/tree/v2.4.1" }, - "time": "2023-12-10T20:43:19+00:00" + "time": "2024-03-19T20:45:05+00:00" }, { "name": "phpoption/phpoption", @@ -2335,23 +2335,25 @@ }, { "name": "symfony/filesystem", - "version": "v6.4.7", + "version": "v6.4.8", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "78dde75f8f6dbbca4ec436a4b0087f7af02076d4" + "reference": "4d37529150e7081c51b3c5d5718c55a04a9503f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/78dde75f8f6dbbca4ec436a4b0087f7af02076d4", - "reference": "78dde75f8f6dbbca4ec436a4b0087f7af02076d4", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/4d37529150e7081c51b3c5d5718c55a04a9503f3", + "reference": "4d37529150e7081c51b3c5d5718c55a04a9503f3", "shasum": "" }, "require": { "php": ">=8.1", "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.8", - "symfony/process": "^5.4|^6.4" + "symfony/polyfill-mbstring": "~1.8" + }, + "require-dev": { + "symfony/process": "^5.4|^6.4|^7.0" }, "type": "library", "autoload": { @@ -2379,7 +2381,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v6.4.7" + "source": "https://github.com/symfony/filesystem/tree/v6.4.8" }, "funding": [ { @@ -2395,20 +2397,20 @@ "type": "tidelift" } ], - "time": "2024-04-18T09:22:46+00:00" + "time": "2024-05-31T14:49:08+00:00" }, { "name": "symfony/finder", - "version": "v6.4.7", + "version": "v6.4.8", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "511c48990be17358c23bf45c5d71ab85d40fb764" + "reference": "3ef977a43883215d560a2cecb82ec8e62131471c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/511c48990be17358c23bf45c5d71ab85d40fb764", - "reference": "511c48990be17358c23bf45c5d71ab85d40fb764", + "url": "https://api.github.com/repos/symfony/finder/zipball/3ef977a43883215d560a2cecb82ec8e62131471c", + "reference": "3ef977a43883215d560a2cecb82ec8e62131471c", "shasum": "" }, "require": { @@ -2443,7 +2445,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v6.4.7" + "source": "https://github.com/symfony/finder/tree/v6.4.8" }, "funding": [ { @@ -2459,7 +2461,7 @@ "type": "tidelift" } ], - "time": "2024-04-23T10:36:43+00:00" + "time": "2024-05-31T14:49:08+00:00" }, { "name": "symfony/mailer", @@ -3103,67 +3105,6 @@ ], "time": "2024-01-29T20:11:03+00:00" }, - { - "name": "symfony/process", - "version": "v6.4.7", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "cdb1c81c145fd5aa9b0038bab694035020943381" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/cdb1c81c145fd5aa9b0038bab694035020943381", - "reference": "cdb1c81c145fd5aa9b0038bab694035020943381", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Executes commands in sub-processes", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/process/tree/v6.4.7" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-04-18T09:22:46+00:00" - }, { "name": "symfony/service-contracts", "version": "v3.5.0", @@ -3428,5 +3369,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/library/config.php b/library/config.php index 1ffbecab6..98476cecf 100644 --- a/library/config.php +++ b/library/config.php @@ -693,6 +693,7 @@ $bb_cfg['tracker'] = [ 'retracker_host' => 'http://retracker.local/announce', 'guest_tracker' => true, 'search_by_tor_status' => true, + 'random_release_button' => true, 'freeleech' => false, // freeleech mode (If enabled, then disable "gold_silver_enabled") 'gold_silver_enabled' => true, // golden / silver days mode (If enabled, then disable "freeleech") 'hybrid_stat_protocol' => 1, // For hybrid torrents there are two identical requests sent by clients, for counting stats we gotta choose one, you can change this to '2' in future, when v1 protocol is outdated diff --git a/library/language/source/main.php b/library/language/source/main.php index e37ad6dcb..3b99e25ec 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -61,6 +61,7 @@ $lang['DISABLED'] = 'Disabled'; $lang['ERROR'] = 'Error'; $lang['SELECT_ACTION'] = 'Select action'; $lang['CLEAR'] = 'Clear'; +$lang['MOVE_TO_TOP'] = 'Move to top'; $lang['UNKNOWN'] = 'Unknown'; $lang['NEXT_PAGE'] = 'Next'; diff --git a/src/Helpers/IPHelper.php b/src/Helpers/IPHelper.php index 47a6c3936..6ae99d1b4 100644 --- a/src/Helpers/IPHelper.php +++ b/src/Helpers/IPHelper.php @@ -11,8 +11,6 @@ namespace TorrentPier\Helpers; use Longman\IPTools\Ip; -use function strlen; - /** * Class IPHelper * @package TorrentPier\Helpers diff --git a/src/Legacy/Cache/APCu.php b/src/Legacy/Cache/APCu.php index 7678629ab..1b3e6cab1 100644 --- a/src/Legacy/Cache/APCu.php +++ b/src/Legacy/Cache/APCu.php @@ -9,8 +9,6 @@ namespace TorrentPier\Legacy\Cache; -use TorrentPier\Dev; - /** * Class APCu * @package TorrentPier\Legacy\Cache diff --git a/src/Legacy/Cache/Common.php b/src/Legacy/Cache/Common.php index a9b473542..03029b512 100644 --- a/src/Legacy/Cache/Common.php +++ b/src/Legacy/Cache/Common.php @@ -9,8 +9,6 @@ namespace TorrentPier\Legacy\Cache; -use TorrentPier\Dev; - /** * Class Common * @package TorrentPier\Legacy\Cache diff --git a/src/Legacy/Cache/File.php b/src/Legacy/Cache/File.php index 81ed8cde0..18a913937 100644 --- a/src/Legacy/Cache/File.php +++ b/src/Legacy/Cache/File.php @@ -9,8 +9,6 @@ namespace TorrentPier\Legacy\Cache; -use TorrentPier\Dev; - /** * Class File * @package TorrentPier\Legacy\Cache diff --git a/src/Legacy/Cache/Memcache.php b/src/Legacy/Cache/Memcache.php index 816c683dd..cada1f7d7 100644 --- a/src/Legacy/Cache/Memcache.php +++ b/src/Legacy/Cache/Memcache.php @@ -9,8 +9,6 @@ namespace TorrentPier\Legacy\Cache; -use TorrentPier\Dev; - /** * Class Memcache * @package TorrentPier\Legacy\Cache diff --git a/src/Legacy/Cache/Redis.php b/src/Legacy/Cache/Redis.php index e93eb7cfe..3b45e06e5 100644 --- a/src/Legacy/Cache/Redis.php +++ b/src/Legacy/Cache/Redis.php @@ -9,8 +9,6 @@ namespace TorrentPier\Legacy\Cache; -use TorrentPier\Dev; - /** * Class Redis * @package TorrentPier\Legacy\Cache diff --git a/src/Legacy/Cache/SqliteCommon.php b/src/Legacy/Cache/SqliteCommon.php index a7e3cb37d..fa8033474 100644 --- a/src/Legacy/Cache/SqliteCommon.php +++ b/src/Legacy/Cache/SqliteCommon.php @@ -10,7 +10,6 @@ namespace TorrentPier\Legacy\Cache; use SQLite3; -use TorrentPier\Dev; /** * Class SqliteCommon diff --git a/src/Legacy/Common/User.php b/src/Legacy/Common/User.php index ac5ed2ac1..26d0bbc2d 100644 --- a/src/Legacy/Common/User.php +++ b/src/Legacy/Common/User.php @@ -10,8 +10,11 @@ namespace TorrentPier\Legacy\Common; use TorrentPier\Legacy\DateDelta; +use TorrentPier\Legacy\Torrent; use TorrentPier\Sessions; +use Exception; + /** * Class User * @package TorrentPier\Legacy\Common @@ -161,8 +164,8 @@ class User $ip_check_u = substr(USER_IP, 0, 6); if ($ip_check_s == $ip_check_u) { - if ($this->data['user_id'] != GUEST_UID && \defined('IN_ADMIN')) { - \define('SID_GET', "sid={$this->data['session_id']}"); + if ($this->data['user_id'] != GUEST_UID && defined('IN_ADMIN')) { + define('SID_GET', "sid={$this->data['session_id']}"); } $session_id = $this->sessiondata['sid'] = $this->data['session_id']; @@ -200,13 +203,13 @@ class User $this->session_create($userdata, true); } - \define('IS_GUEST', !$this->data['session_logged_in']); - \define('IS_ADMIN', !IS_GUEST && (int)$this->data['user_level'] === ADMIN); - \define('IS_MOD', !IS_GUEST && (int)$this->data['user_level'] === MOD); - \define('IS_GROUP_MEMBER', !IS_GUEST && (int)$this->data['user_level'] === GROUP_MEMBER); - \define('IS_USER', !IS_GUEST && (int)$this->data['user_level'] === USER); - \define('IS_SUPER_ADMIN', IS_ADMIN && isset($bb_cfg['super_admins'][$this->data['user_id']])); - \define('IS_AM', IS_ADMIN || IS_MOD); + define('IS_GUEST', !$this->data['session_logged_in']); + define('IS_ADMIN', !IS_GUEST && (int)$this->data['user_level'] === ADMIN); + define('IS_MOD', !IS_GUEST && (int)$this->data['user_level'] === MOD); + define('IS_GROUP_MEMBER', !IS_GUEST && (int)$this->data['user_level'] === GROUP_MEMBER); + define('IS_USER', !IS_GUEST && (int)$this->data['user_level'] === USER); + define('IS_SUPER_ADMIN', IS_ADMIN && isset($bb_cfg['super_admins'][$this->data['user_id']])); + define('IS_AM', IS_ADMIN || IS_MOD); $this->set_shortcuts(); @@ -255,8 +258,8 @@ class User $mod_admin_session = ((int)$this->data['user_level'] === ADMIN || (int)$this->data['user_level'] === MOD); // Generate passkey - if (!\TorrentPier\Legacy\Torrent::getPasskey($this->data['user_id'])) { - if (!\TorrentPier\Legacy\Torrent::generate_passkey($this->data['user_id'], true)) { + if (!Torrent::getPasskey($this->data['user_id'])) { + if (!Torrent::generate_passkey($this->data['user_id'], true)) { bb_simple_die('Could not generate passkey'); } } @@ -289,7 +292,7 @@ class User if (!$session_time = $this->data['user_session_time']) { $last_visit = TIMENOW; - \define('FIRST_LOGON', true); + define('FIRST_LOGON', true); } elseif ($session_time < (TIMENOW - $bb_cfg['last_visit_update_intrv'])) { $last_visit = max($session_time, (TIMENOW - 86400 * $bb_cfg['max_last_visit_days'])); } @@ -329,8 +332,8 @@ class User $this->set_session_cookies($user_id); - if ($login && (\defined('IN_ADMIN') || $mod_admin_session)) { - \define('SID_GET', "sid=$session_id"); + if ($login && (defined('IN_ADMIN') || $mod_admin_session)) { + define('SID_GET', "sid=$session_id"); } Sessions::cache_set_userdata($this->data); @@ -527,7 +530,7 @@ class User * @param bool $create_new * * @return string - * @throws \Exception + * @throws Exception */ public function create_autologin_id(array $userdata, bool $create_new = true): string { @@ -565,7 +568,7 @@ class User { global $bb_cfg, $theme, $source_lang, $DeltaTime; - if (\defined('LANG_DIR')) { + if (defined('LANG_DIR')) { return; } // prevent multiple calling @@ -576,13 +579,13 @@ class User } } - \define('DEFAULT_LANG_DIR', LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/'); - \define('SOURCE_LANG_DIR', LANG_ROOT_DIR . '/source/'); + define('DEFAULT_LANG_DIR', LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/'); + define('SOURCE_LANG_DIR', LANG_ROOT_DIR . '/source/'); if ($this->data['user_id'] != GUEST_UID) { if ($this->data['user_lang'] && $this->data['user_lang'] != $bb_cfg['default_lang']) { $bb_cfg['default_lang'] = basename($this->data['user_lang']); - \define('LANG_DIR', LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/'); + define('LANG_DIR', LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/'); } if (isset($this->data['user_timezone'])) { @@ -593,8 +596,8 @@ class User $this->data['user_lang'] = $bb_cfg['default_lang']; $this->data['user_timezone'] = $bb_cfg['board_timezone']; - if (!\defined('LANG_DIR')) { - \define('LANG_DIR', DEFAULT_LANG_DIR); + if (!defined('LANG_DIR')) { + define('LANG_DIR', DEFAULT_LANG_DIR); } /** Temporary place source language to the global */ @@ -663,7 +666,7 @@ class User } elseif (!empty($_COOKIE['opt_js'])) { $opt_js = json_decode($_COOKIE['opt_js'], true, 512, JSON_THROW_ON_ERROR); - if (\is_array($opt_js)) { + if (is_array($opt_js)) { $this->opt_js = array_merge($this->opt_js, $opt_js); } } diff --git a/src/Legacy/Datastore/APCu.php b/src/Legacy/Datastore/APCu.php index 61f1ca279..08ec2c00e 100644 --- a/src/Legacy/Datastore/APCu.php +++ b/src/Legacy/Datastore/APCu.php @@ -9,8 +9,6 @@ namespace TorrentPier\Legacy\Datastore; -use TorrentPier\Dev; - /** * Class APCu * @package TorrentPier\Legacy\Datastore diff --git a/src/Legacy/Datastore/Common.php b/src/Legacy/Datastore/Common.php index 7774f27d0..d125575bd 100644 --- a/src/Legacy/Datastore/Common.php +++ b/src/Legacy/Datastore/Common.php @@ -9,8 +9,6 @@ namespace TorrentPier\Legacy\Datastore; -use TorrentPier\Dev; - /** * Class Common * @package TorrentPier\Legacy\Datastore diff --git a/src/Legacy/Datastore/File.php b/src/Legacy/Datastore/File.php index d27667c6b..27f2ffea2 100644 --- a/src/Legacy/Datastore/File.php +++ b/src/Legacy/Datastore/File.php @@ -9,8 +9,6 @@ namespace TorrentPier\Legacy\Datastore; -use TorrentPier\Dev; - /** * Class File * @package TorrentPier\Legacy\Datastore diff --git a/src/Legacy/Datastore/Memcache.php b/src/Legacy/Datastore/Memcache.php index 2203a8f69..f561d50b7 100644 --- a/src/Legacy/Datastore/Memcache.php +++ b/src/Legacy/Datastore/Memcache.php @@ -9,8 +9,6 @@ namespace TorrentPier\Legacy\Datastore; -use TorrentPier\Dev; - /** * Class Memcache * @package TorrentPier\Legacy\Datastore diff --git a/src/Legacy/Datastore/Redis.php b/src/Legacy/Datastore/Redis.php index 8a7175bd9..35b662603 100644 --- a/src/Legacy/Datastore/Redis.php +++ b/src/Legacy/Datastore/Redis.php @@ -9,8 +9,6 @@ namespace TorrentPier\Legacy\Datastore; -use TorrentPier\Dev; - /** * Class Redis * @package TorrentPier\Legacy\Datastore diff --git a/src/Legacy/Datastore/SqliteCommon.php b/src/Legacy/Datastore/SqliteCommon.php index 2acbfe399..717e31a19 100644 --- a/src/Legacy/Datastore/SqliteCommon.php +++ b/src/Legacy/Datastore/SqliteCommon.php @@ -10,7 +10,6 @@ namespace TorrentPier\Legacy\Datastore; use SQLite3; -use TorrentPier\Dev; /** * Class SqliteCommon diff --git a/src/Legacy/Select.php b/src/Legacy/Select.php index 9f3d94a5d..267f350f3 100644 --- a/src/Legacy/Select.php +++ b/src/Legacy/Select.php @@ -20,13 +20,13 @@ class Select * * @param string $default_lang * @param string $select_name - * @return string + * + * @return mixed */ - public static function language(string $default_lang, string $select_name = 'language') + public static function language(string $default_lang, string $select_name = 'language'): mixed { global $bb_cfg; - $lang_default = reset($bb_cfg['lang']); $lang_select = ''; - return ($x > 1) ? $lang_select : $lang_default['name']; + return ($x > 1) ? $lang_select : reset($bb_cfg['lang']); } /** @@ -73,9 +73,9 @@ class Select * @param string $default_style * @param string $select_name * - * @return string + * @return mixed */ - public static function template(string $default_style, string $select_name = 'tpl_name') + public static function template(string $default_style, string $select_name = 'tpl_name'): mixed { global $bb_cfg; diff --git a/src/Legacy/SqlDb.php b/src/Legacy/SqlDb.php index 93a69c60f..00362f4a6 100644 --- a/src/Legacy/SqlDb.php +++ b/src/Legacy/SqlDb.php @@ -11,8 +11,6 @@ namespace TorrentPier\Legacy; use mysqli_result; -use TorrentPier\Dev; - /** * Class SqlDb * @package TorrentPier\Legacy @@ -125,7 +123,7 @@ class SqlDb if (!$this->link) { $this->init(); } - if (\is_array($query)) { + if (is_array($query)) { $query = $this->build_sql($query); } $query = '/* ' . $this->debug_find_source() . ' */ ' . $query; @@ -191,43 +189,6 @@ class SqlDb return mysqli_affected_rows($this->link); } - /** - * Fetch current field - * - * @param $field - * @param int $rownum - * @param int $query_id - * - * @return bool - */ - public function sql_fetchfield($field, $rownum = -1, $query_id = 0) - { - $result = null; - if (!$query_id) { - $query_id = $this->query_result; - } - if ($query_id) { - if ($rownum > -1) { - $result = $this->sql_result($query_id, $rownum, $field); - } else { - if (empty($this->row[$query_id]) && empty($this->rowset[$query_id])) { - if ($this->sql_fetchrow()) { - $result = $this->row[$query_id][$field]; - } - } else { - if ($this->rowset[$query_id]) { - $result = $this->rowset[$query_id][0][$field]; - } elseif ($this->row[$query_id]) { - $result = $this->row[$query_id][$field]; - } - } - } - return $result; - } - - return false; - } - /** * @param mysqli_result $res * @param $row @@ -324,23 +285,6 @@ class SqlDb return $this->sql_fetchrowset($result, $field_name); } - /** - * Fetch all rows WRAPPER (with error handling) - * - * @param $query - * @param string $field_name - * - * @return array - */ - public function fetch_all($query, $field_name = '') - { - if (!$result = $this->sql_query($query)) { - $this->trigger_error(); - } - - return $this->sql_fetchrowset($result, $field_name); - } - /** * Get last inserted id after insert statement * @@ -386,13 +330,13 @@ class SqlDb } switch (true) { - case \is_string($v): + case is_string($v): return "'" . $this->escape_string($v) . "'"; - case \is_int($v): + case is_int($v): return (string)$v; - case \is_bool($v): + case is_bool($v): return ($v) ? '1' : '0'; - case \is_float($v): + case is_float($v): return "'$v'"; case null === $v: return 'NULL'; @@ -434,7 +378,7 @@ class SqlDb $dont_escape = $data_already_escaped; $check_type = $check_data_type_in_escape; - if (empty($input_ary) || !\is_array($input_ary)) { + if (empty($input_ary) || !is_array($input_ary)) { $this->trigger_error(__FUNCTION__ . ' - wrong params: $input_ary'); } @@ -764,8 +708,8 @@ class SqlDb } } - if (!\defined('IN_FIRST_SLOW_QUERY')) { - \define('IN_FIRST_SLOW_QUERY', true); + if (!defined('IN_FIRST_SLOW_QUERY')) { + define('IN_FIRST_SLOW_QUERY', true); } CACHE('bb_cache')->set('dont_log_slow_query', $new_priority, $ignoring_time); @@ -899,7 +843,7 @@ class SqlDb $msg = implode(LOG_SEPR, $msg); $msg .= ($info = $this->query_info()) ? ' # ' . $info : ''; $msg .= ' # ' . $this->debug_find_source() . ' '; - $msg .= \defined('IN_CRON') ? 'cron' : basename($_SERVER['REQUEST_URI']); + $msg .= defined('IN_CRON') ? 'cron' : basename($_SERVER['REQUEST_URI']); bb_log($msg . LOG_LF, $log_file); } @@ -910,7 +854,7 @@ class SqlDb */ public function log_slow_query($log_file = 'sql_slow_bb') { - if (!\defined('IN_FIRST_SLOW_QUERY') && CACHE('bb_cache')->get('dont_log_slow_query')) { + if (!defined('IN_FIRST_SLOW_QUERY') && CACHE('bb_cache')->get('dont_log_slow_query')) { return; } $this->log_query($log_file); diff --git a/src/Legacy/Template.php b/src/Legacy/Template.php index 9a1c3b450..63a16b8b2 100644 --- a/src/Legacy/Template.php +++ b/src/Legacy/Template.php @@ -271,7 +271,7 @@ class Template die("Template->loadfile(): No files found for handle $handle"); } $this->xs_startup(); - $force_recompile = empty($this->uncompiled_code[$handle]) ? false : true; + $force_recompile = !empty($this->uncompiled_code[$handle]); // checking if php file exists. if (!empty($this->files_cache[$handle]) && !$force_recompile) { // php file exists - running it instead of tpl @@ -313,12 +313,12 @@ class Template if (str_contains($blockname, '.')) { // Nested block. $blocks = explode('.', $blockname); - $blockcount = \count($blocks) - 1; + $blockcount = count($blocks) - 1; $str = &$this->_tpldata; for ($i = 0; $i < $blockcount; $i++) { $str = &$str[$blocks[$i] . '.']; - $str = &$str[(is_countable($str) ? \count($str) : 0) - 1]; + $str = &$str[(is_countable($str) ? count($str) : 0) - 1]; } // Now we add the block that we're actually assigning to. // We're adding a new iteration to this block with the given @@ -441,7 +441,7 @@ class Template { // Get an array of the blocks involved. $blocks = explode('.', $blockname); - $blockcount = \count($blocks) - 1; + $blockcount = count($blocks) - 1; if ($include_last_iterator) { return '$' . $blocks[$blockcount] . '_item'; } @@ -467,7 +467,7 @@ class Template // Break it up into lines and put " -->" back. $code_lines = explode(' -->', $code); - $count = \count($code_lines); + $count = count($code_lines); for ($i = 0; $i < ($count - 1); $i++) { $code_lines[$i] .= ' -->'; } @@ -486,7 +486,7 @@ class Template // replace all short php tags $new_code = []; - $line_count = \count($code_lines); + $line_count = count($code_lines); for ($i = 0; $i < $line_count; $i++) { $line = $code_lines[$i]; $pos = strpos($line, ' 0) { + if (count($search) > 0) { $code = str_replace($search, $replace, $code); } // This will handle the remaining root-level varrefs @@ -788,7 +788,7 @@ class Template [^\s(),]+)/x', $tag_args, $match); $tokens = $match[0]; - $tokens_cnt = is_countable($tokens) ? \count($tokens) : 0; + $tokens_cnt = is_countable($tokens) ? count($tokens) : 0; $is_arg_stack = []; for ($i = 0; $i < $tokens_cnt; $i++) { @@ -845,11 +845,11 @@ class Template case 'is': $is_arg_start = ($tokens[$i - 1] == ')') ? array_pop($is_arg_stack) : $i - 1; - $is_arg = implode(' ', \array_slice($tokens, $is_arg_start, $i - $is_arg_start)); + $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start)); - $new_tokens = $this->_parse_is_expr($is_arg, \array_slice($tokens, $i + 1)); + $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i + 1)); - array_splice($tokens, $is_arg_start, is_countable($tokens) ? \count($tokens) : 0, $new_tokens); + array_splice($tokens, $is_arg_start, is_countable($tokens) ? count($tokens) : 0, $new_tokens); $i = $is_arg_start; break; @@ -995,7 +995,7 @@ class Template // adding current template $tpl = $this->root . '/'; if (str_starts_with($tpl, './')) { - $tpl = substr($tpl, 2, \strlen($tpl)); + $tpl = substr($tpl, 2, strlen($tpl)); } $this->vars['TEMPLATE'] ??= $tpl; $this->vars['TEMPLATE_NAME'] ??= $this->tpl; diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index 153706ce7..851ff21d1 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -9,6 +9,10 @@ namespace TorrentPier\Legacy; +use Arokettu\Bencode\Bencode; +use Arokettu\Bencode\Bencode\Collection; +use Exception; + /** * Class Torrent * @package TorrentPier\Legacy @@ -318,15 +322,15 @@ class Torrent $file_contents = file_get_contents($filename); try { - $tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY); - } catch (\Exception $e) { + $tor = Bencode::decode($file_contents, dictType: Collection::ARRAY); + } catch (Exception $e) { self::torrent_error_exit(htmlCHR("{$lang['TORFILE_INVALID']}: {$e->getMessage()}")); } if ($bb_cfg['bt_disable_dht']) { $tor['info']['private'] = (int)1; $fp = fopen($filename, 'wb+'); - fwrite($fp, \Arokettu\Bencode\Bencode::encode($tor)); + fwrite($fp, Bencode::encode($tor)); fclose($fp); } @@ -337,7 +341,7 @@ class Torrent $ann = $tor['announce'] ?? ''; $announce_urls['main_url'] = $bb_cfg['bt_announce_url']; - if (!$ann || !\in_array($ann, $announce_urls)) { + if (!$ann || !in_array($ann, $announce_urls)) { $msg = sprintf($lang['INVALID_ANN_URL'], htmlspecialchars($ann), $announce_urls['main_url']); self::torrent_error_exit($msg); } @@ -371,14 +375,14 @@ class Torrent // Getting info_hash v1 if (isset($bt_v1)) { - $info_hash = hash('sha1', \Arokettu\Bencode\Bencode::encode($info), true); + $info_hash = hash('sha1', Bencode::encode($info), true); $info_hash_sql = rtrim(DB()->escape($info_hash), ' '); $info_hash_where = "WHERE info_hash = '$info_hash_sql'"; } // Getting info_hash v2 if (isset($bt_v2)) { - $info_hash_v2 = hash('sha256', \Arokettu\Bencode\Bencode::encode($info), true); + $info_hash_v2 = hash('sha256', Bencode::encode($info), true); $info_hash_v2_sql = rtrim(DB()->escape($info_hash_v2), ' '); $info_hash_where = "WHERE info_hash_v2 = '$info_hash_v2_sql'"; } @@ -398,7 +402,7 @@ class Torrent if (isset($info['length'])) { $totallen = (float)$info['length']; - } elseif (isset($bt_v1, $info['files']) && !isset($bt_v2) && \is_array($info['files'])) { + } elseif (isset($bt_v1, $info['files']) && !isset($bt_v2) && is_array($info['files'])) { foreach ($info['files'] as $fn => $f) { // Exclude padding files if (!isset($f['attr']) || $f['attr'] !== 'p') { @@ -561,8 +565,8 @@ class Torrent // Torrent decoding $file_contents = file_get_contents($filename); try { - $tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY); - } catch (\Exception $e) { + $tor = Bencode::decode($file_contents, dictType: Collection::ARRAY); + } catch (Exception $e) { bb_die(htmlCHR("{$lang['TORFILE_INVALID']}: {$e->getMessage()}")); } @@ -639,13 +643,13 @@ class Torrent unset($tor['comment.utf-8']); // Send torrent - $output = \Arokettu\Bencode\Bencode::encode($tor); + $output = Bencode::encode($tor); $dl_fname = html_entity_decode($topic_title, ENT_QUOTES, 'UTF-8') . ' [' . $bb_cfg['server_name'] . '-' . $topic_id . ']' . '.' . TORRENT_EXT; if (!empty($_COOKIE['explain'])) { $out = "attach path: $filename

"; - $tor['info']['pieces'] = '[...] ' . \strlen($tor['info']['pieces']) . ' bytes'; + $tor['info']['pieces'] = '[...] ' . strlen($tor['info']['pieces']) . ' bytes'; $out .= print_r($tor, true); bb_die("
$out
"); } diff --git a/src/Legacy/TorrentFileList.php b/src/Legacy/TorrentFileList.php index 964c14b22..57f10a855 100644 --- a/src/Legacy/TorrentFileList.php +++ b/src/Legacy/TorrentFileList.php @@ -79,7 +79,7 @@ class TorrentFileList $info['name'] =& $info['name.utf-8']; } - if (isset($info['files']) && \is_array($info['files'])) { + if (isset($info['files']) && is_array($info['files'])) { $this->root_dir = isset($info['name']) ? clean_tor_dirname($info['name']) : '...'; $this->multiple = true; @@ -87,7 +87,7 @@ class TorrentFileList if (isset($f['path.utf-8'])) { $f['path'] =& $f['path.utf-8']; } - if (!isset($f['path']) || !\is_array($f['path'])) { + if (!isset($f['path']) || !is_array($f['path'])) { continue; } // Exclude padding files @@ -101,7 +101,7 @@ class TorrentFileList } $length = isset($f['length']) ? (float)$f['length'] : 0; - $subdir_count = \count($f['path']) - 1; + $subdir_count = count($f['path']) - 1; if ($subdir_count > 0) { $name = array_pop($f['path']); @@ -116,7 +116,7 @@ class TorrentFileList $cur_files_ary =& $cur_files_ary[$subdir]; if ($j === $subdir_count) { - if (\is_string($cur_files_ary)) { + if (is_string($cur_files_ary)) { $GLOBALS['bnc_error'] = 1; break; } diff --git a/src/Legacy/WordsRate.php b/src/Legacy/WordsRate.php index 62ea6c8e4..039d2eaf4 100644 --- a/src/Legacy/WordsRate.php +++ b/src/Legacy/WordsRate.php @@ -46,7 +46,7 @@ class WordsRate $this->del_text_hl = $text; // Long text - if (\strlen($text) > 600) { + if (strlen($text) > 600) { return $this->words_rate; } // Crop quotes if contains +1 diff --git a/styles/templates/default/tracker.tpl b/styles/templates/default/tracker.tpl index cf5e8b5cf..ba2d72401 100644 --- a/styles/templates/default/tracker.tpl +++ b/styles/templates/default/tracker.tpl @@ -62,11 +62,11 @@ ajax.callback.view_post = function(data) { -

{PAGE_TITLE} · {L_RANDOM_RELEASE}

+

{PAGE_TITLE}

diff --git a/styles/templates/default/viewforum.tpl b/styles/templates/default/viewforum.tpl index f140da1d4..9a79208b9 100644 --- a/styles/templates/default/viewforum.tpl +++ b/styles/templates/default/viewforum.tpl @@ -512,6 +512,9 @@ td.topic_id { cursor: pointer; }   +
+ {L_MOVE_TO_TOP} +
diff --git a/styles/templates/default/viewtopic.tpl b/styles/templates/default/viewtopic.tpl index 586408ef4..2dcd456c7 100644 --- a/styles/templates/default/viewtopic.tpl +++ b/styles/templates/default/viewtopic.tpl @@ -576,6 +576,9 @@ function build_poll_add_form (src_el) {S_SELECT_POST_ORDER}  +
+ {L_MOVE_TO_TOP} +
diff --git a/tracker.php b/tracker.php index 9943764d5..c9fa4494e 100644 --- a/tracker.php +++ b/tracker.php @@ -299,7 +299,7 @@ if (isset($_GET[$user_releases_key])) { } // Random release -if (isset($_GET['random_release'])) { +if ($bb_cfg['tracker']['random_release_button'] && isset($_GET['random_release'])) { if ($random_release = DB()->fetch_row("SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE tor_status NOT IN(" . implode(', ', array_keys($bb_cfg['tor_frozen'])) . ") ORDER BY RAND() LIMIT 1")) { redirect(TOPIC_URL . $random_release['topic_id']); } else {