コード例 #1
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);
    }
コード例 #2
0
ファイル: BlogFunctions.cs プロジェクト: LuckyN/test
    /// <summary>
    /// Returns number of comments of given blog.
    /// </summary>
    /// <param name="postId">Post document id</param>
    /// <param name="postAliasPath">Post alias path</param>
    /// <param name="includingTrackbacks">Indicates if trackback comments should be included</param>
    public static int GetBlogCommentsCount(object postId, object postAliasPath, bool includingTrackbacks)
    {
        int             docId       = ValidationHelper.GetInteger(postId, 0);
        string          aliasPath   = ValidationHelper.GetString(postAliasPath, "");
        CurrentUserInfo currentUser = MembershipContext.AuthenticatedUser;

        // There has to be the current site
        if (SiteContext.CurrentSite == null)
        {
            throw new Exception("[BlogFunctions.GetBlogCommentsCount]: There is no current site!");
        }

        bool isOwner = false;

        // Is user authorized to manage comments?
        bool     selectOnlyPublished = (PortalContext.ViewMode == ViewModeEnum.LiveSite);
        TreeNode blogNode            = BlogHelper.GetParentBlog(aliasPath, SiteContext.CurrentSiteName, selectOnlyPublished);

        if (blogNode != null)
        {
            isOwner = (currentUser.UserID == ValidationHelper.GetInteger(blogNode.GetValue("NodeOwner"), 0));
        }

        bool isUserAuthorized = (currentUser.IsAuthorizedPerResource("cms.blog", "Manage") || isOwner || BlogHelper.IsUserBlogModerator(currentUser.UserName, blogNode));

        // Get post comments
        return(BlogCommentInfoProvider.GetPostCommentsCount(docId, !isUserAuthorized, isUserAuthorized, includingTrackbacks));
    }
コード例 #3
0
    protected DataSet gridComments_OnDataReload(string completeWhere, string currentOrder, int currentTopN, string columns, int currentOffset, int currentPageSize, ref int totalRecords)
    {
        string whereCondition     = String.Empty;
        string blogWhereCondition = String.Empty;

        if (ShowFilter)
        {
            whereCondition     = filterElem.CommentWhereCondition;
            blogWhereCondition = filterElem.BlogWhereCondition;
        }
        else
        {
            whereCondition     = CommentWhereCondition;
            blogWhereCondition = BlogWhereCondition;
        }

        // All sites
        if (SiteName == "-1")
        {
            SiteName = TreeProvider.ALL_SITES;
        }

        // Set the current site if the siteName is not defined
        if (String.IsNullOrEmpty(SiteName))
        {
            SiteName = SiteContext.CurrentSiteName;
        }
        return(BlogCommentInfoProvider.GetComments(0, null, whereCondition, blogWhereCondition, columns, currentTopN, currentOrder, currentOffset, currentPageSize, ref totalRecords, SiteName));
    }
コード例 #4
0
ファイル: Default.aspx.cs プロジェクト: tvelzy/RadstackMedia
    /// <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;
    }
コード例 #5
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;
                    }
                }
            }
        }
    }
    protected DataSet gridComments_OnDataReload(string completeWhere, string currentOrder, int currentTopN, string columns, int currentOffset, int currentPageSize, ref int totalRecords)
    {
        string whereCondition;
        string blogWhereCondition;

        if (ShowFilter)
        {
            whereCondition     = filterElem.CommentWhereCondition;
            blogWhereCondition = filterElem.BlogWhereCondition;
        }
        else
        {
            whereCondition     = CommentWhereCondition;
            blogWhereCondition = BlogWhereCondition;
        }

        var siteName = GetValidSiteName();

        return(BlogCommentInfoProvider.GetComments(0, null, whereCondition, blogWhereCondition, columns, currentTopN, currentOrder, currentOffset, currentPageSize, ref totalRecords, siteName));
    }
コード例 #7
0
    /// <summary>
    /// Reloads comment list.
    /// </summary>
    public void ReloadComments()
    {
        this.SetContext();

        this.pnlComment.Visible = this.AreCommentsOpened;

        if (this.PostNode != null)
        {
            CurrentUserInfo currentUser = CMSContext.CurrentUser;

            // Check permissions for blog
            if (this.BlogProperties.CheckPermissions)
            {
                if (currentUser.IsAuthorizedPerDocument(this.PostNode, NodePermissionsEnum.Read) != AuthorizationResultEnum.Allowed)
                {
                    this.Visible = false;
                    return;
                }
            }

            ctrlCommentEdit.PostDocumentId = this.PostNode.DocumentID;
            ctrlCommentEdit.PostNodeId     = this.PostNode.NodeID;
            ctrlCommentEdit.PostCulture    = this.PostNode.DocumentCulture;

            if (!this.BlogProperties.StopProcessing)
            {
                // Get parent blog
                bool     selectOnlyPublished = (CMSContext.ViewMode == ViewModeEnum.LiveSite);
                TreeNode blogNode            = BlogHelper.GetParentBlog(this.AliasPath, this.SiteName, selectOnlyPublished);

                // Determine whether user is authorized to manage comments
                isUserAuthorized = BlogHelper.IsUserAuthorizedToManageComments(blogNode);

                // Get all post comments
                rptComments.DataSource = BlogCommentInfoProvider.GetPostComments(this.PostNode.DocumentID, !isUserAuthorized, isUserAuthorized, DisplayTrackbacks);
                rptComments.DataBind();
            }
        }

        this.ReleaseContext();
    }
コード例 #8
0
    /// <summary>
    /// Reloads comment list.
    /// </summary>
    public void ReloadComments()
    {
        SetContext();

        pnlComment.Visible = AreCommentsOpened;

        if (PostNode != null)
        {
            var currentUser = MembershipContext.AuthenticatedUser;

            // Check permissions for blog
            if (BlogProperties.CheckPermissions)
            {
                if (currentUser.IsAuthorizedPerDocument(PostNode, NodePermissionsEnum.Read) != AuthorizationResultEnum.Allowed)
                {
                    Visible = false;
                    return;
                }
            }

            ctrlCommentEdit.PostDocumentId = PostNode.DocumentID;
            ctrlCommentEdit.PostNodeId     = PostNode.NodeID;
            ctrlCommentEdit.PostCulture    = PostNode.DocumentCulture;

            if (!BlogProperties.StopProcessing)
            {
                // Get parent blog
                bool     selectOnlyPublished = PortalContext.ViewMode.IsLiveSite();
                TreeNode blogNode            = BlogHelper.GetParentBlog(AliasPath, SiteName, selectOnlyPublished);

                // Determine whether user is authorized to manage comments
                isUserAuthorized = BlogHelper.IsUserAuthorizedToManageComments(blogNode);

                // Get all post comments
                rptComments.DataSource = BlogCommentInfoProvider.GetPostComments(PostNode.DocumentID, !isUserAuthorized, isUserAuthorized);
                rptComments.DataBind();
            }
        }

        ReleaseContext();
    }
コード例 #9
0
    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");
    }
コード例 #10
0
ファイル: Default.aspx.cs プロジェクト: tvelzy/RadstackMedia
    /// <summary>
    /// Deletes blog comment. Called when the "Delete comment" button is pressed.
    /// Expects the CreateBlogComment method to be run first.
    /// </summary>
    private bool DeleteBlogComment()
    {
        // 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))
        {
            // Create object from DataRow
            BlogCommentInfo modifyComment = new BlogCommentInfo(comments.Tables[0].Rows[0]);

            // Delete the blog comment
            BlogCommentInfoProvider.DeleteBlogCommentInfo(modifyComment);

            return true;
        }

        return false;
    }
コード例 #11
0
    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");
    }
コード例 #12
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);
    }
コード例 #13
0
    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;
        }
    }
コード例 #14
0
    /// <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();
            }
        }
    }
コード例 #15
0
    /// <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();
            }
        }
    }
コード例 #16
0
    /// <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();
    }
コード例 #17
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;
        }
    }
コード例 #18
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.");
        }
    }
コード例 #19
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;
        }
    }