Ejemplo n.º 1
0
        public string GetFileHtmlWithoutCount(Site site, string fileUrl, NameValueCollection attributes, string innerHtml, bool isStlEntity, bool isLower, bool isUpper)
        {
            if (site == null || string.IsNullOrEmpty(fileUrl))
            {
                return(string.Empty);
            }

            string retVal;

            if (isStlEntity)
            {
                retVal = _pathManager.GetDownloadApiUrl(site.Id, fileUrl);
            }
            else
            {
                var linkAttributes = new NameValueCollection();
                TranslateUtils.AddAttributesIfNotExists(linkAttributes, attributes);
                linkAttributes["href"] = _pathManager.GetDownloadApiUrl(site.Id, fileUrl);
                innerHtml = string.IsNullOrEmpty(innerHtml) ? PageUtils.GetFileNameFromUrl(fileUrl) : innerHtml;

                if (isLower)
                {
                    innerHtml = StringUtils.ToLower(innerHtml);
                }
                if (isUpper)
                {
                    innerHtml = StringUtils.ToUpper(innerHtml);
                }

                retVal = $@"<a {TranslateUtils.ToAttributesString(linkAttributes)}>{innerHtml}</a>";
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        public async Task <string> GetImageOrFlashHtmlAsync(Site site, string imageUrl, NameValueCollection attributes, bool isStlEntity)
        {
            var retVal = string.Empty;

            if (!string.IsNullOrEmpty(imageUrl))
            {
                imageUrl = await _pathManager.ParseSiteUrlAsync(site, imageUrl, false);

                if (isStlEntity)
                {
                    retVal = imageUrl;
                }
                else
                {
                    if (!imageUrl.ToUpper().Trim().EndsWith(".SWF"))
                    {
                        var imageAttributes = new NameValueCollection();
                        TranslateUtils.AddAttributesIfNotExists(imageAttributes, attributes);
                        imageAttributes["src"] = imageUrl;

                        retVal = $@"<img {TranslateUtils.ToAttributesString(imageAttributes)}>";
                    }
                    else
                    {
                        var width  = 100;
                        var height = 100;
                        if (attributes != null)
                        {
                            if (!string.IsNullOrEmpty(attributes["width"]))
                            {
                                width = TranslateUtils.ToInt(attributes["width"]);
                            }
                            if (!string.IsNullOrEmpty(attributes["height"]))
                            {
                                height = TranslateUtils.ToInt(attributes["height"]);
                            }
                        }
                        retVal = $@"
<object classid=""clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"" codebase=""http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"" width=""{width}"" height=""{height}"">
                <param name=""movie"" value=""{imageUrl}"">
                <param name=""quality"" value=""high"">
                <param name=""wmode"" value=""transparent"">
                <embed src=""{imageUrl}"" width=""{width}"" height=""{height}"" quality=""high"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" type=""application/x-shockwave-flash"" wmode=""transparent""></embed></object>
";
                    }
                }
            }
            return(retVal);
        }
Ejemplo n.º 3
0
        private static async Task <string> ParseAsync(IParseManager parseManager, string separator, string target, string linkClass, int wordNum, bool isContainSelf)
        {
            var databaseManager = parseManager.DatabaseManager;
            var pageInfo        = parseManager.PageInfo;
            var contextInfo     = parseManager.ContextInfo;

            if (!string.IsNullOrEmpty(contextInfo.InnerHtml))
            {
                separator = contextInfo.InnerHtml;
            }

            var channel = await databaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId);

            var builder = new StringBuilder();

            var parentsCount = channel.ParentsCount;
            var nodePath     = ListUtils.GetIntList(channel.ParentsPath);

            if (isContainSelf)
            {
                nodePath.Add(contextInfo.ChannelId);
            }
            foreach (var currentId in nodePath.Distinct())
            {
                var currentNodeInfo = await databaseManager.ChannelRepository.GetAsync(currentId);

                if (currentId == pageInfo.SiteId)
                {
                    var attributes = new NameValueCollection();
                    if (!string.IsNullOrEmpty(target))
                    {
                        attributes["target"] = target;
                    }
                    if (!string.IsNullOrEmpty(linkClass))
                    {
                        attributes["class"] = linkClass;
                    }
                    var url = await parseManager.PathManager.GetIndexPageUrlAsync(pageInfo.Site, pageInfo.IsLocal);

                    if (url.Equals(PageUtils.UnClickableUrl))
                    {
                        attributes["target"] = string.Empty;
                    }
                    attributes["href"] = url;
                    var innerHtml = StringUtils.MaxLengthText(currentNodeInfo.ChannelName, wordNum);

                    TranslateUtils.AddAttributesIfNotExists(attributes, contextInfo.Attributes);

                    builder.Append($@"<a {TranslateUtils.ToAttributesString(attributes)}>{innerHtml}</a>");

                    if (parentsCount > 0)
                    {
                        builder.Append(separator);
                    }
                }
                else if (currentId == contextInfo.ChannelId)
                {
                    var attributes = new NameValueCollection();
                    if (!string.IsNullOrEmpty(target))
                    {
                        attributes["target"] = target;
                    }
                    if (!string.IsNullOrEmpty(linkClass))
                    {
                        attributes["class"] = linkClass;
                    }
                    var url = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, currentNodeInfo, pageInfo.IsLocal);

                    if (url.Equals(PageUtils.UnClickableUrl))
                    {
                        attributes["target"] = string.Empty;
                    }
                    attributes["href"] = url;
                    var innerHtml = StringUtils.MaxLengthText(currentNodeInfo.ChannelName, wordNum);

                    TranslateUtils.AddAttributesIfNotExists(attributes, contextInfo.Attributes);

                    builder.Append($@"<a {TranslateUtils.ToAttributesString(attributes)}>{innerHtml}</a>");
                }
                else
                {
                    var attributes = new NameValueCollection();
                    if (!string.IsNullOrEmpty(target))
                    {
                        attributes["target"] = target;
                    }
                    if (!string.IsNullOrEmpty(linkClass))
                    {
                        attributes["class"] = linkClass;
                    }
                    var url = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, currentNodeInfo, pageInfo.IsLocal);

                    if (url.Equals(PageUtils.UnClickableUrl))
                    {
                        attributes["target"] = string.Empty;
                    }
                    attributes["href"] = url;
                    var innerHtml = StringUtils.MaxLengthText(currentNodeInfo.ChannelName, wordNum);

                    TranslateUtils.AddAttributesIfNotExists(attributes, contextInfo.Attributes);

                    builder.Append($@"<a {TranslateUtils.ToAttributesString(attributes)}>{innerHtml}</a>");

                    if (parentsCount > 0)
                    {
                        builder.Append(separator);
                    }
                }
            }

            return(builder.ToString());
        }