/// <summary> /// Check whether a topic is spam or not /// </summary> /// <param name="topic"></param> /// <returns></returns> public bool IsSpam(Topic topic) { // If akisment is is not enable always return false if (Dialogue.Settings().EnableAkismetSpamControl == false || string.IsNullOrEmpty(Dialogue.Settings().AkismetKey)) return false; // Akisment must be enabled var firstOrDefault = topic.Posts.FirstOrDefault(x => x.IsTopicStarter); if (firstOrDefault != null) { var comment = new Comment { blog = AppHelpers.CheckLinkHasHttp(Dialogue.Settings().ForumRootUrlWithDomain), comment_type = "comment", comment_author = topic.Member.UserName, comment_author_email = topic.Member.Email, comment_content = firstOrDefault.PostContent, permalink = String.Empty, referrer = HttpContext.Current.Request.ServerVariables["HTTP_REFERER"], user_agent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"], user_ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] }; var validator = new Validator(Dialogue.Settings().AkismetKey); return validator.IsSpam(comment); } return true; }
/// <summary> /// Check if the input comment is valid or not. /// </summary> /// <param name="comment">The input comment to be checked.</param> /// <returns>True if the comment is valid, false otherwise.</returns> public Boolean IsSpam(Comment comment) { // prepare pars for the request NameValueCollection pars = PreparePars(comment); if (null != pars) { // extract result from the request return ExtractResult(PostRequest(String.Format("http://{0}.rest.akismet.com/1.1/comment-check", m_key), pars)); } // return no spam return false; }
/// <summary> /// Prepare request parameters based on the input comment. /// </summary> /// <param name="comment">The input comment.</param> /// <returns>The prepared parameters if any.</returns> protected virtual NameValueCollection PreparePars(Comment comment) { // check the input parameters if ((null != comment) && (!comment.IsValid)) return null; // initialize result var result = new NameValueCollection(); // add required information result["blog"] = HttpUtility.UrlEncode(comment.blog); result["user_ip"] = HttpUtility.UrlEncode(comment.user_ip); result["user_agent"] = HttpUtility.UrlEncode(comment.user_agent); // add optional information result["referrer"] = String.IsNullOrEmpty(comment.referrer) ? String.Empty : HttpUtility.UrlEncode(comment.referrer); result["permalink"] = String.IsNullOrEmpty(comment.permalink) ? String.Empty : HttpUtility.UrlEncode(comment.permalink); result["comment_type"] = String.IsNullOrEmpty(comment.comment_type) ? String.Empty : HttpUtility.UrlEncode(comment.comment_type); result["comment_author"] = String.IsNullOrEmpty(comment.comment_author) ? String.Empty : HttpUtility.UrlEncode(comment.comment_author); result["comment_author_email"] = String.IsNullOrEmpty(comment.comment_author_email) ? String.Empty : HttpUtility.UrlEncode(comment.comment_author_email); result["comment_author_url"] = String.IsNullOrEmpty(comment.comment_author_url) ? String.Empty : HttpUtility.UrlEncode(comment.comment_author_url); result["comment_content"] = String.IsNullOrEmpty(comment.comment_content) ? String.Empty : HttpUtility.UrlEncode(comment.comment_content); // return result return result; }
/// <summary> /// This call is intended for the marking of false positives, things that were incorrectly marked as spam. /// </summary> /// <param name="comment">The input comment to be sent as ham.</param> /// <returns>True if the comment was successfully sent, false otherwise.</returns> public void SubmitHam(Comment comment) { // prepare pars for the request NameValueCollection pars = PreparePars(comment); if (null != pars) { PostRequest(String.Format("http://{0}.rest.akismet.com/1.1/submit-spam", m_key), pars); } }