コード例 #1
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var minute = Math.Round((double)dasBlogSettings.FilterHtml(Post.Content).Length / 200);

            output.TagName = "span";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.SetAttribute("class", "dbc-post-readtime");
            output.Content.SetHtmlContent(string.Format(READTIMEMINUTES, minute));
        }
コード例 #2
0
 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     output.TagName = "div";
     output.TagMode = TagMode.StartTagAndEndTag;
     output.Attributes.SetAttribute("class", Css);
     Comment.Text = dasBlogSettings.FilterHtml(Comment.Text);
     Comment.Text = Regex.Replace(Comment.Text, "\n", "<br />");
     output.Content.SetHtmlContent(HttpUtility.HtmlDecode(Comment.Text));
 }
コード例 #3
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var delimiters = new char[] { ' ', '\r', '\n' };
            var minute     = Math.Round((double)dasBlogSettings.FilterHtml(Post.Content).Split(delimiters, StringSplitOptions.RemoveEmptyEntries).Length / 200);

            output.TagName = "span";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.SetAttribute("class", "dbc-post-readtime");
            output.Content.SetHtmlContent(string.Format(READTIMEMINUTES, minute));
        }
コード例 #4
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var rx           = new Regex(@"<img.*?src="".*?"".*?>");
            var numberImages = rx.Matches(Post.Content).Count;

            var imgMinutes = (double)(numberImages * 30) / 60;
            var delimiters = new char[] { ' ', '\r', '\n' };
            var minute     = Math.Round((double)dasBlogSettings.FilterHtml(Post.Content).Split(delimiters, StringSplitOptions.RemoveEmptyEntries).Length / 200) + Math.Round(imgMinutes, MidpointRounding.AwayFromZero);

            output.TagName = "span";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.SetAttribute("class", "dbc-post-readtime");
            output.Content.SetHtmlContent(string.Format(READTIMEMINUTES, minute));
        }
コード例 #5
0
        public CommentSaveState AddComment(string postid, Comment comment)
        {
            var saveState = CommentSaveState.Failed;
            var entry     = dataService.GetEntry(postid);

            if (!dasBlogSettings.SiteConfiguration.EnableComments || !entry.AllowComments)
            {
                return(CommentSaveState.SiteCommentsDisabled);
            }

            if (entry != null)
            {
                var targetComment = DateTime.UtcNow.AddDays(-1 * dasBlogSettings.SiteConfiguration.DaysCommentsAllowed);

                if ((targetComment > entry.CreatedUtc))
                {
                    return(CommentSaveState.PostCommentsDisabled);
                }

                // FilterHtml html encodes anything we don't like
                string filteredText = dasBlogSettings.FilterHtml(comment.Content);
                comment.Content = filteredText;

                if (dasBlogSettings.SiteConfiguration.SendCommentsByEmail)
                {
                    var actions = ComposeMailForUsers(entry, comment);
                    dataService.AddComment(comment, actions);
                }
                else
                {
                    dataService.AddComment(comment);
                }


                saveState = CommentSaveState.Added;
            }
            else
            {
                saveState = CommentSaveState.NotFound;
            }

            return(saveState);
        }
コード例 #6
0
        public IActionResult AddComment(AddCommentViewModel addcomment)
        {
            List <string> errors = new List <string>();

            if (!dasBlogSettings.SiteConfiguration.EnableComments)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(Comment(addcomment.TargetEntryId));
            }

            // Optional in case of Captcha. Commenting the settings in the config file
            // Will disable this check. People will typically disable this when using captcha.
            if (!String.IsNullOrEmpty(dasBlogSettings.SiteConfiguration.CheesySpamQ) &&
                !String.IsNullOrEmpty(dasBlogSettings.SiteConfiguration.CheesySpamA) &&
                dasBlogSettings.SiteConfiguration.CheesySpamQ.Trim().Length > 0 &&
                dasBlogSettings.SiteConfiguration.CheesySpamA.Trim().Length > 0)
            {
                if (string.Compare(addcomment.CheesyQuestionAnswered, dasBlogSettings.SiteConfiguration.CheesySpamA,
                                   StringComparison.OrdinalIgnoreCase) != 0)
                {
                    errors.Add("Answer to Spam Question is invalid. Please enter a valid answer for Spam Question and try again.");
                }
            }

            if (dasBlogSettings.SiteConfiguration.EnableCaptcha)
            {
                var recaptchaTask = recaptcha.Validate(Request);
                recaptchaTask.Wait();
                var recaptchaResult = recaptchaTask.Result;
                if ((!recaptchaResult.success || recaptchaResult.score != 0) &&
                    recaptchaResult.score < dasBlogSettings.SiteConfiguration.RecaptchaMinimumScore)
                {
                    errors.Add("Unfinished Captcha. Please finish the captcha by clicking 'I'm not a robot' and try again.");
                }
            }

            if (errors.Count > 0)
            {
                return(CommentError(addcomment, errors));
            }


            addcomment.Content = dasBlogSettings.FilterHtml(addcomment.Content);

            var commt = mapper.Map <NBR.Comment>(addcomment);

            commt.AuthorIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
            commt.AuthorUserAgent = HttpContext.Request.Headers["User-Agent"].ToString();
            commt.CreatedUtc      = commt.ModifiedUtc = DateTime.UtcNow;
            commt.EntryId         = Guid.NewGuid().ToString();
            commt.IsPublic        = !dasBlogSettings.SiteConfiguration.CommentsRequireApproval;

            var state = blogManager.AddComment(addcomment.TargetEntryId, commt);

            if (state == NBR.CommentSaveState.Failed)
            {
                ModelState.AddModelError("", "Comment failed");
                return(StatusCode(500));
            }

            if (state == NBR.CommentSaveState.SiteCommentsDisabled)
            {
                ModelState.AddModelError("", "Comments are closed for this post");
                return(StatusCode(403));
            }

            if (state == NBR.CommentSaveState.PostCommentsDisabled)
            {
                ModelState.AddModelError("", "Comment are currently disabled");
                return(StatusCode(403));
            }

            if (state == NBR.CommentSaveState.NotFound)
            {
                ModelState.AddModelError("", "Invalid Target Post Id");
                return(NotFound());
            }

            logger.LogInformation(new EventDataItem(EventCodes.CommentAdded, null, "Comment created on: {0}", commt.TargetTitle));

            BreakSiteCache();

            return(Comment(addcomment.TargetEntryId));
        }
コード例 #7
0
        public IActionResult AddComment(AddCommentViewModel addcomment)
        {
            if (!dasBlogSettings.SiteConfiguration.EnableComments)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(Comment(addcomment.TargetEntryId));
            }

            if (dasBlogSettings.SiteConfiguration.CheesySpamQ.Trim().Length > 0 &&
                dasBlogSettings.SiteConfiguration.CheesySpamA.Trim().Length > 0)
            {
                if (string.Compare(addcomment.CheesyQuestionAnswered, dasBlogSettings.SiteConfiguration.CheesySpamA,
                                   StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return(Comment(addcomment.TargetEntryId));
                }
            }

            addcomment.Content = dasBlogSettings.FilterHtml(addcomment.Content);

            var commt = mapper.Map <NBR.Comment>(addcomment);

            commt.AuthorIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
            commt.AuthorUserAgent = HttpContext.Request.Headers["User-Agent"].ToString();
            commt.CreatedUtc      = commt.ModifiedUtc = DateTime.UtcNow;
            commt.EntryId         = Guid.NewGuid().ToString();
            commt.IsPublic        = !dasBlogSettings.SiteConfiguration.CommentsRequireApproval;

            var state = blogManager.AddComment(addcomment.TargetEntryId, commt);

            if (state == NBR.CommentSaveState.Failed)
            {
                ModelState.AddModelError("", "Comment failed");
                return(StatusCode(500));
            }

            if (state == NBR.CommentSaveState.SiteCommentsDisabled)
            {
                ModelState.AddModelError("", "Comments are closed for this post");
                return(StatusCode(403));
            }

            if (state == NBR.CommentSaveState.PostCommentsDisabled)
            {
                ModelState.AddModelError("", "Comment are currently disabled");
                return(StatusCode(403));
            }

            if (state == NBR.CommentSaveState.NotFound)
            {
                ModelState.AddModelError("", "Invalid Target Post Id");
                return(NotFound());
            }

            logger.LogInformation(new EventDataItem(EventCodes.CommentAdded, null, "Comment created on: {0}", commt.TargetTitle));

            BreakSiteCache();

            return(Comment(addcomment.TargetEntryId));
        }
コード例 #8
0
        public IActionResult AddComment(AddCommentViewModel addcomment)
        {
            if (!dasBlogSettings.SiteConfiguration.EnableComments)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(Comment(addcomment.TargetEntryId));
            }

            // Optional in case of Captcha. Commenting the settings in the config file
            // Will disable this check. People will typically disable this when using captcha.
            if (!String.IsNullOrEmpty(dasBlogSettings.SiteConfiguration.CheesySpamQ) &&
                !String.IsNullOrEmpty(dasBlogSettings.SiteConfiguration.CheesySpamA) &&
                dasBlogSettings.SiteConfiguration.CheesySpamQ.Trim().Length > 0 &&
                dasBlogSettings.SiteConfiguration.CheesySpamA.Trim().Length > 0)
            {
                if (string.Compare(addcomment.CheesyQuestionAnswered, dasBlogSettings.SiteConfiguration.CheesySpamA,
                                   StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return(Comment(addcomment.TargetEntryId));
                }
            }

            if (dasBlogSettings.SiteConfiguration.EnableCaptcha)
            {
                var recaptchaTask = recaptcha.Validate(Request);
                recaptchaTask.Wait();
                var recaptchaResult = recaptchaTask.Result;
                if ((!recaptchaResult.success || recaptchaResult.score != 0) &&
                    recaptchaResult.score < dasBlogSettings.SiteConfiguration.RecaptchaMinimumScore)
                {
                    // Todo: Rajiv Popat: This just redirects to the comment page. Ideally user should be informed that
                    // the captch is invalid and he should be shown an error page with ability to fix the issue.
                    // We need to have the ability to show errors and let the user fix typos in Captcha or Cheesy
                    // Question. For now we are following the sample implementation as Cheesy Spam Question above
                    // for the sake of consistency but this should be fixed everywhere.
                    return(Comment(addcomment.TargetEntryId));
                }
            }

            addcomment.Content = dasBlogSettings.FilterHtml(addcomment.Content);

            var commt = mapper.Map <NBR.Comment>(addcomment);

            commt.AuthorIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
            commt.AuthorUserAgent = HttpContext.Request.Headers["User-Agent"].ToString();
            commt.CreatedUtc      = commt.ModifiedUtc = DateTime.UtcNow;
            commt.EntryId         = Guid.NewGuid().ToString();
            commt.IsPublic        = !dasBlogSettings.SiteConfiguration.CommentsRequireApproval;

            var state = blogManager.AddComment(addcomment.TargetEntryId, commt);

            if (state == NBR.CommentSaveState.Failed)
            {
                ModelState.AddModelError("", "Comment failed");
                return(StatusCode(500));
            }

            if (state == NBR.CommentSaveState.SiteCommentsDisabled)
            {
                ModelState.AddModelError("", "Comments are closed for this post");
                return(StatusCode(403));
            }

            if (state == NBR.CommentSaveState.PostCommentsDisabled)
            {
                ModelState.AddModelError("", "Comment are currently disabled");
                return(StatusCode(403));
            }

            if (state == NBR.CommentSaveState.NotFound)
            {
                ModelState.AddModelError("", "Invalid Target Post Id");
                return(NotFound());
            }

            logger.LogInformation(new EventDataItem(EventCodes.CommentAdded, null, "Comment created on: {0}", commt.TargetTitle));

            BreakSiteCache();

            return(Comment(addcomment.TargetEntryId));
        }