public void ApproveUnApprove(int approve) { bool bApproved = false; for (int i = 0; i < gvItems.Rows.Count; i++) { CheckBox cb = gvItems.Rows[i].FindControl("cb") as CheckBox; if (cb.Checked) { int iCommentID = 0; Literal literal = gvItems.Rows[i].FindControl("CommentID") as Literal; if (literal != null) { int.TryParse(literal.Text, out iCommentID); } BSComment bsComment = BSComment.GetComment(iCommentID); if (bsComment != null) { bApproved = bsComment.DoApprove(approve == 1); } } } if (bApproved) { MessageBox1.Message = approve == 1 ? Language.Admin["SelectedApproved"] : Language.Admin["SelectedUnApproved"]; MessageBox1.Type = MessageBox.ShowType.Information; MessageBox1.Visible = true; } }
void Comment_Approved(object sender, EventArgs e) { BSComment bsComment = (BSComment)sender; if (bsComment.Approve) { using (DataProcess dp = new DataProcess()) { dp.AddParameter("PostID", bsComment.PostID); dp.AddParameter("NotifyMe", true); dp.AddParameter("Approve", true); dp.ExecuteReader("SELECT DISTINCT Email FROM Comments WHERE PostID=@PostID AND NotifyMe=@NotifyMe AND Approve=@Approve"); if (dp.Return.Status == DataProcessState.Success) { BSPost bsPost = BSPost.GetPost(bsComment.PostID); using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr.Read()) { string strEmail = (string)dr["Email"]; System.Threading.ThreadPool.QueueUserWorkItem(delegate { BSHelper.SendMail(Language.Get["NewCommentNotice"], Blogsa.Settings["smtp_email"].ToString(), Blogsa.Settings["smtp_name"].ToString() , strEmail, "", Language.Get["NewCommentNoticeDescription"] + "<br><br><a href=\"" + bsPost.Link + "\">" + bsPost.Title + "</a>", true); }); } } } } } }
static void FillComment(IDataReader dr, BSComment bsComment) { bsComment.CommentID = Convert.ToInt32(dr["CommentID"]); bsComment.Content = dr["Comment"].ToString(); bsComment.Date = Convert.ToDateTime(dr["CreateDate"]); bsComment.Email = dr["EMail"].ToString(); bsComment.GravatarLink = BSHelper.GetGravatar(bsComment.Email); bsComment.IP = dr["IP"].ToString(); bsComment.PostID = Convert.ToInt32(dr["PostID"]); bsComment.UserID = Convert.ToInt32(dr["UserID"]); bsComment.UserName = dr["Name"].ToString(); bsComment.WebPage = dr["WebPage"].ToString(); bsComment.Approve = Convert.ToBoolean(dr["Approve"]); if (bsComment.UserID != 0) { BSUser user = BSUser.GetUser(bsComment.UserID); if (user != null) { bsComment.UserName = user.Name; bsComment.WebPage = user.WebPage; bsComment.Email = user.Email; bsComment.IsAdmin = user.Role.Equals("admin"); } } }
public static List <BSComment> GetComments(CommentStates state, int iCommentCount) { List <BSComment> comments = new List <BSComment>(); using (DataProcess dp = new DataProcess()) { string top = iCommentCount == 0 ? String.Empty : "TOP " + iCommentCount; if (state == CommentStates.All) { dp.ExecuteReader(String.Format("SELECT {0} * FROM Comments ORDER By CreateDate DESC", top)); } else { dp.AddParameter("Approve", state == CommentStates.Approved); dp.ExecuteReader(String.Format("SELECT {0} * FROM Comments WHERE [Approve]=@Approve ORDER By CreateDate DESC", top)); } if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSComment bsComment = new BSComment(); FillComment(dr, bsComment); comments.Add(bsComment); } } } } return(comments); }
public static void OnDeleting(BSComment BsComment, CancelEventArgs e) { if (Deleting != null) { Deleting(BsComment, e); } }
protected void btnDelete_Click(object sender, EventArgs e) { bool bRemoved = false; for (int i = 0; i < gvItems.Rows.Count; i++) { CheckBox cb = gvItems.Rows[i].FindControl("cb") as CheckBox; if (cb.Checked) { int iCommentID = 0; Literal literal = gvItems.Rows[i].FindControl("CommentID") as Literal; if (literal != null) { int.TryParse(literal.Text, out iCommentID); } BSComment bsComment = BSComment.GetComment(iCommentID); if (bsComment != null) { bRemoved = bsComment.Remove(); } } } if (bRemoved) { MessageBox1.Message = Language.Admin["CommentDeleted"]; MessageBox1.Type = MessageBox.ShowType.Information; MessageBox1.Visible = true; gvItems.DataBind(); } }
public static void OnSaving(BSComment BsComment, CancelEventArgs e) { if (Saving != null) { Saving(BsComment, e); } }
public static void OnSaved(BSComment BsComment, EventArgs e) { if (Saved != null) { Saved(BsComment, e); } }
public static void OnApproved(BSComment BsComment, EventArgs e) { if (Approved != null) { Approved(BsComment, e); } }
public static void OnApproving(BSComment BsComment, CancelEventArgs e) { if (Approving != null) { Approving(BsComment, e); } }
public static List <BSComment> GetCommentsByUserID(int iUserID, CommentStates state) { List <BSComment> comments = new List <BSComment>(); using (DataProcess dp = new DataProcess()) { if (state == CommentStates.All) { dp.AddParameter("UserID", iUserID); dp.ExecuteReader("SELECT * FROM Comments WHERE [UserID]=@UserID ORDER By CreateDate DESC"); } else { dp.AddParameter("UserID", iUserID); dp.AddParameter("Approve", state == CommentStates.Approved); dp.ExecuteReader("SELECT * FROM Comments WHERE [UserID]=@UserID AND [Approve]=@Approve ORDER By CreateDate DESC"); } if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSComment bsComment = new BSComment(); FillComment(dr, bsComment); comments.Add(bsComment); } } } } return(comments); }
public static void OnDeleted(BSComment BsComment, EventArgs e) { if (Deleted != null) { Deleted(BsComment, e); } }
protected void Page_Load(object sender, EventArgs e) { rpLastComments.DataSource = BSComment.GetComments(CommentStates.All, 5); rpLastComments.DataBind(); if (rpLastComments.Items.Count == 0) { ltNoData.Text = Language.Admin["CommentNotFound"]; } }
void Comment_Showing(object sender, System.ComponentModel.CancelEventArgs e) { BSComment bsComment = (BSComment)sender; #region Find Url string urlPattern = @"\b([\d\w\.\/\+\-\?\:]*)((ht|f)tp(s|)\:\/\/|[\d\d\d|\d\d]\.[\d\d\d|\d\d]\.|www\.|\.tv|\.ac|\.com|\.edu|\.gov|\.int|\.mil|\.net|\.org|\.biz|\.info|\.name|\.pro|\.museum|\.co)([\d\w\.\/\%\+\-\=\&\?\:\\\"\'\,\|\~\;]*)\b"; Regex RegExp = new Regex(urlPattern, RegexOptions.Compiled); foreach (Match val in RegExp.Matches(bsComment.Content)) { bsComment.Content = bsComment.Content.Replace(val.Value, "<a href=\"" + val.Value + "\">" + val.Value + "</a>"); } #endregion }
protected void gvItems_DataBinding(object sender, EventArgs e) { string postID = Request["PostID"]; int iPostID = 0; int.TryParse(postID, out iPostID); if (iPostID != 0) { ((GridView)sender).DataSource = BSComment.GetCommentsByPostID(iPostID, CommentStates.All); } else { ((GridView)sender).DataSource = BSComment.GetComments(CommentStates.All); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string commentID = Request["CommentID"]; int iCommentID = 0; int.TryParse(commentID, out iCommentID); if (iCommentID > 0) { divComments.Visible = false; divEditComment.Visible = true; divSideEditComment.Visible = true; BSComment bsComment = BSComment.GetComment(iCommentID); txtName.Text = bsComment.UserName; txtWebSite.Text = bsComment.WebPage; txtComment.Text = bsComment.Content; txtEMail.Text = bsComment.Email; ltIP.Text = bsComment.IP; rblState.SelectedValue = bsComment.Approve ? "1" : "0"; ltCommentedPost.Text = BSPost.GetPost(bsComment.PostID).LinkedTitle; // DateTime txtDateDay.Text = bsComment.Date.Day.ToString("00"); txtDateMonth.Text = bsComment.Date.Month.ToString("00"); txtDateYear.Text = bsComment.Date.Year.ToString("0000"); txtTimeHour.Text = bsComment.Date.Hour.ToString("00"); txtTimeMinute.Text = bsComment.Date.Minute.ToString("00"); txtTimeSecond.Text = bsComment.Date.Second.ToString("00"); } else { divComments.Visible = true; divEditComment.Visible = false; divSideEditComment.Visible = false; gvItems.DataBind(); } } btnDelete.OnClientClick = "return confirm('" + Language.Admin["CommentDeleteConfirm"] + "');"; }
public static void Delete(int iCommentID) { CancelEventArgs eventArgs = new CancelEventArgs(); BSComment bsComment = GetComment(iCommentID); BSComment.OnDeleting(bsComment, eventArgs); if (!eventArgs.Cancel) { using (DataProcess dp = new DataProcess()) { dp.AddParameter("CommentID", iCommentID); dp.ExecuteReader("DELETE FROM Comments WHERE [CommentID]=@CommentID"); if (dp.Return.Status == DataProcessState.Success) { BSComment.OnDeleted(bsComment, EventArgs.Empty); } } } }
public static BSComment GetComment(int iCommentID) { using (DataProcess dp = new DataProcess()) { dp.AddParameter("CommentID", iCommentID); dp.ExecuteReader("SELECT * FROM Comments WHERE [CommentID]=@CommentID"); if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { if (dr != null && dr.Read()) { BSComment bsComment = new BSComment(); FillComment(dr, bsComment); return(bsComment); } } } } return(null); }
protected void btnSavePost_Click(object sender, EventArgs e) { try { int iCommentID = 0; int.TryParse(Request["CommentID"], out iCommentID); BSComment bsComment = BSComment.GetComment(iCommentID); bsComment.UserName = txtName.Text; bsComment.Content = txtComment.Text; bsComment.Email = txtEMail.Text; bsComment.WebPage = txtWebSite.Text; bsComment.Date = new DateTime( Convert.ToInt16(txtDateYear.Text), Convert.ToInt16(txtDateMonth.Text), Convert.ToInt16(txtDateDay.Text), Convert.ToInt16(txtTimeHour.Text), Convert.ToInt16(txtTimeMinute.Text), Convert.ToInt16(txtTimeSecond.Text)); bsComment.Approve = rblState.SelectedValue.Equals("1"); if (bsComment.Save()) { MessageBox1.Message = Language.Admin["CommentSaved"]; MessageBox1.Type = MessageBox.ShowType.Information; } else { MessageBox1.Message = "Error"; MessageBox1.Type = MessageBox.ShowType.Error; } } catch (System.Exception ex) { MessageBox1.Message = ex.Message; MessageBox1.Type = MessageBox.ShowType.Error; } }
public override void DataBind() { if (Page.User.IsInRole("admin")) { Comment.Content += "<div class=\"post-edit-box\">" + "<a href=\"" + ResolveUrl("~/Admin/Comments.aspx?CommentID=" + Comment.CommentID) + "\">" + Language.Get["Edit"] + "</a>" + "<a id=\"comment_delete_" + Comment.CommentID + "\" href=\"javascript:;\" onclick=\"Blogsa.DeleteComment(this," + Comment.CommentID + ");\">" + Language.Get["Delete"] + "</a>" + "<a id=\"comment_approve_" + Comment.CommentID + "\" href=\"javascript:;\" " + (!Comment.Approve ? "style=\"display:none;\"" : "") + " onclick=\"Blogsa.CommentApprove(this," + Comment.CommentID + ");\">" + Language.Get["Approve"] + "</a>" + "<a id=\"comment_unapprove_" + Comment.CommentID + "\" href=\"javascript:;\" " + (Comment.Approve ? "style=\"display:none;\"" : "") + " onclick=\"Blogsa.CommentUnApprove(this," + Comment.CommentID + ");\">" + Language.Get["UnApprove"] + "</a>" + "<span></span>" + "</div>"; } CancelEventArgs eventArgs = new CancelEventArgs(); BSComment.OnShowing(this.Comment, eventArgs); if (!eventArgs.Cancel) { base.DataBind(); BSComment.OnShowed(this.Comment, EventArgs.Empty); } }
public bool DoApprove(bool bApprove) { CancelEventArgs eventArgs = new CancelEventArgs(); BSComment bsComment = GetComment(CommentID); OnApproving(bsComment, eventArgs); if (!eventArgs.Cancel) { using (DataProcess dp = new DataProcess()) { dp.AddParameter("Approve", bApprove); dp.AddParameter("CommentID", CommentID); dp.ExecuteNonQuery("UPDATE Comments SET [Approve]=@Approve WHERE [CommentID]=@CommentID"); if (dp.Return.Status == DataProcessState.Success) { bsComment.Approve = bApprove; OnApproved(bsComment, null); return(true); } } } return(false); }
private static void FillMenu(IDataReader dr, BSMenu menu) { menu.Description = (string)dr["Description"]; menu.MenuGroupID = (int)dr["MenuGroupID"]; menu.MenuID = (int)dr["MenuID"]; menu.MenuType = (MenuTypes)dr["MenuType"]; menu.ObjectID = (int)dr["ObjectID"]; menu.ObjectType = (ObjectTypes)dr["ObjectType"]; menu.ParentID = (int)dr["ParentID"]; menu.Sort = (short)dr["Sort"]; menu.Target = (string)dr["Target"]; menu.Title = (string)dr["Title"]; menu.Url = (string)dr["Url"]; if (menu.Url.StartsWith("~/")) { menu.Url = Blogsa.Url + menu.Url.Substring(2); } switch (menu.ObjectType) { case ObjectTypes.Article: BSPost article = BSPost.GetPost(menu.ObjectID); if (article != null) { menu.Title = article.Title; menu.Url = article.Link; } break; case ObjectTypes.Page: BSPost page = BSPost.GetPost(menu.ObjectID); if (page != null) { menu.Title = page.Title; menu.Url = page.Link; } break; case ObjectTypes.File: BSPost file = BSPost.GetPost(menu.ObjectID); if (file != null) { menu.Title = file.Title; menu.Url = file.Link; } break; case ObjectTypes.Link: BSLink link = BSLink.GetLink(menu.ObjectID); if (link != null) { menu.Title = link.Name; menu.Url = link.Url; } break; case ObjectTypes.Term: BSTerm term = BSTerm.GetTerm(menu.ObjectID); if (term != null) { menu.Title = term.Name; menu.Url = term.Link; } break; case ObjectTypes.Comment: BSComment comment = BSComment.GetComment(menu.ObjectID); if (comment != null) { menu.Title = comment.Content; menu.Url = comment.Link; } break; default: break; } }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid || Session["ActiveUser"] != null) { TextBox txtSecurityCode = this.FindControl("txtSecurityCode") as TextBox; TextBox txtEmail = this.FindControl("txtEmail") as TextBox; TextBox txtWebSite = this.FindControl("txtWebSite") as TextBox; TextBox txtName = this.FindControl("txtName") as TextBox; TextBox txtComment = this.FindControl("txtComment") as TextBox; Literal ltInfo = this.FindControl("ltInfo") as Literal; CheckBox cbxNotifyMe = this.FindControl("cbxNotifyMe") as CheckBox; if (txtSecurityCode.Text.Equals(Session["SecurityCode" + BSPost.CurrentPost.PostID])) { BSComment bsComment = new BSComment(); bsComment.UserName = Server.HtmlEncode(txtName.Text); bsComment.Email = txtEmail.Text; bsComment.Content = BSHelper.GetEncodedHtml(txtComment.Text, true); bsComment.IP = HttpContext.Current.Request.UserHostAddress; if (cbxNotifyMe != null) { bsComment.NotifyMe = cbxNotifyMe.Checked; } bsComment.WebPage = txtWebSite.Text; bsComment.Date = DateTime.Now; bsComment.PostID = BSPost.CurrentPost.PostID; bool approve; bool.TryParse(Blogsa.Settings["add_comment_approve"].Value, out approve); bsComment.Approve = approve; if (Blogsa.ActiveUser != null) { bsComment.UserID = Blogsa.ActiveUser.UserID; bsComment.UserName = Blogsa.ActiveUser.Name; bsComment.Email = Blogsa.ActiveUser.Email; bsComment.Approve = HttpContext.Current.User.IsInRole("admin"); } if (bsComment.Save()) { if (Convert.ToBoolean(Blogsa.Settings["comment_sendmail"].Value) && ((Blogsa.ActiveUser != null && Blogsa.ActiveUser.UserID != bsComment.UserID) || Blogsa.ActiveUser == null)) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { BSHelper.SendMail(Language.Get["YouHaveNewComment"], Blogsa.Settings["smtp_email"].ToString(), Blogsa.Settings["smtp_name"].ToString(), Blogsa.Settings["smtp_email"].ToString(), Blogsa.Settings["smtp_name"].ToString(), string.Format(Language.Get["CommentMailContent"], "<b>" + bsComment.UserName + "</b>", "<b><a href=\"" + BSPost.CurrentPost.Link + "\">" + BSPost.CurrentPost.Title + "</a></b>", "<b>" + BSPost.CurrentPost.CommentCount + "</b>"), true); }); } if (bsComment.Approve) Response.Redirect(BSPost.CurrentPost.Link + "#Comment" + bsComment.CommentID); else { Session["WaitApprove"] = "OK"; Response.Redirect(BSPost.CurrentPost.Link + "#WriteComment"); } } else { ltInfo.Text = "Comment Save Error"; } } else { ltInfo.Text = Language.Get["YourSecurityCodeWrong"]; } } }
public static void OnShowing(BSComment BsComment, CancelEventArgs e) { if (Showing != null) { Showing(BsComment, e); } }
public static void OnShowed(BSComment BsComment, EventArgs e) { if (Showed != null) { Showed(BsComment, e); } }
// Call RSS public static void GetRSS(Page page, RssTypes type) { XmlTextWriter writer = new XmlTextWriter(page.Response.OutputStream, System.Text.Encoding.UTF8); WriteRSSPrologue(writer, type); List <BSPost> posts = new List <BSPost>(); int intFeedCount = Blogsa.Settings["show_feed_count"] != null?Convert.ToInt32(Blogsa.Settings["show_feed_count"]) : 10; if (type == RssTypes.Comments) { List <BSComment> comments = BSComment.GetComments(CommentStates.Approved); if (comments.Count > 0) { foreach (BSComment comment in comments) { BSPost bsPost = BSPost.GetPost(comment.PostID); AddRSSItem(writer, bsPost.Title, bsPost.Link + "#Comments" + comment.CommentID, comment.Content, comment.Date.ToString("EEE, dd MMMM yyyy HH:mm:ss Z"), comment.UserName); } WriteRSSClosing(writer); writer.Flush(); writer.Close(); page.Response.ContentEncoding = System.Text.Encoding.UTF8; page.Response.ContentType = "text/xml"; page.Response.Cache.SetCacheability(HttpCacheability.NoCache); page.Response.End(); } } else if (type == RssTypes.CommentsByPost) { List <BSComment> comments = BSComment.GetCommentsByPostID(Convert.ToInt32(HttpContext.Current.Request["PostID"]), CommentStates.Approved); if (comments.Count > 0) { BSPost bsPost = BSPost.GetPost(Convert.ToInt32(HttpContext.Current.Request["PostID"])); foreach (BSComment comment in comments) { AddRSSItem(writer, bsPost.Title, bsPost.Link + "#Comments" + comment.CommentID, comment.Content, comment.Date.ToString("EEE, dd MMMM yyyy HH:mm:ss Z"), comment.UserName); } WriteRSSClosing(writer); writer.Flush(); writer.Close(); page.Response.ContentEncoding = System.Text.Encoding.UTF8; page.Response.ContentType = "text/xml"; page.Response.Cache.SetCacheability(HttpCacheability.NoCache); page.Response.End(); } } else if (type == RssTypes.Posts) { posts = BSPost.GetPosts(PostTypes.Article, PostStates.Published, 10); if (posts.Count > 0) { foreach (BSPost post in posts) { AddRSSItem(writer, post.Title, post.Link, post.Content, post.Date.ToString("EEE, dd MMMM yyyy HH:mm:ss Z"), post.UserName); } WriteRSSClosing(writer); writer.Flush(); writer.Close(); page.Response.ContentEncoding = System.Text.Encoding.UTF8; page.Response.ContentType = "text/xml"; page.Response.Cache.SetCacheability(HttpCacheability.NoCache); page.Response.End(); } } }
public static List<BSComment> GetCommentsByUserID(int iUserID, CommentStates state) { List<BSComment> comments = new List<BSComment>(); using (DataProcess dp = new DataProcess()) { if (state == CommentStates.All) { dp.AddParameter("UserID", iUserID); dp.ExecuteReader("SELECT * FROM Comments WHERE [UserID]=@UserID ORDER By CreateDate DESC"); } else { dp.AddParameter("UserID", iUserID); dp.AddParameter("Approve", state == CommentStates.Approved); dp.ExecuteReader("SELECT * FROM Comments WHERE [UserID]=@UserID AND [Approve]=@Approve ORDER By CreateDate DESC"); } if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSComment bsComment = new BSComment(); FillComment(dr, bsComment); comments.Add(bsComment); } } } } return comments; }
public static List<BSComment> GetComments(CommentStates state, int iCommentCount) { List<BSComment> comments = new List<BSComment>(); using (DataProcess dp = new DataProcess()) { string top = iCommentCount == 0 ? String.Empty : "TOP " + iCommentCount; if (state == CommentStates.All) { dp.ExecuteReader(String.Format("SELECT {0} * FROM Comments ORDER By CreateDate DESC", top)); } else { dp.AddParameter("Approve", state == CommentStates.Approved); dp.ExecuteReader(String.Format("SELECT {0} * FROM Comments WHERE [Approve]=@Approve ORDER By CreateDate DESC", top)); } if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSComment bsComment = new BSComment(); FillComment(dr, bsComment); comments.Add(bsComment); } } } } return comments; }
public static BSComment GetComment(int iCommentID) { using (DataProcess dp = new DataProcess()) { dp.AddParameter("CommentID", iCommentID); dp.ExecuteReader("SELECT * FROM Comments WHERE [CommentID]=@CommentID"); if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { if (dr != null && dr.Read()) { BSComment bsComment = new BSComment(); FillComment(dr, bsComment); return bsComment; } } } } return null; }
public List <BSComment> GetComments(CommentStates state) { return(BSComment.GetCommentsByPostID(PostID, state)); }
public static int GetCommentCount(int iUserID, CommentStates state) { return(BSComment.GetCommentsByUserID(iUserID, state).Count); }
void Comment_Showing(object sender, System.ComponentModel.CancelEventArgs e) { BSComment bsComment = (BSComment)sender; bsComment.Content = bsComment.Content.Replace("\n", "<br/>"); }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid || Session["ActiveUser"] != null) { TextBox txtSecurityCode = this.FindControl("txtSecurityCode") as TextBox; TextBox txtEmail = this.FindControl("txtEmail") as TextBox; TextBox txtWebSite = this.FindControl("txtWebSite") as TextBox; TextBox txtName = this.FindControl("txtName") as TextBox; TextBox txtComment = this.FindControl("txtComment") as TextBox; Literal ltInfo = this.FindControl("ltInfo") as Literal; CheckBox cbxNotifyMe = this.FindControl("cbxNotifyMe") as CheckBox; if (txtSecurityCode.Text.Equals(Session["SecurityCode" + BSPost.CurrentPost.PostID])) { BSComment bsComment = new BSComment(); bsComment.UserName = Server.HtmlEncode(txtName.Text); bsComment.Email = txtEmail.Text; bsComment.Content = BSHelper.GetEncodedHtml(txtComment.Text, true); bsComment.IP = HttpContext.Current.Request.UserHostAddress; if (cbxNotifyMe != null) { bsComment.NotifyMe = cbxNotifyMe.Checked; } bsComment.WebPage = txtWebSite.Text; bsComment.Date = DateTime.Now; bsComment.PostID = BSPost.CurrentPost.PostID; bool approve; bool.TryParse(Blogsa.Settings["add_comment_approve"].Value, out approve); bsComment.Approve = approve; if (Blogsa.ActiveUser != null) { bsComment.UserID = Blogsa.ActiveUser.UserID; bsComment.UserName = Blogsa.ActiveUser.Name; bsComment.Email = Blogsa.ActiveUser.Email; bsComment.Approve = HttpContext.Current.User.IsInRole("admin"); } if (bsComment.Save()) { if (Convert.ToBoolean(Blogsa.Settings["comment_sendmail"].Value) && ((Blogsa.ActiveUser != null && Blogsa.ActiveUser.UserID != bsComment.UserID) || Blogsa.ActiveUser == null)) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { BSHelper.SendMail(Language.Get["YouHaveNewComment"], Blogsa.Settings["smtp_email"].ToString(), Blogsa.Settings["smtp_name"].ToString(), Blogsa.Settings["smtp_email"].ToString(), Blogsa.Settings["smtp_name"].ToString(), string.Format(Language.Get["CommentMailContent"], "<b>" + bsComment.UserName + "</b>", "<b><a href=\"" + BSPost.CurrentPost.Link + "\">" + BSPost.CurrentPost.Title + "</a></b>", "<b>" + BSPost.CurrentPost.CommentCount + "</b>"), true); }); } if (bsComment.Approve) { Response.Redirect(BSPost.CurrentPost.Link + "#Comment" + bsComment.CommentID); } else { Session["WaitApprove"] = "OK"; Response.Redirect(BSPost.CurrentPost.Link + "#WriteComment"); } } else { ltInfo.Text = "Comment Save Error"; } } else { ltInfo.Text = Language.Get["YourSecurityCodeWrong"]; } } }
public static int GetCommentCount(CommentStates state) { return(BSComment.GetComments(state).Count); }