コード例 #1
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);
        }
コード例 #2
0
ファイル: Comments.cs プロジェクト: harder/GraffitiCMS
        protected override void BeforeValidate()
        {
            base.BeforeValidate();

            //By default we allow no markup
            if (IsNew)
            {
                UniqueId = Guid.NewGuid();
                Body     = Util.ConvertTextToHTML(Body);

                IGraffitiUser gu = GraffitiUsers.Current;

                if (gu != null)
                {
                    if (!DontChangeUser)
                    {
                        Name        = gu.ProperName;
                        WebSite     = gu.WebSite;
                        Email       = gu.Email;
                        IsPublished = true;
                        UserName    = gu.Name;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(WebSite))
                    {
                        WebSite = HttpUtility.HtmlEncode(WebSite);
                    }

                    if (!string.IsNullOrEmpty(Email))
                    {
                        Email = HttpUtility.HtmlEncode(Email);
                    }

                    Name        = HttpUtility.HtmlEncode(Name);
                    SpamScore   = CommentSettings.ScoreComment(this, new Post(PostId));
                    IsPublished = SpamScore < CommentSettings.Get().SpamScore;
                }
            }
        }
コード例 #3
0
ファイル: MetaWeblog.cs プロジェクト: harder/GraffitiCMS
        public string newPost(string blogid, string username, string password, MetaWeblog.Post post, bool publish)
        {
            if (ValidateUser(username, password))
            {
                IGraffitiUser      user      = GraffitiUsers.Current;
                Graffiti.Core.Post postToAdd = new Graffiti.Core.Post();
                postToAdd.ContentType = "text/html";

                postToAdd.PostStatus     = (publish ? PostStatus.Publish : PostStatus.Draft);
                postToAdd.IsPublished    = publish;
                postToAdd.PostBody       = post.description;
                postToAdd.Title          = post.title;
                postToAdd.TagList        = post.GetTagList();
                postToAdd.UserName       = username;
                postToAdd.EnableComments = CommentSettings.Get().EnableCommentsDefault;

                if (post.categories != null && post.categories.Length > 0)
                {
                    postToAdd.CategoryId = AddOrFetchCategory(post.categories[0], user).Id;
                }
                else
                {
                    postToAdd.CategoryId = CategoryController.UnCategorizedId;
                }

                postToAdd.Name = post.GetSlug();

                if (!string.IsNullOrEmpty(post.mt_text_more))
                {
                    postToAdd.ExtendedBody = post.mt_text_more;
                }



                // Get UserTime safely (some clients pass in a DateTime that is not valid)
                try
                {
                    if (post.dateCreated != DateTime.MinValue)
                    {
                        DateTime dtUTC   = post.dateCreated;
                        DateTime dtLocal = dtUTC.ToLocalTime();
                        postToAdd.Published = dtLocal.AddHours(SiteSettings.Get().TimeZoneOffSet);
                    }
                }
                catch { postToAdd.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet); }

                if (postToAdd.Published <= new DateTime(2000, 1, 1))
                {
                    postToAdd.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet);
                }

                try
                {
                    return(PostRevisionManager.CommitPost(postToAdd, user, false, false).ToString());
                }
                catch (Exception ex)
                {
                    if (ex.Message.IndexOf("UNIQUE") > -1)
                    {
                        throw new XmlRpcFaultException(2, "Duplicate Post Name");
                    }

                    else
                    {
                        Log.Error("MetaBlog Error", "An error occored editing the post {0}. Exception: {1} Stack: {2}", post.postid, ex.Message, ex.StackTrace);
                        throw;
                    }
                }
            }


            throw new XmlRpcFaultException(0, "User does not exist");
        }