Exemplo n.º 1
0
        /// <summary>
        /// Checks the comment and returns true if it is spam, otherwise false.
        /// </summary>
        /// <param name="currentStartPage"></param>
        /// <param name="comment"></param>
        /// <returns></returns>
        public bool CheckCommentForSpam(ContentItem currentStartPage, IAntiSpamComment comment)
        {
            string result = SubmitComment(currentStartPage, comment, _checkUrl);

            if (string.IsNullOrEmpty(result))
                throw new InvalidResponseException("Akismet returned an empty response");

            if (result != "true" && result != "false")
                throw new InvalidResponseException(string.Format(CultureInfo.InvariantCulture,
                    "Received the response '{0}' from Akismet. Probably a bad API key.",
                    result));

            return bool.Parse(result);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Submits a comment to Akismet that should have been 
 /// flagged as SPAM, but was not flagged by Akismet.
 /// </summary>
 /// <param name="currentStartPage"></param>
 /// <param name="comment"></param>
 /// <returns></returns>
 public virtual void SubmitSpam(ContentItem currentStartPage, IAntiSpamComment comment)
 {
     SubmitComment(currentStartPage, comment, _submitSpamUrl);
 }
Exemplo n.º 3
0
        string SubmitComment(ContentItem currentStartPage, IAntiSpamComment comment, Url url)
        {
            // Not too many concatenations.  Might not need a string builder.
            string parameters = "blog=" + HttpUtility.UrlEncode(_webContext.GetFullyQualifiedUrl(currentStartPage.Url))
                + "&user_ip=" + comment.IPAddress
                + "&user_agent=" + HttpUtility.UrlEncode(comment.UserAgent);

            if (!string.IsNullOrEmpty(comment.Referrer))
                parameters += "&referer=" + HttpUtility.UrlEncode(comment.Referrer);

            if (comment.Permalink != null)
                parameters += "&permalink=" + HttpUtility.UrlEncode(comment.Permalink.ToString());

            if (!string.IsNullOrEmpty(comment.CommentType))
                parameters += "&comment_type=" + HttpUtility.UrlEncode(comment.CommentType);

            if (!string.IsNullOrEmpty(comment.Author))
                parameters += "&comment_author=" + HttpUtility.UrlEncode(comment.Author);

            if (!string.IsNullOrEmpty(comment.AuthorEmail))
                parameters += "&comment_author_email=" + HttpUtility.UrlEncode(comment.AuthorEmail);

            if (comment.AuthorUrl != null)
                parameters += "&comment_author_url=" + HttpUtility.UrlEncode(comment.AuthorUrl.ToString());

            if (!string.IsNullOrEmpty(comment.Content))
                parameters += "&comment_content=" + HttpUtility.UrlEncode(comment.Content);

            if (comment.ServerEnvironmentVariables != null)
                foreach (string key in comment.ServerEnvironmentVariables)
                    parameters += "&" + key + "=" + HttpUtility.UrlEncode(comment.ServerEnvironmentVariables[key]);

            return _httpClient.PostRequest(url, _userAgent, _configuration.Timeout, parameters).ToLowerInvariant();
        }