Пример #1
0
        protected virtual void EntryXml(Entry entry, BlogConfigurationSettings settings, ITimeZone timezone)
        {
            WriteElementString("title", entry.Title);

            WriteStartElement("link");
            //(Duncanma 11/13/2005, changing alternate to self for 1.0 feed)
            WriteAttributeString("rel", "alternate");
            WriteAttributeString("type", "text/html");
            WriteAttributeString("href", UrlHelper.EntryUrl(entry).ToFullyQualifiedUrl(Blog).ToString());
            WriteEndElement();

            WriteElementString("id", UrlHelper.EntryUrl(entry).ToFullyQualifiedUrl(Blog).ToString());

            //(Duncanma 11/13/2005, hiding created, change issued to
            //published and modified to updated for 1.0 feed)
            //this.WriteElementString("created",W3Utcz(entry.DateCreated));
            WriteElementString("published", W3Utcz(entry.DateCreatedUtc));
            WriteElementString("updated", W3Utcz(entry.DateModifiedUtc));

            if (entry.HasDescription)
            {
                WriteStartElement("summary");
                //(Duncanma 11/13/2005, changing text/html to html for 1.0 feed)
                WriteAttributeString("type", "html");
                WriteString(entry.Description);
                WriteEndElement();
            }

            WriteStartElement("content");
            //(Duncanma 11/13/2005, changing text/html to html for 1.0 feed)
            WriteAttributeString("type", "html");
            //(Duncanma 11/13/2005, hiding mode for 1.0 feed)
            //this.WriteAttributeString("mode","escaped");

            WriteString
            (
                string.Format
                    (CultureInfo.InvariantCulture, "{0}{1}",                         //tag def
                    entry.SyndicateDescriptionOnly ? entry.Description : entry.Body, //use desc or full post
                    (UseAggBugs && settings.Tracking.EnableAggBugs)
                         ? TrackingUrls.AggBugImage(UrlHelper.AggBugUrl(entry.Id))
                         : null //use aggbugs
                    )
            );
            WriteEndElement();

            if (AllowComments && Blog.CommentsEnabled && entry.AllowComments && !entry.CommentingClosed)
            {
                //optional for CommentApi Post location
                WriteElementString("wfw:comment", UrlHelper.CommentApiUrl(entry.Id));
                //optional url for comments
                //this.WriteElementString("comments",entry.Link + "#feedback");
                //optional comment count
                WriteElementString("slash:comments", entry.FeedBackCount.ToString(CultureInfo.InvariantCulture));
                //optional commentRss feed location
                WriteElementString("wfw:commentRss", UrlHelper.CommentRssUrl(entry.Id));
                //optional trackback location
                WriteElementString("trackback:ping", UrlHelper.TrackbacksUrl(entry.Id));
                //core
            }
        }
        /// <summary>
        /// Writes the XML for a single entry.
        /// </summary>
        protected virtual void EntryXml(T item, BlogConfigurationSettings settings)
        {
            //core
            WriteElementString("title", GetTitleFromItem(item));

            ICollection <string> categories = GetCategoriesFromItem(item);

            if (categories != null)
            {
                foreach (string category in categories)
                {
                    WriteElementString("category", category);
                }
            }

            string fullUrl = GetLinkFromItem(item);

            WriteElementString("link", fullUrl);
            WriteElementString
            (
                "description", //Tag
                string.Format
                (
                    CultureInfo.InvariantCulture,
                    "{0}{1}", //tag def
                    GetBodyFromItem(item),
                    (UseAggBugs && settings.Tracking.EnableAggBugs)
                        ? TrackingUrls.AggBugImage(GetAggBugUrl(item))
                        : null //use aggbugs
                )
            );

            string author = GetAuthorFromItem(item);

            if (!String.IsNullOrEmpty(author))
            {
                WriteElementString("dc:creator", author);
            }

            WriteElementString("guid", GetGuid(item));
            WriteElementString("pubDate", GetPublishedDateUtc(item).ToString("r", CultureInfo.InvariantCulture));

            if (ItemCouldContainComments(item))
            {
                if (AllowComments && Blog.CommentsEnabled && ItemAllowsComments(item) && !CommentsClosedOnItem(item))
                {
                    // Comment API (http://wellformedweb.org/story/9)
                    WriteElementString("wfw:comment", GetCommentApiUrl(item));
                }

                WriteElementString("comments", fullUrl + "#feedback");

                if (GetFeedbackCount(item) > 0)
                {
                    WriteElementString("slash:comments", GetFeedbackCount(item).ToString(CultureInfo.InvariantCulture));
                }

                WriteElementString("wfw:commentRss", GetCommentRssUrl(item));

                if (Blog.TrackbacksEnabled)
                {
                    WriteElementString("trackback:ping", GetTrackBackUrl(item));
                }
            }

            EnclosureItem encItem = GetEnclosureFromItem(item);

            if (encItem != null)
            {
                WriteStartElement("enclosure");
                WriteAttributeString("url", encItem.Url);
                WriteAttributeString("length", encItem.Size.ToString(CultureInfo.InvariantCulture));
                WriteAttributeString("type", encItem.MimeType);
                WriteEndElement();
            }
        }
Пример #3
0
        private string GetRSS(IEnumerable <Entry> entries, string appPath)
        {
            if (!appPath.EndsWith("/"))
            {
                appPath += "/";
            }

            var sw     = new StringWriter();
            var writer = new XmlTextWriter(sw);

            //RSS ROOT
            writer.WriteStartElement("rss");
            writer.WriteAttributeString("version", "2.0");
            writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
            writer.WriteAttributeString("xmlns:trackback", "http://madskills.com/public/xml/rss/module/trackback/");
            writer.WriteAttributeString("xmlns:wfw", "http://wellformedweb.org/CommentAPI/");
            writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");

            //Channel
            writer.WriteStartElement("channel");
            //Channel Description
            writer.WriteElementString("title", ConfigurationManager.AppSettings["AggregateTitle"]);
            writer.WriteElementString("link", Context.Request.Url.ToString());
            writer.WriteElementString("description", ConfigurationManager.AppSettings["AggregateDescription"]);
            writer.WriteElementString("generator", VersionInfo.VersionDisplayText);

            string baseUrl = "http://{0}" + appPath + "{1}/";

            bool useAggBugs = Config.Settings.Tracking.EnableAggBugs;

            foreach (Entry entry in entries)
            {
                writer.WriteStartElement("item");
                writer.WriteElementString("title", entry.Title);

                string baselink = string.Format(baseUrl, entry.Blog.Host, entry.Blog.Subfolder);
                string link     = string.Format(CultureInfo.InvariantCulture, baselink + "archive/{0:yyyy/MM/dd}/{1}.aspx",
                                                entry.DateCreatedUtc, entry.EntryName);
                writer.WriteElementString("link", link);

                DateTime entryTime = entry.DateCreatedUtc;

                writer.WriteElementString("pubDate", entry.Blog.TimeZone.ToUtc(entryTime).ToString("r"));
                writer.WriteStartElement("guid");
                writer.WriteAttributeString("isPermaLink", "true");
                writer.WriteString(link);
                writer.WriteEndElement();

                writer.WriteElementString("wfw:comment", string.Format(baselink + "comments/{0}.aspx", entry.Id));
                writer.WriteElementString("wfw:commentRss",
                                          string.Format(baselink + "comments/commentRss/{0}.aspx", entry.Id));
                writer.WriteElementString("comments", link + "#comment");
                writer.WriteElementString("slash:comments", entry.FeedBackCount.ToString(CultureInfo.InvariantCulture));
                writer.WriteElementString("trackback:ping",
                                          string.Format(baselink + "services/trackbacks/{0}.aspx", entry.Id));


                writer.WriteStartElement("source");
                writer.WriteAttributeString("url", baselink + "rss.aspx");
                writer.WriteString(entry.Blog.Title);
                writer.WriteEndElement();

                string aggText = useAggBugs
                                     ? TrackingUrls.AggBugImage(string.Format(baselink + "aggbug/{0}.aspx", entry.Id))
                                     : string.Empty;

                writer.WriteElementString("description",
                                          string.Format(CultureInfo.InvariantCulture, "{0}{1}", entry.Description,
                                                        aggText));
                writer.WriteElementString("dc:creator", entry.Author);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.Flush();
            writer.Close();
            sw.Close();
            return(sw.ToString());
        }