Example #1
0
    /// <summary>
    /// Gets and bulk updates blog comments. Called when the "Get and bulk update comments" button is pressed.
    /// Expects the CreateBlogComment method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateBlogComments()
    {
        // Prepare the parameters
        string where = "CommentText LIKE 'My new%'";
        string blogWhere = "NodeName LIKE 'MyNewBlog%'";

        // Get the data
        DataSet comments = BlogCommentInfoProvider.GetComments(where, blogWhere);
        if (!DataHelper.DataSourceIsEmpty(comments))
        {
            // Loop through the individual items
            foreach (DataRow commentDr in comments.Tables[0].Rows)
            {
                // Create object from DataRow
                BlogCommentInfo modifyComment = new BlogCommentInfo(commentDr);

                // Update the properties
                modifyComment.CommentText = modifyComment.CommentText.ToUpper();

                // Update the blog comment
                BlogCommentInfoProvider.SetBlogCommentInfo(modifyComment);
            }

            return true;
        }

        return false;
    }
Example #2
0
    /// <summary>
    /// Gets and updates blog comment. Called when the "Get and update comment" button is pressed.
    /// Expects the CreateBlogComment method to be run first.
    /// </summary>
    private bool GetAndUpdateBlogComment()
    {
        // Prepare the parameters
        string where = "CommentText LIKE 'My New%'";
        string blogWhere = "BlogName LIKE 'MyNewBlog%'";

        // Get the blog comment
        DataSet comments = BlogCommentInfoProvider.GetComments(where, blogWhere);

        if (!DataHelper.DataSourceIsEmpty(comments))
        {
            // Create object from DataRow
            BlogCommentInfo modifyComment = new BlogCommentInfo(comments.Tables[0].Rows[0]);

            // Update the property
            modifyComment.CommentText = modifyComment.CommentText.ToUpper();

            // Update the blog comment
            BlogCommentInfoProvider.SetBlogCommentInfo(modifyComment);

            return(true);
        }

        return(false);
    }
Example #3
0
    /// <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;
                    }
                }
            }
        }
    }
Example #4
0
    /// <summary>
    /// Creates blog comment. Called when the "Create comment" button is pressed.
    /// </summary>
    private bool CreateBlogComment()
    {
        // Prepare the parameters
        TreeNode blogPostNode = null;

        // Get the content tree
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Get the post
        DataSet posts = BlogHelper.GetBlogPosts(CMSContext.CurrentSiteName, "/MyNewBlog", null, true, null, null, true);

        if (!DataHelper.DataSourceIsEmpty(posts))
        {
            // Create object from DataRow
            blogPostNode = TreeNode.New(posts.Tables[0].Rows[0], "cms.blogpost", tree);
        }

        if (blogPostNode != null)
        {
            // Create new blog comment object
            BlogCommentInfo newComment = new BlogCommentInfo();

            // Set the properties
            newComment.CommentText             = "My new comment";
            newComment.CommentUserName         = CMSContext.CurrentUser.UserName;
            newComment.CommentUserID           = CMSContext.CurrentUser.UserID;
            newComment.CommentApprovedByUserID = CMSContext.CurrentUser.UserID;
            newComment.CommentPostDocumentID   = blogPostNode.DocumentID;
            newComment.CommentDate             = DateTime.Now;

            // Create the blog comment
            BlogCommentInfoProvider.SetBlogCommentInfo(newComment);

            return(true);
        }

        return(false);
    }
    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>
    /// 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();
    }
Example #7
0
    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;
        }
    }
Example #8
0
    /// <summary>
    /// Process trackback parameters.
    /// </summary>
    private void ProcessParameters()
    {
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
        TreeNode     node = tree.SelectSingleNode(postGuid, culture, SiteContext.CurrentSiteName);

        // Check that requested blog post exists
        if (node != null)
        {
            node = TreeHelper.SelectSingleDocument(node.DocumentID);

            // Check if comment from given URL is not already inserted
            DataSet ds = BlogCommentInfoProvider.GetAllComments("CommentPostDocumentID = " + node.DocumentID + " AND CommentIsTrackback=1 AND CommentUrl='" + SqlHelper.GetSafeQueryString(url, false) + "'");

            if (DataHelper.DataSourceIsEmpty(ds))
            {
                // Check if blog for blog post exists
                TreeNode blogNode = BlogHelper.GetParentBlog(node.DocumentID, false);
                if (blogNode != null)
                {
                    // Check if comments are opened
                    int  days   = ValidationHelper.GetInteger(blogNode.GetValue("BlogOpenCommentsFor"), 0);
                    bool opened = false;

                    // Check if comments are always opened
                    if (days == BlogProperties.OPEN_COMMENTS_ALWAYS)
                    {
                        opened = true;
                    }

                    // Check if comments are opened in present time
                    if ((ValidationHelper.GetDateTime(node.GetValue("BlogPostDate"), DateTime.Today).AddDays(days)) >= DateTime.Today)
                    {
                        opened = true;
                    }

                    // Check if comments are disabled
                    if (days == BlogProperties.OPEN_COMMENTS_DISABLE)
                    {
                        opened = false;
                    }

                    // Check if trackback comments are enabled, anonymous comments are enabled, comments are enabled in present time and blog post allow comments
                    if (ValidationHelper.GetBoolean(blogNode.GetValue("BlogEnableTrackbacks"), false) && (ValidationHelper.GetBoolean(blogNode.GetValue("BlogAllowAnonymousComments"), false)) && (opened) && (ValidationHelper.GetBoolean(node.GetValue("BlogPostAllowComments"), false)))
                    {
                        // Create new comment
                        BlogCommentInfo comment = new BlogCommentInfo();

                        comment.CommentUrl              = url.Length > 450 ? url.Substring(0, 450) : url;
                        comment.CommentText             = excerpt;
                        comment.CommentDate             = DateTime.Now;
                        comment.CommentUserName         = GetCommentUserName(blogName, title);
                        comment.CommentUserID           = 0;
                        comment.CommentApprovedByUserID = 0;
                        comment.CommentPostDocumentID   = node.DocumentID;
                        comment.CommentIsTrackback      = true;
                        comment.CommentIsSpam           = false;

                        // User IP address
                        comment.CommentInfo.IPAddress = RequestContext.UserHostAddress;
                        // User agent
                        comment.CommentInfo.Agent = Request.UserAgent;

                        // Check if comments are moderated
                        if (!ValidationHelper.GetBoolean(blogNode.GetValue("BlogModerateComments"), false))
                        {
                            comment.CommentApproved = true;
                        }
                        else
                        {
                            comment.CommentApproved = false;
                        }

                        // Save changes to database
                        BlogCommentInfoProvider.SetBlogCommentInfo(comment);

                        // Send OK response, no error message
                        SendResponse(null);
                    }
                    else
                    {
                        SendResponse("Blog doesn't enable trackbacks.");
                    }
                }
                else
                {
                    SendResponse("Blog not found.");
                }
            }
            else
            {
                SendResponse("Blog post with given URL is already referenced.");
            }
        }
        else
        {
            SendResponse("Blog post not found.");
        }
    }
Example #9
0
    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;
        }
    }