From 055a6e53cae4a32d766269bb2897af627f7bd093 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Sat, 19 Oct 2024 11:36:05 +0700 Subject: [PATCH] Minor improvements (#1658) * Minor improvements * Update install.php * Update install.php * Update .gitignore * Update admin_cron.php * Update Upload.php * Update CHANGELOG.md --- .gitignore | 1 + CHANGELOG.md | 2 +- admin/admin_cron.php | 9 +++++---- install.php | 12 ++++++------ src/Legacy/Common/Upload.php | 23 ++++++++++++----------- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index c7d55de12..5474b0b43 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ ### TorrentPier ### *.log *.integrity +install.php_* .env .php_cs.cache data/avatars diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b76e7095..92a937529 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ - Fixed `md5()` deprecated in PHP 8.4 [\#1561](https://github.com/torrentpier/torrentpier/pull/1561) ([belomaxorka](https://github.com/belomaxorka)) - Increased `USEREMAIL_MAX_LENGTH` [\#1566](https://github.com/torrentpier/torrentpier/pull/1566) ([belomaxorka](https://github.com/belomaxorka)) - Disabled resizing for textarea tag [\#1638](https://github.com/torrentpier/torrentpier/pull/1638) ([belomaxorka](https://github.com/belomaxorka)) -- Minor improvements [\#1570](https://github.com/torrentpier/torrentpier/pull/1570), [\#1571](https://github.com/torrentpier/torrentpier/pull/1571), [\#1575](https://github.com/torrentpier/torrentpier/pull/1575), [\#1589](https://github.com/torrentpier/torrentpier/pull/1589), [\#1592](https://github.com/torrentpier/torrentpier/pull/1592), [\#1605](https://github.com/torrentpier/torrentpier/pull/1605), [\#1611](https://github.com/torrentpier/torrentpier/pull/1611), [\#1612](https://github.com/torrentpier/torrentpier/pull/1612), [\#1615](https://github.com/torrentpier/torrentpier/pull/1615), [\#1627](https://github.com/torrentpier/torrentpier/pull/1627), [\#1633](https://github.com/torrentpier/torrentpier/pull/1633), [\#1641](https://github.com/torrentpier/torrentpier/pull/1641), [\#1651](https://github.com/torrentpier/torrentpier/pull/1651) ([belomaxorka](https://github.com/belomaxorka)) +- Minor improvements [\#1570](https://github.com/torrentpier/torrentpier/pull/1570), [\#1571](https://github.com/torrentpier/torrentpier/pull/1571), [\#1575](https://github.com/torrentpier/torrentpier/pull/1575), [\#1589](https://github.com/torrentpier/torrentpier/pull/1589), [\#1592](https://github.com/torrentpier/torrentpier/pull/1592), [\#1605](https://github.com/torrentpier/torrentpier/pull/1605), [\#1611](https://github.com/torrentpier/torrentpier/pull/1611), [\#1612](https://github.com/torrentpier/torrentpier/pull/1612), [\#1615](https://github.com/torrentpier/torrentpier/pull/1615), [\#1627](https://github.com/torrentpier/torrentpier/pull/1627), [\#1633](https://github.com/torrentpier/torrentpier/pull/1633), [\#1641](https://github.com/torrentpier/torrentpier/pull/1641), [\#1651](https://github.com/torrentpier/torrentpier/pull/1651), [\#1658](https://github.com/torrentpier/torrentpier/pull/1658) ([belomaxorka](https://github.com/belomaxorka)) - Updated deps [\#1563](https://github.com/torrentpier/torrentpier/pull/1563), [\#1564](https://github.com/torrentpier/torrentpier/pull/1564), [\#1608](https://github.com/torrentpier/torrentpier/pull/1608), [\#1609](https://github.com/torrentpier/torrentpier/pull/1609), [\#1610](https://github.com/torrentpier/torrentpier/pull/1610), [\#1637](https://github.com/torrentpier/torrentpier/pull/1637), [\#1646](https://github.com/torrentpier/torrentpier/pull/1646), [\#1647](https://github.com/torrentpier/torrentpier/pull/1647), [\#1650](https://github.com/torrentpier/torrentpier/pull/1650), [\#1656](https://github.com/torrentpier/torrentpier/pull/1656) ([belomaxorka](https://github.com/belomaxorka)) - New Crowdin updates [\#1569](https://github.com/torrentpier/torrentpier/pull/1569), [\#1572](https://github.com/torrentpier/torrentpier/pull/1572), [\#1573](https://github.com/torrentpier/torrentpier/pull/1573), [\#1574](https://github.com/torrentpier/torrentpier/pull/1574), [\#1588](https://github.com/torrentpier/torrentpier/pull/1588), [\#1590](https://github.com/torrentpier/torrentpier/pull/1590), [\#1600](https://github.com/torrentpier/torrentpier/pull/1600), [\#1601](https://github.com/torrentpier/torrentpier/pull/1601), [\#1606](https://github.com/torrentpier/torrentpier/pull/1606), [\#1607](https://github.com/torrentpier/torrentpier/pull/1607), [\#1625](https://github.com/torrentpier/torrentpier/pull/1625), [\#1626](https://github.com/torrentpier/torrentpier/pull/1626), [\#1629](https://github.com/torrentpier/torrentpier/pull/1629), [\#1630](https://github.com/torrentpier/torrentpier/pull/1630), [\#1631](https://github.com/torrentpier/torrentpier/pull/1631), [\#1632](https://github.com/torrentpier/torrentpier/pull/1632), [\#1639](https://github.com/torrentpier/torrentpier/pull/1639), [\#1640](https://github.com/torrentpier/torrentpier/pull/1640), [\#1654](https://github.com/torrentpier/torrentpier/pull/1654), [\#1655](https://github.com/torrentpier/torrentpier/pull/1655) ([Exileum](https://github.com/Exileum)) diff --git a/admin/admin_cron.php b/admin/admin_cron.php index aa31d4439..e2c61565f 100644 --- a/admin/admin_cron.php +++ b/admin/admin_cron.php @@ -188,7 +188,8 @@ switch ($mode) { } if ($submit) { - if ($_POST['mode'] == 'list') { + $mode2 = $_POST['mode'] ?? ''; + if ($mode2 == 'list') { if ($cron_action == 'run' && $jobs) { \TorrentPier\Legacy\Admin\Cron::run_jobs($jobs); } elseif ($cron_action == 'delete' && $jobs) { @@ -198,12 +199,12 @@ if ($submit) { } redirect('admin/' . basename(__FILE__) . '?mode=list'); } elseif (\TorrentPier\Legacy\Admin\Cron::validate_cron_post($_POST) == 1) { - if ($_POST['mode'] == 'edit') { + if ($mode2 == 'edit') { \TorrentPier\Legacy\Admin\Cron::update_cron_job($_POST); - } elseif ($_POST['mode'] == 'add') { + } elseif ($mode2 == 'add') { \TorrentPier\Legacy\Admin\Cron::insert_cron_job($_POST); } else { - bb_die('Mode error'); + bb_die("Invalid mode: $mode2"); } redirect('admin/' . basename(__FILE__) . '?mode=list'); diff --git a/install.php b/install.php index b6eec09e1..d103eee72 100644 --- a/install.php +++ b/install.php @@ -160,13 +160,13 @@ out("- Checking installed extensions...", 'info'); // [1] Check PHP Version if (!version_compare(PHP_VERSION, CHECK_REQUIREMENTS['php_min_version'], '>=')) { - out("- TorrentPier requires PHP version " . CHECK_REQUIREMENTS['php_min_version'] . "+ Your PHP version " . PHP_VERSION, 'error'); + out("- TorrentPier requires PHP version " . CHECK_REQUIREMENTS['php_min_version'] . "+ Your PHP version " . PHP_VERSION, 'warning'); } // [2] Check installed PHP Extensions on server foreach (CHECK_REQUIREMENTS['ext_list'] as $ext) { if (!extension_loaded($ext)) { - out("- ext-$ext not installed", 'error'); + out("- ext-$ext not installed. Check out php.ini file", 'error'); exit; } else { out("- ext-$ext installed!"); @@ -232,14 +232,14 @@ if (!is_file(BB_ROOT . 'vendor/autoload.php')) { out("- Composer successfully downloaded!\n", 'success'); runProcess('php ' . BB_ROOT . 'composer-setup.php --install-dir=' . BB_ROOT); } else { - out('- Cannot download Composer', 'error'); + out('- Cannot download Composer. Please, download it (composer.phar) manually', 'error'); exit; } if (is_file(BB_ROOT . 'composer-setup.php')) { if (unlink(BB_ROOT . 'composer-setup.php')) { out("- Composer installation file successfully removed!\n", 'success'); } else { - out('- Cannot remove Composer installation file. Delete it manually', 'warning'); + out('- Cannot remove Composer installation file (composer-setup.php). Please, delete it manually', 'warning'); } } } @@ -250,7 +250,7 @@ if (!is_file(BB_ROOT . 'vendor/autoload.php')) { runProcess('php ' . BB_ROOT . 'composer.phar install --no-interaction --no-ansi'); out("- Completed! Composer dependencies are installed!\n", 'success'); } else { - out('- composer.phar not found', 'error'); + out('- composer.phar not found. Please, download it (composer.phar) manually', 'error'); exit; } } else { @@ -386,5 +386,5 @@ if (!empty($DB_HOST) && !empty($DB_DATABASE) && !empty($DB_USERNAME)) { $conn->close(); out("- Importing SQL dump completed!\n", 'success'); out("- Voila! Good luck & have fun!", 'success'); - rename(__FILE__, hash('md5', time())); + rename(__FILE__, __FILE__ . '_' . hash('md5', time())); } diff --git a/src/Legacy/Common/Upload.php b/src/Legacy/Common/Upload.php index c60154caf..4e4f872d3 100644 --- a/src/Legacy/Common/Upload.php +++ b/src/Legacy/Common/Upload.php @@ -203,20 +203,21 @@ class Upload * @param array $params * @return bool */ - public function store(string $mode = '', array $params = []) + public function store(string $mode, array $params = []): bool { - if ($mode == 'avatar') { - delete_avatar($params['user_id'], $params['avatar_ext_id']); - $file_path = get_avatar_path($params['user_id'], $this->file_ext_id); - return $this->_move($file_path); + switch ($mode) { + case 'avatar': + delete_avatar($params['user_id'], $params['avatar_ext_id']); + $file_path = get_avatar_path($params['user_id'], $this->file_ext_id); + break; + case 'attach': + $file_path = get_attach_path($params['topic_id']); + break; + default: + trigger_error("Invalid upload mode: $mode", E_USER_ERROR); } - if ($mode == 'attach') { - $file_path = get_attach_path($params['topic_id']); - return $this->_move($file_path); - } - - trigger_error("Invalid upload mode: $mode", E_USER_ERROR); + return $this->_move($file_path); } /**