BlogEngine.Core.SyndicationGenerator.WriteRssItem C# (CSharp) Méthode

WriteRssItem() private static méthode

Writes the RSS channel item element information to the specified XmlWriter using the supplied Page.
private static WriteRssItem ( XmlWriter writer, IPublishable publishable ) : void
writer System.Xml.XmlWriter /// The to write channel item element information to. ///
publishable IPublishable /// The used to generate channel item content. ///
Résultat void
        private static void WriteRssItem(XmlWriter writer, IPublishable publishable)
        {
            // ------------------------------------------------------------
            // Cast IPublishable as Post to support comments/trackback
            // ------------------------------------------------------------
            var post = publishable as Post;
            var comment = publishable as Comment;

            // ------------------------------------------------------------
            // Raise serving event
            // ------------------------------------------------------------
            var arg = new ServingEventArgs(publishable.Content, ServingLocation.Feed);
            publishable.OnServing(arg);
            if (arg.Cancel)
            {
                return;
            }

            // ------------------------------------------------------------
            // Modify post content to make references absolute
            // ------------------------------------------------------------
            var content = Utils.ConvertPublishablePathsToAbsolute(arg.Body, publishable);

            if (comment != null)
            {
                content = content.Replace(Environment.NewLine, "<br />");
            }

            writer.WriteStartElement("item");

            // ------------------------------------------------------------
            // Write required channel item elements
            // ------------------------------------------------------------
            writer.WriteElementString("title", publishable.Title);
            writer.WriteElementString("description", content);
            writer.WriteElementString("link", publishable.AbsoluteLink.ToString());

            // ------------------------------------------------------------
            // Write enclosure tag for podcasting support
            // ------------------------------------------------------------
            if (BlogSettings.Instance.EnableEnclosures)
            {
                var encloser = GetEnclosure(content, publishable);
                if (!string.IsNullOrEmpty(encloser))
                {
                    writer.WriteRaw(encloser);
                }
            }

            // ------------------------------------------------------------
            // Write optional channel item elements
            // ------------------------------------------------------------
            if (!string.IsNullOrEmpty(BlogSettings.Instance.FeedAuthor))
            {
                writer.WriteElementString("author", BlogSettings.Instance.FeedAuthor);
            }
            if (post != null)
            {
                writer.WriteElementString(
                    "comments", String.Concat(publishable.AbsoluteLink.ToString(),
                    BlogSettings.Instance.ModerationType == BlogSettings.Moderation.Disqus ? "#disqus_thread" : "#comment"));
            }

            writer.WriteElementString("guid", GetPermaLink(publishable).ToString());
            writer.WriteElementString("pubDate", ToRfc822DateTime(publishable.DateCreated));

            // ------------------------------------------------------------
            // Write channel item category elements
            // ------------------------------------------------------------
            if (publishable.Categories != null)
            {
                foreach (var category in publishable.Categories)
                {
                    writer.WriteElementString("category", category.Title);
                }
            }

            // ------------------------------------------------------------
            // Write Dublin Core syndication extension elements
            // ------------------------------------------------------------
            if (!String.IsNullOrEmpty(publishable.Author))
            {
                writer.WriteElementString("dc", "publisher", "http://purl.org/dc/elements/1.1/", publishable.Author);
            }

            // if (!String.IsNullOrEmpty(publishable.Description))
            // {
            //     writer.WriteElementString("dc", "description", "http://purl.org/dc/elements/1.1/", publishable.Description);
            // }

            // ------------------------------------------------------------
            // Write pingback syndication extension elements
            // ------------------------------------------------------------
            Uri pingbackServer;
            if (Uri.TryCreate(
                String.Concat(publishable.Blog.AbsoluteWebRoot.ToString().TrimEnd('/'), "/pingback.axd"),
                UriKind.RelativeOrAbsolute,
                out pingbackServer))
            {
                writer.WriteElementString(
                    "pingback",
                    "server",
                    "http://madskills.com/public/xml/rss/module/pingback/",
                    pingbackServer.ToString());
                writer.WriteElementString(
                    "pingback",
                    "target",
                    "http://madskills.com/public/xml/rss/module/pingback/",
                    GetPermaLink(publishable).ToString());
            }

            // ------------------------------------------------------------
            // Write slash syndication extension elements
            // ------------------------------------------------------------
            if (post != null && post.Comments != null)
            {
                writer.WriteElementString(
                    "slash",
                    "comments",
                    "http://purl.org/rss/1.0/modules/slash/",
                    post.Comments.Count.ToString(CultureInfo.InvariantCulture));
            }

            // ------------------------------------------------------------
            // Write trackback syndication extension elements
            // ------------------------------------------------------------
            if (post != null && post.TrackbackLink != null)
            {
                writer.WriteElementString(
                    "trackback",
                    "ping",
                    "http://madskills.com/public/xml/rss/module/trackback/",
                    post.TrackbackLink.ToString());
            }

            // ------------------------------------------------------------
            // Write well-formed web syndication extension elements
            // ------------------------------------------------------------
            writer.WriteElementString(
                "wfw",
                "comment",
                "http://wellformedweb.org/CommentAPI/",
                String.Concat(publishable.AbsoluteLink.ToString(),
                BlogSettings.Instance.ModerationType == BlogSettings.Moderation.Disqus ? "#disqus_thread" : "#comment"));
            writer.WriteElementString(
                "wfw",
                "commentRss",
                "http://wellformedweb.org/CommentAPI/",
                string.Format("{0}/syndication.axd?post={1}", publishable.Blog.AbsoluteWebRoot.ToString().TrimEnd('/'), publishable.Id));

            // ------------------------------------------------------------
            // Write </item> element
            // ------------------------------------------------------------
            writer.WriteEndElement();
        }