public static void Render(FrontContext context) { var script = context.SiteDb.Scripts.Get(context.Route.objectId); context.RenderContext.Response.ContentType = "application/javascript;charset=utf-8"; if (script != null && script.Body != null) { if (script.Extension == null || script.Extension == "js" || script.Extension == ".js") { context.RenderContext.Response.Body = Encoding.UTF8.GetBytes(script.Body); } else { var engines = Kooboo.Sites.Engine.Manager.GetScript(); var find = engines.Find(o => o.Extension == script.Extension); if (find != null) { var code = find.Execute(context.RenderContext, script.Body); context.RenderContext.Response.Body = Encoding.UTF8.GetBytes(code); } else { context.RenderContext.Response.Body = Encoding.UTF8.GetBytes(script.Body); } } } }
public static void VideoVersion(FrontContext context) { if (context.RenderContext.WebSite.EnableVideoBrowserCache) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } }
private static EvaluatorOption GetPageOption(FrontContext context) { EvaluatorOption renderoption = new EvaluatorOption(); if (context.WebSite != null && context.WebSite.EnableSitePath) { renderoption.RenderUrl = true; } else { renderoption.RenderUrl = false; } if (context.Page.Headers.HasValue()) { if (context.Page.HasLayout) { renderoption.RenderHeader = false; } else { renderoption.RenderHeader = true; } } else { renderoption.RenderHeader = false; } //renderoption.RenderHeader = context.Page.Headers.HasValue(); renderoption.RequireBindingInfo = context.RenderContext.Request.Channel == Data.Context.RequestChannel.InlineDesign; renderoption.OwnerObjectId = context.Page.Id; return(renderoption); }
private static string Getbody(FrontContext context, Models.Script script) { string result = null; if (script != null && script.Body != null) { if (script.Extension == null || script.Extension == "js" || script.Extension == ".js") { result = script.Body; } else { var engines = Kooboo.Sites.Engine.Manager.GetScript(); var find = engines.Find(o => o.Extension == script.Extension); if (find != null) { result = find.Execute(context.RenderContext, script.Body); } else { result = script.Body; } } } return(result); }
public static void RenderFile(FrontContext context, Models.CmsFile file) { string contentType; if (!string.IsNullOrEmpty(file.ContentType)) { contentType = file.ContentType; } else { contentType = IOHelper.MimeType(file.Name); } context.RenderContext.Response.ContentType = contentType; if (file.ContentBytes != null) { context.RenderContext.Response.Body = file.ContentBytes; } else if (!string.IsNullOrEmpty(file.ContentString)) { context.RenderContext.Response.Body = DataConstants.DefaultEncoding.GetBytes(file.ContentString); } // cache for font. if (contentType != null && contentType.ToLower().Contains("font")) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } }
public async static Task RenderAsync(FrontContext context) { var image = await context.SiteDb.ImagePool.GetAsync(context.Route.objectId); if (image == null || image.ContentBytes == null) { image = await context.SiteDb.Images.GetAsync(context.Route.objectId); } // var image = context.SiteDb.Images.Get(context.Route.objectId); if (context.RenderContext.WebSite.EnableImageLog) { if (context.RenderContext.Request.Channel == Data.Context.RequestChannel.Default) { Kooboo.Data.Models.ImageLog log = new Data.Models.ImageLog(); log.ClientIP = context.RenderContext.Request.IP; log.Url = context.RenderContext.Request.RawRelativeUrl; log.StartTime = DateTime.Now; if (image != null) { log.Size = image.Size; log.ImageId = image.Id; } context.RenderContext.WebSite.SiteDb().ImageLog.Add(log); } } if (image == null) { return; } RenderImage(context, image); }
public static void Render(FrontContext context) { var css = context.SiteDb.Styles.Get(context.Route.objectId); context.RenderContext.Response.ContentType = "text/css;charset=utf-8"; if (css != null && css.Body != null) { var body = GetBody(css); if (context.RenderContext.WebSite != null && context.RenderContext.WebSite.EnableJsCssCompress) { if (css != null) { body = CompressCache.Get(css.Id, css.Version, body, CompressType.css); } } TextBodyRender.SetBody(context, body); var version = context.RenderContext.Request.GetValue("version"); if (!string.IsNullOrWhiteSpace(version)) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } } }
public static void Render(FrontContext context) { var code = context.SiteDb.Code.Get(context.Route.objectId); if (code != null) { string result = string.Empty; if (code.IsJson) { result = code.Body; } else { result = Scripting.Manager.ExecuteCode(context.RenderContext, code.Body, code.Id); } context.RenderContext.Response.ContentType = "application/javascript"; if (code.Cors) { context.RenderContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); } if (!string.IsNullOrEmpty(result)) { context.RenderContext.Response.Body = Encoding.UTF8.GetBytes(result); } } else { context.RenderContext.Response.StatusCode = 404; } }
public static void Render(FrontContext context) { var css = context.SiteDb.Styles.Get(context.Route.objectId); context.RenderContext.Response.ContentType = "text/css;charset=utf-8"; if (css != null && css.Body != null) { var bytes = Encoding.UTF8.GetBytes(css.Body); //if (context.RenderContext.EnableTextGZip) //{ // context.RenderContext.Response.Headers.Add("Content-encoding", "GZip"); // context.RenderContext.Response.OrginalLength = bytes.Length; // var stream = new System.IO.MemoryStream(bytes); //context.RenderContext.Response.Stream = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionLevel.Fastest); //} //else //{ // var body = GetBody(css); context.RenderContext.Response.Body = bytes; // } } }
public static EvaluatorOption GetPageOption(FrontContext context) { EvaluatorOption renderoption = new EvaluatorOption(); if (context.Page.Headers.HasValue()) { if (context.Page.HasLayout) { renderoption.RenderHeader = false; } else { renderoption.RenderHeader = true; } } else { renderoption.RenderHeader = false; } renderoption.OwnerObjectId = context.Page.Id; SetOption(renderoption, context.RenderContext); return(renderoption); }
public static void Render(FrontContext context) { var script = context.SiteDb.Scripts.Get(context.Route.objectId); context.RenderContext.Response.ContentType = "application/javascript;charset=utf-8"; string result = Getbody(context, script); if (context.RenderContext.WebSite != null && context.RenderContext.WebSite.EnableJsCssCompress) { if (script != null) { result = CompressCache.Get(script.Id, script.Version, result, CompressType.js); } } TextBodyRender.SetBody(context, result); var version = context.RenderContext.Request.GetValue("version"); if (!string.IsNullOrWhiteSpace(version)) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } }
public static async Task <string> RenderMockAsync(RenderContext context, Page page) { FrontContext frontcontext = new FrontContext(context); frontcontext.Page = page; context.MockData = true; return(await RenderEngine.RenderMockPageAsync(frontcontext)); }
public byte[] GetContentBytes(FrontContext context, Models.Image image) { if (image.ContentBytes == null) { var sitedb = context.RenderContext.WebSite.SiteDb(); } return(image.ContentBytes); }
public static void ScriptStyleVersion(FrontContext context) { var version = context.RenderContext.Request.GetValue("version"); if (!string.IsNullOrWhiteSpace(version)) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } }
public static void Render(FrontContext context) { var start = System.DateTime.Now; var code = context.SiteDb.Code.Get(context.Route.objectId); if (code != null) { string result = string.Empty; var enableCORS = context?.WebSite?.EnableCORS ?? false; if (code.IsJson) { result = code.Body; } else if (CorsHelper.IsOptionsRequest(context) && enableCORS) { result = ""; } else { result = Scripting.Manager.ExecuteCode(context.RenderContext, code.Body, code.Id); } //context.RenderContext.Response.ContentType = "application/javascript"; if (code.Cors || enableCORS) { CorsHelper.HandleHeaders(context); } if (!string.IsNullOrEmpty(result)) { context.RenderContext.Response.Body = Encoding.UTF8.GetBytes(result); } } else { context.RenderContext.Response.StatusCode = 404; } if (context.WebSite.EnableVisitorLog) { string detail = ""; if (context.RenderContext.Request.Body != null) { detail = context.RenderContext.Request.Body; } context.Log.AddEntry("API call", context.RenderContext.Request.RawRelativeUrl, start, System.DateTime.Now, (short)context.RenderContext.Response.StatusCode, detail); context.Page = new Models.Page() { Name = "system api page" }; } }
//public static void Render(FrontContext context) //{ // var image = context.SiteDb.ImagePool.Get(context.Route.objectId); // if (image == null || image.ContentBytes == null) // { // image = context.SiteDb.Images.Get(context.Route.objectId); // } // if (context.RenderContext.WebSite.EnableImageLog) // { // if (context.RenderContext.Request.Channel == Data.Context.RequestChannel.Default) // { // Kooboo.Data.Models.ImageLog log = new Data.Models.ImageLog(); // log.ClientIP = context.RenderContext.Request.IP; // log.Url = context.RenderContext.Request.RawRelativeUrl; // log.StartTime = DateTime.Now; // if (image != null) // { // log.Size = image.Size; // log.ImageId = image.Id; // } // context.RenderContext.WebSite.SiteDb().ImageLog.Add(log); // } // } // if (image == null) // { // return; // } // RenderImage(context, image); //} public static void RenderImage(FrontContext context, Models.Image image) { context.RenderContext.Response.ContentType = "image"; if (Kooboo.Lib.Helper.UrlHelper.GetFileType(image.Extension) == Lib.Helper.UrlHelper.UrlFileType.Image) { string imagetype = image.Extension; if (imagetype.StartsWith(".")) { imagetype = imagetype.Substring(1); } context.RenderContext.Response.ContentType = context.RenderContext.Response.ContentType + "/" + imagetype; } //"image/svg+xml" if (image.Extension == "svg" || image.Extension == ".svg") { context.RenderContext.Response.ContentType += "+xml"; } var bytes = image.ContentBytes; var width = context.RenderContext.Request.Get("width"); if (!string.IsNullOrEmpty(width)) { var height = context.RenderContext.Request.Get("height"); if (!string.IsNullOrWhiteSpace(height)) { int intwidth = 0; int intheight = 0; if (int.TryParse(width, out intwidth) && int.TryParse(height, out intheight)) { bytes = GetImageThumbnail(context.RenderContext, bytes, intwidth, intheight, image.Version); } } else { int intwidth = 0; if (int.TryParse(width, out intwidth)) { if (image.Height > 0 && image.Width > 0) { int intheight = (int)intwidth * image.Height / image.Width; bytes = GetImageThumbnail(context.RenderContext, bytes, intwidth, intheight, image.Version); } } } } context.RenderContext.Response.Body = bytes; }
public static async Task RenderAsync(FrontContext context) { var file = context.SiteDb.Files.Get(context.Route.objectId, true); if (file == null) { return; } await RenderFile(context, file); }
public static async Task RenderAsync(FrontContext context) { var file = await context.SiteDb.FilePool.GetAsync(context.Route.objectId); if (file == null) { return; } RenderFile(context, file); }
public static void Render(FrontContext context) { var script = context.SiteDb.Scripts.Get(context.Route.objectId); context.RenderContext.Response.ContentType = "application/javascript;charset=utf-8"; string result = Getbody(context, script); TextBodyRender.SetBody(context, result); }
public static void RenderFile(FrontContext context, Models.CmsFile file) { string contentType; if (!string.IsNullOrEmpty(file.ContentType)) { contentType = file.ContentType; } else { contentType = IOHelper.MimeType(file.Name); } context.RenderContext.Response.ContentType = contentType; if (file.ContentBytes != null) { context.RenderContext.Response.Body = file.ContentBytes; } else if (!string.IsNullOrEmpty(file.ContentString)) { context.RenderContext.Response.Body = DataConstants.DefaultEncoding.GetBytes(file.ContentString); } // cache for font. if (contentType != null) { if (contentType.ToLower().Contains("font")) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } else if (contentType.ToLower().Contains("image")) { context.RenderContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); context.RenderContext.Response.Headers.Add("Access-Control-Allow-Headers", "*"); if (context.RenderContext.WebSite.EnableImageBrowserCache) { if (context.RenderContext.WebSite.ImageCacheDays > 0) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddDays(context.RenderContext.WebSite.ImageCacheDays).ToString("r"); } else { // double verify... var version = context.RenderContext.Request.GetValue("version"); if (!string.IsNullOrWhiteSpace(version)) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } } } } } }
public async static Task RenderAsync(FrontContext context) { var image = await context.SiteDb.ImagePool.GetAsync(context.Route.objectId); if (image == null || image.ContentBytes == null) { image = await context.SiteDb.Images.GetAsync(context.Route.objectId); } //var image = context.SiteDb.Images.Get(context.Route.objectId); if (context.RenderContext.WebSite.EnableImageLog) { if (context.RenderContext.Request.Channel == Data.Context.RequestChannel.Default) { Kooboo.Data.Models.ImageLog log = new Data.Models.ImageLog(); log.ClientIP = context.RenderContext.Request.IP; log.Url = context.RenderContext.Request.RawRelativeUrl; log.StartTime = DateTime.Now; if (image != null) { log.Size = image.Size; log.ImageId = image.Id; } context.RenderContext.WebSite.SiteDb().ImageLog.Add(log); } } if (image == null) { return; } RenderImage(context, image); context.RenderContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); context.RenderContext.Response.Headers.Add("Access-Control-Allow-Headers", "*"); if (context.RenderContext.WebSite.EnableImageBrowserCache) { if (context.RenderContext.WebSite.ImageCacheDays > 0) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddDays(context.RenderContext.WebSite.ImageCacheDays).ToString("r"); } else { // double verify... var version = context.RenderContext.Request.GetValue("version"); if (!string.IsNullOrWhiteSpace(version)) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } } } }
public static void Render(FrontContext context) { var file = context.SiteDb.Files.Get(context.Route.objectId); if (file == null) { return; } RenderFile(context, file); }
public static void Render(FrontContext context) { var css = context.SiteDb.Styles.Get(context.Route.objectId); context.RenderContext.Response.ContentType = "text/css;charset=utf-8"; if (css != null && css.Body != null) { // var body = GetBody(css); context.RenderContext.Response.Body = Encoding.UTF8.GetBytes(css.Body); } }
public static async Task <string> RenderPageAsync(FrontContext context) { if (context.Page.Parameters.Count > 0) { context.RenderContext.DataContext.Push(context.Page.Parameters); } string result = string.Empty; List <IRenderTask> RenderPlan = null; var option = RenderOptionHelper.GetPageOption(context); if (option.RequireBindingInfo) { string html = DomService.ApplyKoobooId(context.Page.Body); RenderPlan = RenderEvaluator.Evaluate(html, option); var traceability = new ComponentTrace(context.Page.Id.ToString(), "page"); var bindingTask = new BindingRenderTask(traceability, new Dictionary <string, string> { { "scope", "true" } }); RenderPlan.Insert(0, bindingTask); RenderPlan.Add(bindingTask.BindingEndRenderTask); result = RenderHelper.Render(RenderPlan, context.RenderContext); result = DomService.EnsureDocType(result); } else { RenderPlan = Cache.RenderPlan.GetOrAddRenderPlan(context.SiteDb, context.Page.Id, () => RenderEvaluator.Evaluate(context.Page.Body, option)); result = RenderHelper.Render(RenderPlan, context.RenderContext); } if (context.Page.Type == Models.PageType.RichText) { //special for richtext editor. meta name = "viewport" content = "width=device-width, initial-scale=1" var header = new Models.HtmlHeader(); Dictionary <string, string> content = new Dictionary <string, string>(); content.Add("", "width=device-width, initial-scale=1"); header.Metas.Add(new Models.HtmlMeta() { name = "viewport", content = content }); result = HtmlHeadService.SetHeaderToHtml(result, header); } return(result); }
public static async Task RenderAsync(FrontContext context) { // fire Page Event. . Page page = null; if (context.RenderContext.WebSite.EnableFrontEvents && context.RenderContext.IsSiteBinding) { page = FrontEvent.Manager.RaisePageEvent(FrontEvent.enumEventType.PageFinding, context.RenderContext); if (page == null) { page = context.SiteDb.Pages.Get(context.Route.objectId); if (page != null) { var changepage = FrontEvent.Manager.RaisePageEvent(FrontEvent.enumEventType.PageFound, context.RenderContext, page); if (changepage != null) { page = changepage; } } else { // page = FrontEvent.Manager.RaisePageEvent(FrontEvent.enumEventType.PageNotFound, context.RenderContext); } } } context.Page = page != null? page: context.SiteDb.Pages.Get(context.Route.objectId); string html = null; if (context.Page != null) { html = await RenderEngine.RenderPageAsync(context); } if (!string.IsNullOrEmpty(html)) { var bytes = Encoding.UTF8.GetBytes(html); context.RenderContext.Response.Body = bytes; } else { context.RenderContext.Response.Body = new byte[0]; } }
public static async Task <string> RenderPageAsync(FrontContext context) { if (context.Page.Parameters.Count > 0) { context.RenderContext.DataContext.Push(context.Page.Parameters); } string result = string.Empty; List <IRenderTask> RenderPlan = null; if (context.RenderContext.Request.Channel != Data.Context.RequestChannel.InlineDesign) { RenderPlan = Cache.RenderPlan.GetOrAddRenderPlan(context.SiteDb, context.Page.Id, () => RenderEvaluator.Evaluate(context.Page.Body, GetPageOption(context))); result = RenderHelper.Render(RenderPlan, context.RenderContext); } else { string html = DomService.ApplyKoobooId(context.Page.Body); RenderPlan = RenderEvaluator.Evaluate(html, GetPageOption(context)); RenderPlan.Insert(0, new BindingObjectRenderTask() { ObjectType = "page", NameOrId = context.Page.Id.ToString() }); result = RenderHelper.Render(RenderPlan, context.RenderContext); result = DomService.EnsureDocType(result); } if (context.Page.Type == Models.PageType.RichText) { //special for richtext editor. meta name = "viewport" content = "width=device-width, initial-scale=1" var header = new Models.HtmlHeader(); Dictionary <string, string> content = new Dictionary <string, string>(); content.Add("", "width=device-width, initial-scale=1"); header.Metas.Add(new Models.HtmlMeta() { name = "viewport", content = content }); result = HtmlHeadService.SetHeaderToHtml(result, header); } return(result); }
public static void ImageVersion(FrontContext context) { if (context.RenderContext.WebSite.EnableImageBrowserCache) { if (context.RenderContext.WebSite.ImageCacheDays > 0) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddDays(context.RenderContext.WebSite.ImageCacheDays).ToString("r"); } else { // double verify... var version = context.RenderContext.Request.GetValue("version"); if (!string.IsNullOrWhiteSpace(version)) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } } } }
public async static void Render(FrontContext context) { Components.ComponentSetting setting = new Components.ComponentSetting(); setting.TagName = "view"; setting.NameOrId = context.Route.objectId.ToString(); var ViewComponent = Components.Container.Get("view"); string viewresult = null; if (ViewComponent != null) { viewresult = await ViewComponent.RenderAsync(context.RenderContext, setting); } if (!string.IsNullOrEmpty(viewresult)) { context.RenderContext.Response.Body = Encoding.UTF8.GetBytes(viewresult); } }
public static void Render(FrontContext context) { var script = context.SiteDb.Scripts.Get(context.Route.objectId); context.RenderContext.Response.ContentType = "application/javascript;charset=utf-8"; string result = Getbody(context, script); if (context.RenderContext.WebSite != null && context.RenderContext.WebSite.EnableJsCssCompress) { if (script != null) { result = CompressCache.Get(script.Id, script.Version, result, CompressType.js); } } TextBodyRender.SetBody(context, result); VersionRenderer.ScriptStyleVersion(context); }
public static void Render(FrontContext context) { var css = context.SiteDb.Styles.Get(context.Route.objectId); context.RenderContext.Response.ContentType = "text/css;charset=utf-8"; if (css != null && css.Body != null) { var body = GetBody(context.RenderContext, css); if (context.RenderContext.WebSite != null && context.RenderContext.WebSite.EnableJsCssCompress) { if (css != null) { body = CompressCache.Get(css.Id, css.Version, body, CompressType.css); } } TextBodyRender.SetBody(context, body); VersionRenderer.ScriptStyleVersion(context); } }