diff --git a/Makefile b/Makefile index 422a294fb..1fbf264f3 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,14 @@ ocelot-reload-conf: ocelot-reload-db: pkill -USR1 ocelot +.PHONY: rector +rector: + vendor/bin/rector process --config lib/rector.php + +.PHONY: rector-dry-run +rector-dry-run: + vendor/bin/rector process --dry-run --config lib/rector.php + .PHONY: test test: lint-css lint-php composer test diff --git a/lib/config.php b/lib/config.php index b1ac070e5..4bff20bb0 100644 --- a/lib/config.php +++ b/lib/config.php @@ -617,6 +617,9 @@ defined('VIP') or define('VIP', 6); // The secret Donor forum. defined('DONOR_FORUM') or define('DONOR_FORUM', 70); +// Where Announcements are sent. +defined('ANNOUNCEMENT_FORUM_ID') or define('ANNOUNCEMENT_FORUM_ID', 12); + // Where Edit Requests are sent. defined('EDITING_FORUM_ID') or define('EDITING_FORUM_ID', 34); diff --git a/lib/rector.php b/lib/rector.php new file mode 100644 index 000000000..7b4f2fb21 --- /dev/null +++ b/lib/rector.php @@ -0,0 +1,34 @@ +paths([ + // __DIR__ . '/../app', + __DIR__ . '/../classes', + // __DIR__ . '/../lib', + // __DIR__ . '/../sections', + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_82, + SetList::DEAD_CODE, + ]); + + $rectorConfig->skip([ + JsonThrowOnErrorRector::class, + CountOnNullRector::class, + NullToStrictStringFuncCallArgRector::class, + ]); + + $rectorConfig->disableParallel(); +}; diff --git a/sections/ajax/better/index.php b/sections/ajax/better/index.php index b4bdca2b6..a8025313a 100644 --- a/sections/ajax/better/index.php +++ b/sections/ajax/better/index.php @@ -1,19 +1,7 @@ 'failure']); - break; -} +match ($_GET['method'] ?? '') { + 'transcode' => require_once('transcode.php'), + 'single' => require_once('single.php'), + default => json_error('bad method'), +}; diff --git a/sections/ajax/bookmarks/artists.php b/sections/ajax/bookmarks/artists.php index e1ebe1eff..6533fb74c 100644 --- a/sections/ajax/bookmarks/artists.php +++ b/sections/ajax/bookmarks/artists.php @@ -25,7 +25,7 @@ $ArtistList = $DB->to_array(); $JsonArtists = []; foreach ($ArtistList as $Artist) { - list($ArtistID, $Name) = $Artist; + [$ArtistID, $Name] = $Artist; $JsonArtists[] = [ 'artistId' => (int)$ArtistID, 'artistName' => $Name diff --git a/sections/ajax/forum/index.php b/sections/ajax/forum/index.php index c2811fd31..072475d9c 100644 --- a/sections/ajax/forum/index.php +++ b/sections/ajax/forum/index.php @@ -4,17 +4,9 @@ if ($Viewer->disableForums()) { print json_die('failure'); } -switch ($_GET['type'] ?? 'main') { - case 'main': - require('main.php'); - break; - case 'viewforum': - require('forum.php'); - break; - case 'viewthread': - require('thread.php'); - break; - default: - print json_error('type'); - break; -} +match ($_GET['type'] ?? 'main') { + 'main' => require_once('main.php'), + 'viewforum' => require_once('forum.php'), + 'viewthread' => require_once('thread.php'), + default => json_error('type'), +}; diff --git a/sections/ajax/forum/thread.php b/sections/ajax/forum/thread.php index 65a3d0eaf..0e53b5c14 100644 --- a/sections/ajax/forum/thread.php +++ b/sections/ajax/forum/thread.php @@ -117,7 +117,7 @@ if ($thread->pinnedPostId()) { $userCache = []; $JsonPosts = []; -foreach ($slice as $Key => $Post) { +foreach ($slice as $Post) { [$PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime] = array_values($Post); if (!isset($userCache[$AuthorID])) { $userCache[$AuthorID] = $userMan->findById((int)$AuthorID); diff --git a/sections/ajax/inbox/inbox.php b/sections/ajax/inbox/inbox.php index cfdd02251..ed8f8c49f 100644 --- a/sections/ajax/inbox/inbox.php +++ b/sections/ajax/inbox/inbox.php @@ -4,7 +4,7 @@ $json = new Gazelle\Json\Inbox( $Viewer, $_GET['type'] ?? 'inbox', (int)($_GET['page'] ?? 1), - (bool)(($_GET['sort'] ?? 'unread') === 'unread'), + ($_GET['sort'] ?? 'unread') === 'unread', new Gazelle\Manager\User, ); diff --git a/sections/ajax/inbox/index.php b/sections/ajax/inbox/index.php index 0d1a787c9..fb4f77538 100644 --- a/sections/ajax/inbox/index.php +++ b/sections/ajax/inbox/index.php @@ -1,10 +1,6 @@ 'viewconv.php', + default => 'inbox.php', +}); diff --git a/sections/ajax/index.php b/sections/ajax/index.php index c2aab1a92..9a118736e 100644 --- a/sections/ajax/index.php +++ b/sections/ajax/index.php @@ -57,11 +57,11 @@ if (isset($Aliases[$Action])) { $_GET['action'] = $Action = $Aliases[$action]; } if (!$Action || !isset($Viewer)) { - json_die("failure"); + json_error("failure"); } $UserID = $Viewer->id(); -if (!empty($_SERVER['CONTENT_TYPE']) && substr($_SERVER['CONTENT_TYPE'], 0, 16) === 'application/json') { +if (!empty($_SERVER['CONTENT_TYPE']) && str_starts_with($_SERVER['CONTENT_TYPE'], 'application/json')) { $_POST = json_decode(file_get_contents('php://input'), true); } @@ -75,13 +75,13 @@ if (!$Viewer->permitted('site_unlimit_ajax') && isset($LimitedPages[$Action])) { } else { $Cache->increment_value('ajax_requests_'.$UserID); if ($UserRequests > $rate) { - json_die("failure", "Rate limit exceeded"); + json_error("failure", "Rate limit exceeded"); } } } if (AJAX && !defined('AUTHED_BY_TOKEN') && in_array($Action, $RequireTokenPages)) { - json_die("failure", "This page requires an api token"); + json_error("failure", "This page requires an api token"); } switch ($Action) { @@ -183,14 +183,10 @@ switch ($Action) { require_once('similar_artists.php'); break; case 'userhistory': - switch ($_GET['type'] ?? '') { - case 'posts': - require_once('userhistory/post_history.php'); - break; - default: - json_die('bad type'); - break; - } + match ($_GET['type'] ?? '') { + 'posts' => require_once('userhistory/post_history.php'), + default => json_error('bad type'), + }; break; case 'votefavorite': require_once('takevote.php'); @@ -255,5 +251,5 @@ switch ($Action) { break; default: // If they're screwing around with the query string - json_die("failure"); + json_error("failure"); } diff --git a/sections/ajax/similar_artists.php b/sections/ajax/similar_artists.php index b6605fb06..ecad031b2 100644 --- a/sections/ajax/similar_artists.php +++ b/sections/ajax/similar_artists.php @@ -23,7 +23,7 @@ $DB->prepared_query(" ", $artistId, $limit ); -while (list($ArtistID, $Name, $Score) = $DB->next_record(MYSQLI_NUM, false)) { +while ([$ArtistID, $Name, $Score] = $DB->next_record(MYSQLI_NUM, false)) { $results[] = [ 'id' => (int)$ArtistID, 'name' => $Name, diff --git a/sections/ajax/tcomments.php b/sections/ajax/tcomments.php index 6658fa5b9..a7a087e4c 100644 --- a/sections/ajax/tcomments.php +++ b/sections/ajax/tcomments.php @@ -11,7 +11,7 @@ $userCache = []; $userMan = new Gazelle\Manager\User; $JsonComments = []; -foreach ($thread as $Key => $Post) { +foreach ($thread as $Post) { [$PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername] = array_values($Post); if (!isset($userCache[$AuthorID])) { $userCache[$AuthorID] = $userMan->findById((int)$AuthorID); diff --git a/sections/ajax/top10/index.php b/sections/ajax/top10/index.php index bb9c88fc2..19e2dcd8e 100644 --- a/sections/ajax/top10/index.php +++ b/sections/ajax/top10/index.php @@ -4,20 +4,10 @@ if (!$Viewer->permitted('site_top10')) { json_die('failure'); } -switch ($_GET['type'] ?? 'torrents') { - case 'users': - require_once('users.php'); - break; - case 'tags': - require_once('tags.php'); - break; - case 'history': - require_once('history.php'); - break; - case 'torrents': - require_once('torrents.php'); - break; - default: - print json_encode(['status' => 'failure']); - break; -} +match ($_GET['type'] ?? 'torrents') { + 'history' => require_once('history.php'), + 'tags' => require_once('tags.php'), + 'torrents' => require_once('torrents.php'), + 'users' => require_once('users.php'), + default => json_error('bad type'), +}; diff --git a/sections/ajax/userhistory/index.php b/sections/ajax/userhistory/index.php index bcc7bfef7..1653d546d 100644 --- a/sections/ajax/userhistory/index.php +++ b/sections/ajax/userhistory/index.php @@ -1,10 +1,6 @@ require_once('post_history.php'), + default => json_error('bad type'), +}; diff --git a/sections/apply/admin.php b/sections/apply/admin.php index a9c4dfb2b..6e049a669 100644 --- a/sections/apply/admin.php +++ b/sections/apply/admin.php @@ -10,7 +10,7 @@ $editId = 0; $saved = ''; if (isset($_POST['auth'])) { authorize(); - $edit = array_filter($_POST, function ($x) { return preg_match('/^edit-\d+$/', $x);}, ARRAY_FILTER_USE_KEY); + $edit = array_filter($_POST, fn ($x) => preg_match('/^edit-\d+$/', $x), ARRAY_FILTER_USE_KEY); if (is_array($edit) && count($edit) == 1) { $editId = trim(array_keys($edit)[0], 'edit-'); $appRole = new Gazelle\ApplicantRole($editId); diff --git a/sections/apply/view.php b/sections/apply/view.php index 38e08cfb4..8a89d9d40 100644 --- a/sections/apply/view.php +++ b/sections/apply/view.php @@ -1,5 +1,8 @@ permitted('admin_manage_applicants'); /* important for viewing the full story and full applicant list */ +$Resolved = (isset($_GET['status']) && $_GET['status'] === 'resolved'); + if (isset($_POST['id']) && is_number($_POST['id'])) { authorize(); $ID = (int)$_POST['id']; @@ -7,13 +10,12 @@ if (isset($_POST['id']) && is_number($_POST['id'])) { if (!$IS_STAFF && $app->userId() != $Viewer->id()) { error(403); } - $remove = array_filter($_POST, function ($x) { return preg_match('/^note-delete-\d+$/', $x);}, ARRAY_FILTER_USE_KEY); + $remove = array_filter($_POST, fn ($x) => preg_match('/^note-delete-\d+$/', $x), ARRAY_FILTER_USE_KEY); if (is_array($remove) && count($remove) == 1) { $app->removeNote( trim(array_keys($remove)[0], 'note-delete-') ); - } - elseif (isset($_POST['resolve'])) { + } elseif (isset($_POST['resolve'])) { if ($_POST['resolve'] === 'Resolve') { $app->resolve(true); header('Location: /apply.php?action=view'); @@ -22,8 +24,7 @@ if (isset($_POST['id']) && is_number($_POST['id'])) { elseif ($_POST['resolve'] === 'Reopen') { $app->resolve(false); } - } - elseif (isset($_POST['note_reply'])) { + } elseif (isset($_POST['note_reply'])) { $app->saveNote( $Viewer, $_POST['note_reply'], @@ -37,7 +38,7 @@ if (isset($_POST['id']) && is_number($_POST['id'])) { error(403); } } -$Resolved = (isset($_GET['status']) && $_GET['status'] === 'resolved'); + echo $Twig->render('applicant/view.twig', [ 'app' => $app ?? null, 'auth' => $Viewer->auth(), diff --git a/sections/artist/artist.php b/sections/artist/artist.php index 898007c04..f7678913d 100644 --- a/sections/artist/artist.php +++ b/sections/artist/artist.php @@ -2,7 +2,9 @@ $RevisionID = (int)($_GET['revisionid'] ?? 0); $artistMan = new Gazelle\Manager\Artist; -$Artist = $artistMan->findById((int)($_GET['id'] ?? 0), $RevisionID); +$Artist = $RevisionID + ? $artistMan->findByIdAndRevision((int)($_GET['id'] ?? 0), $RevisionID) + : $artistMan->findById((int)($_GET['id'] ?? 0)); if (is_null($Artist)) { error(404); } diff --git a/sections/artist/concerts.php b/sections/artist/concerts.php index c4e0f032f..9f8799ae8 100644 --- a/sections/artist/concerts.php +++ b/sections/artist/concerts.php @@ -111,14 +111,12 @@ $Website function get_date_title($Str) { $Exploded = explode(' ', $Str); - $Date = $Exploded[2] . ' ' . $Exploded[1] . ', ' . $Exploded[3]; - return $Date; + return $Exploded[2] . ' ' . $Exploded[1] . ', ' . $Exploded[3]; } function get_date_post($Str) { $Exploded = explode(' ', $Str); - $Date = $Exploded[2] . ' ' . $Exploded[1] . ', ' . $Exploded[3] . ' (' . rtrim($Exploded[0], ',') . ')'; - return $Date; + return $Exploded[2] . ' ' . $Exploded[1] . ', ' . $Exploded[3] . ' (' . rtrim($Exploded[0], ',') . ')'; } ?> diff --git a/sections/artist/index.php b/sections/artist/index.php index 5526b1a0f..983c25f19 100644 --- a/sections/artist/index.php +++ b/sections/artist/index.php @@ -1,73 +1,32 @@ require_once('add_similar.php'), + 'add_alias' => require_once('add_alias.php'), + 'change_artistid' => require_once('change_artistid.php'), + 'download' => require_once('download.php'), + 'rename' => require_once('rename.php'), + 'edit' => require_once('takeedit.php'), + 'takeeditrequest' => require_once('takeeditrequest.php'), + default => error(0), + }; } elseif (!empty($_GET['action'])) { - switch ($_GET['action']) { - case 'autocomplete': - require_once('autocomplete.php'); - break; - case 'change_artistid': - require_once('change_artistid.php'); - break; - case 'delete': - require_once('delete.php'); - break; - case 'delete_alias': - require_once('delete_alias.php'); - break; - case 'delete_similar': - require_once('delete_similar.php'); - break; - case 'edit': - require_once('edit.php'); - break; - case 'editrequest': - require_once('editrequest.php'); - break; - case 'history': - require_once('history.php'); - break; - case 'notify': - require_once('notify.php'); - break; - case 'notifyremove': - require_once('notifyremove.php'); - break; - case 'revert': - require_once('takeedit.php'); - break; - case 'vote_similar': - require_once('vote_similar.php'); - break; - default: - error(0); - break; - } + match ($_GET['action']) { + 'autocomplete' => require_once('autocomplete.php'), + 'change_artistid' => require_once('change_artistid.php'), + 'delete' => require_once('delete.php'), + 'delete_alias' => require_once('delete_alias.php'), + 'delete_similar' => require_once('delete_similar.php'), + 'edit' => require_once('edit.php'), + 'editrequest' => require_once('editrequest.php'), + 'history' => require_once('history.php'), + 'notify' => require_once('notify.php'), + 'notifyremove' => require_once('notifyremove.php'), + 'revert' => require_once('takeedit.php'), + 'vote_similar' => require_once('vote_similar.php'), + default => error(0), + }; } else { if (!empty($_GET['id'])) { require_once('artist.php'); diff --git a/sections/artist/rename.php b/sections/artist/rename.php index eb4078029..4a1359aaf 100644 --- a/sections/artist/rename.php +++ b/sections/artist/rename.php @@ -42,7 +42,7 @@ if (!($oldAliasId = $artist->getAlias($oldName))) { error('Could not find existing alias ID'); } -list($TargetAliasID, $TargetArtistID) = $DB->row(" +[$TargetAliasID, $TargetArtistID] = $DB->row(" SELECT AliasID, ArtistID FROM artists_alias WHERE name = ? diff --git a/sections/better/index.php b/sections/better/index.php index 57d28bbbb..f35f7852a 100644 --- a/sections/better/index.php +++ b/sections/better/index.php @@ -1,10 +1,6 @@ 'transcode.php', + default => 'better.php', +}); diff --git a/sections/blog/index.php b/sections/blog/index.php index ad277727f..85ec60f7f 100644 --- a/sections/blog/index.php +++ b/sections/blog/index.php @@ -1,21 +1,9 @@ 'dead_thread.php', + 'deleteblog' => 'delete_blog.php', + 'takeeditblog' => 'take_edit_blog.php', + 'takenewblog' => 'take_new_blog.php', + default => 'blog_page.php', +}); diff --git a/sections/bonus/history.php b/sections/bonus/history.php index b99eb1be2..c0f987d38 100644 --- a/sections/bonus/history.php +++ b/sections/bonus/history.php @@ -23,7 +23,7 @@ echo $Twig->render('user/bonus-history.twig', [ 'item' => $bonus->purchaseHistory(), 'summary' => $summary, 'pool_summary' => $poolSummary, - 'pool_total' => array_reduce($poolSummary, function ($sum = 0, array $s = []) { return $sum + $s['total']; }), + 'pool_total' => array_reduce($poolSummary, fn ($sum = 0, array $s = []) => $sum + $s['total']), 'paginator' => $paginator, 'user' => $user, 'viewer' => $Viewer, diff --git a/sections/bonus/index.php b/sections/bonus/index.php index d68b57c24..084a7c3d1 100644 --- a/sections/bonus/index.php +++ b/sections/bonus/index.php @@ -9,43 +9,26 @@ const DEFAULT_PAGE = 'store.php'; switch ($_GET['action'] ?? '') { case 'purchase': /* handle validity and cost as early as possible */ - if (isset($_REQUEST['label']) && preg_match('/^[a-z]{1,15}(-\w{1,15}){0,4}/', $_REQUEST['label'])) { + if (preg_match('/^[a-z]{1,15}(-\w{1,15}){0,4}/', $_REQUEST['label'] ?? '')) { $viewerBonus = new \Gazelle\User\Bonus($Viewer); $Label = $_REQUEST['label']; $Item = $viewerBonus->getItem($Label); - if ($Item) { - $Price = $viewerBonus->getEffectivePrice($Label); - if ($Price > $Viewer->bonusPointsTotal()) { - error('You cannot afford this item.'); - } - switch($Label) { - case 'token-1': case 'token-2': case 'token-3': case 'token-4': - require_once('tokens.php'); - break; - case 'other-1': case 'other-2': case 'other-3': case 'other-4': - require_once('token_other.php'); - break; - case 'invite': - require_once('invite.php'); - break; - case 'title-bb-y': - case 'title-bb-n': - case 'title-off': - require_once('title.php'); - break; - case 'collage-1': - case 'seedbox': - require_once('purchase.php'); - break; - default: - require_once(DEFAULT_PAGE); - break; - } - } - else { + if (!$Item) { require_once(DEFAULT_PAGE); break; } + $Price = $viewerBonus->getEffectivePrice($Label); + if ($Price > $Viewer->bonusPointsTotal()) { + error('You cannot afford this item.'); + } + require_once(match ($Label) { + 'invite' => 'invite.php', + 'collage-1', 'seedbox' => 'purchase.php', + 'title-bb-y', 'title-bb-n', 'title-off' => 'title.php', + 'token-1', 'token-2', 'token-3', 'token-4' => 'tokens.php', + 'other-1', 'other-2', 'other-3', 'other-4' => 'token_other.php', + default => DEFAULT_PAGE, + }); } break; case 'bprates': diff --git a/sections/bonus/invite.php b/sections/bonus/invite.php index 69bf409b0..a37607017 100644 --- a/sections/bonus/invite.php +++ b/sections/bonus/invite.php @@ -1,7 +1,5 @@ purchaseInvite()) { error("You cannot purchase an invite (either you don't have the privilege or you don't have enough bonus points)."); diff --git a/sections/bonus/title.php b/sections/bonus/title.php index c49b8eee1..8de7c856d 100644 --- a/sections/bonus/title.php +++ b/sections/bonus/title.php @@ -1,7 +1,5 @@ require_once('edit_torrents.php'), + default => error(404), + }; break; case 'view': switch ($_REQUEST['type'] ?? 'torrents') { case 'torrents': - require('torrents.php'); + require_once('torrents.php'); break; case 'artists': - require('artists.php'); + require_once('artists.php'); break; case 'collages': $_GET['bookmarks'] = '1'; - require(__DIR__ . '/../collages/browse.php'); + require_once(__DIR__ . '/../collages/browse.php'); break; case 'requests': $_GET['type'] = 'bookmarks'; - require(__DIR__ . '/../requests/requests.php'); + require_once(__DIR__ . '/../requests/requests.php'); break; default: error(404); diff --git a/sections/bookmarks/torrents.php b/sections/bookmarks/torrents.php index 9a51e1117..9eee1ef75 100644 --- a/sections/bookmarks/torrents.php +++ b/sections/bookmarks/torrents.php @@ -33,7 +33,7 @@ $artistLeaderboard = $bookmark->torrentArtistLeaderboard(new Gazelle\Manager\Art $tagLeaderboard = $bookmark->torrentTagLeaderboard(); $CollageCovers = $Viewer->option('CollageCovers') ?? 25; -View::show_header($user->username() . " › Bookmarked torrent groups", $title, ['js' => 'browse,collage']); +View::show_header($user->username() . " › Bookmarked torrent groups", ['js' => 'browse,collage']); ?>