Example #1
0
        public void MoveDown()
        {
            SelectQuery query = Forum.GetSelectQueryStub(core, typeof(Forum));
            query.AddCondition("forum_parent_id", ParentId);
            query.AddCondition("forum_item_id", Owner.Id);
            query.AddCondition("forum_item_type_id", Owner.TypeId);
            query.AddCondition("forum_order", ConditionEquality.GreaterThan, Order);
            query.AddSort(SortOrder.Ascending, "forum_order");
            query.LimitCount = 2;

            DataTable levelForumsDataTable = db.Query(query);

            Forum record0 = null;
            Forum record1 = null;
            int difference = 0;
            int differenceBelow = 0;

            if (levelForumsDataTable.Rows.Count == 0)
            {
                /* Cannot move down */
                return;
            }
            if (levelForumsDataTable.Rows.Count >= 1)
            {
                record0 = new Forum(core, levelForumsDataTable.Rows[0]);
                difference = record0.Order - Order;
            }
            if (levelForumsDataTable.Rows.Count >= 2)
            {
                record1 = new Forum(core, levelForumsDataTable.Rows[1]);
                differenceBelow = record1.Order - record0.Order;
            }

            query = Forum.GetSelectQueryStub(core, typeof(Forum));
            query.AddCondition("forum_order", ConditionEquality.GreaterThanEqual, Order);
            if (record0 != null)
            {
                query.AddCondition("forum_order", ConditionEquality.LessThan, record0.Order);
            }
            else
            {
                /* TODO: test */
                query = Forum.GetSelectQueryStub(core, typeof(Forum));
                query.AddCondition("forum_parent_id", ParentId); /* or any level below */
                query.AddCondition("forum_item_id", Owner.Id);
                query.AddCondition("forum_item_type_id", Owner.TypeId);
                query.AddCondition("forum_order", ConditionEquality.GreaterThan, Order);
                query.AddSort(SortOrder.Descending, "forum_order");
                query.LimitCount = 1;

                levelForumsDataTable = core.Db.Query(query);

                Forum record = null;
                if (levelForumsDataTable.Rows.Count == 1)
                {
                    record = new Forum(core, levelForumsDataTable.Rows[0]);

                    query.AddCondition("forum_order", ConditionEquality.LessThanEqual, record.Order);
                }
            }

            List<long> updateIds = new List<long>();

            foreach (DataRow dr in db.Query(query).Rows)
            {
                updateIds.Add((long)dr["forum_id"]);
            }

            db.BeginTransaction();
            UpdateQuery uQuery;

            if (record0 != null)
            {
                uQuery = new UpdateQuery(Item.GetTable(typeof(Forum)));
                uQuery.AddField("forum_order", new QueryOperation("forum_order", QueryOperations.Subtraction, difference));
                uQuery.AddCondition("forum_order", ConditionEquality.GreaterThanEqual, record0.Order);
                if (record1 != null)
                {
                    uQuery.AddCondition("forum_order", ConditionEquality.LessThan, record1.Order);
                }
                else
                {
                    /* TODO: test */
                    query = Forum.GetSelectQueryStub(core, typeof(Forum));
                    query.AddCondition("forum_parent_id", ParentId); /* or any level below */
                    query.AddCondition("forum_item_id", Owner.Id);
                    query.AddCondition("forum_item_type_id", Owner.TypeId);
                    query.AddCondition("forum_order", ConditionEquality.GreaterThan, Order);
                    query.AddSort(SortOrder.Descending, "forum_order");
                    query.LimitCount = 1;

                    levelForumsDataTable = core.Db.Query(query);

                    Forum record = null;
                    if (levelForumsDataTable.Rows.Count == 1)
                    {
                        record = new Forum(core, levelForumsDataTable.Rows[0]);

                        query.AddCondition("forum_order", ConditionEquality.LessThanEqual, record.Order);
                    }
                }

                db.Query(uQuery);
            }

            if (updateIds.Count > 0)
            {
                uQuery = new UpdateQuery(Item.GetTable(typeof(Forum)));
                uQuery.AddField("forum_order", new QueryOperation("forum_order", QueryOperations.Addition, differenceBelow));
                uQuery.AddCondition("forum_id", ConditionEquality.In, updateIds);

                db.Query(uQuery);
            }
        }
        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"));
            }
        }
Example #3
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;
        }
Example #4
0
        public TopicPost AddReply(Core core, Forum forum, string subject, string text)
        {
            db.BeginTransaction();

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

            topicPosts++;

            UpdateQuery uQuery = new UpdateQuery(ForumTopic.GetTable(typeof(ForumTopic)));
            uQuery.AddField("topic_posts", new QueryOperation("topic_posts", QueryOperations.Addition, 1));
            uQuery.AddField("topic_last_post_id", post.Id);
            uQuery.AddField("topic_last_post_time_ut", post.TimeCreatedRaw);
            uQuery.AddCondition("topic_id", post.TopicId);

            long rowsUpdated = db.Query(uQuery);

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

            if (forumId > 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_last_post_id", post.Id);
                uQuery.AddField("forum_last_post_time_ut", post.TimeCreatedRaw);
                uQuery.AddCondition("forum_id", ConditionEquality.In, parentForumIds);

                rowsUpdated = db.Query(uQuery);

                if (rowsUpdated < 1)
                {
                    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.AddCondition("forum_item_id", Forum.Owner.Id);
            uQuery.AddCondition("forum_item_type_id", Forum.Owner.TypeId);

            rowsUpdated = db.Query(uQuery);

            if (rowsUpdated != 1)
            {
                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 = 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);

                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 post;
        }
Example #5
0
        internal static void Create(Core core, Forum forum)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (core.LoggedInMemberId > 0)
            {
                InsertQuery iQuery = new InsertQuery(GetTable(typeof(ForumReadStatus)));
                iQuery.AddField("forum_id", forum.Id);
                iQuery.AddField("user_id", core.LoggedInMemberId);
                iQuery.AddField("read_time_ut", UnixTime.UnixTimeStamp()); // forum.LastPostTimeRaw

                core.Db.Query(iQuery);
            }
        }
Example #6
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;
                    }
            }
        }
Example #7
0
        void McpMain_Lock(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            long topicId = core.Functions.RequestLong("t", 0);
            long forumId = core.Functions.RequestLong("f", 0);
            long updated = 0;
            Forum forum = null;

            if (topicId > 0)
            {
                ForumTopic topic = null;

                try
                {
                    topic = new ForumTopic(core, topicId);
                }
                catch (InvalidTopicException)
                {
                    return;
                }

                if (topic.Forum.Access.Can("LOCK_TOPICS"))
                {
                    switch (e.Mode)
                    {
                        case "lock":
                            topic.IsLocked = true;
                            break;
                        case "unlock":
                            topic.IsLocked = false;
                            break;
                    }

                    topic.Update();

                    updated = 1;
                }
            }
            else
            {
                // Not locking a single topic, locking from the MCP

                List<long> topicIds = core.Functions.FormLongArray("checkbox");

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

                switch (e.Mode)
                {
                    case "lock":
                        forum.LockTopics(topicIds);
                        break;
                    case "unlock":
                        forum.UnLockTopics(topicIds);
                        break;
                }

                updated = topicIds.Count;
            }

            switch (e.Mode)
            {
                case "lock":
                    core.Display.ShowMessage("Locked", "The selected topics (" + updated.ToString() + ") have been locked.");
                    break;
                case "unlock":
                    core.Display.ShowMessage("Unlocked", "The selected topics (" + updated.ToString() + ") have been unlocked.");
                    break;
            }
            SetRedirectUri(BuildUri());
        }
Example #8
0
        internal TopicPost(Core core, Forum forum, ForumTopic topic, long postId)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(Post_ItemLoad);
            this.forum = forum;
            this.topic = topic;

            try
            {
                LoadItem(postId);
            }
            catch (InvalidItemException)
            {
                throw new InvalidPostException();
            }
        }
Example #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="core"></param>
        /// <param name="parent"></param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="rules"></param>
        /// <param name="permissions"></param>
        /// <param name="isCategory"></param>
        /// <returns></returns>
        /// <exception cref="NullCoreException"></exception>
        /// <exception cref="InvalidForumException"></exception>
        /// <exception cref="UnauthorisedToCreateItemException"></exception>
        public static Forum Create(Core core, Forum parent, string title, string description, string rules, ushort permissions, bool isCategory)
        {
            string parents;
            int order = 0;
            int level = 0;

            //core.db.BeginTransaction();

            if (core == null)
            {
                throw new NullCoreException();
            }

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

            level = parent.Level + 1;

            if (parent.Owner is UserGroup)
            {
                if (!((UserGroup)parent.Owner).IsGroupOperator(core.Session.LoggedInMember.ItemKey))
                {
                    // todo: throw new exception
                    throw new UnauthorisedToCreateItemException();
                }
            }

            SelectQuery query = new SelectQuery(GetTable(typeof(Forum)));
            query.AddFields("forum_order");
            query.AddCondition("forum_order", ConditionEquality.GreaterThan, parent.Order);
            query.AddCondition("forum_item_id", parent.Owner.Id);
            query.AddCondition("forum_item_type_id", parent.Owner.TypeId);
            query.AddCondition("forum_parent_id", parent.Id);
            query.AddSort(SortOrder.Descending, "forum_order");
            query.LimitCount = 1;

            DataTable orderTable = core.Db.Query(query);

            if (orderTable.Rows.Count == 1)
            {
                order = (int)orderTable.Rows[0]["forum_order"] + 1;
            }
            else
            {
                order = parent.Order + 1;
            }

            // increment all items below in the order
            UpdateQuery uQuery = new UpdateQuery(GetTable(typeof(Forum)));
            uQuery.AddField("forum_order", new QueryOperation("forum_order", QueryOperations.Addition, 1));
            uQuery.AddCondition("forum_order", ConditionEquality.GreaterThanEqual, order);
            uQuery.AddCondition("forum_item_id", parent.Owner.Id);
            uQuery.AddCondition("forum_item_type_id", parent.Owner.TypeId);

            core.Db.Query(uQuery);

            ParentTree parentTree = new ParentTree();

            if (parent.Parents != null)
            {
                foreach (ParentTreeNode ptn in parent.Parents.Nodes)
                {
                    parentTree.Nodes.Add(new ParentTreeNode(ptn.ParentTitle, ptn.ParentId));
                }
            }

            if (parent.Id > 0)
            {
                parentTree.Nodes.Add(new ParentTreeNode(parent.Title, parent.Id));
            }

            XmlSerializer xs = new XmlSerializer(typeof(ParentTree));
            StringBuilder sb = new StringBuilder();
            StringWriter stw = new StringWriter(sb);

            xs.Serialize(stw, parentTree);
            stw.Flush();
            stw.Close();

            parents = sb.ToString();

            InsertQuery iquery = new InsertQuery(GetTable(typeof(Forum)));
            iquery.AddField("forum_parent_id", parent.Id);
            iquery.AddField("forum_title", title);
            iquery.AddField("forum_description", description);
            iquery.AddField("forum_rules", rules);
            iquery.AddField("forum_order", order);
            iquery.AddField("forum_level", level);
            iquery.AddField("forum_category", isCategory);
            iquery.AddField("forum_locked", false);
            iquery.AddField("forum_topics", 0);
            iquery.AddField("forum_posts", 0);
            iquery.AddField("forum_item_id", parent.Owner.Id);
            iquery.AddField("forum_item_type_id", parent.Owner.TypeId);
            iquery.AddField("forum_parents", parents);
            iquery.AddField("forum_last_post_id", 0);
            iquery.AddField("forum_last_post_time_ut", UnixTime.UnixTimeStamp());

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

            Forum forum = new Forum(core, forumId);

            /* LOAD THE DEFAULT ITEM PERMISSIONS */
            //Access.CreateAllGrantsForOwner(core, forum);

            if (parent.Owner is UserGroup)
            {
                Access.CreateGrantForPrimitive(core, forum, UserGroup.GetGroupMembersGroupKey(core), "VIEW");
                Access.CreateGrantForPrimitive(core, forum, UserGroup.GetGroupMembersGroupKey(core), "VIEW_TOPICS");
                Access.CreateGrantForPrimitive(core, forum, UserGroup.GetGroupMembersGroupKey(core), "LIST_TOPICS");
                Access.CreateGrantForPrimitive(core, forum, UserGroup.GetGroupMembersGroupKey(core), "REPLY_TOPICS");
                Access.CreateGrantForPrimitive(core, forum, UserGroup.GetGroupMembersGroupKey(core), "CREATE_TOPICS");
                Access.CreateGrantForPrimitive(core, forum, UserGroup.GetGroupMembersGroupKey(core), "REPORT_POSTS");
                Access.CreateGrantForPrimitive(core, forum, UserGroup.GetGroupOperatorsGroupKey(core), "CREATE_STICKY");
                Access.CreateGrantForPrimitive(core, forum, UserGroup.GetGroupOfficersGroupKey(core), "CREATE_STICKY");
                Access.CreateGrantForPrimitive(core, forum, UserGroup.GetGroupOperatorsGroupKey(core), "CREATE_ANNOUNCEMENT");
            }

            return forum;
        }
Example #10
0
        public static List<Forum> GetForumLevels(Core core, Forum parent, int levels)
        {
            List<Forum> forums = new List<Forum>();

            SelectQuery query = Item.GetSelectQueryStub(core, typeof(Forum));
            query.AddCondition("forum_item_id", parent.Owner.Id);
            query.AddCondition("forum_item_type_id", parent.Owner.TypeId);
            query.AddCondition("forum_level", ConditionEquality.GreaterThan, parent.Level);
            query.AddCondition("forum_level", ConditionEquality.LessThanEqual, parent.Level + levels);
            query.AddCondition("forum_order", ConditionEquality.GreaterThanEqual, parent.Order);
            query.AddSort(SortOrder.Ascending, "forum_order");

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

            bool isFirst = true;
            long topLevelParent = -1;
            while (forumsReader.Read())
            {
                Forum forum;
                if (parent.Owner is UserGroup)
                {
                    forum = new Forum(core, parent.Settings, (UserGroup)parent.Owner, forumsReader);
                }
                else
                {
                    forum = new Forum(core, parent.Settings, forumsReader);
                }

                if (isFirst)
                {
                    if (forum.Order != parent.Order + 1 && forum.Order != 0)
                    {
                        break;
                    }
                    isFirst = false;
                }

                if (topLevelParent == -1)
                {
                    forums.Add(forum);
                    topLevelParent = forum.parentId;
                }
                else
                {
                    if ((forum.Level == (parent.Level + 1)) && (forum.parentId != topLevelParent))
                    {
                        break;
                    }
                    else
                    {
                        forums.Add(forum);
                    }
                }
            }

            forumsReader.Close();
            forumsReader.Dispose();

            return forums;
        }
Example #11
0
        public static SelectBox BuildForumJumpBox(Core core, Primitive owner, long currentForum)
        {
            SelectBox sb = new SelectBox("forum");

            sb.Add(new SelectBoxItem("", core.Prose.GetString("SELECT_A_FORUM")));
            sb.Add(new SelectBoxItem("", "--------------------"));

            SelectQuery query = Item.GetSelectQueryStub(core, typeof(Forum));
            query.AddCondition("forum_item_id", owner.Id);
            query.AddCondition("forum_item_type_id", owner.TypeId);
            query.AddSort(SortOrder.Ascending, "forum_order");

            DataTable forumsTable = core.Db.Query(query);

            foreach (DataRow dr in forumsTable.Rows)
            {
                Forum forum;
                if (owner is UserGroup)
                {
                    forum = new Forum(core, (UserGroup)owner, dr);
                }
                else
                {
                    forum = new Forum(core, dr);
                }
                if (forum != null)
                {
                    if (forum.Access.Can("VIEW"))
                    {
                        sb.Add(new SelectBoxItem(forum.Id.ToString(), forum.Title));
                    }
                }
            }

            if (sb.ContainsKey(currentForum.ToString()))
            {
                sb.SelectedKey = currentForum.ToString();
            }

            return sb;
        }
Example #12
0
        public void MoveUp()
        {
            if (Order == 0)
            {
                return;
            }

            SelectQuery query = Forum.GetSelectQueryStub(core, typeof(Forum));
            query.AddCondition("forum_parent_id", ParentId);
            query.AddCondition("forum_item_id", Owner.Id);
            query.AddCondition("forum_item_type_id", Owner.TypeId);
            query.AddCondition("forum_order", ConditionEquality.LessThan, Order);
            query.AddSort(SortOrder.Descending, "forum_order");
            query.LimitCount = 2;

            DataTable levelForumsDataTable = db.Query(query);

            Forum record0 = null;
            Forum record1 = null;
            int difference = 0;
            int differenceAbove = 0;

            if (levelForumsDataTable.Rows.Count == 0)
            {
                /* Cannot move up */
                return;
            }

            if (levelForumsDataTable.Rows.Count >= 1)
            {
                record0 = new Forum(core, levelForumsDataTable.Rows[0]);
                difference = record0.Order - Order;
            }

            if (levelForumsDataTable.Rows.Count >= 2)
            {
                record1 = new Forum(core, levelForumsDataTable.Rows[1]);
                differenceAbove = record1.Order - record0.Order;
            }

            // Get IDs of forums from this to next forum down
            // move all up by difference

            // Get IDs of foruns from next forum up to this
            // move all down by difference2
        }
Example #13
0
        public bool MoveTopics(long toForumId, params long[] topicIds)
        {
            if (!Access.Can("MOVE_TOPICS"))
            {
                return false;
            }

            Forum toForum = new Forum(core, toForumId);
            if (!toForum.Access.Can("MOVE_TOPICS"))
            {
                return false;
            }

            if (toForum.ownerKey.Id != ownerKey.Id || toForum.ownerKey.TypeId != ownerKey.TypeId)
            {
                return false;
            }

            /* Can move the topics */

            /* Validate the topics belong to the from forum */
            List<ForumTopic> topics = GetTopicsFlat(topicIds);

            if (topics.Count < topicIds.Length)
            {
                return false;
            }

            long posts = 0;
            bool newerPosts = false;
            long lastPost = toForum.LastPostId;
            long lastPostTime = toForum.lastPostTimeRaw;

            bool newestPost = false;

            for (int i = 0; i < topics.Count; i++)
            {
                posts++;
                posts += topics[i].Posts;
                if (topics[i].TimeLastPostRaw > toForum.lastPostTimeRaw)
                {
                    lastPost = topics[i].LastPostId;
                    lastPostTime = topics[i].TimeLastPostRaw;
                }
                if (topics[i].LastPostId == toForum.LastPostId)
                {
                    newestPost = true;
                }
            }

            db.BeginTransaction();

            UpdateQuery uQuery = new UpdateQuery(typeof(ForumTopic));
            uQuery.AddField("forum_id", toForumId);
            uQuery.AddCondition("topic_id", ConditionEquality.In, topicIds);

            db.Query(uQuery);

            uQuery = new UpdateQuery(typeof(Forum));
            uQuery.AddField("forum_topics", new QueryOperation("forum_topics", QueryOperations.Subtraction, topicIds.Length));
            uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Subtraction, posts));
            if (newestPost)
            {
            }
            uQuery.AddCondition("forum_id", forumId);

            db.Query(uQuery);

            uQuery = new UpdateQuery(typeof(Forum));
            uQuery.AddField("forum_topics", new QueryOperation("forum_topics", QueryOperations.Addition, topicIds.Length));
            uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Addition, posts));
            if (newerPosts)
            {
                uQuery.AddField("forum_last_post_id", lastPost);
                uQuery.AddField("forum_last_post_time_ut", lastPostTime);
            }
            uQuery.AddCondition("forum_id", forumId);

            db.Query(uQuery);

            return true;
        }
Example #14
0
        void AccountForumManage_Delete_Save(object sender, EventArgs e)
        {
            long forumId = core.Functions.FormLong("id", 0);

            Forum forum;

            try
            {
                forum = new Forum(core, forumId);
            }
            catch (InvalidForumException)
            {
                DisplayGenericError();
                return;
            }

            forum.Delete();

            core.Display.ShowMessage("Forum deleted", "The forum has been deleted.");
        }
Example #15
0
        void McpMain_Move(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

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

            ForumTopic topic = null;
            Forum newForum = null;
            Forum oldForum = null;

            try
            {
                topic = new ForumTopic(core, topicId);
                oldForum = topic.Forum;
            }
            catch (InvalidTopicException)
            {
                return;
            }

            try
            {
                if (forumId > 0)
                {
                    newForum = new Forum(core, forumId);
                }
                else
                {
                    newForum = new Forum(core, Owner);
                }
            }
            catch (InvalidTopicException)
            {
                return;
            }

            /* Cannot move topics outside the forum to another owner's forum */
            if (newForum.Owner.Id != Owner.Id || newForum.Owner.TypeId != Owner.TypeId)
            {
                return;
            }

            /* Attempting to move to the same forum (not a move, ignore) */
            if (oldForum.Id == newForum.Id)
            {
                return;
            }

            db.BeginTransaction();

            {
                UpdateQuery uQuery = new UpdateQuery(typeof(ForumTopic));
                uQuery.AddField("forum_id", newForum.Id);
                uQuery.AddCondition("topic_id", topic.Id);

                db.Query(uQuery);
            }

            {
                UpdateQuery uQuery = new UpdateQuery(typeof(TopicPost));
                uQuery.AddField("forum_id", newForum.Id);
                uQuery.AddCondition("topic_id", topic.Id);

                db.Query(uQuery);
            }

            {
                UpdateQuery uQuery = new UpdateQuery(typeof(TopicReadStatus));
                uQuery.AddField("forum_id", newForum.Id);
                uQuery.AddCondition("topic_id", topic.Id);

                db.Query(uQuery);
            }

            {
                if (oldForum.Id > 0)
                {
                    UpdateQuery uQuery = new UpdateQuery(typeof(Forum));
                    uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Subtraction, topic.Posts + 1));
                    uQuery.AddField("forum_topics", new QueryOperation("forum_topics", QueryOperations.Subtraction, 1));
                    uQuery.AddCondition("forum_id", oldForum.Id);

                    db.Query(uQuery);
                }
            }

            {
                if (newForum.Id > 0)
                {
                    UpdateQuery uQuery = new UpdateQuery(typeof(Forum));
                    uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Addition, topic.Posts + 1));
                    uQuery.AddField("forum_topics", new QueryOperation("forum_topics", QueryOperations.Addition, 1));
                    uQuery.AddCondition("forum_id", newForum.Id);

                    db.Query(uQuery);
                }
            }
        }
Example #16
0
        public void ShowGroupForum(HookEventArgs e)
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "viewprofileforum");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            Forum forum = new Forum(core, (UserGroup)e.Owner);
            template.Parse("U_FORUM", forum.Uri);

            List<ForumTopic> recentTopics = forum.GetTopicsFlat(0, 10);

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

            topicLastPosts = TopicPost.GetTopicLastPosts(core, recentTopics);

            template.Parse("TOPICS", recentTopics.Count.ToString());

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

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

                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;
                }
            }

            e.core.AddMainPanel(template);
        }
Example #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);
        }
Example #18
0
        internal static TopicPost Create(Core core, Forum forum, ForumTopic topic, string subject, string text)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (forum == null)
            {
                if (topic.ForumId == forum.Id)
                {
                    forum = topic.Forum;
                }
            }
            else
            {
                if (topic.ForumId != forum.Id)
                {
                    forum = topic.Forum;
                }
            }

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

            if (topic == null)
            {
                throw new InvalidTopicException();
            }

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

            InsertQuery iQuery = new InsertQuery(NumberedItem.GetTable(typeof(TopicPost)));
            iQuery.AddField("topic_id", topic.Id);
            iQuery.AddField("forum_id", forum.Id);
            iQuery.AddField("user_id", core.LoggedInMemberId);
            iQuery.AddField("post_title", subject);
            iQuery.AddField("post_text", text);
            iQuery.AddField("post_time_ut", UnixTime.UnixTimeStamp());
            iQuery.AddField("post_modified_ut", UnixTime.UnixTimeStamp());
            iQuery.AddField("post_ip", core.Session.IPAddress.ToString());

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

            TopicPost newPost = new TopicPost(core, forum, topic, postId);

            core.Search.Index(newPost, new SearchField("forum_id", forum.Id.ToString()));

            return newPost;
        }
Example #19
0
        void AccountForumManage_Edit_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long parentId = core.Functions.FormLong("parent", 0);
            long forumId = core.Functions.FormLong("id", 0);
            string title = core.Http.Form["title"];
            string description = core.Http.Form["description"];
            string rules = core.Http.Form["rules"];
            string type = core.Http.Form["type"];

            Forum forum;

            try
            {
                forum = new Forum(core, forumId);
            }
            catch (InvalidForumException)
            {
                DisplayGenericError();
                return;
            }

            /*if (parentId != forum.ParentId)
            {
                db.BeginTransaction();
                int order = 0;
                int level = 0;

                Forum parent = null;

                if (parentId > 0)
                {
                    parent = new Forum(core, parentId);
                }
                else
                {
                    parent = new Forum(core, Owner);
                }

                if (!parent.Owner.Equals(Owner))
                {
                    DisplayError("Cannot move forum to another owner");
                    return;
                }

                forum.ParentId = parentId;

                level = parent.Level + 1;

                forum.Level = level;

                SelectQuery query = new SelectQuery(typeof(Forum));
                query.AddFields("forum_order");
                query.AddCondition("forum_order", ConditionEquality.GreaterThan, parent.Order);
                query.AddCondition("forum_item_id", parent.Owner.Id);
                query.AddCondition("forum_item_type_id", parent.Owner.TypeId);
                query.AddCondition("forum_parent_id", parent.Id);
                query.AddSort(SortOrder.Descending, "forum_order");
                query.LimitCount = 1;

                DataTable orderTable = core.Db.Query(query);

                if (orderTable.Rows.Count == 1)
                {
                    int tableorder = (int)orderTable.Rows[0]["forum_order"];
                    if (forum.Order < tableorder)
                    {
                        order = tableorder;
                    }
                    else
                    {
                        order = tableorder + 1;
                    }
                }
                else
                {
                    if (forum.Order < parent.Order)
                    {
                        order = parent.Order;
                    }
                    else
                    {
                        order = parent.Order + 1;
                    }
                }

                if (order > forum.Order)
                {
                    UpdateQuery uQuery = new UpdateQuery(typeof(Forum));
                    uQuery.AddField("forum_order", new QueryOperation("forum_order", QueryOperations.Subtraction, 1));
                    uQuery.AddCondition("forum_order", ConditionEquality.GreaterThan, forum.Order);
                    uQuery.AddCondition("forum_order", ConditionEquality.LessThanEqual, order);
                    uQuery.AddCondition("forum_item_id", parent.Owner.Id);
                    uQuery.AddCondition("forum_item_type_id", parent.Owner.TypeId);

                    core.Db.Query(uQuery);
                }

                if (order < forum.Order)
                {
                    UpdateQuery uQuery = new UpdateQuery(typeof(Forum));
                    uQuery.AddField("forum_order", new QueryOperation("forum_order", QueryOperations.Addition, 1));
                    uQuery.AddCondition("forum_order", ConditionEquality.GreaterThanEqual, order);
                    uQuery.AddCondition("forum_order", ConditionEquality.LessThan, forum.Order);
                    uQuery.AddCondition("forum_item_id", parent.Owner.Id);
                    uQuery.AddCondition("forum_item_type_id", parent.Owner.TypeId);

                    core.Db.Query(uQuery);
                }

                /*
                // decrement all items below old order in the order
                UpdateQuery uQuery = new UpdateQuery(typeof(Forum));
                uQuery.AddField("forum_order", new QueryOperation("forum_order", QueryOperations.Subtraction, 1));
                uQuery.AddCondition("forum_order", ConditionEquality.GreaterThanEqual, forum.Order);
                uQuery.AddCondition("forum_item_id", parent.Owner.Id);
                uQuery.AddCondition("forum_item_type_id", parent.Owner.TypeId);

                core.Db.Query(uQuery);

                // increment all items below in the order
                uQuery = new UpdateQuery(typeof(Forum));
                uQuery.AddField("forum_order", new QueryOperation("forum_order", QueryOperations.Addition, 1));
                uQuery.AddCondition("forum_order", ConditionEquality.GreaterThanEqual, order);
                uQuery.AddCondition("forum_item_id", parent.Owner.Id);
                uQuery.AddCondition("forum_item_type_id", parent.Owner.TypeId);

                core.Db.Query(uQuery);/

                forum.Order = order;
            }*/

            forum.Title = title;
            forum.Description = description;
            forum.Rules = rules;
            //forum.Permissions = Functions.GetPermission();

            try
            {
                forum.Update();
            }
            catch (UnauthorisedToUpdateItemException)
            {
                DisplayGenericError();
                return;
            }

            if (forum.ParentId == 0)
            {
                SetRedirectUri(BuildUri("forum"));
            }
            else
            {
                SetRedirectUri(BuildUri("forum", forum.ParentId));
            }
            core.Display.ShowMessage("Forum updated", "You have updated the forum");
        }
Example #20
0
        private void ShowPostingScreen(string submitMode, ShowPPageEventArgs e)
        {
            long forumId = core.Functions.FormLong("f", core.Functions.RequestLong("f", 0));
            long topicId = core.Functions.FormLong("t", core.Functions.RequestLong("t", 0));
            long postId = core.Functions.FormLong("p", core.Functions.RequestLong("p", 0));
            string subject = core.Http.Form["subject"];
            string text = core.Http.Form["post"];
            string mode = core.Http.Query["mode"];
            string topicState = core.Http.Form["topic-state"];

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

            if (string.IsNullOrEmpty(mode))
            {
                mode = core.Http.Form["mode"];
            }

            if (string.IsNullOrEmpty(topicState))
            {
                topicState = ((byte)TopicStates.Normal).ToString();
            }

            List<SelectBoxItem> sbis = new List<SelectBoxItem>();
            sbis.Add(new SelectBoxItem(((byte)TopicStates.Normal).ToString(), "Topic"));

            if (page is GPage)
            {
                core.Template.Parse("S_POST", core.Hyperlink.AppendSid(string.Format("{0}forum/post",
                    ((GPage)page).Group.UriStub), true));

                if (((GPage)page).Group.IsGroupOperator(core.Session.LoggedInMember.ItemKey) && topicId == 0)
                {
                    // TODO: Global, remember to update columns to 4
                }
            }

            if (topicId > 0)
            {
                ForumTopic thisTopic = new ForumTopic(core, topicId);

                List<TopicPost> posts = thisTopic.GetLastPosts(10);

                if (posts.Count > 0)
                {
                    core.Template.Parse("PREVIEW_TOPIC", "TRUE");
                }

                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("POST_MODIFIED", core.tz.DateTimeToString(post.GetModifiedDate(core.tz)));
                    postVariableCollection.Parse("ID", post.Id.ToString());
                    core.Display.ParseBbcode(postVariableCollection, "TEXT", post.Text);
                    postVariableCollection.Parse("U_USER", post.Poster.Uri);
                    postVariableCollection.Parse("USER_DISPLAY_NAME", post.Poster.UserInfo.DisplayName);
                    postVariableCollection.Parse("USER_TILE", post.Poster.Tile);
                    postVariableCollection.Parse("USER_ICON", post.Poster.Icon);
                    postVariableCollection.Parse("USER_JOINED", core.Tz.DateTimeToString(post.Poster.UserInfo.GetRegistrationDate(core.Tz)));
                    postVariableCollection.Parse("USER_COUNTRY", post.Poster.Profile.Country);

                    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 (thisTopic.Forum.Access.Can("CREATE_STICKY"))
                {
                    sbis.Add(new SelectBoxItem(((byte)TopicStates.Sticky).ToString(), "Sticky"));
                }
                if (thisTopic.Forum.Access.Can("CREATE_ANNOUNCEMENTS"))
                {
                    sbis.Add(new SelectBoxItem(((byte)TopicStates.Announcement).ToString(), "Announcement"));
                }

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

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

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

                breadCrumbParts.Add(new string[] { "*forum/post/?t=" + thisTopic.Id.ToString() + "&mode=reply", core.Prose.GetString("POST_REPLY") });
            }
            else if (forumId > 0)
            {
                Forum 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;
                }

                if (forum.Access.Can("CREATE_STICKY"))
                {
                    sbis.Add(new SelectBoxItem(((byte)TopicStates.Sticky).ToString(), "Sticky"));
                }
                if (forum.Access.Can("CREATE_ANNOUNCEMENTS"))
                {
                    sbis.Add(new SelectBoxItem(((byte)TopicStates.Announcement).ToString(), "Announcement"));
                }

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

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

                breadCrumbParts.Add(new string[] { "*forum/post/?f=" + forum.Id.ToString() + "&mode=post", core.Prose.GetString("NEW_TOPIC") });
            }

            core.Template.Parse("S_MODE", mode);

            if (forumId > 0)
            {
                core.Template.Parse("S_FORUM", forumId.ToString());
            }

            if (topicId > 0)
            {
                core.Template.Parse("S_TOPIC", topicId.ToString());
            }

            if (postId > 0)
            {
                core.Template.Parse("S_ID", postId.ToString());
            }

            if (!string.IsNullOrEmpty(subject))
            {
                core.Template.Parse("S_SUBJECT", subject);
            }
            else
            {
                if (topicId > 0)
                {
                    ForumTopic topic = new ForumTopic(core, topicId);
                    core.Template.Parse("S_SUBJECT", "RE: " + topic.Title);
                }
            }

            if (!string.IsNullOrEmpty(text))
            {
                core.Template.Parse("S_POST_TEXT", text);
            }

            if (sbis.Count > 1 && (mode == "post" || mode == "edit"))
            {
                core.Display.ParseRadioArray("S_TOPIC_STATE", "topic-state", sbis.Count, sbis, topicState);
            }

            if (submitMode != "none")
            {
                if (topicId == 0 && (string.IsNullOrEmpty(subject) || subject.Length < 3))
                {
                    core.Template.Parse("ERROR", "New topic must have a subject");
                    return;
                }

                if (string.IsNullOrEmpty(text) || text.Length < 3)
                {
                    core.Template.Parse("ERROR", "Post too short, must be at least three characters long");
                    return;
                }
            }

            if (submitMode == "preview")
            {
                core.Display.ParseBbcode("PREVIEW", text);
                core.Display.ParseBbcode("SUBJECT", subject);

                try
                {
                    ForumMember member = new ForumMember(core, page.Owner, page.loggedInMember);

                    core.Display.ParseBbcode("SIGNATURE", member.ForumSignature);
                }
                catch (InvalidForumMemberException)
                {
                }
            }

            foreach (Emoticon emoticon in core.Emoticons)
            {
                if (emoticon.Category == "modifier") continue;
                if (emoticon.Category == "people" && emoticon.Code.Length < 3)
                {
                    VariableCollection emoticonVariableCollection = e.Template.CreateChild("emoticon_list");
                    emoticonVariableCollection.Parse("CODE", emoticon.Code);
                    emoticonVariableCollection.Parse("URI", emoticon.File);
                }
                else
                {
                    VariableCollection emoticonVariableCollection = e.Template.CreateChild("emoticon_hidden_list");
                    emoticonVariableCollection.Parse("CODE", emoticon.Code);
                    emoticonVariableCollection.Parse("URI", emoticon.File);
                }
            }

            if (submitMode == "draft" || submitMode == "post")
            {
                SavePost(mode, subject, text);
            }

            page.Owner.ParseBreadCrumbs(breadCrumbParts);
        }
Example #21
0
        void AccountForumManage_Move(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

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

            Forum forum;

            try
            {
                forum = new Forum(core, forumId);
            }
            catch (InvalidForumException)
            {
                DisplayGenericError();
                return;
            }

            switch (e.Mode)
            {
                case "move-up":
                    forum.MoveUp();
                    core.Display.ShowMessage("Forum moved up", "You have moved the forum up in the list.");
                    break;
                case "move-down":
                    forum.MoveDown();
                    core.Display.ShowMessage("Forum moved down", "You have moved the forum down in the list.");
                    break;
            }
        }
Example #22
0
        public ForumTopic(Core core, Forum forum, System.Data.Common.DbDataReader topicRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(Topic_ItemLoad);

            this.forum = forum;

            try
            {
                loadItemInfo(topicRow);
            }
            catch (InvalidItemException)
            {
                throw new InvalidTopicException();
            }

            try
            {
                readStatus = new TopicReadStatus(core, topicRow);
                readStatusLoaded = true;
            }
            catch (InvalidTopicReadStatusException)
            {
                readStatus = null;
                readStatusLoaded = true;
            }
        }
Example #23
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);
        }
Example #24
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;
            }
        }
Example #25
0
        void AccountForumManage_New_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long parentId = core.Functions.FormLong("parent", 0);
            string title = core.Http.Form["title"];
            string description = core.Http.Form["description"];
            string rules = core.Http.Form["rules"];
            string type = core.Http.Form["type"];
            bool isCategory = (type == "CAT");

            Forum parent;

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

            if (parent != null)
            {
                try
                {
                    Forum forum = Forum.Create(core, parent, title, description, rules, 0x1111, isCategory);
                    if (parentId == 0)
                    {
                        SetRedirectUri(BuildUri("forum"));
                    }
                    else
                    {
                        SetRedirectUri(BuildUri("forum", forum.ParentId));
                    }
                    core.Display.ShowMessage("Forum Created", "A new forum has been created");
                }
                catch (UnauthorisedToCreateItemException)
                {
                    DisplayGenericError();
                }
                catch (InvalidForumException)
                {
                    DisplayGenericError();
                }
            }
        }
Example #26
0
        public ForumTopic(Core core, Forum forum, long topicId)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(Topic_ItemLoad);

            this.forum = forum;

            SelectQuery query = ForumTopic_GetSelectQueryStub(core);
            query.AddCondition("`forum_topics`.`topic_id`", topicId);

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

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

                loadItemInfo(topicReader);

                try
                {
                    readStatus = new TopicReadStatus(core, topicReader);
                    readStatusLoaded = true;
                }
                catch (InvalidTopicReadStatusException)
                {
                    readStatus = null;
                    readStatusLoaded = true;
                }

                topicReader.Close();
                topicReader.Dispose();
            }
            else
            {
                topicReader.Close();
                topicReader.Dispose();

                throw new InvalidTopicException();
            }
        }
Example #27
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");
            }
        }