示例#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, bool isClearTags, 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);

                    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))
            {
                var extension = PathUtils.GetExtension(picUrl);
                if (FileUtils.IsFlash(extension))
                {
                    parsedContent = await StlPdf.ParseAsync(parseManager);
                }
                else if (FileUtils.IsPlayer(extension))
                {
                    parsedContent = await StlPlayer.ParseAsync(parseManager);
                }
                else
                {
                    parsedContent = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, picUrl, pageInfo.IsLocal);

                    if (!isClearTags && !contextInfo.IsStlEntity)
                    {
                        attributes["src"] = (string)parsedContent;
                        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, string playUrl, string imageUrl, string playBy, int width, int height, string type, bool isAutoPlay)
        {
            var pageInfo    = parseManager.PageInfo;
            var contextInfo = parseManager.ContextInfo;

            if (string.IsNullOrEmpty(playUrl))
            {
                var contentId = contextInfo.ContentId;
                if (contentId != 0)//获取内容视频
                {
                    var contentInfo = await parseManager.GetContentAsync();

                    if (contentInfo != null)
                    {
                        playUrl = contentInfo.Get <string>(type);
                        if (string.IsNullOrEmpty(playUrl))
                        {
                            playUrl = contentInfo.VideoUrl;
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(playUrl))
            {
                return(string.Empty);
            }

            playUrl = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, playUrl, pageInfo.IsLocal);

            imageUrl = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, imageUrl, pageInfo.IsLocal);

            var extension = PathUtils.GetExtension(playUrl);
            var elementId = StringUtils.GetElementId();

            var fileType = FileUtils.GetType(extension);

            if (FileUtils.IsFlash(extension))
            {
                return(await StlPdf.ParseAsync(parseManager));
            }

            if (FileUtils.IsImage(extension))
            {
                return(await StlImage.ParseAsync(parseManager));
            }

            if (fileType == FileType.Avi)
            {
                return(ParseAvi(elementId, width, height, isAutoPlay, playUrl));
            }

            if (fileType == FileType.Mpg)
            {
                return(ParseMpg(elementId, width, height, isAutoPlay, playUrl));
            }

            if (fileType == FileType.Rm || fileType == FileType.Rmb || fileType == FileType.Rmvb)
            {
                return(ParseRm(contextInfo, elementId, width, height, isAutoPlay, playUrl));
            }

            if (fileType == FileType.Wmv)
            {
                return(ParseWmv(elementId, width, height, isAutoPlay, playUrl));
            }

            if (fileType == FileType.Wma)
            {
                return(ParseWma(elementId, isAutoPlay, playUrl));
            }

            if (StringUtils.EqualsIgnoreCase(playBy, PlayByJwPlayer))
            {
                await pageInfo.AddPageBodyCodeIfNotExistsAsync(ParsePage.Const.JsAcJwPlayer6);

                return($@"
<div id='{elementId}'></div>
<script type='text/javascript'>
	jwplayer('{elementId}').setup({{
        autostart: {StringUtils.ToLower(isAutoPlay.ToString())},
		file: ""{playUrl}"",
		width: ""{width}"",
		height: ""{height}"",
		image: ""{imageUrl}""
	}});
</script>
");
            }

            if (StringUtils.EqualsIgnoreCase(playBy, PlayByFlowPlayer))
            {
                await pageInfo.AddPageBodyCodeIfNotExistsAsync(ParsePage.Const.JsAcFlowPlayer);

                var imageHtml = string.Empty;
                if (!string.IsNullOrEmpty(imageUrl))
                {
                    imageHtml = $@"<img src=""{imageUrl}"" style=""{(width > 0 ? $"width:{width}px;" : string.Empty)}{(height > 0 ? $"height:{height}px;" : string.Empty)}"" />";
                }

                var swfUrl = parseManager.PathManager.GetSiteFilesUrl(Resources.FlowPlayer.Swf);
                return($@"
<a href=""{playUrl}"" style=""display:block;{(width > 0 ? $"width:{width}px;" : string.Empty)}{(height > 0 ? $"height:{height}px;" : string.Empty)}"" id=""{elementId}"">{imageHtml}</a>
<script language=""javascript"">
    flowplayer(""{elementId}"", ""{swfUrl}"", {{
        clip:  {{
            autoPlay: {StringUtils.ToLower(isAutoPlay.ToString())}
        }}
    }});
</script>
");
            }

            return(await StlVideo.ParseAsync(parseManager));
        }