public static string ParseDynamicContent(int publishmentSystemId, int channelId, int contentId, int templateId, bool isPageRefresh, string templateContent, string pageUrl, int pageIndex, string ajaxDivId, NameValueCollection queryString, UserInfo userInfo) { var templateInfo = TemplateManager.GetTemplateInfo(publishmentSystemId, templateId); //TemplateManager.GetTemplateInfo(publishmentSystemID, channelID, templateType); var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemId); var pageInfo = new PageInfo(channelId, contentId, publishmentSystemInfo, templateInfo, userInfo); pageInfo.SetUniqueId(1000); var contextInfo = new ContextInfo(pageInfo); templateContent = StlRequestEntities.ParseRequestEntities(queryString, templateContent); var contentBuilder = new StringBuilder(templateContent); var stlElementList = StlParserUtility.GetStlElementList(contentBuilder.ToString()); //如果标签中存在<stl:pageContents> if (StlParserUtility.IsStlElementExists(StlPageContents.ElementName, stlElementList)) { var stlElement = StlParserUtility.GetStlElement(StlPageContents.ElementName, stlElementList); var stlPageContentsElement = stlElement; var stlPageContentsElementReplaceString = stlElement; var pageContentsElementParser = new StlPageContents(stlPageContentsElement, pageInfo, contextInfo, true); int totalNum; var pageCount = pageContentsElementParser.GetPageCount(out totalNum); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == pageIndex) { var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, false); contentBuilder.Replace(stlPageContentsElementReplaceString, pageHtml); StlParserManager.ReplacePageElementsInDynamicPage(contentBuilder, pageInfo, stlElementList, pageUrl, pageInfo.PageNodeId, currentPageIndex, pageCount, totalNum, isPageRefresh, ajaxDivId); break; } } } //如果标签中存在<stl:pageChannels> else if (StlParserUtility.IsStlElementExists(StlPageChannels.ElementName, stlElementList)) { var stlElement = StlParserUtility.GetStlElement(StlPageChannels.ElementName, stlElementList); var stlPageChannelsElement = stlElement; var stlPageChannelsElementReplaceString = stlElement; var pageChannelsElementParser = new StlPageChannels(stlPageChannelsElement, pageInfo, contextInfo, true); int totalNum; var pageCount = pageChannelsElementParser.GetPageCount(out totalNum); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == pageIndex) { var pageHtml = pageChannelsElementParser.Parse(currentPageIndex, pageCount); contentBuilder.Replace(stlPageChannelsElementReplaceString, pageHtml); StlParserManager.ReplacePageElementsInDynamicPage(contentBuilder, pageInfo, stlElementList, pageUrl, pageInfo.PageNodeId, currentPageIndex, pageCount, totalNum, isPageRefresh, ajaxDivId); break; } } } //如果标签中存在<stl:pageComments> else if (StlParserUtility.IsStlElementExists(StlPageComments.ElementName, stlElementList)) { var stlElement = StlParserUtility.GetStlElement(StlPageComments.ElementName, stlElementList); var stlPageCommentsElement = stlElement; var stlPageCommentsElementReplaceString = stlElement; var pageCommentsElementParser = new StlPageComments(stlPageCommentsElement, pageInfo, contextInfo, true); int totalNum; var pageCount = pageCommentsElementParser.GetPageCount(out totalNum); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == pageIndex) { var pageHtml = pageCommentsElementParser.Parse(currentPageIndex, pageCount); contentBuilder.Replace(stlPageCommentsElementReplaceString, pageHtml); StlParserManager.ReplacePageElementsInDynamicPage(contentBuilder, pageInfo, stlElementList, pageUrl, pageInfo.PageNodeId, currentPageIndex, pageCount, totalNum, isPageRefresh, ajaxDivId); break; } } } //如果标签中存在<stl:pageinputContents> else if (StlParserUtility.IsStlElementExists(StlPageInputContents.ElementName, stlElementList)) { var stlElement = StlParserUtility.GetStlElement(StlPageInputContents.ElementName, stlElementList); var stlPageInputContentsElement = stlElement; var stlPageInputContentsElementReplaceString = stlElement; var pageInputContentsElementParser = new StlPageInputContents(stlPageInputContentsElement, pageInfo, contextInfo, true); int totalNum; var pageCount = pageInputContentsElementParser.GetPageCount(out totalNum); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == pageIndex) { var pageHtml = pageInputContentsElementParser.Parse(currentPageIndex, pageCount); contentBuilder.Replace(stlPageInputContentsElementReplaceString, pageHtml); StlParserManager.ReplacePageElementsInDynamicPage(contentBuilder, pageInfo, stlElementList, pageUrl, pageInfo.PageNodeId, currentPageIndex, pageCount, totalNum, isPageRefresh, ajaxDivId); break; } } } //如果标签中存在<stl:pageSqlContents> else if (StlParserUtility.IsStlElementExists(StlPageSqlContents.ElementName, stlElementList)) { var stlElement = StlParserUtility.GetStlElement(StlPageSqlContents.ElementName, stlElementList); var stlPageSqlContentsElement = stlElement; var stlPageSqlContentsElementReplaceString = stlElement; var pageSqlContentsElementParser = new StlPageSqlContents(stlPageSqlContentsElement, pageInfo, contextInfo, true); int totalNum; var pageCount = pageSqlContentsElementParser.GetPageCount(out totalNum); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == pageIndex) { var pageHtml = pageSqlContentsElementParser.Parse(currentPageIndex, pageCount); contentBuilder.Replace(stlPageSqlContentsElementReplaceString, pageHtml); StlParserManager.ReplacePageElementsInDynamicPage(contentBuilder, pageInfo, stlElementList, pageUrl, pageInfo.PageNodeId, currentPageIndex, pageCount, totalNum, isPageRefresh, ajaxDivId); break; } } } else if (StlParserUtility.IsStlElementExists(StlPageItems.ElementName, stlElementList)) { var pageCount = TranslateUtils.ToInt(queryString["pageCount"]); var totalNum = TranslateUtils.ToInt(queryString["totalNum"]); var pageContentsAjaxDivId = queryString["pageContentsAjaxDivID"]; for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { if (currentPageIndex == pageIndex) { StlParserManager.ReplacePageElementsInDynamicPage(contentBuilder, pageInfo, stlElementList, pageUrl, pageInfo.PageNodeId, currentPageIndex, pageCount, totalNum, isPageRefresh, pageContentsAjaxDivId); break; } } } StlParserManager.ParseInnerContent(contentBuilder, pageInfo, contextInfo); //string afterBodyScript = StlParserManager.GetPageInfoScript(pageInfo, true); //string beforBodyScript = StlParserManager.GetPageInfoScript(pageInfo, false); //return afterBodyScript + StlParserUtility.GetBackHtml(contentBuilder.ToString(), pageInfo) + beforBodyScript; return(StlParserUtility.GetBackHtml(contentBuilder.ToString(), pageInfo)); //return contentBuilder.ToString(); }
//public void CreateIndex() //{ // var templateInfo = TemplateManager.GetTemplateInfo(PublishmentSystemId, 0, ETemplateType.IndexPageTemplate); // if (templateInfo == null) return; // var pageInfo = new PageInfo(PublishmentSystemId, 0, PublishmentSystemInfo, templateInfo, null); // var contextInfo = new ContextInfo(pageInfo); // var filePath = PathUtility.GetIndexPageFilePath(PublishmentSystemInfo, templateInfo.CreatedFileFullName, IsHeadquarters); // var contentBuilder = new StringBuilder(StlCacheManager.FileContent.GetTemplateContent(PublishmentSystemInfo, templateInfo)); // StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); // GenerateFile(filePath, pageInfo.TemplateInfo.Charset, contentBuilder); //} public void CreateChannel(int nodeId) { var nodeInfo = NodeManager.GetNodeInfo(PublishmentSystemId, nodeId); if (nodeInfo == null) { return; } //if (nodeId == PublishmentSystemId) //{ // CreateIndex(); // return; //} if (!string.IsNullOrEmpty(nodeInfo.LinkUrl)) { return; } if (!ELinkTypeUtils.IsCreatable(nodeInfo)) { return; } var templateInfo = nodeId == PublishmentSystemId?TemplateManager.GetTemplateInfo(PublishmentSystemId, 0, ETemplateType.IndexPageTemplate) : TemplateManager.GetTemplateInfo(PublishmentSystemId, nodeId, ETemplateType.ChannelTemplate); var filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, nodeId, 0); var pageInfo = new PageInfo(nodeId, 0, PublishmentSystemInfo, templateInfo, null); var contextInfo = new ContextInfo(pageInfo); var contentBuilder = new StringBuilder(StlCacheManager.FileContent.GetTemplateContent(PublishmentSystemInfo, templateInfo)); var stlLabelList = StlParserUtility.GetStlLabelList(contentBuilder.ToString()); var stlPageContentElement = string.Empty; foreach (var label in stlLabelList) { if (!StlParserUtility.IsStlChannelElement(label, NodeAttribute.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;//一共需要的页数 StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); 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.PageNodeId, currentPageIndex, pageCount, 0); filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); GenerateFile(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 = StlPageContents.Translate(stlElement); var pageContentsElementParser = new StlPageContents(stlElement, pageInfo, contextInfo, false); int totalNum; var pageCount = pageContentsElementParser.GetPageCount(out totalNum); StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, true); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); thePageInfo.AddLastPageScript(pageInfo); GenerateFile(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 = StlPageChannels.Translate(stlElement); var pageChannelsElementParser = new StlPageChannels(stlElement, pageInfo, contextInfo, false); int totalNum; var pageCount = pageChannelsElementParser.GetPageCount(out totalNum); StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); var pageHtml = pageChannelsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } //如果标签中存在<stl:pageSqlContents> else if (StlParserUtility.IsStlElementExists(StlPageSqlContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageSqlContents.ElementName, stlLabelList); var stlElementTranslated = StlPageSqlContents.Translate(stlElement); var pageSqlContentsElementParser = new StlPageSqlContents(stlElement, pageInfo, contextInfo, false); int totalNum; var pageCount = pageSqlContentsElementParser.GetPageCount(out totalNum); StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); var pageHtml = pageSqlContentsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } //如果标签中存在<stl:StlPageInputContents> else if (StlParserUtility.IsStlElementExists(StlPageInputContents.ElementName, stlLabelList)) { var stlElement = StlParserUtility.GetStlElement(StlPageInputContents.ElementName, stlLabelList); var stlElementTranslated = StlPageInputContents.Translate(stlElement); var pageInputContentsElementParser = new StlPageInputContents(stlElement, pageInfo, contextInfo, true); int totalNum; var pageCount = pageInputContentsElementParser.GetPageCount(out totalNum); StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); var pageHtml = pageInputContentsElementParser.Parse(currentPageIndex, pageCount); var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); } } else { StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); GenerateFile(filePath, pageInfo.TemplateInfo.Charset, contentBuilder); } }