public void Page_Load(object sender, EventArgs e) { if (IsForbidden) { return; } _tableStyleId = AuthRequest.GetQueryInt("TableStyleID"); _relatedIdentities = TranslateUtils.StringCollectionToIntList(AuthRequest.GetQueryString("RelatedIdentities")); if (_relatedIdentities.Count == 0) { _relatedIdentities.Add(0); } _tableName = AuthRequest.GetQueryString("TableName"); _attributeName = AuthRequest.GetQueryString("AttributeName"); _redirectUrl = StringUtils.ValueFromUrl(AuthRequest.GetQueryString("RedirectUrl")); _styleInfo = _tableStyleId != 0 ? TableStyleManager.GetTableStyleInfo(_tableStyleId) : TableStyleManager.GetTableStyleInfo(_tableName, _attributeName, _relatedIdentities); if (IsPostBack) { return; } DdlIsValidate.Items[0].Value = true.ToString(); DdlIsValidate.Items[1].Value = false.ToString(); ControlUtils.SelectSingleItem(DdlIsValidate, _styleInfo.Additional.IsValidate.ToString()); DdlIsRequired.Items[0].Value = true.ToString(); DdlIsRequired.Items[1].Value = false.ToString(); ControlUtils.SelectSingleItem(DdlIsRequired, _styleInfo.Additional.IsRequired.ToString()); PhNum.Visible = InputTypeUtils.EqualsAny(_styleInfo.InputType, InputType.Text, InputType.TextArea); TbMinNum.Text = _styleInfo.Additional.MinNum.ToString(); TbMaxNum.Text = _styleInfo.Additional.MaxNum.ToString(); ValidateTypeUtils.AddListItems(DdlValidateType); ControlUtils.SelectSingleItem(DdlValidateType, _styleInfo.Additional.ValidateType.Value); TbRegExp.Text = _styleInfo.Additional.RegExp; TbErrorMessage.Text = _styleInfo.Additional.ErrorMessage; DdlValidate_SelectedIndexChanged(null, EventArgs.Empty); }
private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, string type, string formatString, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper) { if (string.IsNullOrEmpty(type)) { return(string.Empty); } var parsedContent = string.Empty; if (contextInfo.ContextType == EContextType.Each) { parsedContent = contextInfo.ItemContainer.EachItem.DataItem as string; return(parsedContent); } if (type.ToLower().Equals(TypeSiteName.ToLower())) { parsedContent = pageInfo.SiteInfo.SiteName; } else if (type.ToLower().Equals(TypeSiteUrl.ToLower())) { parsedContent = pageInfo.SiteInfo.Additional.WebUrl; } else if (type.ToLower().Equals(TypeDate.ToLower())) { if (!pageInfo.BodyCodes.ContainsKey("datestring.js")) { pageInfo.BodyCodes.Add("datestring.js", $@"<script charset=""{SiteFilesAssets.DateString.Charset}"" src=""{SiteFilesAssets.GetUrl( pageInfo.ApiUrl, SiteFilesAssets.DateString.Js)}"" type=""text/javascript""></script>"); } parsedContent = @"<script language=""javascript"" type=""text/javascript"">RunGLNL(false);</script>"; } else if (type.ToLower().Equals(TypeDateOfTraditional.ToLower())) { if (!pageInfo.BodyCodes.ContainsKey("datestring")) { pageInfo.BodyCodes.Add("datestring", $@"<script charset=""{SiteFilesAssets.DateString.Charset}"" src=""{SiteFilesAssets.GetUrl( pageInfo.ApiUrl, SiteFilesAssets.DateString.Js)}"" type=""text/javascript""></script>"); } parsedContent = @"<script language=""javascript"" type=""text/javascript"">RunGLNL(true);</script>"; } else if (pageInfo.Parameters != null && pageInfo.Parameters.ContainsKey(type)) { pageInfo.Parameters.TryGetValue(type, out parsedContent); parsedContent = StringUtils.ParseString(InputType.Text, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } else { if (pageInfo.SiteInfo.Additional.GetString(type) != null) { parsedContent = pageInfo.SiteInfo.Additional.GetString(type); if (!string.IsNullOrEmpty(parsedContent)) { var styleInfo = TableStyleManager.GetTableStyleInfo(DataProvider.SiteDao.TableName, type, RelatedIdentities.GetRelatedIdentities(pageInfo.SiteId, pageInfo.SiteId)); // 如果 styleInfo.TableStyleId <= 0,表示此字段已经被删除了,不需要再显示值了 ekun008 if (styleInfo.Id > 0) { if (isClearTags && InputTypeUtils.EqualsAny(styleInfo.InputType, InputType.Image, InputType.File)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } else { parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, separator, pageInfo.SiteInfo, styleInfo, formatString, contextInfo.Attributes, contextInfo.InnerXml, false); parsedContent = StringUtils.ParseString(styleInfo.InputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } } else { // 如果字段已经被删除或不再显示了,则此字段的值为空。有时虚拟字段值不会清空 parsedContent = string.Empty; } } } } return(parsedContent); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var attributeName = entityName.Substring(5, entityName.Length - 6); if (StringUtils.EqualsIgnoreCase(PoweredBy, attributeName))//支持信息 { parsedContent = @"Powered by <a href=""http://www.siteserver.cn"" target=""_blank"">SiteServer CMS</a>"; } else if (StringUtils.EqualsIgnoreCase(RootUrl, attributeName))//系统根目录地址 { parsedContent = PageUtils.ParseConfigRootUrl("~"); if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = parsedContent.TrimEnd('/'); } } else if (StringUtils.EqualsIgnoreCase(ApiUrl, attributeName))//API地址 { parsedContent = pageInfo.ApiUrl.TrimEnd('/'); } else if (StringUtils.EqualsIgnoreCase(SiteId, attributeName))//ID { parsedContent = pageInfo.SiteId.ToString(); } else if (StringUtils.EqualsIgnoreCase(SiteName, attributeName))//名称 { parsedContent = pageInfo.SiteInfo.SiteName; } else if (StringUtils.EqualsIgnoreCase(SiteUrl, attributeName))//域名地址 { parsedContent = PageUtility.GetSiteUrl(pageInfo.SiteInfo, pageInfo.IsLocal).TrimEnd('/'); } else if (StringUtils.EqualsIgnoreCase(SiteDir, attributeName))//文件夹 { parsedContent = pageInfo.SiteInfo.SiteDir; } else if (StringUtils.EqualsIgnoreCase(CurrentUrl, attributeName))//当前页地址 { parsedContent = StlParserUtility.GetStlCurrentUrl(pageInfo.SiteInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo, pageInfo.TemplateInfo.TemplateType, pageInfo.TemplateInfo.Id, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(ChannelUrl, attributeName))//栏目页地址 { parsedContent = PageUtility.GetChannelUrl(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId), pageInfo.IsLocal); } //else if (StringUtils.EqualsIgnoreCase(HomeUrl, attributeName))//用户中心地址 //{ // parsedContent = pageInfo.HomeUrl.TrimEnd('/'); //} //else if (StringUtils.EqualsIgnoreCase(attributeName, LoginUrl)) //{ // var returnUrl = StlUtility.GetStlCurrentUrl(pageInfo.SiteInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo, pageInfo.TemplateInfo.TemplateType, pageInfo.TemplateInfo.TemplateId); // parsedContent = HomeUtils.GetLoginUrl(pageInfo.HomeUrl, returnUrl); //} //else if (StringUtils.EqualsIgnoreCase(attributeName, LogoutUrl)) //{ // var returnUrl = StlUtility.GetStlCurrentUrl(pageInfo.SiteInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo, pageInfo.TemplateInfo.TemplateType, pageInfo.TemplateInfo.TemplateId); // parsedContent = HomeUtils.GetLogoutUrl(pageInfo.HomeUrl, returnUrl); //} //else if (StringUtils.EqualsIgnoreCase(attributeName, RegisterUrl)) //{ // var returnUrl = StlUtility.GetStlCurrentUrl(pageInfo.SiteInfo, contextInfo.ChannelId, contextInfo.ContentId, contextInfo.ContentInfo, pageInfo.TemplateInfo.TemplateType, pageInfo.TemplateInfo.TemplateId); // parsedContent = HomeUtils.GetRegisterUrl(pageInfo.HomeUrl, returnUrl); //} else if (StringUtils.StartsWithIgnoreCase(attributeName, "TableFor"))// { if (StringUtils.EqualsIgnoreCase(attributeName, "TableForContent")) { parsedContent = pageInfo.SiteInfo.TableName; } } else if (StringUtils.StartsWithIgnoreCase(attributeName, "Site"))// { parsedContent = pageInfo.SiteInfo.Additional.GetString(attributeName.Substring(4)); } else { if (pageInfo.SiteInfo.Additional.ContainsKey(attributeName)) { parsedContent = pageInfo.SiteInfo.Additional.GetString(attributeName); if (!string.IsNullOrEmpty(parsedContent)) { var styleInfo = TableStyleManager.GetTableStyleInfo(DataProvider.SiteDao.TableName, attributeName, RelatedIdentities.GetRelatedIdentities(pageInfo.SiteId, pageInfo.SiteId)); // 如果 styleInfo.TableStyleId <= 0,表示此字段已经被删除了,不需要再显示值了 ekun008 if (styleInfo.Id > 0) { parsedContent = InputTypeUtils.EqualsAny(styleInfo.InputType, InputType.Image, InputType.File) ? PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal) : InputParserUtility.GetContentByTableStyle(parsedContent, string.Empty, pageInfo.SiteInfo, styleInfo, string.Empty, null, string.Empty, true); } else { // 如果字段已经被删除或不再显示了,则此字段的值为空。有时虚拟字段值不会清空 parsedContent = string.Empty; } } } } } catch { // ignored } return(parsedContent); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var channelIndex = StlParserUtility.GetValueFromEntity(stlEntity); var attributeName = entityName.Substring(9, entityName.Length - 10); var upLevel = 0; var topLevel = -1; var channelId = contextInfo.ChannelId; if (!string.IsNullOrEmpty(channelIndex)) { //channelId = DataProvider.ChannelDao.GetIdByIndexName(pageInfo.SiteId, channelIndex); channelId = Node.GetIdByIndexName(pageInfo.SiteId, channelIndex); if (channelId == 0) { channelId = contextInfo.ChannelId; } } if (attributeName.ToLower().StartsWith("up") && attributeName.IndexOf(".", StringComparison.Ordinal) != -1) { if (attributeName.ToLower().StartsWith("up.")) { upLevel = 1; } else { var upLevelStr = attributeName.Substring(2, attributeName.IndexOf(".", StringComparison.Ordinal) - 2); upLevel = TranslateUtils.ToInt(upLevelStr); } topLevel = -1; attributeName = attributeName.Substring(attributeName.IndexOf(".", StringComparison.Ordinal) + 1); } else if (attributeName.ToLower().StartsWith("top") && attributeName.IndexOf(".", StringComparison.Ordinal) != -1) { if (attributeName.ToLower().StartsWith("top.")) { topLevel = 1; } else { var topLevelStr = attributeName.Substring(3, attributeName.IndexOf(".", StringComparison.Ordinal) - 3); topLevel = TranslateUtils.ToInt(topLevelStr); } upLevel = 0; attributeName = attributeName.Substring(attributeName.IndexOf(".", StringComparison.Ordinal) + 1); } var nodeInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, StlDataUtility.GetChannelIdByLevel(pageInfo.SiteId, channelId, upLevel, topLevel)); if (StringUtils.EqualsIgnoreCase(ChannelId, attributeName))//栏目ID { parsedContent = nodeInfo.Id.ToString(); } else if (StringUtils.EqualsIgnoreCase(Title, attributeName) || StringUtils.EqualsIgnoreCase(ChannelName, attributeName))//栏目名称 { parsedContent = nodeInfo.ChannelName; } else if (StringUtils.EqualsIgnoreCase(ChannelIndex, attributeName))//栏目索引 { parsedContent = nodeInfo.IndexName; } else if (StringUtils.EqualsIgnoreCase(Content, attributeName))//栏目正文 { parsedContent = ContentUtility.TextEditorContentDecode(pageInfo.SiteInfo, nodeInfo.Content, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(NavigationUrl, attributeName))//栏目链接地址 { parsedContent = PageUtility.GetChannelUrl(pageInfo.SiteInfo, nodeInfo, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(ImageUrl, attributeName))//栏目图片地址 { parsedContent = nodeInfo.ImageUrl; if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(AddDate, attributeName))//栏目添加日期 { parsedContent = DateUtils.Format(nodeInfo.AddDate, string.Empty); } else if (StringUtils.EqualsIgnoreCase(DirectoryName, attributeName))//生成文件夹名称 { parsedContent = PathUtils.GetDirectoryName(nodeInfo.FilePath, true); } else if (StringUtils.EqualsIgnoreCase(Group, attributeName))//栏目组别 { parsedContent = nodeInfo.GroupNameCollection; } else if (StringUtils.StartsWithIgnoreCase(attributeName, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ChannelItem != null) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ChannelItem.ItemIndex, attributeName, contextInfo).ToString(); } else if (StringUtils.EqualsIgnoreCase(ChannelAttribute.Keywords, attributeName))//栏目组别 { parsedContent = nodeInfo.Keywords; } else if (StringUtils.EqualsIgnoreCase(ChannelAttribute.Description, attributeName))//栏目组别 { parsedContent = nodeInfo.Description; } else { //var styleInfo = TableStyleManager.GetTableStyleInfo(ETableStyle.Channel, DataProvider.ChannelDao.TableName, attributeName, RelatedIdentities.GetChannelRelatedIdentities(pageInfo.SiteId, nodeInfo.ChannelId)); //parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, ",", pageInfo.SiteInfo, ETableStyle.Channel, styleInfo, string.Empty, null, string.Empty, true); var formCollection = nodeInfo.Additional.ToNameValueCollection(); if (formCollection != null && formCollection.Count > 0) { var styleInfo = TableStyleManager.GetTableStyleInfo(DataProvider.ChannelDao.TableName, attributeName, RelatedIdentities.GetChannelRelatedIdentities(pageInfo.SiteId, nodeInfo.Id)); // 如果 styleInfo.TableStyleId <= 0,表示此字段已经被删除了,不需要再显示值了 ekun008 if (styleInfo.Id > 0) { parsedContent = GetValue(attributeName, formCollection, false, styleInfo.DefaultValue); if (!string.IsNullOrEmpty(parsedContent)) { if (InputTypeUtils.EqualsAny(styleInfo.InputType, InputType.Image, InputType.File)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } else { parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, null, pageInfo.SiteInfo, styleInfo, string.Empty, null, string.Empty, true); } } } } } } catch { // ignored } return(parsedContent); }
private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, SiteInfo siteInfo, string type, string formatString, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper) { if (siteInfo == null) { return(string.Empty); } var parsedContent = string.Empty; if (!string.IsNullOrEmpty(contextInfo.InnerHtml)) { var preSiteInfo = pageInfo.SiteInfo; var prePageChannelId = pageInfo.PageChannelId; var prePageContentId = pageInfo.PageContentId; pageInfo.ChangeSite(siteInfo, siteInfo.Id, 0, contextInfo); var innerBuilder = new StringBuilder(contextInfo.InnerHtml); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); parsedContent = innerBuilder.ToString(); pageInfo.ChangeSite(preSiteInfo, prePageChannelId, prePageContentId, contextInfo); return(parsedContent); } var inputType = InputType.Text; if (type.ToLower().Equals(TypeSiteName.ToLower())) { parsedContent = pageInfo.SiteInfo.SiteName; } else if (type.ToLower().Equals(TypeSiteUrl.ToLower())) { parsedContent = pageInfo.SiteInfo.Additional.WebUrl; } else if (pageInfo.SiteInfo.Additional.GetString(type) != null) { parsedContent = pageInfo.SiteInfo.Additional.GetString(type); if (!string.IsNullOrEmpty(parsedContent)) { var styleInfo = TableStyleManager.GetTableStyleInfo(DataProvider.SiteDao.TableName, type, TableStyleManager.GetRelatedIdentities(pageInfo.SiteId)); // 如果 styleInfo.TableStyleId <= 0,表示此字段已经被删除了,不需要再显示值了 ekun008 if (styleInfo.Id > 0) { if (isClearTags && InputTypeUtils.EqualsAny(styleInfo.InputType, InputType.Image, InputType.File)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } else { parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, separator, pageInfo.SiteInfo, styleInfo, formatString, contextInfo.Attributes, contextInfo.InnerHtml, false); inputType = styleInfo.InputType; //parsedContent = StringUtils.ParseString(styleInfo.InputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } } else { // 如果字段已经被删除或不再显示了,则此字段的值为空。有时虚拟字段值不会清空 parsedContent = string.Empty; } } } if (string.IsNullOrEmpty(parsedContent)) { return(string.Empty); } return(InputTypeUtils.ParseString(inputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString)); }
internal static async Task <string> ParseAsync(string stlEntity, IParseManager parseManager) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var parsedContent = string.Empty; try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var attributeName = entityName.Substring(5, entityName.Length - 6); if (StringUtils.EqualsIgnoreCase(PoweredBy, attributeName))//支持信息 { parsedContent = @$ "Powered by <a href=" "{CloudUtils.Www.Host}" " target=" "_blank" ">SS CMS</a>"; } else if (StringUtils.EqualsIgnoreCase(RootUrl, attributeName))//系统根目录地址 { parsedContent = parseManager.PathManager.ParseUrl("~"); if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = parsedContent.TrimEnd('/'); } } else if (StringUtils.EqualsIgnoreCase(ApiUrl, attributeName))//API地址 { parsedContent = parseManager.PathManager.GetRootUrl(); } else if (StringUtils.EqualsIgnoreCase(SiteId, attributeName))//ID { parsedContent = pageInfo.SiteId.ToString(); } else if (StringUtils.EqualsIgnoreCase(SiteName, attributeName))//名称 { parsedContent = pageInfo.Site.SiteName; } else if (StringUtils.EqualsIgnoreCase(SiteUrl, attributeName))//域名地址 { parsedContent = (await parseManager.PathManager.GetSiteUrlAsync(pageInfo.Site, pageInfo.IsLocal)).TrimEnd('/'); } else if (StringUtils.EqualsIgnoreCase(SiteDir, attributeName))//文件夹 { parsedContent = pageInfo.Site.SiteDir; } else if (StringUtils.EqualsIgnoreCase(CurrentUrl, attributeName))//当前页地址 { var contentInfo = await parseManager.GetContentAsync(); parsedContent = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(ChannelUrl, attributeName))//栏目页地址 { parsedContent = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, await databaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId), pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(HomeUrl, attributeName))//用户中心地址 { parsedContent = parseManager.PathManager.GetHomeUrl(string.Empty).TrimEnd('/'); } else if (StringUtils.EqualsIgnoreCase(LoginUrl, attributeName)) { var contentInfo = await parseManager.GetContentAsync(); var returnUrl = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal); parsedContent = parseManager.PathManager.GetHomeUrl($"pages/login.html?returnUrl={PageUtils.UrlEncode(returnUrl)}"); } else if (StringUtils.EqualsIgnoreCase(LogoutUrl, attributeName)) { var contentInfo = await parseManager.GetContentAsync(); var returnUrl = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal); parsedContent = parseManager.PathManager.GetHomeUrl($"pages/logout.html?returnUrl={PageUtils.UrlEncode(returnUrl)}"); } else if (StringUtils.EqualsIgnoreCase(RegisterUrl, attributeName)) { var contentInfo = await parseManager.GetContentAsync(); var returnUrl = await StlParserUtility.GetStlCurrentUrlAsync(parseManager, pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId, contentInfo, pageInfo.Template.TemplateType, pageInfo.Template.Id, pageInfo.IsLocal); parsedContent = parseManager.PathManager.GetHomeUrl($"pages/register.html?returnUrl={PageUtils.UrlEncode(returnUrl)}"); } else if (StringUtils.StartsWithIgnoreCase(attributeName, "TableFor"))// { if (StringUtils.EqualsIgnoreCase(attributeName, "TableForContent")) { parsedContent = pageInfo.Site.TableName; } } else if (StringUtils.StartsWithIgnoreCase(attributeName, "Site"))// { parsedContent = pageInfo.Site.Get <string>(attributeName.Substring(4)); } else if (pageInfo.Parameters != null && pageInfo.Parameters.ContainsKey(attributeName)) { pageInfo.Parameters.TryGetValue(attributeName, out parsedContent); } else { if (pageInfo.Site.ContainsKey(attributeName)) { parsedContent = pageInfo.Site.Get <string>(attributeName); if (!string.IsNullOrEmpty(parsedContent)) { var styleInfo = await databaseManager.TableStyleRepository.GetTableStyleAsync(databaseManager.SiteRepository.TableName, attributeName, databaseManager.TableStyleRepository.GetRelatedIdentities(pageInfo.SiteId)); if (styleInfo.Id > 0) { var inputParser = new InputParserManager(parseManager.PathManager); parsedContent = InputTypeUtils.EqualsAny(styleInfo.InputType, InputType.Image, InputType.File) ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal) : await inputParser.GetContentByTableStyleAsync(parsedContent, string.Empty, pageInfo.Site, styleInfo, string.Empty, null, string.Empty, true); } else { // 如果字段已经被删除或不再显示了,则此字段的值为空。有时虚拟字段值不会清空 parsedContent = string.Empty; } } } } } catch { // ignored } return(parsedContent); }
private static async Task <string> ParseAsync(IParseManager parseManager, Site site, string type, string formatString, string no, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, NameValueCollection attributes) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; if (site == null) { return(string.Empty); } var parsedContent = string.Empty; if (!string.IsNullOrEmpty(contextInfo.InnerHtml)) { var preSite = pageInfo.Site; var prePageChannelId = pageInfo.PageChannelId; var prePageContentId = pageInfo.PageContentId; pageInfo.ChangeSite(site, site.Id, 0, contextInfo); var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); parsedContent = innerBuilder.ToString(); pageInfo.ChangeSite(preSite, prePageChannelId, prePageContentId, contextInfo); return(parsedContent); } var inputType = InputType.Text; if (StringUtils.EqualsIgnoreCase(type, TypeSiteName)) { parsedContent = site.SiteName; } else if (StringUtils.EqualsIgnoreCase(type, TypeImageUrl)) { var inputParser = new InputParserManager(parseManager.PathManager); if (no == "all") { var sbParsedContent = new StringBuilder(); //第一条 sbParsedContent.Append(contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(site, site.ImageUrl, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(site, site.ImageUrl, attributes, false)); //第n条 var countName = ColumnsManager.GetCountName(nameof(Content.ImageUrl)); var count = site.Get <int>(countName); for (var i = 1; i <= count; i++) { var extendName = ColumnsManager.GetExtendName(nameof(Content.ImageUrl), i); var extend = site.Get <string>(extendName); sbParsedContent.Append(contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, extend, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, extend, attributes, false)); } parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no); if (num <= 1) { parsedContent = contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(site, site.ImageUrl, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(site, site.ImageUrl, attributes, false); } else { var extendName = ColumnsManager.GetExtendName(nameof(Site.ImageUrl), num - 1); var extend = site.Get <string>(extendName); if (!string.IsNullOrEmpty(extend)) { parsedContent = contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, extend, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, extend, attributes, false); } } } } else if (StringUtils.EqualsIgnoreCase(type, TypeKeywords)) { parsedContent = site.Keywords; } else if (StringUtils.EqualsIgnoreCase(type, TypeDescription)) { parsedContent = site.Description; } else if (StringUtils.EqualsIgnoreCase(type, TypeSiteUrl)) { parsedContent = await parseManager.PathManager.GetWebUrlAsync(site); } else if (pageInfo.Site.Get <string>(type) != null) { parsedContent = pageInfo.Site.Get <string>(type); if (!string.IsNullOrEmpty(parsedContent)) { var styleInfo = await databaseManager.TableStyleRepository.GetTableStyleAsync(databaseManager.SiteRepository.TableName, type, databaseManager.TableStyleRepository.GetRelatedIdentities(pageInfo.SiteId)); if (styleInfo.Id > 0) { if (isClearTags && InputTypeUtils.EqualsAny(styleInfo.InputType, InputType.Image, InputType.Video, InputType.File)) { parsedContent = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal); } else { var inputParser = new InputParserManager(parseManager.PathManager); parsedContent = await inputParser.GetContentByTableStyleAsync(parsedContent, separator, pageInfo.Site, styleInfo, formatString, attributes, contextInfo.InnerHtml, contextInfo.IsStlEntity); inputType = styleInfo.InputType; //parsedContent = StringUtils.ParseString(styleInfo.InputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } } else { // 如果字段已经被删除或不再显示了,则此字段的值为空。有时虚拟字段值不会清空 parsedContent = string.Empty; } } } if (string.IsNullOrEmpty(parsedContent)) { return(string.Empty); } return(InputTypeUtils.ParseString(inputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString)); }
internal static async Task <string> ParseAsync(string stlEntity, IParseManager parseManager) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var parsedContent = string.Empty; try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var channelIndex = StlParserUtility.GetValueFromEntity(stlEntity); var attributeName = entityName.Substring(9, entityName.Length - 10); var upLevel = 0; var topLevel = -1; var channelId = contextInfo.ChannelId; if (!string.IsNullOrEmpty(channelIndex)) { //channelId = databaseManager.ChannelRepository.GetIdByIndexName(pageInfo.SiteId, channelIndex); channelId = await databaseManager.ChannelRepository.GetChannelIdByIndexNameAsync(pageInfo.SiteId, channelIndex); if (channelId == 0) { channelId = contextInfo.ChannelId; } } if (StringUtils.StartsWithIgnoreCase(attributeName, "up") && attributeName.IndexOf(".", StringComparison.Ordinal) != -1) { if (StringUtils.StartsWithIgnoreCase(attributeName, "up.")) { upLevel = 1; } else { var upLevelStr = attributeName.Substring(2, attributeName.IndexOf(".", StringComparison.Ordinal) - 2); upLevel = TranslateUtils.ToInt(upLevelStr); } topLevel = -1; attributeName = attributeName.Substring(attributeName.IndexOf(".", StringComparison.Ordinal) + 1); } else if (StringUtils.StartsWithIgnoreCase(attributeName, "top") && attributeName.IndexOf(".", StringComparison.Ordinal) != -1) { if (StringUtils.StartsWithIgnoreCase(attributeName, "top.")) { topLevel = 1; } else { var topLevelStr = attributeName.Substring(3, attributeName.IndexOf(".", StringComparison.Ordinal) - 3); topLevel = TranslateUtils.ToInt(topLevelStr); } upLevel = 0; attributeName = attributeName.Substring(attributeName.IndexOf(".", StringComparison.Ordinal) + 1); } var dataManager = new StlDataManager(parseManager.DatabaseManager); var nodeInfo = await databaseManager.ChannelRepository.GetAsync(await dataManager.GetChannelIdByLevelAsync(pageInfo.SiteId, channelId, upLevel, topLevel)); if (StringUtils.EqualsIgnoreCase(ChannelId, attributeName))//栏目ID { parsedContent = nodeInfo.Id.ToString(); } else if (StringUtils.EqualsIgnoreCase(Title, attributeName) || StringUtils.EqualsIgnoreCase(ChannelName, attributeName))//栏目名称 { parsedContent = nodeInfo.ChannelName; } else if (StringUtils.EqualsIgnoreCase(ChannelIndex, attributeName))//栏目索引 { parsedContent = nodeInfo.IndexName; } else if (StringUtils.EqualsIgnoreCase(Content, attributeName))//栏目正文 { parsedContent = await parseManager.PathManager.DecodeTextEditorAsync(pageInfo.Site, nodeInfo.Content, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(NavigationUrl, attributeName))//栏目链接地址 { parsedContent = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, nodeInfo, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(ImageUrl, attributeName))//栏目图片地址 { parsedContent = nodeInfo.ImageUrl; if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(AddDate, attributeName))//栏目添加日期 { parsedContent = DateUtils.Format(nodeInfo.AddDate, string.Empty); } else if (StringUtils.EqualsIgnoreCase(DirectoryName, attributeName))//生成文件夹名称 { parsedContent = PathUtils.GetDirectoryName(nodeInfo.FilePath, true); } else if (StringUtils.EqualsIgnoreCase(Group, attributeName))//栏目组别 { parsedContent = ListUtils.ToString(nodeInfo.GroupNames); } else if (StringUtils.StartsWithIgnoreCase(attributeName, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ChannelItem != null) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ChannelItem.Key, attributeName, contextInfo).ToString(); } else if (StringUtils.EqualsIgnoreCase(nameof(Channel.Keywords), attributeName))//栏目组别 { parsedContent = nodeInfo.Keywords; } else if (StringUtils.EqualsIgnoreCase(nameof(Channel.Description), attributeName))//栏目组别 { parsedContent = nodeInfo.Description; } else { //var styleInfo = TableStyleManager.GetTableStyleInfo(ETableStyle.Channel, databaseManager.ChannelRepository.TableName, attributeName, RelatedIdentities.GetChannelRelatedIdentities(pageInfo.SiteId, node.ChannelId)); //parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, ",", pageInfo.Site, ETableStyle.Channel, styleInfo, string.Empty, null, string.Empty, true); var styleInfo = await databaseManager.TableStyleRepository.GetTableStyleAsync(databaseManager.ChannelRepository.TableName, attributeName, databaseManager.TableStyleRepository.GetRelatedIdentities(nodeInfo)); if (styleInfo.Id > 0) { parsedContent = GetValue(attributeName, nodeInfo, false, styleInfo.DefaultValue); if (!string.IsNullOrEmpty(parsedContent)) { if (InputTypeUtils.EqualsAny(styleInfo.InputType, InputType.Image, InputType.File)) { parsedContent = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal); } else { var inputParser = new InputParserManager(parseManager.PathManager); parsedContent = await inputParser.GetContentByTableStyleAsync(parsedContent, null, pageInfo.Site, styleInfo, string.Empty, null, string.Empty, true); } } } } } catch { // ignored } return(parsedContent); }