예제 #1
0
        void AccountForumSettings_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            ForumSettings settings = new ForumSettings(core, Owner);
            settings.TopicsPerPage = core.Functions.FormInt("topics-per-page", 10);
            settings.PostsPerPage = core.Functions.FormInt("posts-per-page", 10);
            settings.AllowTopicsAtRoot = core.Http.Form["root-topics"] != null;

            settings.Update();

            this.SetInformation("Forum Settings Saved");
        }
예제 #2
0
        public static void ShowHelp(object sender, ShowPPageEventArgs e)
        {
            ForumSettings settings;
            try
            {
                settings = new ForumSettings(e.Core, e.Page.Owner);
            }
            catch (InvalidForumSettingsException)
            {
                ForumSettings.Create(e.Core, e.Page.Owner);
                settings = new ForumSettings(e.Core, e.Page.Owner);
            }

            e.Template.SetTemplate("Forum", "help");
            ForumSettings.ShowForumHeader(e.Core, e.Page);

            e.Template.Parse("PAGE_TITLE", e.Core.Prose.GetString("FORUM_HELP"));

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

            e.Page.Owner.ParseBreadCrumbs(breadCrumbParts);
        }
예제 #3
0
        private void SavePost(string mode, string subject, string text)
        {
            AccountSubModule.AuthoriseRequestSid(core);

            long postId = core.Functions.FormLong("p", 0);
            long forumId = core.Functions.FormLong("f", 0);
            long topicId = core.Functions.FormLong("t", 0);

            switch (mode)
            {
                case "edit":
                    // Edit Post
                    break;
                case "reply":
                    // Post Reply
                    try
                    {
                        ForumSettings settings = new ForumSettings(core, ((PPage)page).Owner);
                        Forum forum;

                        if (forumId == 0)
                        {
                            forum = new Forum(core, settings);
                        }
                        else
                        {
                            forum = new Forum(core, forumId);
                        }

                        if (!forum.Access.Can("REPLY_TOPICS"))
                        {
                            core.Display.ShowMessage("Cannot reply", "Not authorised to reply to topic");
                            return;
                        }

                        ForumTopic topic = new ForumTopic(core, forum, topicId);

                        if (topic.IsLocked)
                        {
                            core.Display.ShowMessage("Topic Locked", "The topic cannot be replied to as it has been locked.");
                            return;
                        }

                        TopicPost post = topic.AddReply(core, forum, subject, text);

                        core.Template.Parse("REDIRECT_URI", post.Uri);
                        core.Display.ShowMessage("Reply Posted", "Reply has been posted");
                        return;
                    }
                    catch (InvalidTopicException)
                    {
                        core.Display.ShowMessage("ERROR", "An error occured");
                    }
                    break;
                case "post":
                    // New Topic
                    try
                    {
                        Forum forum;

                        if (forumId == 0 && page is PPage)
                        {
                            forum = new Forum(core, ((PPage)page).Owner);
                        }
                        else
                        {
                            forum = new Forum(core, forumId);
                        }

                        if (!forum.Access.Can("CREATE_TOPICS"))
                        {
                            core.Display.ShowMessage("Cannot create new topic", "Not authorised to create a new topic");
                            return;
                        }

                        /*try
                        {*/
                        TopicStates topicState = 0;

                        if (core.Http["topic-state"] != null)
                        {
                            topicState = (TopicStates)core.Functions.FormByte("topic-state", (byte)TopicStates.Normal);
                        }

                        if (topicState == TopicStates.Announcement && (!forum.Access.Can("CREATE_ANNOUNCEMENTS")))
                        {
                            topicState = TopicStates.Normal;
                        }

                        if (topicState == TopicStates.Sticky && (!forum.Access.Can("CREATE_STICKY")))
                        {
                            topicState = TopicStates.Normal;
                        }

                        ForumTopic topic = ForumTopic.Create(core, forum, subject, text, topicState);

                        core.Template.Parse("REDIRECT_URI", topic.Uri);
                        core.Display.ShowMessage("Topic Posted", "Topic has been posted");
                        return;
                        /*}
                        catch
                        {
                            Display.ShowMessage("Error", "Error creating new topic.");
                            return;
                        }*/
                    }
                    catch (InvalidForumException)
                    {
                        core.Display.ShowMessage("Cannot create new topic", "Not authorised to create a new topic");
                        return;
                    }
            }
        }
예제 #4
0
        void AccountForumSettings_Show(object sender, EventArgs e)
        {
            SetTemplate("account_forum_settings");

            Save(new EventHandler(AccountForumSettings_Save));

            ForumSettings settings;
            try
            {
                settings = new ForumSettings(core, Owner);
            }
            catch (InvalidForumSettingsException)
            {
                ForumSettings.Create(core, Owner);
                settings = new ForumSettings(core, Owner);
            }

            CheckBox rootTopicsCheckBox = new CheckBox("root-topics");
            rootTopicsCheckBox.IsChecked = settings.AllowTopicsAtRoot;

            template.Parse("S_TOPICS_PER_PAGE", settings.TopicsPerPage.ToString());
            template.Parse("S_POSTS_PER_PAGE", settings.PostsPerPage.ToString());
            template.Parse("S_ROOT_TOPICS", rootTopicsCheckBox);
        }
예제 #5
0
        public static ForumSettings Create(Core core, Primitive owner)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            //if (!thisGroup.IsGroupOperator(core.session.LoggedInMember))
            {
                // todo: throw new exception
                // commented out due to errors on live site
                //throw new UnauthorisedToCreateItemException();
            }

            InsertQuery iQuery = new InsertQuery(GetTable(typeof(ForumSettings)));
            iQuery.AddField("forum_item_id", owner.Id);
            iQuery.AddField("forum_item_type_id", owner.TypeId);
            iQuery.AddField("forum_topics", 0);
            iQuery.AddField("forum_posts", 0);
            iQuery.AddField("forum_topics_per_page", 10);
            iQuery.AddField("forum_posts_per_page", 10);
            iQuery.AddField("forum_allow_topics_root", true);

            long settingsId = core.Db.Query(iQuery);

            ForumSettings settings = new ForumSettings(core, settingsId);

            if (owner is UserGroup)
            {
                settings.Access.CreateAllGrantsForPrimitive(UserGroup.GetGroupOperatorsGroupKey(core));
                settings.Access.CreateGrantForPrimitive(UserGroup.GetGroupMembersGroupKey(core), "VIEW", "VIEW_TOPICS", "LIST_TOPICS", "REPLY_TOPICS", "CREATE_TOPICS");
                settings.Access.CreateGrantForPrimitive(User.GetEveryoneGroupKey(core), "VIEW", "VIEW_TOPICS", "LIST_TOPICS");
            }
            if (owner is ApplicationEntry)
            {
                settings.Access.CreateGrantForPrimitive(User.GetRegisteredUsersGroupKey(core), "VIEW", "VIEW_TOPICS", "LIST_TOPICS", "REPLY_TOPICS", "CREATE_TOPICS");
                settings.Access.CreateGrantForPrimitive(User.GetEveryoneGroupKey(core), "VIEW", "VIEW_TOPICS", "LIST_TOPICS");
            }

            return settings;
        }
예제 #6
0
        void AccountForumManage_Show(object sender, EventArgs e)
        {
            SetTemplate("account_forum_manage");

            long forumId = core.Functions.RequestLong("id", 0);

            Forum thisForum;
            if (forumId == 0)
            {
                if (Owner is UserGroup)
                {
                    thisForum = new Forum(core, (UserGroup)Owner);
                }
                else
                {
                    thisForum = null;
                }
            }
            else
            {
                thisForum = new Forum(core, forumId);
            }

            if (thisForum != null)
            {
                template.Parse("FORUM_TITLE", thisForum.Title);
                template.Parse("U_FORUM", thisForum.Uri);

                if (thisForum.Id == 0)
                {
                    ForumSettings settings;
                    try
                    {
                        settings = new ForumSettings(core, thisForum.Owner);
                    }
                    catch (InvalidForumSettingsException)
                    {
                        ForumSettings.Create(core, thisForum.Owner);
                        settings = new ForumSettings(core, thisForum.Owner);
                    }
                    //ForumSettings settings = new ForumSettings(core, thisForum.Owner);
                    template.Parse("U_PERMISSIONS", core.Hyperlink.AppendAbsoluteSid(string.Format("/api/acl?id={0}&type={1}", settings.Id, ItemType.GetTypeId(core, typeof(ForumSettings))), true));
                }
                else
                {
                    template.Parse("U_PERMISSIONS", core.Hyperlink.AppendAbsoluteSid(string.Format("/api/acl?id={0}&type={1}", thisForum.Id, ItemType.GetTypeId(core, typeof(Forum))), true));
                }

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

                foreach (Forum forum in forums)
                {
                    VariableCollection forumVariableCollection = template.CreateChild("forum_list");

                    forumVariableCollection.Parse("TITLE", forum.Title);
                    forumVariableCollection.Parse("U_SUB_FORUMS", BuildUri("forum", forum.Id));
                    forumVariableCollection.Parse("U_VIEW", forum.Uri);
                    forumVariableCollection.Parse("U_EDIT", BuildUri("forum", "edit", forum.Id));
                    forumVariableCollection.Parse("U_MOVE_UP", BuildUri("forum", "move-up", forum.Id));
                    forumVariableCollection.Parse("U_MOVE_DOWN", BuildUri("forum", "move-down", forum.Id));
                    forumVariableCollection.Parse("U_EDIT_PERMISSION", core.Hyperlink.AppendAbsoluteSid(string.Format("/api/acl?id={0}&type={1}", forum.Id, ItemType.GetTypeId(core, typeof(Forum))), true));
                    forumVariableCollection.Parse("U_DELETE", BuildUri("forum", "delete", forum.Id));
                }
            }

            if (forumId > 0)
            {
                template.Parse("U_CREATE_FORUM", BuildUri("forum", "new", forumId));
            }
            else
            {
                template.Parse("U_CREATE_FORUM", BuildUri("forum", "new"));
            }
        }
예제 #7
0
        void AccountForumManage_New(object sender, ModuleModeEventArgs e)
        {
            SetTemplate("account_forum_edit");

            long id = core.Functions.RequestLong("id", 0);

            /* Forum Types SelectBox */
            SelectBox forumTypesSelectBox = new SelectBox("type");
            Dictionary<string, string> forumTypes = new Dictionary<string, string>();
            forumTypesSelectBox.Add(new SelectBoxItem("FORUM", "Forum"));
            forumTypesSelectBox.Add(new SelectBoxItem("CAT", "Category"));
            //forumTypes.Add("LINK", "Link");

            /* Forum Types SelectBox */
            SelectBox forumParentSelectBox = new SelectBox("parent");

            /* Title TextBox */
            TextBox titleTextBox = new TextBox("title");
            titleTextBox.MaxLength = 127;

            /* Description TextBox */
            TextBox descriptionTextBox = new TextBox("description");
            descriptionTextBox.IsFormatted = true;
            descriptionTextBox.Lines = 6;

            /* Rules TextBox */
            TextBox rulesTextBox = new TextBox("rules");
            rulesTextBox.IsFormatted = true;
            rulesTextBox.Lines = 6;

            ForumSettings settings = new ForumSettings(core, Owner);
            List<Forum> forums = settings.GetForums();

            forumParentSelectBox.Add(new SelectBoxItem("0", ""));
            foreach (Forum forum in forums)
            {
                string levelString = string.Empty;

                for (int i = 0; i < forum.Level; i++)
                {
                    levelString += "--";
                }

                SelectBoxItem item = new SelectBoxItem(forum.Id.ToString(), levelString + " " + forum.Title);

                if (forum.Id == id && e.Mode == "edit")
                {
                    item.Selectable = false;
                }

                forumParentSelectBox.Add(item);
            }

            switch (e.Mode)
            {
                case "new":
                    forumTypesSelectBox.SelectedKey = "FORUM";

                    template.Parse("S_ID", id.ToString());
                    forumParentSelectBox.SelectedKey = id.ToString();

                    break;
                case "edit":
                    try
                    {
                        Forum forum = new Forum(core, id);

                        string type = "FORUM";

                        if (forum.IsCategory)
                        {
                            type = "CAT";
                        }

                        titleTextBox.Value = forum.Title;
                        forumParentSelectBox.SelectedKey = forum.ParentId.ToString();
                        descriptionTextBox.Value = forum.Description;
                        rulesTextBox.Value = forum.Rules;

                        template.Parse("S_ID", forum.Id.ToString());

                        List<string> disabledItems = new List<string>();
                        forumTypesSelectBox["FORUM"].Selectable = false;
                        forumTypesSelectBox["CAT"].Selectable = false;
                        //forumTypesSelectBox["LINK"].Selectable = false;

                        forumTypesSelectBox.SelectedKey = type;

                        template.Parse("EDIT", "TRUE");
                    }
                    catch (InvalidForumException)
                    {
                        DisplayGenericError();
                    }
                    break;
            }

            /* Parse the form fields */
            template.Parse("S_TITLE", titleTextBox);
            template.Parse("S_DESCRIPTION", descriptionTextBox);
            template.Parse("S_RULES", rulesTextBox);
            template.Parse("S_FORUM_TYPE", forumTypesSelectBox);
            template.Parse("S_FORUM_PARENT", forumParentSelectBox);
        }
예제 #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");
            }
        }
예제 #9
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);
        }
예제 #10
0
        void AccountForumRanks_Show(object sender, EventArgs e)
        {
            SetTemplate("account_forum_ranks");

            ForumSettings settings = new ForumSettings(core, Owner);
            List<ForumMemberRank> ranks = settings.GetRanks();

            foreach (ForumMemberRank rank in ranks)
            {
                VariableCollection ranksVariableCollection = template.CreateChild("rank_list");

                ranksVariableCollection.Parse("RANK", rank.RankTitleText);
                ranksVariableCollection.Parse("SPECIAL", (rank.RankSpecial) ? "True" : "False");
                ranksVariableCollection.Parse("MINIMUM_POSTS", rank.RankPosts.ToString());

                ranksVariableCollection.Parse("U_EDIT", BuildUri("ranks", "edit", rank.Id));
                ranksVariableCollection.Parse("U_DELETE", BuildUri("ranks", "delete", rank.Id));
            }

            template.Parse("U_NEW_RANK", BuildUri("ranks", "add"));
        }
예제 #11
0
        public Forum(Core core, ForumSettings settings, UserGroup owner, System.Data.Common.DbDataReader forumDataRow)
            : base(core)
        {
            this.owner = owner;
            this.settings = settings;
            ItemLoad += new ItemLoadHandler(Forum_ItemLoad);

            try
            {
                loadItemInfo(forumDataRow);
            }
            catch (InvalidItemException)
            {
                throw new InvalidForumException();
            }

            try
            {
                readStatus = new ForumReadStatus(core, forumDataRow);
                readStatusLoaded = true;
            }
            catch (InvalidForumReadStatusException)
            {
                readStatus = null;
                readStatusLoaded = true;
            }
        }
예제 #12
0
        public Forum(Core core, ForumSettings settings, DataRow forumDataRow)
            : base(core)
        {
            this.settings = settings;
            ItemLoad += new ItemLoadHandler(Forum_ItemLoad);

            try
            {
                loadItemInfo(forumDataRow);
            }
            catch (InvalidItemException)
            {
                throw new InvalidForumException();
            }

            try
            {
                readStatus = new ForumReadStatus(core, forumDataRow);
                readStatusLoaded = true;
            }
            catch (InvalidForumReadStatusException)
            {
                readStatus = null;
                readStatusLoaded = true;
            }
        }
예제 #13
0
        public Forum(Core core, ForumSettings settings, long forumId)
            : base(core)
        {
            this.settings = settings;
            ItemLoad += new ItemLoadHandler(Forum_ItemLoad);

            SelectQuery query = Forum_GetSelectQueryStub(core);
            query.AddCondition("`forum`.`forum_id`", forumId);

            System.Data.Common.DbDataReader forumReader = db.ReaderQuery(query);

            if (forumReader.HasRows)
            {
                forumReader.Read();

                loadItemInfo(forumReader);

                try
                {
                    readStatus = new ForumReadStatus(core, forumReader);
                    readStatusLoaded = true;
                }
                catch (InvalidForumReadStatusException)
                {
                    readStatus = null;
                    readStatusLoaded = true;
                }

                forumReader.Close();
                forumReader.Dispose();
            }
            else
            {
                throw new InvalidForumException();
            }
        }
예제 #14
0
 public Forum(Core core, ForumSettings settings)
     : base(core)
 {
     this.settings = settings;
     this.owner = settings.Owner;
     this.ownerKey = new ItemKey(owner.Id, owner.TypeId);
     forumId = 0;
     forumLocked = false;
     forumLevel = 0;
     forumTitle = "Forums";
 }
예제 #15
0
        public static ForumTopic Create(Core core, Forum forum, string subject, string text, TopicStates status)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (forum == null)
            {
                throw new InvalidForumException();
            }

            core.Db.BeginTransaction();

            if (!forum.Access.Can("CREATE_TOPICS"))
            {
                // todo: throw new exception
                throw new UnauthorisedToCreateItemException();
            }

            if ((status == TopicStates.Announcement || status == TopicStates.Global) && (!forum.Access.Can("CREATE_ANNOUNCEMENTS")))
            {
                throw new UnauthorisedToCreateItemException();
            }

            if (status == TopicStates.Sticky && (!forum.Access.Can("CREATE_STICKY")))
            {
                throw new UnauthorisedToCreateItemException();
            }

            if (forum.Owner is UserGroup)
            {
                ForumSettings settings = new ForumSettings(core, (UserGroup)forum.Owner);

                if (forum.Id == 0 && (!settings.AllowTopicsAtRoot))
                {
                    throw new UnauthorisedToCreateItemException();
                }

                if (!((UserGroup)forum.Owner).IsGroupOperator(core.Session.LoggedInMember.ItemKey))
                {
                    status = TopicStates.Normal;
                }
            }

            InsertQuery iquery = new InsertQuery(ForumTopic.GetTable(typeof(ForumTopic)));
            iquery.AddField("forum_id", forum.Id);
            iquery.AddField("topic_title", subject);
            iquery.AddField("user_id", core.LoggedInMemberId);
            iquery.AddField("topic_posts", 0);
            iquery.AddField("topic_views", 0);
            iquery.AddField("topic_time_ut", UnixTime.UnixTimeStamp());
            iquery.AddField("topic_modified_ut", UnixTime.UnixTimeStamp());
            iquery.AddField("topic_last_post_time_ut", UnixTime.UnixTimeStamp());
            iquery.AddField("topic_status", (byte)status);
            iquery.AddField("topic_locked", false);
            iquery.AddField("topic_last_post_id", 0);
            iquery.AddField("topic_first_post_id", 0);
            iquery.AddField("topic_item_id", forum.Owner.Id);
            iquery.AddField("topic_item_type_id", forum.Owner.TypeId);

            long topicId = core.Db.Query(iquery);

            ForumTopic topic = new ForumTopic(core, forum, topicId);

            TopicPost post = TopicPost.Create(core, forum, topic, subject, text);

            UpdateQuery uQuery = new UpdateQuery(ForumTopic.GetTable(typeof(ForumTopic)));
            uQuery.AddField("topic_first_post_id", post.Id);
            uQuery.AddField("topic_last_post_id", post.Id);
            uQuery.AddField("topic_last_post_time_ut", post.TimeCreatedRaw);
            uQuery.AddCondition("topic_id", topic.Id);

            long rowsUpdated = core.Db.Query(uQuery);

            topic.firstPostId = post.Id;
            topic.lastPostId = post.Id;
            topic.lastPostTimeRaw = post.TimeCreatedRaw;

            if (rowsUpdated != 1)
            {
                core.Db.RollBackTransaction();
                core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
            }

            if (forum.Id > 0)
            {
                List<long> parentForumIds = new List<long>();
                parentForumIds.Add(forum.Id);

                if (forum.Parents != null)
                {
                    foreach (ParentTreeNode ptn in forum.Parents.Nodes)
                    {
                        parentForumIds.Add(ptn.ParentId);
                    }
                }

                uQuery = new UpdateQuery(Forum.GetTable(typeof(Forum)));
                uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Addition, 1));
                uQuery.AddField("forum_topics", new QueryOperation("forum_topics", QueryOperations.Addition, 1));
                uQuery.AddField("forum_last_post_id", post.Id);
                uQuery.AddField("forum_last_post_time_ut", post.TimeCreatedRaw);
                uQuery.AddCondition("forum_id", ConditionEquality.In, parentForumIds);

                rowsUpdated = core.Db.Query(uQuery);

                if (rowsUpdated < 1)
                {
                    core.Db.RollBackTransaction();
                    core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
                }

                uQuery = new UpdateQuery(Forum.GetTable(typeof(Forum)));
                uQuery.AddField("forum_topics", new QueryOperation("forum_topics_paged", QueryOperations.Addition, 1));
                uQuery.AddCondition("forum_id", forum.Id);

                rowsUpdated = core.Db.Query(uQuery);

                if (rowsUpdated < 1)
                {
                    core.Db.RollBackTransaction();
                    core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
                }
            }

            uQuery = new UpdateQuery(ForumSettings.GetTable(typeof(ForumSettings)));
            uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Addition, 1));
            uQuery.AddField("forum_topics", new QueryOperation("forum_topics", QueryOperations.Addition, 1));
            uQuery.AddCondition("forum_item_id", forum.Owner.Id);
            uQuery.AddCondition("forum_item_type_id", forum.Owner.TypeId);

            rowsUpdated = core.Db.Query(uQuery);

            if (rowsUpdated != 1)
            {
                core.Db.RollBackTransaction();
                core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
            }

            /*uQuery = new UpdateQuery(ForumMember.GetTable(typeof(ForumMember)));
            uQuery.AddField("posts", new QueryOperation("posts", QueryOperations.Addition, 1));
            uQuery.AddCondition("user_id", core.session.LoggedInMember.Id);
            uQuery.AddCondition("item_id", forum.Owner.Id);
            uQuery.AddCondition("item_type_id", forum.Owner.TypeId);

            rowsUpdated = core.db.Query(uQuery);

            if (rowsUpdated == 0)
            {
                ForumMember fm = ForumMember.Create(core, forum.Owner, core.session.LoggedInMember, true);

                uQuery = new UpdateQuery(ForumMember.GetTable(typeof(ForumMember)));
                uQuery.AddField("posts", new QueryOperation("posts", QueryOperations.Addition, 1));
                uQuery.AddCondition("user_id", core.session.LoggedInMember.Id);
                uQuery.AddCondition("item_id", forum.Owner.Id);
                uQuery.AddCondition("item_type_id", forum.Owner.TypeId);

                core.db.Query(uQuery);
            }*/

            ForumMember fm = null;

            try
            {
                fm = new ForumMember(core, forum.Owner, core.Session.LoggedInMember);
            }
            catch (InvalidForumMemberException)
            {
                fm = ForumMember.Create(core, forum.Owner, core.Session.LoggedInMember, true);
            }

            fm.ForumPosts += 1;

            /*Dictionary<long, ForumMemberRank> ranks = ForumMemberRank.GetRanks(core, forum.Owner);

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

            fm.Update(typeof(ForumMember));

            return topic;
        }
예제 #16
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;
            }
        }
예제 #17
0
        void McpMain_Show(object sender, EventArgs e)
        {
            //AuthoriseRequestSid();
            SetTemplate("mcp_main");

            /* */
            SubmitButton submitButton = new SubmitButton("submit", "Submit");

            /* */
            SelectBox actionsSelectBox = new SelectBox("mode");

            long forumId = core.Functions.RequestLong("f", 0);
            Forum thisForum = null;
            ForumSettings settings = null;

            try
            {
                settings = new ForumSettings(core, Owner);
                if (forumId > 0)
                {
                    thisForum = new Forum(core, settings, forumId);
                }
                else
                {
                    thisForum = new Forum(core, settings);
                }
            }
            catch (InvalidForumSettingsException)
            {
                core.Functions.Generate404();
            }
            catch (InvalidForumException)
            {
                core.Functions.Generate404();
            }

            if (thisForum.Access.Can("LOCK_TOPICS"))
            {
                actionsSelectBox.Add(new SelectBoxItem("lock", "Lock"));
                actionsSelectBox.Add(new SelectBoxItem("unlock", "Unlock"));
            }
            if (thisForum.Access.Can("MOVE_TOPICS"))
            {
                actionsSelectBox.Add(new SelectBoxItem("move", "Move"));
            }
            if (thisForum.Access.Can("DELETE_TOPICS"))
            {
                actionsSelectBox.Add(new SelectBoxItem("delete", "Delete"));
            }

            List<ForumTopic> announcements = thisForum.GetAnnouncements();
            List<ForumTopic> topics = thisForum.GetTopics(core.TopLevelPageNumber, settings.TopicsPerPage);
            List<ForumTopic> allTopics = new List<ForumTopic>();
            allTopics.AddRange(announcements);
            allTopics.AddRange(topics);

            Dictionary<long, TopicPost> topicLastPosts;

            topicLastPosts = TopicPost.GetTopicLastPosts(core, allTopics);

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

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

                CheckBox checkBox = new CheckBox("checkbox[" + topic.Id.ToString() + "]");

                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);
                topicVariableCollection.Parse("S_CHECK", checkBox);

                if (topicLastPosts.ContainsKey(topic.LastPostId))
                {
                    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;
                }
            }

            template.Parse("TOPICS", allTopics.Count.ToString());
            template.Parse("S_ACTIONS", actionsSelectBox);
            template.Parse("S_SUBMIT", submitButton);
        }