From 782012849ad7975b0263e39b85b755ad8d7e9dad Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 1 Apr 2014 15:49:26 -0700 Subject: [PATCH] Using the blog's description in RSS feeds --- .../Feeds/BlogPartFeedItemBuilder.cs | 48 +++++++++++++++++++ .../Orchard.Blogs/Orchard.Blogs.csproj | 1 + 2 files changed, 49 insertions(+) create mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Feeds/BlogPartFeedItemBuilder.cs diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Feeds/BlogPartFeedItemBuilder.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Feeds/BlogPartFeedItemBuilder.cs new file mode 100644 index 000000000..b29532c56 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Feeds/BlogPartFeedItemBuilder.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web.Mvc; +using System.Web.Routing; +using System.Xml.Linq; +using JetBrains.Annotations; +using Orchard.Blogs.Models; +using Orchard.ContentManagement; +using Orchard.Core.Feeds; +using Orchard.Core.Feeds.Models; +using Orchard.Mvc.Extensions; +using Orchard.Services; + +namespace Orchard.Blogs.Feeds { + public class BlogPartFeedItemBuilder : IFeedItemBuilder { + private IContentManager _contentManager; + public BlogPartFeedItemBuilder(IContentManager contentManager) { + _contentManager = contentManager; + } + + public void Populate(FeedContext context) { + var containerIdValue = context.ValueProvider.GetValue("containerid"); + if (containerIdValue == null) + return; + + var containerId = (int)containerIdValue.ConvertTo(typeof(int)); + var container = _contentManager.Get(containerId); + + if (container == null) { + return; + } + + if (container.ContentType != "Blog") { + return; + } + + var blog = container.As(); + + if (context.Format == "rss") { + context.Response.Element.SetElementValue("description", blog.Description); + } + else { + context.Builder.AddProperty(context, null, "description", blog.Description); + } + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj index 868eece16..e4d5f059e 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj @@ -72,6 +72,7 @@ +