diff --git a/DNN Platform/Library/Mvc/Skins/SkinHelpers.User.cs b/DNN Platform/Library/Mvc/Skins/SkinHelpers.User.cs index 918d6e47e5e..736433c4928 100644 --- a/DNN Platform/Library/Mvc/Skins/SkinHelpers.User.cs +++ b/DNN Platform/Library/Mvc/Skins/SkinHelpers.User.cs @@ -26,6 +26,8 @@ namespace DotNetNuke.Web.Mvc.Skins public static partial class SkinHelpers { + private static string userResourceFile = GetSkinsResourceFile("User.ascx"); + public static IHtmlString User(this HtmlHelper helper, string cssClass = "SkinObject", string text = "", string url = "", bool showUnreadMessages = true, bool showAvatar = true, bool legacyMode = true, bool showInErrorPage = false) { var portalSettings = PortalSettings.Current; @@ -37,24 +39,30 @@ public static IHtmlString User(this HtmlHelper 0 ? string.Format(Localization.GetString("Messages", userResourceFile), unreadMessages) : string.Format(Localization.GetString("NoMessages", userResourceFile)); + ul.InnerHtml += CreateMenuItem(messageLinkText, "userMessages", navigationManager.NavigateURL(GetMessageTab(portalSettings))); + + // Create Notifications var unreadAlerts = NotificationsController.Instance.CountNotifications(userInfo.UserID, PortalController.GetEffectivePortalId(userInfo.PortalID)); + var alertLink = navigationManager.NavigateURL(GetMessageTab(portalSettings), string.Empty, string.Format("userId={0}", userInfo.UserID), "view=notifications", "action=notifications"); + var alertLinkText = unreadAlerts > 0 ? string.Format(Localization.GetString("Notifications", userResourceFile), unreadAlerts) : string.Format(Localization.GetString("NoNotifications", userResourceFile)); - userMenu.InnerHtml += CreateMessageMenuItem("userMessages", navigationManager.NavigateURL(GetMessageTab(portalSettings), string.Empty, $"userId={userInfo.UserID}"), "Messages", unreadMessages); - userMenu.InnerHtml += CreateMessageMenuItem("userNotifications", navigationManager.NavigateURL(GetMessageTab(portalSettings), string.Empty, $"userId={userInfo.UserID}", "view=notifications", "action=notifications"), "Notifications", unreadAlerts); + ul.InnerHtml += CreateMenuItem(alertLinkText, "userNotifications", alertLink); } - userMenu.InnerHtml += CreateMenuItem("userSettings", navigationManager.NavigateURL(portalSettings.UserTabId, "Profile", $"userId={userInfo.UserID}", "pageno=1"), "Account"); - userMenu.InnerHtml += CreateMenuItem("userProfilename", navigationManager.NavigateURL(portalSettings.UserTabId, "Profile", $"userId={userInfo.UserID}", "pageno=2"), "EditProfile"); - userMenu.InnerHtml += CreateMenuItem("userLogout", navigationManager.NavigateURL(portalSettings.ActiveTab.TabID, "Logoff"), "Logout", true); + // Create User Display Name Link + var userDisplayText = userInfo.DisplayName; + var userDisplayTextUrl = Globals.UserProfileURL(userInfo.UserID); + var userDisplayTextToolTip = Localization.GetString("VisitMyProfile", userResourceFile); - userNameLi.InnerHtml = userNameLink.ToString() + userMenu.ToString(); - ul.InnerHtml += userNameLi.ToString(); + ul.InnerHtml += CreateMenuItem(userDisplayText, "userDisplayName", userDisplayTextUrl); if (showAvatar) { var userProfileLi = new TagBuilder("li"); userProfileLi.AddCssClass("userProfile"); - var profileLink = new TagBuilder("a"); - profileLink.Attributes.Add("href", Globals.UserProfileURL(userInfo.UserID)); - + // Get the Profile Image var profileImg = new TagBuilder("img"); profileImg.Attributes.Add("src", UserController.Instance.GetUserProfilePictureUrl(userInfo.UserID, 32, 32)); - profileImg.Attributes.Add("alt", Localization.GetString("ProfilePicture", GetSkinsResourceFile("UserAndLogin.ascx"))); - - var profileImgSpan = new TagBuilder("span"); - profileImgSpan.AddCssClass("userProfileImg"); - profileImgSpan.InnerHtml = profileImg.ToString(); - - profileLink.InnerHtml = profileImgSpan.ToString(); - userProfileLi.InnerHtml = profileLink.ToString(); + profileImg.Attributes.Add("alt", Localization.GetString("ProfilePicture", userResourceFile)); - ul.InnerHtml += userProfileLi.ToString(); + ul.InnerHtml += CreateMenuItem(profileImg.ToString(), "userProfileImg", userDisplayTextUrl); } } userPropertiesDiv.InnerHtml = ul.ToString(); - return new MvcHtmlString(userPropertiesDiv.ToString()); + userWrapperDiv.InnerHtml = userPropertiesDiv.ToString(); + return new MvcHtmlString(userWrapperDiv.ToString()); } private static string CreateMenuItem(string cssClass, string href, string resourceKey, bool isStrong = false) @@ -155,13 +148,27 @@ private static string CreateMenuItem(string cssClass, string href, string resour var a = new TagBuilder("a"); a.Attributes.Add("href", href); - var text = Localization.GetString(resourceKey, Localization.GetResourceFile(null, "UserAndLogin.ascx")); + var text = Localization.GetString(resourceKey, userResourceFile); a.InnerHtml = isStrong ? $"{text}" : text; li.InnerHtml = a.ToString(); return li.ToString(); } + private static string CreateMenuItem(string text, string cssClass, string href) + { + var li = new TagBuilder("li"); + li.AddCssClass(cssClass); + + var a = new TagBuilder("a"); + a.Attributes.Add("href", href); + + a.InnerHtml += text; + + li.InnerHtml = a.ToString(); + return li.ToString(); + } + private static string CreateMessageMenuItem(string cssClass, string href, string resourceKey, int count) { var li = new TagBuilder("li"); @@ -178,7 +185,9 @@ private static string CreateMessageMenuItem(string cssClass, string href, string a.InnerHtml = span.ToString(); } - a.InnerHtml += Localization.GetString(resourceKey, Localization.GetResourceFile(null, "UserAndLogin.ascx")); + var innerText = Localization.GetString(resourceKey, userResourceFile); + innerText = string.Format(innerText, count.ToString()); + a.InnerHtml += innerText; li.InnerHtml = a.ToString(); return li.ToString();