public static string RenderTemplate(HttpContext httpContext, GraffitiContext graffitiContext, string virtualPath) { try { return(TemplateEngine.Evaluate(LoadFile(httpContext.Server.MapPath(virtualPath)), graffitiContext)); } catch (Exception ex) { if (httpContext.Request.IsAuthenticated) { return(string.Format("<p>The view {0} (NOT THEMED) could not be rendered</p><p>{1}</p>", virtualPath, ex)); } else { return("Content could not be rendered"); } } }
public static string RenderTemplate(HttpContext httpContext, GraffitiContext graffitiContext, string theme, string file) { try { return(TemplateEngine.Evaluate(LoadFile(theme, file), graffitiContext)); } catch (Exception ex) { if (httpContext.Request.IsAuthenticated) { return(string.Format("<p>The view {0} ({2}) could not be rendered</p><p>{1}</p>", file, ex, theme)); } else { return("Content could not be rendered"); } } }
public static bool Send(EmailTemplate template) { Events.Instance().ExecuteBeforeEmailSent(template); string fileText = Util.GetFileText(HttpContext.Current.Server.MapPath("~/__utility/emails/" + template.TemplateName)); fileText = TemplateEngine.Evaluate(fileText, template.Context); using (MailMessage mm = new MailMessage(template.From ?? SiteSettings.Get().EmailFrom, template.To)) { mm.Subject = template.Subject; mm.IsBodyHtml = template.IsHTML; mm.Body = fileText; mm.Headers.Add("Reply-To", template.ReplyTo ?? template.From ?? SiteSettings.Get().EmailFrom); SendMailMessage(mm); } Events.Instance().ExecuteAfterEmailSent(template); return(true); }
public static bool Send(string templateFile, string emailTo, string subject, PageTemplateToolboxContext cntxt) { string fileText = Util.GetFileText(HttpContext.Current.Server.MapPath("~/__utility/emails/" + templateFile)); fileText = TemplateEngine.Evaluate(fileText, cntxt); SiteSettings settings = SiteSettings.Get(); using (MailMessage mm = new MailMessage(settings.EmailFrom, emailTo)) { mm.Subject = subject; mm.IsBodyHtml = true; mm.Body = fileText; SmtpClient client = new SmtpClient(); client.Host = settings.EmailServer; if (settings.EmailServerRequiresAuthentication) { client.Credentials = new NetworkCredential(settings.EmailUser, settings.EmailPassword); } if (settings.EmailRequiresSSL) { client.EnableSsl = true; } if (settings.EmailPort > 0) { client.Port = settings.EmailPort; } client.Send(mm); } return(true); }
public static void Write(string pageTemplateFile, string virtualPath, PageTemplateToolboxContext cntxt) { if (SiteSettings.Get().GenerateFolders) { string fileText = Util.GetFileText(HttpContext.Current.Server.MapPath("~/__utility/pages/" + pageTemplateFile)); //fileText = string.Format(fileText, list.ToArray()); fileText = TemplateEngine.Evaluate(fileText, cntxt); string absPath = HttpContext.Current.Server.MapPath(virtualPath); FileInfo fi = new FileInfo(absPath); if (!fi.Directory.Exists) { fi.Directory.Create(); } using (StreamWriter sw = new StreamWriter(absPath, false)) { sw.WriteLine(fileText); sw.Close(); } } }
/// <summary> /// Renders the contents of a view and a layout into the response stream /// </summary> public static void Render(HttpContext httpContext, GraffitiContext graffitiContext, string theme) { httpContext.Response.ClearContent(); try { graffitiContext["childContent"] = TemplateEngine.Evaluate(LoadFile(theme, graffitiContext.View), graffitiContext); } catch (DirectoryNotFoundException exDNF) { Log.Error("Site theme error", "The {0} theme seems to be missing. Graffiti CMS can not find a folder for that theme. Error details: {1}", theme, exDNF.Message); if (httpContext.Request.IsAuthenticated) { httpContext.Response.Write( string.Format( "<h1>The {0} theme seems to be missing</h1><p>Graffiti CMS can not find a folder for that theme. Please check your files or <a href=\"{2}\">select a different theme</a>.</p><p>Error Details: {1}</p>", theme, exDNF.Message, new Urls().Admin)); } else { httpContext.Response.Write( "<h1>Site Theme Error</h1><p>Please try again later or contact the site administrator.</p>"); } return; } catch (Exception ex) { Log.Error("Site view file rendering error", "The view {0} ({1}) could not be rendered. Error details: {2}", graffitiContext.View, theme, ex.Message); if (httpContext.Request.IsAuthenticated) { graffitiContext["childContent"] = string.Format("<p>The view {0} ({2}) could not be rendered</p><p>Error Details: {1}</p>", graffitiContext.View, ex, theme); } else { graffitiContext["childContent"] = "Content could not be rendered"; } } try { TemplateEngine.Evaluate(httpContext.Response.Output, LoadFile(theme, graffitiContext.Layout), graffitiContext); } catch (Exception ex) { Log.Error("Site layout rendering error", "The layout {0} ({1}) could not be rendered. Error details: {2}", graffitiContext.Layout, theme, ex.Message); if (httpContext.Request.IsAuthenticated) { httpContext.Response.Write( string.Format("<p>The layout {0} ({2}) could not be rendered</p><p>{1}</p>", graffitiContext.Layout, ex, theme)); } else { httpContext.Response.Write("<h1>Site Error</h1><p>Please try again later or contact the site administrator.</p>"); } } }