private static void ParseLayoutFile(IXmlPageTemplate pageTemplate, out PlaceholderDescriptor[] placeholders, out string defaultPlaceholder) { var placeholdersInfo = TemplateInfo.GetRenderingPlaceHolders(pageTemplate.Id); defaultPlaceholder = placeholdersInfo.DefaultPlaceholderId; placeholders = placeholdersInfo .Placeholders .Select(pair => new PlaceholderDescriptor { Id = pair.Key, Title = pair.Value }) .ToArray(); }
public string SavePageContent(string pageId, string placeholderId, string content) { Guid pageGuid = Guid.Parse(pageId); string contentHtml = HttpUtility.UrlDecode(content); contentHtml = HttpUtility.HtmlDecode(contentHtml.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;")); string xhtmlDocumentWrapper = string.Format("<html xmlns='http://www.w3.org/1999/xhtml'><head></head><body>{0}</body></html>", contentHtml); XElement xElement = XElement.Parse(xhtmlDocumentWrapper); RemoveInvalidElements(xElement); contentHtml = string.Concat((xElement.Elements().Select(b => b.ToString())).ToArray()); foreach (PublicationScope scope in Enum.GetValues(typeof(PublicationScope))) { using (DataConnection connection = new DataConnection(scope)) { var phHolder = Composite.Data.PageManager.GetPlaceholderContent(pageGuid).Where(ph => ph.PlaceHolderId == placeholderId).SingleOrDefault(); if (phHolder != null) { phHolder.Content = contentHtml; connection.Update <IPagePlaceholderContent>(phHolder); } else { var page = connection.Get <IPage>().Where(p => p.Id == pageGuid).SingleOrDefault(); var templateInfo = TemplateInfo.GetRenderingPlaceHolders(page.TemplateId); foreach (var ph in templateInfo.Placeholders) { if (ph.Key == placeholderId) { IPagePlaceholderContent newPh = connection.CreateNew <IPagePlaceholderContent>(); newPh.PageId = pageGuid; newPh.PlaceHolderId = placeholderId; newPh.Content = contentHtml; connection.Add <IPagePlaceholderContent>(newPh); } } } } } return("Success"); }