Esempio n. 1
0
        public void MarkHam(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,
            };

#if !DEBUG
            api.SubmitHam(akismetComment);
#endif
        }
Esempio n. 2
0
    public void Report(Comment comment)
    {
        if (_api == null)
        {
            Initialize();
        }

        if (_settings == null)
        {
            InitSettings();
        }

        AkismetComment akismetComment = GetAkismetComment(comment);

        if (comment.IsApproved)
        {
            Utils.Log(string.Format("Akismet: Reporting NOT spam from \"{0}\" at \"{1}\"", comment.Author, comment.IP));
            _api.SubmitHam(akismetComment);
        }
        else
        {
            Utils.Log(string.Format("Akismet: Reporting SPAM from \"{0}\" at \"{1}\"", comment.Author, comment.IP));
            _api.SubmitSpam(akismetComment);
        }
    }
Esempio n. 3
0
        public static void MarkHam(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,
            };

#if !DEBUG
            api.SubmitHam(akismetComment);
#endif
        }
 /// <summary>
 /// This call is intended for the marking of false positives, things that were incorrectly marked as spam.
 /// </summary>
 /// <param name="comment">The comment.</param>
 public void SubmitHam(CheckCommentForSpam comment)
 {
     if (VerifyKey)
     {
         AkismetComment akismetComment = ConvertCommentToAkismetComment(comment);
         Service.SubmitHam(akismetComment);
     }
 }
Esempio n. 5
0
        private void ValidateUpdatingComment(Comment comment)
        {
            var catchSpamInComments = Config.Get <AkismetModuleConfig>().ProtectComments;

            if (catchSpamInComments)
            {
                var blogsMan        = BlogsManager.GetManager(string.Empty, "DummyTransaction");
                var existingComment = SystemManager.GetCommentsService().GetComment(comment.Id.ToString());

                if (existingComment != null && existingComment.Status != comment.Status.ToString())
                {
                    Akismet akismetApiClient = new Akismet(Config.Get <AkismetModuleConfig>().ApiKey, "http://www.sitefinity.com", "SitefinityAkismetModule");
                    if (!akismetApiClient.VerifyKey())
                    {
                        return;
                    }

                    var akismetDbContext    = new AkismetEntityContext();
                    var existingAkismetData = akismetDbContext.AkismetDataList.SingleOrDefault(a => a.ContentItemId == comment.Id);
                    if (existingAkismetData != null)
                    {
                        var updatedComment = new AkismetComment()
                        {
                            Blog               = "http://www.sitefinity.com",
                            CommentContent     = comment.Content,
                            CommentType        = "comment",
                            Referrer           = existingAkismetData.Referrer,
                            UserAgent          = existingAkismetData.UserAgent,
                            UserIp             = existingAkismetData.UserIP,
                            CommentAuthor      = comment.AuthorName,
                            CommentAuthorEmail = comment.Email,
                            CommentAuthorUrl   = comment.Website
                        };

                        if (comment.CommentStatus.ToString() == Telerik.Sitefinity.Services.Comments.StatusConstants.Spam)
                        {
                            // the item has been marked as spam
                            akismetApiClient.SubmitSpam(updatedComment);
                        }
                        else
                        {
                            // the item has been marked as ham
                            akismetApiClient.SubmitHam(updatedComment);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        private void ValidateUpdatingForumPost(ForumPost post, string origin, Guid userId)
        {
            var catchSpamInForums = Config.Get <AkismetModuleConfig>().ProtectForums;

            if (catchSpamInForums)
            {
                var forumsMan = ForumsManager.GetManager(string.Empty, "DummyTransaction");

                var existingPost = forumsMan.GetPost(post.Id);
                if (existingPost != null && existingPost.IsMarkedSpam != post.IsMarkedSpam)
                {
                    Akismet akismetApiClient = new Akismet(Config.Get <AkismetModuleConfig>().ApiKey, "http://www.sitefinity.com", "SitefinityAkismetModule");
                    if (!akismetApiClient.VerifyKey())
                    {
                        return;
                    }

                    var akismetDbContext    = new AkismetEntityContext();
                    var existingAkismetData = akismetDbContext.AkismetDataList.SingleOrDefault(a => a.ContentItemId == post.Id);
                    if (existingAkismetData != null)
                    {
                        var updatedForumPost = new AkismetComment()
                        {
                            Blog           = "http://www.sitefinity.com",
                            CommentContent = post.Content,
                            CommentType    = "comment",
                            Referrer       = existingAkismetData.Referrer,
                            UserAgent      = existingAkismetData.UserAgent,
                            UserIp         = existingAkismetData.UserIP,
                        };

                        if (post.IsMarkedSpam)
                        {
                            // the item has been marked as spam
                            akismetApiClient.SubmitSpam(updatedForumPost);
                        }
                        else
                        {
                            // the item has been marked as ham
                            akismetApiClient.SubmitHam(updatedForumPost);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Report mistakes back to service
        /// </summary>
        /// <param name="comment">BlogEngine comment</param>
        public void Report(Comment comment)
        {
            if (api == null)
            {
                this.Initialize();
            }

            var akismetComment = GetAkismetComment(comment);

            if (comment.IsApproved)
            {
                Utils.Log(string.Format("TypePad: Reporting NOT spam from \"{0}\" at \"{1}\"", comment.Author, comment.IP));
                api.SubmitHam(akismetComment);
            }
            else
            {
                Utils.Log(string.Format("TypePad: Reporting SPAM from \"{0}\" at \"{1}\"", comment.Author, comment.IP));
                api.SubmitSpam(akismetComment);
            }
        }
Esempio n. 8
0
        public JsonResult ChangeSpamMark(int id)
        {
            Comment comment = CommentServices.FindEntityByIdentity(id);

            //Create a new instance of the Akismet API and verify your key is valid.
            Akismet api = new Akismet(BgResources.Akismet_API_key, Request.Url.AbsoluteUri, HttpContext.Request.UserAgent);

            if (!api.VerifyKey())
            {
                return(Json(new { result = "error", text = Resources.AppMessages.AkismetApikeyInvalid }));
            }

            //Now create an instance of AkismetComment, populating it with values
            //from the POSTed form collection.
            AkismetComment akismetComment = new AkismetComment
            {
                Blog               = Request.Url.Scheme + "://" + Request.Url.Host,
                UserIp             = comment.Ip,
                UserAgent          = comment.UserAgent,
                CommentContent     = comment.Message,
                CommentType        = "comment",
                CommentAuthor      = comment.AnonymousUser != null ? comment.AnonymousUser.Username : comment.User.Username,
                CommentAuthorEmail = comment.AnonymousUser != null ? comment.AnonymousUser.Email : comment.User.Email,
                CommentAuthorUrl   = comment.AnonymousUser != null ? comment.AnonymousUser.Web : String.Empty
            };

            if (comment.IsSpam)
            {
                comment.IsSpam = false;
                api.SubmitHam(akismetComment);
            }
            else
            {
                comment.IsSpam = true;
                api.SubmitSpam(akismetComment);
            }

            BlogServices.SaveComment(comment);

            return(Json(new { result = "ok" }));
        }
Esempio n. 9
0
        public static void MarkAsHam(int memberId, string body, string commentType)
        {
            var akismetApi = new Akismet(AkismetApiKey, "http://our.umbraco.org", "Test/1.0");

            if (akismetApi.VerifyKey() == false)
            {
                throw new Exception("Akismet API key could not be verified");
            }

            var member = new Member(memberId);

            var comment = new AkismetComment
            {
                Blog               = "http://our.umbraco.org",
                UserIp             = member.getProperty("ip").Value.ToString(),
                CommentAuthor      = member.Text,
                CommentAuthorEmail = member.Email,
                CommentType        = commentType,
                CommentContent     = body
            };

            akismetApi.SubmitHam(comment);
        }