コード例 #1
0
ファイル: form.go プロジェクト: JessonChan/wetalk
func (form *ArticleAdminForm) SetToArticle(article *models.Article) {
	utils.SetFormValues(form, article)

	if article.User == nil {
		article.User = &models.User{}
	}
	article.User.Id = form.User

	if article.LastAuthor == nil {
		article.LastAuthor = &models.User{}
	}
	article.LastAuthor.Id = form.LastAuthor

	article.ContentCache = utils.RenderMarkdown(article.Content)
	article.ContentCacheZhCn = utils.RenderMarkdown(article.ContentZhCn)
}
コード例 #2
0
ファイル: post.go プロジェクト: netxfly/wetalk
func (m *Comment) GetMessageCache() string {
	if setting.RealtimeRenderMD {
		return utils.RenderMarkdown(m.Message)
	} else {
		return m.MessageCache
	}
}
コード例 #3
0
ファイル: post.go プロジェクト: netxfly/wetalk
func (m *Post) GetContentCache() string {
	if setting.RealtimeRenderMD {
		return utils.RenderMarkdown(m.Content)
	} else {
		return m.ContentCache
	}
}
コード例 #4
0
ファイル: form.go プロジェクト: oyoy8629/XWetalk
func (form *PostAdminForm) SetToPost(post *models.Post) {
	utils.SetFormValues(form, post)

	if post.User == nil {
		post.User = &models.User{}
	}
	post.User.Id = form.User

	if post.LastReply == nil {
		post.LastReply = &models.User{}
	}
	post.LastReply.Id = form.LastReply

	if post.LastAuthor == nil {
		post.LastAuthor = &models.User{}
	}
	post.LastAuthor.Id = form.LastAuthor

	if post.Topic == nil {
		post.Topic = &models.Topic{}
	}
	post.Topic.Id = form.Topic

	if post.Category == nil {
		post.Category = &models.Category{}
	}
	post.Category.Id = form.Category

	post.ContentCache = utils.RenderMarkdown(post.Content)
}
コード例 #5
0
ファイル: form.go プロジェクト: oyoy8629/XWetalk
func (form *PostForm) UpdatePost(post *models.Post, user *models.User) error {
	changes := utils.FormChanges(post, form)
	if len(changes) == 0 {
		return nil
	}
	utils.SetFormValues(form, post)
	post.Category.Id = form.Category
	post.Topic.Id = form.Topic
	for _, c := range changes {
		if c == "Content" {
			post.ContentCache = utils.RenderMarkdown(form.Content)
			changes = append(changes, "ContentCache")
		}
	}

	// update last edit author
	if post.LastAuthor != nil && post.LastAuthor.Id != user.Id {
		post.LastAuthor = user
		changes = append(changes, "LastAuthor")
	}

	changes = append(changes, "Updated")

	return post.Update(changes...)
}
コード例 #6
0
ファイル: form.go プロジェクト: netxfly/wetalk
func (form *PostAdminForm) SetToPost(post *models.Post) {
	utils.SetFormValues(form, post)

	if post.User == nil {
		post.User = &models.User{}
	}
	post.User.Id = form.User

	if post.LastReply == nil {
		post.LastReply = &models.User{}
	}
	post.LastReply.Id = form.LastReply

	if post.LastAuthor == nil {
		post.LastAuthor = &models.User{}
	}
	post.LastAuthor.Id = form.LastAuthor

	if post.Topic == nil {
		post.Topic = &models.Topic{}
	}
	post.Topic.Id = form.Topic
	//get category
	topic := &models.Topic{Id: form.Topic}
	if err := topic.Read("Id"); err == nil {
		if post.Category == nil {
			post.Category = &models.Category{}
		}
		post.Category.Id = topic.Category.Id
	}
	post.ContentCache = utils.RenderMarkdown(post.Content)
}
コード例 #7
0
ファイル: page.go プロジェクト: netxfly/wetalk
func (m *Page) GetContentCache() string {
	var content, contentCache string
	content = m.Content
	contentCache = m.ContentCache

	if setting.RealtimeRenderMD {
		return utils.RenderMarkdown(content)
	} else {
		return contentCache
	}
}
コード例 #8
0
ファイル: form.go プロジェクト: JessonChan/wetalk
func (form *PostForm) SavePost(post *models.Post, user *models.User) error {
	utils.SetFormValues(form, post)
	post.Category = &models.Category{Id: form.Category}
	post.Topic = &models.Topic{Id: form.Topic}
	post.User = user
	post.LastReply = user
	post.LastAuthor = user
	post.ContentCache = utils.RenderMarkdown(form.Content)

	// mentioned follow users
	FilterMentions(user, post.ContentCache)

	return post.Insert()
}
コード例 #9
0
ファイル: form.go プロジェクト: netxfly/wetalk
func (form *PageAdminForm) SetToPage(page *models.Page) {
	utils.SetFormValues(form, page)

	if page.User == nil {
		page.User = &models.User{}
	}
	page.User.Id = form.User

	if page.LastAuthor == nil {
		page.LastAuthor = &models.User{}
	}
	page.LastAuthor.Id = form.LastAuthor

	page.ContentCache = utils.RenderMarkdown(page.Content)
}
コード例 #10
0
ファイル: form.go プロジェクト: oyoy8629/XWetalk
func (form *CommentAdminForm) SetToComment(comment *models.Comment) {
	utils.SetFormValues(form, comment)

	if comment.User == nil {
		comment.User = &models.User{}
	}
	comment.User.Id = form.User

	if comment.Post == nil {
		comment.Post = &models.Post{}
	}
	comment.Post.Id = form.Post

	comment.MessageCache = utils.RenderMarkdown(comment.Message)
}
コード例 #11
0
ファイル: article.go プロジェクト: JessonChan/wetalk
func (m *Article) GetContentCache(lang string) string {
	var content, contentCache string
	switch i18n.IndexLang(lang) {
	case setting.LangZhCN:
		content = m.ContentZhCn
		contentCache = m.ContentCacheZhCn
	default:
		content = m.Content
		contentCache = m.ContentCache
	}
	if setting.RealtimeRenderMD {
		return utils.RenderMarkdown(content)
	} else {
		return contentCache
	}
}
コード例 #12
0
ファイル: form.go プロジェクト: oyoy8629/XWetalk
func (form *CommentForm) SaveComment(comment *models.Comment, user *models.User, post *models.Post) error {
	comment.Message = form.Message
	comment.MessageCache = utils.RenderMarkdown(form.Message)
	comment.User = user
	comment.Post = post
	if err := comment.Insert(); err == nil {
		post.LastReply = user
		post.Update("LastReply", "Updated")

		cnt, _ := post.Comments().Filter("Id__lte", comment.Id).Count()
		comment.Floor = int(cnt)
		return comment.Update("Floor")
	} else {
		return err
	}
}
コード例 #13
0
ファイル: markdown.go プロジェクト: JessonChan/wetalk
func (this *ApiRouter) Markdown() {
	if this.CheckActiveRedirect() {
		return
	}

	if this.IsAjax() {
		result := map[string]interface{}{
			"success": false,
		}
		action := this.GetString("action")
		switch action {
		case "preview":
			content := this.GetString("content")
			result["preview"] = utils.RenderMarkdown(content)
			result["success"] = true
		}
		this.Data["json"] = result
		this.ServeJson()
	}
}