Skip to content

Commit

Permalink
Merge pull request #10 from Timo-Design/feature/02-Privacy
Browse files Browse the repository at this point in the history
Fixes User Sko
  • Loading branch information
sachatrauwaen authored Nov 5, 2024
2 parents b874cbc + fa9f286 commit 96793ab
Showing 1 changed file with 49 additions and 40 deletions.
89 changes: 49 additions & 40 deletions DNN Platform/Library/Mvc/Skins/SkinHelpers.User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DotNetNuke.Framework.Models.PageModel> helper, string cssClass = "SkinObject", string text = "", string url = "", bool showUnreadMessages = true, bool showAvatar = true, bool legacyMode = true, bool showInErrorPage = false)
{
var portalSettings = PortalSettings.Current;
Expand All @@ -37,24 +39,30 @@ public static IHtmlString User(this HtmlHelper<DotNetNuke.Framework.Models.PageM
return MvcHtmlString.Empty;
}

var userWrapperDiv = new TagBuilder("div");
userWrapperDiv.AddCssClass("registerGroup");

var userPropertiesDiv = new TagBuilder("div");
userPropertiesDiv.AddCssClass("userProperties");

var ul = new TagBuilder("ul");

ul.AddCssClass("buttonGroup");

if (!HttpContext.Current.Request.IsAuthenticated)
{
// Niet-geauthenticeerde gebruiker logica
// Unauthenticated User Logic
if (portalSettings.UserRegistration != (int)Globals.PortalRegistrationType.NoRegistration &&
(portalSettings.Users < portalSettings.UserQuota || portalSettings.UserQuota == 0))
{
// User Register
var registerLi = new TagBuilder("li");
registerLi.AddCssClass("userRegister");

var registerLink = new TagBuilder("a");
registerLink.AddCssClass(cssClass);
registerLink.Attributes.Add("rel", "nofollow");
registerLink.InnerHtml = !string.IsNullOrEmpty(text) ? text.Replace("src=\"", "src=\"" + portalSettings.ActiveTab.SkinPath) : Localization.GetString("Register", GetSkinsResourceFile("UserAndLogin.ascx"));
registerLink.InnerHtml = !string.IsNullOrEmpty(text) ? text.Replace("src=\"", "src=\"" + portalSettings.ActiveTab.SkinPath) : Localization.GetString("Register", userResourceFile);
registerLink.Attributes.Add("href", !string.IsNullOrEmpty(url) ? url : Globals.RegisterURL(HttpUtility.UrlEncode(navigationManager.NavigateURL()), Null.NullString));

if (portalSettings.EnablePopUps && portalSettings.RegisterTabId == Null.NullInteger/*&& !AuthenticationController.HasSocialAuthenticationEnabled(portalSettings)*/)
Expand All @@ -75,7 +83,7 @@ public static IHtmlString User(this HtmlHelper<DotNetNuke.Framework.Models.PageM
var loginLink = new TagBuilder("a");
loginLink.AddCssClass(cssClass);
loginLink.Attributes.Add("rel", "nofollow");
loginLink.InnerHtml = Localization.GetString("Login", GetSkinsResourceFile("UserAndLogin.ascx"));
loginLink.InnerHtml = Localization.GetString("Login", userResourceFile);
loginLink.Attributes.Add("href", Globals.LoginURL(HttpUtility.UrlEncode(HttpContext.Current.Request.RawUrl), HttpContext.Current.Request.QueryString["override"] != null));

if (portalSettings.EnablePopUps && portalSettings.LoginTabId == Null.NullInteger/*&& !AuthenticationController.HasSocialAuthenticationEnabled(portalSettings)*/)
Expand All @@ -90,62 +98,47 @@ public static IHtmlString User(this HtmlHelper<DotNetNuke.Framework.Models.PageM
}
else if (userInfo.UserID != -1)
{
// Geauthenticeerde gebruiker logica
var userNameLi = new TagBuilder("li");
userNameLi.AddCssClass("userName");

var userNameLink = new TagBuilder("a");
userNameLink.Attributes.Add("id", "dnn_dnnUser_userNameLink");
userNameLink.Attributes.Add("href", "#");
userNameLink.InnerHtml = userInfo.DisplayName;

var userMenu = new TagBuilder("ul");
userMenu.AddCssClass("userMenu");

// Voeg hier de verschillende menu-items toe (viewProfile, userMessages, userNotifications, etc.)
userMenu.InnerHtml += CreateMenuItem("viewProfile", Globals.UserProfileURL(userInfo.UserID), "Profile");

// Add menu-items (viewProfile, userMessages, userNotifications, etc.)
if (showUnreadMessages)
{
// Create Messages
var unreadMessages = InternalMessagingController.Instance.CountUnreadMessages(userInfo.UserID, PortalController.GetEffectivePortalId(userInfo.PortalID));

var messageLinkText = unreadMessages > 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)
Expand All @@ -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 ? $"<strong>{text}</strong>" : 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");
Expand All @@ -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();
Expand Down

0 comments on commit 96793ab

Please sign in to comment.