mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
#18228: Applying IHmltFilter when rendering Rss
Work Item: 18228 --HG-- branch : 1.x
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
@@ -6,6 +7,7 @@ using System.Xml.Linq;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Core.Feeds.Models;
|
using Orchard.Core.Feeds.Models;
|
||||||
|
using Orchard.Services;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
namespace Orchard.Core.Feeds.StandardBuilders {
|
namespace Orchard.Core.Feeds.StandardBuilders {
|
||||||
@@ -13,10 +15,15 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
|||||||
public class CorePartsFeedItemBuilder : IFeedItemBuilder {
|
public class CorePartsFeedItemBuilder : IFeedItemBuilder {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
private readonly RouteCollection _routes;
|
private readonly RouteCollection _routes;
|
||||||
|
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
||||||
|
|
||||||
public CorePartsFeedItemBuilder(IContentManager contentManager, RouteCollection routes) {
|
public CorePartsFeedItemBuilder(
|
||||||
|
IContentManager contentManager,
|
||||||
|
RouteCollection routes,
|
||||||
|
IEnumerable<IHtmlFilter> htmlFilters) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_routes = routes;
|
_routes = routes;
|
||||||
|
_htmlFilters = htmlFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Populate(FeedContext context) {
|
public void Populate(FeedContext context) {
|
||||||
@@ -24,7 +31,8 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
|||||||
|
|
||||||
var inspector = new ItemInspector(
|
var inspector = new ItemInspector(
|
||||||
feedItem.Item,
|
feedItem.Item,
|
||||||
_contentManager.GetItemMetadata(feedItem.Item));
|
_contentManager.GetItemMetadata(feedItem.Item),
|
||||||
|
_htmlFilters);
|
||||||
|
|
||||||
|
|
||||||
// TODO: author
|
// TODO: author
|
||||||
|
@@ -1,21 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Core.Common.Settings;
|
||||||
using Orchard.Core.Routable.Models;
|
using Orchard.Core.Routable.Models;
|
||||||
|
using Orchard.Services;
|
||||||
|
|
||||||
namespace Orchard.Core.Feeds.StandardBuilders {
|
namespace Orchard.Core.Feeds.StandardBuilders {
|
||||||
public class ItemInspector {
|
public class ItemInspector {
|
||||||
private readonly IContent _item;
|
private readonly IContent _item;
|
||||||
private readonly ContentItemMetadata _metadata;
|
private readonly ContentItemMetadata _metadata;
|
||||||
|
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
||||||
private readonly ICommonPart _common;
|
private readonly ICommonPart _common;
|
||||||
private readonly RoutePart _routable;
|
private readonly RoutePart _routable;
|
||||||
private readonly BodyPart _body;
|
private readonly BodyPart _body;
|
||||||
|
|
||||||
public ItemInspector(IContent item, ContentItemMetadata metadata) {
|
public ItemInspector(IContent item, ContentItemMetadata metadata, IEnumerable<IHtmlFilter> htmlFilters) {
|
||||||
_item = item;
|
_item = item;
|
||||||
_metadata = metadata;
|
_metadata = metadata;
|
||||||
|
_htmlFilters = htmlFilters;
|
||||||
_common = item.Get<ICommonPart>();
|
_common = item.Get<ICommonPart>();
|
||||||
_routable = item.Get<RoutePart>();
|
_routable = item.Get<RoutePart>();
|
||||||
_body = item.Get<BodyPart>();
|
_body = item.Get<BodyPart>();
|
||||||
@@ -43,7 +49,7 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
|||||||
public string Description {
|
public string Description {
|
||||||
get {
|
get {
|
||||||
if (_body != null && !string.IsNullOrEmpty(_body.Text)) {
|
if (_body != null && !string.IsNullOrEmpty(_body.Text)) {
|
||||||
return _body.Text;
|
return _htmlFilters.Aggregate(_body.Text, (text, filter) => filter.ProcessContent(text, GetFlavor(_body)));
|
||||||
}
|
}
|
||||||
return Title;
|
return Title;
|
||||||
}
|
}
|
||||||
@@ -56,5 +62,12 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetFlavor(BodyPart part) {
|
||||||
|
var typePartSettings = part.Settings.GetModel<BodyTypePartSettings>();
|
||||||
|
return (typePartSettings != null && !string.IsNullOrWhiteSpace(typePartSettings.Flavor))
|
||||||
|
? typePartSettings.Flavor
|
||||||
|
: part.PartDefinition.Settings.GetModel<BodyPartSettings>().FlavorDefault;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -6,15 +7,18 @@ using Orchard.ContentManagement;
|
|||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Core.Feeds.Models;
|
using Orchard.Core.Feeds.Models;
|
||||||
using Orchard.Core.Feeds.StandardBuilders;
|
using Orchard.Core.Feeds.StandardBuilders;
|
||||||
|
using Orchard.Services;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
namespace Orchard.Core.Feeds.StandardQueries {
|
namespace Orchard.Core.Feeds.StandardQueries {
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class ContainerFeedQuery : IFeedQueryProvider, IFeedQuery {
|
public class ContainerFeedQuery : IFeedQueryProvider, IFeedQuery {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
||||||
|
|
||||||
public ContainerFeedQuery(IContentManager contentManager) {
|
public ContainerFeedQuery(IContentManager contentManager, IEnumerable<IHtmlFilter> htmlFilters) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
|
_htmlFilters = htmlFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FeedQueryMatch Match(FeedContext context) {
|
public FeedQueryMatch Match(FeedContext context) {
|
||||||
@@ -38,7 +42,7 @@ namespace Orchard.Core.Feeds.StandardQueries {
|
|||||||
var containerId = (int)containerIdValue.ConvertTo(typeof(int));
|
var containerId = (int)containerIdValue.ConvertTo(typeof(int));
|
||||||
var container = _contentManager.Get(containerId);
|
var container = _contentManager.Get(containerId);
|
||||||
|
|
||||||
var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container));
|
var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container), _htmlFilters);
|
||||||
if (context.Format == "rss") {
|
if (context.Format == "rss") {
|
||||||
var link = new XElement("link");
|
var link = new XElement("link");
|
||||||
context.Response.Element.SetElementValue("title", inspector.Title);
|
context.Response.Element.SetElementValue("title", inspector.Title);
|
||||||
|
Reference in New Issue
Block a user