internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var attributeName = entityName.Substring(12, entityName.Length - 13); var nodeInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId); if (StringUtils.EqualsIgnoreCase(PreviousChannel, attributeName) || StringUtils.EqualsIgnoreCase(NextChannel, attributeName)) { var taxis = nodeInfo.Taxis; var isNextChannel = !StringUtils.EqualsIgnoreCase(attributeName, PreviousChannel); //var siblingChannelId = DataProvider.ChannelDao.GetIdByParentIdAndTaxis(nodeInfo.ParentId, taxis, isNextChannel); var siblingChannelId = StlChannelCache.GetIdByParentIdAndTaxis(nodeInfo.ParentId, taxis, isNextChannel); if (siblingChannelId != 0) { var siblingNodeInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, siblingChannelId); parsedContent = PageUtility.GetChannelUrl(pageInfo.SiteInfo, siblingNodeInfo, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(PreviousContent, attributeName) || StringUtils.EqualsIgnoreCase(NextContent, attributeName)) { if (contextInfo.ContentId != 0) { var taxis = contextInfo.ContentInfo.Taxis; var isNextContent = !StringUtils.EqualsIgnoreCase(attributeName, PreviousContent); var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, contextInfo.ChannelId); var siblingContentId = StlContentCache.GetContentId(tableName, contextInfo.ChannelId, taxis, isNextContent); if (siblingContentId != 0) { var contentInfo = ContentManager.GetContentInfo(pageInfo.SiteInfo, contextInfo.ChannelId, siblingContentId); parsedContent = PageUtility.GetContentUrl(pageInfo.SiteInfo, contentInfo, pageInfo.IsLocal); } } } } catch { // ignored } if (string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtils.UnclickedUrl; } return(parsedContent); }
private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, HtmlAnchor stlAnchor, string type, string emptyText, string tipText, int wordNum, bool isKeyboard) { string parsedContent; string successTemplateString; string failureTemplateString; StlParserUtility.GetYesNo(contextInfo.InnerHtml, out successTemplateString, out failureTemplateString); if (string.IsNullOrEmpty(successTemplateString)) { var nodeInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId); if (type.ToLower().Equals(TypePreviousChannel.ToLower()) || type.ToLower().Equals(TypeNextChannel.ToLower())) { var taxis = nodeInfo.Taxis; var isNextChannel = !StringUtils.EqualsIgnoreCase(type, TypePreviousChannel); //var siblingChannelId = DataProvider.ChannelDao.GetIdByParentIdAndTaxis(nodeInfo.ParentId, taxis, isNextChannel); var siblingChannelId = StlChannelCache.GetIdByParentIdAndTaxis(nodeInfo.ParentId, taxis, isNextChannel); if (siblingChannelId != 0) { var siblingNodeInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, siblingChannelId); var url = PageUtility.GetChannelUrl(pageInfo.SiteInfo, siblingNodeInfo, pageInfo.IsLocal); if (url.Equals(PageUtils.UnclickedUrl)) { stlAnchor.Target = string.Empty; } stlAnchor.HRef = url; if (string.IsNullOrEmpty(contextInfo.InnerHtml)) { stlAnchor.InnerHtml = ChannelManager.GetChannelName(pageInfo.SiteId, siblingChannelId); if (wordNum > 0) { stlAnchor.InnerHtml = StringUtils.MaxLengthText(stlAnchor.InnerHtml, wordNum); } } else { contextInfo.ChannelId = siblingChannelId; var innerBuilder = new StringBuilder(contextInfo.InnerHtml); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); stlAnchor.InnerHtml = innerBuilder.ToString(); } } } else if (type.ToLower().Equals(TypePreviousContent.ToLower()) || type.ToLower().Equals(TypeNextContent.ToLower())) { if (contextInfo.ContentId != 0) { var taxis = contextInfo.ContentInfo.Taxis; var isNextContent = !StringUtils.EqualsIgnoreCase(type, TypePreviousContent); var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, contextInfo.ChannelId); //var siblingContentId = DataProvider.ContentDao.GetContentId(tableName, contextInfo.ChannelId, taxis, isNextContent); var siblingContentId = StlContentCache.GetContentId(tableName, contextInfo.ChannelId, taxis, isNextContent); if (siblingContentId != 0) { //var siblingContentInfo = DataProvider.ContentDao.GetContentInfo(tableStyle, tableName, siblingContentId); var siblingContentInfo = ContentManager.GetContentInfo(pageInfo.SiteInfo, contextInfo.ChannelId, siblingContentId); var url = PageUtility.GetContentUrl(pageInfo.SiteInfo, siblingContentInfo, pageInfo.IsLocal); if (url.Equals(PageUtils.UnclickedUrl)) { stlAnchor.Target = string.Empty; } stlAnchor.HRef = url; if (isKeyboard) { var keyCode = isNextContent ? 39 : 37; var scriptContent = new StringBuilder(); pageInfo.AddPageBodyCodeIfNotExists(PageInfo.Const.Jquery); scriptContent.Append($@"<script language=""javascript"" type=""text/javascript""> $(document).keydown(function(event){{ if(event.keyCode=={keyCode}){{location = '{url}';}} }}); </script> "); var nextOrPrevious = isNextContent ? "nextContent" : "previousContent"; pageInfo.BodyCodes[nextOrPrevious] = scriptContent.ToString(); } if (string.IsNullOrEmpty(contextInfo.InnerHtml)) { stlAnchor.InnerHtml = siblingContentInfo.Title; if (wordNum > 0) { stlAnchor.InnerHtml = StringUtils.MaxLengthText(stlAnchor.InnerHtml, wordNum); } } else { var innerBuilder = new StringBuilder(contextInfo.InnerHtml); contextInfo.ContentId = siblingContentId; StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); stlAnchor.InnerHtml = innerBuilder.ToString(); } } } } parsedContent = string.IsNullOrEmpty(stlAnchor.HRef) ? emptyText : ControlUtils.GetControlRenderHtml(stlAnchor); } else { var nodeInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId); var isSuccess = false; var theContextInfo = contextInfo.Clone(); if (type.ToLower().Equals(TypePreviousChannel.ToLower()) || type.ToLower().Equals(TypeNextChannel.ToLower())) { var taxis = nodeInfo.Taxis; var isNextChannel = !StringUtils.EqualsIgnoreCase(type, TypePreviousChannel); //var siblingChannelId = DataProvider.ChannelDao.GetIdByParentIdAndTaxis(nodeInfo.ParentId, taxis, isNextChannel); var siblingChannelId = StlChannelCache.GetIdByParentIdAndTaxis(nodeInfo.ParentId, taxis, isNextChannel); if (siblingChannelId != 0) { isSuccess = true; theContextInfo.ContextType = EContextType.Channel; theContextInfo.ChannelId = siblingChannelId; } } else if (type.ToLower().Equals(TypePreviousContent.ToLower()) || type.ToLower().Equals(TypeNextContent.ToLower())) { if (contextInfo.ContentId != 0) { var taxis = contextInfo.ContentInfo.Taxis; var isNextContent = !StringUtils.EqualsIgnoreCase(type, TypePreviousContent); var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, contextInfo.ChannelId); //var siblingContentId = DataProvider.ContentDao.GetContentId(tableName, contextInfo.ChannelId, taxis, isNextContent); var siblingContentId = StlContentCache.GetContentId(tableName, contextInfo.ChannelId, taxis, isNextContent); if (siblingContentId != 0) { isSuccess = true; theContextInfo.ContextType = EContextType.Content; theContextInfo.ContentId = siblingContentId; theContextInfo.ContentInfo = null; } } } parsedContent = isSuccess ? successTemplateString : failureTemplateString; if (!string.IsNullOrEmpty(parsedContent)) { var innerBuilder = new StringBuilder(parsedContent); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, theContextInfo); parsedContent = innerBuilder.ToString(); } } parsedContent = tipText + parsedContent; return(parsedContent); }