func Home(context *GoInk.Context) { context.Layout("home") page, _ := strconv.Atoi(context.Param("page")) size, _ := strconv.Atoi(model.GetSetting("article_size")) articles, pager := model.GetArticleList(page, size) context.Render("home/home", map[string]interface{}{ "Articles": articles, "Pager": pager, }) }
func TopPage(context *GoInk.Context) { slug := context.Param("slug") page := model.GetContentBySlug(slug) if page == nil { context.Redirect("/") return } if page.IsLinked && page.Type == "page" { context.Layout("home") context.Render("home/page", map[string]interface{}{ "Title": page.Title, "Page": page, }) page.Hits++ return } context.Redirect("/") }
func Page(context *GoInk.Context) { id, _ := strconv.Atoi(context.Param("id")) slug := context.Param("slug") article := model.GetContentById(id) if article == nil { context.Redirect("/") return } if article.Slug != slug || article.Type != "page" { context.Redirect("/") return } article.Hits++ context.Layout("home") context.Render("home/page", map[string]interface{}{ "Title": article.Title, "Page": article, //"CommentHtml": Comments(context, article), }) }
func PageEdit(context *GoInk.Context) { id, _ := strconv.Atoi(context.Param("id")) c := model.GetContentById(id) if c == nil { context.Redirect("/admin/pages/") return } if context.Method == "DELETE" { model.RemoveContent(c) Json(context, true).End() return } if context.Method == "POST" { data := context.Input() if !c.ChangeSlug(data["slug"]) { Json(context, false).Set("msg", "固定链接重复").End() return } c.Title = data["title"] c.Text = data["content"] //c.Tags = strings.Split(strings.Replace(data["tag"], ",", ",", -1), ",") c.IsComment = data["comment"] == "1" c.IsLinked = data["link"] == "1" //c.AuthorId, _ = strconv.Atoi(context.Cookie("token-user")) //c.Template = "blog.html" c.Status = data["status"] //c.Format = "markdown" model.SaveContent(c) Json(context, true).Set("content", c).End() //c.Type = "article" return } context.Layout("admin") context.Render("admin/edit_page", map[string]interface{}{ "Title": "编辑文章", "Page": c, }) }
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() co := new(model.Comment) co.Author = data["user"] co.Email = data["email"] co.Url = data["url"] co.Content = strings.Replace(utils.Html2str(data["content"]), "\n", "<br/>", -1) 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() }