protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { var positionType = controllerContext.HttpContext.Request["PositionType"]; object model = null; switch (positionType) { case "View": model = new ViewPosition(); break; case "Module": model = new ModulePosition(); break; case "Content": model = new HtmlPosition(); break; default: break; } bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType()); return(model); }
public virtual ActionResult ProcessHtml(HtmlPosition pos) { if (IsGet()) { return(View()); } return(Json(new { html = new PageDesignHtmlContent(pos).ToHtmlString() })); }
public Search.Models.IndexObject GetIndexObject(object o) { IndexObject indexObject = null; Page page = (Page)o; NameValueCollection storeFields = new NameValueCollection(); NameValueCollection sysFields = new NameValueCollection(); sysFields.Add("SiteName", page.Site.FullName); sysFields.Add("PageName", page.FullName); string title = ""; StringBuilder body = new StringBuilder(); if (page.HtmlMeta != null && !string.IsNullOrEmpty(page.HtmlMeta.HtmlTitle)) { title = page.HtmlMeta.HtmlTitle; } if (!string.IsNullOrEmpty(page.ContentTitle)) { body.AppendFormat(title); title = page.ContentTitle; } if (page.PagePositions != null) { foreach (var item in page.PagePositions.Where(it => (it is HtmlBlockPosition) || (it is HtmlPosition))) { if (item is HtmlBlockPosition) { HtmlBlockPosition htmlBlockPosition = (HtmlBlockPosition)item; var htmlBlock = new HtmlBlock(page.Site, htmlBlockPosition.BlockName).LastVersion().AsActual(); if (htmlBlock != null) { body.Append(" " + Kooboo.Extensions.StringExtensions.StripAllTags(htmlBlock.Body)); } } else { HtmlPosition htmlPosition = (HtmlPosition)item; body.Append(" " + Kooboo.Extensions.StringExtensions.StripAllTags(htmlPosition.Html)); } } } indexObject = new IndexObject() { Title = title, Body = body.ToString(), StoreFields = storeFields, SystemFields = sysFields, NativeType = typeof(Page).AssemblyQualifiedNameWithoutVersion() }; return(indexObject); }
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)); }
public PageDesignHtmlContent(HtmlPosition pos) : base(pos) { // html this.Parameter.Add("Html", PageDesignContent.Code(pos.Html)); // name var name = HttpUtility.UrlDecode(pos.Html).StripAllTags().Trim(); name = System.Text.RegularExpressions.Regex.Replace(name, "\\s+", " "); if (name.Length > 10) { name = name.Substring(0, 7) + "..."; } this.Parameter["Name"] = PageDesignContent.Code("Html:" + name); }
// public method public static List <PagePosition> ParsePagePositions(string clientJson) { clientJson = HttpUtility.UrlDecode(clientJson); var positions = new List <PagePosition>(); var list = ParseJson <List <Dictionary <string, object> > >(clientJson); foreach (var item in list) { PagePosition pos = null; var t = item.Str("Type"); if (t == PageDesignViewContent.TypeKey) { pos = new ViewPosition() { ViewName = item.Str("ViewName"), Parameters = ParseViewParameters(item.Str("Parameters")), OutputCache = ParseJson <CacheSettings>(item.Str("OutputCache")) }; } else if (t == PageDesignModuleContent.TypeKey) { pos = new ModulePosition() { ModuleName = item.Str("ModuleName"), Exclusive = (item.Str("Exclusive") == "true"), Entry = ParseModuleEntry(item.Str("EntryAction"), item.Str("EntryController")) }; } else if (t == PageDesignFolderContent.TypeKey) { pos = new ContentPosition() { Type = ParseEnum <ContentPositionType>(item.Str("ContentPositionType")), DataRule = ParseJson <FolderDataRule>(item.Str("DataRule")) }; } else if (t == PageDesignHtmlContent.TypeKey) { pos = new HtmlPosition() { Html = item.Str("Html") }; } else if (t == PageDesignHtmlBlockContent.TypeKey) { pos = new HtmlBlockPosition() { BlockName = item.Str("BlockName") }; } // add if (pos != null) { pos.LayoutPositionId = item.Str("LayoutPositionId"); pos.PagePositionId = item.Str("PagePositionId"); pos.Order = item.Int("Order"); positions.Add(pos); } } // ret return(positions); }
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); }
// public method public static List <PagePosition> ParsePagePositions(string clientJson) { clientJson = HttpUtility.UrlDecode(clientJson); var positions = new List <PagePosition>(); var list = ParseJson <List <Dictionary <string, object> > >(clientJson); foreach (var item in list) { PagePosition pos = null; var t = item.Str("Type"); if (t == PageDesignViewContent.TypeKey) { bool skipError = false; bool.TryParse(item.Str("SkipError"), out skipError); pos = new ViewPosition() { ViewName = item.Str("ViewName"), SkipError = skipError, Parameters = ParseViewParameters(item.Str("Parameters")), OutputCache = ParseJson <CacheSettings>(item.Str("OutputCache")) }; } else if (t == PageDesignModuleContent.TypeKey) { bool skipError = false; bool.TryParse(item.Str("SkipError"), out skipError); pos = new ModulePosition() { ModuleName = item.Str("ModuleName"), SkipError = skipError, Exclusive = (item.Str("Exclusive") == "true"), Entry = ParseModuleEntry(item) }; } else if (t == PageDesignFolderContent.TypeKey) { pos = new ContentPosition() { Type = ParseEnum <ContentPositionType>(item.Str("ContentPositionType")), DataRule = ParseJson <FolderDataRule>(item.Str("DataRule")) }; } else if (t == PageDesignHtmlContent.TypeKey) { pos = new HtmlPosition() { Html = item.Str("Html") }; } else if (t == PageDesignHtmlBlockContent.TypeKey) { pos = new HtmlBlockPosition() { BlockName = item.Str("BlockName") }; } else if (t == PageDesignProxyContent.TypeKey) { pos = new ProxyPosition() { Host = item.Str("Host"), RequestPath = item.Str("RequestPath"), NoProxy = item.Str("NoProxy") == "true", //ProxyStylesheet = item.Str("ProxyStylesheet") == "true", OutputCache = ParseJson <CacheSettings>(item.Str("OutputCache")) }; } // add if (pos != null) { pos.LayoutPositionId = item.Str("LayoutPositionId"); pos.PagePositionId = item.Str("PagePositionId"); pos.Order = item.Int("Order"); positions.Add(pos); } } // ret return(positions); }