/// <summary> /// Handle mass actions. /// </summary> protected void btnAction_Click(object sender, EventArgs e) { if (drpAction.SelectedValue != "SELECT") { ArrayList list = gridComments.SelectedItems; if (list.Count > 0) { foreach (string commnentId in list) { BlogCommentInfo bci = BlogCommentInfoProvider.GetBlogCommentInfo(Convert.ToInt32(commnentId)); switch (drpAction.SelectedValue.ToLower()) { case "delete": // Delete specified comment BlogCommentInfoProvider.DeleteBlogCommentInfo(bci); break; case "approve": if (!bci.CommentApproved) { // Set comment as 'approved' bci.CommentApproved = true; bci.CommentApprovedByUserID = CMSContext.CurrentUser.UserID; BlogCommentInfoProvider.SetBlogCommentInfo(bci); } break; case "reject": if (bci.CommentApproved) { // Set comment as 'reject' bci.CommentApproved = false; bci.CommentApprovedByUserID = 0; BlogCommentInfoProvider.SetBlogCommentInfo(bci); } break; case "spam": if (!bci.CommentIsSpam) { bci.CommentIsSpam = true; BlogCommentInfoProvider.SetBlogCommentInfo(bci); } break; case "nospam": if (bci.CommentIsSpam) { bci.CommentIsSpam = false; BlogCommentInfoProvider.SetBlogCommentInfo(bci); } break; } } } } }
protected void Page_Load(object sender, EventArgs e) { commentId = QueryHelper.GetInteger("commentID", 0); // Get comment info BlogCommentInfo commentObj = BlogCommentInfoProvider.GetBlogCommentInfo(commentId); EditedObject = commentObj; if (commentObj != null) { // Get parent blog TreeNode blogNode = BlogHelper.GetParentBlog(commentObj.CommentPostDocumentID, false); // Check site ID of edited blog if ((blogNode != null) && (blogNode.NodeSiteID != CMSContext.CurrentSiteID)) { EditedObject = null; } bool isAuthorized = BlogHelper.IsUserAuthorizedToManageComments(blogNode); // Check "manage" permission if (!isAuthorized) { RedirectToAccessDenied("cms.blog", "Manage"); } ctrlCommentEdit.CommentId = commentId; } btnOk.Click += btnOk_Click; btnOk.Text = GetString("General.OK"); btnOk.ValidationGroup = ctrlCommentEdit.ValidationGroup; ctrlCommentEdit.IsLiveSite = false; ctrlCommentEdit.OnAfterCommentSaved += new OnAfterCommentSavedEventHandler(ctrlCommentEdit_OnAfterCommentSaved); CurrentMaster.Title.TitleText = GetString("Blog.CommentEdit.Title"); CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Blog_Comment/object.png"); }
protected void Page_Load(object sender, EventArgs e) { commentId = QueryHelper.GetInteger("commentID", 0); // Get comment info BlogCommentInfo commentObj = BlogCommentInfoProvider.GetBlogCommentInfo(commentId); EditedObject = commentObj; if (commentObj != null) { // Get parent blog TreeNode blogNode = BlogHelper.GetParentBlog(commentObj.CommentPostDocumentID, false); // Check site ID of edited blog if ((blogNode != null) && (blogNode.NodeSiteID != SiteContext.CurrentSiteID)) { EditedObject = null; } bool isAuthorized = BlogHelper.IsUserAuthorizedToManageComments(blogNode); // Check "manage" permission if (!isAuthorized) { RedirectToAccessDenied("cms.blog", "Manage"); } ctrlCommentEdit.CommentId = commentId; } Save += (s, ea) => ctrlCommentEdit.PerformAction(); ctrlCommentEdit.IsLiveSite = false; ctrlCommentEdit.OnAfterCommentSaved += ctrlCommentEdit_OnAfterCommentSaved; PageTitle.TitleText = GetString("Blog.CommentEdit.Title"); }
protected void gridComments_OnAction(string actionName, object actionArgument) { int commentId = ValidationHelper.GetInteger(actionArgument, 0); switch (actionName.ToLowerCSafe()) { case "delete": // Delete specified comment BlogCommentInfoProvider.DeleteBlogCommentInfo(commentId); break; case "approve": BlogCommentInfo bci = BlogCommentInfoProvider.GetBlogCommentInfo(commentId); if (bci != null) { if (bci.CommentApproved) { // Set comment as 'rejected' bci.CommentApproved = false; bci.CommentApprovedByUserID = 0; } else { // Set comment as 'approved' bci.CommentApproved = true; bci.CommentApprovedByUserID = currentUser.UserID; } BlogCommentInfoProvider.SetBlogCommentInfo(bci); } break; case "edit": // JavaScript break; } }
/// <summary> /// Fill form with the comment data. /// </summary> protected void LoadCommentData() { // Get comment info from database BlogCommentInfo bci = BlogCommentInfoProvider.GetBlogCommentInfo(mCommentId); if (bci != null) { txtName.Text = bci.CommentUserName; txtUrl.Text = bci.CommentUrl; txtComments.Text = bci.CommentText; txtEmail.Text = bci.CommentEmail; chkApproved.Checked = bci.CommentApproved; chkSpam.Checked = bci.CommentIsSpam; if (PortalContext.ViewMode.IsLiveSite() && (MembershipContext.AuthenticatedUser != null)) { lblInsertedDate.Text = TimeZoneMethods.ConvertDateTime(bci.CommentDate, this).ToString(); } else { lblInsertedDate.Text = bci.CommentDate.ToString(); } } }
/// <summary> /// Fill form with the comment data. /// </summary> protected void LoadCommentData() { // Get comment info from database BlogCommentInfo bci = BlogCommentInfoProvider.GetBlogCommentInfo(mCommentId); if (bci != null) { txtName.Text = bci.CommentUserName; txtUrl.Text = bci.CommentUrl; txtComments.Text = bci.CommentText; txtEmail.Text = bci.CommentEmail; chkApproved.Checked = bci.CommentApproved; chkSpam.Checked = bci.CommentIsSpam; if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && (CMSContext.CurrentUser != null)) { lblInsertedDate.Text = CMSContext.ConvertDateTime(bci.CommentDate, this).ToString(); } else { lblInsertedDate.Text = bci.CommentDate.ToString(); } } }
/// <summary> /// Handle mass actions. /// </summary> protected void btnAction_Click(object sender, EventArgs e) { if (drpAction.SelectedValue != "SELECT") { List <string> list = gridComments.SelectedItems; if (list.Count > 0) { foreach (string commnentId in list) { BlogCommentInfo bci = BlogCommentInfoProvider.GetBlogCommentInfo(Convert.ToInt32(commnentId)); switch (drpAction.SelectedValue.ToLowerCSafe()) { case "delete": // Delete specified comment BlogCommentInfoProvider.DeleteBlogCommentInfo(bci); break; case "approve": if (!bci.CommentApproved) { // Set comment as 'approved' bci.CommentApproved = true; bci.CommentApprovedByUserID = MembershipContext.AuthenticatedUser.UserID; BlogCommentInfoProvider.SetBlogCommentInfo(bci); } break; case "reject": if (bci.CommentApproved) { // Set comment as 'reject' bci.CommentApproved = false; bci.CommentApprovedByUserID = 0; BlogCommentInfoProvider.SetBlogCommentInfo(bci); } break; case "spam": if (!bci.CommentIsSpam) { bci.CommentIsSpam = true; BlogCommentInfoProvider.SetBlogCommentInfo(bci); } break; case "nospam": if (bci.CommentIsSpam) { bci.CommentIsSpam = false; BlogCommentInfoProvider.SetBlogCommentInfo(bci); } break; } } } } // Clear selection gridComments.ResetSelection(); ReloadData(); }
private void mBlogComment_OnCommentAction(string actionName, object actionArgument) { // Get comment ID int commentId = ValidationHelper.GetInteger(actionArgument, 0); BlogCommentInfo bci; switch (actionName.ToLowerCSafe()) { case "delete": // Check 'Manage' permission if (!isUserAuthorized) { AccessDenied("cms.blog", "Manage"); } // Delete comment BlogCommentInfoProvider.DeleteBlogCommentInfo(commentId); ReloadData(); break; case "approve": // Check 'Manage' permission if (!isUserAuthorized) { AccessDenied("cms.blog", "Manage"); } // Set comment as 'approved' bci = BlogCommentInfoProvider.GetBlogCommentInfo(commentId); var currentUser = MembershipContext.AuthenticatedUser; if ((bci != null) && (currentUser != null)) { bci.CommentApprovedByUserID = currentUser.UserID; bci.CommentApproved = true; BlogCommentInfoProvider.SetBlogCommentInfo(bci); } ReloadData(); break; case "reject": // Check 'Manage' permission if (!isUserAuthorized) { AccessDenied("cms.blog", "Manage"); } // Set comment as 'rejected' bci = BlogCommentInfoProvider.GetBlogCommentInfo(commentId); if (bci != null) { bci.CommentApprovedByUserID = 0; bci.CommentApproved = false; BlogCommentInfoProvider.SetBlogCommentInfo(bci); } ReloadData(); break; } }
public void PerformAction() { // Check banned ip if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { lblError.Visible = true; lblError.Text = GetString("General.BannedIP"); return; } if (OnBeforeCommentSaved != null) { OnBeforeCommentSaved(); } // Validate form string errorMessage = ValidateForm(); if (errorMessage == "") { // Check flooding when message being inserted through the LiveSite if (IsLiveSite && FloodProtectionHelper.CheckFlooding(SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser)) { lblError.Visible = true; lblError.Text = GetString("General.FloodProtection"); return; } var currentUser = MembershipContext.AuthenticatedUser; // Create new comment BlogCommentInfo bci; if (IsInsertMode) { bci = new BlogCommentInfo(); bci.CommentDate = DateTime.Now; bci.CommentPostDocumentID = mPostDocumentId; // User IP address bci.CommentInfo.IPAddress = RequestContext.UserHostAddress; // User agent bci.CommentInfo.Agent = Request.UserAgent; if (!currentUser.IsPublic()) { bci.CommentUserID = currentUser.UserID; } bci.CommentIsTrackback = false; } // Get existing comment else { bci = BlogCommentInfoProvider.GetBlogCommentInfo(mCommentId); } // Update basic comment properties if (bci != null) { // Add http:// if needed string url = txtUrl.Text.Trim(); if (url != "") { if ((!url.ToLowerCSafe().StartsWithCSafe("http://")) && (!url.ToLowerCSafe().StartsWithCSafe("https://"))) { url = "http://" + url; } } bci.CommentIsSpam = chkSpam.Checked; bci.CommentApproved = chkApproved.Checked; bci.CommentUserName = txtName.Text.Trim(); bci.CommentUrl = url; bci.CommentText = txtComments.Text.Trim(); bci.CommentUrl = bci.CommentUrl.ToLowerCSafe().Replace("javascript", "_javascript"); bci.CommentEmail = txtEmail.Text.Trim(); } if (IsInsertMode) { // Auto approve owner comments if (bci != null) { TreeNode blogNode = BlogHelper.GetParentBlog(bci.CommentPostDocumentID, false); if ((currentUser != null) && (blogNode != null)) { bool isAuthorized = BlogHelper.IsUserAuthorizedToManageComments(blogNode); if (isAuthorized) { bci.CommentApprovedByUserID = blogNode.NodeOwner; bci.CommentApproved = true; } else { // Is blog moderated ? bool moderated = ValidationHelper.GetBoolean(blogNode.GetValue("BlogModerateComments"), false); bci.CommentApprovedByUserID = 0; bci.CommentApproved = !moderated; } } } } // Perform bad words check if (!BadWordInfoProvider.CanUseBadWords(MembershipContext.AuthenticatedUser, SiteContext.CurrentSiteName)) { if (bci != null) { // Prepare columns to check Dictionary <string, int> columns = new Dictionary <string, int>(); columns.Add("CommentText", 0); columns.Add("CommentUserName", 200); // Perform bad words to check errorMessage = BadWordsHelper.CheckBadWords(bci, columns, "CommentApproved", "CommentApprovedByUserID", bci.CommentText, MembershipContext.AuthenticatedUser.UserID, () => ValidateComment(bci)); } } if (errorMessage == string.Empty) { if (bci != null) { if (!ValidateComment(bci)) { // Show error message lblError.Visible = true; lblError.Text = GetString("Blog.CommentEdit.EmptyBadWord"); } else { // Subscribe new subscriber if (chkSubscribe.Checked) { // Check for duplicate subscriptions BlogPostSubscriptionInfo bpsi = BlogPostSubscriptionInfoProvider.GetBlogPostSubscriptionInfo(txtEmail.Text, mPostDocumentId); if ((bpsi == null) || !bpsi.SubscriptionApproved) { bpsi = new BlogPostSubscriptionInfo(); bpsi.SubscriptionEmail = txtEmail.Text; bpsi.SubscriptionPostDocumentID = mPostDocumentId; bpsi.SubscriptionUserID = bci.CommentUserID; BlogPostSubscriptionInfoProvider.Subscribe(bpsi, DateTime.Now, true, true); if (bpsi.SubscriptionApproved) { LogRegistrationActivity(bpsi); } } else { errorMessage = GetString("blog.subscription.emailexists"); } } if (errorMessage == "") { // Save changes to database BlogCommentInfoProvider.SetBlogCommentInfo(bci); if (!bci.CommentApproved) { CommentSavedText = GetString("blog.comments.requiresmoderationafteraction"); } // Inform user lblInfo.Visible = true; lblInfo.Text = CommentSavedText; // Clear form when required if (mClearFormAfterSave) { txtComments.Text = ""; txtUrl.Text = ""; ctrlCaptcha.Value = ""; } LogCommentActivity(bci, PostNodeId, PostCulture); if (OnAfterCommentSaved != null) { OnAfterCommentSaved(bci); } } } } } } if (errorMessage != "") { // Show error message lblError.Visible = true; lblError.Text = errorMessage; } }