mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Fix RSS feed for comments
Need to use "Comment" content item instead of "CommentRecord" --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045909
This commit is contained in:
@@ -24,14 +24,14 @@ namespace Orchard.Comments.Feeds {
|
||||
Localizer T { get; set; }
|
||||
|
||||
public void Populate(FeedContext context) {
|
||||
foreach (var feedItem in context.Response.Items.OfType<FeedItem<CommentRecord>>()) {
|
||||
foreach (var feedItem in context.Response.Items.OfType<FeedItem<Comment>>()) {
|
||||
var comment = feedItem.Item;
|
||||
var commentedOn = _contentManager.Get(feedItem.Item.CommentedOn);
|
||||
var commentedOn = _contentManager.Get(feedItem.Item.Record.CommentedOn);
|
||||
var commentedOnInspector = new ItemInspector(
|
||||
commentedOn,
|
||||
_contentManager.GetItemMetadata(commentedOn));
|
||||
|
||||
var title = T("Comment on {0} by {1}", commentedOnInspector.Title, comment.Author);
|
||||
var title = T("Comment on {0} by {1}", commentedOnInspector.Title, comment.Record.Author);
|
||||
|
||||
|
||||
// add to known formats
|
||||
@@ -40,14 +40,14 @@ namespace Orchard.Comments.Feeds {
|
||||
var guid = new XElement("guid", new XAttribute("isPermaLink", "false"));
|
||||
context.Response.Contextualize(requestContext => {
|
||||
var urlHelper = new UrlHelper(requestContext);
|
||||
link.Add(urlHelper.RouteUrl(commentedOnInspector.Link) + "#comment-" + comment.Id);
|
||||
guid.Add("urn:comment:" + comment.Id);
|
||||
link.Add(urlHelper.RouteUrl(commentedOnInspector.Link) + "#comment-" + comment.Record.Id);
|
||||
guid.Add("urn:comment:" + comment.Record.Id);
|
||||
});
|
||||
|
||||
feedItem.Element.SetElementValue("title", title);
|
||||
feedItem.Element.Add(link);
|
||||
feedItem.Element.SetElementValue("description", comment.CommentText);
|
||||
feedItem.Element.SetElementValue("pubDate", comment.CommentDateUtc);//TODO: format
|
||||
feedItem.Element.SetElementValue("description", comment.Record.CommentText);
|
||||
feedItem.Element.SetElementValue("pubDate", comment.Record.CommentDateUtc);//TODO: format
|
||||
feedItem.Element.Add(guid);
|
||||
}
|
||||
else {
|
||||
@@ -57,9 +57,9 @@ namespace Orchard.Comments.Feeds {
|
||||
context.Builder.AddProperty(context, feedItem1, "link", urlHelper.RouteUrl(commentedOnInspector.Link));
|
||||
});
|
||||
context.Builder.AddProperty(context, feedItem, "title", title.ToString());
|
||||
context.Builder.AddProperty(context, feedItem, "description", comment.CommentText);
|
||||
context.Builder.AddProperty(context, feedItem, "description", comment.Record.CommentText);
|
||||
|
||||
context.Builder.AddProperty(context, feedItem, "published-date", Convert.ToString(comment.CommentDateUtc)); // format? cvt to generic T?
|
||||
context.Builder.AddProperty(context, feedItem, "published-date", Convert.ToString(comment.Record.CommentDateUtc)); // format? cvt to generic T?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Feeds;
|
||||
using Orchard.Core.Feeds.Models;
|
||||
using Orchard.Data;
|
||||
@@ -7,11 +8,10 @@ using Orchard.Data;
|
||||
namespace Orchard.Comments.Feeds {
|
||||
[UsedImplicitly]
|
||||
public class CommentedOnFeedQuery : IFeedQueryProvider, IFeedQuery {
|
||||
private readonly IRepository<CommentRecord> _commentRepository;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public CommentedOnFeedQuery(
|
||||
IRepository<CommentRecord> commentRepository) {
|
||||
_commentRepository = commentRepository;
|
||||
public CommentedOnFeedQuery(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
public FeedQueryMatch Match(FeedContext context) {
|
||||
@@ -29,10 +29,11 @@ namespace Orchard.Comments.Feeds {
|
||||
if (limitValue != null)
|
||||
limit = (int)limitValue.ConvertTo(typeof(int));
|
||||
|
||||
var comments = _commentRepository.Fetch(
|
||||
x => x.CommentedOn == commentedOn && x.Status == CommentStatus.Approved,
|
||||
o => o.Desc(x => x.CommentDateUtc),
|
||||
0, limit);
|
||||
var comments = _contentManager
|
||||
.Query<Comment, CommentRecord>()
|
||||
.Where(x => x.CommentedOn == commentedOn && x.Status == CommentStatus.Approved)
|
||||
.OrderByDescending(x => x.CommentDateUtc)
|
||||
.Slice(0, limit);
|
||||
|
||||
foreach (var comment in comments) {
|
||||
context.Builder.AddItem(context, comment);
|
||||
|
@@ -118,7 +118,7 @@ namespace Orchard.Comments.Services {
|
||||
comment.Record.UserName = (CurrentUser == null ? "Anonymous" : CurrentUser.UserName);
|
||||
comment.Record.CommentedOn = context.CommentedOn;
|
||||
|
||||
comment.Record.Status = _commentValidator.ValidateComment(comment.Record) ? CommentStatus.Pending : CommentStatus.Spam;
|
||||
comment.Record.Status = _commentValidator.ValidateComment(comment) ? CommentStatus.Pending : CommentStatus.Spam;
|
||||
|
||||
// store id of the next layer for large-grained operations, e.g. rss on blog
|
||||
//TODO:(rpaquay) Get rid of this (comment aspect takes care of container)
|
||||
|
@@ -27,7 +27,7 @@ namespace Orchard.Comments.Services {
|
||||
|
||||
#region Implementation of ICommentValidator
|
||||
|
||||
public bool ValidateComment(CommentRecord comment) {
|
||||
public bool ValidateComment(Comment comment) {
|
||||
CommentSettingsRecord commentSettingsRecord = CurrentSite.As<CommentSettings>().Record;
|
||||
string akismetKey = commentSettingsRecord.AkismetKey;
|
||||
string akismetUrl = commentSettingsRecord.AkismetUrl;
|
||||
@@ -44,11 +44,11 @@ namespace Orchard.Comments.Services {
|
||||
}
|
||||
Akismet akismetApi = new Akismet(akismetKey, akismetUrl, null);
|
||||
AkismetComment akismetComment = new AkismetComment {
|
||||
CommentAuthor = comment.Author,
|
||||
CommentAuthorEmail = comment.Email,
|
||||
Blog = comment.SiteName,
|
||||
CommentAuthorUrl = comment.SiteName,
|
||||
CommentContent = comment.CommentText,
|
||||
CommentAuthor = comment.Record.Author,
|
||||
CommentAuthorEmail = comment.Record.Email,
|
||||
Blog = comment.Record.SiteName,
|
||||
CommentAuthorUrl = comment.Record.SiteName,
|
||||
CommentContent = comment.Record.CommentText,
|
||||
UserAgent = HttpContext.Current.Request.UserAgent,
|
||||
};
|
||||
|
||||
|
@@ -2,6 +2,6 @@ using Orchard.Comments.Models;
|
||||
|
||||
namespace Orchard.Comments.Services {
|
||||
public interface ICommentValidator : IDependency {
|
||||
bool ValidateComment(CommentRecord comment);
|
||||
bool ValidateComment(Comment comment);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user