Skip to content

Commit

Permalink
#1211 RSS recommendations. Fixed all warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
skoshelev committed Oct 13, 2016
1 parent 256b3ad commit c448403
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
23 changes: 21 additions & 2 deletions src/Presentation/Nop.Web.Framework/RssActionResult.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
using System.ServiceModel.Syndication;
using System;
using System.ServiceModel.Syndication;
using System.Web.Mvc;
using System.Xml;
using System.Xml.Linq;
using Nop.Core;

namespace Nop.Web.Framework
{
public class RssActionResult : ActionResult
{
/// <summary>
/// Ctor
/// </summary>
/// <param name="feed">Syndication feed</param>
/// <param name="feedPageUrl">Feed page url for atom self link</param>
public RssActionResult(SyndicationFeed feed, string feedPageUrl)
{
this.Feed = feed;
//add atom namespace
XNamespace atom = "http://www.w3.org/2005/Atom";
this.Feed.AttributeExtensions.Add(new XmlQualifiedName("atom", XNamespace.Xmlns.NamespaceName), atom.NamespaceName);
//add atom:link with rel='self'
this.Feed.ElementExtensions.Add(new XElement(atom + "link", new XAttribute("href", new Uri(feedPageUrl)), new XAttribute("rel", "self"), new XAttribute("type", "application/rss+xml")));
}
public SyndicationFeed Feed { get; set; }

public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = MimeTypes.ApplicationRssXml;

var rssFormatter = new Rss20FeedFormatter(Feed);
var rssFormatter = Feed.GetRss20Formatter();
//remove a10 namespace
rssFormatter.SerializeExtensionsAsAtom = false;

using (var writer = XmlWriter.Create(context.HttpContext.Response.Output))
{
rssFormatter.WriteTo(writer);
Expand Down
14 changes: 7 additions & 7 deletions src/Presentation/Nop.Web/Controllers/BlogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ public ActionResult BlogByMonth(BlogPagingFilteringModel command)
public ActionResult ListRss(int languageId)
{
var feed = new SyndicationFeed(
string.Format("{0}: Blog", _storeContext.CurrentStore.GetLocalized(x => x.Name)),
"Blog",
new Uri(_webHelper.GetStoreLocation(false)),
string.Format("urn:store:{0}:blog", _storeContext.CurrentStore.Id),
DateTime.UtcNow);
string.Format("{0}: Blog", _storeContext.CurrentStore.GetLocalized(x => x.Name)),
"Blog",
new Uri(_webHelper.GetStoreLocation(false)),
string.Format("urn:store:{0}:blog", _storeContext.CurrentStore.Id),
DateTime.UtcNow);

if (!_blogSettings.Enabled)
return new RssActionResult { Feed = feed };
return new RssActionResult(feed, _webHelper.GetThisPageUrl(false));

var items = new List<SyndicationItem>();
var blogPosts = _blogService.GetAllBlogPosts(_storeContext.CurrentStore.Id, languageId);
Expand All @@ -241,7 +241,7 @@ public ActionResult ListRss(int languageId)
items.Add(new SyndicationItem(blogPost.Title, blogPost.Body, new Uri(blogPostUrl), String.Format("urn:store:{0}:blog:post:{1}", _storeContext.CurrentStore.Id, blogPost.Id), blogPost.CreatedOnUtc));
}
feed.Items = items;
return new RssActionResult { Feed = feed };
return new RssActionResult(feed, _webHelper.GetThisPageUrl(false));
}

public ActionResult BlogPost(int blogPostId)
Expand Down
6 changes: 3 additions & 3 deletions src/Presentation/Nop.Web/Controllers/BoardsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public ActionResult ActiveDiscussionsRss(int forumId = 0)
}
feed.Items = items;

return new RssActionResult { Feed = feed };
return new RssActionResult(feed, _webHelper.GetThisPageUrl(false));
}

public ActionResult ForumGroup(int id)
Expand Down Expand Up @@ -417,10 +417,10 @@ public ActionResult ForumRss(int id)

feed.Items = items;

return new RssActionResult { Feed = feed };
return new RssActionResult(feed, _webHelper.GetThisPageUrl(false));
}

return new RssActionResult { Feed = new SyndicationFeed() };
return new RssActionResult(new SyndicationFeed(), _webHelper.GetThisPageUrl(false));
}

[HttpPost]
Expand Down
4 changes: 2 additions & 2 deletions src/Presentation/Nop.Web/Controllers/NewsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public ActionResult ListRss(int languageId)
DateTime.UtcNow);

if (!_newsSettings.Enabled)
return new RssActionResult { Feed = feed };
return new RssActionResult(feed, _webHelper.GetThisPageUrl(false));

var items = new List<SyndicationItem>();
var newsItems = _newsService.GetAllNews(languageId, _storeContext.CurrentStore.Id);
Expand All @@ -231,7 +231,7 @@ public ActionResult ListRss(int languageId)
items.Add(new SyndicationItem(n.Title, n.Short, new Uri(newsUrl), String.Format("urn:store:{0}:news:blog:{1}", _storeContext.CurrentStore.Id, n.Id), n.CreatedOnUtc));
}
feed.Items = items;
return new RssActionResult { Feed = feed };
return new RssActionResult(feed, _webHelper.GetThisPageUrl(false));
}

public ActionResult NewsItem(int newsItemId)
Expand Down
4 changes: 2 additions & 2 deletions src/Presentation/Nop.Web/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ public ActionResult NewProductsRss()
DateTime.UtcNow);

if (!_catalogSettings.NewProductsEnabled)
return new RssActionResult { Feed = feed };
return new RssActionResult(feed, _webHelper.GetThisPageUrl(false));

var items = new List<SyndicationItem>();

Expand All @@ -1194,7 +1194,7 @@ public ActionResult NewProductsRss()

}
feed.Items = items;
return new RssActionResult { Feed = feed };
return new RssActionResult(feed, _webHelper.GetThisPageUrl(false));
}

#endregion
Expand Down

0 comments on commit c448403

Please sign in to comment.