mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 03:58:13 +08:00
Adding comment tokens
--HG-- branch : 1.x
This commit is contained in:
@@ -2,5 +2,5 @@
|
|||||||
6cd31f00d00d734408da2f2928220b0b7e59b293 src/Orchard.Web/Modules/Orchard.Projections
|
6cd31f00d00d734408da2f2928220b0b7e59b293 src/Orchard.Web/Modules/Orchard.Projections
|
||||||
204bdef384f41bb5e463bed6b98a056945a7d839 src/Orchard.Web/Modules/Orchard.Rules
|
204bdef384f41bb5e463bed6b98a056945a7d839 src/Orchard.Web/Modules/Orchard.Rules
|
||||||
ce578373f907c0a55fd91229a344f0755f290174 src/Orchard.Web/Modules/Orchard.TaskLease
|
ce578373f907c0a55fd91229a344f0755f290174 src/Orchard.Web/Modules/Orchard.TaskLease
|
||||||
cf73534c335f39e6d9695c2a0ce64c426d1be9f2 src/Orchard.Web/Modules/Orchard.Tokens
|
dfeb1f4ebcdc587267ab21bc6bbd1d5dde96e264 src/Orchard.Web/Modules/Orchard.Tokens
|
||||||
114e75928872042f092b0cc7cafa1a58c208d8ae src/orchard.web/modules/Orchard.Fields
|
114e75928872042f092b0cc7cafa1a58c208d8ae src/orchard.web/modules/Orchard.Fields
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using Orchard.Comments.Models;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Events;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Comments.Tokens {
|
||||||
|
public interface ITokenProvider : IEventHandler {
|
||||||
|
void Describe(dynamic context);
|
||||||
|
void Evaluate(dynamic context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CommentTokens : ITokenProvider {
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
|
public CommentTokens(IContentManager contentManager) {
|
||||||
|
_contentManager = contentManager;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public void Describe(dynamic context) {
|
||||||
|
context.For("Content", T("Content Items"), T("Content Items"))
|
||||||
|
.Token("CommentedOn", T("Commented On"), T("The content item this comment was created on."))
|
||||||
|
.Token("CommentMessage", T("Comment Message"), T("The text of the comment itself"))
|
||||||
|
.Token("CommentAuthor", T("Comment Author"), T("The author of the comment."))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Evaluate(dynamic context) {
|
||||||
|
context.For<IContent>("Content")
|
||||||
|
.Token("CommentedOn", (Func<IContent, object>)(content => content.As<CommentPart>().Record.CommentedOn))
|
||||||
|
.Chain("CommentedOn", "Content", (Func<IContent, object>)(content => _contentManager.Get(content.As<CommentPart>().Record.CommentedOn)))
|
||||||
|
.Token("CommentMessage", (Func<IContent, object>)(content => content.As<CommentPart>().Record.CommentText))
|
||||||
|
.Token("CommentAuthor", (Func<IContent, object>)CommentAuthor)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string CommentAuthor(IContent comment) {
|
||||||
|
var commentPart = comment.As<CommentPart>();
|
||||||
|
return String.IsNullOrWhiteSpace(commentPart.Record.UserName) ? commentPart.Record.Author : commentPart.Record.UserName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user