Exemplo n.º 1
0
        public bool ValidateComment(Comment comment) {
            CommentSettingsRecord commentSettingsRecord = CurrentSite.As<CommentSettings>().Record;
            string akismetKey = commentSettingsRecord.AkismetKey;
            string akismetUrl = commentSettingsRecord.AkismetUrl;
            bool enableSpamProtection = commentSettingsRecord.EnableSpamProtection;
            if (enableSpamProtection == false) {
                return true;
            }
            if (String.IsNullOrEmpty(akismetKey)) {
                _notifer.Information(T("Please configure your Akismet key for spam protection"));
                return true;
            }
            if (String.IsNullOrEmpty(akismetUrl)) {
                akismetUrl = "http://www.orchardproject.net";
            }
            Akismet akismetApi = new Akismet(akismetKey, akismetUrl, null);
            AkismetComment akismetComment = new AkismetComment {
                CommentAuthor = comment.Record.Author,
                CommentAuthorEmail = comment.Record.Email,
                Blog = comment.Record.SiteName,
                CommentAuthorUrl = comment.Record.SiteName,
                CommentContent = comment.Record.CommentText,
                UserAgent = HttpContext.Current.Request.UserAgent,
            };

            if (akismetApi.VerifyKey()) {
                return akismetApi.CommentCheck(akismetComment);
            }

            return false;
        }
Exemplo n.º 2
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();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static bool CheckForSpam(PostComments.Comment comment)
        {
            var api = new Akismet(AkismetKey, BlogUrl, comment.UserAgent);
            if (!api.VerifyKey()) throw new Exception("Akismet API key invalid.");

            var akismetComment = new AkismetComment
            {
                Blog = BlogUrl,
                UserIp = comment.UserHostAddress,
                UserAgent = comment.UserAgent,
                CommentContent = comment.Body,
                CommentType = "comment",
                CommentAuthor = comment.Author,
                CommentAuthorEmail = comment.Email,
                CommentAuthorUrl = comment.Url,
            };

            //Check if Akismet thinks this comment is spam. Returns TRUE if spam.
            return api.CommentCheck(akismetComment);
        }
Exemplo n.º 4
0
        public bool CheckForSpam(PostComments.Comment comment)
        {
            //Create a new instance of the Akismet API and verify your key is valid.
            string blog = ConfigurationManager.AppSettings["MainUrl"];
            var api = new Akismet(akismetKey, blog, comment.UserAgent);
            if (!api.VerifyKey()) throw new Exception("Akismet API key invalid.");

            var akismetComment = new AkismetComment
            {
                Blog = blog,
                UserIp = comment.UserHostAddress,
                UserAgent = comment.UserAgent,
                CommentContent = comment.Body,
                CommentType = "comment",
                CommentAuthor = comment.Author,
                CommentAuthorEmail = comment.Email,
                CommentAuthorUrl = comment.Url,
            };

            //Check if Akismet thinks this comment is spam. Returns TRUE if spam.
            return api.CommentCheck(akismetComment);
        }
Exemplo n.º 5
0
        internal static bool CheckCommentForSpamUsingAkismet(HttpRequest request, string name, 
                        string email, string webSite, string feedbackText)
        {
            //Test spam username: viagra-test-123
            Akismet akismetAPI = new Akismet(CacheHandler.GetBlogConfig().AkismetApiKey,
                "http://www." + CacheHandler.GetBlogConfig().Host, "Test/1.0");
            if (!akismetAPI.VerifyKey())
            {
                throw new Exception("Akismet key could not be verified.");
            }
            AkismetComment comment = new AkismetComment();
            comment.Blog = "http://www." + CacheHandler.GetBlogConfig().Host;
            comment.UserIp = request.UserHostAddress;
            comment.UserAgent = request.UserAgent;
            comment.CommentContent = feedbackText;
            comment.CommentType = "comment";
            comment.CommentAuthor = name;
            comment.CommentAuthorEmail = email;
            comment.CommentAuthorUrl = webSite;

            bool spamCheck = akismetAPI.CommentCheck(comment);
            return spamCheck;
        }
Exemplo n.º 6
0
        public static int ScoreComment(Comment comment, Post p)
        {
            int score = 0;

            CommentSettings cs = Get();

            if (string.IsNullOrEmpty(comment.Body))
                throw new Exception("No comment body found");

            if (!cs.EnableCommentOnPost(p))
                throw new Exception("No new comments are allowed on this post");

            if(comment.Body.Trim().Length < 20)
            {
                score += (-1*(comment.Body.Trim().Length - 20));
            }

            score += Regex.Matches(comment.Body, @"(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])", RegexOptions.IgnoreCase).Count;

            score += CountWords(comment);

            if (!String.IsNullOrEmpty(cs.AkismetId))
            {
                try
                {
                    AkismetComment akComment = GetComment(comment);
                    Akismet akismet = new Akismet(cs.AkismetId, akComment.Blog, SiteSettings.Version);

                    if (akismet.CommentCheck(akComment))
                        score += cs.AkismetScore;
                }
                catch(Exception ex)
                {
                    Log.Error("Spam - Akismet", "Akismet scoring failed.\n\nReason: {0}", ex);
                }
            }

            return score;
        }