Esempio n. 1
0
        private Dictionary <string, string> ReplaceInlineCssUrl(Kooboo.Dom.Element element, AnalyzerContext Context)
        {
            string csstext = element.getAttribute("style");

            if (string.IsNullOrEmpty(csstext))
            {
                return(null);
            }

            Dictionary <string, string> replace = new Dictionary <string, string>();

            var urlInfos = Service.CssService.GetUrlInfos(csstext);

            foreach (var item in urlInfos)
            {
                if (string.IsNullOrEmpty(item.PureUrl) || item.PureUrl.Trim().ToLower().StartsWith("#"))
                {
                    continue;
                }

                string newurl = string.Empty;
                if (item.isImportRule)
                {
                    newurl = CssManager.AddImport(item.PureUrl, Context.AbsoluteUrl, Context.DownloadManager, Context.ObjectId);
                }
                else
                {
                    if (Kooboo.Lib.Utilities.DataUriService.isDataUri(item.PureUrl))
                    {
                        newurl = CssManager.ParseDataUri(item.PureUrl, Context.DownloadManager);
                    }
                    else
                    {
                        newurl = CssManager.DownloadCssFile(item.PureUrl, Context.AbsoluteUrl, Context.DownloadManager, Context.ObjectId);
                    }
                }

                if (newurl != item.PureUrl)
                {
                    replace.Add(item.PureUrl, newurl);
                }
            }

            return(replace);
        }
Esempio n. 2
0
        public static string GetImageNonSrcUrl(Kooboo.Dom.Element imagetag)
        {
            if (imagetag == null)
            {
                return(null);
            }

            foreach (var item in imagetag.attributes)
            {
                if (item != null && item.name != null)
                {
                    string name = item.name.Trim().ToLower();
                    if (name != "src" && name.Contains("src"))
                    {
                        return(item.value);
                    }
                }
            }
            return(null);
        }
Esempio n. 3
0
        public static bool IsMatch(Kooboo.Dom.Element el, List <simpleSelector> selectors)
        {
            if (selectorMatch.Match(el, selectors))
            {
                return(true);
            }

            foreach (var item in el.childNodes.item)
            {
                if (item.nodeType == Dom.enumNodeType.ELEMENT)
                {
                    var subel  = item as Element;
                    var testok = IsMatch(subel, selectors);
                    if (testok)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 4
0
        private Dictionary <string, string> ReplaceLinks(Kooboo.Dom.Element element, AnalyzerContext Context)
        {
            string itemsrc = Service.DomUrlService.GetLinkOrSrc(element);

            if (string.IsNullOrEmpty(itemsrc))
            {
                return(null);
            }

            Dictionary <string, string> replace = new Dictionary <string, string>();

            string absoluteurl = UrlHelper.Combine(Context.AbsoluteUrl, itemsrc);

            bool issamehost = UrlHelper.isSameHost(absoluteurl, Context.OriginalImportUrl);

            var objectType = Service.ConstTypeService.GetConstTypeByUrl(absoluteurl);

            if (issamehost)
            {
                string relativeurl = UrlHelper.RelativePath(absoluteurl, issamehost);

                if (itemsrc != relativeurl)
                {
                    replace.Add(itemsrc, relativeurl);
                }
            }
            else
            {
                if (itemsrc != absoluteurl)
                {
                    replace.Add(itemsrc, absoluteurl);
                }
            }

            return(replace);
        }