public ForumTopicSummary(IDataReader reader) { lastMessageDate = reader["LastMessageDate"] == DBNull.Value ? DateTime.MinValue : (DateTime)reader["LastMessageDate"]; lastMessageID = reader["LastMessageID"] == DBNull.Value ? 0 : (long)reader["LastMessageID"]; lastMessageAuthorID = reader["LastMessageAuthorID"] == DBNull.Value ? null : (long?)reader["LastMessageAuthorID"]; lastMessageAuthorName = reader["LastMessageAuthorName"] == DBNull.Value ? null : (string)reader["LastMessageAuthorName"]; topicMessage = reader["TopicMessage"] == DBNull.Value ? null : (string)reader["TopicMessage"]; messageCount = (int)reader["MessageCount"]; rowIndex = (long)reader["RowIndex"]; topic = new ForumTopic(reader); }
private void PostTopic() { string forumStr = Request.Form["forum"]; string path = Request.Form["path"]; string notLoggedInURL = Request.Form["notLoggedInURL"]; Forum forum = DataLayer.SelectForumByURLToken(forumStr); if (forum == null) forum = DataLayer.SelectForumByCode(forumStr); if (forum == null) { WriteErrorMessage("Bad forum code"); return; } #region Check to see if the current user is allowed to post a new topic switch (forum.PostNewTopics) { case Forum.AccessType.AllowAnonymous: throw new NotImplementedException("need to put in anonymous author name."); case Forum.AccessType.ActivatedMembers: CheckAuthentication(notLoggedInURL); if (!SecurityProvider.CurrentUser.Activated) { WriteErrorMessage("You're not authenticated yet."); return; } break; case Forum.AccessType.AllMembers: CheckAuthentication(notLoggedInURL); break; case Forum.AccessType.Administrators: CheckAuthentication(notLoggedInURL); if (!SecurityProvider.CurrentUser.HasPermission(PermissionType.AdministrativeAccess)) { WriteErrorMessage("Only administrators may post new topics."); return; } break; case Forum.AccessType.RoleMembers: CheckAuthentication(notLoggedInURL); if (forum.PostWriteAccessRoleID.HasValue) { Role role = SecurityProvider.DataLayer.SelectRole(forum.PostWriteAccessRoleID.Value); if (role != null) { if (SecurityProvider.CurrentUser.HasRole(role.RoleCode)) break; } } WriteErrorMessage("You don't have the required permissions to post new topics."); return; } #endregion ForumTopic topic = new ForumTopic(); ForumTopicMessage msg = new ForumTopicMessage(); if (WebAuthentication.Instance.IsLoggedIn) { topic.AuthorUserID = SecurityProvider.CurrentUser.UserID; msg.AuthorUserID = SecurityProvider.CurrentUser.UserID; } else { throw new NotImplementedException("need to put in anonymous author name."); //topic.AuthorName = //msg.AuthorName = } topic.DateCreated = SprocketDate.Now; topic.ForumID = forum.ForumID; topic.ForumTopicID = 0; #warning to do: let administrators put in a "locked" checkbox to lock the topic by default when posting it topic.Locked = false; #warning to do: check for spam if (forum.RequireModeration) topic.Moderation = ForumModerationState.Pending; else topic.Moderation = ForumModerationState.Approved; #warning to do: should be able to make the topic sticky when posting it topic.Sticky = false; #warning to do: validate the subject. if invalid, store values in fast-expiring cookie and redirect to standalone posting page topic.Subject = Request.Form["subject"]; #warning to do: administrators should be able to specify a URL Token //topic.URLToken msg.BodySource = Request.Form["body"]; switch (forum.Markup) { case Forum.MarkupType.BBCode: #warning to do: check for images in source throw new NotImplementedException("BBCode not implemented yet."); case Forum.MarkupType.None: msg.BodyOutput = HttpUtility.HtmlEncode(msg.BodySource).Replace(Environment.NewLine, "<br />"); break; case Forum.MarkupType.Textile: #warning to do: check for images in source msg.BodyOutput = Textile.TextileFormatter.FormatString(msg.BodySource); break; case Forum.MarkupType.LimitedHTML: #warning to do: check for images in source throw new NotImplementedException("Limited HTML not implemented yet."); case Forum.MarkupType.ExtendedHTML: #warning to do: check for images in source msg.BodyOutput = WebUtility.SafeHtmlString(msg.BodySource, true); break; default: throw new NotImplementedException(); } #warning to do: signatures need to be appended to the output msg.ForumTopicMessageID = 0; msg.DateCreated = SprocketDate.Now; if (forum.RequireModeration) msg.Moderation = ForumModerationState.Pending; else { if (MightBeSpam(msg.BodySource)) { msg.Moderation = ForumModerationState.Pending; topic.Moderation = ForumModerationState.Pending; } else { msg.Moderation = ForumModerationState.Approved; } } try { using (TransactionScope scope = new TransactionScope()) { DatabaseManager.DatabaseEngine.PersistConnection(); DataLayer.Store(topic); msg.ForumTopicID = topic.ForumTopicID; DataLayer.Store(msg); scope.Complete(); } } finally { DatabaseManager.DatabaseEngine.ReleaseConnection(); } #warning to do: redirect to message rather than the forum itself. }
public ForumTopic Clone() { ForumTopic copy = new ForumTopic(); copy.forumTopicID = forumTopicID; copy.forumID = forumID; copy.authorUserID = authorUserID; copy.authorName = authorName; copy.subject = subject; copy.dateCreated = dateCreated; copy.sticky = sticky; copy.moderationState = moderationState; copy.locked = locked; copy.uRLToken = uRLToken; return copy; }