예제 #1
0
        private string MatchUserBoxGroups([NotNull] string userBox, [NotNull] DataTable roleStyleTable)
        {
            const string StyledNick = @"<span class=""YafGroup_{0}"" style=""{1}"">{0}</span>";

            string filler = string.Empty;

            Regex rx = this.GetRegex(Constants.UserBox.Groups);

            if (this.Get <YafBoardSettings>().ShowGroups)
            {
                var groupsText = new StringBuilder(500);

                bool   bFirst    = true;
                string roleStyle = null;

                foreach (string role in RoleMembershipHelper.GetRolesForUser(this.DataRow["UserName"].ToString()))
                {
                    string role1 = role;

                    foreach (DataRow drow in
                             roleStyleTable.Rows.Cast <DataRow>().Where(drow => drow["LegendID"].ToType <int>() == 1 && drow["Style"] != null && drow["Name"].ToString() == role1))
                    {
                        roleStyle = this.TransformStyle.DecodeStyleByString(drow["Style"].ToString(), true);
                        break;
                    }

                    if (bFirst)
                    {
                        groupsText.AppendLine(
                            this.Get <YafBoardSettings>().UseStyledNicks ? StyledNick.FormatWith(role, roleStyle) : role);

                        bFirst = false;
                    }
                    else
                    {
                        if (this.Get <YafBoardSettings>().UseStyledNicks)
                        {
                            groupsText.AppendLine((@", " + StyledNick).FormatWith(role, roleStyle));
                        }
                        else
                        {
                            groupsText.AppendFormat(", {0}", role);
                        }
                    }

                    roleStyle = null;
                }

                filler = this.Get <YafBoardSettings>().UserBoxGroups.FormatWith(
                    this.GetText("groups"), groupsText);

                // mddubs : 02/21/2009
                // Remove the space before the first comma when multiple groups exist.
                filler = filler.Replace("\r\n,", ",");
            }

            // replaces template placeholder with actual groups
            userBox = rx.Replace(userBox, filler);
            return(userBox);
        }
예제 #2
0
        private string MatchUserBoxGroups([NotNull] string userBox, [NotNull] DataTable roleStyleTable)
        {
            const string StyledNick = @"<span class=""YafGroup_{0}"" style=""{1}"">{0}</span>";

            string filler = string.Empty;

            Regex rx = this.GetRegex(Constants.UserBox.Groups);

            if (this.Get <YafBoardSettings>().ShowGroups)
            {
                var groupsText = new StringBuilder(500);

                bool   bFirst    = true;
                bool   hasRole   = false;
                string roleStyle = null;

                var userName = this.DataRow["IsGuest"].ToType <bool>()
                                   ? UserMembershipHelper.GuestUserName
                                   : this.DataRow["UserName"].ToString();

                foreach (string role in RoleMembershipHelper.GetRolesForUser(userName))
                {
                    string role1 = role;

                    foreach (DataRow drow in
                             roleStyleTable.Rows.Cast <DataRow>().Where(
                                 drow =>
                                 drow["LegendID"].ToType <int>() == 1 && drow["Style"] != null &&
                                 drow["Name"].ToString() == role1))
                    {
                        roleStyle = this.TransformStyle.DecodeStyleByString(drow["Style"].ToString(), true);
                        break;
                    }

                    if (bFirst)
                    {
                        groupsText.AppendLine(
                            this.Get <YafBoardSettings>().UseStyledNicks ? StyledNick.FormatWith(role, roleStyle) : role);

                        bFirst = false;
                    }
                    else
                    {
                        if (this.Get <YafBoardSettings>().UseStyledNicks)
                        {
                            groupsText.AppendLine((@", " + StyledNick).FormatWith(role, roleStyle));
                        }
                        else
                        {
                            groupsText.AppendFormat(", {0}", role);
                        }
                    }

                    roleStyle = null;
                    hasRole   = true;
                }

                // vzrus: Only a guest normally has no role
                if (!hasRole)
                {
                    DataTable dt = this.Get <IDataCache>().GetOrSet(
                        Constants.Cache.GuestGroupsCache,
                        () => LegacyDb.group_member(PageContext.PageBoardID, this.DataRow["UserID"]),
                        TimeSpan.FromMinutes(60));

                    foreach (string guestRole in
                             dt.Rows.Cast <DataRow>().Where(role => role["Member"].ToType <int>() > 0).Select(
                                 role => role["Name"].ToString()))
                    {
                        foreach (DataRow drow in
                                 roleStyleTable.Rows.Cast <DataRow>().Where(
                                     drow =>
                                     drow["LegendID"].ToType <int>() == 1 && drow["Style"] != null &&
                                     drow["Name"].ToString() == guestRole))
                        {
                            roleStyle = this.TransformStyle.DecodeStyleByString(drow["Style"].ToString(), true);
                            break;
                        }

                        groupsText.AppendLine(
                            this.Get <YafBoardSettings>().UseStyledNicks
                                ? StyledNick.FormatWith(guestRole, roleStyle)
                                : guestRole);
                        break;
                    }
                }

                filler = this.Get <YafBoardSettings>().UserBoxGroups.FormatWith(this.GetText("groups"), groupsText);

                // mddubs : 02/21/2009
                // Remove the space before the first comma when multiple groups exist.
                filler = filler.Replace("\r\n,", ",");
            }

            // replaces template placeholder with actual groups
            userBox = rx.Replace(userBox, filler);
            return(userBox);
        }