private void GetCategories(Blog blog, WordpressNamespaces namespaces, XElement channel) { // Loop through the elements and build the category list. IEnumerable<XElement> categories = from cat in channel.Elements(namespaces.WpNamespace + "category") select cat; foreach (XElement categoryElement in categories) { var createdCategory = InternalSchemaAssemblers.AssembleCategory(namespaces, categoryElement); if (blog.Categories.CategoryList.All(o => o.ID != createdCategory.ID)) blog.Categories.CategoryList.Add(createdCategory); } // WordPress stores the parent category as the description, but BlogML wants the ID. Now that we have a // complete list, we'll go back through and fix them. IEnumerable<Category> children = from a in blog.Categories.CategoryList where a.ParentCategory != null select a; foreach (Category child in children) { IEnumerable<Category> parent = from a in blog.Categories.CategoryList where a.Title == child.ParentCategory select a; if (parent.Any()) { child.ParentCategory = parent.ElementAt(0).ID; } } }
private Blog CreateTopLevelBlog(WordpressNamespaces namespaces, XElement channel) { Blog blog = new Blog(_clock); blog.DateCreated = DateTime.Parse(Constants.ParseRssDate(channel.Element("pubDate").Value)); blog.Title = new Title(); blog.Title.Value = channel.Element("title").Value; blog.SubTitle = new Title(); blog.SubTitle.Value = channel.Element("description").Value; // This is the first element we use the WP namespace; make sure it works. // (See issue #4 - thanks to stephenway for reporting it.) var rootUrlElement = channel.WordpressElement(namespaces, "base_blog_url"); if (rootUrlElement == null) throw new NotSupportedException("Unable to determine the blog base URL."); blog.RootURL = rootUrlElement.Value; blog.Authors = new Authors(); blog.Categories = new Categories(); blog.Tags = new Tags(); blog.Posts = new Posts(); return blog; }
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); } }
private Blog CreateTopLevelBlog(BlogMLBlog blogMLBlog) { Blog blog = new Blog(_clock); blog.DateCreated = blogMLBlog.DateCreated; blog.Title = new Title(); blog.Title.Value = blogMLBlog.Title; blog.SubTitle = new Title(); blog.SubTitle.Value = blogMLBlog.SubTitle; blog.RootURL = blogMLBlog.RootUrl; blog.Authors = new Authors(); blog.Categories = new Categories(); blog.Tags = new Tags(); blog.Posts = new Posts(); return blog; }
private void GetCategories(Blog blog, BlogMLBlog blogMLBlog) { foreach (var blogMLcategory in blogMLBlog.Categories) { Category category = new Category(); category.ID = blogMLcategory.ID; category.Approved = blogMLcategory.Approved; category.DateCreated = blogMLcategory.DateCreated; category.DateModified = blogMLcategory.DateModified; category.Description = blogMLcategory.Description; category.ParentCategory = blogMLcategory.ParentRef; category.Title = blogMLcategory.Title; blog.Categories.CategoryList.Add(category); } }
private void GetAuthors(Blog blog, BlogMLBlog blogMLBlog) { foreach (var blogMLAuthor in blogMLBlog.Authors) { Author author = new Author(); author.ID = blogMLAuthor.ID; author.Approved = blogMLAuthor.Approved; author.DateCreated = blogMLAuthor.DateCreated; author.DateModified = blogMLAuthor.DateModified; author.Email = blogMLAuthor.Email; author.Title = blogMLAuthor.Title; blog.Authors.AuthorList.Add(author); } }
private void ImportBlog(Blog blog, ImportSettings importSettings) { _blogImportStrategy.Import(importSettings, blog, null); RebuildOrchardIndexes(); _orchardServices.Notifier.Information(T("Blog Import has completed successfully. All errors will be listed below, and you may review report generated via the reports link in the menu at anytime.")); }
private string GetAuthorReference(Blog blog, string author) { string id = Constants.Slug(author); IEnumerable<Author> authors = from a in blog.Authors.AuthorList where a.ID == id select a; if (!authors.Any()) { // Author not found - let's create them! Author newAuthor = new Author(); newAuthor.ID = id; newAuthor.Email = id + "@" + (new Uri(blog.RootURL)).Host; newAuthor.Title = author; blog.Authors.AuthorList.Add(newAuthor); } return id; }
private void GetPosts(Blog blog, WordpressNamespaces namespaces, XElement channel) { IEnumerable<XElement> posts = from item in channel.Elements("item") where item.WordpressElement(namespaces, "status").Value == "publish" select item; // NGM Might want update urls within content to stop redirects? foreach (XElement item in posts) { Post post = InternalSchemaAssemblers.AssemblePost(namespaces, item); // We need to get the author reference separately, as we need the AuthorList from the blog. AuthorReference author = new AuthorReference(); author.ID = GetAuthorReference(blog, ((XText)item.Element(namespaces.DcNamespace + "creator").FirstNode).Value); post.Authors.AuthorReferenceList.Add(author); blog.Posts.PostList.Add(post); } }
private void GetTags(Blog blog, WordpressNamespaces namespaces, XElement channel) { // Loop through the elements and build the category list. IEnumerable<XElement> tags = from tag in channel.Elements(namespaces.WpNamespace + "tag") select tag; foreach (XElement tagElement in tags) { var createdTag = InternalSchemaAssemblers.AssembleTag(namespaces, tagElement); if (blog.Tags.TagList.All(o => o.ID != createdTag.ID)) blog.Tags.TagList.Add(createdTag); } // WordPress stores the parent category as the description, but BlogML wants the ID. Now that we have a // complete list, we'll go back through and fix them. IEnumerable<Tag> children = from a in blog.Tags.TagList where a.Slug != null select a; foreach (Tag child in children) { IEnumerable<Tag> parent = from a in blog.Tags.TagList where a.Title == child.Slug select a; if (0 < parent.Count()) { child.Slug = parent.ElementAt(0).ID; } } }