/// <summary> /// Creates the commentforumdata from a given reader /// </summary> /// <param name="reader">The database reaser</param> /// <returns>A Filled comment forum object</returns> private CommentForum CommentForumCreateFromReader(IDnaDataReader reader) { var closingDate = reader.GetDateTime("forumclosedate"); //if (closingDate == null) //{ // closingDate = DateTime.MaxValue; //} var site = SiteList.GetSite(reader.GetStringNullAsEmpty("sitename")); var commentForum = new CommentForum(); commentForum.Title = reader.GetStringNullAsEmpty("Title"); commentForum.Id = reader.GetStringNullAsEmpty("UID"); commentForum.CanRead = reader.GetByteNullAsZero("canRead") == 1; commentForum.CanWrite = reader.GetByteNullAsZero("canWrite") == 1; commentForum.ParentUri = reader.GetStringNullAsEmpty("Url"); commentForum.SiteName = reader.GetStringNullAsEmpty("sitename"); commentForum.CloseDate = closingDate; commentForum.LastUpdate = reader.GetDateTime("LastUpdated"); if (reader.GetDateTime("lastposted") > commentForum.LastUpdate) { //use last posted as it is newer commentForum.LastUpdate = reader.GetDateTime("lastposted"); } commentForum.Updated = new DateTimeHelper(commentForum.LastUpdate); commentForum.Created = new DateTimeHelper(reader.GetDateTime("DateCreated")); commentForum.commentSummary = new CommentsSummary { Total = reader.GetInt32NullAsZero("ForumPostCount"), EditorPicksTotal = reader.GetInt32NullAsZero("editorpickcount") }; commentForum.ForumID = reader.GetInt32NullAsZero("forumid"); commentForum.isClosed = !commentForum.CanWrite || site.IsEmergencyClosed || site.IsSiteScheduledClosed(DateTime.Now) || (DateTime.Now > closingDate); //MaxCharacterCount = siteList.GetSiteOptionValueInt(site.SiteID, "CommentForum", "'MaxCommentCharacterLength") var replacements = new Dictionary<string, string>(); replacements.Add("commentforumid", reader.GetStringNullAsEmpty("uid")); replacements.Add("sitename", site.SiteName); if (reader.Exists("IsContactForm") && !reader.IsDBNull("IsContactForm")) { commentForum.isContactForm = true; commentForum.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.ContactFormById, replacements); commentForum.commentSummary.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.ContactFormById, replacements); } else { commentForum.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.CommentForumById, replacements); commentForum.commentSummary.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.CommentsByCommentForumId, replacements); } //get moderation status commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Unknown; if (!reader.IsDBNull("moderationstatus")) { //if it is set for the specific forum commentForum.ModerationServiceGroup = (ModerationStatus.ForumStatus) (reader.GetTinyIntAsInt("moderationstatus")); } if (commentForum.ModerationServiceGroup == ModerationStatus.ForumStatus.Unknown) { //else fall back to site moderation status switch (site.ModerationStatus) { case ModerationStatus.SiteStatus.UnMod: commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Reactive; break; case ModerationStatus.SiteStatus.PreMod: commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.PreMod; break; case ModerationStatus.SiteStatus.PostMod: commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.PostMod; break; default: commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Reactive; break; } } commentForum.NotSignedInUserId = reader.GetInt32NullAsZero("NotSignedInUserId"); commentForum.allowNotSignedInCommenting = commentForum.NotSignedInUserId != 0; return commentForum; }
/// <summary> /// Generates the individual Comment CommentBoxForum Xml within the Comment CommentBoxForum List xml page /// </summary> /// <param name="dataReader">SP containing the comment forums</param> /// <param name="commentForumList">Parent node to attach to</param> private void AddCommentForumListXML(IDnaDataReader dataReader, XmlNode commentForumList) { // start creating the comment forum structure XmlNode commentForum = CreateElementNode("COMMENTFORUM"); AddAttribute(commentForum, "UID", dataReader.GetStringNullAsEmpty("uid")); AddAttribute(commentForum, "FORUMID", dataReader.GetInt32NullAsZero("forumID").ToString()); AddAttribute(commentForum, "FORUMPOSTCOUNT", dataReader.GetInt32NullAsZero("forumpostcount").ToString()); AddAttribute(commentForum, "FORUMPOSTLIMIT", InputContext.GetSiteOptionValueInt("Forum", "PostLimit")); AddAttribute(commentForum, "CANWRITE", dataReader.GetByteNullAsZero("CanWrite").ToString()); AddAttribute(commentForum, "NOTSIGNEDINUSERID", dataReader.GetInt32NullAsZero("NotSignedInUserID").ToString()); AddTextTag(commentForum, "HOSTPAGEURL", dataReader.GetStringNullAsEmpty("url")); AddTextTag(commentForum, "TITLE", dataReader.GetStringNullAsEmpty("title")); AddTextTag(commentForum, "MODSTATUS", dataReader.GetByteNullAsZero("ModerationStatus")); AddTextTag(commentForum, "SITEID", dataReader.GetInt32NullAsZero("siteid")); AddTextTag(commentForum, "FASTMOD", dataReader.GetInt32NullAsZero("fastmod")); if (dataReader.DoesFieldExist("DateCreated") && !dataReader.IsDBNull("DateCreated")) { DateTime dateCreated = dataReader.GetDateTime("DateCreated"); AddElement(commentForum, "DATECREATED", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, dateCreated)); } if (dataReader.DoesFieldExist("ForumCloseDate") && !dataReader.IsDBNull("ForumCloseDate")) { DateTime closeDate = dataReader.GetDateTime("ForumCloseDate"); AddElement(commentForum, "CLOSEDATE", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, closeDate)); } if (dataReader.DoesFieldExist("LastUpdated") && !dataReader.IsDBNull("LastUpdated")) { DateTime dateLastUpdated = dataReader.GetDateTime("LastUpdated"); AddElement(commentForum, "LASTUPDATED", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, dateLastUpdated)); } int forumId = dataReader.GetInt32NullAsZero("forumID"); //get terms admin object TermsFilterAdmin termsAdmin = TermsFilterAdmin.CreateForumTermAdmin(InputContext.CreateDnaDataReaderCreator(), _cache, forumId); XmlDocument termNodeDoc = SerialiseToXmlDoc(termsAdmin); string termNodeText = termNodeDoc.DocumentElement.InnerXml.ToString(); AddXmlTextTag(commentForum, "TERMS", termNodeText); commentForumList.AppendChild(commentForum); }
private MostCommentedCommentForum MostCommentedCommentForumCreateFromReader(IDnaDataReader reader) { var mostCommentedCommentForum = new MostCommentedCommentForum(); mostCommentedCommentForum.UID = reader.GetStringNullAsEmpty("Uid"); var site = SiteList.GetSite(reader.GetInt32NullAsZero("SiteID")); mostCommentedCommentForum.SiteName = (site != null) && (false == string.IsNullOrEmpty(site.SiteName)) ? site.SiteName : string.Empty; mostCommentedCommentForum.ForumId = reader.GetInt32NullAsZero("ForumID"); mostCommentedCommentForum.Url = reader.GetStringNullAsEmpty("Url"); mostCommentedCommentForum.Title = reader.GetStringNullAsEmpty("Title"); mostCommentedCommentForum.CanWrite = reader.GetByteNullAsZero("CanWrite") == 1; mostCommentedCommentForum.ForumPostCount = reader.GetInt32NullAsZero("ForumPostCount"); mostCommentedCommentForum.DateCreated = reader.GetDateTime("DateCreated"); mostCommentedCommentForum.ForumCloseDate = reader.GetDateTime("ForumCloseDate"); mostCommentedCommentForum.CommentForumListCount = reader.GetInt32NullAsZero("CommentForumListCount"); mostCommentedCommentForum.LastPosted = reader.GetDateTime("LastPosted"); return mostCommentedCommentForum; }
private static Contribution CreateContributionInternal(IDnaDataReader reader) { Contribution contribution = new Contribution(); // Make sure we got something back if (reader.HasRows && reader.Read()) { contribution.Body = reader.GetStringNullAsEmpty("Body"); contribution.PostIndex = reader.GetLongNullAsZero("PostIndex"); contribution.SiteName = reader.GetStringNullAsEmpty("SiteName"); contribution.SiteType = (SiteType)Enum.Parse(typeof(SiteType), reader.GetStringNullAsEmpty("SiteType")); contribution.SiteDescription = reader.GetStringNullAsEmpty("SiteDescription"); contribution.SiteUrl = reader.GetStringNullAsEmpty("UrlName"); contribution.FirstSubject = reader.GetStringNullAsEmpty("FirstSubject"); contribution.Subject = reader.GetStringNullAsEmpty("Subject"); contribution.Timestamp = new DateTimeHelper(reader.GetDateTime("TimeStamp")); contribution.Title = reader.GetStringNullAsEmpty("ForumTitle"); contribution.ThreadEntryID = reader.GetInt32("ThreadEntryID"); contribution.CommentForumUrl = reader.GetStringNullAsEmpty("CommentForumUrl"); contribution.GuideEntrySubject = reader.GetStringNullAsEmpty("GuideEntrySubject"); contribution.TotalPostsOnForum = reader.GetInt32NullAsZero("TotalPostsOnForum"); contribution.AuthorUserId = reader.GetInt32NullAsZero("AuthorUserId"); contribution.AuthorUsername = reader.GetStringNullAsEmpty("AuthorUsername"); contribution.AuthorIdentityUsername = reader.GetStringNullAsEmpty("AuthorIdentityUsername"); bool forumCanWrite = reader.GetByteNullAsZero("ForumCanWrite") == 1; bool isEmergencyClosed = reader.GetInt32NullAsZero("SiteEmergencyClosed") == 1; //bool isSiteScheduledClosed = reader2.GetByteNullAsZero("SiteScheduledClosed") == 1; DateTime closingDate = DateTime.MaxValue; if (reader.DoesFieldExist("forumclosedate") && !reader.IsDBNull("forumclosedate")) { closingDate = reader.GetDateTime("forumclosedate"); contribution.ForumCloseDate = new DateTimeHelper(closingDate); } contribution.isClosed = (!forumCanWrite || isEmergencyClosed || (closingDate != null && DateTime.Now > closingDate)); } else { throw ApiException.GetError(ErrorType.ThreadPostNotFound); } return contribution; }
private void AddCommentForumListXML(IDnaDataReader dataReader, XmlNode commentForumList) { // start creating the comment forum structure XmlNode commentForum = CreateElementNode("COMMENTFORUM"); AddAttribute(commentForum, "UID", dataReader.GetStringNullAsEmpty("uid")); AddAttribute(commentForum, "FORUMID", dataReader.GetInt32NullAsZero("forumID").ToString()); AddAttribute(commentForum, "FORUMPOSTCOUNT", dataReader.GetInt32NullAsZero("forumpostcount").ToString()); AddAttribute(commentForum, "FORUMPOSTLIMIT", InputContext.GetSiteOptionValueInt("Forum", "PostLimit")); AddAttribute(commentForum, "CANWRITE", dataReader.GetByteNullAsZero("CanWrite").ToString()); AddAttribute(commentForum, "NOTSIGNEDINUSERID", dataReader.GetInt32NullAsZero("NotSignedInUserID").ToString()); AddTextTag(commentForum, "HOSTPAGEURL", dataReader.GetStringNullAsEmpty("url")); AddTextTag(commentForum, "TITLE", dataReader.GetStringNullAsEmpty("title")); AddTextTag(commentForum, "MODSTATUS", dataReader.GetByteNullAsZero("ModerationStatus")); AddTextTag(commentForum, "SITEID", dataReader.GetInt32NullAsZero("siteid")); AddTextTag(commentForum, "FASTMOD", dataReader.GetInt32NullAsZero("fastmod")); AddTextTag(commentForum, "CONTACTEMAIL", dataReader.GetStringNullAsEmpty("encryptedcontactemail")); if (dataReader.DoesFieldExist("DateCreated") && !dataReader.IsDBNull("DateCreated")) { DateTime dateCreated = dataReader.GetDateTime("DateCreated"); AddElement(commentForum, "DATECREATED", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, dateCreated)); } if (dataReader.DoesFieldExist("ForumCloseDate") && !dataReader.IsDBNull("ForumCloseDate")) { DateTime closeDate = dataReader.GetDateTime("ForumCloseDate"); AddElement(commentForum, "CLOSEDATE", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, closeDate)); } if (dataReader.DoesFieldExist("LastUpdated") && !dataReader.IsDBNull("LastUpdated")) { DateTime dateLastUpdated = dataReader.GetDateTime("LastUpdated"); AddElement(commentForum, "LASTUPDATED", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, dateLastUpdated)); } int forumId = dataReader.GetInt32NullAsZero("forumID"); AddXmlTextTag(commentForum, "TERMS", ""); commentForumList.AppendChild(commentForum); }
/// <summary> /// Creates the XML fragment for the CommentBoxForum Thread Posts /// </summary> /// <param name="uid">The unique identifier for the Comment CommentBoxForum</param> /// <param name="fromPostIndex">Start Post Index</param> /// <param name="toPostIndex">Finish Post Index</param> /// <param name="dataReader">Dna Data Reader object</param> /// <param name="show">Number of Posts requested</param> /// <param name="forumPostCount">Total number of Posts</param> /// <param name="parent">Parent node of FORUMTHREADPOSTS element.</param> /// <returns>Actual number of posts returned</returns> private int CreateForumThreadPosts(string uid, int fromPostIndex, int toPostIndex, IDnaDataReader dataReader, int show, int forumPostCount, XmlNode parent) { XmlNode forumPosts = CreateElementNode("FORUMTHREADPOSTS"); AddAttribute(forumPosts, "GUESTBOOK", "1"); AddAttribute(forumPosts, "FORUMID", dataReader.GetInt32NullAsZero("forumID").ToString()); AddAttribute(forumPosts, "ALERTINSTANTLY", dataReader.GetInt32NullAsZero("alertInstantly").ToString()); int returnedFrom = dataReader.GetInt32NullAsZero("from"); if (returnedFrom < 0) { returnedFrom = 0; } int returnedTo = dataReader.GetInt32NullAsZero("to"); AddAttribute(forumPosts, "FROM", returnedFrom.ToString()); AddAttribute(forumPosts, "TO", returnedTo.ToString()); AddAttribute(forumPosts, "SHOW", show.ToString()); AddAttribute(forumPosts, "FORUMPOSTCOUNT", forumPostCount.ToString()); AddAttribute(forumPosts, "FORUMPOSTLIMIT", InputContext.GetSiteOptionValueInt("Forum", "PostLimit")); AddAttribute(forumPosts, "SITEID", dataReader.GetInt32NullAsZero("siteID").ToString()); AddAttribute(forumPosts, "CANREAD", dataReader.GetByteNullAsZero("ForumCanRead").ToString()); AddAttribute(forumPosts, "CANWRITE", dataReader.GetByteNullAsZero("ForumCanWrite").ToString()); AddAttribute(forumPosts, "DEFAULTCANREAD", dataReader.GetByteNullAsZero("ForumCanRead").ToString()); AddAttribute(forumPosts, "DEFAULTCANWRITE", dataReader.GetByteNullAsZero("ForumCanWrite").ToString()); AddAttribute(forumPosts, "UID", uid); string hostpageurl = dataReader.GetStringNullAsEmpty("URL"); hostpageurl = StringUtils.EscapeAllXml(hostpageurl); AddAttribute(forumPosts, "HOSTPAGEURL", hostpageurl); byte moderationStatus = dataReader.GetByteNullAsZero("moderationStatus"); AddAttribute(forumPosts, "MODERATIONSTATUS", moderationStatus.ToString()); //Worked out the number of posts from the returned to and from int returnedCount = (returnedTo - returnedFrom) + 1; int actualPostCount = 0; if (forumPostCount > 0) { do { ForumPost.AddPostXml(dataReader, this, forumPosts, InputContext); actualPostCount++; returnedCount--; } while (returnedCount > 0 && dataReader.Read()); } parent.AppendChild(forumPosts); return actualPostCount; }
/// <summary> /// Method to generate POST XML and add to a parent node /// </summary> /// <param name="reader">DataReader result of stored procedure returning forum post data.</param> /// <param name="component">DnaComponent to add posts to.</param> /// <param name="parentNode">Parent Node to xml the generated xml to.</param> /// <param name="context">The Input Context</param> public static void AddPostXml(IDnaDataReader reader, DnaComponent component, XmlNode parentNode, IInputContext context) { int hidden = 0; int inReplyTo = 0; int prevSibling = 0; int nextSibling = 0; int firstChild = 0; int userID = 0; int entryId = 0; int threadId = 0; int postIndex = 0; string subject = String.Empty; string datePosted = String.Empty; string bodyText = String.Empty; string hostPageUrl = String.Empty; string commentForumTitle = String.Empty; //get from db if (reader.DoesFieldExist("parent")) { inReplyTo = reader.GetInt32NullAsZero("parent"); } if (reader.DoesFieldExist("prevSibling")) { prevSibling = reader.GetInt32NullAsZero("prevSibling"); } if (reader.DoesFieldExist("nextSibling")) { nextSibling = reader.GetInt32NullAsZero("nextSibling"); } if (reader.DoesFieldExist("firstChild")) { firstChild = reader.GetInt32NullAsZero("firstChild"); } if (reader.DoesFieldExist("userID")) { userID = reader.GetInt32NullAsZero("userID"); } if (reader.DoesFieldExist("hidden")) { hidden = reader.GetInt32NullAsZero("hidden"); } subject = String.Empty; if (hidden == 3) // 3 means premoderated! - hidden! { subject = "Hidden"; } else if (hidden > 0) { subject = "Removed"; } else { subject = reader["subject"] as string; subject = StringUtils.EscapeAllXml(subject); } datePosted = String.Empty; if (reader["datePosted"] != DBNull.Value) { datePosted = reader["datePosted"].ToString(); } bodyText = String.Empty; if (hidden == 3) // 3 means premoderated! - hidden! { bodyText = "This post has been hidden"; } else if (hidden > 0) { bodyText = "This post has been Removed"; } else { bodyText = reader.GetStringNullAsEmpty("text"); } byte postStyle = reader.GetByteNullAsZero("postStyle"); if (postStyle != 1) { bodyText = StringUtils.ConvertPlainText(bodyText); } else { //TODO Do we need Rich Post stuff for the post style?? string temp = "<RICHPOST>" + bodyText.Replace("\r\n", "<BR />").Replace("\n", "<BR />") + "</RICHPOST>"; //Regex regex = new Regex(@"(<[^<>]+)<BR \/>"); //while (regex.Match(temp).Success) //{ // temp = regex.Replace(temp,@"$1 "); //} //bodyText = temp; bodyText = HtmlUtils.TryParseToValidHtml(temp); } if (reader.DoesFieldExist("hostpageurl")) { hostPageUrl = reader.GetStringNullAsEmpty("hostpageurl"); } if (reader.DoesFieldExist("commentforumtitle")) { commentForumTitle = reader.GetStringNullAsEmpty("commentforumtitle"); } if (reader.DoesFieldExist("entryID")) { entryId = reader.GetInt32NullAsZero("entryID"); } if (reader.DoesFieldExist("threadID")) { threadId = reader.GetInt32NullAsZero("threadID"); } if (reader.DoesFieldExist("postindex")) { postIndex = reader.GetInt32NullAsZero("postindex"); } string canRead = String.Empty; if (reader.DoesFieldExist("canRead")) { canRead = reader.GetByteNullAsZero("canRead").ToString(); } string canWrite = String.Empty; if (reader.DoesFieldExist("canWrite")) { canWrite = reader.GetByteNullAsZero("canWrite").ToString(); } XmlNode post = component.CreateElementNode("POST"); User user = new User(context); user.AddUserXMLBlock(reader, userID, post); AddPostXmlInternal(component, parentNode, context, hidden, inReplyTo, prevSibling, nextSibling, firstChild, userID, subject, datePosted, bodyText, hostPageUrl, commentForumTitle, entryId, threadId, postIndex, canRead, canWrite, post.ChildNodes[0]); }
/// <summary> /// Creates a threadpost from a given reader /// </summary> /// <param name="reader"></param> /// <param name="prefix">The data base name prefix</param> /// <param name="postId">postId to get</param> /// <param name="post">The post in question to load with data</param> /// <param name="applySkin">Whether we need to process the text into html for output</param> /// <returns></returns> static public ThreadPost CreateThreadPostFromReader(IDnaDataReader reader, string prefix, int postId, ThreadPost post, bool applySkin) { if (post == null) { post = new ThreadPost() { PostId = postId }; } if (reader.DoesFieldExist(prefix +"threadid")) { post.ThreadId = reader.GetInt32NullAsZero(prefix +"threadid"); } if (reader.DoesFieldExist(prefix +"parent")) { post.InReplyTo = reader.GetInt32NullAsZero(prefix +"parent"); } if (reader.DoesFieldExist(prefix +"replypostindex")) { post.InReplyToIndex = reader.GetInt32NullAsZero(prefix + "replypostindex"); } if (reader.DoesFieldExist(prefix +"postindex")) { post.Index = reader.GetInt32NullAsZero(prefix + "postindex"); } if (reader.DoesFieldExist(prefix +"prevSibling")) { post.PrevSibling = reader.GetInt32NullAsZero(prefix +"prevSibling"); } if (reader.DoesFieldExist(prefix +"nextSibling")) { post.NextSibling = reader.GetInt32NullAsZero(prefix +"nextSibling"); } if (reader.DoesFieldExist(prefix +"firstChild")) { post.FirstChild = reader.GetInt32NullAsZero(prefix +"firstChild"); } if (reader.DoesFieldExist(prefix +"hidden")) { post.Hidden = (byte)reader.GetInt32NullAsZero(prefix +"hidden"); } if (reader.DoesFieldExist(prefix +"subject")) { post.Subject = FormatSubject(reader.GetStringNullAsEmpty("subject"), (CommentStatus.Hidden)post.Hidden); } if (reader.DoesFieldExist(prefix + "datePosted") && reader[prefix + "datePosted"] != DBNull.Value) { post.DatePosted = new DateElement(reader.GetDateTime(prefix + "datePosted".ToString())); } if (reader.DoesFieldExist(prefix +"postStyle")) { post.Style = (PostStyle.Style)reader.GetByteNullAsZero(prefix + "postStyle"); } if (reader.DoesFieldExist(prefix +"text")) { post.Text = ThreadPost.FormatPost(reader.GetStringNullAsEmpty(prefix + "text"), (CommentStatus.Hidden)post.Hidden, true, applySkin); } if (reader.DoesFieldExist(prefix +"hostpageurl")) { post.HostPageUrl = reader.GetStringNullAsEmpty(prefix + "hostpageurl"); } if (reader.DoesFieldExist(prefix +"commentforumtitle")) { post.CommentForumTitle = reader.GetStringNullAsEmpty(prefix + "commentforumtitle"); } post.User = BBC.Dna.Objects.User.CreateUserFromReader(reader); #region Depreciated code /* * This code has been depreciated from forum.cpp ln 1066 as the functionality is no longer in use. // Add the event date if it has one! bOk = bOk && AddDBXMLDateTag("eventdate",NULL,false,true); // Get the Type of post we're looking at bOk = bOk && AddDBXMLTag("type",NULL,false,true,&sPostType); // Now see if we are an event or notice, if so put the taginfo in for the post if (sPostType.CompareText("Notice") || sPostType.CompareText("Event")) { // We've got a notice or event! Get all the tag info CTagItem TagItem(m_InputContext); if (TagItem.InitialiseFromThreadId(ThreadID,m_SiteID,pViewer) && TagItem.GetAllNodesTaggedForItem()) { TagItem.GetAsString(sPosts); } } */ #endregion return post; }