src/ZKEACMS.GlobalScripts/Service/GlobalScriptsProviderService.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/* http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
using Easy.RepositoryPattern;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using ZKEACMS.GlobalScripts.Models;
using Easy;
using Microsoft.AspNetCore.Http;
using ZKEACMS.Page;
using ZKEACMS.Event;
using ZKEACMS.Setting;
using Microsoft.AspNetCore.Html;
using Easy.Extend;
namespace ZKEACMS.GlobalScripts.Service
{
public abstract class GlobalScriptsProviderService<T> : IEventHandler where T : GlobalScript, new()
{
private readonly IApplicationContextAccessor _applicationContextAccessor;
private readonly IApplicationSettingService _applicationSettingService;
public GlobalScriptsProviderService(IApplicationContextAccessor applicationContextAccessor, IApplicationSettingService applicationSettingService)
{
_applicationContextAccessor = applicationContextAccessor;
_applicationSettingService = applicationSettingService;
}
public virtual void Handle(object entity, EventArg e)
{
CMSApplicationContext applicationContext = _applicationContextAccessor.Current;
var script = _applicationSettingService.Get<T>();
if (script != null && script.Script.IsNotNullAndWhiteSpace())
{
if (script.Script.IndexOf("</script>", StringComparison.OrdinalIgnoreCase) > 0)
{
HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();
htmlContentBuilder.AppendHtml(script.Script);
if (script.Location == (int)ScriptLocation.Header)
{
applicationContext.HeaderPart.Add(htmlContentBuilder);
}
else
{
applicationContext.FooterPart.Add(htmlContentBuilder);
}
}
else
{
HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();
htmlContentBuilder.AppendHtml("<script type=\"text/javascript\">");
htmlContentBuilder.AppendHtml(script.Script);
htmlContentBuilder.AppendHtml("</script>");
if (script.Location == (int)ScriptLocation.Header)
{
applicationContext.HeaderPart.Add(htmlContentBuilder);
}
后面还有 10 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。