Example #1
0
func (ac *ArticleController) Get() {
	var (
		article = new(model.Article)
		opt     = service.ArticleReadOption{
			Id:        ac.ParamInt64(":id"),
			Link:      ac.Param(":link"),
			Status:    model.ARTICLE_STATUS_PUBLISH,
			IsHit:     true,
			IsPublish: true,
		}
		opt2 = service.CommentListOption{
			From:   model.COMMENT_FROM_ARTICLE,
			Status: 0,
		}
		comments = make([]*model.Comment, 0)
	)
	if err := service.Call(service.Article.Read, opt, article); err != nil {
		status := 500
		if err == service.ErrArticleNotFound {
			status = 404
		}
		ac.RenderError(status, err)
		return
	}
	if article.Id != opt.Id || article.Link != opt.Link {
		ac.RenderError(404, nil)
		return
	}
	opt2.FromId = article.Id
	if service.Setting.Comment.ShowWaitComment {
		opt2.AllAccessible = true
	} else {
		opt2.AllApproved = true
	}
	if err := service.Call(service.Comment.ListForContent, opt2, &comments); err != nil {
		ac.RenderError(500, err)
		return
	}

	shouldShowComments := true
	if article.IsCommentClosed() && len(comments) == 0 {
		shouldShowComments = false
	}

	if ac.AuthUser != nil {
		ac.Assign(middle.AuthUserTemplateField, nil) // set auth user nil instead of middleware assignment
		ac.Assign("FrontUser", model.NewFrontUser(ac.AuthUser))
	}

	ac.Title(article.Title + " - " + service.Setting.General.Title)
	ac.Assign("Article", article)
	ac.Assign("Comments", comments)
	ac.Assign("ShouldShowComments", shouldShowComments)
	ac.Assign("IsCommentEnable", article.IsCommentable(service.Setting.Comment.AutoCloseDay))
	ac.Assign("CommentUrl", fmt.Sprintf("/comment/article/%d", article.Id))
	ac.Assign("XsrfHTML", ac.XsrfFormHtml())
	ac.Render("single.tmpl")
}
Example #2
0
func (cc *CommentController) Get() {
	cc.Title("COMMENT - " + strings.ToUpper(core.PUGO_NAME))
	var (
		opt = service.CommentListOption{
			Page:    cc.FormInt("page", 1),
			Size:    cc.FormInt("size", 10),
			IsCount: true,
		}
		comments = make([]*model.Comment, 0)
		pager    = new(utils.Pager)
	)

	// load comment
	switch cc.Form("status") {
	case "all":
		opt.Status = 0
	case "approved":
		opt.Status = model.COMMENT_STATUS_APPROVED
	case "wait":
		opt.Status = model.COMMENT_STATUS_WAIT
	case "spam":
		opt.Status = model.COMMENT_STATUS_SPAM
	default:
		opt.Status = 0
	}
	if err := service.Call(service.Comment.List, opt, &comments, pager); err != nil {
		cc.RenderError(500, err)
		return
	}

	// build pager url
	query := cc.Req().URL.Query()
	query.Del("page")
	queryStr := query.Encode()
	if len(queryStr) == 0 {
		queryStr = "/admin/manage/comment?page=%d"
	} else {
		queryStr = "/admin/manage/comment?" + queryStr + "&page=%d"
	}

	cc.Assign("PageUrl", queryStr)
	cc.Assign("Comments", comments)
	cc.Assign("Pager", pager)
	cc.Render("manage_comment.tmpl")
}