Esempio n. 1
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.");
        }
    }