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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
@@ -6,6 +7,7 @@ using System.Xml.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Feeds.Models;
|
||||
using Orchard.Services;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Core.Feeds.StandardBuilders {
|
||||
@@ -13,10 +15,15 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
||||
public class CorePartsFeedItemBuilder : IFeedItemBuilder {
|
||||
private readonly IContentManager _contentManager;
|
||||
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;
|
||||
_routes = routes;
|
||||
_htmlFilters = htmlFilters;
|
||||
}
|
||||
|
||||
public void Populate(FeedContext context) {
|
||||
@@ -24,7 +31,8 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
||||
|
||||
var inspector = new ItemInspector(
|
||||
feedItem.Item,
|
||||
_contentManager.GetItemMetadata(feedItem.Item));
|
||||
_contentManager.GetItemMetadata(feedItem.Item),
|
||||
_htmlFilters);
|
||||
|
||||
|
||||
// TODO: author
|
||||
|
@@ -1,21 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Routing;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Common.Settings;
|
||||
using Orchard.Core.Routable.Models;
|
||||
using Orchard.Services;
|
||||
|
||||
namespace Orchard.Core.Feeds.StandardBuilders {
|
||||
public class ItemInspector {
|
||||
private readonly IContent _item;
|
||||
private readonly ContentItemMetadata _metadata;
|
||||
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
||||
private readonly ICommonPart _common;
|
||||
private readonly RoutePart _routable;
|
||||
private readonly BodyPart _body;
|
||||
|
||||
public ItemInspector(IContent item, ContentItemMetadata metadata) {
|
||||
public ItemInspector(IContent item, ContentItemMetadata metadata, IEnumerable<IHtmlFilter> htmlFilters) {
|
||||
_item = item;
|
||||
_metadata = metadata;
|
||||
_htmlFilters = htmlFilters;
|
||||
_common = item.Get<ICommonPart>();
|
||||
_routable = item.Get<RoutePart>();
|
||||
_body = item.Get<BodyPart>();
|
||||
@@ -43,7 +49,7 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
||||
public string Description {
|
||||
get {
|
||||
if (_body != null && !string.IsNullOrEmpty(_body.Text)) {
|
||||
return _body.Text;
|
||||
return _htmlFilters.Aggregate(_body.Text, (text, filter) => filter.ProcessContent(text, GetFlavor(_body)));
|
||||
}
|
||||
return Title;
|
||||
}
|
||||
@@ -56,5 +62,12 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
||||
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.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using System.Xml.Linq;
|
||||
using JetBrains.Annotations;
|
||||
@@ -6,15 +7,18 @@ using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Feeds.Models;
|
||||
using Orchard.Core.Feeds.StandardBuilders;
|
||||
using Orchard.Services;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Core.Feeds.StandardQueries {
|
||||
[UsedImplicitly]
|
||||
public class ContainerFeedQuery : IFeedQueryProvider, IFeedQuery {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
||||
|
||||
public ContainerFeedQuery(IContentManager contentManager) {
|
||||
public ContainerFeedQuery(IContentManager contentManager, IEnumerable<IHtmlFilter> htmlFilters) {
|
||||
_contentManager = contentManager;
|
||||
_htmlFilters = htmlFilters;
|
||||
}
|
||||
|
||||
public FeedQueryMatch Match(FeedContext context) {
|
||||
@@ -38,7 +42,7 @@ namespace Orchard.Core.Feeds.StandardQueries {
|
||||
var containerId = (int)containerIdValue.ConvertTo(typeof(int));
|
||||
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") {
|
||||
var link = new XElement("link");
|
||||
context.Response.Element.SetElementValue("title", inspector.Title);
|
||||
|
Reference in New Issue
Block a user