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..."); }
public ActionResult Trackback(string blog_name, string url, string title, string excerpt, int id) { var model = new TrackbackInput { blog_name = blog_name, url = url, title = title, excerpt = excerpt }; if (model.url.IsNullOrWhiteSpace()) { return TrackbackError("URL Is Missing"); } var post = CurrentSession .Include<Post>(x => x.CommentsId) .Load<Post>(id); if (post == null) { return RedirectToAction("AllPosts", "Posts"); } var postUrl = Url.Action("Details", "PostDetails", post.ToRouteData()); if (postUrl.ExistsOn(model.url) == false) { return TrackbackError("The source page does not link"); } var comments = CurrentSession.Load<PostComments>(post.CommentsId); if (comments.AreCommentsClosed(post, BlogConfig.NumberOfDayToCloseComments) || post.AllowComments == false) { return TrackbackError("Comments closed"); } var trackbackExists = comments.Comments.TrackbackOrPingbackExists(model.url); if (trackbackExists) { return TrackbackError("Trackback already registered"); } var comment = new PostComments.Comment(); comment.Id = comments.GenerateNewCommentId(); comment.Created = ApplicationTime.Current; comment.Content = "Trackback od {0} - {1}".FormatWith(model.title, model.excerpt); comment.Author = model.blog_name; comment.Type = CommentType.Trackback; comment.UserAgent = GeneralUtils.GetClientAgent(); comment.UserHostAddress = GeneralUtils.GetClientIp(); comment.Email = CommentType.Trackback.ToString(); comment.Url = model.url; comment.IsSpam = _akismetService.CheckForSpam(comment); if (comment.IsSpam) { comments.Spam.Add(comment); } else { post.CommentsCount++; comments.Comments.Add(comment); } return TrackbackSuccess(); }
string IPingbackService.pingback(string sourceUri, string targetUri) { if (sourceUri.IsNullOrEmpty()) { _log.Trace("Wrong param for pinback: sourceUri"); throw new XmlRpcFaultException(16, "The source URI does not exist."); } if (targetUri.IsNullOrEmpty()) { _log.Trace("Wrong param for pinback: targetUri"); throw new XmlRpcFaultException(32, "The specified target URI does not exist."); } var title = string.Empty; if (targetUri.ExistsOn(sourceUri, out title) == false) { _log.Warn("SPAM: someone tried to add pinback without linking to our site. Source URI: {0}. Pinback to: {1}", sourceUri, targetUri); throw new XmlRpcFaultException(17, "The source URI does not contain a link to the target URI, and so cannot be used as a source."); } var slug = get_slug(targetUri); _log.Trace("Target uri: {0}, slug: {1}", targetUri, slug); using (var session = _store.OpenSession()) { var config = session.Load<ScrewdriverConfig>("Blog/Config"); var post = session.Query<Post>() .Include(x => x.CommentsId) .WhereIsPublicPost() .WithSlug(slug) .FirstOrDefault(); if (post == null) { _log.Trace("The specified target URI cannot be used as a target. It either doesn't exist, or it is not a pingback-enabled resource."); throw new XmlRpcFaultException(33, "The specified target URI cannot be used as a target. It either doesn't exist, or it is not a pingback-enabled resource."); } var comments = session.Load<PostComments>(post.CommentsId); if (comments.AreCommentsClosed(post, config.NumberOfDayToCloseComments) || post.AllowComments == false) { _log.Trace("Comments closed, pinback blocked for target URI: {0}", targetUri); throw new XmlRpcFaultException(33, "The specified target URI cannot be used as a target. It either doesn't exist, or it is not a pingback-enabled resource."); } var exists = comments.Comments.TrackbackOrPingbackExists(sourceUri); if (exists) { _log.Trace("Pingback from {0} already exists on {1}", sourceUri, targetUri); throw new XmlRpcFaultException(48, "The pingback has already been registered."); } var comment = new PostComments.Comment(); comment.Id = comments.GenerateNewCommentId(); comment.Created = ApplicationTime.Current; comment.Author = GeneralUtils.GetDomain(sourceUri); comment.Email = CommentType.Pingback.ToString(); comment.Type = CommentType.Pingback; comment.Url = sourceUri; comment.UserAgent = GeneralUtils.GetClientAgent(); comment.UserHostAddress = GeneralUtils.GetClientIp(); comment.Content = "Pingback z {0} - {1}".FormatWith(comment.Author, title); var isSpam = _akismetService.CheckForSpam(comment); if (isSpam) { comment.IsSpam = true; comments.Spam.Add(comment); } else { post.CommentsCount++; comments.Comments.Add(comment); } session.SaveChanges(); } return "Your ping request has been received successfully.!"; }