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": "撰写文章", }) }
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()) }() } }