public IBarelyView Index() { var c = BlogEntryData.All().Find(Query.EQ("Publish", true)).SetSortOrder(SortBy.Descending("Posted")); c = c.SetLimit(Config.PageSize); var entries = new List <BlogEntryData>(); foreach (var e in c) { string text = BetterCache.Get <string>(e.ID.ToString()); if (text == null) { e.Text = Config.GetMarkdown().Transform(e.Text); BetterCache.Add(e.ID.ToString(), e.Text); } else { e.Text = text; } entries.Add(e); } var v = new BlogIndexView(); v.ShowPaging = true; v.Page = 1; v.PageMax = ((int)c.Count()) / Config.PageSize + 1; v.Entries = entries; v.Layout.Active = "home"; v.Layout.Title = "Earlz.Net - Programming, Electronics, Hacking, Oh My!"; return(v); }
public IBarelyView New(string entryid, CommentData post) { if (Form["Link"] != "") { return(null); } post.Name = post.Name.Substring(0, Math.Min(post.Name.Length, 32)); post.Text = post.Text.Substring(0, Math.Min(post.Text.Length, 1024)); post.IPAddress = Request.UserHostAddress; post.UserAgent = Request.UserAgent; post.Text = CheckLines(post.Text); if (post.Text == "OOONNNNYYYYTTTTIIIII") { throw new HttpException(500, "F**k you."); } BlogEntryData entry = BlogEntryData.Get(entryid); if (entry == null) { throw new HttpException(404, "Blog entry not found"); } post.EntryID = entry.ID; post.Posted = DateTime.Now; post.Save(); BlogEntryData.RecalculateComments(entry.ID); Response.Redirect(BlogHandler.GetUrl(entry)); return(null); }
public IBarelyView Edit(BlogRouteModel route, BlogEntryData data) { var entry = BlogEntryData.Get(route.Date); if (Method != HttpMethod.Post) { //first diplay the page var v = new ModifyBlogView(); v.Entry = entry; v.Layout.Title = "Editing '" + entry.Title + "'"; return(v); } else { //then receive the form and store it data.ID = entry.ID; //set ID so mongodb can find it (and update it instead of create) data.Posted = entry.Posted; if (!entry.Publish && data.Publish) //if not previously published, update the time so it's "bumped" { data.Posted = DateTime.Now; //this shouldn't have any SEO implications unless I unpublish and then republish. } data.Edited = DateTime.Now; BetterCache.Remove <string>(data.ID.ToString()); data.Save(); Response.Redirect(GetUrl(data)); return(null); //never actually reaches here } }
public IBarelyView Index() { var v = new TagIndexView(); v.Layout.Active = "tags"; v.Layout.Title = "Tag List - Earlz.Net"; var c = BlogEntryData.All(); var l = new List <string>(100); foreach (var i in c.FindAll()) { if (i.Tags == null) { continue; } foreach (var j in i.Tags) { if (!l.Contains(j)) { l.Add(j); } } } l.Sort(); v.Tags = l; return(v); }
public IBarelyView RecalculateCommentCounts() { foreach (var entry in BlogEntryData.All().FindAllAs <BlogEntryData>()) { BlogEntryData.RecalculateComments(entry.ID); } return(new WrapperView("Complete!")); }
public IBarelyView Delete(string id) { var comment = CommentData.Get(new ObjectId(id)); CommentData.Delete(id); BlogEntryData.RecalculateComments(comment.EntryID); return(new WrapperView("Deleted comment")); }
public static string GetUrl(BlogEntryData entry, string action) { //return "/view/"+entry.ID.ToString(); DateTime tmp = entry.Posted.ToUniversalTime(); string date = tmp.Year + "/" + tmp.Month.ToString().PadLeft(2, '0') + "/" + tmp.Day.ToString().PadLeft(2, '0') + "/" + tmp.Hour.ToString().PadLeft(2, '0') + tmp.Minute.ToString().PadLeft(2, '0'); return("/" + action + "/" + date + "/" + Routing.Slugify(entry.Title)); }
public static string GetFullUrl(BlogEntryData entry) { string host = Config.HostName; if (string.IsNullOrEmpty(host)) { host = Request.Url.Host; } return("http://" + host + GetUrl(entry)); }
public void TestingDataContext() { using (var dataContext = new DataContext()) { var blogEntry = new BlogEntryData { Title = "My first blog Entry", Content = "I love blogging, it is so cool" }; dataContext.BlogEntries.Add(blogEntry); dataContext.SaveChanges(); } }
public IBarelyView New(BlogEntryData data) { if (Method != HttpMethod.Post) { var v = new ModifyBlogView(); v.Layout.Active = "home"; return(v); } else { data.Posted = DateTime.Now; data.Edited = DateTime.Now; data.Save(); Response.Redirect(GetUrl(data)); return(null); } }
public IBarelyView View(BlogRouteModel route) { BlogEntryData entry; try{ entry = BlogEntryData.Get(route.Date); }catch { throw new HttpException(404, "Blog entry not found"); } if (entry == null) { throw new HttpException(404, "Blog entry not found"); } if (GetUrl(entry) != Request.Url.AbsolutePath) { PermanentRedirect(GetUrl(entry)); } string text = BetterCache.Get <string>(entry.ID.ToString()); if (text == null) { entry.Text = Config.GetMarkdown().Transform(entry.Text); BetterCache.Add(entry.ID.ToString(), entry.Text); } else { entry.Text = text; } var v = new BlogEntryView(); v.Layout.Title = ""; if (entry.Tags != null) { v.Layout.Title = entry.Tags[0] + " - "; } v.Layout.Title += entry.Title + " - Earlz.Net"; #if DEBUG v.Layout.Title += "-" + entry.ID.ToString(); #endif v.ShowComments = true; v.Entry = entry; v.Summary = false; return(v); }
public IBarelyView Index(int page) { var c = BlogEntryData.All().FindAs <BlogEntryData>(Query.EQ("Publish", true)).SetSortOrder(SortBy.Descending("Posted")); page -= 1; //so that routes start with /blog/1 than /blog/0 if (page == 0) { PermanentRedirect("/"); } c = c.SetSkip(page * Config.PageSize).SetLimit(Config.PageSize); int pagecount = ((int)c.Count()) / Config.PageSize + 1; //this takes a total count on the collection, not the query. var entries = new List <BlogEntryData>(); foreach (var e in c) { string text = BetterCache.Get <string>(e.ID.ToString()); if (text == null) { e.Text = Config.GetMarkdown().Transform(e.Text); BetterCache.Add(e.ID.ToString(), e.Text); } else { e.Text = text; } entries.Add(e); } if (entries.Count == 0) { throw new HttpException(404, "not found"); } var v = new BlogIndexView(); v.ShowPaging = true; page += 1; v.Page = page; v.PageMax = pagecount; v.Entries = entries; v.Layout.Active = "home"; v.Layout.Title = "Archive - Page " + (page) + " of " + (v.PageMax) + " - Earlz.Net"; return(v); }
public IBarelyView Tag(string tag, int page) { var v = new BlogIndexView(); v.ShowPaging = true; v.Tag = tag; v.Layout.Active = "tags"; MongoCursor <BlogEntryData> c; if (tag == "private-draft") { c = BlogEntryData.All().Find(Query.In("Tags", new BsonArray(new string[] { tag }))).SetSortOrder(SortBy.Descending(new string[] { "Posted" })); } else { //otherwise, filter out the private-draft results c = BlogEntryData.All().Find(Query.And(Query.NotIn("Tags", new BsonArray(new string[] { "private-draft" })), Query.In("Tags", new BsonArray(new string[] { tag })))).SetSortOrder(SortBy.Descending(new String[] { "Posted" })); } page -= 1; //so that routes start with /blog/1 than /blog/0 c = c.SetSkip(page * Config.PageSize).SetLimit(Config.PageSize); int pagecount = ((int)c.Count()) / Config.PageSize + 1; //this takes a total count on the collection, not the query. var entries = new List <BlogEntryData>(); foreach (var e in c) { e.Text = Config.GetMarkdown().Transform(e.Text); entries.Add(e); } if (entries.Count == 0) { throw new HttpException(404, "not found"); } page += 1; v.Page = page; v.PageMax = pagecount; v.Entries = entries; v.Layout.Active = "tags"; v.Layout.Title = "Posts Tagged '" + tag + "' - Page " + (page) + " of " + (v.PageMax) + " - Earlz.Net"; return(v); }
public IBarelyView Get() { var v = new BlogEntryView(); v.Layout.Title = "About Me - Earlz.Net"; v.Layout.Active = "aboutme"; v.Entry = BlogEntryData.All().FindOneAs <BlogEntryData>(Query.In("Tags", new BsonValue[] { "page-aboutme" })); string text = BetterCache.Get <string>(v.Entry.ID.ToString()); if (text == null) { v.Entry.Text = Config.GetMarkdown().Transform(v.Entry.Text); BetterCache.Add(v.Entry.ID.ToString(), v.Entry.Text); } else { v.Entry.Text = text; } v.ShowComments = true; v.Summary = false; return(v); }
protected override void Seed(DataContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // var codingTag = new BlogTagData { Title = "Coding" }; var drawingTag = new BlogTagData { Title = "Drawing" }; context.BlogTags .AddOrUpdate(e => e.Title, codingTag, drawingTag); context.SaveChanges(); context.BlogEntries .AddOrUpdate(e => e.Title, new BlogEntryData { Title = "Writing a Blog Engine", Identifier = BlogEntryData.GetIdentifier("Writing a Blog Engine"), Summary = "<p>How to write a blog entry in C#.NET</p>", Content = "<p>So you want to write yourself a blog engine eh?</p><p>Well lets get started</p>", Tags = new[] { codingTag }, IsPublished = true, PublishedOn = DateTime.UtcNow }, new BlogEntryData { Title = "Keyword search support for EF", Identifier = BlogEntryData.GetIdentifier("Keyword search support for EF"), Summary = "<p>Adding support for keyword indexing to your entities</p>", Content = "<p>Adding support for keyword indexing to your entities</p>", Tags = new[] { codingTag }, IsPublished = true, PublishedOn = DateTime.UtcNow }, new BlogEntryData { Title = "Drawing on the iPad", Identifier = BlogEntryData.GetIdentifier("Drawing on the iPad"), Summary = "<p>There are a number of good apps for drawing on the iPad</p>", Content = "<p>I have downloaded a few and compare them here</p>", Tags = new[] { drawingTag } }); context.SaveChanges(); }
void BuildOutput() { __Write(@""); __Write(@""); __Write(@" "); __Write(@" <div class=""entry""> "); if (Entry == null) { __Write(@" <form method=""post"" action=""/new""> "); } else { __Write(@" <form method=""post"" action="""); { object __v; __v = BlogHandler.GetUrl(Entry, "edit"); __OutputVariable(__v); } __Write(@"""> "); } __Write(@" "); if (Entry == null) { Entry = new BlogEntryData(); } __Write(@" Title: <input type=""text"" name=""Title"" value="""); { object __v; __v = Entry.Title; __OutputVariable(__v); } __Write(@""" /> <br /> Text: <textarea rows=""10"" cols=""80"" name=""Text"">"); { object __v; __v = Entry.Text; __OutputVariable(__v); } __Write(@"</textarea><br /> Publish To Index?: <input type=""checkbox"" name=""Publish"" checked="""); { object __v; __v = Entry.Publish ? "yes" : "no"; __OutputVariable(__v); } __Write(@""" value=""true"" /><br /> Tags: "); if (Entry.Tags != null) { __Write(@" <input type=""text"" name=""Tags"" value=""" ); foreach (var tag in Entry.Tags) { __Write(@""); { object __v; __v = tag; __OutputVariable(__v); } __Write(@" "); } __Write(@""" /> "); } else { __Write(@" <input type=""text"" name=""Tags"" value="""" /> "); } __Write(@" <br /> <input type=""submit"" value=""Submit"" /> </form> </div>"); }
public static string GetTweet(BlogEntryData entry) { return("data-url=\"" + HttpUtility.HtmlAttributeEncode(GetFullUrl(entry)) + "\" data-text=\"" + HttpUtility.HtmlAttributeEncode(entry.Title) + "\" data-via=\"earlzdotnet\""); }
public static string GetUrl(BlogEntryData entry) { return(GetUrl(entry, "view")); }