mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding support for RSS feed proxies
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
|
||||
namespace Orchard.Core.Feeds {
|
||||
public interface IFeedManager : IDependency {
|
||||
void Register(string title, string format, RouteValueDictionary values);
|
||||
void Register(string title, string format, string url);
|
||||
MvcHtmlString GetRegisteredLinks(HtmlHelper html);
|
||||
|
||||
// Currently implemented in FeedController action... tbd
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
@@ -12,6 +13,7 @@ namespace Orchard.Core.Feeds.Services {
|
||||
class Link {
|
||||
public string Title { get; set; }
|
||||
public RouteValueDictionary RouteValues { get; set; }
|
||||
public string Url { get; set; }
|
||||
}
|
||||
|
||||
public void Register(string title, string format, RouteValueDictionary values) {
|
||||
@@ -28,14 +30,16 @@ namespace Orchard.Core.Feeds.Services {
|
||||
_links.Add(new Link { Title = title, RouteValues = link });
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Register(string title, string format, string url) {
|
||||
_links.Add(new Link { Title = title, Url = url });
|
||||
}
|
||||
|
||||
public MvcHtmlString GetRegisteredLinks(HtmlHelper html) {
|
||||
var urlHelper = new UrlHelper(html.ViewContext.RequestContext, html.RouteCollection);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (var link in _links) {
|
||||
var linkUrl = urlHelper.RouteUrl(link.RouteValues);
|
||||
var linkUrl = String.IsNullOrWhiteSpace(link.Url) ? urlHelper.RouteUrl(link.RouteValues) : link.Url;
|
||||
sb.Append("\r\n");
|
||||
sb.Append(@"<link rel=""alternate"" type=""application/rss+xml""");
|
||||
if (!string.IsNullOrEmpty(link.Title)) {
|
||||
|
@@ -54,11 +54,17 @@ namespace Orchard.Blogs.Drivers {
|
||||
if (postCount != null) {
|
||||
part.PostCount = Convert.ToInt32(postCount);
|
||||
}
|
||||
|
||||
var feedProxyUrl = context.Attribute(part.PartDefinition.Name, "FeedProxyUrl");
|
||||
if (feedProxyUrl != null) {
|
||||
part.FeedProxyUrl = feedProxyUrl;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(BlogPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Description", part.Description);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("PostCount", part.PostCount);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("FeedProxyUrl", part.FeedProxyUrl);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Core.Feeds;
|
||||
@@ -5,8 +6,17 @@ using Orchard.Core.Feeds;
|
||||
namespace Orchard.Blogs.Extensions {
|
||||
public static class FeedManagerExtensions {
|
||||
public static void Register(this IFeedManager feedManager, BlogPart blogPart, string blogTitle) {
|
||||
feedManager.Register(blogTitle, "rss", new RouteValueDictionary { { "containerid", blogPart.Id } });
|
||||
feedManager.Register(blogTitle + " - Comments", "rss", new RouteValueDictionary { { "commentedoncontainer", blogPart.Id } });
|
||||
|
||||
if (String.IsNullOrWhiteSpace(blogPart.FeedProxyUrl)) {
|
||||
feedManager.Register(blogTitle, "rss", new RouteValueDictionary {{"containerid", blogPart.Id}});
|
||||
}
|
||||
else {
|
||||
feedManager.Register(blogTitle, "rss", blogPart.FeedProxyUrl);
|
||||
}
|
||||
|
||||
if (blogPart.EnableCommentsFeed) {
|
||||
feedManager.Register(blogTitle + " - Comments", "rss", new RouteValueDictionary {{"commentedoncontainer", blogPart.Id}});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,5 +17,15 @@ namespace Orchard.Blogs.Models {
|
||||
get { return this.Retrieve(x => x.PostCount); }
|
||||
set { this.Store(x => x.PostCount, value); }
|
||||
}
|
||||
|
||||
public string FeedProxyUrl {
|
||||
get { return this.Retrieve(x => x.FeedProxyUrl); }
|
||||
set { this.Store(x => x.FeedProxyUrl, value); }
|
||||
}
|
||||
|
||||
public bool EnableCommentsFeed {
|
||||
get { return this.Retrieve(x => x.EnableCommentsFeed, false); }
|
||||
set { this.Store(x => x.EnableCommentsFeed, value); }
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,20 @@
|
||||
@model Orchard.Blogs.Models.BlogPart
|
||||
@using Orchard.Mvc.Extensions
|
||||
@model Orchard.Blogs.Models.BlogPart
|
||||
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.Description, T("Description"))
|
||||
@Html.TextAreaFor(m => m.Description, 5, 60, null)
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.FeedProxyUrl, T("Feed proxy Url"))
|
||||
@Html.TextBoxFor(m => m.FeedProxyUrl, new { @class = "text medium" })
|
||||
<span class="hint">@T("Provide a custom public url which will be used to proxy the local rss feed.")</span>
|
||||
<span class="hint">@T("The current feed is available at <a href=\"{0}\">{0}</a>.", Url.AbsoluteAction("Index", "Feed", new { area = "Feeds", containerid = Model.Id }))</span>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
@Html.CheckBoxFor(m => m.EnableCommentsFeed)
|
||||
@Html.LabelFor(m => m.EnableCommentsFeed, T("Render a comments rss feed").Text, new { @class = "forcheckbox" })
|
||||
<span class="hint">@T("Enable to render the comments rss feed.")</span>
|
||||
</fieldset>
|
||||
|
Reference in New Issue
Block a user