Esempio n. 1
0
func Feed(context *GoInk.Context) {
	baseUrl := model.GetSetting("site_url")
	article, _ := model.GetArticleList(1, 20)
	feed := new(feeds.Feed)
	feed.Title = model.GetSetting("site_title")
	feed.Link = &feeds.Link{Href: baseUrl}
	feed.Description = model.GetSetting("site_description")
	author := model.GetUsersByRole("ADMIN")[0]
	feed.Author = &feeds.Author{author.Nick, author.Email}
	feed.Items = make([]*feeds.Item, 0)
	var create int64
	if len(article) > 0 {
		create = article[0].EditTime
	} else {
		create = utils.Now()
	}
	feed.Created = time.Unix(create, 0)
	for _, a := range article {
		item := new(feeds.Item)
		item.Title = a.Title
		item.Link = &feeds.Link{Href: path.Join(baseUrl, a.Link())}
		item.Author = feed.Author
		item.Created = time.Unix(a.CreateTime, 0)
		item.Description = utils.Html2str(a.Summary())
		feed.Items = append(feed.Items, item)
	}
	str, e := feed.ToRss()
	if e != nil {
		panic(e)
	}
	context.ContentType("application/rss+xml;charset=UTF-8")
	context.Body = []byte(str)
}
Esempio n. 2
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
}
Esempio n. 3
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())
		}()
	}
}