= renderGameBreadcrumb($dataOut) ?>
»
@@ -110,11 +129,22 @@ function displayCore() {
-
diff --git a/app/Community/AppServiceProvider.php b/app/Community/AppServiceProvider.php index c68e825273..4f990474f9 100644 --- a/app/Community/AppServiceProvider.php +++ b/app/Community/AppServiceProvider.php @@ -16,6 +16,7 @@ use App\Community\Commands\SyncVotes; use App\Community\Components\ActivePlayers; use App\Community\Components\DeveloperGameStatsTable; +use App\Community\Components\ForumRecentPosts; use App\Community\Components\GlobalStatistics; use App\Community\Components\MessageIcon; use App\Community\Components\UserCard; @@ -109,6 +110,7 @@ public function boot(): void Blade::component('active-players', ActivePlayers::class); Blade::component('developer-game-stats-table', DeveloperGameStatsTable::class); Blade::component('global-statistics', GlobalStatistics::class); + Blade::component('forum-recent-posts', ForumRecentPosts::class); Blade::component('user-card', UserCard::class); Blade::component('user-progression-status', UserProgressionStatus::class); diff --git a/app/Community/Components/ForumRecentPosts.php b/app/Community/Components/ForumRecentPosts.php new file mode 100644 index 0000000000..7cb4e217ee --- /dev/null +++ b/app/Community/Components/ForumRecentPosts.php @@ -0,0 +1,84 @@ +user = Auth::user() ?? null; + $this->numToFetch = $numToFetch; + } + + public function render(): ?View + { + $recentForumPosts = $this->prepareRecentForumPosts( + $this->numToFetch, + $this->user?->Permissions ?? Permissions::Unregistered, + $this->user?->websitePrefs ?? 0, + ); + + return view('community.components.forum.recent-posts', [ + 'recentForumPosts' => $recentForumPosts, + 'userPreferences' => $this->user?->websitePrefs ?? 0, + ]); + } + + private function prepareRecentForumPosts(int $numToFetch = 4, int $userPermissions = Permissions::Unregistered, int $userPreferences = 0): array + { + $recentForumPosts = []; + $rawRecentPosts = getRecentForumPosts(0, $numToFetch, 100, $userPermissions); + + if ($rawRecentPosts->isEmpty()) { + return $recentForumPosts; + } + + $isShowAbsoluteDatesPreferenceSet = $userPreferences && BitSet($userPreferences, UserPreference::Forum_ShowAbsoluteDates); + + foreach ($rawRecentPosts as $rawRecentPost) { + $recentForumPosts[] = [ + 'ShortMsg' => $this->buildShortMessage($rawRecentPost), + 'Author' => $rawRecentPost['Author'], + 'ForumTopicTitle' => $rawRecentPost['ForumTopicTitle'], + 'HasDateTooltip' => !$isShowAbsoluteDatesPreferenceSet, + + // "viewtopic.php?t=12345&c=112233#112233" + 'URL' => '/viewtopic.php?t=' + . $rawRecentPost['ForumTopicID'] . '&c=' . $rawRecentPost['CommentID'] + . '#' . $rawRecentPost['CommentID'], + + 'PostedAt' => $isShowAbsoluteDatesPreferenceSet + ? getNiceDate(strtotime($rawRecentPost['PostedAt'])) + : Carbon::parse($rawRecentPost['PostedAt'])->diffForHumans(), + + 'TitleAttribute' => $isShowAbsoluteDatesPreferenceSet + ? null + : Carbon::parse($rawRecentPost['PostedAt'])->format('F j Y, g:ia'), + ]; + } + + return $recentForumPosts; + } + + private function buildShortMessage(array $rawRecentPost): string + { + $shortMsg = trim($rawRecentPost['ShortMsg']); + $shortMsg = $rawRecentPost['IsTruncated'] ? $shortMsg . "..." : $shortMsg; + + return Shortcode::stripAndClamp($shortMsg); + } +} diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index 69798dfa64..eade16773f 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -38,7 +38,6 @@ require_once __DIR__ . '/render/avatar.php'; require_once __DIR__ . '/render/code-note.php'; require_once __DIR__ . '/render/comment.php'; -require_once __DIR__ . '/render/forum.php'; require_once __DIR__ . '/render/game.php'; require_once __DIR__ . '/render/layout.php'; require_once __DIR__ . '/render/leaderboard.php'; diff --git a/app/Helpers/render/forum.php b/app/Helpers/render/forum.php deleted file mode 100644 index 8aa7141837..0000000000 --- a/app/Helpers/render/forum.php +++ /dev/null @@ -1,67 +0,0 @@ -user(); - $permissions = $user?->Permissions ?? Permissions::Unregistered; - $preferences = $user?->websitePrefs ?? 0; - - echo "