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); }
/// <summary> /// Gets the Post for the specified name /// </summary> /// <param name="name"></param> /// <returns></returns> public Post GetPost(string name) { if (string.IsNullOrEmpty(name)) { return(null); } if (name.StartsWith("/")) { name = name.Substring(1); } if (name.EndsWith("/")) { name = name.Substring(0, name.Length - 1); } if (string.IsNullOrEmpty(name)) { return(null); } int postId = Post.GetPostIdByName(name); if (postId == -1) { return(null); } return(Post.GetCachedPost(postId)); }
private void MostPopularPostReport() { context.Response.ContentType = "text/xml"; XmlTextWriter xml = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8); ReportData data = Reports.MostPopularPosts(); xml.WriteStartElement("pie"); int counter = 0; foreach (int key in data.Titles.Keys) { counter++; xml.WriteStartElement("slice"); xml.WriteAttributeString("title", data.Titles[key]); xml.WriteAttributeString("url", Post.GetCachedPost(key).Url); if (counter == 1) { xml.WriteAttributeString("pull_out", "true"); } xml.WriteValue(data.Counts[key]); xml.WriteEndElement(); } xml.WriteEndElement(); xml.Close(); }
private void ViewsByDateReport_Single() { int year; int month; int day; int.TryParse(context.Request.QueryString["year"], out year); int.TryParse(context.Request.QueryString["month"], out month); int.TryParse(context.Request.QueryString["day"], out day); DateTime date = new DateTime(year, month, day); context.Response.ContentType = "text/xml"; XmlTextWriter xml = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8); ReportData viewsBySingle_ReportData = Reports.ViewsByDateSingle(date); xml.WriteStartElement("chart"); // Series labels xml.WriteStartElement("series"); foreach (int key in viewsBySingle_ReportData.Titles.Keys) { xml.WriteStartElement("value"); xml.WriteAttributeString("xid", key.ToString()); xml.WriteAttributeString("url", Post.GetCachedPost(key).Url); xml.WriteValue(viewsBySingle_ReportData.Titles[key]); xml.WriteEndElement(); } xml.WriteEndElement(); xml.WriteStartElement("graphs"); xml.WriteStartElement("graph"); xml.WriteAttributeString("gid", "1"); foreach (int key in viewsBySingle_ReportData.Counts.Keys) { xml.WriteStartElement("value"); xml.WriteAttributeString("xid", key.ToString()); xml.WriteAttributeString("url", Post.GetCachedPost(key).Url); xml.WriteValue(viewsBySingle_ReportData.Counts[key]); xml.WriteEndElement(); } xml.WriteEndElement(); xml.Close(); }
/// <summary> /// Gets the sites featured post /// </summary> /// <returns></returns> public Post Featured() { SiteSettings settings = SiteSettings.Get(); if (settings.FeaturedId > 0) { Post p = Post.GetCachedPost(settings.FeaturedId); if (p.IsPublished) { return(p); } } return(null); }
/// <summary> /// Gets the sites featured post for the specifed Category /// </summary> /// <param name="category"></param> /// <returns></returns> private static Post Featured(Category category) { if (category != null) { if (category.FeaturedId > 0) { Post p = Post.GetCachedPost(category.FeaturedId); if (p.IsPublished) { return(p); } } } return(null); }
private void ViewsByPostReport() { context.Response.ContentType = "text/xml"; XmlTextWriter xml = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8); DateTime minDate = new DateTime(long.Parse(context.Request.QueryString["minDate"])); DateTime maxDate = new DateTime(long.Parse(context.Request.QueryString["maxDate"])); ReportData data = Reports.GetViewsByPost(minDate, maxDate); xml.WriteStartElement("chart"); // Series labels xml.WriteStartElement("series"); foreach (int key in data.Titles.Keys) { xml.WriteStartElement("value"); xml.WriteAttributeString("xid", key.ToString()); xml.WriteAttributeString("url", Post.GetCachedPost(key).Url); xml.WriteValue(data.Titles[key]); xml.WriteEndElement(); } xml.WriteEndElement(); xml.WriteStartElement("graphs"); xml.WriteStartElement("graph"); xml.WriteAttributeString("gid", "1"); foreach (int key in data.Counts.Keys) { xml.WriteStartElement("value"); xml.WriteAttributeString("xid", key.ToString()); xml.WriteAttributeString("url", "views/post/?id=" + key); xml.WriteValue(data.Counts[key]); xml.WriteEndElement(); } xml.WriteEndElement(); xml.Close(); }
/// <summary> /// Gets the Post for the specified ID /// </summary> /// <param name="id"></param> /// <returns></returns> public Post GetPost(int id) { return(Post.GetCachedPost(id)); }