// StartBackupTimer starts backup operation timer for auto backup stuff. func StartBackupTimer(app *GoInk.App, t int) { model.SetTimerFunc("backup-data", 144, func() { filename, e := DoBackup(app, true) if e != nil { model.CreateMessage("backup", "[0]"+e.Error()) } else { model.CreateMessage("backup", "[1]"+filename) } println("backup files in", t, "hours") }) }
func CmdBackup(context *GoInk.Context) { if context.Method == "POST" { file, e := cmd.DoBackup(context.App(), true) if e != nil { Json(context, false).Set("msg", e.Error()).End() return } Json(context, true).Set("file", file).End() context.Do("bakcup_success", file) model.CreateMessage("backup", "[1]"+file) return } if context.Method == "DELETE" { file := context.String("file") if file == "" { Json(context, false).End() return } cmd.RemoveBackupFile(file) Json(context, true).End() context.Do("backup_delete", file) return } files, _ := cmd.GetBackupFiles() context.Layout("admin/cmd") context.Render("admin/cmd/backup", map[string]interface{}{ "Files": files, "Title": "备份", }) }
func Comment(context *GoInk.Context) { cid, _ := strconv.Atoi(context.Param("id")) if cid < 1 { Json(context, false).End() return } if model.GetContentById(cid) == nil { Json(context, false).End() return } data := context.Input() msg := validateComment(data) if msg != "" { Json(context, false).Set("msg", msg).End() return } co := new(model.Comment) co.Author = data["user"] co.Email = data["email"] co.Url = data["url"] co.Content = data["content"] co.Avatar = utils.Gravatar(co.Email, "50") co.Pid, _ = strconv.Atoi(data["pid"]) co.Ip = context.Ip co.UserAgent = context.UserAgent co.IsAdmin = false model.CreateComment(cid, co) Json(context, true).Set("comment", co.ToJson()).End() model.CreateMessage("comment", co) context.Do("comment_created", co) }
func AdminComments(context *GoInk.Context) { if context.Method == "DELETE" { id := context.Int("id") cmt := model.GetCommentById(id) model.RemoveComment(cmt.Cid, id) Json(context, true).End() context.Do("comment_delete", id) return } if context.Method == "PUT" { id := context.Int("id") cmt2 := model.GetCommentById(id) cmt2.Status = "approved" cmt2.GetReader().Active = true model.SaveComment(cmt2) Json(context, true).End() context.Do("comment_change_status", cmt2) return } if context.Method == "POST" { // get required data pid := context.Int("pid") cid := model.GetCommentById(pid).Cid uid, _ := strconv.Atoi(context.Cookie("token-user")) user := model.GetUserById(uid) co := new(model.Comment) co.Author = user.Nick co.Email = user.Email co.Url = user.Url co.Content = context.String("content") co.Avatar = utils.Gravatar(co.Email, "50") co.Pid = pid co.Ip = context.Ip co.UserAgent = context.UserAgent co.IsAdmin = true model.CreateComment(cid, co) Json(context, true).Set("comment", co.ToJson()).End() model.CreateMessage("comment", co) context.Do("comment_reply", co) return } page := context.IntOr("page", 1) comments, pager := model.GetCommentList(page, 10) context.Layout("admin/admin") context.Render("admin/comments", map[string]interface{}{ "Title": "评论", "Comments": comments, "Pager": pager, }) }