private static async Task <string> ParseAsync(IParseManager parseManager, NameValueCollection attributes) { var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var innerHtml = string.Empty; if (!string.IsNullOrEmpty(contextInfo.InnerHtml)) { var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); innerHtml = innerBuilder.ToString(); } var parsedContent = string.Empty; if (pageInfo.EditMode == EditMode.Visual) { var elementId = StringUtils.GetElementId(); VisualUtility.AddEditableToAttributes(attributes, elementId, contextInfo.ElementName); parsedContent = GetParsedContent(attributes, innerHtml); VisualUtility.AddEditableToPage(pageInfo, elementId, contextInfo, parsedContent); } else { parsedContent = GetParsedContent(attributes, innerHtml); } return(parsedContent); }
public static async Task <object> ParseAsync(IParseManager parseManager) { var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var listInfo = await ListInfo.GetListInfoAsync(parseManager, ParseType.Content); var dataSource = await GetContentsDataSourceAsync(parseManager, listInfo); if (parseManager.ContextInfo.IsStlEntity) { return(ParseEntity(dataSource)); } var innerHtml = await ParseAsync(parseManager, listInfo, dataSource); var parsedContent = string.Empty; if (pageInfo.EditMode == EditMode.Visual) { var elementId = StringUtils.GetElementId(); var attributes = new NameValueCollection(); VisualUtility.AddEditableToAttributes(attributes, elementId, contextInfo.ElementName); parsedContent = @$ "<div {TranslateUtils.ToAttributesString(attributes)}>{innerHtml}</div>"; VisualUtility.AddEditableToPage(pageInfo, elementId, contextInfo, parsedContent); } else { parsedContent = innerHtml; } return(parsedContent); }
private static async Task <object> ParseAsync(IParseManager parseManager, NameValueCollection attributes, bool isGetPicUrlFromAttribute, string channelIndex, string channelName, int upLevel, int topLevel, string type, int no, bool isOriginal, bool isClearTags, string src, string altSrc) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var contentId = 0; if (!isGetPicUrlFromAttribute) { contentId = contextInfo.ContentId; } var contextType = contextInfo.ContextType; var picUrl = string.Empty; if (!string.IsNullOrEmpty(src)) { picUrl = src; } else { if (contextType == ParseType.Undefined) { contextType = contentId != 0 ? ParseType.Content : ParseType.Channel; } if (contextType == ParseType.Content) { var contentInfo = await parseManager.GetContentAsync(); if (isOriginal) { if (contentInfo != null && contentInfo.ReferenceId > 0 && contentInfo.SourceId > 0) { var targetChannelId = contentInfo.SourceId; var targetSiteId = await databaseManager.ChannelRepository.GetSiteIdAsync(targetChannelId); var targetSite = await databaseManager.SiteRepository.GetAsync(targetSiteId); var targetNodeInfo = await databaseManager.ChannelRepository.GetAsync(targetChannelId); var targetContentInfo = await databaseManager.ContentRepository.GetAsync(targetSite, targetNodeInfo, contentInfo.ReferenceId); if (targetContentInfo != null && targetContentInfo.ChannelId > 0) { contentInfo = targetContentInfo; } } } if (contentInfo == null) { contentInfo = await databaseManager.ContentRepository.GetAsync(pageInfo.Site, contextInfo.ChannelId, contentId); } if (contentInfo != null) { if (no <= 1) { picUrl = contentInfo.Get <string>(type); } else { var extendName = ColumnsManager.GetExtendName(type, no - 1); picUrl = contentInfo.Get <string>(extendName); } } } else if (contextType == ParseType.Channel) //获取栏目图片 { var dataManager = new StlDataManager(parseManager.DatabaseManager); var channelId = await dataManager.GetChannelIdByLevelAsync(pageInfo.SiteId, contextInfo.ChannelId, upLevel, topLevel); channelId = await dataManager.GetChannelIdByChannelIdOrChannelIndexOrChannelNameAsync( pageInfo.SiteId, channelId, channelIndex, channelName); var channel = await databaseManager.ChannelRepository.GetAsync(channelId); if (no <= 1) { picUrl = channel.Get <string>(type); } else { var extendName = ColumnsManager.GetExtendName(type, no - 1); picUrl = channel.Get <string>(extendName); } } else if (contextType == ParseType.Each) { picUrl = contextInfo.ItemContainer.EachItem.Value as string; } } if (string.IsNullOrEmpty(picUrl)) { picUrl = altSrc; } if (string.IsNullOrEmpty(picUrl)) { return(string.Empty); } var extension = PathUtils.GetExtension(picUrl); if (FileUtils.IsFlash(extension)) { return(await StlPdf.ParseAsync(parseManager)); } if (FileUtils.IsPlayer(extension)) { return(await StlPlayer.ParseAsync(parseManager)); } picUrl = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, picUrl, pageInfo.IsLocal); if (isClearTags || contextInfo.IsStlEntity) { return(picUrl); } attributes["src"] = picUrl; var parsedContent = string.Empty; if (pageInfo.EditMode == EditMode.Visual) { var elementId = StringUtils.GetElementId(); VisualUtility.AddEditableToAttributes(attributes, elementId, contextInfo.ElementName); parsedContent = GetParsedContent(attributes); VisualUtility.AddEditableToPage(pageInfo, elementId, contextInfo, parsedContent); } else { parsedContent = GetParsedContent(attributes); } return(parsedContent); }
private static async Task <string> ParseAsync(IParseManager parseManager, string channelIndex, string channelName, int upLevel, int topLevel, bool removeTarget, string href, string queryString, string host, Dictionary <string, string> attributes) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; attributes.TryGetValue("id", out var htmlId); if (!string.IsNullOrEmpty(htmlId) && !string.IsNullOrEmpty(contextInfo.ContainerClientId)) { htmlId = contextInfo.ContainerClientId + "_" + htmlId; } if (!string.IsNullOrEmpty(htmlId)) { attributes["id"] = htmlId; } var innerHtml = string.Empty; var url = string.Empty; var onclick = string.Empty; if (!string.IsNullOrEmpty(href)) { url = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, href, pageInfo.IsLocal); var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); innerHtml = innerBuilder.ToString(); } else { if (contextInfo.ContextType == ParseType.Undefined) { contextInfo.ContextType = contextInfo.ContentId != 0 ? ParseType.Content : ParseType.Channel; } if (contextInfo.ContextType == ParseType.Content) //获取内容Url { var contentInfo = await parseManager.GetContentAsync(); if (contentInfo != null) { url = await parseManager.PathManager.GetContentUrlAsync(pageInfo.Site, contentInfo, pageInfo.IsLocal); } else { var nodeInfo = await databaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId); url = await parseManager.PathManager.GetContentUrlAsync(pageInfo.Site, nodeInfo, contextInfo.ContentId, pageInfo.IsLocal); } if (string.IsNullOrEmpty(contextInfo.InnerHtml)) { var title = contentInfo?.Title; title = ContentUtility.FormatTitle( contentInfo?.Get <string>("BackgroundContentAttribute.TitleFormatString"), title); if (pageInfo.Site.IsContentTitleBreakLine) { title = title.Replace(" ", string.Empty); } innerHtml = title; } else { var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); innerHtml = innerBuilder.ToString(); } } else if (contextInfo.ContextType == ParseType.Channel) //获取栏目Url { var dataManager = new StlDataManager(parseManager.DatabaseManager); contextInfo.ChannelId = await dataManager.GetChannelIdByLevelAsync(pageInfo.SiteId, contextInfo.ChannelId, upLevel, topLevel); contextInfo.ChannelId = await databaseManager.ChannelRepository.GetChannelIdAsync(pageInfo.SiteId, contextInfo.ChannelId, channelIndex, channelName); var channel = await databaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId); url = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, channel, pageInfo.IsLocal); if (string.IsNullOrWhiteSpace(contextInfo.InnerHtml)) { innerHtml = channel.ChannelName; } else { var innerBuilder = new StringBuilder(contextInfo.InnerHtml); await parseManager.ParseInnerContentAsync(innerBuilder); innerHtml = innerBuilder.ToString(); } } } if (url.Equals(PageUtils.UnClickableUrl)) { removeTarget = true; } else { if (!string.IsNullOrEmpty(host)) { url = PageUtils.AddProtocolToUrl(url, host); } if (!string.IsNullOrEmpty(queryString)) { url = PageUtils.AddQueryString(url, queryString); } } attributes["href"] = url; if (!string.IsNullOrEmpty(onclick)) { attributes["onclick"] = onclick; } if (removeTarget) { attributes["target"] = string.Empty; } // 如果是实体标签,则只返回url if (contextInfo.IsStlEntity) { return(url); } var parsedContent = string.Empty; if (pageInfo.EditMode == EditMode.Visual) { var elementId = StringUtils.GetElementId(); VisualUtility.AddEditableToAttributes(attributes, elementId, contextInfo.ElementName); parsedContent = GetParsedContent(attributes, innerHtml); VisualUtility.AddEditableToPage(pageInfo, elementId, contextInfo, parsedContent); } else { parsedContent = GetParsedContent(attributes, innerHtml); } return(parsedContent); }