Пример #1
0
        public static void Show(Core core, GPage page, long forumId, long topicId)
        {
            long m = core.Functions.RequestLong("m", 0); // post, seeing as p has been globally reserved for page and cannot be used for post, we use m for message
            Forum thisForum = null;

            core.Template.SetTemplate("Forum", "viewtopic");
            ForumSettings.ShowForumHeader(core, page);

            ForumSettings settings = new ForumSettings(core, page.Owner);

            try
            {
                if (forumId == 0)
                {
                    thisForum = new Forum(page.Core, page.Group);
                }
                else
                {
                    thisForum = new Forum(page.Core, forumId);
                }
            }
            catch (InvalidForumException)
            {
                // ignore
            }

            try
            {
                ForumTopic thisTopic = new ForumTopic(core, thisForum, topicId);

                if (thisForum == null)
                {
                    thisForum = thisTopic.Forum;
                }

                if (!thisForum.Access.Can("VIEW_TOPICS"))
                {
                    core.Functions.Generate403();
                    return;
                }

                if (page is GPage)
                {
                    if (core.LoggedInMemberId > 0 && (!((GPage)page).Group.IsGroupMember(core.Session.LoggedInMember.ItemKey)))
                    {
                        core.Template.Parse("U_JOIN", ((GPage)page).Group.JoinUri);
                    }
                }

                core.Template.Parse("PAGE_TITLE", thisTopic.Title);
                core.Template.Parse("TOPIC_TITLE", thisTopic.Title);

                List<TopicPost> posts;
                if (m > 0)
                {
                    posts = thisTopic.GetPosts(m, settings.PostsPerPage);
                }
                else
                {
                    posts = thisTopic.GetPosts(page.TopLevelPageNumber, settings.PostsPerPage);
                }

                core.Template.Parse("POSTS", posts.Count.ToString());

                List<long> posterIds = new List<long>();
                List<long> rankIds = new List<long>();

                foreach (TopicPost post in posts)
                {
                    if (!posterIds.Contains(post.UserId))
                    {
                        posterIds.Add(post.UserId);
                    }
                }

                Dictionary<long, ForumMember> postersList = ForumMember.GetMembers(core, thisForum.Owner, posterIds);

                foreach (ForumMember fm in postersList.Values)
                {
                    if (!rankIds.Contains(fm.ForumRankId))
                    {
                        rankIds.Add(fm.ForumRankId);
                    }
                }

                /*Dictionary<long, ForumMemberRank> ranksList = null;

                if (rankIds.Count > 0)
                {
                    ranksList = ForumMemberRank.GetRanks(core, thisForum.Owner, rankIds);
                }
                else
                {
                    ranksList = new Dictionary<long, ForumMemberRank>();
                }*/

                Dictionary<long, ForumMemberRank> ranksList = ForumMemberRank.GetRanks(core, thisForum.Owner);

                foreach (ForumMember fm in postersList.Values)
                {
                    if (!(ranksList.ContainsKey(fm.ForumRankId) && ranksList[fm.ForumRankId].RankSpecial))
                    {
                        int rankLastMin = 0;
                        foreach (ForumMemberRank rank in ranksList.Values)
                        {
                            if ((!rank.RankSpecial) && fm.ForumPosts >= rank.RankPosts && rank.RankPosts > rankLastMin)
                            {
                                fm.ForumRankId = rank.Id;
                                rankLastMin = rank.RankPosts;
                            }
                        }
                    }
                }

                foreach (TopicPost post in posts)
                {
                    VariableCollection postVariableCollection = core.Template.CreateChild("post_list");

                    postVariableCollection.Parse("SUBJECT", post.Title);
                    postVariableCollection.Parse("POST_TIME", core.Tz.DateTimeToString(post.GetCreatedDate(core.Tz)));
                    postVariableCollection.Parse("URI", post.Uri);
                    //postVariableCollection.Parse("POST_MODIFIED", core.tz.DateTimeToString(post.GetModifiedDate(core.tz)));
                    postVariableCollection.Parse("ID", post.Id.ToString());
                    core.Display.ParseBbcode(postVariableCollection, "TEXT", post.Text);
                    if (postersList.ContainsKey(post.UserId))
                    {
                        postVariableCollection.Parse("U_USER", post.Poster.Uri);
                        postVariableCollection.Parse("USER_DISPLAY_NAME", postersList[post.UserId].UserInfo.DisplayName);
                        postVariableCollection.Parse("USER_TILE", postersList[post.UserId].Tile);
                        postVariableCollection.Parse("USER_ICON", postersList[post.UserId].Icon);
                        postVariableCollection.Parse("USER_JOINED", core.Tz.DateTimeToString(postersList[post.UserId].UserInfo.GetRegistrationDate(core.Tz)));
                        postVariableCollection.Parse("USER_COUNTRY", postersList[post.UserId].Profile.Country);
                        postVariableCollection.Parse("USER_POSTS", postersList[post.UserId].ForumPosts.ToString());
                        core.Display.ParseBbcode(postVariableCollection, "SIGNATURE", postersList[post.UserId].ForumSignature);

                        if (ranksList.ContainsKey(postersList[post.UserId].ForumRankId))
                        {
                            postVariableCollection.Parse("USER_RANK", ranksList[postersList[post.UserId].ForumRankId].RankTitleText);
                        }
                    }
                    else
                    {
                        postVariableCollection.Parse("USER_DISPLAY_NAME", "Anonymous");
                    }

                    if (thisTopic.ReadStatus == null)
                    {
                        postVariableCollection.Parse("IS_READ", "FALSE");
                    }
                    else
                    {
                        if (thisTopic.ReadStatus.ReadTimeRaw < post.TimeCreatedRaw)
                        {
                            postVariableCollection.Parse("IS_READ", "FALSE");
                        }
                        else
                        {
                            postVariableCollection.Parse("IS_READ", "TRUE");
                        }
                    }
                }

                if (posts.Count > 0)
                {
                    thisTopic.Read(posts[posts.Count - 1]);
                }

                ItemView.LogView(core, thisTopic);

                if (thisForum.Access.Can("CREATE_TOPICS"))
                {
                    core.Template.Parse("U_NEW_TOPIC", thisForum.NewTopicUri);
                }
                if (thisForum.Access.Can("REPLY_TOPICS") && (!thisTopic.IsLocked))
                {
                    core.Template.Parse("U_NEW_REPLY", thisTopic.ReplyUri);
                }

                core.Display.ParsePagination(thisTopic.Uri, settings.PostsPerPage, thisTopic.Posts + 1);

                List<string[]> breadCrumbParts = new List<string[]>();
                breadCrumbParts.Add(new string[] { "forum", core.Prose.GetString("FORUM") });

                if (thisForum.Parents != null)
                {
                    foreach (ParentTreeNode ptn in thisForum.Parents.Nodes)
                    {
                        breadCrumbParts.Add(new string[] { "*" + ptn.ParentId.ToString(), ptn.ParentTitle });
                    }
                }

                if (thisForum.Id > 0)
                {
                    breadCrumbParts.Add(new string[] { thisForum.Id.ToString(), thisForum.Title });
                }

                breadCrumbParts.Add(new string[] { "topic-" + thisTopic.Id.ToString(), thisTopic.Title });

                page.Group.ParseBreadCrumbs(breadCrumbParts);
            }
            catch (InvalidTopicException)
            {
                return;
            }
        }
Пример #2
0
        public static void ShowMemberlist(Core core, GPage page)
        {
            core.Template.SetTemplate("Groups", "viewgroupmemberlist");

            core.Template.Parse("PAGE_TITLE", "Member list for " + page.Group.DisplayName);
            core.Template.Parse("MEMBERS_TITLE", "Member list for " + page.Group.DisplayName);
            core.Template.Parse("MEMBERS", ((ulong)page.Group.Members).ToString());

            core.Template.Parse("U_FILTER_ALL", page.Group.MemberlistUri);
            core.Template.Parse("U_FILTER_BEGINS_A", page.Group.GetMemberlistUri("a"));
            core.Template.Parse("U_FILTER_BEGINS_B", page.Group.GetMemberlistUri("b"));
            core.Template.Parse("U_FILTER_BEGINS_C", page.Group.GetMemberlistUri("c"));
            core.Template.Parse("U_FILTER_BEGINS_D", page.Group.GetMemberlistUri("d"));
            core.Template.Parse("U_FILTER_BEGINS_E", page.Group.GetMemberlistUri("e"));
            core.Template.Parse("U_FILTER_BEGINS_F", page.Group.GetMemberlistUri("f"));
            core.Template.Parse("U_FILTER_BEGINS_G", page.Group.GetMemberlistUri("g"));
            core.Template.Parse("U_FILTER_BEGINS_H", page.Group.GetMemberlistUri("h"));
            core.Template.Parse("U_FILTER_BEGINS_I", page.Group.GetMemberlistUri("i"));
            core.Template.Parse("U_FILTER_BEGINS_J", page.Group.GetMemberlistUri("j"));
            core.Template.Parse("U_FILTER_BEGINS_K", page.Group.GetMemberlistUri("k"));
            core.Template.Parse("U_FILTER_BEGINS_L", page.Group.GetMemberlistUri("l"));
            core.Template.Parse("U_FILTER_BEGINS_M", page.Group.GetMemberlistUri("m"));
            core.Template.Parse("U_FILTER_BEGINS_N", page.Group.GetMemberlistUri("n"));
            core.Template.Parse("U_FILTER_BEGINS_O", page.Group.GetMemberlistUri("o"));
            core.Template.Parse("U_FILTER_BEGINS_P", page.Group.GetMemberlistUri("p"));
            core.Template.Parse("U_FILTER_BEGINS_Q", page.Group.GetMemberlistUri("q"));
            core.Template.Parse("U_FILTER_BEGINS_R", page.Group.GetMemberlistUri("r"));
            core.Template.Parse("U_FILTER_BEGINS_S", page.Group.GetMemberlistUri("s"));
            core.Template.Parse("U_FILTER_BEGINS_T", page.Group.GetMemberlistUri("t"));
            core.Template.Parse("U_FILTER_BEGINS_U", page.Group.GetMemberlistUri("u"));
            core.Template.Parse("U_FILTER_BEGINS_V", page.Group.GetMemberlistUri("v"));
            core.Template.Parse("U_FILTER_BEGINS_W", page.Group.GetMemberlistUri("w"));
            core.Template.Parse("U_FILTER_BEGINS_X", page.Group.GetMemberlistUri("x"));
            core.Template.Parse("U_FILTER_BEGINS_Y", page.Group.GetMemberlistUri("y"));
            core.Template.Parse("U_FILTER_BEGINS_Z", page.Group.GetMemberlistUri("z"));

            if (page.Group.IsGroupOperator(core.LoggedInMemberItemKey))
            {
                core.Template.Parse("GROUP_OPERATOR", "TRUE");

                SelectQuery query = GroupMember.GetSelectQueryStub(core, UserLoadOptions.All);
                query.AddCondition("group_members.group_id", page.Group.Id);
                query.AddCondition("group_member_approved", false);
                query.AddSort(SortOrder.Ascending, "group_member_date_ut");

                System.Data.Common.DbDataReader approvalReader = core.Db.ReaderQuery(query);

                if (approvalReader.HasRows)
                {
                    core.Template.Parse("IS_WAITING_APPROVAL", "TRUE");
                }

                while(approvalReader.Read())
                {
                    GroupMember approvalMember = new GroupMember(core, approvalReader, UserLoadOptions.Profile);

                    VariableCollection approvalVariableCollection = core.Template.CreateChild("approval_list");

                    approvalVariableCollection.Parse("USER_DISPLAY_NAME", approvalMember.DisplayName);
                    approvalVariableCollection.Parse("U_PROFILE", approvalMember.Uri);
                    approvalVariableCollection.Parse("U_APPROVE", approvalMember.ApproveMemberUri);
                }

                approvalReader.Close();
                approvalReader.Dispose();

            }

            List<GroupMember> members = page.Group.GetMembers(page.TopLevelPageNumber, 18, core.Functions.GetFilter());
            foreach (GroupMember member in members)
            {
                VariableCollection memberVariableCollection = core.Template.CreateChild("member_list");

                memberVariableCollection.Parse("USER_DISPLAY_NAME", member.DisplayName);
                memberVariableCollection.Parse("JOIN_DATE", page.tz.DateTimeToString(member.GetGroupMemberJoinDate(page.tz)));
                memberVariableCollection.Parse("USER_AGE", member.Profile.AgeString);
                memberVariableCollection.Parse("USER_COUNTRY", member.Profile.Country);
                memberVariableCollection.Parse("USER_CAPTION", string.Empty);

                memberVariableCollection.Parse("U_PROFILE", member.Uri);
                if (core.LoggedInMemberId > 0)
                {
                    if (page.Group.IsGroupOperator(core.LoggedInMemberItemKey))
                    {
                        if (!member.IsOperator)
                        {
                            // let's say you can't ban an operator, show ban link if not an operator
                            memberVariableCollection.Parse("U_BAN", member.BanUri);
                            memberVariableCollection.Parse("U_MAKE_OPERATOR", member.MakeOperatorUri);
                        }

                        memberVariableCollection.Parse("U_MAKE_OFFICER", member.MakeOfficerUri);
                    }
                }
                memberVariableCollection.Parse("ICON", member.Icon);
                memberVariableCollection.Parse("TILE", member.Tile);
                memberVariableCollection.Parse("MOBILE_COVER", member.MobileCoverPhoto);

                memberVariableCollection.Parse("ID", member.Id);
                memberVariableCollection.Parse("TYPE", member.TypeId);
                memberVariableCollection.Parse("LOCATION", member.Profile.Country);
                memberVariableCollection.Parse("ABSTRACT", page.Core.Bbcode.Parse(member.Profile.Autobiography));
                memberVariableCollection.Parse("SUBSCRIBERS", member.Info.Subscribers);

                if (Subscription.IsSubscribed(page.Core, member.ItemKey))
                {
                    memberVariableCollection.Parse("SUBSCRIBERD", "TRUE");
                    memberVariableCollection.Parse("U_SUBSCRIBE", page.Core.Hyperlink.BuildUnsubscribeUri(member.ItemKey));
                }
                else
                {
                    memberVariableCollection.Parse("U_SUBSCRIBE", page.Core.Hyperlink.BuildSubscribeUri(member.ItemKey));
                }

                if (page.Core.Session.SignedIn && member.Id == page.Core.LoggedInMemberId)
                {
                    memberVariableCollection.Parse("ME", "TRUE");
                }
            }

            string pageUri = page.Group.MemberlistUri;
            core.Display.ParsePagination(pageUri, 18, page.Group.Members);

            List<string[]> breadCrumbParts = new List<string[]>();

            breadCrumbParts.Add(new string[] { "members", core.Prose.GetString("MEMBERS") });

            page.Group.ParseBreadCrumbs(breadCrumbParts);
        }
Пример #3
0
        public static void Show(Core core, GPage page)
        {
            core.Template.SetTemplate("GuestBook", "viewguestbook");

            if (core.Session.IsLoggedIn)
            {
                if (page.Group.IsGroupMember(core.Session.LoggedInMember.ItemKey))
                {
                    core.Template.Parse("CAN_COMMENT", "TRUE");
                }
            }

            /* Pages */
            core.Display.ParsePageList(page.Owner, true);

            core.Template.Parse("PAGE_TITLE", string.Format(core.Prose.GetString("USERS_GUEST_BOOK"), page.Owner.DisplayNameOwnership));

            core.Display.DisplayComments(core.Template, page.Group, page.Group);
            core.Display.ParsePagination("COMMENT_PAGINATION", GuestBook.Uri(core, page.Group), 10, page.Group.Comments);

            List<string[]> breadCrumbParts = new List<string[]>();

            breadCrumbParts.Add(new string[] { "comments", core.Prose.GetString("GUEST_BOOK") });

            page.Group.ParseBreadCrumbs(breadCrumbParts);
            //Prose.GetString("GuestBook");
        }
Пример #4
0
        public static void Show(Core core, GPage page)
        {
            core.Template.SetTemplate("Groups", "viewgroup");

            core.Template.Parse("U_GROUP", page.Group.Uri);
            core.Template.Parse("GROUP_DISPLAY_NAME", page.Group.DisplayName);

            /* pages */
            core.Display.ParsePageList(page.Owner, true);

            core.Template.Parse("PRIMITIVE_THUMB", page.Owner.Thumbnail);
            core.Template.Parse("USER_ICON", page.Owner.Thumbnail);
            core.Template.Parse("USER_COVER_PHOTO", page.Owner.CoverPhoto);
            core.Template.Parse("USER_MOBILE_COVER_PHOTO", page.Owner.MobileCoverPhoto);

            string langMembers = (page.Group.Members != 1) ? "members" : "member";
            string langIsAre = (page.Group.Members != 1) ? "are" : "is";

            //page.template.ParseRaw("DESCRIPTION", Bbcode.Parse(HttpUtility.HtmlEncode(page.ThisGroup.Description), core.session.LoggedInMember));
            core.Display.ParseBbcode("DESCRIPTION", page.Group.Description);
            core.Template.Parse("DATE_CREATED", core.Tz.DateTimeToString(page.Group.DateCreated(core.Tz)));
            core.Template.Parse("CATEGORY", page.Group.Category);

            core.Template.Parse("MEMBERS", page.Group.Members.ToString());
            core.Template.Parse("OPERATORS", page.Group.Operators.ToString());
            core.Template.Parse("OFFICERS", page.Group.Officers.ToString());
            core.Template.Parse("L_MEMBERS", langMembers);
            core.Template.Parse("L_IS_ARE", langIsAre);
            core.Template.Parse("U_MEMBERLIST", page.Group.MemberlistUri);

            if (core.Session.IsLoggedIn)
            {
                if (page.Group.IsGroupOperator(core.Session.LoggedInMember.ItemKey))
                {
                    core.Template.Parse("IS_OPERATOR", "TRUE");
                    core.Template.Parse("U_GROUP_ACCOUNT", core.Hyperlink.AppendSid(page.Group.AccountUriStub));
                }

                if (!page.Group.IsGroupMemberAbsolute(core.Session.LoggedInMember.ItemKey))
                {
                    core.Template.Parse("U_JOIN", page.Group.JoinUri);
                }
                else
                {
                    if (!page.Group.IsGroupOperator(core.Session.LoggedInMember.ItemKey))
                    {
                        if (page.Group.IsGroupMember(core.Session.LoggedInMember.ItemKey))
                        {
                            core.Template.Parse("U_LEAVE", page.Group.LeaveUri);
                        }
                        else if (page.Group.IsGroupMemberPending(core.Session.LoggedInMember.ItemKey))
                        {
                            core.Template.Parse("U_CANCEL", page.Group.LeaveUri);
                        }
                    }

                    if (page.Group.IsGroupMember(core.Session.LoggedInMember.ItemKey))
                    {
                        core.Template.Parse("U_INVITE", page.Group.InviteUri);
                    }
                }
            }

            List<GroupMember> members = page.Group.GetMembers(1, 8);

            foreach (GroupMember member in members)
            {
                VariableCollection membersVariableCollection = core.Template.CreateChild("member_list");

                membersVariableCollection.Parse("USER_DISPLAY_NAME", member.DisplayName);
                membersVariableCollection.Parse("U_PROFILE", member.Uri);
                membersVariableCollection.Parse("ICON", member.Icon);
                membersVariableCollection.Parse("TILE", member.Tile);
            }

            List<GroupMember> operators = page.Group.GetOperators();

            foreach (GroupMember groupOperator in operators)
            {
                VariableCollection operatorsVariableCollection = core.Template.CreateChild("operator_list");

                operatorsVariableCollection.Parse("USER_DISPLAY_NAME", groupOperator.DisplayName);
                operatorsVariableCollection.Parse("U_PROFILE", groupOperator.Uri);
                if (core.Session.LoggedInMember != null)
                {
                    if (groupOperator.UserId == core.Session.LoggedInMember.UserId)
                    {
                        operatorsVariableCollection.Parse("U_RESIGN", page.Group.ResignOperatorUri);
                    }
                }
            }

            List<GroupOfficer> officers = page.Group.GetOfficers();

            foreach (GroupOfficer groupOfficer in officers)
            {
                VariableCollection officersVariableCollection = core.Template.CreateChild("officer_list");

                officersVariableCollection.Parse("USER_DISPLAY_NAME", groupOfficer.DisplayName);
                officersVariableCollection.Parse("U_PROFILE", groupOfficer.Uri);
                officersVariableCollection.Parse("OFFICER_TITLE", groupOfficer.OfficeTitle);
                if (core.LoggedInMemberId > 0)
                {
                    if (page.Group.IsGroupOperator(core.Session.LoggedInMember.ItemKey))
                    {
                        officersVariableCollection.Parse("U_REMOVE", groupOfficer.BuildRemoveOfficerUri());
                    }
                }
            }

            List<string[]> breadCrumbParts = new List<string[]>();
            if (!core.IsMobile)
            {
                breadCrumbParts.Add(new string[] { "profile", core.Prose.GetString("PROFILE") });
            }

            page.Owner.ParseBreadCrumbs(breadCrumbParts);

            core.InvokeHooks(new HookEventArgs(core, AppPrimitives.Group, page.Group));
        }
Пример #5
0
 public ShowGPageEventArgs(GPage page)
     : base(page)
 {
 }
Пример #6
0
 public ShowGPageEventArgs(GPage page, long itemId)
     : base(page, itemId)
 {
 }
Пример #7
0
        public static void ShowMemberlist(Core core, GPage page)
        {
            core.Template.SetTemplate("Forum", "memberlist");
            ForumSettings.ShowForumHeader(core, page);
            ForumSettings settings = new ForumSettings(core, page.Owner);

            core.Template.Parse("PAGE_TITLE", core.Prose.GetString("MEMBERLIST"));

            core.Template.Parse("U_FILTER_ALL", GenerateMemberlistUri(core, page.Group));
            core.Template.Parse("U_FILTER_BEGINS_A", GenerateMemberlistUri(core, page.Owner, "a"));
            core.Template.Parse("U_FILTER_BEGINS_B", GenerateMemberlistUri(core, page.Owner, "b"));
            core.Template.Parse("U_FILTER_BEGINS_C", GenerateMemberlistUri(core, page.Owner, "c"));
            core.Template.Parse("U_FILTER_BEGINS_D", GenerateMemberlistUri(core, page.Owner, "d"));
            core.Template.Parse("U_FILTER_BEGINS_E", GenerateMemberlistUri(core, page.Owner, "e"));
            core.Template.Parse("U_FILTER_BEGINS_F", GenerateMemberlistUri(core, page.Owner, "f"));
            core.Template.Parse("U_FILTER_BEGINS_G", GenerateMemberlistUri(core, page.Owner, "g"));
            core.Template.Parse("U_FILTER_BEGINS_H", GenerateMemberlistUri(core, page.Owner, "h"));
            core.Template.Parse("U_FILTER_BEGINS_I", GenerateMemberlistUri(core, page.Owner, "i"));
            core.Template.Parse("U_FILTER_BEGINS_J", GenerateMemberlistUri(core, page.Owner, "j"));
            core.Template.Parse("U_FILTER_BEGINS_K", GenerateMemberlistUri(core, page.Owner, "k"));
            core.Template.Parse("U_FILTER_BEGINS_L", GenerateMemberlistUri(core, page.Owner, "l"));
            core.Template.Parse("U_FILTER_BEGINS_M", GenerateMemberlistUri(core, page.Owner, "m"));
            core.Template.Parse("U_FILTER_BEGINS_N", GenerateMemberlistUri(core, page.Owner, "n"));
            core.Template.Parse("U_FILTER_BEGINS_O", GenerateMemberlistUri(core, page.Owner, "o"));
            core.Template.Parse("U_FILTER_BEGINS_P", GenerateMemberlistUri(core, page.Owner, "p"));
            core.Template.Parse("U_FILTER_BEGINS_Q", GenerateMemberlistUri(core, page.Owner, "q"));
            core.Template.Parse("U_FILTER_BEGINS_R", GenerateMemberlistUri(core, page.Owner, "r"));
            core.Template.Parse("U_FILTER_BEGINS_S", GenerateMemberlistUri(core, page.Owner, "s"));
            core.Template.Parse("U_FILTER_BEGINS_T", GenerateMemberlistUri(core, page.Owner, "t"));
            core.Template.Parse("U_FILTER_BEGINS_U", GenerateMemberlistUri(core, page.Owner, "u"));
            core.Template.Parse("U_FILTER_BEGINS_V", GenerateMemberlistUri(core, page.Owner, "v"));
            core.Template.Parse("U_FILTER_BEGINS_W", GenerateMemberlistUri(core, page.Owner, "w"));
            core.Template.Parse("U_FILTER_BEGINS_X", GenerateMemberlistUri(core, page.Owner, "x"));
            core.Template.Parse("U_FILTER_BEGINS_Y", GenerateMemberlistUri(core, page.Owner, "y"));
            core.Template.Parse("U_FILTER_BEGINS_Z", GenerateMemberlistUri(core, page.Owner, "z"));

            Dictionary<long, ForumMember> members = ForumMember.GetMembers(core, page.Owner, core.Functions.GetFilter(), page.TopLevelPageNumber, 20);

            foreach (ForumMember member in members.Values)
            {
                VariableCollection memberVariableCollection = core.Template.CreateChild("member_list");

                memberVariableCollection.Parse("USER_DISPLAY_NAME", member.DisplayName);
                //memberVariableCollection.Parse("JOIN_DATE", page.tz.DateTimeToString(member.GetGroupMemberJoinDate(page.tz)));
                memberVariableCollection.Parse("USER_COUNTRY", member.Profile.Country);

                memberVariableCollection.Parse("U_PROFILE", member.Uri);

                memberVariableCollection.Parse("POSTS", member.ForumPosts.ToString());

                memberVariableCollection.Parse("ICON", member.Icon);
                memberVariableCollection.Parse("TILE", member.Tile);
                memberVariableCollection.Parse("MOBILE_COVER", member.MobileCoverPhoto);

                memberVariableCollection.Parse("ID", member.Id);
                memberVariableCollection.Parse("TYPE", member.TypeId);
                memberVariableCollection.Parse("LOCATION", member.Profile.Country);
                memberVariableCollection.Parse("ABSTRACT", page.Core.Bbcode.Parse(member.Profile.Autobiography));
                memberVariableCollection.Parse("SUBSCRIBERS", member.Info.Subscribers);

                if (Subscription.IsSubscribed(page.Core, member.ItemKey))
                {
                    memberVariableCollection.Parse("SUBSCRIBERD", "TRUE");
                    memberVariableCollection.Parse("U_SUBSCRIBE", page.Core.Hyperlink.BuildUnsubscribeUri(member.ItemKey));
                }
                else
                {
                    memberVariableCollection.Parse("U_SUBSCRIBE", page.Core.Hyperlink.BuildSubscribeUri(member.ItemKey));
                }

                if (page.Core.Session.SignedIn && member.Id == page.Core.LoggedInMemberId)
                {
                    memberVariableCollection.Parse("ME", "TRUE");
                }
            }

            List<string[]> breadCrumbParts = new List<string[]>();
            breadCrumbParts.Add(new string[] { "forum", core.Prose.GetString("FORUM") });
            breadCrumbParts.Add(new string[] { "memberlist", core.Prose.GetString("MEMBERLIST") });

            page.Owner.ParseBreadCrumbs(breadCrumbParts);

            core.Display.ParsePagination(ForumMember.GenerateMemberlistUri(core, page.Owner, core.Functions.GetFilter()), 20, settings.Members);
        }
Пример #8
0
        public static void Show(Core core, GPage page, long forumId)
        {
            string mark = core.Http.Query["mark"];
            ForumSettings settings;
            try
            {
                settings = new ForumSettings(core, page.Group);
            }
            catch (InvalidForumSettingsException)
            {
                ForumSettings.Create(core, page.Group);
                settings = new ForumSettings(core, page.Group);
            }
            Forum thisForum = null;
            long topicsCount = 0;

            core.Template.SetTemplate("Forum", "viewforum");
            ForumSettings.ShowForumHeader(core, page);

            try
            {
                if (forumId > 0)
                {
                    thisForum = new Forum(page.Core, settings, forumId);

                    core.Template.Parse("PAGE_TITLE", thisForum.Title);
                    core.Template.Parse("FORUM_TITLE", thisForum.Title);

                    core.Template.Parse("SHOW_TOPICS", "TRUE");
                }
                else
                {
                    thisForum = new Forum(page.Core, settings);

                    core.Template.Parse("PAGE_TITLE", core.Prose.GetString("FORUM"));
                    core.Template.Parse("FORUM_TITLE", core.Prose.GetString("FORUM"));

                    if (settings.AllowTopicsAtRoot)
                    {
                        core.Template.Parse("SHOW_TOPICS", "TRUE");
                    }
                }
            }
            catch (InvalidForumException)
            {
                return;
            }

            if (mark == "topics")
            {
                thisForum.ReadAll(false);
            }

            if (mark == "forums")
            {
                thisForum.ReadAll(true);
            }

            if (core.LoggedInMemberId > 0 && (!page.Group.IsGroupMember(core.Session.LoggedInMember.ItemKey)))
            {
                core.Template.Parse("U_JOIN", page.Group.JoinUri);
            }

            topicsCount = thisForum.Topics;

            if (!string.IsNullOrEmpty(thisForum.Rules))
            {
                core.Display.ParseBbcode(core.Template, "RULES", thisForum.Rules);
            }

            List<Forum> forums = GetForumLevels(core, thisForum, 2);
            List<IPermissibleItem> items = new List<IPermissibleItem>();

            //List<Forum> forums = thisForum.GetForums();
            List<Forum> accessibleForums = new List<Forum>();

            foreach (Forum forum in forums)
            {
                items.Add(forum);
            }
            items.Add(thisForum);

            core.AcessControlCache.CacheGrants(items);

            foreach (Forum forum in forums)
            {
                if (forum.Access.Can("VIEW"))
                {
                    accessibleForums.Add(forum);
                }
            }
            forums = accessibleForums;

            if (!thisForum.Access.Can("VIEW"))
            {
                core.Functions.Generate403();
                return;
            }

            core.Template.Parse("FORUMS", forums.Count.ToString());

            // ForumId, TopicPost
            Dictionary<long, TopicPost> lastPosts;
            List<long> lastPostIds = new List<long>();

            foreach (Forum forum in forums)
            {
                lastPostIds.Add(forum.LastPostId);
            }

            lastPosts = TopicPost.GetPosts(core, lastPostIds);

            VariableCollection lastForumVariableCollection = null;
            bool lastCategory = true;
            bool first = true;
            long lastCategoryId = 0;
            Forum lastForum = null;
            foreach (Forum forum in forums)
            {
                if (lastForum != null && (!lastForum.IsCategory) && lastForum.Id == forum.parentId && lastForumVariableCollection != null)
                {
                    VariableCollection subForumVariableCollection = lastForumVariableCollection.CreateChild("sub_forum_list");

                    subForumVariableCollection.Parse("TITLE", forum.Title);
                    subForumVariableCollection.Parse("URI", forum.Uri);

                    continue;
                }

                if ((first && (!forum.IsCategory)) || (lastCategoryId != forum.parentId && (!forum.IsCategory)))
                {
                    VariableCollection defaultVariableCollection = core.Template.CreateChild("forum_list");
                    defaultVariableCollection.Parse("TITLE", "Forum");
                    defaultVariableCollection.Parse("IS_CATEGORY", "TRUE");
                    if (lastForumVariableCollection != null)
                    {
                        lastForumVariableCollection.Parse("IS_LAST", "TRUE");
                    }
                    first = false;
                    lastCategoryId = forum.parentId;
                    lastCategory = true;
                }

                VariableCollection forumVariableCollection = core.Template.CreateChild("forum_list");

                forumVariableCollection.Parse("TITLE", forum.Title);
                core.Display.ParseBbcode(forumVariableCollection, "DESCRIPTION", forum.Description);
                forumVariableCollection.Parse("URI", forum.Uri);
                forumVariableCollection.Parse("POSTS", forum.Posts.ToString());
                forumVariableCollection.Parse("TOPICS", forum.Topics.ToString());

                if (lastPosts.ContainsKey(forum.LastPostId))
                {
                    forumVariableCollection.Parse("LAST_POST_URI", lastPosts[forum.LastPostId].Uri);
                    forumVariableCollection.Parse("LAST_POST_TITLE", lastPosts[forum.LastPostId].Title);
                    core.Display.ParseBbcode(forumVariableCollection, "LAST_POST", string.Format("[iurl={0}]{1}[/iurl]\n{2}",
                        lastPosts[forum.LastPostId].Uri, Functions.TrimStringToWord(lastPosts[forum.LastPostId].Title, 20), core.Tz.DateTimeToString(lastPosts[forum.LastPostId].GetCreatedDate(core.Tz))));
                }
                else
                {
                    forumVariableCollection.Parse("LAST_POST", "No posts");
                }

                if (forum.IsRead)
                {
                    forumVariableCollection.Parse("IS_READ", "TRUE");
                }
                else
                {
                    forumVariableCollection.Parse("IS_READ", "FALSE");
                }

                if (forum.IsCategory)
                {
                    forumVariableCollection.Parse("IS_CATEGORY", "TRUE");
                    if (lastForumVariableCollection != null)
                    {
                        lastForumVariableCollection.Parse("IS_LAST", "TRUE");
                    }
                    lastCategoryId = forum.Id;
                    lastCategory = true;
                }
                else
                {
                    topicsCount -= forum.Topics;
                    forumVariableCollection.Parse("IS_FORUM", "TRUE");
                    if (lastCategory)
                    {
                        forumVariableCollection.Parse("IS_FIRST", "TRUE");
                    }
                    lastForumVariableCollection = forumVariableCollection;
                    lastCategory = false;
                }
                first = false;
                lastForum = forum;
            }

            if (lastForumVariableCollection != null)
            {
                lastForumVariableCollection.Parse("IS_LAST", "TRUE");
            }

            if ((settings.AllowTopicsAtRoot && forumId == 0) || forumId > 0)
            {
                if (thisForum.TopicsPaged > 0)
                {
                    List<ForumTopic> announcements = thisForum.GetAnnouncements();
                    List<ForumTopic> topics = thisForum.GetTopics(page.TopLevelPageNumber, settings.TopicsPerPage);
                    List<ForumTopic> allTopics = new List<ForumTopic>();
                    allTopics.AddRange(announcements);
                    allTopics.AddRange(topics);

                    topicsCount -= announcements.Count; // aren't counted in pagination

                    core.Template.Parse("ANNOUNCEMENTS", announcements.Count.ToString());
                    //page.template.Parse("TOPICS", topics.Count.ToString());

                    // PostId, TopicPost
                    Dictionary<long, TopicPost> topicLastPosts;

                    topicLastPosts = TopicPost.GetTopicLastPosts(core, allTopics);

                    core.Template.Parse("TOPICS", allTopics.Count.ToString());

                    foreach (ForumTopic topic in allTopics)
                    {
                        core.LoadUserProfile(topic.PosterId);
                    }

                    foreach (ForumTopic topic in allTopics)
                    {
                        VariableCollection topicVariableCollection = core.Template.CreateChild("topic_list");

                        if (topic.Posts > settings.PostsPerPage)
                        {
                            core.Display.ParseMinimalPagination(topicVariableCollection, "PAGINATION", topic.Uri, 0, settings.PostsPerPage, topic.Posts);
                        }
                        else
                        {
                            topicVariableCollection.Parse("PAGINATION", "FALSE");
                        }

                        topicVariableCollection.Parse("TITLE", topic.Title);
                        topicVariableCollection.Parse("URI", topic.Uri);
                        topicVariableCollection.Parse("VIEWS", topic.Views.ToString());
                        topicVariableCollection.Parse("REPLIES", topic.Posts.ToString());
                        topicVariableCollection.Parse("DATE", core.Tz.DateTimeToString(topic.GetCreatedDate(core.Tz)));
                        topicVariableCollection.Parse("USERNAME", core.PrimitiveCache[topic.PosterId].DisplayName);
                        topicVariableCollection.Parse("U_POSTER", core.PrimitiveCache[topic.PosterId].Uri);

                        if (topicLastPosts.ContainsKey(topic.LastPostId))
                        {
                            topicVariableCollection.Parse("LAST_POST_URI", topicLastPosts[topic.LastPostId].Uri);
                            topicVariableCollection.Parse("LAST_POST_TITLE", topicLastPosts[topic.LastPostId].Title);
                            core.Display.ParseBbcode(topicVariableCollection, "LAST_POST", string.Format("[iurl={0}]{1}[/iurl]\n{2}",
                                topicLastPosts[topic.LastPostId].Uri, Functions.TrimStringToWord(topicLastPosts[topic.LastPostId].Title, 20), core.Tz.DateTimeToString(topicLastPosts[topic.LastPostId].GetCreatedDate(core.Tz))));
                        }
                        else
                        {
                            topicVariableCollection.Parse("LAST_POST", "No posts");
                        }

                        switch (topic.Status)
                        {
                            case TopicStates.Normal:
                                if (topic.IsRead)
                                {
                                    if (topic.IsLocked)
                                    {
                                        topicVariableCollection.Parse("IS_NORMAL_READ_LOCKED", "TRUE");
                                    }
                                    else
                                    {
                                        topicVariableCollection.Parse("IS_NORMAL_READ_UNLOCKED", "TRUE");
                                    }
                                }
                                else
                                {
                                    if (topic.IsLocked)
                                    {
                                        topicVariableCollection.Parse("IS_NORMAL_UNREAD_LOCKED", "TRUE");
                                    }
                                    else
                                    {
                                        topicVariableCollection.Parse("IS_NORMAL_UNREAD_UNLOCKED", "TRUE");
                                    }
                                }
                                break;
                            case TopicStates.Sticky:
                                if (topic.IsRead)
                                {
                                    if (topic.IsLocked)
                                    {
                                        topicVariableCollection.Parse("IS_STICKY_READ_LOCKED", "TRUE");
                                    }
                                    else
                                    {
                                        topicVariableCollection.Parse("IS_STICKY_READ_UNLOCKED", "TRUE");
                                    }
                                }
                                else
                                {
                                    if (topic.IsLocked)
                                    {
                                        topicVariableCollection.Parse("IS_STICKY_UNREAD_LOCKED", "TRUE");
                                    }
                                    else
                                    {
                                        topicVariableCollection.Parse("IS_STICKY_UNREAD_UNLOCKED", "TRUE");
                                    }
                                }

                                break;
                            case TopicStates.Announcement:
                            case TopicStates.Global:
                                if (topic.IsRead)
                                {
                                    if (topic.IsLocked)
                                    {
                                        topicVariableCollection.Parse("IS_ANNOUNCEMENT_READ_LOCKED", "TRUE");
                                    }
                                    else
                                    {
                                        topicVariableCollection.Parse("IS_ANNOUNCEMENT_READ_UNLOCKED", "TRUE");
                                    }
                                }
                                else
                                {
                                    if (topic.IsLocked)
                                    {
                                        topicVariableCollection.Parse("IS_ANNOUNCEMENT_UNREAD_LOCKED", "TRUE");
                                    }
                                    else
                                    {
                                        topicVariableCollection.Parse("IS_ANNOUNCEMENT_UNREAD_UNLOCKED", "TRUE");
                                    }
                                }

                                break;
                        }
                    }
                }

                if (!thisForum.IsCategory)
                {
                    if (thisForum.Access.Can("CREATE_TOPICS"))
                    {
                        core.Template.Parse("U_NEW_TOPIC", thisForum.NewTopicUri);
                    }
                }

                core.Display.ParsePagination(thisForum.Uri, settings.TopicsPerPage, thisForum.TopicsPaged);
            }

            List<string[]> breadCrumbParts = new List<string[]>();
            breadCrumbParts.Add(new string[] { "forum", core.Prose.GetString("FORUM") });

            if (thisForum.Parents != null)
            {
                foreach (ParentTreeNode ptn in thisForum.Parents.Nodes)
                {
                    breadCrumbParts.Add(new string[] { "*" + ptn.ParentId.ToString(), ptn.ParentTitle });
                }
            }

            if (thisForum.Id > 0)
            {
                breadCrumbParts.Add(new string[] { thisForum.Id.ToString(), thisForum.Title });
            }

            page.Group.ParseBreadCrumbs(breadCrumbParts);

            if (thisForum.Id == 0)
            {
                core.Template.Parse("INDEX_STATISTICS", "TRUE");
                core.Template.Parse("FORUM_POSTS", core.Functions.LargeIntegerToString(settings.Posts));
                core.Template.Parse("FORUM_TOPICS", core.Functions.LargeIntegerToString(settings.Topics));
                core.Template.Parse("GROUP_MEMBERS", core.Functions.LargeIntegerToString(page.Group.Members));
            }

            PermissionsList permissions = new PermissionsList(core);
            bool flagPermissionsBlock = false;

            if (thisForum.Access.Can("CREATE_TOPICS"))
            {
                permissions.Add(core.Prose.GetString("YOU_CAN_CREATE_TOPICS"), true);
                flagPermissionsBlock = true;
            }
            else
            {
                permissions.Add(core.Prose.GetString("YOU_CAN_CREATE_TOPICS"), false);
                flagPermissionsBlock = true;
            }
            if (thisForum.Access.Can("REPLY_TOPICS"))
            {
                permissions.Add(core.Prose.GetString("YOU_CAN_POST_REPLIES"), true);
                flagPermissionsBlock = true;
            }
            else
            {
                permissions.Add(core.Prose.GetString("YOU_CAN_POST_REPLIES"), false);
                flagPermissionsBlock = true;
            }
            if (thisForum.Access.Can("EDIT_OWN_POSTS"))
            {
                permissions.Add(core.Prose.GetString("YOU_CAN_EDIT_YOUR_POSTS"), true);
                flagPermissionsBlock = true;
            }
            if (thisForum.Access.Can("DELETE_OWN_POSTS"))
            {
                permissions.Add(core.Prose.GetString("YOU_CAN_DELETE_YOUR_POSTS"), true);
                flagPermissionsBlock = true;
            }
            if (thisForum.Access.Can("DELETE_TOPICS") || thisForum.Access.Can("LOCK_TOPICS"))
            {
                permissions.Add(core.Prose.GetString("YOU_CAN_MODERATE_FORUM"), true, core.Hyperlink.StripSid(thisForum.ModeratorControlPanelUri));
                flagPermissionsBlock = true;
            }

            if (flagPermissionsBlock)
            {
                permissions.Parse("PERMISSION_BLOCK");
            }
        }