예제 #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();
                    }
                }
            }
        }
예제 #2
0
        public void Process(CreateCommentArgs args)
        {
            Assert.IsNotNull(args.Comment, "Comment cannot be null");
            ProfanityFilterArgs filterArgs = new ProfanityFilterArgs
            {
                Input = args.Comment.Text
            };

            CorePipeline.Run("weblogProfanityFilter", filterArgs);
            if (!filterArgs.Valid)
            {
                args.AbortPipeline();
            }
            args.Comment.Text = filterArgs.Input;
        }
예제 #3
0
        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();
                    }
                }
            }
        }
예제 #4
0
        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();
                }
            }
        }
예제 #5
0
        public void Process(CreateCommentArgs args)
        {
            Assert.IsNotNull(args.CommentItem, "Comment Item cannot be null");

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

                if (workflow != null)
                {
                    var api = _akismetApi;
                    if (api == null)
                    {
                        api = new Akismet();
                    }

                    var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;

                    var blogItem = _blogManager.GetCurrentBlog(args.CommentItem);
                    var url      = _linkManager.GetAbsoluteItemUrl(blogItem);

                    api.Init(_commentSettings.AkismetAPIKey, url, "WeBlog/" + version);

                    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(_commentSettings.CommentWorkflowCommandSpam, args.CommentItem, "Akismet classified this comment as spam", false, new object[0]);
                        }

                        args.AbortPipeline();
                    }
                }
            }
        }