private void GetPosts(Blog blog, BlogMLBlog blogMLBlog) { foreach (var blogMLPost in blogMLBlog.Posts) { Post post = new Post(); post.ID = blogMLPost.ID; post.HasExcerpt = blogMLPost.HasExcerpt; if (post.HasExcerpt) post.Excerpt = new Content { Type = blogMLPost.Excerpt.ContentType.ToString().ToLowerInvariant(), Value = blogMLPost.Excerpt.Text }; foreach (BlogMLAttachment blogMLAttachment in blogMLPost.Attachments) { Attachment attachment = new Attachment(); attachment.Embedded = blogMLAttachment.Embedded; attachment.Value = blogMLAttachment.Data; attachment.MimeType = blogMLAttachment.MimeType; attachment.ExternalURI = blogMLAttachment.Path; attachment.URL = blogMLAttachment.Url; post.Attachments.AttachmentList.Add(attachment); } foreach (BlogMLAuthorReference blogMLAuthor in blogMLPost.Authors) { AuthorReference authorReference = new AuthorReference(); authorReference.ID = blogMLAuthor.Ref; post.Authors.AuthorReferenceList.Add(authorReference); } foreach (BlogMLCategoryReference blogMLCategory in blogMLPost.Categories) { CategoryReference categoryReference = new CategoryReference(); categoryReference.ID = blogMLCategory.Ref; post.Categories.CategoryReferenceList.Add(categoryReference); } foreach (BlogMLComment blogMLComment in blogMLPost.Comments) { Comment comment = new Comment(); comment.ID = blogMLComment.ID; comment.Approved = blogMLComment.Approved; comment.Content = new Content { Type = blogMLComment.Content.ContentType.ToString().ToLowerInvariant(), Value = blogMLComment.Content.Text }; comment.DateCreated = blogMLComment.DateCreated; comment.DateModified = blogMLComment.DateModified; comment.Title = blogMLComment.Title; comment.UserEmail = blogMLComment.UserEMail; comment.UserName = blogMLComment.UserName; comment.UserURL = blogMLComment.UserUrl; post.Comments.CommentList.Add(comment); } // hmm do I care? //foreach (BlogMLTrackback blogMLTrackback in blogMLPost.Trackbacks) { // Trackback trackback = new Trackback(); // trackback.ID = blogMLTrackback.ID; // trackback.Approved = blogMLTrackback.Approved; // trackback.DateCreated = blogMLTrackback.DateCreated; // trackback.DateModified = blogMLTrackback.DateModified; // trackback.Title = blogMLTrackback.Title; // trackback.Url = blogMLTrackback.Url; //} post.Approved = blogMLPost.Approved; post.Content = new Content { Type = blogMLPost.Content.ContentType.ToString().ToLowerInvariant(), Value = blogMLPost.Content.Text }; post.DateCreated = blogMLPost.DateCreated; post.DateModified = blogMLPost.DateModified; post.HasExcerpt = blogMLPost.HasExcerpt; if (post.HasExcerpt) post.Excerpt = new Content { Type = blogMLPost.Excerpt.ContentType.ToString().ToLowerInvariant(), Value = blogMLPost.Excerpt.Text }; post.PostName = new Title {Type = Content.TypeHTML, Value = blogMLPost.PostName}; post.PostUrl = blogMLPost.PostUrl; post.Title = blogMLPost.Title; post.Type = blogMLPost.PostType.ToString(); post.Views = blogMLPost.Views; blog.Posts.PostList.Add(post); } }
internal static Post AssemblePost(WordpressNamespaces namespaces, XElement postElement) { Post post = new Post(); // Node (parent) properties. post.ID = postElement.WordpressElement(namespaces, "post_id").Value; post.Title = postElement.Element("title").Value; post.DateCreated = DateTime.Parse(Constants.ParseRssDate(postElement.Element("pubDate").Value)); post.DateModified = DateTime.Parse(Constants.ParseRssDate(postElement.Element("pubDate").Value)); post.PostUrl = (new Uri(postElement.Element("link").Value).AbsolutePath).TrimStart('/'); // NGM post.Approved = true; // Object properties. post.Content = new Content(); post.Content.Type = Content.TypeHTML; post.Content.Value = ((XCData)postElement.ContentElement(namespaces, "encoded").FirstNode).Value; post.PostName = new Title(); post.PostName.Type = Content.TypeHTML; post.PostName.Value = postElement.Element("title").Value; string excerpt = ((XCData)postElement.Element(namespaces.ExcerptNamespace + "encoded").FirstNode).Value; if (String.Empty == excerpt) { post.HasExcerpt = false; } else { post.Excerpt = new Content(); post.Excerpt.Type = Content.TypeHTML; post.Excerpt.Value = excerpt; post.HasExcerpt = true; } // Category references. IEnumerable<XElement> categories = from cat in postElement.Elements("category") where cat.Attribute("domain") != null && cat.Attribute("domain").Value == "category" select cat; if (categories.Any()) { post.Categories = new CategoryReferences(); foreach(XElement reference in categories) { post.Categories.CategoryReferenceList.Add(AssembleCategoryReference(reference)); } } // Tag references. IEnumerable<XElement> tags = from tag in postElement.Elements("category") where tag.Attribute("domain") != null && (tag.Attribute("domain").Value == "post_tag" || tag.Attribute("domain").Value == "tag") && tag.Attribute("nicename") != null select tag; if (tags.Any()) { post.Tags = new TagReferences(); foreach (XElement reference in tags) { post.Tags.TagReferenceList.Add(new TagReference(reference)); } } // Comments on this post. IEnumerable<XElement> comments = from comment in postElement.Elements(namespaces.WpNamespace + "comment") where comment.WordpressElement(namespaces, "comment_approved").Value == "1" && string.IsNullOrEmpty(comment.WordpressElement(namespaces, "comment_type").Value) select comment; post.Comments = new Comments(); if (comments.Any()) { foreach(XElement comment in comments) { post.Comments.CommentList.Add(AssembleComment(namespaces, comment)); } } if (postElement.WordpressElement(namespaces, "comment_status").Value == "open") post.Comments.Enabled = true; else { post.Comments.Enabled = false; } // Trackbacks for this post. IEnumerable<XElement> trackbax = from tb in postElement.Elements(namespaces.WpNamespace + "comment") where tb.WordpressElement(namespaces, "comment_approved").Value == "1" && ((tb.WordpressElement(namespaces, "comment_type").Value == "trackback") || (tb.WordpressElement(namespaces, "comment_type").Value == "pingback")) select tb; if (trackbax.Any()) { post.Trackbacks = new Trackbacks(); foreach(XElement trackback in trackbax) { post.Trackbacks.TrackbackList.Add(AssembleTrackback(namespaces, trackback)); } } post.Authors = new AuthorReferences(); post.Authors.AuthorReferenceList.Add(new AuthorReference { ID = postElement.Element(namespaces.DcNamespace + "creator").Value }); return post; }