Exemple #1
0
        public override void Initialize(Rendering rendering)
        {
            base.Initialize(rendering);

            if (string.IsNullOrEmpty(UrlToLike))
            {
                UrlToLike = _linkManager.GetAbsoluteItemUrl(DataSourceItem);
            }
        }
Exemple #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (string.IsNullOrEmpty(UrlToCommentOn))
            {
                UrlToCommentOn = _linkManager.GetAbsoluteItemUrl(DataSourceItem);
            }
        }
Exemple #3
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();
                    }
                }
            }
        }