示例#1
0
        private static async Task <object> ParseImplAsync(IParseManager parseManager, NameValueCollection attributes, bool isGetPicUrlFromAttribute, string channelIndex, string channelName, int upLevel, int topLevel, string type, int no, bool isOriginal, string src, string altSrc)
        {
            var databaseManager = parseManager.DatabaseManager;
            var pageInfo        = parseManager.PageInfo;
            var contextInfo     = parseManager.ContextInfo;

            object parsedContent = null;

            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 = databaseManager.ChannelRepository.GetSiteId(targetChannelId);
                            var targetSiteId = await databaseManager.ChannelRepository.GetSiteIdAsync(targetChannelId);

                            var targetSite = await databaseManager.SiteRepository.GetAsync(targetSiteId);

                            var targetNodeInfo = await databaseManager.ChannelRepository.GetAsync(targetChannelId);

                            //var targetContentInfo = databaseManager.ContentRepository.GetContentInfo(tableStyle, tableName, contentInfo.ReferenceId);
                            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);

                    picUrl = channel.ImageUrl;
                }
                else if (contextType == ParseType.Each)
                {
                    picUrl = contextInfo.ItemContainer.EachItem.Value as string;
                }
            }

            if (string.IsNullOrEmpty(picUrl))
            {
                picUrl = altSrc;
            }

            if (!string.IsNullOrEmpty(picUrl))
            {
                var extension = PathUtils.GetExtension(picUrl);
                if (FileUtils.IsFlash(extension))
                {
                    parsedContent = await StlFlash.ParseAsync(parseManager);
                }
                else if (FileUtils.IsPlayer(extension))
                {
                    parsedContent = await StlPlayer.ParseAsync(parseManager);
                }
                else
                {
                    attributes["src"] = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, picUrl, pageInfo.IsLocal);

                    parsedContent = $@"<img {TranslateUtils.ToAttributesString(attributes)}>";
                }
            }

            return(parsedContent);
        }
示例#2
0
        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);
        }
示例#3
0
        private static async Task <object> ParseImplAsync(IParseManager parseManager, bool isGetPicUrlFromAttribute, string channelIndex, string channelName, int upLevel, int topLevel, string type, string src, string altSrc, string width, string height)
        {
            var pageInfo    = parseManager.PageInfo;
            var contextInfo = parseManager.ContextInfo;

            object parsedContent = null;

            var contentId = 0;

            //判断是否图片地址由标签属性获得
            if (!isGetPicUrlFromAttribute)
            {
                contentId = contextInfo.ContentId;
            }
            var contentInfo = await parseManager.GetContentAsync();

            var flashUrl = string.Empty;

            if (!string.IsNullOrEmpty(src))
            {
                flashUrl = src;
            }
            else
            {
                if (contentId != 0)//获取内容Flash
                {
                    if (contentInfo != null)
                    {
                        flashUrl = contentInfo.Get <string>(type);
                    }
                }
                else//获取栏目Flash
                {
                    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 parseManager.DatabaseManager.ChannelRepository.GetAsync(channelId);

                    flashUrl = channel.ImageUrl;
                }
            }

            if (string.IsNullOrEmpty(flashUrl))
            {
                flashUrl = altSrc;
            }

            // 如果是实体标签则返回空
            if (contextInfo.IsStlEntity)
            {
                return(flashUrl);
            }

            if (!string.IsNullOrEmpty(flashUrl))
            {
                var extension = PathUtils.GetExtension(flashUrl);
                if (FileUtils.IsImage(extension))
                {
                    parsedContent = await StlImage.ParseAsync(parseManager);
                }
                else if (FileUtils.IsPlayer(extension))
                {
                    parsedContent = await StlPlayer.ParseAsync(parseManager);
                }
                else
                {
                    flashUrl = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, flashUrl, pageInfo.IsLocal);

                    parsedContent = $@"
<embed src=""{flashUrl}"" allowfullscreen=""true"" width=""{width}"" height=""{height}"" align=""middle"" allowscriptaccess=""always"" type=""application/x-shockwave-flash"" />
";
                }
            }

            return(parsedContent);
        }