protected override void LoadContent(GraffitiContext graffitiContext) { graffitiContext["where"] = "post"; Post post = Post.GetCachedPost(PostId); if (post.IsDeleted || (!post.IsPublished && GraffitiUsers.Current == null)) { RedirectTo(new Urls().Home); } else if (PostName != null && CategoryName != null && (!Util.AreEqualIgnoreCase(PostName, post.Name) || !Util.AreEqualIgnoreCase(CategoryName, post.Category.LinkName))) { RedirectTo(post.Url); } else if (Context.Request.Cookies["Graffiti-Post-" + PostId] == null) { Post.UpdateViewCount(PostId); //SPs.UpdatePostView(PostId).Execute(); HttpCookie cookie = new HttpCookie("Graffiti-Post-" + PostId, PostId.ToString()); Context.Response.Cookies.Add(cookie); } graffitiContext["title"] = post.Title + " : " + SiteSettings.Get().Title; graffitiContext["category"] = post.Category; graffitiContext["post"] = post; graffitiContext.RegisterOnRequestDelegate("feedback", GetPostFeedback); graffitiContext.RegisterOnRequestDelegate("comments", GetPostComments); graffitiContext.RegisterOnRequestDelegate("trackbacks", GetPostTrackbacks); }
private GraffitiContext(HttpContext context) { _context = context; atc = ToolboxManager.GetApplicationToolbox(); currentContext = this; }
/// <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>"); } }
protected override void LoadContent(GraffitiContext graffitiContext) { IsIndexable = false; graffitiContext["where"] = "category"; Category category = new CategoryController().GetCachedCategory(CategoryID, false); if(CategoryName != null && !Util.AreEqualIgnoreCase(CategoryName,category.LinkName)) { RedirectTo(category.Url); } graffitiContext["title"] = category.Name + " : " + SiteSettings.Get().Title; graffitiContext["category"] = category; graffitiContext.RegisterOnRequestDelegate("posts", GetCategoryPosts); // GetCategoryPosts needs to be called so the pager works GetCategoryPosts("posts", graffitiContext); }
protected virtual object GetCategoryPosts(string key, GraffitiContext graffitiContext) { Category category = new CategoryController().GetCachedCategory(CategoryID, false); int pageSize = SiteSettings.Get().PageSize; PostCollection pc = ZCache.Get<PostCollection>(string.Format(CacheKey, PageIndex, CategoryID, category.SortOrder, pageSize)); if (pc == null) { pc = new PostCollection(); Query q = PostCollection.DefaultQuery(PageIndex, pageSize, category.SortOrder); if (Category.IncludeChildPosts) { if (category.ParentId > 0) q.AndWhere(Post.Columns.CategoryId, CategoryID); else { List<int> ids = new List<int>(category.Children.Count + 1); foreach (Category child in category.Children) ids.Add(child.Id); ids.Add(category.Id); q.AndInWhere(Post.Columns.CategoryId, ids.ToArray()); } } else { q.AndWhere(Post.Columns.CategoryId, CategoryID); } pc.LoadAndCloseReader(q.ExecuteReader()); ZCache.InsertCache(string.Format(CacheKey, PageIndex, CategoryID, category.SortOrder, pageSize), pc, 60); } graffitiContext.TotalRecords = category.PostCount; graffitiContext.PageIndex = PageIndex; graffitiContext.PageSize = SiteSettings.Get().PageSize; return pc; }
public static void Unload() { currentContext = null; }
public static GraffitiContext Create(HttpContext context) { GraffitiContext gContext = new GraffitiContext(context); // Allow plugins to modify the GraffitiContext after it is loaded Graffiti.Core.Events.Instance().ExecuteLoadGraffitiContext(gContext); return gContext; }
/// <summary> /// Overridable in subclasses. Should be used to add custom data to the graffitiContext. /// </summary> /// <param name="graffitiContext">The context passed to the view at runtime.</param> protected virtual void LoadContent(GraffitiContext graffitiContext) { }
protected void SetDataTypeHelpers(GraffitiContext graffitiContext) { object[] builtInHelpers = new object[] { new StaticAccessorHelper<Byte>(), new StaticAccessorHelper<SByte>(), new StaticAccessorHelper<Int16>(), new StaticAccessorHelper<Int32>(), new StaticAccessorHelper<Int64>(), new StaticAccessorHelper<UInt16>(), new StaticAccessorHelper<UInt32>(), new StaticAccessorHelper<UInt64>(), new StaticAccessorHelper<Single>(), new StaticAccessorHelper<Double>(), new StaticAccessorHelper<Boolean>(), new StaticAccessorHelper<Char>(), new StaticAccessorHelper<Decimal>(), new StaticAccessorHelper<String>(), new StaticAccessorHelper<Guid>(), new StaticAccessorHelper<DateTime>() }; foreach (object helper in builtInHelpers) { graffitiContext[helper.GetType().GetGenericArguments()[0].Name] = helper; } }
/// <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>"); } } }
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"; } }
protected virtual object NamedViewLoader(string key, GraffitiContext graffitiContext) { string the_View_Name = ViewLookUp("." + key + ".view", key + ".view"); return macros.LoadThemeView(the_View_Name); }
protected virtual object GetPostTrackbacks(string key, GraffitiContext graffitiContext) { return new Data().PostTrackbacks(PostId); }
/// <summary> /// Executes the LoadGraffitiContext event /// </summary> /// <param name="item"></param> internal void ExecuteLoadGraffitiContext(GraffitiContext context) { GraffitiContextEventHandler re = Events[LoadGraffitiContextObject] as GraffitiContextEventHandler; if (re != null) { re(context, EventArgs.Empty); } }
protected virtual object NamedViewLoader(string key, GraffitiContext graffitiContext) { string the_View_Name = ViewLookUp("." + key + ".view", key + ".view"); return(macros.LoadThemeView(the_View_Name)); }
protected virtual object GetPostTrackbacks(string key, GraffitiContext graffitiContext) { return(new Data().PostTrackbacks(PostId)); }
/// <summary> /// Loads/sets all global default content /// </summary> /// <param name="graffitiContext">Current context</param> /// <param name="view">Name of the view requested</param> protected virtual void SetContextDefault(GraffitiContext graffitiContext, string view) { graffitiContext["request"] = Context.Request; graffitiContext["response"] = Context.Response; graffitiContext["url"] = Context.Request.RawUrl.ToLower().Replace(Util.DEFAULT_PAGE_LOWERED, string.Empty); graffitiContext["pageIndex"] = Int32.Parse(Context.Request.QueryString["p"] ?? "1"); graffitiContext["isUser"] = Context.Request.IsAuthenticated; graffitiContext["user"] = GraffitiUsers.Current; graffitiContext["categoryID"] = CategoryID; graffitiContext["postID"] = PostId; graffitiContext["tagName"] = TagName; graffitiContext.Layout = ViewLookUp(".layout.view", "layout.view"); graffitiContext.View = view; SetDataTypeHelpers(graffitiContext); graffitiContext.RegisterOnRequestDelegate("header", NamedViewLoader); graffitiContext.RegisterOnRequestDelegate("navigation", NamedViewLoader); graffitiContext.RegisterOnRequestDelegate("sidebar", NamedViewLoader); graffitiContext.RegisterOnRequestDelegate("left-sidebar", NamedViewLoader); graffitiContext.RegisterOnRequestDelegate("right-sidebar", NamedViewLoader); graffitiContext.RegisterOnRequestDelegate("footer", NamedViewLoader); }