public Core.Entities.Menu.ThemeTemplateResponse Render(Dictionary <string, string> Attributes) { Core.Entities.Menu.ThemeTemplateResponse response = new Core.Entities.Menu.ThemeTemplateResponse(); string blockguid = Attributes["data-guid"]; Core.Data.Entities.CustomBlock block = Core.Managers.BlockManager.GetAll(PortalSettings.Current).Where(c => c.Guid.ToLower() == blockguid.ToLower()).FirstOrDefault(); if (block != null) { response.Markup = block.Html; response.Style = block.Css; } return(response); }
internal static HttpResponseMessage Export(int PortalID, string Name) { HttpResponseMessage Response = new HttpResponseMessage(); ExportTemplate exportTemplate = new ExportTemplate { Guid = Guid.NewGuid().ToString(), Type = TemplateType.SiteTemplate.ToString(), UpdatedOn = DateTime.UtcNow, Templates = new List <Layout>() }; Dictionary <string, string> Assets = new Dictionary <string, string>(); foreach (Core.Data.Entities.Pages page in Core.Managers.PageManager.GetAllPublishedPages(PortalID, null)) { Dnn.PersonaBar.Pages.Services.Dto.PageSettings pageSettings = Dnn.PersonaBar.Pages.Components.PagesController.Instance.GetPageSettings(page.TabID); Layout layout = new Layout { Content = Core.Managers.PageManager.TokenizeTemplateLinks(page.Content, false, Assets) }; HtmlDocument html = new HtmlDocument(); html.LoadHtml(layout.Content); IEnumerable <HtmlNode> query = html.DocumentNode.Descendants("div"); foreach (HtmlNode item in query.ToList()) { if (item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault() != null && !string.IsNullOrEmpty(item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault().Value) && item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault().Value.ToLower() == "global") { string guid = item.Attributes.Where(a => a.Name == "data-guid").FirstOrDefault().Value.ToLower(); Core.Data.Entities.CustomBlock Block = Core.Managers.BlockManager.GetByLocale(PortalID, guid, null); if (Block != null) { if (layout.Blocks == null) { layout.Blocks = new List <Core.Data.Entities.CustomBlock>(); } layout.Blocks.Add(Block); } } } layout.Name = pageSettings.Name; layout.Content = html.DocumentNode.OuterHtml; layout.SVG = ""; layout.ContentJSON = Core.Managers.PageManager.TokenizeTemplateLinks(page.ContentJSON, true, Assets); layout.Style = page.Style; layout.StyleJSON = page.StyleJSON; layout.Type = pageSettings.PageType = pageSettings.PageType.ToLower() == "url" ? "URL" : (pageSettings.DisableLink && pageSettings.IncludeInMenu) ? "Folder" : "Standard"; exportTemplate.Templates.Add(layout); } string serializedExportTemplate = JsonConvert.SerializeObject(exportTemplate); if (!string.IsNullOrEmpty(serializedExportTemplate)) { byte[] fileBytes = null; using (MemoryStream memoryStream = new MemoryStream()) { using (ZipArchive zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { AddZipItem("ExportTemplate.json", Encoding.ASCII.GetBytes(serializedExportTemplate), zip); //AddZipItem(ScreenShotFileInfo.FileName, ToByteArray(FileManager.Instance.GetFileContent(ScreenShotFileInfo)), zip); if (Assets != null && Assets.Count > 0) { foreach (KeyValuePair <string, string> asset in Assets) { string FileName = asset.Key.Replace(Vanjaro.Core.Managers.PageManager.ExportTemplateRootToken, ""); string FileUrl = asset.Value; if (FileUrl.StartsWith("/")) { FileUrl = string.Format("{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority, FileUrl); } AddZipItem("Assets/" + FileName, new WebClient().DownloadData(FileUrl), zip); } } string Theme = Core.Managers.ThemeManager.GetCurrentThemeName(); if (!string.IsNullOrEmpty(Theme)) { PortalInfo portalInfo = PortalController.Instance.GetPortal(PortalID); string FolderPath = HttpContext.Current.Server.MapPath("~/Portals/_default/vThemes/" + Theme + "/editor"); if (Directory.Exists(FolderPath)) { foreach (string file in Directory.EnumerateFiles(FolderPath, "*", SearchOption.AllDirectories)) { AddZipItem("Theme/editor" + file.Replace(FolderPath, "").Replace("\\", "/"), File.ReadAllBytes(file), zip); } } FolderPath = HttpContext.Current.Server.MapPath("~/Portals/_default/vThemes/" + Theme + "/scss"); if (Directory.Exists(FolderPath)) { foreach (string file in Directory.EnumerateFiles(FolderPath)) { AddZipItem("Theme/scss" + file.Replace(FolderPath, "").Replace("\\", "/"), File.ReadAllBytes(file), zip); } } if (File.Exists(HttpContext.Current.Server.MapPath("~/Portals/_default/vThemes/" + Theme + "/theme.editor.custom.json"))) { AddZipItem("Theme/theme.editor.custom.json", File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/Portals/_default/vThemes/" + Theme + "/theme.editor.custom.json")), zip); } } } fileBytes = memoryStream.ToArray(); } string fileName = Name + "_SiteTemplate.zip"; Response.Content = new ByteArrayContent(fileBytes.ToArray()); Response.Content.Headers.Add("x-filename", fileName); Response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); Response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; Response.StatusCode = HttpStatusCode.OK; } return(Response); }