Esempio n. 1
0
 public Post()
     : base()
 {
     // These are the only required item.
     Content = new Content();
     Authors = new AuthorReferences();
 }
Esempio n. 2
0
        /// <summary>
        /// Constructor for a filled post.
        /// </summary>
        /// <param name="item">
        /// The WXR post element.
        /// </param>
        public Post(XElement item)
        {
            // Node (parent) properties.
            ID          = item.Element(Util.wpNamespace + "post_id").Value;
            Title       = item.Element("title").Value;
            DateCreated = Util.ParseRSSDate(item.Element("pubDate").Value);
            Approved    = "true";

            // Object properties.
            Content       = new Content();
            Content.Type  = Content.TypeHTML;
            Content.Value = Util.ReplaceCRLF(((XCData)item.Element(Util.contentNamespace + "encoded").FirstNode).Value);

            PostName       = new Title();
            PostName.Type  = Content.TypeHTML;
            PostName.Value = item.Element("title").Value;

            var excerptNode = item.Element(Util.excerptNamespace + "encoded");

            if (null == excerptNode)
            {
                HasExcerpt = false;
            }
            else
            {
                var excerpt = ((XCData)excerptNode.FirstNode).Value;

                if (String.Empty == excerpt)
                {
                    HasExcerpt = false;
                }
                else
                {
                    Excerpt       = new Content();
                    Excerpt.Type  = Content.TypeHTML;
                    Excerpt.Value = excerpt;
                    HasExcerpt    = true;
                }
            }

            // Category references.
            var categories =
                from cat in item.Elements("category")
                where cat.Attribute("domain") != null && cat.Attribute("domain").Value == "category"
                select cat;

            if (0 < categories.Count())
            {
                Categories = new CategoryReferences();

                foreach (var reference in categories)
                {
                    Categories.CategoryReferenceList.Add(new CategoryReference(reference));
                }
            }

            // Tags for this post.
            var tags =
                from tag in item.Elements("category")
                where tag.Attribute("domain") != null && tag.Attribute("domain").Value == "post_tag"
                select tag;

            if (0 < tags.Count())
            {
                Tags = new TagReferences();

                foreach (var reference in tags)
                {
                    Tags.TagReferenceList.Add(new TagReference(reference));
                }
            }

            // Comments on this post.
            var comments =
                from comment in item.Elements(Util.wpNamespace + "comment")
                where comment.Element(Util.wpNamespace + "comment_approved").Value == "1" &&
                comment.Element(Util.wpNamespace + "comment_type").Value == String.Empty
                select comment;

            if (0 < comments.Count())
            {
                Comments = new Comments();

                foreach (var comment in comments)
                {
                    Comments.CommentList.Add(new Comment(comment));
                }
            }

            // Trackbacks for this post.
            var trackbax =
                from tb in item.Elements(Util.wpNamespace + "comment")
                where tb.Element(Util.wpNamespace + "comment_approved").Value == "1" &&
                ((tb.Element(Util.wpNamespace + "comment_type").Value == "trackback") ||
                 (tb.Element(Util.wpNamespace + "comment_type").Value == "pingback"))
                select tb;

            if (0 < trackbax.Count())
            {
                Trackbacks = new Trackbacks();

                foreach (var trackback in trackbax)
                {
                    Trackbacks.TrackbackList.Add(new Trackback(trackback));
                }
            }

            Authors     = new AuthorReferences();
            Attachments = new Attachments();
        }