diff --git a/assets/css/misuzu/profile/forum-activity.css b/assets/css/misuzu/profile/forum-activity.css new file mode 100644 index 0000000..7d90da7 --- /dev/null +++ b/assets/css/misuzu/profile/forum-activity.css @@ -0,0 +1,24 @@ +.profile__forum-activity__content { + margin: 5px; +} + +.profile__forum-activity__topic { + margin-top: 5px; +} + +.profile__forum-activity__leader { + font-size: .9em; + margin: 0 5px; +} + +.profile__forum-activity .forum__category__icon { + width: 30px; + height: 30px; + font-size: 1.5em; + line-height: 1.5em; + flex: 0 0 30px; +} + +.profile__forum-activity .forum__category { + background-color: rgba(17, 17, 17, .6); +} diff --git a/public/profile.php b/public/profile.php index 669ecca..a35260e 100644 --- a/public/profile.php +++ b/public/profile.php @@ -353,10 +353,20 @@ switch($profileMode) { $template = 'profile.index'; $warnings = $profileUser->getProfileWarnings($currentUser); + $activeCategoryStats = $viewingAsGuest ? null : forum_get_user_most_active_category_info($profileUser->getId()); + $activeCategoryInfo = empty($activeCategoryStats->forum_id) ? null : forum_get($activeCategoryStats->forum_id); + + $activeTopicStats = $viewingAsGuest ? null : forum_get_user_most_active_topic_info($profileUser->getId()); + $activeTopicInfo = empty($activeTopicStats->topic_id) ? null : forum_topic_get($activeTopicStats->topic_id); + Template::set([ 'profile_warnings' => $warnings, 'profile_warnings_view_private' => $canManageWarnings, 'profile_warnings_can_manage' => $canManageWarnings, + 'profile_active_category_stats' => $activeCategoryStats, + 'profile_active_category_info' => $activeCategoryInfo, + 'profile_active_topic_stats' => $activeTopicStats, + 'profile_active_topic_info' => $activeTopicInfo, ]); break; } diff --git a/src/Forum/forum.php b/src/Forum/forum.php index 46fadb2..9cf82f8 100644 --- a/src/Forum/forum.php +++ b/src/Forum/forum.php @@ -526,3 +526,18 @@ function forum_count_synchronise(int $forumId = MSZ_FORUM_ROOT, bool $save = tru return compact('topics', 'posts'); } + +function forum_get_user_most_active_category_info(int $userId): ?object { + if($userId < 1) + return null; + + global $cfg; + + $getActiveForum = \Misuzu\DB::prepare(sprintf( + 'SELECT forum_id, COUNT(*) AS post_count FROM msz_forum_posts WHERE user_id = :user AND post_deleted IS NULL AND forum_id NOT IN (%s) GROUP BY forum_id ORDER BY post_count DESC LIMIT 1', + implode(',', $cfg->getValue('forum_leader.unranked.forum', \Misuzu\Config\IConfig::T_ARR)) + )); + $getActiveForum->bind('user', $userId); + + return $getActiveForum->fetchObject(); +} diff --git a/src/Forum/topic.php b/src/Forum/topic.php index 989059a..181998a 100644 --- a/src/Forum/topic.php +++ b/src/Forum/topic.php @@ -652,3 +652,18 @@ function forum_topic_nuke(int $topicId): bool { $nukeTopic->bind('topic', $topicId); return $nukeTopic->execute(); } + +function forum_get_user_most_active_topic_info(int $userId): ?object { + if($userId < 1) + return null; + + global $cfg; + + $getActiveForum = \Misuzu\DB::prepare(sprintf( + 'SELECT topic_id, COUNT(*) AS post_count FROM msz_forum_posts WHERE user_id = :user AND post_deleted IS NULL AND forum_id NOT IN (%s) GROUP BY topic_id ORDER BY post_count DESC LIMIT 1', + implode(',', $cfg->getValue('forum_leader.unranked.forum', \Misuzu\Config\IConfig::T_ARR)) + )); + $getActiveForum->bind('user', $userId); + + return $getActiveForum->fetchObject(); +} diff --git a/templates/profile/index.twig b/templates/profile/index.twig index 2b5f87e..b2cad28 100644 --- a/templates/profile/index.twig +++ b/templates/profile/index.twig @@ -81,7 +81,8 @@ {% set show_profile_fields = profile_is_editing ? perms.edit_profile : profile_fields|length > 0 %} {% set show_background_settings = profile_is_editing and perms.edit_background %} {% set show_birthdate = profile_is_editing and perms.edit_birthdate %} - {% set show_sidebar = show_profile_fields or show_background_settings %} + {% set show_active_forum_info = not profile_is_editing and (profile_active_category_info.forum_id|default(0) > 0 or profile_active_topic_info.topic_id|default(0) > 0) %} + {% set show_sidebar = show_profile_fields or show_background_settings or show_birthdate or show_active_forum_info %} {% if show_sidebar %}