internal static void Create(Core core, ForumTopic topic, TopicPost lastVisiblePost) { if (core == null) { throw new NullCoreException(); } if (core.LoggedInMemberId > 0) { InsertQuery iQuery = new InsertQuery(GetTable(typeof(TopicReadStatus))); iQuery.AddField("topic_id", topic.Id); iQuery.AddField("user_id", core.LoggedInMemberId); iQuery.AddField("forum_id", topic.ForumId); iQuery.AddField("read_time_ut", lastVisiblePost.TimeCreatedRaw); core.Db.Query(iQuery); } }
internal static void Create(Core core, ForumTopic topic) { if (core == null) { throw new NullCoreException(); } if (core.LoggedInMemberId > 0) { InsertQuery iQuery = new InsertQuery(GetTable(typeof(TopicReadStatus))); iQuery.AddField("topic_id", topic.Id); iQuery.AddField("user_id", core.LoggedInMemberId); iQuery.AddField("forum_id", topic.ForumId); iQuery.AddField("read_time_ut", UnixTime.UnixTimeStamp()); // topic.LastPostTimRaw core.Db.Query(iQuery); } }
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; }
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; } }
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); }
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; } } }
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(); } }
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; }
public TopicPost(Core core, ForumTopic topic, System.Data.Common.DbDataReader postRow) : base(core) { this.topic = topic; ItemLoad += new ItemLoadHandler(Post_ItemLoad); try { loadItemInfo(postRow); } catch (InvalidItemException) { throw new InvalidPostException(); } }
void McpMain_Delete(object sender, ModuleModeEventArgs e) { AuthoriseRequestSid(); long topicId = core.Functions.FormLong("t", 0); long updated = 0; ForumTopic topic = null; if (topicId > 0) { try { topic = new ForumTopic(core, topicId); } catch (InvalidTopicException) { return; } if (topic.Forum.Access.Can("DELETE_TOPICS")) { // TODO: statistics updating //topic.Delete(); } } else { // Not deleting a single topic, locking from the MCP List<long> topicIds = core.Functions.FormLongArray("checkbox"); } core.Display.ShowMessage("Locked", "The selected topics (" + updated.ToString() + ") have been deleted."); SetRedirectUri(BuildUri()); }
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); } } }
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()); }
/*public List<ForumTopic> GetTopics(int currentPage, int perPage) { List<ForumTopic> topics = new List<ForumTopic>(); SelectQuery query = new SelectQuery("forum_topics"); query.AddCondition("forum_id", forumId); query.AddCondition("topic_item_id", ownerId); query.AddCondition("topic_item_type", ownerType); query.AddSort(SortOrder.Descending, "topic_last_post_id"); DataTable topicsTable = db.Query(query); /*DataTable topicsTable = db.Query(string.Format(@"SELECT {0} FROM forum_topics LEFT JOIN topic_posts tp ON tp.post_id = ft.topic_last_post_id WHERE ft.item_id = {1} AND ft.item_type = '{2}' ORDER BY ft.topic_last_post_time DESC", ForumTopic.FORUM_TOPIC_INFO_FIELDS, owner.Id, owner.GetType()));*\/ foreach (DataRow dr in topicsTable.Rows) { topics.Add(new ForumTopic(core, dr)); } return topics; }*/ public List<ForumTopic> GetTopicsFlat(int currentPge, int perPage) { List<ForumTopic> topics = new List<ForumTopic>(); SelectQuery query = ForumTopic.GetSelectQueryStub(core, typeof(ForumTopic), false); query.AddFields(TopicPost.GetFieldsPrefixed(core, typeof(TopicPost))); query.AddJoin(JoinTypes.Left, TopicPost.GetTable(typeof(TopicPost)), "topic_last_post_id", "post_id"); if (core.LoggedInMemberId > 0) { query.AddFields(TopicPost.GetFieldsPrefixed(core, typeof(TopicReadStatus))); TableJoin tj1 = query.AddJoin(JoinTypes.Left, TopicReadStatus.GetTable(typeof(TopicReadStatus)), "topic_id", "topic_id"); tj1.AddCondition("`forum_topic_read_status`.`user_id`", core.LoggedInMemberId); } query.AddCondition("topic_item_id", ownerKey.Id); query.AddCondition("topic_item_type_id", ownerKey.TypeId); query.AddSort(SortOrder.Descending, "topic_last_post_id"); query.LimitStart = (currentPge - 1) * perPage; query.LimitCount = perPage; System.Data.Common.DbDataReader topicsReader = db.ReaderQuery(query); while(topicsReader.Read()) { ForumTopic topic = new ForumTopic(core, topicsReader); core.ItemCache.RequestItem(new ItemKey(topic.ForumId, ItemType.GetTypeId(core, typeof(Forum)))); topics.Add(topic); } topicsReader.Close(); topicsReader.Dispose(); return topics; }