示例#1
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)
}
示例#2
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),
	})
}
示例#3
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,
	})
}
示例#4
0
文件: home.go 项目: WytheOnly/GoBlog
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()
}
示例#5
0
func (p *EmailPlugin) sendEmail(co *model.Comment, isCreate bool) {
	var (
		tpl     *template.Template
		buff    bytes.Buffer
		pco     *model.Comment
		content *model.Content
		err     error
		user    *model.User
		title   string
		from    mail.Address
		to      mail.Address
	)

	// get article or page content instance
	content = model.GetContentById(co.Cid)
	if content == nil {
		println("error content getting in email plugin")
		return
	}
	// email for notify new commment creation
	if co.Pid < 1 {
		tpl = p.templates["created"]

		err = tpl.Execute(&buff, map[string]interface{}{
			"link":      model.GetSetting("site_url"),
			"site":      model.GetSetting("site_title"),
			"author":    co.Author,
			"text":      template.HTML(co.Content),
			"title":     content.Title,
			"permalink": path.Join(model.GetSetting("site_url"), content.Link()),
		})
		if err != nil {
			fmt.Println(err)
			return
		}
		user = model.GetUsersByRole("ADMIN")[0]
		from = mail.Address{"no-reply@" + model.GetSetting("site_url"), p.settings["smtp_email_user"]}
		to = mail.Address{user.Nick, user.Email}
		title = co.Author + "在您的网站发表新评论"
		p.sendSmtp(from, to, title, buff.Bytes())
		return
	}
	// send mail for the author of comment replying to
	pco = model.GetCommentById(co.Pid)
	tpl = p.templates["reply"]
	err = tpl.Execute(&buff, map[string]interface{}{
		"link":      model.GetSetting("site_url"),
		"site":      model.GetSetting("site_title"),
		"author_p":  pco.Author,
		"text_p":    template.HTML(pco.Content),
		"author":    co.Author,
		"text":      template.HTML(co.Content),
		"title":     content.Title,
		"permalink": path.Join(model.GetSetting("site_url"), content.Link()),
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	user = model.GetUsersByRole("ADMIN")[0]

	from = mail.Address{pco.Author + "@" + model.GetSetting("site_url"), p.settings["smtp_email_user"]}
	to = mail.Address{pco.Author, pco.Email}
	title = "您的评论有了回复"
	p.sendSmtp(from, to, title, buff.Bytes())
	// send email to notice admin new comment creation
	// this comment is a reply comment
	if isCreate {
		go func() {
			tpl = p.templates["created"]

			err = tpl.Execute(&buff, map[string]interface{}{
				"link":      model.GetSetting("site_url"),
				"site":      model.GetSetting("site_title"),
				"author":    co.Author,
				"text":      template.HTML("回复" + pco.Author + ":<br/>" + co.Content),
				"title":     content.Title,
				"permalink": path.Join(model.GetSetting("site_url"), content.Link()),
			})
			if err != nil {
				fmt.Println(err)
				return
			}
			user = model.GetUsersByRole("ADMIN")[0]
			from = mail.Address{"no-reply@" + model.GetSetting("site_url"), p.settings["smtp_email_user"]}
			to = mail.Address{user.Nick, user.Email}
			title = co.Author + "在您的网站发表新评论"
			p.sendSmtp(from, to, title, buff.Bytes())
		}()
	}
}