private HttpResponseMessage GetResponseMessage(VisualInfo visualInfo) { if (visualInfo.SiteInfo == null || visualInfo.TemplateInfo == null) { return(null); } var siteInfo = visualInfo.SiteInfo; var templateInfo = visualInfo.TemplateInfo; var pageInfo = new PageInfo(visualInfo.ChannelId, visualInfo.ContentId, siteInfo, templateInfo, new Dictionary <string, object>()) { IsLocal = true }; var contextInfo = new ContextInfo(pageInfo) { ContextType = visualInfo.ContextType }; var contentBuilder = new StringBuilder(TemplateManager.GetTemplateContent(siteInfo, templateInfo)); //需要完善,考虑单页模板、内容正文、翻页及外部链接 if (templateInfo.TemplateType == TemplateType.FileTemplate) //单页 { Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); return(Response(contentBuilder.ToString(), siteInfo)); } if (templateInfo.TemplateType == TemplateType.IndexPageTemplate || templateInfo.TemplateType == TemplateType.ChannelTemplate) //栏目页面 { var nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, visualInfo.ChannelId); if (nodeInfo == null) { return(null); } if (nodeInfo.ParentId > 0) { if (!string.IsNullOrEmpty(nodeInfo.LinkUrl)) { PageUtils.Redirect(nodeInfo.LinkUrl); return(null); } } var stlLabelList = StlParserUtility.GetStlLabelList(contentBuilder.ToString()); //如果标签中存在Content var stlContentElement = string.Empty; foreach (var label in stlLabelList) { if (StlParserUtility.IsStlChannelElement(label, ChannelAttribute.PageContent)) { stlContentElement = label; break; } } if (!string.IsNullOrEmpty(stlContentElement))//内容存在 { var innerBuilder = new StringBuilder(stlContentElement); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); var contentAttributeHtml = innerBuilder.ToString(); var pageCount = StringUtils.GetCount(ContentUtility.PagePlaceHolder, contentAttributeHtml) + 1;//一共需要的页数 if (pageCount > 1) { Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var index = contentAttributeHtml.IndexOf(ContentUtility.PagePlaceHolder, StringComparison.Ordinal); var length = index == -1 ? contentAttributeHtml.Length : index; if (currentPageIndex == visualInfo.PageIndex) { var pagedContentAttributeHtml = contentAttributeHtml.Substring(0, length); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlContentElement, pagedContentAttributeHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, 0); return(Response(pagedBuilder.ToString(), siteInfo)); } if (index != -1) { contentAttributeHtml = contentAttributeHtml.Substring(length + ContentUtility.PagePlaceHolder.Length); } } return(null); } contentBuilder.Replace(stlContentElement, contentAttributeHtml); } if (StlParserUtility.IsStlElementExists(StlPageContents.ElementName, stlLabelList))//如果标签中存在<stl:pageContents> { var stlElement = StlParserUtility.GetStlElement(StlPageContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageContentsElementParser = new StlPageContents(stlElement, pageInfo, contextInfo); var pageCount = pageContentsElementParser.GetPageCount(out var totalNum); Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == visualInfo.PageIndex) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, false); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); return(Response(pagedBuilder.ToString(), siteInfo)); } } } else if (StlParserUtility.IsStlElementExists(StlPageChannels.ElementName, stlLabelList))//如果标签中存在<stl:pageChannels> { var stlElement = StlParserUtility.GetStlElement(StlPageChannels.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageChannelsElementParser = new StlPageChannels(stlElement, pageInfo, contextInfo); var pageCount = pageChannelsElementParser.GetPageCount(out var totalNum); Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == visualInfo.PageIndex) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var pageHtml = pageChannelsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); return(Response(pagedBuilder.ToString(), siteInfo)); } } } else if (StlParserUtility.IsStlElementExists(StlPageSqlContents.ElementName, stlLabelList))//如果标签中存在<stl:pageSqlContents> { var stlElement = StlParserUtility.GetStlElement(StlPageSqlContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageSqlContentsElementParser = new StlPageSqlContents(stlElement, pageInfo, contextInfo); var pageCount = pageSqlContentsElementParser.GetPageCount(out var totalNum); Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == visualInfo.PageIndex) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var pageHtml = pageSqlContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, false); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); return(Response(pagedBuilder.ToString(), siteInfo)); } } } Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); return(Response(contentBuilder.ToString(), siteInfo)); } if (templateInfo.TemplateType == TemplateType.ContentTemplate) //内容页面 { if (contextInfo.ContentInfo == null) { return(null); } if (!string.IsNullOrEmpty(contextInfo.ContentInfo.GetString(ContentAttribute.LinkUrl))) { PageUtils.Redirect(contextInfo.ContentInfo.GetString(ContentAttribute.LinkUrl)); return(null); } var stlLabelList = StlParserUtility.GetStlLabelList(contentBuilder.ToString()); if (StlParserUtility.IsStlContentElementWithTypePageContent(stlLabelList))//内容存在 { var stlElement = StlParserUtility.GetStlContentElementWithTypePageContent(stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); contentBuilder.Replace(stlElement, stlElementTranslated); var innerBuilder = new StringBuilder(stlElement); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); var pageContentHtml = innerBuilder.ToString(); var pageCount = StringUtils.GetCount(ContentUtility.PagePlaceHolder, pageContentHtml) + 1;//一共需要的页数 Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var index = pageContentHtml.IndexOf(ContentUtility.PagePlaceHolder, StringComparison.Ordinal); var length = index == -1 ? pageContentHtml.Length : index; if (currentPageIndex == visualInfo.PageIndex) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var pageHtml = pageContentHtml.Substring(0, length); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInContentPage(pagedBuilder, thePageInfo, stlLabelList, visualInfo.ChannelId, visualInfo.ContentId, currentPageIndex, pageCount); return(Response(pagedBuilder.ToString(), siteInfo)); } if (index != -1) { pageContentHtml = pageContentHtml.Substring(length + ContentUtility.PagePlaceHolder.Length); } } } if (StlParserUtility.IsStlElementExists(StlPageContents.ElementName, stlLabelList))//如果标签中存在<stl:pageContents> { var stlElement = StlParserUtility.GetStlElement(StlPageContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageContentsElementParser = new StlPageContents(stlElement, pageInfo, contextInfo); var pageCount = pageContentsElementParser.GetPageCount(out var totalNum); Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == visualInfo.PageIndex) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, false); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInContentPage(pagedBuilder, thePageInfo, stlLabelList, visualInfo.ChannelId, visualInfo.ContentId, currentPageIndex, pageCount); return(Response(pagedBuilder.ToString(), siteInfo)); } } } else if (StlParserUtility.IsStlElementExists(StlPageChannels.ElementName, stlLabelList))//如果标签中存在<stl:pageChannels> { var stlElement = StlParserUtility.GetStlElement(StlPageChannels.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageChannelsElementParser = new StlPageChannels(stlElement, pageInfo, contextInfo); var pageCount = pageChannelsElementParser.GetPageCount(out _); Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == visualInfo.PageIndex) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var pageHtml = pageChannelsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInContentPage(pagedBuilder, thePageInfo, stlLabelList, visualInfo.ChannelId, visualInfo.ContentId, currentPageIndex, pageCount); return(Response(pagedBuilder.ToString(), siteInfo)); } } } else if (StlParserUtility.IsStlElementExists(StlPageSqlContents.ElementName, stlLabelList))//如果标签中存在<stl:pageSqlContents> { var stlElement = StlParserUtility.GetStlElement(StlPageSqlContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageSqlContentsElementParser = new StlPageSqlContents(stlElement, pageInfo, contextInfo); var pageCount = pageSqlContentsElementParser.GetPageCount(out var totalNum); Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == visualInfo.PageIndex) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var pageHtml = pageSqlContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, false); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInContentPage(pagedBuilder, thePageInfo, stlLabelList, visualInfo.ChannelId, visualInfo.ContentId, currentPageIndex, pageCount); return(Response(pagedBuilder.ToString(), siteInfo)); } } } Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); StlParserManager.ReplacePageElementsInContentPage(contentBuilder, pageInfo, stlLabelList, contextInfo.ContentInfo.ChannelId, contextInfo.ContentInfo.Id, 0, 1); return(Response(contentBuilder.ToString(), siteInfo)); } return(null); }
private HttpResponseMessage GetChannelTemplate(VisualInfo visualInfo, SiteInfo siteInfo, StringBuilder contentBuilder, PageInfo pageInfo, ContextInfo contextInfo) { var nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, visualInfo.ChannelId); if (nodeInfo == null) { return(null); } if (nodeInfo.ParentId > 0) { if (!string.IsNullOrEmpty(nodeInfo.LinkUrl)) { PageUtils.Redirect(nodeInfo.LinkUrl); return(null); } } var stlLabelList = StlParserUtility.GetStlLabelList(contentBuilder.ToString()); //如果标签中存在Content var stlContentElement = string.Empty; foreach (var label in stlLabelList) { if (StlParserUtility.IsStlChannelElement(label, ChannelAttribute.PageContent)) { stlContentElement = label; break; } } if (!string.IsNullOrEmpty(stlContentElement)) //内容存在 { var innerBuilder = new StringBuilder(stlContentElement); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); var contentAttributeHtml = innerBuilder.ToString(); var pageCount = StringUtils.GetCount(ContentUtility.PagePlaceHolder, contentAttributeHtml) + 1; //一共需要的页数 if (pageCount > 1) { Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var index = contentAttributeHtml.IndexOf(ContentUtility.PagePlaceHolder, StringComparison.Ordinal); var length = index == -1 ? contentAttributeHtml.Length : index; if (currentPageIndex == visualInfo.PageIndex) { var pagedContentAttributeHtml = contentAttributeHtml.Substring(0, length); var pagedBuilder = new StringBuilder(contentBuilder.ToString() .Replace(stlContentElement, pagedContentAttributeHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, 0); return(Response(pagedBuilder.ToString(), siteInfo)); } if (index != -1) { contentAttributeHtml = contentAttributeHtml.Substring(length + ContentUtility.PagePlaceHolder.Length); } } return(null); } contentBuilder.Replace(stlContentElement, contentAttributeHtml); } if (StlParserUtility.IsStlElementExists(StlPageContents.ElementName, stlLabelList)) //如果标签中存在<stl:pageContents> { var stlElement = StlParserUtility.GetStlElement(StlPageContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageContentsElementParser = new StlPageContents(stlElement, pageInfo, contextInfo); var pageCount = pageContentsElementParser.GetPageCount(out var totalNum); Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == visualInfo.PageIndex) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, false); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); return(Response(pagedBuilder.ToString(), siteInfo)); } } } else if (StlParserUtility.IsStlElementExists(StlPageChannels.ElementName, stlLabelList)) //如果标签中存在<stl:pageChannels> { var stlElement = StlParserUtility.GetStlElement(StlPageChannels.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageChannelsElementParser = new StlPageChannels(stlElement, pageInfo, contextInfo); var pageCount = pageChannelsElementParser.GetPageCount(out var totalNum); Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == visualInfo.PageIndex) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var pageHtml = pageChannelsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); return(Response(pagedBuilder.ToString(), siteInfo)); } } } else if (StlParserUtility.IsStlElementExists(StlPageSqlContents.ElementName, stlLabelList) ) //如果标签中存在<stl:pageSqlContents> { var stlElement = StlParserUtility.GetStlElement(StlPageSqlContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageSqlContentsElementParser = new StlPageSqlContents(stlElement, pageInfo, contextInfo); var pageCount = pageSqlContentsElementParser.GetPageCount(out var totalNum); Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == visualInfo.PageIndex) { var thePageInfo = pageInfo.Clone(); thePageInfo.IsLocal = true; var pageHtml = pageSqlContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, false); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); return(Response(pagedBuilder.ToString(), siteInfo)); } } } Parser.Parse(pageInfo, contextInfo, contentBuilder, visualInfo.FilePath, true); return(Response(contentBuilder.ToString(), siteInfo)); }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (this.StopProcessing) { // Do nothing } else { this.partPlaceholder.CheckPermissions = this.CheckPermissions; this.partPlaceholder.CacheMinutes = this.CacheMinutes; // Load content only when default page template or path is defined string templateName = this.PageTemplate; string path = this.Path; if ((templateName != "") || (path != "")) { ViewModeEnum viewMode = ViewModeEnum.Unknown; // Process template only if the control is on the last hierarchy page PageInfo currentPage = this.PagePlaceholder.PageInfo; PageInfo usePage = null; PageTemplateInfo ti = null; if (String.IsNullOrEmpty(path)) { // Use the same page usePage = this.PagePlaceholder.PageInfo; if (this.UseDefaultTemplateOnSubPages || (currentPage.ChildPageInfo == null) || (currentPage.ChildPageInfo.PageTemplateInfo == null) || (currentPage.ChildPageInfo.PageTemplateInfo.PageTemplateId == 0)) { ti = PageTemplateInfoProvider.GetPageTemplateInfo(templateName); } } else { // Resolve the path first path = CMSContext.ResolveCurrentPath(path); // Get specific page usePage = PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, path, CMSContext.PreferredCultureCode, null, false); if (this.PortalManager.ViewMode != ViewModeEnum.LiveSite) { viewMode = ViewModeEnum.Preview; // Get current document content if (usePage != null) { TreeNode node = DocumentHelper.GetDocument(usePage.DocumentId, null); if (node != null) { usePage.LoadVersion(node); } } } // Get the appropriate page template if (String.IsNullOrEmpty(templateName)) { ti = usePage.PageTemplateInfo; } else { ti = PageTemplateInfoProvider.GetPageTemplateInfo(templateName); } } if ((usePage != null) && (ti != null)) { // If same template as current page, avoid cycling if (ti.PageTemplateId == currentPage.PageTemplateInfo.PageTemplateId) { this.lblError.Text = GetString("WebPart.PagePlaceHolder.CurrentTemplateNotAllowed"); this.lblError.Visible = true; } else { usePage = usePage.Clone(); usePage.DocumentPageTemplateID = ti.PageTemplateId; usePage.PageTemplateInfo = ti; // Load the current page info with the template and document if (viewMode != ViewModeEnum.Unknown) { this.partPlaceholder.ViewMode = viewMode; } this.partPlaceholder.UsingDefaultPageTemplate = true; this.partPlaceholder.PageLevel = this.PagePlaceholder.PageLevel; this.partPlaceholder.LoadContent(usePage, true); } } } } }
private static async Task CreateChannelAsync(int siteId, int channelId) { var siteInfo = SiteManager.GetSiteInfo(siteId); var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId); if (channelInfo == null) { return; } if (!string.IsNullOrEmpty(channelInfo.LinkUrl)) { return; } if (!ELinkTypeUtils.IsCreatable(siteInfo, channelInfo)) { return; } var templateInfo = channelId == siteId ? TemplateManager.GetIndexPageTemplateInfo(siteId) : TemplateManager.GetChannelTemplateInfo(siteId, channelId); var filePath = PathUtility.GetChannelPageFilePath(siteInfo, channelId, 0); var pageInfo = new PageInfo(channelId, 0, siteInfo, templateInfo, new Dictionary <string, object>()); var contextInfo = new ContextInfo(pageInfo) { ContextType = EContextType.Channel }; var contentBuilder = new StringBuilder(TemplateManager.GetTemplateContent(siteInfo, templateInfo)); var stlLabelList = StlParserUtility.GetStlLabelList(contentBuilder.ToString()); var stlPageContentElement = string.Empty; foreach (var label in stlLabelList) { if (!StlParserUtility.IsStlChannelElement(label, ChannelAttribute.PageContent)) { continue; } stlPageContentElement = label; break; } //如果标签中存在<stl:channel type="PageContent"></stl:channel> if (!string.IsNullOrEmpty(stlPageContentElement)) //内容存在 { var innerBuilder = new StringBuilder(stlPageContentElement); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); var contentAttributeHtml = innerBuilder.ToString(); var pageCount = StringUtils.GetCount(ContentUtility.PagePlaceHolder, contentAttributeHtml) + 1; //一共需要的页数 pageInfo.AddPageBodyCodeIfNotExists(PageInfo.Const.Jquery); Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); var index = contentAttributeHtml.IndexOf(ContentUtility.PagePlaceHolder, StringComparison.Ordinal); var length = index == -1 ? contentAttributeHtml.Length : index; var pagedContentAttributeHtml = contentAttributeHtml.Substring(0, length); var pagedBuilder = new StringBuilder(contentBuilder.ToString() .Replace(stlPageContentElement, pagedContentAttributeHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, 0); filePath = PathUtility.GetChannelPageFilePath(siteInfo, thePageInfo.PageChannelId, currentPageIndex); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); if (index != -1) { contentAttributeHtml = contentAttributeHtml.Substring(length + ContentUtility.PagePlaceHolder.Length); } } } //如果标签中存在<stl:pageContents> else if (StlParserUtility.IsStlElementExists(StlPageContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageContentsElementParser = new StlPageContents(stlElement, pageInfo, contextInfo); int totalNum; var pageCount = pageContentsElementParser.GetPageCount(out totalNum); pageInfo.AddPageBodyCodeIfNotExists(PageInfo.Const.Jquery); Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, true); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(siteInfo, thePageInfo.PageChannelId, currentPageIndex); thePageInfo.AddLastPageScript(pageInfo); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); thePageInfo.ClearLastPageScript(pageInfo); pageInfo.ClearLastPageScript(); } } //如果标签中存在<stl:pageChannels> else if (StlParserUtility.IsStlElementExists(StlPageChannels.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageChannels.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageChannelsElementParser = new StlPageChannels(stlElement, pageInfo, contextInfo); int totalNum; var pageCount = pageChannelsElementParser.GetPageCount(out totalNum); pageInfo.AddPageBodyCodeIfNotExists(PageInfo.Const.Jquery); Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); var pageHtml = pageChannelsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(siteInfo, thePageInfo.PageChannelId, currentPageIndex); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } //如果标签中存在<stl:pageSqlContents> else if (StlParserUtility.IsStlElementExists(StlPageSqlContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageSqlContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageSqlContentsElementParser = new StlPageSqlContents(stlElement, pageInfo, contextInfo); int totalNum; var pageCount = pageSqlContentsElementParser.GetPageCount(out totalNum); pageInfo.AddPageBodyCodeIfNotExists(PageInfo.Const.Jquery); Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); var pageHtml = pageSqlContentsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(siteInfo, thePageInfo.PageChannelId, currentPageIndex); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } else { Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, contentBuilder); } }
private static async Task CreateContentAsync(SiteInfo siteInfo, ChannelInfo channelInfo, int contentId) { var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId); if (contentInfo == null) { return; } if (!contentInfo.IsChecked) { DeleteManager.DeleteContent(siteInfo, channelInfo.Id, contentId); return; } //引用链接,不需要生成内容页;引用内容,需要生成内容页; if (contentInfo.ReferenceId > 0 && ETranslateContentTypeUtils.GetEnumType(contentInfo.GetString(ContentAttribute.TranslateContentType)) != ETranslateContentType.ReferenceContent) { return; } if (!string.IsNullOrEmpty(contentInfo.GetString(ContentAttribute.LinkUrl))) { return; } if (siteInfo.Additional.IsCreateStaticContentByAddDate && contentInfo.AddDate < siteInfo.Additional.CreateStaticContentAddDate) { return; } var templateInfo = TemplateManager.GetContentTemplateInfo(siteInfo.Id, channelInfo.Id); var pageInfo = new PageInfo(channelInfo.Id, contentId, siteInfo, templateInfo, new Dictionary <string, object>()); var contextInfo = new ContextInfo(pageInfo) { ContextType = EContextType.Content, ContentInfo = contentInfo }; var filePath = PathUtility.GetContentPageFilePath(siteInfo, pageInfo.PageChannelId, contentInfo, 0); var contentBuilder = new StringBuilder(TemplateManager.GetTemplateContent(siteInfo, templateInfo)); var stlLabelList = StlParserUtility.GetStlLabelList(contentBuilder.ToString()); //如果标签中存在<stl:content type="PageContent"></stl:content> if (StlParserUtility.IsStlContentElementWithTypePageContent(stlLabelList)) //内容存在 { var stlElement = StlParserUtility.GetStlContentElementWithTypePageContent(stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); contentBuilder.Replace(stlElement, stlElementTranslated); var innerBuilder = new StringBuilder(stlElement); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); var pageContentHtml = innerBuilder.ToString(); var pageCount = StringUtils.GetCount(ContentUtility.PagePlaceHolder, pageContentHtml) + 1; //一共需要的页数 Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); var index = pageContentHtml.IndexOf(ContentUtility.PagePlaceHolder, StringComparison.Ordinal); var length = index == -1 ? pageContentHtml.Length : index; var pageHtml = pageContentHtml.Substring(0, length); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInContentPage(pagedBuilder, thePageInfo, stlLabelList, channelInfo.Id, contentId, currentPageIndex, pageCount); filePath = PathUtility.GetContentPageFilePath(siteInfo, thePageInfo.PageChannelId, contentInfo, currentPageIndex); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); if (index != -1) { pageContentHtml = pageContentHtml.Substring(length + ContentUtility.PagePlaceHolder.Length); } } } //如果标签中存在<stl:pageContents> else if (StlParserUtility.IsStlElementExists(StlPageContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageContentsElementParser = new StlPageContents(stlElement, pageInfo, contextInfo); int totalNum; var pageCount = pageContentsElementParser.GetPageCount(out totalNum); Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, true); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInContentPage(pagedBuilder, thePageInfo, stlLabelList, channelInfo.Id, contentId, currentPageIndex, pageCount); filePath = PathUtility.GetContentPageFilePath(siteInfo, thePageInfo.PageChannelId, contentInfo, currentPageIndex); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } //如果标签中存在<stl:pageChannels> else if (StlParserUtility.IsStlElementExists(StlPageChannels.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageChannels.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageChannelsElementParser = new StlPageChannels(stlElement, pageInfo, contextInfo); var pageCount = pageChannelsElementParser.GetPageCount(out _); Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); var pageHtml = pageChannelsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInContentPage(pagedBuilder, thePageInfo, stlLabelList, channelInfo.Id, contentId, currentPageIndex, pageCount); filePath = PathUtility.GetContentPageFilePath(siteInfo, thePageInfo.PageChannelId, contentInfo, currentPageIndex); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } //如果标签中存在<stl:pageSqlContents> else if (StlParserUtility.IsStlElementExists(StlPageSqlContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageSqlContents.ElementName, stlLabelList); var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); var pageSqlContentsElementParser = new StlPageSqlContents(stlElement, pageInfo, contextInfo); var pageCount = pageSqlContentsElementParser.GetPageCount(out _); Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); var pageHtml = pageSqlContentsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInContentPage(pagedBuilder, thePageInfo, stlLabelList, channelInfo.Id, contentId, currentPageIndex, pageCount); filePath = PathUtility.GetContentPageFilePath(siteInfo, thePageInfo.PageChannelId, contentInfo, currentPageIndex); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } else //无翻页 { Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, contentBuilder); } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { partPlaceholder.CheckPermissions = CheckPermissions; partPlaceholder.CacheMinutes = CacheMinutes; // Load content only when default page template or path is defined string templateName = PageTemplate; string path = Path; if ((templateName != "") || (path != "")) { ViewModeEnum viewMode = ViewModeEnum.Unknown; // Process template only if the control is on the last hierarchy page PageInfo currentPage = PagePlaceholder.PageInfo; PageInfo usePage = null; PageTemplateInfo ti = null; if (String.IsNullOrEmpty(path)) { // Use the same page usePage = PagePlaceholder.PageInfo; if (UseDefaultTemplateOnSubPages || (currentPage.ChildPageInfo == null) || (currentPage.ChildPageInfo.UsedPageTemplateInfo == null) || (currentPage.ChildPageInfo.UsedPageTemplateInfo.PageTemplateId == 0)) { ti = PageTemplateInfoProvider.GetPageTemplateInfo(templateName); } } else { // Resolve the path first path = MacroResolver.ResolveCurrentPath(path); // Get specific page usePage = PageInfoProvider.GetPageInfo(SiteContext.CurrentSiteName, path, LocalizationContext.PreferredCultureCode, null, false); if (PortalManager.ViewMode != ViewModeEnum.LiveSite) { viewMode = ViewModeEnum.Preview; // Set design mode for document's placeholder if is currently displayed TreeNode tn = DocumentContext.CurrentDocument; if ((tn != null) && (PortalContext.ViewMode == ViewModeEnum.Design) && tn.NodeAliasPath.EqualsCSafe(path, true)) { viewMode = ViewModeEnum.Design; } // Get current document content if (usePage != null) { usePage.LoadVersion(); } } // Get the appropriate page template if (String.IsNullOrEmpty(templateName)) { ti = (usePage != null) ? usePage.UsedPageTemplateInfo : null; } else { ti = PageTemplateInfoProvider.GetPageTemplateInfo(templateName); } } if ((usePage != null) && (ti != null)) { // If same template as current page, avoid cycling if (ti.PageTemplateId == currentPage.UsedPageTemplateInfo.PageTemplateId) { lblError.Text = GetString("WebPart.PagePlaceHolder.CurrentTemplateNotAllowed"); lblError.Visible = true; } else { usePage = usePage.Clone(); // Setup the page template int templateId = ti.PageTemplateId; usePage.SetPageTemplateId(templateId); usePage.UsedPageTemplateInfo = ti; // Load the current page info with the template and document if (viewMode != ViewModeEnum.Unknown) { partPlaceholder.ViewMode = viewMode; } partPlaceholder.UsingDefaultPageTemplate = !string.IsNullOrEmpty(templateName); partPlaceholder.UsingDefaultDocument = !string.IsNullOrEmpty(path); partPlaceholder.PageLevel = PagePlaceholder.PageLevel; partPlaceholder.LoadContent(usePage, true); } } } } }