Skip to content

Commit b68157d

Browse files
committed
smartstore#709 Forum topics RSS feed improvements
1 parent 5f28e47 commit b68157d

4 files changed

Lines changed: 68 additions & 51 deletions

File tree

src/Libraries/SmartStore.Data/Migrations/201506261756463_PrimaryStoreCurrencyMultiStore.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
154154
builder.Delete("Admin.Configuration.Currencies.CantDeleteExchange");
155155
builder.Delete("Admin.Configuration.Currencies.Fields.MarkAsPrimaryStoreCurrency");
156156
builder.Delete("Admin.Configuration.Currencies.Fields.MarkAsPrimaryExchangeRateCurrency");
157+
builder.Delete("Forum.ForumFeedTitle");
157158
}
158159
}
159160
}

src/Libraries/SmartStore.Services/Forums/ForumService.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using SmartStore.Core.Events;
1313
using SmartStore.Services.Common;
1414
using SmartStore.Services.Customers;
15+
using SmartStore.Services.Localization;
1516
using SmartStore.Services.Messages;
1617
using SmartStore.Services.Seo;
1718
using SmartStore.Utilities;
@@ -1486,6 +1487,7 @@ public virtual SmartSyndicationFeed CreateActiveDiscussionsRssFeed(UrlHelper url
14861487
if (urlHelper == null)
14871488
throw new ArgumentNullException("urlHelper");
14881489

1490+
var language = _services.WorkContext.WorkingLanguage;
14891491
var protocol = _services.WebHelper.IsCurrentConnectionSecured() ? "https" : "http";
14901492
var selfLink = urlHelper.Action("ActiveDiscussionsRSS", "Boards", null, protocol);
14911493
var discussionLink = urlHelper.Action("ActiveDiscussions", "Boards", null, protocol);
@@ -1495,7 +1497,7 @@ public virtual SmartSyndicationFeed CreateActiveDiscussionsRssFeed(UrlHelper url
14951497
var feed = new SmartSyndicationFeed(new Uri(discussionLink), title, _services.Localization.GetResource("Forum.ActiveDiscussionsFeedDescription"));
14961498

14971499
feed.AddNamespaces(false);
1498-
feed.Init(selfLink, _services.WorkContext.WorkingLanguage);
1500+
feed.Init(selfLink, language);
14991501

15001502
if (!_forumSettings.ActiveDiscussionsFeedEnabled)
15011503
return feed;
@@ -1521,6 +1523,58 @@ public virtual SmartSyndicationFeed CreateActiveDiscussionsRssFeed(UrlHelper url
15211523
return feed;
15221524
}
15231525

1526+
/// <summary>
1527+
/// Creates a RSS feed with forum topics
1528+
/// </summary>
1529+
/// <param name="urlHelper">UrlHelper to generate URLs</param>
1530+
/// <returns>SmartSyndicationFeed object</returns>
1531+
public virtual SmartSyndicationFeed CreateForumRssFeed(UrlHelper urlHelper, int forumId)
1532+
{
1533+
if (urlHelper == null)
1534+
throw new ArgumentNullException("urlHelper");
1535+
1536+
var language = _services.WorkContext.WorkingLanguage;
1537+
var protocol = _services.WebHelper.IsCurrentConnectionSecured() ? "https" : "http";
1538+
var selfLink = urlHelper.Action("ForumRSS", "Boards", null, protocol);
1539+
var forumLink = urlHelper.Action("Forum", "Boards", new { id = forumId }, protocol);
1540+
1541+
var feed = new SmartSyndicationFeed(new Uri(forumLink), _services.StoreContext.CurrentStore.Name, _services.Localization.GetResource("Forum.ForumFeedDescription"));
1542+
1543+
feed.AddNamespaces(false);
1544+
feed.Init(selfLink, language);
1545+
1546+
if (!_forumSettings.ForumFeedsEnabled)
1547+
return feed;
1548+
1549+
var forum = GetForumById(forumId);
1550+
1551+
if (forum == null)
1552+
return feed;
1553+
1554+
feed.Title = new TextSyndicationContent("{0} - {1}".FormatInvariant(_services.StoreContext.CurrentStore.Name, forum.GetLocalized(x => x.Name, language.Id)));
1555+
1556+
var items = new List<SyndicationItem>();
1557+
var topics = GetAllTopics(forumId, 0, string.Empty, ForumSearchType.All, 0, 0, _forumSettings.ForumFeedCount);
1558+
1559+
var viewsText = _services.Localization.GetResource("Forum.Views");
1560+
var repliesText = _services.Localization.GetResource("Forum.Replies");
1561+
1562+
foreach (var topic in topics)
1563+
{
1564+
string topicUrl = urlHelper.RouteUrl("TopicSlug", new { id = topic.Id, slug = topic.GetSeName() }, "http");
1565+
var synopsis = "{0}: {1}, {2}: {3}".FormatInvariant(repliesText, topic.NumReplies, viewsText, topic.Views);
1566+
1567+
var item = feed.CreateItem(topic.Subject, synopsis, topicUrl, topic.LastPostTime ?? topic.UpdatedOnUtc);
1568+
1569+
items.Add(item);
1570+
}
1571+
1572+
feed.Items = items;
1573+
1574+
return feed;
1575+
}
1576+
1577+
15241578
#endregion
15251579
}
15261580
}

src/Libraries/SmartStore.Services/Forums/IForumService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,5 +353,12 @@ IPagedList<ForumSubscription> GetAllSubscriptions(int customerId, int forumId,
353353
/// <param name="urlHelper">UrlHelper to generate URLs</param>
354354
/// <returns>SmartSyndicationFeed object</returns>
355355
SmartSyndicationFeed CreateActiveDiscussionsRssFeed(UrlHelper urlHelper, int forumId);
356+
357+
/// <summary>
358+
/// Creates a RSS feed with forum topics
359+
/// </summary>
360+
/// <param name="urlHelper">UrlHelper to generate URLs</param>
361+
/// <returns>SmartSyndicationFeed object</returns>
362+
SmartSyndicationFeed CreateForumRssFeed(UrlHelper urlHelper, int forumId);
356363
}
357364
}

src/Presentation/SmartStore.Web/Controllers/BoardsController.cs

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.ServiceModel.Syndication;
54
using System.Web.Mvc;
65
using SmartStore.Core;
76
using SmartStore.Core.Domain.Customers;
@@ -18,6 +17,7 @@
1817
using SmartStore.Services.Seo;
1918
using SmartStore.Web.Framework;
2019
using SmartStore.Web.Framework.Controllers;
20+
using SmartStore.Web.Framework.Mvc;
2121
using SmartStore.Web.Framework.Security;
2222
using SmartStore.Web.Models.Boards;
2323

@@ -34,7 +34,6 @@ public partial class BoardsController : PublicControllerBase
3434
private readonly ICountryService _countryService;
3535
private readonly IWebHelper _webHelper;
3636
private readonly IWorkContext _workContext;
37-
private readonly IStoreContext _storeContext;
3837
private readonly ForumSettings _forumSettings;
3938
private readonly CustomerSettings _customerSettings;
4039
private readonly MediaSettings _mediaSettings;
@@ -50,7 +49,6 @@ public BoardsController(IForumService forumService,
5049
ICountryService countryService,
5150
IWebHelper webHelper,
5251
IWorkContext workContext,
53-
IStoreContext storeContext,
5452
ForumSettings forumSettings,
5553
CustomerSettings customerSettings,
5654
MediaSettings mediaSettings,
@@ -62,7 +60,6 @@ public BoardsController(IForumService forumService,
6260
this._countryService = countryService;
6361
this._webHelper = webHelper;
6462
this._workContext = workContext;
65-
this._storeContext = storeContext;
6663
this._forumSettings = forumSettings;
6764
this._customerSettings = customerSettings;
6865
this._mediaSettings = mediaSettings;
@@ -263,6 +260,7 @@ public ActionResult ActiveDiscussions(int forumId = 0)
263260
return View(model);
264261
}
265262

263+
[Compress]
266264
public ActionResult ActiveDiscussionsRss(int forumId = 0)
267265
{
268266
if (!_forumSettings.ForumsEnabled)
@@ -345,58 +343,15 @@ public ActionResult Forum(int id, int page = 1)
345343
return RedirectToRoute("Boards");
346344
}
347345

346+
[Compress]
348347
public ActionResult ForumRss(int id)
349348
{
350349
if (!_forumSettings.ForumsEnabled)
351-
{
352-
return HttpNotFound();
353-
}
354-
355-
if (!_forumSettings.ForumFeedsEnabled)
356-
{
357350
return HttpNotFound();
358-
}
359-
360-
int topicLimit = _forumSettings.ForumFeedCount;
361-
var forum = _forumService.GetForumById(id);
362-
363-
if (forum != null)
364-
{
365-
//Order by newest topic posts & limit the number of topics to return
366-
var topics = _forumService.GetAllTopics(forum.Id, 0, string.Empty, ForumSearchType.All, 0, 0, topicLimit);
367-
368-
string url = Url.Action("ForumRSS", null, new { id = forum.Id }, "http");
369351

370-
var feedTitle = _localizationService.GetResource("Forum.ForumFeedTitle");
371-
var feedDescription = _localizationService.GetResource("Forum.ForumFeedDescription");
372-
373-
var feed = new SyndicationFeed(
374-
string.Format(feedTitle, _storeContext.CurrentStore.Name, forum.GetLocalized(x => x.Name)),
375-
feedDescription,
376-
new Uri(url),
377-
string.Format("ForumRSS:{0}", forum.Id),
378-
DateTime.UtcNow);
379-
380-
var items = new List<SyndicationItem>();
381-
382-
var viewsText = _localizationService.GetResource("Forum.Views");
383-
var repliesText = _localizationService.GetResource("Forum.Replies");
384-
385-
foreach (var topic in topics)
386-
{
387-
string topicUrl = Url.RouteUrl("TopicSlug", new { id = topic.Id, slug = topic.GetSeName() }, "http");
388-
string content = string.Format("{2}: {0}, {3}: {1}", topic.NumReplies.ToString(), topic.Views.ToString(), repliesText, viewsText);
389-
390-
items.Add(new SyndicationItem(topic.Subject, content, new Uri(topicUrl), String.Format("Topic:{0}", topic.Id),
391-
(topic.LastPostTime ?? topic.UpdatedOnUtc)));
392-
}
393-
394-
feed.Items = items;
395-
396-
return new RssActionResult() { Feed = feed };
397-
}
352+
var feed = _forumService.CreateForumRssFeed(Url, id);
398353

399-
return new RssActionResult() { Feed = new SyndicationFeed() };
354+
return new RssActionResult { Feed = feed };
400355
}
401356

402357
[HttpPost]

0 commit comments

Comments
 (0)