public void Page_Load(object sender, EventArgs e) { if (IsForbidden) { return; } PageUtils.CheckRequestParameter("siteId"); if (AuthRequest.IsQueryExists("FileName")) { _fileName = AuthRequest.GetQueryString("FileName"); _fileName = PathUtils.RemoveParentPath(_fileName); } _directoryPath = PathUtility.MapPath(SiteInfo, "@/include"); if (IsPostBack) { return; } VerifySitePermissions(ConfigManager.WebSitePermissions.Template); LtlPageTitle.Text = string.IsNullOrEmpty(_fileName) ? "添加包含文件" : "编辑包含文件"; var isCodeMirror = SiteInfo.Additional.ConfigTemplateIsCodeMirror; BtnEditorType.Text = isCodeMirror ? "采用纯文本编辑模式" : "采用代码编辑模式"; PhCodeMirror.Visible = isCodeMirror; ECharsetUtils.AddListItems(DdlCharset); if (_fileName != null) { if (!EFileSystemTypeUtils.IsHtml(PathUtils.GetExtension(_fileName))) { PageUtils.RedirectToErrorPage("对不起,此文件无法编辑!"); } else { TbRelatedFileName.Text = PathUtils.RemoveExtension(_fileName); LtlCreatedFileExtName.Text = PathUtils.GetExtension(_fileName); var fileCharset = FileUtils.GetFileCharset(PathUtils.Combine(_directoryPath, _fileName)); ControlUtils.SelectSingleItemIgnoreCase(DdlCharset, ECharsetUtils.GetValue(fileCharset)); TbContent.Text = FileUtils.ReadText(PathUtils.Combine(_directoryPath, _fileName), fileCharset); } } else { LtlCreatedFileExtName.Text = ".html"; ControlUtils.SelectSingleItemIgnoreCase(DdlCharset, SiteInfo.Additional.Charset); } }
public void Page_Load(object sender, EventArgs e) { if (IsForbidden) { return; } PageUtils.CheckRequestParameter("PublishmentSystemID"); if (Body.IsQueryExists("FileName")) { fileName = Body.GetQueryString("FileName"); fileName = PathUtils.RemoveParentPath(fileName); } directoryPath = PathUtility.MapPath(PublishmentSystemInfo, "@/include"); if (!IsPostBack) { var pageTitle = string.IsNullOrEmpty(fileName) ? "添加包含文件" : "编辑包含文件"; BreadCrumb(AppManager.Cms.LeftMenu.IdTemplate, pageTitle, AppManager.Cms.Permission.WebSite.Template); ltlPageTitle.Text = pageTitle; ECharsetUtils.AddListItems(Charset); if (fileName != null) { if (!EFileSystemTypeUtils.IsHtml(PathUtils.GetExtension(fileName))) { PageUtils.RedirectToErrorPage("对不起,此文件无法编辑!"); } else { RelatedFileName.Text = PathUtils.RemoveExtension(fileName); ltlCreatedFileExtName.Text = PathUtils.GetExtension(fileName); var fileCharset = FileUtils.GetFileCharset(PathUtils.Combine(directoryPath, fileName)); ControlUtils.SelectListItemsIgnoreCase(Charset, ECharsetUtils.GetValue(fileCharset)); Content.Text = FileUtils.ReadText(PathUtils.Combine(directoryPath, fileName), fileCharset); } } else { ltlCreatedFileExtName.Text = ".html"; ControlUtils.SelectListItemsIgnoreCase(Charset, PublishmentSystemInfo.Additional.Charset); } } }
public static void ParseStl(PublishmentSystemInfo publishmentSystemInfo, PageInfo pageInfo, ContextInfo contextInfo, StringBuilder contentBuilder, string filePath, bool isDynamic) { if (contentBuilder.Length > 0) { StlParserManager.ParseTemplateContent(contentBuilder, pageInfo, contextInfo); } if (EFileSystemTypeUtils.IsHtml(PathUtils.GetExtension(filePath))) { if (pageInfo.TemplateInfo.TemplateType != ETemplateType.FileTemplate) { AddSeoMetaToContent(pageInfo, contentBuilder); } AddAdvertisementsToContent(pageInfo); if (isDynamic) { var pageUrl = PageUtils.AddProtocolToUrl(PageUtility.GetPublishmentSystemUrlByPhysicalPath(publishmentSystemInfo, filePath)); string templateString = $@" <base href=""{pageUrl}"" />"; StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString); } if (pageInfo.PublishmentSystemInfo.Additional.IsCreateBrowserNoCache) { const string templateString = @" <META HTTP-EQUIV=""Pragma"" CONTENT=""no-cache""> <META HTTP-EQUIV=""Expires"" CONTENT=""-1"">"; StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString); } if (pageInfo.PublishmentSystemInfo.Additional.IsCreateIe8Compatible) { const string templateString = @" <META HTTP-EQUIV=""x-ua-compatible"" CONTENT=""ie=7"" />"; StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString); } if (pageInfo.PublishmentSystemInfo.Additional.IsCreateJsIgnoreError) { const string templateString = @" <script type=""text/javascript"">window.onerror=function(){return true;}</script>"; StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString); } if (pageInfo.PageContentId > 0 && pageInfo.PublishmentSystemInfo.Additional.IsCountHits && !pageInfo.IsPageScriptsExists(PageInfo.JsAdStlCountHits)) { pageInfo.AddPageEndScriptsIfNotExists(PageInfo.JsAdStlCountHits, $@" <script src=""{ActionsAddContentHits.GetUrl(pageInfo.ApiUrl, pageInfo.PublishmentSystemId, pageInfo.PageNodeId, pageInfo.PageContentId)}"" type=""text/javascript""></script>"); } if (pageInfo.PublishmentSystemInfo.Additional.IsTracker && !pageInfo.IsPageScriptsExists(PageInfo.JsAdAddTracker)) { pageInfo.AddPageEndScriptsIfNotExists(PageInfo.JsAdAddTracker, $@" <script src=""{SiteFilesAssets.Tracker.GetScriptUrl(pageInfo.ApiUrl)}"" type=""text/javascript""></script> <script type=""text/javascript"">AddTrackerCount('{ActionsAddTrackerCount.GetUrl(pageInfo.ApiUrl, pageInfo.PublishmentSystemId, pageInfo.PageNodeId, pageInfo.PageContentId)}', {pageInfo.PublishmentSystemId});</script>"); } var headScripts = StlParserManager.GetPageInfoHeadScript(pageInfo, contextInfo); if (!string.IsNullOrEmpty(headScripts)) { if (contentBuilder.ToString().IndexOf("</head>", StringComparison.Ordinal) != -1 || contentBuilder.ToString().IndexOf("</HEAD>", StringComparison.Ordinal) != -1) { StringUtils.InsertBefore(new[] { "</head>", "</HEAD>" }, contentBuilder, headScripts); } else { contentBuilder.Insert(0, headScripts); } } var afterBodyScripts = StlParserManager.GetPageInfoScript(pageInfo, true); if (!string.IsNullOrEmpty(afterBodyScripts)) { if (contentBuilder.ToString().IndexOf("<body", StringComparison.Ordinal) != -1 || contentBuilder.ToString().IndexOf("<BODY", StringComparison.Ordinal) != -1) { var index = contentBuilder.ToString().IndexOf("<body", StringComparison.Ordinal); if (index == -1) { index = contentBuilder.ToString().IndexOf("<BODY", StringComparison.Ordinal); } index = contentBuilder.ToString().IndexOf(">", index, StringComparison.Ordinal); contentBuilder.Insert(index + 1, StringUtils.Constants.ReturnAndNewline + afterBodyScripts + StringUtils.Constants.ReturnAndNewline); } else { contentBuilder.Insert(0, afterBodyScripts); } } var beforeBodyScripts = StlParserManager.GetPageInfoScript(pageInfo, false); if (!string.IsNullOrEmpty(beforeBodyScripts)) { if (contentBuilder.ToString().IndexOf("</body>", StringComparison.Ordinal) != -1 || contentBuilder.ToString().IndexOf("</BODY>", StringComparison.Ordinal) != -1) { var index = contentBuilder.ToString().IndexOf("</body>", StringComparison.Ordinal); if (index == -1) { index = contentBuilder.ToString().IndexOf("</BODY>", StringComparison.Ordinal); } contentBuilder.Insert(index, StringUtils.Constants.ReturnAndNewline + beforeBodyScripts + StringUtils.Constants.ReturnAndNewline); } else { contentBuilder.Append(beforeBodyScripts); } } if (pageInfo.PublishmentSystemInfo.Additional.IsCreateDoubleClick) { var fileTemplateId = 0; if (pageInfo.TemplateInfo.TemplateType == ETemplateType.FileTemplate) { fileTemplateId = pageInfo.TemplateInfo.TemplateId; } var ajaxUrl = ActionsTrigger.GetUrl(pageInfo.PublishmentSystemInfo.Additional.ApiUrl, pageInfo.PublishmentSystemId, contextInfo.ChannelID, contextInfo.ContentID, fileTemplateId, true); pageInfo.AddPageEndScriptsIfNotExists("CreateDoubleClick", $@" <script type=""text/javascript"" language=""javascript"">document.ondblclick=function(x){{location.href = '{ajaxUrl}';}}</script>"); } if (pageInfo.PageEndScriptKeys.Count > 0) { var endScriptBuilder = new StringBuilder(); foreach (string scriptKey in pageInfo.PageEndScriptKeys) { endScriptBuilder.Append(pageInfo.GetPageEndScripts(scriptKey)); } endScriptBuilder.Append(StringUtils.Constants.ReturnAndNewline); //contentBuilder.Append(endScriptBuilder.ToString()); //StringUtils.InsertBeforeOrAppend(new string[] { "</body>", "</BODY>" }, contentBuilder, endScriptBuilder.ToString()); StringUtils.InsertAfterOrAppend(new[] { "</html>", "</html>" }, contentBuilder, endScriptBuilder.ToString()); } if (pageInfo.PublishmentSystemInfo.Additional.IsCreateShowPageInfo) { contentBuilder.Append($@" <!-- {pageInfo.TemplateInfo.RelatedFileName}({ETemplateTypeUtils.GetText(pageInfo.TemplateInfo.TemplateType)}) -->"); } } }
public static void Parse(SiteInfo siteInfo, PageInfo pageInfo, ContextInfo contextInfo, StringBuilder contentBuilder, string filePath, bool isDynamic) { foreach (var service in PluginManager.Services) { try { service.OnBeforeStlParse(new ParseEventArgs(pageInfo.SiteId, pageInfo.PageChannelId, pageInfo.PageContentId, pageInfo.TemplateInfo.TemplateType, pageInfo.TemplateInfo.Id, filePath, contentBuilder)); } catch (Exception ex) { LogUtils.AddPluginErrorLog(service.PluginId, ex, nameof(service.OnBeforeStlParse)); } } if (contentBuilder.Length > 0) { StlParserManager.ParseTemplateContent(contentBuilder, pageInfo, contextInfo); } if (EFileSystemTypeUtils.IsHtml(PathUtils.GetExtension(filePath))) { if (isDynamic) { var pageUrl = PageUtils.AddProtocolToUrl(PageUtils.ParseNavigationUrl($"~/{PathUtils.GetPathDifference(WebConfigUtils.PhysicalApplicationPath, filePath)}")); string templateString = $@" <base href=""{pageUrl}"" />"; StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString); } if (pageInfo.SiteInfo.Additional.IsCreateBrowserNoCache) { const string templateString = @" <META HTTP-EQUIV=""Pragma"" CONTENT=""no-cache""> <META HTTP-EQUIV=""Expires"" CONTENT=""-1"">"; StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString); } if (pageInfo.SiteInfo.Additional.IsCreateIe8Compatible) { const string templateString = @" <META HTTP-EQUIV=""x-ua-compatible"" CONTENT=""ie=7"" />"; StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString); } if (pageInfo.SiteInfo.Additional.IsCreateJsIgnoreError) { const string templateString = @" <script type=""text/javascript"">window.onerror=function(){return true;}</script>"; StringUtils.InsertAfter(new[] { "<head>", "<HEAD>" }, contentBuilder, templateString); } if (pageInfo.PageContentId > 0 && pageInfo.SiteInfo.Additional.IsCountHits && !pageInfo.BodyCodes.ContainsKey(PageInfo.Const.JsAdStlCountHits)) { if (!pageInfo.FootCodes.ContainsKey(PageInfo.Const.JsAdStlCountHits)) { pageInfo.FootCodes.Add(PageInfo.Const.JsAdStlCountHits, $@" <script src=""{ApiRouteActionsAddContentHits.GetUrl(pageInfo.ApiUrl, pageInfo.SiteId, pageInfo.PageChannelId, pageInfo.PageContentId)}"" type=""text/javascript""></script>"); } } var isShowPageInfo = pageInfo.SiteInfo.Additional.IsCreateShowPageInfo; if (!pageInfo.IsLocal) { if (pageInfo.SiteInfo.Additional.IsCreateDoubleClick) { var fileTemplateId = 0; if (pageInfo.TemplateInfo.TemplateType == TemplateType.FileTemplate) { fileTemplateId = pageInfo.TemplateInfo.Id; } var apiUrl = pageInfo.ApiUrl; var ajaxUrl = ApiRouteActionsTrigger.GetUrl(apiUrl, pageInfo.SiteId, contextInfo.ChannelId, contextInfo.ContentId, fileTemplateId, true); if (!pageInfo.FootCodes.ContainsKey("CreateDoubleClick")) { pageInfo.FootCodes.Add("CreateDoubleClick", $@" <script type=""text/javascript"" language=""javascript"">document.ondblclick=function(x){{location.href = '{ajaxUrl}&returnUrl=' + encodeURIComponent(location.search);}}</script>"); } } } else { isShowPageInfo = true; } if (isShowPageInfo) { contentBuilder.Append($@" <!-- {pageInfo.TemplateInfo.RelatedFileName}({TemplateTypeUtils.GetText(pageInfo.TemplateInfo.TemplateType)}) -->"); } var headScripts = StlParserManager.GetPageInfoHeadScript(pageInfo, contextInfo); if (!string.IsNullOrEmpty(headScripts)) { if (contentBuilder.ToString().IndexOf("</head>", StringComparison.Ordinal) != -1 || contentBuilder.ToString().IndexOf("</HEAD>", StringComparison.Ordinal) != -1) { StringUtils.InsertBefore(new[] { "</head>", "</HEAD>" }, contentBuilder, headScripts); } else { contentBuilder.Insert(0, headScripts); } } var afterBodyScripts = StlParserManager.GetPageBodyCodes(pageInfo); if (!string.IsNullOrEmpty(afterBodyScripts)) { if (contentBuilder.ToString().IndexOf("<body", StringComparison.Ordinal) != -1 || contentBuilder.ToString().IndexOf("<BODY", StringComparison.Ordinal) != -1) { var index = contentBuilder.ToString().IndexOf("<body", StringComparison.Ordinal); if (index == -1) { index = contentBuilder.ToString().IndexOf("<BODY", StringComparison.Ordinal); } index = contentBuilder.ToString().IndexOf(">", index, StringComparison.Ordinal); contentBuilder.Insert(index + 1, StringUtils.Constants.ReturnAndNewline + afterBodyScripts + StringUtils.Constants.ReturnAndNewline); } else { contentBuilder.Insert(0, afterBodyScripts); } } if (pageInfo.FootCodes.Count > 0) { var builder = new StringBuilder(); foreach (var key in pageInfo.FootCodes.Keys) { builder.Append(pageInfo.FootCodes[key]); } builder.Append(StringUtils.Constants.ReturnAndNewline); //contentBuilder.Append(endScriptBuilder.ToString()); //StringUtils.InsertBeforeOrAppend(new string[] { "</body>", "</BODY>" }, contentBuilder, endScriptBuilder.ToString()); StringUtils.InsertAfterOrAppend(new[] { "</html>", "</html>" }, contentBuilder, builder.ToString()); } } foreach (var service in PluginManager.Services) { try { service.OnAfterStlParse(new ParseEventArgs(pageInfo.SiteId, pageInfo.PageChannelId, pageInfo.PageContentId, pageInfo.TemplateInfo.TemplateType, pageInfo.TemplateInfo.Id, filePath, contentBuilder)); } catch (Exception ex) { LogUtils.AddPluginErrorLog(service.PluginId, ex, nameof(service.OnAfterStlParse)); } } }