示例#1
0
文件: Akismet.cs 项目: LByron/BS
 /// <summary>Submits AkismetComment object into Akismet database.</summary>
 /// <param name="comment">AkismetComment object to submit.</param>
 public void SubmitSpam(AkismetComment comment)
 {
     string value = HttpPost(String.Format(submitSpamUrl, apiKey), CreateData(comment), CharSet);
     #if DEBUG
     Console.WriteLine("SubmitSpam() = {0}.", value);
     #endif
 }
示例#2
0
        /// <summary>Retracts false positive from Akismet database.</summary>
        /// <param name="comment">AkismetComment object to retract.</param>
        public void SubmitHam(AkismetComment comment)
        {
            string value = HttpPost(String.Format(submitHamUrl, apiKey), CreateData(comment), CharSet);

#if DEBUG
            Console.WriteLine("SubmitHam() = {0}.", value);
#endif
        }
示例#3
0
        public AkismetStatus Process(AkismetComment comment, ISettings blogSettings)
        {            
            var commentStatus = new AkismetStatus(comment);
            commentStatus.CheckIfSpamOrHam(_akismetService)
                         .SubmitSpam(_akismetService)
                         .SubmitHam(_akismetService);            

            return commentStatus;
        }
示例#4
0
        public AkismetStatus Process(AkismetComment comment, ISettings blogSettings)
        {
            var commentStatus = new AkismetStatus(comment);

            commentStatus.CheckIfSpamOrHam(_akismetService)
            .SubmitSpam(_akismetService)
            .SubmitHam(_akismetService);

            return(commentStatus);
        }
示例#5
0
        /// <summary>Checks AkismetComment object against Akismet database.</summary>
        /// <param name="comment">AkismetComment object to check.</param>
        /// <returns>'True' if spam, 'False' if not spam.</returns>
        public bool CommentCheck(AkismetComment comment) {
            bool value = false;

            value = Convert.ToBoolean(HttpPost(String.Format(commentCheckUrl, apiKey), CreateData(comment), CharSet));

#if DEBUG
            Console.WriteLine("CommentCheck() = {0}.", value);
#endif

            return value;
        }
示例#6
0
        /// <summary>Checks AkismetComment object against Akismet database.</summary>
        /// <param name="comment">AkismetComment object to check.</param>
        /// <returns>'True' if spam, 'False' if not spam.</returns>
        public bool CommentCheck(AkismetComment comment)
        {
            bool value = false;

            value = Convert.ToBoolean(HttpPost(String.Format(commentCheckUrl, apiKey), CreateData(comment), CharSet));

#if DEBUG
            Console.WriteLine("CommentCheck() = {0}.", value);
#endif

            return(value);
        }
示例#7
0
        public bool CommentCheck(AkismetComment comment)
        {
            var isSpam = false;

            SpamQualifiers.ForEach(spam =>
            {
                if (!isSpam && comment.CommentContent.Contains(spam))
                    isSpam = true;
            });

            return isSpam;
        }
        public AkismetStatus ProcessComment()
        {
            var akismetEnabled = _settingsRepository.BlogAkismetEnabled;
            var deleteSpam     = _settingsRepository.BlogAkismetDeleteSpam;
            var akismetStatus  = new AkismetStatus();

            if (akismetEnabled && !_requestData.IsAuthenticated)
            {
                /* If the url or akismet key is invalid, this part
                 * might throw an exception. If it does, the comment
                 * is swallowed, as we do not know the status of the
                 * comment. If it happens, just correct the url or the
                 * key and you should be fine!
                 *
                 * */

                var comment          = AkismetComment.Create(_commentEntity, _requestData);
                var akistmetPipeline = new AkismetPipeline(_akismetService);

                try
                {
                    akismetStatus = akistmetPipeline.Process(comment, _settingsRepository);

                    if (akismetStatus.IsSpam && !deleteSpam)
                    {
                        _commentEntity.CommentStatus = 2; // its spam
                        _commentRepository.AddComment(_commentEntity);
                    }
                    else if (akismetStatus.IsHam)
                    {
                        _commentEntity.CommentStatus = 0;
                        _commentRepository.AddComment(_commentEntity);
                    }
                }
                catch (Exception exception)
                {
                    _error.InsertException(exception);
                }
            }
            else
            {
                // submit the comment, mark as approved if the user is logged in
                _commentEntity.CommentStatus = _requestData.IsAuthenticated ? 0 : 1;
                _commentRepository.AddComment(_commentEntity);
            }

            return(akismetStatus);
        }
示例#9
0
文件: AkismetTest.cs 项目: LByron/BS
        public void SubmitHam()
        {
            var comment = new AkismetComment
                {
                    Blog = blog,
                    UserIp = "127.0.0.1",
                    UserAgent =
                        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
                    CommentContent = "Hey, I'm testing out the Akismet API!",
                    CommentType = "blog",
                    CommentAuthor = "Joel",
                    CommentAuthorEmail = "",
                    CommentAuthorUrl = ""
                };

            api.SubmitHam(comment);
        }
示例#10
0
        public void SubmitSpam()
        {
            var comment = new AkismetComment
                {
                    Blog = blog,
                    UserIp = "147.202.45.202",
                    UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)",
                    CommentContent =
                        "A friend of mine told me about this place. I'm just wondering if this thing works.   You check this posts everyday incase <a href=\"http://someone.finderinn.com\">find someone</a> needs some help?  I think this is a great job! Really nice place http://someone.finderinn.com here.   I found a lot of interesting stuff all around.  I enjoy beeing here and i'll come back soon. Many greetings.",
                    CommentType = "blog",
                    CommentAuthor = "someone",
                    CommentAuthorEmail = "*****@*****.**",
                    CommentAuthorUrl = "http://someone.finderinn.com"
                };

            api.SubmitSpam(comment);
        }
示例#11
0
        /// <summary>Takes an AkismetComment object and returns an (escaped) string of data to POST.</summary>
        /// <param name="comment">AkismetComment object to translate.</param>
        /// <returns>A System.String containing the data to POST to Akismet API.</returns>
        private string CreateData(AkismetComment comment)
        {
            string value = String.Format("blog={0}&user_ip={1}&user_agent={2}&referrer={3}&permalink={4}&comment_type={5}" +
                                         "&comment_author={6}&comment_author_email={7}&comment_author_url={8}&comment_content={9}",
                                         UrlEncoder.UrlEncode(comment.Blog),
                                         UrlEncoder.UrlEncode(comment.UserIp),
                                         UrlEncoder.UrlEncode(comment.UserAgent),
                                         UrlEncoder.UrlEncode(comment.Referrer),
                                         UrlEncoder.UrlEncode(comment.Permalink),
                                         UrlEncoder.UrlEncode(comment.CommentType),
                                         UrlEncoder.UrlEncode(comment.CommentAuthor),
                                         UrlEncoder.UrlEncode(comment.CommentAuthorEmail),
                                         UrlEncoder.UrlEncode(comment.CommentAuthorUrl),
                                         UrlEncoder.UrlEncode(comment.CommentContent)
                                         );

            return(value);
        }
示例#12
0
文件: AkismetTest.cs 项目: LByron/BS
        public void NonSpamTest()
        {
            var comment = new AkismetComment
                {
                    Blog = blog,
                    UserIp = "127.0.0.1",
                    UserAgent =
                        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
                    CommentContent = "Hey, I'm testing out the Akismet API!",
                    CommentType = "blog",
                    CommentAuthor = "Joel",
                    CommentAuthorEmail = "",
                    CommentAuthorUrl = ""
                };

            bool result = api.CommentCheck(comment);

            Assert.IsFalse(result, "API was expected to return 'False' when 'True' was returned instead.");
        }
示例#13
0
        /// <summary>Takes an AkismetComment object and returns an (escaped) string of data to POST.</summary>
        /// <param name="comment">AkismetComment object to translate.</param>
        /// <returns>A System.String containing the data to POST to Akismet API.</returns>
        private string CreateData(AkismetComment comment) {
            string value = String.Format("blog={0}&user_ip={1}&user_agent={2}&referrer={3}&permalink={4}&comment_type={5}" +
                "&comment_author={6}&comment_author_email={7}&comment_author_url={8}&comment_content={9}",
                UrlEncoder.UrlEncode(comment.Blog),
                UrlEncoder.UrlEncode(comment.UserIp),
                UrlEncoder.UrlEncode(comment.UserAgent),
                UrlEncoder.UrlEncode(comment.Referrer),
                UrlEncoder.UrlEncode(comment.Permalink),
                UrlEncoder.UrlEncode(comment.CommentType),
                UrlEncoder.UrlEncode(comment.CommentAuthor),
                UrlEncoder.UrlEncode(comment.CommentAuthorEmail),
                UrlEncoder.UrlEncode(comment.CommentAuthorUrl),
                UrlEncoder.UrlEncode(comment.CommentContent)
            );

            return value;
        }
示例#14
0
 public void SubmitSpam(AkismetComment comment)
 {
 }