protected virtual IHtmlString RenderHtmlPosition(HtmlPosition htmlPosition) { string html = htmlPosition.Html; if (PageContext.EnabledInlineEditing(EditingType.Page) && PageContext.PageRequestContext.Page.IsLocalized(PageContext.PageRequestContext.Site)) { if (PageContext.PageRequestContext.Page.Published.Value == false || (PageContext.PageRequestContext.Page.Published.Value == true && ServiceFactory.UserManager.Authorize(PageContext.PageRequestContext.Site, PageContext.ControllerContext.HttpContext.User.Identity.Name, Kooboo.CMS.Account.Models.Permission.Sites_Page_PublishPermission))) { html = string.Format("<var start=\"true\" editType=\"html\" dataType=\"{0}\" positionId=\"{1}\" positionName=\"{2}\" style=\"display:none;\"></var>{3}<var end=\"true\" style=\"display:none;\"></var>", FieldDataType.RichText.ToString(), htmlPosition.PagePositionId, HttpUtility.HtmlAttributeEncode(htmlPosition.ToString()), html); } } return(new HtmlString(html)); }
private void checkHtml() { string html = getHtmlFormWeb(); StringReader strReader = new StringReader(html); StringBuilder chlResult = new StringBuilder(); //資料分析 Dictionary <String, StringBuilder> result = new Dictionary <string, StringBuilder>(); //<Title, Desc> HtmlPosition position = HtmlPosition.Undefined; HtmlPosition prevPosition = HtmlPosition.Undefined; //Para if (checkExist(txt_URL.Text, new List <string>() { "?", "&" }, CheckType.IncludeAll)) { List <string> data = txt_URL.Text.Split('?')[1].Split('&').ToList(); muchData = data.Count() > 5; foreach (string date in data) { addContent(ref result, "Url Data", date); } } while (true) { //Read By Line string currrentTxt = strReader.ReadLine(); if (currrentTxt == null) { break; } else if (!string.IsNullOrWhiteSpace(currrentTxt)) { #region - Check - //Position if (checkExist(currrentTxt, new List <string>() { "<head>" }, CheckType.Exist)) { position = HtmlPosition.Header; } else if (checkExist(currrentTxt, new List <string>() { "<body>" }, CheckType.Exist)) { position = HtmlPosition.Body; } else if (checkExist(currrentTxt, new List <string>() { "<script" }, CheckType.Exist)) { prevPosition = position; position = HtmlPosition.Script; } else if (checkExist(currrentTxt, new List <string>() { "</script>" }, CheckType.Exist)) { position = prevPosition; } //Canonical if (checkExist(currrentTxt, new List <string>() { "link", "rel", "canonical" }, CheckType.IncludeAll)) { string key = "Canonical"; addContent(ref result, key, currrentTxt); hasCanonical = true; } //Title if (position == HtmlPosition.Header && checkExist(currrentTxt, new List <string>() { "<title>" }, CheckType.Exist)) { string[] httpString = currrentTxt.Split(new string[] { "<title>" }, StringSplitOptions.None); result.Add("Title", new StringBuilder().AppendLine(httpString[1].Split(new string[] { "</title>" }, StringSplitOptions.None)[0])); } //Descriptions if (checkExist(currrentTxt, new List <string>() { "Description" }, CheckType.Exist)) { string key = string.Concat(position.ToString(), " ", "Description"); addContent(ref result, key, currrentTxt); } //Http if (checkExist(currrentTxt, new List <string>() { "http:" }, CheckType.Exist)) { string key = "Http Content"; string[] httpString = currrentTxt.Split(new string[] { "http:" }, StringSplitOptions.None); for (int i = 1; i < httpString.Length; i++) { addContent(ref result, key, string.Concat("http:", httpString[i].Split('"')[0])); } hasHttp = true; } //Image if (checkExist(currrentTxt, new List <string>() { "<img" }, CheckType.Exist)) { string key = "Images"; string[] img = currrentTxt.Split(new string[] { "src=\"" }, StringSplitOptions.None); for (int i = 1; i < img.Length; i++) { addContent(ref result, key, img[i].Split('"')[0]); } } //Link if (checkExist(currrentTxt, new List <string>() { "<a href" }, CheckType.Exist)) { string key = "Links"; string[] link = currrentTxt.Split(new string[] { "href=\"" }, StringSplitOptions.None); for (int i = 1; i < link.Length; i++) { string linkurl = link[i].Split('"')[0]; string linkdesc = string.Empty; string[] linkdescs = link[i].Split(new string[] { "title=" }, StringSplitOptions.None); if (linkdescs.Length == 1) { if (checkExist(currrentTxt, new List <string>() { "<", ">" }, CheckType.IncludeAll)) { linkdesc = linkdescs[0].Split('>')[1].Split('<')[0]; } } else { linkdesc = linkdescs[1].Split('"')[1]; } if (string.IsNullOrWhiteSpace(linkdesc)) { addContent(ref result, key, link[i].Split('"')[0]); } else { addContent(ref result, key, string.Concat("[", linkdesc, "]", link[i].Split('"')[0])); } } } #endregion } } printout(result); }