Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Commit

Permalink
Compilable now in weekly.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnly92 committed Dec 10, 2011
1 parent 3290a3d commit 23f71ed
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
6 changes: 3 additions & 3 deletions controllers/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func (c *Admin) LoginPost(ctx *web.Context) {
return
}
if ctx.Params["username"] == config.Get("adminuser") && ctx.Params["password"] == config.Get("adminpasswd") {
t := time.LocalTime()
t := time.Now()
var h hash.Hash = sha1.New()
h.Write([]byte(strconv.Itoa64(t.Seconds())))
sessionH.Data["logged"] = hex.EncodeToString(h.Sum())
h.Write([]byte(strconv.FormatInt(t.Unix(), 10)))
sessionH.Data["logged"] = hex.EncodeToString(h.Sum(nil))
}
ctx.Redirect(302, "/admin/post/list")
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *Index) ReadPost(ctx *web.Context, postId string) string {
viewVars := make(map[string]interface{})
viewVars["Title"] = result.Title
viewVars["Content"] = result.Content
viewVars["Date"] = time.SecondsToLocalTime(result.Created).Format(blogConfig.Get("dateFormat"))
viewVars["Date"] = time.Unix(result.Created, 0).Format(blogConfig.Get("dateFormat"))
viewVars["Id"] = objectIdHex(result.Id.String())
// To be used within the {{Comments}} blog
viewVars["PostId"] = objectIdHex(result.Id.String())
Expand All @@ -56,7 +56,7 @@ func (c *Index) ReadPost(ctx *web.Context, postId string) string {
for i, v := range result.Comments {
comments = append(comments, map[string]string{
"Number": strconv.Itoa(i+1),
"Date": time.SecondsToLocalTime(v.Created).Format(blogConfig.Get("dateFormat")),
"Date": time.Unix(v.Created, 0).Format(blogConfig.Get("dateFormat")),
"Id": v.Id[0:9],
"RealId": v.Id,
"Content": v.Content,
Expand Down Expand Up @@ -90,7 +90,7 @@ func (c *Index) ReadPage(pageSlug string) string {
viewVars := make(map[string]string)
viewVars["Title"] = result.Title
viewVars["Content"] = result.Content
viewVars["Date"] = time.SecondsToLocalTime(result.Created).Format(blogConfig.Get("dateFormat"))
viewVars["Date"] = time.Unix(result.Created, 0).Format(blogConfig.Get("dateFormat"))

output := mustache.RenderFile("templates/view-page.mustache", viewVars)
return render(output, result.Title)
Expand Down
15 changes: 7 additions & 8 deletions models/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"launchpad.net/gobson/bson"
"launchpad.net/mgo"
"os"
"time"
//"math"
)
Expand All @@ -30,7 +29,7 @@ func PageModelInit() *PageModel {
func (page *PageModel) Sidebar() []map[string]string {
var result *Page
results := []map[string]string{}
callback := func() os.Error {
callback := func() error {
results = append(results, map[string]string {"Title": result.Title, "Slug": result.Slug})
return nil
}
Expand All @@ -44,12 +43,12 @@ func (page *PageModel) Sidebar() []map[string]string {
func (page *PageModel) List() []map[string]string {
var result *Page
results := []map[string]string{}
callback := func() os.Error {
t := time.SecondsToLocalTime(result.Created)
callback := func() error {
t := time.Unix(result.Created, 0)
results = append(results, map[string]string {"Title":result.Title, "Date":t.Format("2006 Jan 02 15:04"), "Id": objectIdHex(result.Id.String())})
return nil
}
var err os.Error
var err error
err = page.c.Find(nil).Sort(bson.M{"timestamp":-1}).For(&result, callback)
if err != nil {
panic(err)
Expand All @@ -58,12 +57,12 @@ func (page *PageModel) List() []map[string]string {
}

func (page *PageModel) Create(title string, content string) {
t := time.LocalTime()
t := time.Now()
slug := toAscii(title)
if page.GetBySlug(slug) != nil {
slug += "-2"
}
err := page.c.Insert(&Page{"", title, slug, content, t.Seconds(), 0})
err := page.c.Insert(&Page{"", title, slug, content, t.Unix(), 0})
if err != nil {
panic(err)
}
Expand All @@ -81,7 +80,7 @@ func (page *PageModel) Update(title string, content string, id string) {
}
result.Slug = slug
result.Content = content
result.Modified = time.LocalTime().Seconds()
result.Modified = time.Now().Unix()
err := page.c.Update(bson.M{"_id":bson.ObjectIdHex(id)},result)
if err != nil {
panic(err)
Expand Down
31 changes: 15 additions & 16 deletions models/posts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"launchpad.net/gobson/bson"
"launchpad.net/mgo"
"os"
"time"
"hash"
"crypto/sha1"
Expand All @@ -19,7 +18,7 @@ type Post struct {
Content string
Created int64 "timestamp"
Modified int64
Status uint
Status uint64
Type uint
Comments []Comment
}
Expand Down Expand Up @@ -58,8 +57,8 @@ func (post *PostModel) FrontPage() []map[string]string {
var result *Post
results := []map[string]string{}
posts, _ := strconv.Atoi(blogConfig.Get("postsPerPage"))
err := post.c.Find(bson.M{"status":1}).Sort(bson.M{"timestamp":-1}).Limit(posts).For(&result, func() os.Error {
t := time.SecondsToLocalTime(result.Created)
err := post.c.Find(bson.M{"status":1}).Sort(bson.M{"timestamp":-1}).Limit(posts).For(&result, func() error {
t := time.Unix(result.Created, 0)
if result.Type == 1 {
renderer := blackfriday.HtmlRenderer(post.html_flags,"","")
result.Content = string(blackfriday.Markdown([]byte(result.Content), renderer, post.extensions))
Expand Down Expand Up @@ -139,16 +138,16 @@ func (post *PostModel) TotalPages() int {
func (post *PostModel) PostListing(page int) []map[string]string {
var result *Post
results := []map[string]string{}
callback := func() os.Error {
t := time.SecondsToLocalTime(result.Created)
callback := func() error {
t := time.Unix(result.Created, 0)
p := map[string]string {"Title":result.Title, "Date":t.Format(blogConfig.Get("dateFormat")), "Id": objectIdHex(result.Id.String())}
if (result.Status == 0) {
p["Draft"] = "1"
}
results = append(results, p)
return nil
}
var err os.Error
var err error
if page == 0 {
err = post.c.Find(nil).Sort(bson.M{"timestamp":-1}).For(&result, callback)
} else {
Expand All @@ -162,9 +161,9 @@ func (post *PostModel) PostListing(page int) []map[string]string {
}

func (post *PostModel) Create(title string, content string, status string, markdown uint) {
t := time.LocalTime()
tmp, _ := strconv.Atoui(status)
err := post.c.Insert(&Post{"", title, content, t.Seconds(), 0, tmp, markdown, make([]Comment,0)})
t := time.Now()
tmp, _ := strconv.ParseUint(status, 10, 64)
err := post.c.Insert(&Post{"", title, content, t.Unix(), 0, tmp, markdown, make([]Comment,0)})
if err != nil {
panic(err)
}
Expand All @@ -176,11 +175,11 @@ func (post *PostModel) InsertComment(postId string, content string, author strin
author = "Anonymous"
}
// Generate ID
t := time.LocalTime()
t := time.Now()
var h hash.Hash = sha1.New()
h.Write([]byte(author+strconv.Itoa64(t.Seconds())))
id := hex.EncodeToString(h.Sum())
comment := Comment{id, content, author, t.Seconds()}
h.Write([]byte(author+strconv.FormatInt(t.Unix(),10)))
id := hex.EncodeToString(h.Sum(nil))
comment := Comment{id, content, author, t.Unix()}
result.Comments = append(result.Comments, comment)
err := post.c.Update(bson.M{"_id":bson.ObjectIdHex(postId)},result)
if err != nil {
Expand Down Expand Up @@ -211,8 +210,8 @@ func (post *PostModel) Update(title string, content string, status string, postI
result := post.Get(postId)
result.Title = title
result.Content = content
result.Modified = time.LocalTime().Seconds()
result.Status, _ = strconv.Atoui(status)
result.Modified = time.Now().Unix()
result.Status, _ = strconv.ParseUint(status,0,64)
err := post.c.Update(bson.M{"_id":bson.ObjectIdHex(postId)},result)
if err != nil {
panic(err)
Expand Down

0 comments on commit 23f71ed

Please sign in to comment.