From d423c53cde50c1e5e37b28e4b50f7cdff573d825 Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 10 Feb 2023 09:04:15 +0000 Subject: [PATCH] Added most active forum category and topic to profiles. --- assets/css/misuzu/profile/forum-activity.css | 24 +++++ public/profile.php | 10 ++ src/Forum/forum.php | 15 +++ src/Forum/topic.php | 15 +++ templates/profile/index.twig | 99 +++++++++++++++++++- 5 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 assets/css/misuzu/profile/forum-activity.css 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 %}
@@ -136,6 +137,102 @@
{% endif %} + {% if show_active_forum_info %} +
+ {{ container_title('Forum Activity') }} + +
+ {% if profile_active_category_info is not empty %} +
+ {% set forum = profile_active_category_info %} + {% if forum.forum_icon is defined and forum.forum_icon is not empty %} + {% set forum_icon = forum.forum_icon %} + {% elseif forum.forum_archived is defined and forum.forum_archived %} + {% set forum_icon = 'fas fa-archive fa-fw' %} + {% elseif forum.forum_type is defined and forum.forum_type != constant('MSZ_FORUM_TYPE_DISCUSSION') %} + {% if forum.forum_type == constant('MSZ_FORUM_TYPE_LINK') %} + {% set forum_icon = 'fas fa-link fa-fw' %} + {% elseif forum.forum_type == constant('MSZ_FORUM_TYPE_CATEGORY') %} + {% set forum_icon = 'fas fa-folder fa-fw' %} + {% endif %} + {% else %} + {% set forum_icon = 'fas fa-comments fa-fw' %} + {% endif %} + +
+ Most active category +
+ +
+ + +
+
+ +
+ +
+
+ {{ forum.forum_name }} +
+ +
+ {{ profile_active_category_stats.post_count|number_format }} post{{ profile_active_category_stats.post_count == 1 ? '' : 's' }} + / {{ ((profile_active_category_stats.post_count / profile_stats.forum_post_count) * 100)|number_format(2) }}% of total posts +
+
+
+
+
+ {% endif %} + {% if profile_active_topic_info is not empty %} +
+ {% set topic = profile_active_topic_info %} + {% if topic.topic_deleted is defined and topic.topic_deleted is not null %} + {% set topic_icon = 'fas fa-trash-alt' %} + {% elseif topic.topic_type is defined and topic.topic_type != constant('MSZ_TOPIC_TYPE_DISCUSSION') %} + {% if topic.topic_type == constant('MSZ_TOPIC_TYPE_ANNOUNCEMENT') or topic.topic_type == constant('MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT') %} + {% set topic_icon = 'fas fa-bullhorn' %} + {% elseif topic.topic_type == constant('MSZ_TOPIC_TYPE_STICKY') %} + {% set topic_icon = 'fas fa-thumbtack' %} + {% endif %} + {% elseif topic.topic_locked is defined and topic.topic_locked is not null %} + {% set topic_icon = 'fas fa-lock' %} + {% else %} + {% set topic_icon = 'fas fa-comment' %} + {% endif %} + +
+ Most active topic +
+ +
+ + +
+
+ +
+ +
+
+ + {{ topic.topic_title }} + +
+ +
+ {{ profile_active_topic_stats.post_count|number_format }} post{{ profile_active_topic_stats.post_count == 1 ? '' : 's' }} + / {{ ((profile_active_topic_stats.post_count / profile_stats.forum_post_count) * 100)|number_format(2) }}% of total posts +
+
+
+
+
+ {% endif %} +
+
+ {% endif %} {% if show_birthdate %}
{{ container_title('Birthdate') }}