コード例 #1
0
        public bool CheckForSpam(PostComments.Comment comment)
        {
            var api = get_api();
            if (api == null)
            {
                return false;
            }

            var ac = get_comment(comment);

            #if DEBUG
            return false;
            #else
            var isSpam = api.IsSpam(ac);

            _log.Trace("Comment: {0} is Spam: {1}", comment.ToJson(), isSpam);

            return isSpam;
            #endif
        }
コード例 #2
0
ファイル: MetaWeblog.cs プロジェクト: Gutek/MovingScrewdriver
        string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
        {
            _log.Trace("Adding new blog post. Blogid: {0}, Publish: {1}, Post: {2}", blogid, publish, post.ToJson());

            Models.Post newPost;
            using (var session = _store.OpenSession())
            {
                var user = validate_user(username, password);
                var comments = new PostComments
                {
                    Comments = new List<PostComments.Comment>(),
                    Spam = new List<PostComments.Comment>()
                };
                session.Store(comments);

                var currentDate = ApplicationTime.Current;
                var publishDate = post.dateCreated  == null ? currentDate : _schedule.Schedule(new DateTimeOffset(post.dateCreated.Value));

                var cat = post.categories == null ? new List<string>() : post.categories.ToList();
                var key = post.mt_keywords.IsNullOrWhiteSpace() ? new List<string>() : post.mt_keywords.Split(',').ToList();

                newPost = new Models.Post
                {
                    AuthorId = user.Id,
                    Content = post.description,
                    CommentsId = comments.Id,
                    Created = currentDate,
                    Modified = currentDate,
                    PublishAt = publishDate,
                    Categories = cat.Select(x => new Models.Post.SlugItem { Title = x }).ToList(),
                    Tags = key.Select(x => new Models.Post.SlugItem { Title = x }).ToList(),
                    Title = HttpUtility.HtmlDecode(post.title),
                    CommentsCount = 0,
                    AllowComments = true,
                };

                // only send notification when post is published!
                if (publishDate == currentDate)
                {
                    try
                    {
                        _notification.Send(newPost
                            , new Uri(Url.AbsoluteAction("Details", "PostDetails", newPost.ToRouteData())));
                        newPost.NotificationSend = true;
                    }
                    catch (Exception ex)
                    {
                        newPost.NotificationSend = false;
                    }
                }

                session.Store(newPost);
                comments.Post = new PostComments.PostReference
                {
                    Id = newPost.Id,
                    Published = publishDate,
                    Slug = newPost.Slug
                };

                session.SaveChanges();
            }

            return newPost.Id;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Gutek/MovingScrewdriver
        public void ImportBlogMl()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tCreating Users...");
            using (var session = _store.OpenSession())
            {
                var user = new BlogOwner
                {
                    Id = "Blog/Owner",
                    Email = "",
                    FirstName = "",
                    LastName = "",
                    Nick = "",
                    Twitter = ""
                };

                user.ResetPassword("admin123");

                session.Store(user);
                session.SaveChanges();
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tImporting Posts...");

            foreach (var oldPost in _blog.Posts)
            {
                var post = new Post
                {
                    AuthorId = "Blog/Owner",
                    Created = new DateTimeOffset(oldPost.DateCreated),
                    Modified = new DateTimeOffset(oldPost.DateCreated),
                    PublishAt = new DateTimeOffset(oldPost.DateCreated),
                    Content = oldPost.Content.Text.Replace("http:/URL/image.axd?picture=", "http://URL/content/old-images/"),

                    Title = HttpUtility.HtmlDecode(oldPost.Title),
                    Slug = SlugConverter.TitleToSlug(HttpUtility.HtmlDecode(oldPost.Title)),
                    LegacyUniqueId = oldPost.ID,
                    LegacySlug = Regex.Match(oldPost.PostUrl, @"([^/]+)(?=\.\w+$)").Value,

                    AllowComments = true
                };

                var categoriesRefs = oldPost.Categories.OfType<BlogMLCategoryReference>();
                var oldCategories = from x in categoriesRefs
                                    join z in _blog.Categories on x.Ref equals z.ID
                                    select new Post.SlugItem
                                    {
                                        Title = z.Title
                                    };

                var oldTags = from x in oldPost.Tags.OfType<BlogMLTagReference>()
                              select new Post.SlugItem
                              {
                                Title = x.Ref
                              };

                post.Categories = oldCategories.ToList();
                post.Tags = oldTags.ToList();

                var commentsCollection = new PostComments();

                foreach (var oldComment in oldPost.Comments.OfType<BlogMLComment>())
                {
                    var comment = new PostComments.Comment
                    {
                        Id = commentsCollection.GenerateNewCommentId(),
                        Author = oldComment.UserName,
                        Content = convert_to_markdown(oldComment.Content.Text),
                        Created = oldComment.DateCreated,
                        Email = oldComment.UserEMail,
                        Type = CommentType.Comment,
                        Url = oldComment.UserUrl,
                        Important = oldComment.UserEMail.Equals("EMAIL", StringComparison.OrdinalIgnoreCase),
                        UserAgent = string.Empty,
                        UserHostAddress = oldComment.UserIp,
                        IsSpam = oldComment.Approved == false,
                    };

                    if (oldComment.Approved)
                    {
                        commentsCollection.Comments.Add(comment);
                    }
                    else
                    {
                        commentsCollection.Spam.Add(comment);
                    }

                }

                foreach (var trackbacks in oldPost.Trackbacks.OfType<BlogMLTrackback>())
                {
                    var comment = new PostComments.Comment
                    {
                        Id = commentsCollection.GenerateNewCommentId(),
                        Type = CommentType.Trackback,
                        Author = trackbacks.UserName,
                        Content = trackbacks.Content.Text,
                        Created = trackbacks.DateCreated,
                        Email = CommentType.Trackback.ToString(),
                        Url = trackbacks.Url,
                        Important = false,
                        UserAgent = string.Empty,
                        UserHostAddress = trackbacks.UserIp,
                        IsSpam = trackbacks.Approved == false,
                    };

                    if (trackbacks.Approved)
                    {
                        commentsCollection.Comments.Add(comment);
                    }
                    else
                    {
                        commentsCollection.Spam.Add(comment);
                    }
                }

                post.CommentsCount = commentsCollection.Comments.Count;

                using (IDocumentSession session = _store.OpenSession())
                {
                    session.Store(commentsCollection);
                    post.CommentsId = commentsCollection.Id;

                    session.Store(post);
                    commentsCollection.Post = new PostComments.PostReference
                    {
                        Id = post.Id,
                        Published = post.PublishAt,
                        Slug = post.Slug
                    };

                    session.SaveChanges();
                }
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tDone...");
        }
コード例 #4
0
        public void SubmitHam(PostComments.Comment comment)
        {
            var api = get_api();
            if (api == null)
            {
                return;
            }

            var ac = get_comment(comment);

            #if !DEBUG
            api.SubmitHam(ac);
            #endif
        }
コード例 #5
0
 private Comment get_comment(PostComments.Comment comment)
 {
     return new Comment
     {
         blog = Domain,
         user_ip = comment.UserHostAddress,
         user_agent = comment.UserAgent,
         comment_author = comment.Author,
         comment_author_email = comment.Email,
         comment_author_url = comment.Url,
         comment_content = comment.Content,
         comment_type = comment.Type.ToString().ToLowerInvariant()
     };
 }