private void RenderFeed() { if (siteSettings == null) { return; } Argotic.Syndication.RssFeed feed = new Argotic.Syndication.RssFeed(); RssChannel channel = new RssChannel(); channel.Generator = "mojoPortal CMS Recent Content Feed Geenrator"; feed.Channel = channel; List<IndexItem> recentContent = GetData(); // gets the data and initilizes the channel params if (!shouldRender) { WebUtils.SetupRedirect(this, redirectUrl); return; } if (channelTitle.Length == 0) { channelTitle = "Recent Content"; } //empty string will cause an error channel.Title = channelTitle; channel.Link = new System.Uri(channelLink); if (channelDescription.Length == 0) { channelDescription = "Recent Content"; } //empty string will cause an error channel.Description = channelDescription; channel.Copyright = channelCopyright; channel.ManagingEditor = channelManagingEditor; channel.TimeToLive = channelTimeToLive; int itemsAdded = 0; if (recentContent != null) { foreach (IndexItem indexItem in recentContent) { RssItem item = new RssItem(); string itemUrl = BuildUrl(indexItem); item.Link = new Uri(itemUrl); item.Guid = new RssGuid(itemUrl); item.Title = FormatLinkText(indexItem); item.PublicationDate = indexItem.LastModUtc; item.Author = indexItem.Author; item.Description = indexItem.ContentAbstract; channel.AddItem(item); itemsAdded += 1; } } if (itemsAdded == 0) { //channel must have at least one item RssItem item = new RssItem(); item.Link = new Uri(siteRoot); item.Title = "Stay tuned for future updates. "; //item.Description = item.PublicationDate = DateTime.UtcNow; channel.AddItem(item); } // no cache locally if (Request.Url.AbsolutePath.Contains("localhost")) { Response.Cache.SetExpires(DateTime.Now.AddMinutes(-30)); Response.Cache.SetCacheability(HttpCacheability.NoCache); } else { Response.Cache.SetExpires(DateTime.Now.AddMinutes(feedCacheTimeInMinutes)); Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.VaryByParams["f;gc;n;pageid;mid"] = true; } Response.ContentType = "application/xml"; Encoding encoding = new UTF8Encoding(); Response.ContentEncoding = encoding; using (XmlTextWriter xmlTextWriter = new XmlTextWriter(Response.OutputStream, encoding)) { xmlTextWriter.Formatting = Formatting.Indented; ////////////////// // style for RSS Feed viewed in browsers if (ConfigurationManager.AppSettings["RSSCSS"] != null) { string rssCss = ConfigurationManager.AppSettings["RSSCSS"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/css\" href=\"" + cssBaseUrl + rssCss + "\" ?>"); } if (ConfigurationManager.AppSettings["RSSXsl"] != null) { string rssXsl = ConfigurationManager.AppSettings["RSSXsl"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + cssBaseUrl + rssXsl + "\" ?>"); } /////////////////////////// feed.Save(xmlTextWriter); } }
/// <summary> /// Initializes the supplied <see cref="RssChannel"/> optional entities using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="channel">The <see cref="RssChannel"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the channel XML data.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param> /// <exception cref="ArgumentNullException">The <paramref name="channel"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillChannelOptionals(RssChannel channel, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(channel, "channel"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Extract optional channel information //------------------------------------------------------------ XPathNavigator copyrightNavigator = navigator.SelectSingleNode("copyright", manager); XPathNavigator managingEditorNavigator = navigator.SelectSingleNode("managingEditor", manager); XPathNavigator webMasterNavigator = navigator.SelectSingleNode("webMaster", manager); XPathNavigator ratingNavigator = navigator.SelectSingleNode("rating", manager); XPathNavigator publicationNavigator = navigator.SelectSingleNode("pubDate", manager); XPathNavigator lastBuildDateNavigator = navigator.SelectSingleNode("lastBuildDate", manager); XPathNavigator textInputNavigator = navigator.SelectSingleNode("textInput", manager); if (copyrightNavigator != null) { channel.Copyright = copyrightNavigator.Value; } if (managingEditorNavigator != null) { channel.ManagingEditor = managingEditorNavigator.Value; } if (webMasterNavigator != null) { channel.Webmaster = webMasterNavigator.Value; } if (ratingNavigator != null) { channel.Rating = ratingNavigator.Value; } if (publicationNavigator != null) { DateTime publicationDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate)) { channel.PublicationDate = publicationDate; } } if (lastBuildDateNavigator != null) { DateTime lastBuildDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(lastBuildDateNavigator.Value, out lastBuildDate)) { channel.LastBuildDate = lastBuildDate; } } if (textInputNavigator != null) { channel.TextInput = new RssTextInput(); Rss091SyndicationResourceAdapter.FillTextInput(channel.TextInput, textInputNavigator, manager, settings); } }
private void RenderRss() { Argotic.Syndication.RssFeed feed = new Argotic.Syndication.RssFeed(); RssChannel channel = new RssChannel(); channel.Generator = "mojoPortal Blog Module"; channel.Language = SiteUtils.GetDefaultCulture(); feed.Channel = channel; if (module.ModuleTitle.Length > 0) { channel.Title = module.ModuleTitle; } else { channel.Title = "Blog"; // it will cause an error if this is left blank so we must populate it if the module title is an emty string. } // this became broken when we combined query string params, since pageid is not one of the params this always returns the home page url // instead of the blog page url //string pu = WebUtils.ResolveServerUrl(SiteUtils.GetCurrentPageUrl()); string pu = WebUtils.ResolveServerUrl(SiteUtils.GetPageUrl(pageSettings)); channel.Link = new System.Uri(pu); channel.SelfLink = Request.Url; if (config.ChannelDescription.Length > 0) { channel.Description = config.ChannelDescription; } if (config.Copyright.Length > 0) { channel.Copyright = config.Copyright; } channel.ManagingEditor = config.ManagingEditorEmail; if (config.ManagingEditorName.Length > 0) { channel.ManagingEditor += " (" + config.ManagingEditorName + ")"; } if (config.FeedTimeToLive > -1) { channel.TimeToLive = config.FeedTimeToLive; } // Create and add iTunes information to feed channel ITunesSyndicationExtension channelExtension = new ITunesSyndicationExtension(); channelExtension.Context.Subtitle = config.ChannelDescription; if (config.HasExplicitContent) { channelExtension.Context.ExplicitMaterial = ITunesExplicitMaterial.Yes; } else { channelExtension.Context.ExplicitMaterial = ITunesExplicitMaterial.No; } channelExtension.Context.Author = config.ManagingEditorEmail; if (config.ManagingEditorName.Length > 0) { channelExtension.Context.Author += " (" + config.ManagingEditorName + ")"; } channelExtension.Context.Summary = config.ChannelDescription; channelExtension.Context.Owner = new ITunesOwner(config.ManagingEditorEmail, config.ManagingEditorName); if (config.FeedLogoUrl.Length > 0) { try { channelExtension.Context.Image = new Uri(config.FeedLogoUrl); } catch (ArgumentNullException) { } catch (UriFormatException) { } } if (config.FeedMainCategory.Length > 0) { ITunesCategory mainCat = new ITunesCategory(config.FeedMainCategory); if (config.FeedSubCategory.Length > 0) { mainCat.Categories.Add(new ITunesCategory(config.FeedSubCategory)); } channelExtension.Context.Categories.Add(mainCat); } feed.Channel.AddExtension(channelExtension); DataSet dsBlogPosts = GetData(); DataTable posts = dsBlogPosts.Tables["Posts"]; foreach (DataRow dr in posts.Rows) { bool inFeed = Convert.ToBoolean(dr["IncludeInFeed"]); if (!inFeed) { continue; } RssItem item = new RssItem(); int itemId = Convert.ToInt32(dr["ItemID"]); string blogItemUrl = FormatBlogUrl(dr["ItemUrl"].ToString(), itemId); item.Link = new Uri(Request.Url, blogItemUrl); item.Guid = new RssGuid(blogItemUrl); item.Title = dr["Heading"].ToString(); item.PublicationDate = Convert.ToDateTime(dr["StartDate"]); bool showAuthor = Convert.ToBoolean(dr["ShowAuthorName"]); if (showAuthor) { // techically this is supposed to be an email address // but wouldn't that lead to a lot of spam? string authorEmail = dr["Email"].ToString(); string authorName = dr["Name"].ToString(); if (BlogConfiguration.IncludeAuthorEmailInFeed) { item.Author = authorEmail + " (" + authorName + ")"; } else { item.Author = authorName; } } else if (config.ManagingEditorEmail.Length > 0) { item.Author = config.ManagingEditorEmail; } item.Comments = new Uri(blogItemUrl); string signature = string.Empty; if (config.AddSignature) { signature = "<br /><a href='" + blogItemUrl + "'>" + dr["Name"].ToString() + "</a>"; } if ((config.AddCommentsLinkToFeed) && (config.AllowComments)) { signature += " " + "<a href='" + blogItemUrl + "'>...</a>"; } if (config.AddTweetThisToFeed) { signature += GenerateTweetThisLink(item.Title, blogItemUrl); } if (config.AddFacebookLikeToFeed) { signature += GenerateFacebookLikeButton(blogItemUrl); } string blogPost = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, dr["Description"].ToString().RemoveCDataTags()); string staticMapLink = BuildStaticMapMarkup(dr); if (staticMapLink.Length > 0) { // add a google static map blogPost += staticMapLink; } if ((!config.UseExcerptInFeed) || (blogPost.Length <= config.ExcerptLength)) { item.Description = blogPost + signature; } else { string excerpt = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, dr["Abstract"].ToString().RemoveCDataTags()); if ((excerpt.Length > 0) && (excerpt != "<p> </p>")) { excerpt = excerpt + config.ExcerptSuffix + " <a href='" + blogItemUrl + "'>" + config.MoreLinkText + "</a><div class='excerptspacer'> </div>"; } else { excerpt = UIHelper.CreateExcerpt(dr["Description"].ToString(), config.ExcerptLength, config.ExcerptSuffix) + " <a href='" + blogItemUrl + "'>" + config.MoreLinkText + "</a><div class='excerptspacer'> </div>"; ; } item.Description = excerpt; } // how to add media enclosures for podcasting //http://www.podcast411.com/howto_1.html //http://argotic.codeplex.com/wikipage?title=Generating%20an%20extended%20RSS%20feed //http://techwhimsy.com/stream-mp3s-with-google-mp3-player //Uri url = new Uri("http://media.libsyn.com/media/podcast411/411_060325.mp3"); //string type = "audio/mpeg"; //long length = 11779397; string blogGuid = dr["BlogGuid"].ToString(); string whereClause = string.Format("ItemGuid = '{0}'", blogGuid); if (!config.UseExcerptInFeed) { DataView dv = new DataView(dsBlogPosts.Tables["Attachments"], whereClause, "", DataViewRowState.CurrentRows); foreach (DataRowView rowView in dv) { DataRow row = rowView.Row; Uri mediaUrl = new Uri(WebUtils.ResolveServerUrl(attachmentBaseUrl + row["ServerFileName"].ToString())); long contentLength = Convert.ToInt64(row["ContentLength"]); string contentType = row["ContentType"].ToString(); RssEnclosure enclosure = new RssEnclosure(contentLength, contentType, mediaUrl); item.Enclosures.Add(enclosure); //http://argotic.codeplex.com/wikipage?title=Generating%20an%20extended%20RSS%20feed ITunesSyndicationExtension itemExtension = new ITunesSyndicationExtension(); itemExtension.Context.Author = dr["Name"].ToString(); itemExtension.Context.Subtitle = dr["SubTitle"].ToString(); //itemExtension.Context.Summary = "The iTunes syndication extension properties that are used vary based on whether extending the channel or an item"; //itemExtension.Context.Duration = new TimeSpan(1, 2, 13); //itemExtension.Context.Keywords.Add("Podcast"); //itemExtension.Context.Keywords.Add("iTunes"); whereClause = string.Format("ItemID = '{0}'", itemId); DataView dvCat = new DataView(dsBlogPosts.Tables["Categories"], whereClause, "", DataViewRowState.CurrentRows); foreach (DataRowView rView in dvCat) { DataRow r = rView.Row; item.Categories.Add(new RssCategory(r["Category"].ToString())); itemExtension.Context.Keywords.Add(r["Category"].ToString()); } item.AddExtension(itemExtension); } } channel.AddItem(item); } if ((config.FeedburnerFeedUrl.Length > 0) || (Request.Url.AbsolutePath.Contains("localhost"))) { Response.Cache.SetExpires(DateTime.Now.AddMinutes(-30)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.VaryByParams["r"] = true; } else { Response.Cache.SetExpires(DateTime.Now.AddMinutes(30)); Response.Cache.SetCacheability(HttpCacheability.Public); } Response.ContentType = "application/xml"; Encoding encoding = new UTF8Encoding(); Response.ContentEncoding = encoding; using (XmlTextWriter xmlTextWriter = new XmlTextWriter(Response.OutputStream, encoding)) { xmlTextWriter.Formatting = Formatting.Indented; ////////////////// // style for RSS Feed viewed in browsers if (ConfigurationManager.AppSettings["RSSCSS"] != null) { string rssCss = ConfigurationManager.AppSettings["RSSCSS"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/css\" href=\"" + cssBaseUrl + rssCss + "\" ?>"); } if (ConfigurationManager.AppSettings["RSSXsl"] != null) { string rssXsl = ConfigurationManager.AppSettings["RSSXsl"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + cssBaseUrl + rssXsl + "\" ?>"); } /////////////////////////// feed.Save(xmlTextWriter); } }
/// <summary> /// Initializes the supplied <see cref="RssChannel"/> collection entities using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="channel">The <see cref="RssChannel"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the channel XML data.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param> /// <exception cref="ArgumentNullException">The <paramref name="channel"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillChannelCollections(RssChannel channel, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(channel, "channel"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Extract channel collections information //------------------------------------------------------------ XPathNodeIterator skipDaysIterator = navigator.Select("skipDays/day", manager); XPathNodeIterator skipHoursIterator = navigator.Select("skipHours/hour", manager); XPathNodeIterator itemIterator = navigator.Select("item", manager); if (skipDaysIterator != null && skipDaysIterator.Count > 0) { while (skipDaysIterator.MoveNext()) { if (!String.IsNullOrEmpty(skipDaysIterator.Current.Value)) { try { DayOfWeek day = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), skipDaysIterator.Current.Value, true); if (!channel.SkipDays.Contains(day)) { channel.SkipDays.Add(day); } } catch (ArgumentException) { System.Diagnostics.Trace.TraceWarning("Rss091SyndicationResourceAdapter unable to determine DayOfWeek with a name of {0}.", skipDaysIterator.Current.Value); } } } } if (skipHoursIterator != null && skipHoursIterator.Count > 0) { while (skipHoursIterator.MoveNext()) { int hour; if (Int32.TryParse(skipHoursIterator.Current.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out hour)) { hour = hour - 1; // Convert to zero-based range if (!channel.SkipHours.Contains(hour) && (hour >= 0 && hour <= 23)) { channel.SkipHours.Add(hour); } else { System.Diagnostics.Trace.TraceWarning("Rss091SyndicationResourceAdapter unable to add duplicate or out-of-range skip hour with a value of {0}.", hour); } } } } if (itemIterator != null && itemIterator.Count > 0) { int counter = 0; while (itemIterator.MoveNext()) { RssItem item = new RssItem(); counter++; if (settings.RetrievalLimit != 0 && counter > settings.RetrievalLimit) { break; } XPathNavigator titleNavigator = itemIterator.Current.SelectSingleNode("title", manager); XPathNavigator linkNavigator = itemIterator.Current.SelectSingleNode("link", manager); XPathNavigator descriptionNavigator = itemIterator.Current.SelectSingleNode("description", manager); if (titleNavigator != null) { item.Title = titleNavigator.Value; } if (descriptionNavigator != null) { item.Description = descriptionNavigator.Value; } if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { item.Link = link; } } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(itemIterator.Current, settings); adapter.Fill(item); ((Collection<RssItem>)channel.Items).Add(item); } } }
/// <summary> /// Initializes the supplied <see cref="RssChannel"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="channel">The <see cref="RssChannel"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the channel XML data.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param> /// <exception cref="ArgumentNullException">The <paramref name="channel"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillChannel(RssChannel channel, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(channel, "channel"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Load required channel information //------------------------------------------------------------ XPathNavigator descriptionNavigator = navigator.SelectSingleNode("description", manager); XPathNavigator linkNavigator = navigator.SelectSingleNode("link", manager); XPathNavigator titleNavigator = navigator.SelectSingleNode("title", manager); XPathNavigator languageNavigator = navigator.SelectSingleNode("language", manager); if (descriptionNavigator != null && !String.IsNullOrEmpty(descriptionNavigator.Value)) { channel.Description = descriptionNavigator.Value; } if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { channel.Link = link; } } if (titleNavigator != null && !String.IsNullOrEmpty(titleNavigator.Value)) { channel.Title = titleNavigator.Value; } if (languageNavigator != null && !String.IsNullOrEmpty(languageNavigator.Value)) { try { CultureInfo language = new CultureInfo(languageNavigator.Value); channel.Language = language; } catch (ArgumentException) { System.Diagnostics.Trace.TraceWarning("Rss091SyndicationResourceAdapter unable to determine CultureInfo with a name of {0}.", languageNavigator.Value); } } XPathNavigator imageNavigator = navigator.SelectSingleNode("image", manager); if (imageNavigator != null) { channel.Image = new RssImage(); Rss091SyndicationResourceAdapter.FillImage(channel.Image, imageNavigator, manager, settings); } //------------------------------------------------------------ // Load channel optional information //------------------------------------------------------------ Rss091SyndicationResourceAdapter.FillChannelOptionals(channel, navigator, manager, settings); //------------------------------------------------------------ // Load channel collections //------------------------------------------------------------ Rss091SyndicationResourceAdapter.FillChannelCollections(channel, navigator, manager, settings); SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings); adapter.Fill(channel); }
private void RenderRss() { if (pageSettings == null) { return; } RssForum rssForum = new RssForum(); rssForum.SiteId = siteSettings.SiteId; rssForum.ModuleId = moduleId; rssForum.PageId = pageId; rssForum.ItemId = itemId; rssForum.ThreadId = threadId; rssForum.MaximumDays = maxDaysOld; Argotic.Syndication.RssFeed feed = new Argotic.Syndication.RssFeed(); RssChannel channel = new RssChannel(); channel.Generator = "mojoPortal Forum module"; string channelLink = WebUtils.ResolveServerUrl(SiteUtils.GetPageUrl(pageSettings)); channel.Link = new System.Uri(channelLink); // if (config.ChannelDescription.Length > 0) { channel.Description = config.ChannelDescription; } feed.Channel = channel; string target = navigationSiteRoot + "/Forums/Thread.aspx?pageid="; using (IDataReader posts = rssForum.GetPostsForRss()) { while ((posts.Read()) && (entryCount <= entriesLimit)) { string pageViewRoles = posts["AuthorizedRoles"].ToString(); string moduleViewRoles = posts["ViewRoles"].ToString(); bool include = (bypassPageSecurity || (pageViewRoles.Contains("All Users")) && ((moduleViewRoles.Length == 0) || (moduleViewRoles.Contains("All Users"))) ) ; if (!include) { continue; } RssItem item = new RssItem(); item.Title = posts["Subject"].ToString(); item.Description = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, posts["Post"].ToString()); item.PublicationDate = Convert.ToDateTime(posts["PostDate"]); int p = Convert.ToInt32(posts["PageID"]); int t = Convert.ToInt32(posts["ThreadID"]); //if (target.IndexOf("&thread=") < 0 && target.IndexOf("?thread=") < 0) //{ // if (target.IndexOf("?") < 0) // { // target += "?thread=" + posts["ThreadID"].ToString() + "#post" + posts["PostID"].ToString(); // } // else // { // target += "&thread=" + posts["ThreadID"].ToString() + "#post" + posts["PostID"].ToString(); // } //} //https://www.mojoportal.com/Forums/Thread.aspx?pageid=5&t=11417~1#post47516 if ((isGoogleFeedReader) && (ForumConfiguration.UseOldParamsForGoogleReader)) { //item.Link = new System.Uri(target + p.ToInvariantString() + "&thread=" + t.ToInvariantString() + "#post" + posts["PostID"].ToString()); item.Link = new System.Uri(target + p.ToInvariantString() + "&thread=" + t.ToInvariantString()); } else { item.Link = new System.Uri(target + p.ToInvariantString() + "&t=" + t.ToInvariantString() + "~-1#post" + posts["PostID"].ToString()); } RssGuid g = new RssGuid(target, true); item.Guid = g; item.Author = posts["StartedBy"].ToString(); channel.AddItem(item); entryCount += 1; } } Response.Cache.SetExpires(DateTime.Now.AddMinutes(5)); Response.Cache.SetCacheability(HttpCacheability.Public); Response.ContentType = "application/xml"; Encoding encoding = new UTF8Encoding(); Response.ContentEncoding = encoding; using (XmlTextWriter xmlTextWriter = new XmlTextWriter(Response.OutputStream, encoding)) { xmlTextWriter.Formatting = Formatting.Indented; ////////////////// // style for RSS Feed viewed in browsers if (ConfigurationManager.AppSettings["RSSCSS"] != null) { string rssCss = ConfigurationManager.AppSettings["RSSCSS"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/css\" href=\"" + cssBaseUrl + rssCss + "\" ?>"); } if (ConfigurationManager.AppSettings["RSSXsl"] != null) { string rssXsl = ConfigurationManager.AppSettings["RSSXsl"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + cssBaseUrl + rssXsl + "\" ?>"); } /////////////////////////// feed.Save(xmlTextWriter); } }
private void RenderRss() { DataView dv = FeedCache.GetRssFeedEntries( module.ModuleId, module.ModuleGuid, entryCacheTimeout, maxDaysOld, maxEntriesPerFeed, EnableSelectivePublishing).DefaultView; dv.Sort = "PubDate DESC"; if (dv.Table.Rows.Count == 0) { return; } Argotic.Syndication.RssFeed feed = new Argotic.Syndication.RssFeed(); RssChannel channel = new RssChannel(); channel.Generator = "mojoPortal Feed Manager module"; feed.Channel = channel; if (module != null) { channel.Title = module.ModuleTitle; channel.Description = module.ModuleTitle; //channel.LastBuildDate = channel.Items.LatestPubDate(); try { channel.Link = new System.Uri(WebUtils.ResolveServerUrl(SiteUtils.GetCurrentPageUrl())); } catch (UriFormatException) { channel.Link = new System.Uri(SiteUtils.GetNavigationSiteRoot()); } } else { // this prevents an error: Can't close RssWriter without first writing a channel. channel.Title = "Not Found"; channel.Description = "Not Found"; channel.LastBuildDate = DateTime.UtcNow; //channel.Link = new System.Uri(SiteUtils.GetCurrentPageUrl()); } foreach (DataRowView row in dv) { bool confirmed = Convert.ToBoolean(row["Confirmed"]); if (!EnableSelectivePublishing) { confirmed = true; } if (confirmed) { RssItem item = new RssItem(); item.Title = row["Title"].ToString(); item.Description = row["Description"].ToString(); item.PublicationDate = Convert.ToDateTime(row["PubDate"]); item.Link = new System.Uri(row["Link"].ToString()); Trace.Write(item.Link.ToString()); item.Author = row["Author"].ToString(); channel.AddItem(item); } } Response.Cache.SetExpires(DateTime.Now.AddMinutes(5)); Response.Cache.SetCacheability(HttpCacheability.Public); Response.ContentType = "application/xml"; Encoding encoding = new UTF8Encoding(); Response.ContentEncoding = encoding; using (XmlTextWriter xmlTextWriter = new XmlTextWriter(Response.OutputStream, encoding)) { xmlTextWriter.Formatting = Formatting.Indented; ////////////////// // style for RSS Feed viewed in browsers if (ConfigurationManager.AppSettings["RSSCSS"] != null) { string rssCss = ConfigurationManager.AppSettings["RSSCSS"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/css\" href=\"" + cssBaseUrl + rssCss + "\" ?>"); } if (ConfigurationManager.AppSettings["RSSXsl"] != null) { string rssXsl = ConfigurationManager.AppSettings["RSSXsl"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + cssBaseUrl + rssXsl + "\" ?>"); } /////////////////////////// feed.Save(xmlTextWriter); } }
/// <summary> /// Initializes the supplied <see cref="RssChannel"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="channel">The <see cref="RssChannel"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the channel XML data.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param> /// <exception cref="ArgumentNullException">The <paramref name="channel"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillChannel(RssChannel channel, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(channel, "channel"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Load required channel information //------------------------------------------------------------ XPathNavigator descriptionNavigator = navigator.SelectSingleNode("rss:description", manager); XPathNavigator linkNavigator = navigator.SelectSingleNode("rss:link", manager); XPathNavigator titleNavigator = navigator.SelectSingleNode("rss:title", manager); if (descriptionNavigator != null && !String.IsNullOrEmpty(descriptionNavigator.Value)) { channel.Description = descriptionNavigator.Value; } if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { channel.Link = link; } } if (titleNavigator != null && !String.IsNullOrEmpty(titleNavigator.Value)) { channel.Title = titleNavigator.Value; } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings); adapter.Fill(channel); }