Exemple #1
0
func CmdMonitor(ctx *GoInk.Context) {
	ctx.Layout("admin/cmd")
	ctx.Render("admin/cmd/monitor", map[string]interface{}{
		"Title": "系统监控",
		"M":     cmd.ReadMemStats(),
	})
}
Exemple #2
0
func CmdMessage(context *GoInk.Context) {
	context.Layout("admin/cmd")
	context.Render("admin/cmd/message", map[string]interface{}{
		"Title":    "消息",
		"Messages": model.GetMessages(),
	})
}
Exemple #3
0
func Rss(ctx *GoInk.Context) {
	baseUrl := model.GetSetting("site_url")
	article, _ := model.GetPublishArticleList(1, 20)
	author := model.GetUsersByRole("ADMIN")[0]

	articleMap := make([]map[string]string, len(article))
	for i, a := range article {
		m := make(map[string]string)
		m["Title"] = a.Title
		m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
		m["Author"] = author.Nick
		str := utils.Markdown2Html(a.Content())
		str = strings.Replace(str, `src="/`, `src="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
		str = strings.Replace(str, `href="/`, `href="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
		m["Desc"] = str
		m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC822)
		articleMap[i] = m
	}

	ctx.ContentType("application/rss+xml;charset=UTF-8")

	bytes, e := ctx.App().View().Render("rss.xml", map[string]interface{}{
		"Title":    model.GetSetting("site_title"),
		"Link":     baseUrl,
		"Desc":     model.GetSetting("site_description"),
		"Created":  time.Unix(utils.Now(), 0).Format(time.RFC822),
		"Articles": articleMap,
	})
	if e != nil {
		panic(e)
	}
	ctx.Body = bytes
}
Exemple #4
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()
		go model.UpdateCommentAdmin(user)
		context.Do("profile_update", user)
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/profile", map[string]interface{}{
		"Title": "个性资料",
		"User":  user,
	})
}
Exemple #5
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()
		context.Do("article_created", c)
		//c.Type = "article"
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/write_article", map[string]interface{}{
		"Title": "撰写文章",
	})
}
Exemple #6
0
func SetThemeCache(ctx *GoInk.Context, cache bool) {
	ctx.App().View().NoCache()
	ctx.App().View().IsCache = cache
	if cache {
		model.SetSetting("theme_cache", "true")
	} else {
		model.SetSetting("theme_cache", "false")
	}
	model.SyncSettings()
}
Exemple #7
0
func NavigatorSetting(context *GoInk.Context) {
	order := context.Strings("order")
	text := context.Strings("text")
	title := context.Strings("title")
	link := context.Strings("link")
	model.SetNavigators(order, text, title, link)
	Json(context, true).End()
	context.Do("setting_saved")
	return
}
Exemple #8
0
func CmdLogs(context *GoInk.Context) {
	if context.Method == "DELETE" {
		cmd.RemoveLogFile(context.App(), context.String("file"))
		Json(context, true).End()
		return
	}
	context.Layout("admin/cmd")
	context.Render("admin/cmd/log", map[string]interface{}{
		"Title": "日志",
		"Logs":  cmd.GetLogs(context.App()),
	})
}
Exemple #9
0
func Home(context *GoInk.Context) {
	context.Layout("home")
	page, _ := strconv.Atoi(context.Param("page"))
	articles, pager := model.GetPublishArticleList(page, getArticleListSize())
	data := map[string]interface{}{
		"Articles":    articles,
		"Pager":       pager,
		"SidebarHtml": SidebarHtml(context),
	}
	if page > 1 {
		data["Title"] = "第 " + strconv.Itoa(page) + " 页"
	}
	Theme(context).Layout("home").Render("index", data)
}
Exemple #10
0
func Auth(context *GoInk.Context) {
	tokenValue := context.Cookie("token-value")
	token := model.GetTokenByValue(tokenValue)
	if token == nil {
		context.Redirect("/logout/")
		context.End()
		return
	}
	if !token.IsValid() {
		context.Redirect("/logout/")
		context.End()
		return
	}
}
Exemple #11
0
func AdminMessageRead(context *GoInk.Context) {
	id := context.Int("id")
	if id < 0 {
		Json(context, false).End()
		return
	}
	m := model.GetMessage(id)
	if m == nil {
		Json(context, false).End()
		return
	}
	model.SaveMessageRead(m)
	Json(context, true).End()
}
Exemple #12
0
func AdminFiles(context *GoInk.Context) {
	if context.Method == "DELETE" {
		id := context.Int("id")
		model.RemoveFile(id)
		Json(context, true).End()
		context.Do("attach_delete", id)
		return
	}
	files, pager := model.GetFileList(context.Int("page"), 10)
	context.Layout("admin/admin")
	context.Render("admin/files", map[string]interface{}{
		"Title": "媒体文件",
		"Files": files,
		"Pager": pager,
	})
}
Exemple #13
0
func SiteMap(ctx *GoInk.Context) {
	baseUrl := model.GetSetting("site_url")
	println(baseUrl)
	article, _ := model.GetPublishArticleList(1, 50)
	navigators := model.GetNavigators()
	now := time.Unix(utils.Now(), 0).Format(time.RFC3339)

	articleMap := make([]map[string]string, len(article))
	for i, a := range article {
		m := make(map[string]string)
		m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
		m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC3339)
		articleMap[i] = m
	}

	navMap := make([]map[string]string, 0)
	for _, n := range navigators {
		m := make(map[string]string)
		if n.Link == "/" {
			continue
		}
		if strings.HasPrefix(n.Link, "/") {
			m["Link"] = strings.Replace(baseUrl+n.Link, baseUrl+"/", baseUrl, -1)
		} else {
			m["Link"] = n.Link
		}
		m["Created"] = now
		navMap = append(navMap, m)
	}

	ctx.ContentType("text/xml")
	bytes, e := ctx.App().View().Render("sitemap.xml", map[string]interface{}{
		"Title":      model.GetSetting("site_title"),
		"Link":       baseUrl,
		"Created":    now,
		"Articles":   articleMap,
		"Navigators": navMap,
	})
	if e != nil {
		panic(e)
	}
	ctx.Body = bytes

}
Exemple #14
0
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)
}
Exemple #15
0
func AdminArticle(context *GoInk.Context) {
	articles, pager := model.GetArticleList(context.Int("page"), 10)
	context.Layout("admin/admin")
	context.Render("admin/articles", map[string]interface{}{
		"Title":    "文章",
		"Articles": articles,
		"Pager":    pager,
	})
}
Exemple #16
0
func AdminPage(context *GoInk.Context) {
	pages, pager := model.GetPageList(context.Int("page"), 10)
	context.Layout("admin/admin")
	context.Render("admin/pages", map[string]interface{}{
		"Title": "页面",
		"Pages": pages,
		"Pager": pager,
	})
}
Exemple #17
0
func CmdTheme(ctx *GoInk.Context) {
	if ctx.Method == "POST" {
		change := ctx.String("cache")
		if change != "" {
			cmd.SetThemeCache(ctx, change == "true")
			Json(ctx, true).End()
			return
		}
		theme := ctx.String("theme")
		if theme != "" {
			model.SetSetting("site_theme", theme)
			model.SyncSettings()
			Json(ctx, true).End()
			return
		}
		return
	}
	ctx.Layout("admin/cmd")
	ctx.Render("admin/cmd/theme", map[string]interface{}{
		"Title":        "主题",
		"Themes":       cmd.GetThemes(ctx.App().Get("view_dir")),
		"CurrentTheme": model.GetSetting("site_theme"),
	})
}
Exemple #18
0
func Admin(context *GoInk.Context) {
	uid, _ := strconv.Atoi(context.Cookie("token-user"))
	user := model.GetUserById(uid)
	context.Layout("admin/admin")
	context.Render("admin/home", map[string]interface{}{
		"Title":    "控制台",
		"Statis":   model.NewStatis(),
		"User":     user,
		"Messages": model.GetUnreadMessages(),
	})
}
Exemple #19
0
func Article(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 != "article" {
		context.Redirect("/")
		return
	}
	article.Hits++
	Theme(context).Layout("home").Render("article", map[string]interface{}{
		"Title":       article.Title,
		"Article":     article,
		"CommentHtml": CommentHtml(context, article),
	})
}
Exemple #20
0
func CmdReader(ctx *GoInk.Context) {
	if ctx.Method == "POST" {
		email := ctx.String("email")
		model.RemoveReader(email)
		Json(ctx, true).End()
		return
	}
	ctx.Layout("admin/cmd")
	ctx.Render("admin/cmd/reader", map[string]interface{}{
		"Title":   "读者",
		"Readers": model.GetReaders(),
	})
}
Exemple #21
0
func CustomSetting(context *GoInk.Context) {
	keys := context.Strings("key")
	values := context.Strings("value")
	for i, k := range keys {
		if len(k) < 1 {
			continue
		}
		model.SetSetting("c_"+k, values[i])
	}
	model.SyncSettings()
	Json(context, true).End()
	context.Do("setting_saved")
	return
}
Exemple #22
0
func AdminSetting(context *GoInk.Context) {
	if context.Method == "POST" {
		data := context.Input()
		for k, v := range data {
			if v == "" {
				if data[k+"_def"] != "" {
					v = data[k+"_def"]
				}
			}
			model.SetSetting(k, v)
		}
		model.SyncSettings()
		Json(context, true).End()
		context.Do("setting_saved")
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/setting", map[string]interface{}{
		"Title":      "配置",
		"Custom":     model.GetCustomSettings(),
		"Navigators": model.GetNavigators(),
	})
}
Exemple #23
0
func TopPage(context *GoInk.Context) {
	slug := context.Param("slug")
	page := model.GetContentBySlug(slug)
	if page == nil || page.Status != "publish" {
		context.Redirect("/")
		return
	}
	if page.IsLinked && page.Type == "page" {
		Theme(context).Layout("home").Render("page", map[string]interface{}{
			"Title": page.Title,
			"Page":  page,
		})
		page.Hits++
		return
	}
	context.Redirect("/")
}
Exemple #24
0
func TagArticles(ctx *GoInk.Context) {
	ctx.Layout("home")
	page, _ := strconv.Atoi(ctx.Param("page"))
	tag, _ := url.QueryUnescape(ctx.Param("tag"))
	size := getArticleListSize()
	articles, pager := model.GetTaggedArticleList(tag, page, getArticleListSize())
	// fix dotted tag
	if len(articles) < 1 && strings.Contains(tag, "-") {
		articles, pager = model.GetTaggedArticleList(strings.Replace(tag, "-", ".", -1), page, size)
	}
	Theme(ctx).Layout("home").Render("index", map[string]interface{}{
		"Articles":    articles,
		"Pager":       pager,
		"SidebarHtml": SidebarHtml(ctx),
		"Tag":         tag,
		"Title":       tag,
	})
}
Exemple #25
0
// default handler, implement GoInk.Handler
func homeHandler(ctx *GoInk.Context) {
	ctx.Body = []byte("Hello GoInk !")
}
Exemple #26
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()
		context.Do("page_modified", c)
		//c.Type = "article"
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/edit_page", map[string]interface{}{
		"Title": "编辑文章",
		"Page":  c,
	})
}
Exemple #27
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()
		context.Do("password_update", user)
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/password", map[string]interface{}{
		"Title": "修改密码",
		//"User":user,
	})
}
Exemple #28
0
func PluginSetting(context *GoInk.Context) {
	key := context.Param("plugin_key")
	if key == "" {
		context.Redirect("/admin/plugins/")
		return
	}
	p := plugin.GetPluginByKey(key)
	if p == nil {
		context.Redirect("/admin/plugins/")
		return
	}
	if context.Method == "POST" {
		p.SetSetting(context.Input())
		Json(context, true).End()
		context.Do("plugin_setting_saved", p)
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/plugin_setting", map[string]interface{}{
		"Title": "插件 - " + p.Name(),
		"Form":  p.Form(),
	})
}
Exemple #29
0
func AdminPlugin(context *GoInk.Context) {
	if context.Method == "POST" {
		action := context.String("action")
		if action == "" {
			Json(context, false).End()
			return
		}
		pln := context.String("plugin")
		if action == "activate" {
			plugin.Activate(pln)
			plugin.Update(context.App())
			Json(context, true).End()
			context.Do("plugin_activated", pln)
			return
		}
		if action == "deactivate" {
			plugin.Deactivate(pln)
			Json(context, true).End()
			context.Do("plugin_deactivated", pln)
			return
		}
		context.Status = 405
		Json(context, false).End()
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/plugin", map[string]interface{}{
		"Title":   "插件",
		"Plugins": plugin.GetPlugins(),
	})
}
Exemple #30
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()
		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,
	})
}