예제 #1
0
		public string GetUsersOnline(int portalId, int moduleId, User user)
		{
			var sb = new StringBuilder();
			var dr = DataProvider.Instance().Profiles_GetUsersOnline(portalId, moduleId, 2);
			try
			{
				var mainSettings = DataCache.MainSettings(moduleId);
				
                while (dr.Read())
				{
                    if(sb.Length > 0)
                        sb.Append(", ");

				    sb.Append(UserProfiles.GetDisplayName(moduleId, true, false, user.IsAdmin || user.IsSuperUser, dr.GetInt("UserId"), dr.GetString("Username"), dr.GetString("FirstName"), dr.GetString("LastName"), dr.GetString("DisplayName")));
				}

				dr.Close();
				return sb.ToString();
			}
			catch (Exception ex)
			{
				if (! dr.IsClosed)
				{
					dr.Close();
				}
				return string.Empty;
			}


		}
예제 #2
0
        public static string GetPostInfo(int portalId, int moduleId, int userId, string username, User up, string imagePath, bool isMod, string ipAddress, bool isUserOnline, CurrentUserTypes currentUserType, int currentUserId, bool userPrefHideAvatar, int timeZoneOffset)
        {
            var sPostInfo = ParseProfileInfo(portalId, moduleId, userId, username, up, imagePath, isMod, ipAddress, currentUserType, currentUserId, userPrefHideAvatar, timeZoneOffset);
            if (sPostInfo.ToLower().Contains("<br"))
                return sPostInfo;

            var sr = new StringReader(sPostInfo);
            var sTrim = string.Empty;
            while (sr.Peek() != -1)
            {
                var tmp = sr.ReadLine();
                if (tmp != null && tmp.Trim() != string.Empty)
                {
                    sTrim += tmp.Trim() + "<br />";
                }
            }
            return sTrim;
        }
예제 #3
0
        public static string PreviewTopic(int topicTemplateID, int portalId, int moduleId, int tabId, Forum forumInfo, int userId, string body, string imagePath, User up, DateTime postDate, CurrentUserTypes currentUserType, int currentUserId, int timeZoneOffset)
        {
            var sTemplate = GetTopicTemplate(topicTemplateID, moduleId);
            try
            {
                var mainSettings = DataCache.MainSettings(moduleId);
                var sTopic = GetTemplateSection(sTemplate, "[TOPIC]", "[/TOPIC]");
                sTopic = sTopic.Replace("[ACTIONS:ALERT]", string.Empty);
                sTopic = sTopic.Replace("[ACTIONS:EDIT]", string.Empty);
                sTopic = sTopic.Replace("[ACTIONS:DELETE]", string.Empty);
                sTopic = sTopic.Replace("[ACTIONS:QUOTE]", string.Empty);
                sTopic = sTopic.Replace("[ACTIONS:REPLY]", string.Empty);
                sTopic = sTopic.Replace("[POSTDATE]", Utilities.GetDate(postDate, moduleId, timeZoneOffset));
                sTopic = sTopic.Replace("[POSTINFO]", GetPostInfo(portalId, moduleId, userId, up.UserName, up, imagePath, false, HttpContext.Current.Request.UserHostAddress, true, currentUserType, currentUserId, false, timeZoneOffset));
                sTemplate = ParsePreview(portalId, sTopic, body, moduleId);
                sTemplate = "<table class=\"afgrid\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\" border=\"1\">" + sTemplate;
                sTemplate = sTemplate + "</table>";
                sTemplate = Utilities.LocalizeControl(sTemplate);
                sTemplate = Utilities.StripTokens(sTemplate);
            }
            catch (Exception ex)
            {
                sTemplate = ex.ToString();
            }

            return sTemplate;
        }
예제 #4
0
        public static string ParseProfileTemplate(string profileTemplate, User up, int portalId, int moduleId, string imagePath, CurrentUserTypes currentUserType, bool legacyTemplate, bool userPrefHideAvatar, bool userPrefHideSignature, string ipAddress, int currentUserId, int timeZoneOffset)
        {
            try
            {
                if (legacyTemplate)
                    profileTemplate = CleanTemplate(profileTemplate);

                if (up.Profile == null)
                    up = new UserController().FillProfile(portalId, -1, up);

                // TODO figure out why/if this recurion is possible.  Seems a bit scary as it could create a loop.
                if (profileTemplate.Contains("[POSTINFO]"))
                {
                    var sPostInfo = GetPostInfo(portalId, moduleId, up.UserId, up.UserName, up, imagePath, false, ipAddress, up.Profile.IsUserOnline, currentUserType, currentUserId, userPrefHideAvatar, timeZoneOffset);
                    profileTemplate = profileTemplate.Replace("[POSTINFO]", sPostInfo);
                }

                var mainSettings = DataCache.MainSettings(moduleId);

                // Parse DNN profile fields if needed
                var pt = profileTemplate;
                if (pt.IndexOf("[DNN:PROFILE:", StringComparison.Ordinal) >= 0)
                    pt = ParseProfile(portalId, up.UserId, pt, currentUserType, currentUserId);

                // Parse Roles
                if (pt.Contains("[ROLES:"))
                    pt = ParseRoles(pt, (up.UserId == -1) ? string.Empty : up.Profile.Roles);

                var result = new StringBuilder(pt);

                // Used in a few places to determine if info should be shown or removed.
                var isMod = (currentUserType == CurrentUserTypes.Admin || currentUserType == CurrentUserTypes.ForumMod || currentUserType == CurrentUserTypes.SuperUser);

                 // Used in a few places to determine if info should be shown or removed.
                var isAdmin = (currentUserType == CurrentUserTypes.Admin || currentUserType == CurrentUserTypes.SuperUser);

                var isAuthethenticated = currentUserType != CurrentUserTypes.Anon;

                // IP Address
                result.Replace("[MODIPADDRESS]", isMod ? ipAddress : string.Empty);

                // User Edit
                result.Replace("[AF:BUTTON:EDITUSER]", isAdmin && up.UserId > 0 ? string.Format("<button class='af-button af-button-edituser' data-id='{0}' data-name='{1}'>[RESX:Edit]</button>", up.UserId, Utilities.JSON.EscapeJsonString(up.DisplayName)) : string.Empty);

                // Points
                var totalPoints = up.PostCount;
                if (mainSettings.EnablePoints && up.UserId > 0 && up.Profile != null)
                {
                    totalPoints = (up.Profile.TopicCount * mainSettings.TopicPointValue) + (up.Profile.ReplyCount * mainSettings.ReplyPointValue) + (up.Profile.AnswerCount * mainSettings.AnswerPointValue) + up.Profile.RewardPoints;
                    result.Replace("[AF:PROFILE:TOTALPOINTS]", totalPoints.ToString());
                    result.Replace("[AF:POINTS:VIEWCOUNT]", up.Profile.ViewCount.ToString());
                    result.Replace("[AF:POINTS:ANSWERCOUNT]", up.Profile.AnswerCount.ToString());
                    result.Replace("[AF:POINTS:REWARDPOINTS]", up.Profile.RewardPoints.ToString());
                }
                else
                {
                    result.Replace("[AF:PROFILE:TOTALPOINTS]", string.Empty);
                    result.Replace("[AF:POINTS:VIEWCOUNT]", string.Empty);
                    result.Replace("[AF:POINTS:ANSWERCOUNT]", string.Empty);
                    result.Replace("[AF:POINTS:REWARDPOINTS]", string.Empty);
                }

                // User Status
                var sUserStatus = string.Empty;
                if (mainSettings.UsersOnlineEnabled && up.UserId > 0 && up.Profile != null)
                    sUserStatus = UserProfiles.UserStatus(imagePath, up.Profile.IsUserOnline, up.UserId, moduleId, "[RESX:UserOnline]", "[RESX:UserOffline]");

                result.Replace("[AF:PROFILE:USERSTATUS]", sUserStatus);
                result.Replace("[AF:PROFILE:USERSTATUS:CSS]", sUserStatus.Contains("online") ? "af-status-online" : "af-status-offline");

                // Rank
                result.Replace("[AF:PROFILE:RANKDISPLAY]", (up.UserId > 0) ? UserProfiles.GetUserRank(portalId, moduleId, up.UserId, totalPoints, 0) : string.Empty);
                result.Replace("[AF:PROFILE:RANKNAME]", (up.UserId > 0) ? UserProfiles.GetUserRank(portalId, moduleId, up.UserId, totalPoints, 1) : string.Empty);

                // PM Image/link
                var pmUrl = string.Empty;
                var pmLink = string.Empty;
                if (up.UserId > 0 && currentUserId >= 0 && up.UserId != currentUserId)
                {
                    switch (mainSettings.PMType)
                    {
                        case PMTypes.Core:
                            pmLink = "<img class='ComposeMessage' data-recipient='{ \"id\": \"user-" + up.UserId + "\", \"name\": \"" + HttpUtility.JavaScriptStringEncode(up.DisplayName) + "\"}' src='" + imagePath + "/images/icon_pm.png' alt=\"[RESX:SendPM]\" title=\"[RESX:SendPM]\" border=\"0\" /></a>";
                            break;

                        case PMTypes.Ventrian:
                            pmUrl = Common.Globals.NavigateURL(mainSettings.PMTabId, string.Empty, new[] {"type=compose", "sendto=" + up.UserId});
                            pmLink = "<a href=\"" + pmUrl + "\"><img src=\"" + imagePath + "/images/icon_pm.png\" alt=\"[RESX:SendPM]\" border=\"0\" /></a>";
                            break;
                    }
                }

                result.Replace("[AF:PROFILE:PMLINK]", pmLink);
                result.Replace("[AF:PROFILE:PMURL]", pmUrl);

                // Signature
                var sSignature = string.Empty;
                if (mainSettings.AllowSignatures != 0 && ! userPrefHideSignature && up.Profile != null && !up.Profile.SignatureDisabled)
                {
                    sSignature = up.Profile.Signature;

                    if (sSignature != string.Empty)
                        sSignature = Utilities.ManageImagePath(sSignature);

                    switch (mainSettings.AllowSignatures)
                    {
                        case 1:
                            sSignature = Utilities.HTMLEncode(sSignature);
                            sSignature = sSignature.Replace(System.Environment.NewLine, "<br />");
                            break;
                        case 2:
                            sSignature = Utilities.HTMLDecode(sSignature);
                            break;
                    }
                }

                result.Replace("[AF:PROFILE:SIGNATURE]", sSignature);

                // Avatar
                var sAvatar = string.Empty;
                if (! userPrefHideAvatar && !up.Profile.AvatarDisabled)
                    sAvatar = UserProfiles.GetAvatar(up.UserId, mainSettings.AvatarWidth, mainSettings.AvatarHeight);

                result.Replace("[AF:PROFILE:AVATAR]", sAvatar);

                // Display Name
                result.Replace("[AF:PROFILE:DISPLAYNAME]", UserProfiles.GetDisplayName(moduleId, true, isMod, isAdmin, up.UserId, up.UserName, up.FirstName, up.LastName, up.DisplayName));

                // These fields are no longer used
                result.Replace("[AF:PROFILE:LOCATION]", string.Empty);
                result.Replace("[AF:PROFILE:WEBSITE]", string.Empty);
                result.Replace("[AF:PROFILE:YAHOO]", string.Empty);
                result.Replace("[AF:PROFILE:MSN]", string.Empty);
                result.Replace("[AF:PROFILE:ICQ]", string.Empty);
                result.Replace("[AF:PROFILE:AOL]", string.Empty);
                result.Replace("[AF:PROFILE:OCCUPATION]", string.Empty);
                result.Replace("[AF:PROFILE:INTERESTS]", string.Empty);
                result.Replace("[AF:CONTROL:AVATAREDIT]", string.Empty);
                result.Replace("[AF:BUTTON:PROFILEEDIT]", string.Empty);
                result.Replace("[AF:BUTTON:PROFILESAVE]", string.Empty);
                result.Replace("[AF:BUTTON:PROFILECANCEL]", string.Empty);
                result.Replace("[AF:PROFILE:BIO]", string.Empty);
                result.Replace("[MODUSERSETTINGS]", string.Empty);

                // Date Created
                var sDateCreated = string.Empty;
                var sDateCreatedReplacement = "[AF:PROFILE:DATECREATED]";
                if (up.UserId > 0 && up.Profile != null && up.Profile.DateCreated != null)
                {
                    if (pt.Contains("[AF:PROFILE:DATECREATED:"))
                    {
                        var sFormat = pt.Substring(pt.IndexOf("[AF:PROFILE:DATECREATED:", StringComparison.Ordinal) + (sDateCreatedReplacement.Length), 1);
                        sDateCreated = up.Profile.DateCreated.ToString(sFormat);
                        sDateCreatedReplacement = "[AF:PROFILE:DATECREATED:" + sFormat + "]";
                    }
                    else
                        sDateCreated = Utilities.GetDate(up.Profile.DateCreated, moduleId, timeZoneOffset);
                }
                result.Replace(sDateCreatedReplacement, sDateCreated);

                // Last Activity
                var sDateLastActivity = string.Empty;
                var sDateLastActivityReplacement = "[AF:PROFILE:DATELASTACTIVITY]";

                if (up.Profile.DateLastActivity != null && up.UserId > 0)
                {
                    if (pt.Contains("[AF:PROFILE:DATELASTACTIVITY:"))
                    {
                        string sFormat = pt.Substring(pt.IndexOf("[AF:PROFILE:DATELASTACTIVITY:", StringComparison.Ordinal) + (sDateLastActivityReplacement.Length), 1);
                        sDateLastActivity = up.Profile.DateLastActivity.ToString(sFormat);
                        sDateLastActivityReplacement = "[AF:PROFILE:DATELASTACTIVITY:" + sFormat + "]";
                    }
                    else
                        sDateLastActivity = Utilities.GetDate(up.Profile.DateLastActivity, moduleId, timeZoneOffset);
                }
                result.Replace(sDateLastActivityReplacement, sDateLastActivity);

                // Post Count
                result.Replace("[AF:PROFILE:POSTCOUNT]", (up.PostCount == 0) ? string.Empty : up.PostCount.ToString());
                result.Replace("[AF:PROFILE:USERCAPTION]", up.Profile.UserCaption);
                result.Replace("[AF:PROFILE:USERID]", up.UserId.ToString());
                result.Replace("[AF:PROFILE:USERNAME]", Utilities.HTMLEncode(up.UserName).Replace("&amp;#", "&#"));
                result.Replace("[AF:PROFILE:FIRSTNAME]", Utilities.HTMLEncode(up.FirstName).Replace("&amp;#", "&#"));
                result.Replace("[AF:PROFILE:LASTNAME]", Utilities.HTMLEncode(up.LastName).Replace("&amp;#", "&#"));
                result.Replace("[AF:PROFILE:DATELASTPOST]", (up.Profile.DateLastPost == DateTime.MinValue) ? string.Empty : Utilities.GetDate(up.Profile.DateLastPost, moduleId, timeZoneOffset));
                result.Replace("[AF:PROFILE:TOPICCOUNT]", up.Profile.TopicCount.ToString());
                result.Replace("[AF:PROFILE:REPLYCOUNT]", up.Profile.ReplyCount.ToString());
                result.Replace("[AF:PROFILE:ANSWERCOUNT]", up.Profile.AnswerCount.ToString());
                result.Replace("[AF:PROFILE:REWARDPOINTS]", up.Profile.RewardPoints.ToString());

                return result.ToString();
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
예제 #5
0
 public static string ParseProfileTemplate(string profileTemplate, User up, int portalId, int moduleId, string imagePath, CurrentUserTypes currentUserType, bool legacyTemplate, bool userPrefHideAvatar, bool userPrefHideSignature, string ipAddress, int timeZoneOffset)
 {
     return ParseProfileTemplate(profileTemplate, up, portalId, moduleId, imagePath, currentUserType, legacyTemplate, userPrefHideAvatar, userPrefHideSignature, ipAddress, -1, timeZoneOffset);
 }
예제 #6
0
 public static string ParseProfileTemplate(string profileTemplate, User up, int portalId, int moduleId, string imagePath, CurrentUserTypes currentUserType, bool legacyTemplate, int timeZoneOffset)
 {
     return ParseProfileTemplate(profileTemplate, up, portalId, moduleId, imagePath, currentUserType, false, false, false, string.Empty, -1, timeZoneOffset);
 }
예제 #7
0
        public static string ParseProfileInfo(int portalId, int moduleId, int userId, string username, User up, string imagePath, bool isMod, string ipAddress, CurrentUserTypes currentUserType, int currentUserId, bool userPrefHideAvatar, int timeZoneOffset)
        {
            var mainSettings = DataCache.MainSettings(moduleId);

            var cacheKey = string.Format(CacheKeys.PostInfo, moduleId);
            var myTemplate = Convert.ToString(DataCache.CacheRetrieve(cacheKey));
            if (string.IsNullOrEmpty(myTemplate))
            {
                var objTemplateInfo = GetTemplateByName("ProfileInfo", moduleId, portalId);
                myTemplate = objTemplateInfo.TemplateHTML;
                if (cacheKey != string.Empty)
                    DataCache.CacheStore(cacheKey, myTemplate);
            }

            myTemplate = ParseProfileTemplate(myTemplate, up, portalId, moduleId, imagePath, currentUserType, true, userPrefHideAvatar, false, ipAddress, currentUserId, timeZoneOffset);

            return myTemplate;
        }
예제 #8
0
		public User DNNGetCurrentUser(int SiteId, int ModuleId)
		{
			PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
			User u = new User();
			DotNetNuke.Entities.Users.UserInfo cu = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
			u = LoadUser(cu);

			u = FillProfile(SiteId, ModuleId, u);
			ForumController fc = new ForumController();
			string fs = fc.GetForumsForUser(u.UserRoles, SiteId, ModuleId, "CanApprove");
			if (! (string.IsNullOrEmpty(fs)))
			{
				u.Profile.IsMod = true;
			}
			else
			{
				u.Profile.IsMod = false;
			}


			return u;
		}
예제 #9
0
		internal User LoadUser(DotNetNuke.Entities.Users.UserInfo dnnUser)
		{
			PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
			User u = new User();
			DotNetNuke.Entities.Users.UserInfo cu = dnnUser;

			u.UserId = cu.UserID;
			u.UserName = cu.Username;
			u.IsSuperUser = cu.IsSuperUser;
			u.IsAdmin = cu.IsInRole(_portalSettings.AdministratorRoleName);
			u.DateCreated = cu.Membership.CreatedDate;
			u.DateUpdated = cu.Membership.LastActivityDate;
			u.FirstName = cu.FirstName;
			u.LastName = cu.LastName;
			u.DisplayName = cu.DisplayName;
			u.Email = cu.Email;
			u.UserRoles = GetRoleIds(cu.Roles, _portalSettings.PortalId); //RolesToString(cu.Roles)
			if (cu.IsSuperUser)
			{
				u.UserRoles += Globals.DefaultAnonRoles + _portalSettings.AdministratorRoleId + ";";
			}
			Social social = new Social();
			u.UserRoles += "|" + cu.UserID + "|" + social.ActiveSocialGroups(cu.UserID, _portalSettings.PortalId) + "|";

			if (! cu.IsSuperUser)
			{
				u.Properties = GetUserProperties(dnnUser);
			}

			return u;
		}
예제 #10
0
		public User FillProfile(int SiteId, int ModuleId, User u)
		{
			if (u != null && u.UserId > 0)
			{
				u.Profile = Profiles_Get(SiteId, ModuleId, u.UserId);
			}
			return u;
		}
예제 #11
0
		public User GetDNNUser(int SiteId, int ModuleId, string userName)
		{
			PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
			User u = new User();
			DotNetNuke.Entities.Users.UserInfo dnnUser = DotNetNuke.Entities.Users.UserController.GetUserByName(_portalSettings.PortalId, userName);
			u = LoadUser(dnnUser);
			return u;
		}
예제 #12
0
		private User GetDNNUser(int SiteId, int ModuleId, int userId)
		{
			PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
			User u = new User();
			DotNetNuke.Entities.Users.UserController uc = new DotNetNuke.Entities.Users.UserController();
			DotNetNuke.Entities.Users.UserInfo dnnUser = uc.GetUser(_portalSettings.PortalId, userId);
			u = LoadUser(dnnUser);
			return u;
		}
예제 #13
0
		public string GetForumsHtmlOption(int portalId, int moduleId, User currentUser)
		{
			var userForums = GetForumsForUser(currentUser.UserRoles, portalId, moduleId, "CanView");
			var dt = DataProvider.Instance().UI_ForumView(portalId, moduleId, currentUser.UserId, currentUser.IsSuperUser, userForums).Tables[0];
			var i = 0;
			var n = 1;
			var tmpGroupCount = 0;
			var tmpForumCount = 0;
			var tmpGroupKey = string.Empty;
			var tmpForumKey = string.Empty;
			var sb = new StringBuilder();
			foreach (DataRow dr in dt.Rows)
			{
				var bView = Permissions.HasPerm(dr["CanView"].ToString(), currentUser.UserRoles);
				var groupName = Convert.ToString(dr["GroupName"]);
				var groupId = Convert.ToInt32(dr["ForumGroupId"]);
				var groupKey = groupName + groupId.ToString();
				var forumName = Convert.ToString(dr["ForumName"]);
				var forumId = Convert.ToInt32(dr["ForumId"]);
				var forumKey = forumName + forumId.ToString();
				var parentForumId = Convert.ToInt32(dr["ParentForumId"]);

				//TODO - Need to add support for Group Permissions and GroupHidden

				if (tmpGroupKey != groupKey)
				{
					sb.AppendFormat("<option value=\"{0}\">{1}</option>", "-1", groupName);
					n += 1;
					tmpGroupKey = groupKey;
				}

				if (bView)
				{
					if (parentForumId == 0)
					{
						sb.AppendFormat("<option value=\"{0}\">{1}</option>", dr["ForumID"], "--" + dr["ForumName"]);
						n += 1;
						sb.Append(GetSubForums(n, Convert.ToInt32(dr["ForumId"]), dt, ref n));
					}

				}
			}

			return sb.ToString();
		}