/// <summary> /// 把内容中的图片,相对地址变为绝对地址。 /// </summary> /// <param name="tmp_content"></param> /// <param name="url"></param> public static void ImageSrc(ref string tmp_content, string url) { //如果遇到使用绝对路径的图片,转换为全路径。 NodeList htmlNodes = new Parser(new Lexer(tmp_content.Replace("<IMG", "<img").Replace("<Img", "<img"))).Parse(new TagNameFilter("img")); for (int j = htmlNodes.Count - 1; j >= 0; j--) { ImageTag link = (ImageTag)htmlNodes.ElementAt(j); string urlpart = link.GetAttribute("src"); if (!string.IsNullOrEmpty(urlpart) && !new Regex(@"^http:").IsMatch(urlpart)) { urlpart = new xkHttp().getDealUrl(url, urlpart); string oldlink = link.ToHtml(); link.RemoveAttribute("src"); link.RemoveAttribute("onclick"); string newsrc = "src=\"" + urlpart + "\" "; string newlink = link.ToHtml(); newlink = newlink.Insert(5, newsrc); tmp_content = tmp_content.Replace(oldlink, newlink); //EchoHelper.Echo("成功转换了一个图片的SRC属性!", "", EchoHelper.EchoType.普通信息); } if (!string.IsNullOrEmpty(urlpart) && new Regex(@"^\.\.").IsMatch(urlpart)) { string oldlink = link.ToHtml(); tmp_content = tmp_content.Replace(oldlink, ""); } } }
private string RenderNode(string prefix, int Level, TreeNode CurrentNode, bool IsLastNode) { if (OnNodeRender != null) { CurrentNode = OnNodeRender(IsLastNode, Level, CurrentNode); } Text = new LinkTag(); List <TreeNode> ChildList = Data.Where(c => c.ParentId == CurrentNode.Id).ToList(); bool HasChild = (ChildList.Count > 0); string DataAttr = ""; if (NodeKeys.Count > 0) { DataAttr = " data=\"({ ids: [" + string.Join(",", CurrentNode.Keys.ToArray()) + "] })\""; } string html = "<div class=\"TreeNode\" id=\"" + BaseId + "_TreeNode" + CurrentNode.Id + "\"" + DataAttr + "><span id=\"" + BaseId + "_TreeNodePrefix" + CurrentNode.Id + "\">" + prefix + "</span>"; if (HasChild && IsLastNode) { OpenCloseImage.Id = BaseId + "_TreeNodeState" + CurrentNode.Id; if (CurrentNode.Open) { OpenCloseImage.Src = BaseFolder + "tree/minusbottom.gif"; } else { OpenCloseImage.Src = BaseFolder + "tree/plusbottom.gif"; } OpenCloseImage.SetAttribute("onclick", string.Format(BaseId + ".changeState('{0}','{1}','{2}')", CurrentNode.Id, CurrentNode.Icon, CurrentNode.IconOpen)); html += OpenCloseImage.ToHtml(); } else if (HasChild && !IsLastNode) { OpenCloseImage.Id = BaseId + "_TreeNodeState" + CurrentNode.Id; if (CurrentNode.Open) { OpenCloseImage.Src = BaseFolder + "tree/minus.gif"; } else { OpenCloseImage.Src = BaseFolder + "tree/plus.gif"; } OpenCloseImage.SetAttribute("onclick", string.Format(BaseId + ".changeState('{0}','{1}','{2}',null)", CurrentNode.Id, CurrentNode.Icon, CurrentNode.IconOpen)); html += OpenCloseImage.ToHtml(); } else if (!HasChild && IsLastNode) { OtherImage.Src = BaseFolder + "tree/joinbottom.gif"; html += OtherImage.ToHtml(); } else { OtherImage.Src = BaseFolder + "tree/join.gif"; html += OtherImage.ToHtml(); } if (EnableCheckbox) { html += "<input onclick=\"" + BaseId + ".checkNode(this,'" + CurrentNode.Id + "')\" type=\"checkbox\" name=\"" + BaseId + "_CHK\" value=\"" + CurrentNode.Id + "\" />"; } if (EnableNodeImage) { OtherImage.Id = BaseId + "_TreeNodeFolder" + CurrentNode.Id; if (HasChild) { if (CurrentNode.Open) { OtherImage.Src = (!string.IsNullOrEmpty(CurrentNode.IconOpen)) ? CurrentNode.IconOpen : BaseFolder + "tree/folderopen.gif"; } else { OtherImage.Src = (!string.IsNullOrEmpty(CurrentNode.Icon)) ? CurrentNode.Icon : BaseFolder + "tree/folder.gif"; } html += OtherImage.ToHtml(); } else { OtherImage.Src = BaseFolder + "tree/page.gif"; html += OtherImage.ToHtml(); } OtherImage.ClearAttribute("id"); } Text.SetAttribute("onclick", string.Format(BaseId + ".selectNode('{0}',{1})", CurrentNode.Id, IsLastNode.ToString().ToLower())); Text.SetAttribute("ondblclick", string.Format(BaseId + ".selectNodeDBL('{0}',{1})", CurrentNode.Id, IsLastNode.ToString().ToLower())); if (!string.IsNullOrEmpty(CurrentNode.Url)) { Text.Href = CurrentNode.Url; if (!string.IsNullOrEmpty(CurrentNode.Target)) { Text.SetAttribute("target", CurrentNode.Target); } } else if (HasChild) { Text.Href = "javascript:" + string.Format(BaseId + ".changeState('{0}','{1}','{2}',null)", CurrentNode.Id, CurrentNode.Icon, CurrentNode.IconOpen); } Text.TagContent = CurrentNode.Name; if (!string.IsNullOrEmpty(CurrentNode.Title)) { Text.SetAttribute("title", CurrentNode.Title); } html += Text.ToHtml() + "</div>"; if (HasChild) { string ss = ""; if (CurrentNode.Open) { ss = " style=\"display:block\""; } html += "<div class=\"TreeNodeChilds\" id=\"" + BaseId + "_TreeNodeChilds" + CurrentNode.Id + "\"" + ss + ">"; if (IsLastNode) { OtherImage.Src = BaseFolder + "tree/empty.gif"; } else { OtherImage.Src = BaseFolder + "tree/line.gif"; } prefix += OtherImage.ToHtml(); for (int i = 0; i < ChildList.Count; i++) { IsLastNode = (i == (ChildList.Count - 1)); html += RenderNode(prefix, (Level + 1), ChildList[i], IsLastNode); } html += "</div>"; } return(html); }