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 "
"; - echo "

Forum Activity

"; - - $recentPostData = getRecentForumPosts(0, $numToFetch, 100, $permissions); - - if ($recentPostData->isNotEmpty()) { - $isShowAbsoluteDatesPreferenceSet = $preferences && BitSet($preferences, UserPreference::Forum_ShowAbsoluteDates); - - foreach ($recentPostData as $nextData) { - $postedAt = - $isShowAbsoluteDatesPreferenceSet - ? getNiceDate(strtotime($nextData['PostedAt'])) - : Carbon::parse($nextData['PostedAt'])->diffForHumans(); - - $shortMsg = trim($nextData['ShortMsg']); - if ($nextData['IsTruncated']) { - $shortMsg .= "..."; - } - $author = $nextData['Author']; - $commentID = $nextData['CommentID']; - $forumTopicID = $nextData['ForumTopicID']; - $forumTopicTitle = $nextData['ForumTopicTitle']; - - sanitize_outputs( - $shortMsg, - $author, - $forumTopicTitle, - ); - - $tooltipClassName = $isShowAbsoluteDatesPreferenceSet ? "" : "cursor-help"; - $titleAttribute = $isShowAbsoluteDatesPreferenceSet - ? "" - : "title='" . Carbon::parse($nextData['PostedAt'])->format('F j Y, g:ia') . "'"; - - echo "
"; - echo "
"; - echo userAvatar($author, iconSize: 16); - echo " $postedAt
"; - echo "
View
"; - echo "
"; - echo "in $forumTopicTitle
"; - echo "
"; - echo Shortcode::stripAndClamp($shortMsg); - echo "
"; - echo "
"; - } - } - - echo "
more...
"; - - echo "
"; -} diff --git a/public/forum.php b/public/forum.php index 729bfc7060..11f672908f 100644 --- a/public/forum.php +++ b/public/forum.php @@ -1,6 +1,7 @@ share('sidebar', true) ?> diff --git a/public/reportissue.php b/public/reportissue.php index 665efb470a..f8b2fae244 100644 --- a/public/reportissue.php +++ b/public/reportissue.php @@ -44,16 +44,35 @@ RenderContentStart("Report Broken Achievement"); ?> + -
+ +
- + diff --git a/public/viewforum.php b/public/viewforum.php index 9f504b1758..6e6e43cbbd 100644 --- a/public/viewforum.php +++ b/public/viewforum.php @@ -2,6 +2,7 @@ use App\Site\Enums\Permissions; use App\Support\Shortcode\Shortcode; +use Illuminate\Support\Facades\Blade; authenticateFromCookie($user, $permissions, $userDetails); @@ -167,6 +168,6 @@
share('sidebar', true) ?> diff --git a/resources/views/community/components/forum/recent-posts.blade.php b/resources/views/community/components/forum/recent-posts.blade.php new file mode 100644 index 0000000000..373913a596 --- /dev/null +++ b/resources/views/community/components/forum/recent-posts.blade.php @@ -0,0 +1,39 @@ +@props([ + 'recentForumPosts' => [], + 'userPreferences' => 0, +]) + +
+

Forum Activity

+ +
+ @foreach ($recentForumPosts as $recentForumPost) +
+
+
+ {!! userAvatar($recentForumPost['Author'], iconSize: 16) !!} + + {{ $recentForumPost['PostedAt'] }} + +
+ + View +
+ +

in {{ $recentForumPost['ForumTopicTitle'] }}

+ +

+ {{ $recentForumPost['ShortMsg'] }} +

+
+ @endforeach +
+ +
+ more... +
+
diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index f1586416ac..4bd93f0f9d 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -18,12 +18,12 @@ - +
+ +
+ - - + @slot('sidebar') @include('content.top-links')