Beispiel #1
0
func ArticleWrite(context *GoInk.Context) {
	if context.Method == "POST" {
		c := new(model.Content)
		c.Id = 0
		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 = false
		c.AuthorId, _ = strconv.Atoi(context.Cookie("token-user"))
		c.Template = "blog.html"
		c.Status = data["status"]
		c.Format = "markdown"
		c.Hits = 1
		var e error
		c, e = model.CreateContent(c, "article")
		if e != nil {
			Json(context, false).Set("msg", e.Error()).End()
			return
		}
		Json(context, true).Set("content", c).End()
		//c.Type = "article"
		return
	}
	context.Layout("admin")
	context.Render("admin/write_article", map[string]interface{}{
		"Title": "撰写文章",
	})
}
Beispiel #2
0
func AdminProfile(context *GoInk.Context) {
	uid, _ := strconv.Atoi(context.Cookie("token-user"))
	user := model.GetUserById(uid)
	if context.Method == "POST" {
		data := context.Input()
		if !user.ChangeEmail(data["email"]) {
			Json(context, false).Set("msg", "邮箱与别的用户重复").End()
			return
		}
		user.Name = data["user"]
		user.Email = data["email"]
		user.Avatar = utils.Gravatar(user.Email, "180")
		user.Url = data["url"]
		user.Nick = data["nick"]
		user.Bio = data["bio"]
		Json(context, true).End()
		go model.SyncUsers()
		return
	}
	context.Layout("admin")
	context.Render("admin/profile", map[string]interface{}{
		"Title": "个性资料",
		"User":  user,
	})
}
Beispiel #3
0
func CmdBackup(context *GoInk.Context) {
	if context.Method == "POST" {
		file, e := cmd.DoBackup(context.App())
		if e != nil {
			Json(context, false).Set("msg", e.Error()).End()
			return
		}
		Json(context, true).Set("file", file).End()
		return
	}
	if context.Method == "DELETE" {
		file := context.String("file")
		if file == "" {
			Json(context, false).End()
			return
		}
		cmd.RemoveBackupFile(file)
		Json(context, true).End()
		return
	}
	files, _ := cmd.GetBackupFiles()
	context.Layout("cmd")
	context.Render("cmd/backup", map[string]interface{}{
		"Files": files,
	})
}
Beispiel #4
0
func AdminArticle(context *GoInk.Context) {
	articles, pager := model.GetArticleList(context.Int("page"), 10)
	context.Layout("admin")
	context.Render("admin/articles", map[string]interface{}{
		"Title":    "文章",
		"Articles": articles,
		"Pager":    pager,
	})
}
Beispiel #5
0
func AdminPage(context *GoInk.Context) {
	pages, pager := model.GetPageList(context.Int("page"), 10)
	context.Layout("admin")
	context.Render("admin/pages", map[string]interface{}{
		"Title": "页面",
		"Pages": pages,
		"Pager": pager,
	})
}
Beispiel #6
0
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,
	})
}
Beispiel #7
0
func AdminFiles(context *GoInk.Context) {
	if context.Method == "DELETE" {
		id := context.Int("id")
		model.RemoveFile(id)
		Json(context, true).End()
		return
	}
	files, pager := model.GetFileList(context.Int("page"), 10)
	context.Layout("admin")
	context.Render("admin/files", map[string]interface{}{
		"Title": "媒体文件",
		"Files": files,
		"Pager": pager,
	})
}
Beispiel #8
0
func AdminSetting(context *GoInk.Context) {
	if context.Method == "POST" {
		data := context.Input()
		for k, v := range data {
			model.SetSetting(k, v)
		}
		model.SyncSettings()
		Json(context, true).End()
		return
	}
	context.Layout("admin")
	context.Render("admin/setting", map[string]interface{}{
		"Title": "配置",
	})
}
Beispiel #9
0
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()
		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()
		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 = strings.Replace(utils.Html2str(context.String("content")), "\n", "<br/>", -1)
		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()
		return
	}
	page := context.IntOr("page", 1)
	comments, pager := model.GetCommentList(page, 6)
	context.Layout("admin")
	context.Render("admin/comments", map[string]interface{}{
		"Title":    "评论",
		"Comments": comments,
		"Pager":    pager,
	})
}
Beispiel #10
0
func CustomSetting(context *GoInk.Context) {
	if context.Method == "POST" {
		keys := context.Strings("key")
		values := context.Strings("value")
		for i, k := range keys {
			model.SetSetting("c_"+k, values[i])
		}
		model.SyncSettings()
		Json(context, true).End()
		return
	}
	context.Layout("admin")
	context.Render("admin/custom_setting", map[string]interface{}{
		"Title":    "自定义配置",
		"Settings": model.GetCustomSettings(),
	})
}
Beispiel #11
0
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("/")
}
Beispiel #12
0
func AdminPassword(context *GoInk.Context) {
	if context.Method == "POST" {
		uid, _ := strconv.Atoi(context.Cookie("token-user"))
		user := model.GetUserById(uid)
		if !user.CheckPassword(context.String("old")) {
			Json(context, false).Set("msg", "旧密码错误").End()
			return
		}
		user.ChangePassword(context.String("new"))
		go model.SyncUsers()
		Json(context, true).End()
		return
	}
	context.Layout("admin")
	context.Render("admin/password", map[string]interface{}{
		"Title": "修改密码",
		//"User":user,
	})
}
Beispiel #13
0
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),
	})
}
Beispiel #14
0
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,
	})
}
Beispiel #15
0
func Admin(context *GoInk.Context) {
	context.Layout("admin")
	context.Render("admin/home", map[string]interface{}{
		"Title": "控制台",
	})
}