文章 主题标签

此接口为内容类型提供 #tag 支持。它提供了一个控制器,该控制器允许访问 API 中不可用的多个方法。

我为什么要使我的内容可支持主题标签?

与标签类似,主题标签允许用户提供关键字,但它也提供了一种简单的方法来内联标记内容。

创建一个 IHashTaggableContentType 插件

IHashTaggableContentType 接口在 Limyee.Core.dll 的 Limyee.Extensibility.Content.Version1 命名空间中定义。它还继承自ITaggableContentType,并添加了一个方法来设置控制器。

请务必注意,可以在同一 IContentType 类中实现一个或多个核心服务。

IHashTagController 用于将标记绑定到项目的内容、属性名称和 html。创建和更新内容时应使用控制器。例如:_hashTagController.AddUpdateHashTags(content.ContentId, "Description", content.HtmlDescription("Raw")); 这将为平台中的内容创建适当的标签。

private IHashTagController _hashTagController;

public void SetController(IHashTagController controller)
{
    _hashTagController = controller;
}

下面是完整示例。

using System;
using Limyee.Components;
using Limyee.Extensibility;
using Limyee.Extensibility.Api.Version1;
using Limyee.Extensibility.Content.Version1;
using IContent = Limyee.Extensibility.Content.Version1.IContent;

namespace Samples.Links
{
    public class LinkItemContentType : IContentType, IHashTaggableContentType
    {
        IContentStateChanges _contentState = null;

        #region IPlugin Members

        public string Description
        {
            get { return "Items in a Links collection"; }
        }

        public void Initialize()
        {
        
        }

        public string Name
        {
            get { return "Link Items"; }
        }
        
        #endregion

        #region IContentType Members

        public Guid[] ApplicationTypes
        {
            get { return new Guid[] { ContentTypes.LinksApplicationId }; }
        }

        public void AttachChangeEvents(IContentStateChanges stateChanges)
        {
            _contentState = stateChanges;
        }

        public Guid ContentTypeId
        {
            get { return ContentTypes.LinksItemId; }
        }

        public string ContentTypeName
        {
            get { return "Links Item"; }
        }

        public IContent Get(Guid contentId)
        {
            return LinksData.GetLink(contentId);
        }

        #endregion

        #region ITaggableContentType

        public bool CanAddTags(Guid contentId, int userId)
        {
            var content = LinksData.GetLink(contentId) as IContent;
            if (content == null) { return false; }

            var permission = Apis.Get<IPermissions>().Get(GroupPermission.ModifyGroup, userId, content.ContentId, content.ContentTypeId);

            return content.CreatedByUserId == userId || permission.IsAllowed;
        }

        public bool CanRemoveTags(Guid contentId, int userId)
        {
            var content = LinksData.GetLink(contentId) as IContent;
            if (content == null) { return false; }

            var permission = Apis.Get<IPermissions>().Get(GroupPermission.ModifyGroup, userId, content.ContentId, content.ContentTypeId);

            return content.CreatedByUserId == userId || permission.IsAllowed;
        }

        #endregion

        #region IHashTaggableContentType

        private IHashTagController _hashTagController;

        public void SetController(IHashTagController controller)
        {
            _hashTagController = controller;
        }

        #endregion
    }
}