Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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;
                }
            }
        }
Esempio n. 3
0
        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;
                }
            }
        }