Example #1
0
        public void Process(CreateCommentArgs args)
        {
            Assert.IsNotNull(args.CommentItem, "Comment Item cannot be null");

            if (!string.IsNullOrEmpty(Settings.AkismetAPIKey) && !string.IsNullOrEmpty(Settings.CommentWorkflowCommandSpam))
            {
                var workflow = args.Database.WorkflowProvider.GetWorkflow(args.CommentItem);

                if (workflow != null)
                {
                    var api = new Akismet(Settings.AkismetAPIKey, ManagerFactory.BlogManagerInstance.GetCurrentBlog().SafeGet(x => x.Url), "WeBlog/2.1");
                    var isSpam = api.CommentCheck(args.CommentItem);

                    if (isSpam)
                    {
                        //Need to switch to shell website to execute workflow
                        using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext(Sitecore.Constants.ShellSiteName)))
                        {
                            workflow.Execute(Settings.CommentWorkflowCommandSpam, args.CommentItem, "Akismet classified this comment as spam", false, new object[0]);
                        }

                        args.AbortPipeline();
                    }
                }
            }
        }
        public void Process(CreateCommentArgs args)
        {
            Assert.IsNotNull(args.Database, "Database cannot be null");
            Assert.IsNotNull(args.Comment, "Comment cannot be null");
            Assert.IsNotNull(args.EntryID, "Entry ID cannot be null");

            var entryItem = args.Database.GetItem(args.EntryID, args.Language);
            if (entryItem != null)
            {
                var query = "fast:{0}//*[@email='{1}' and @name='{2}' and @comment='{3}']".FormatWith(
                    entryItem.Paths.FullPath, args.Comment.AuthorEmail, args.Comment.AuthorName, args.Comment.Text);
                var comments = args.Database.SelectItems(query);

                if(comments.Length > 0)
                    args.AbortPipeline();
            }
        }
Example #3
0
        public void Process(CreateCommentArgs args)
        {
            Assert.IsNotNull(args.Comment, "Comment DTO cannot be null");

            if (HttpContext.Current != null)
            {
                // Get cookie
                var cookie = HttpContext.Current.Request.Cookies[Constants.CookieName];
                if (cookie != null)
                {
                    // get the most recent comment hashes
                    var hashes = cookie.Value.Split(new char[] {';'});
                    var currentHash = args.Comment.GetHash();

                    if(hashes.Contains(currentHash))
                        args.AbortPipeline();
                }
            }
        }
    public void Process(CreateCommentArgs args)
    {
      Assert.IsNotNull(args.Database, "Database cannot be null");
      Assert.IsNotNull(args.Comment, "Comment cannot be null");
      Assert.IsNotNull(args.EntryID, "Entry ID cannot be null");

      var entryItem = args.Database.GetItem(args.EntryID, args.Language);
      if (entryItem != null)
      {
        // End at end of today to make sure we cover comments from today properly
        var dateEnd = System.DateTime.UtcNow.Date.AddDays(1);
        var dateStart = dateEnd - TimeSpan;

        var blog = ManagerFactory.BlogManagerInstance.GetCurrentBlog(entryItem);
        if (blog != null)
        {
          var commentTemplate = blog.BlogSettings.CommentTemplateID;

          var query = "{0}//*[@@templateid='{1}' and @__created > '{2}' and @__created < '{3}']".FormatWith(
            ContentHelper.EscapePath(entryItem.Paths.FullPath), commentTemplate, DateUtil.ToIsoDate(dateStart), DateUtil.ToIsoDate(dateEnd));

          var comments = args.Database.SelectItems(query);

          var match = false;

          foreach (var item in comments)
          {
            var commentItem = (CommentItem) item;
            if (string.Compare(commentItem.AuthorName, args.Comment.AuthorName, StringComparison.OrdinalIgnoreCase) == 0 &&
                string.Compare(commentItem.Email.Raw, args.Comment.AuthorEmail, StringComparison.OrdinalIgnoreCase) == 0 &&
                string.Compare(commentItem.Comment.Raw, args.Comment.Text, StringComparison.OrdinalIgnoreCase) == 0)
            {
              match = true;
              Log.Warn("[WeBlog] Duplicate comment submission. Existing item: {0}".FormatWith(commentItem.ID), this);
            }
          }

          if (match)
            args.AbortPipeline();
        }
      }
    }