Пример #1
0
func (this *PostController) setPost(post *models.Post) {
	this.TplName = "post.tpl"
	this.Data["Author"] = post.Author
	this.Data["Post"] = post
	this.Data["PageTitle"] = fmt.Sprintf("%s - %s", post.PostTitle, blogTitle)

	this.LoadSidebar([]string{"LatestComments", "MostPopular", "TagCloud"})

	// comments
	comments := models.NewCommentModel().ByPostId(post.PostId, "-CommentId")
	this.Data["Comments"] = comments

	comment_author, res := this.Ctx.GetSecureCookie(COOKIE_SECURE_KEY_COMMENT, COOKIE_NAME_COMMENT_AUTHOR)
	if res == true {
		this.Data["CommentAuthor"] = comment_author
	}
	comment_author_mail, res := this.Ctx.GetSecureCookie(COOKIE_SECURE_KEY_COMMENT, COOKIE_NAME_COMMENT_AUTHOR_MAIL)
	if res == true {
		this.Data["CommentAuthorMail"] = comment_author_mail
	}
	comment_author_url, res := this.Ctx.GetSecureCookie(COOKIE_SECURE_KEY_COMMENT, COOKIE_NAME_COMMENT_AUTHOR_URL)
	if res == true {
		this.Data["CommentAuthorUrl"] = comment_author_url
	}
}
Пример #2
0
func (this *BaseController) LoadSidebar(widgets []string) {
	for _, widget := range widgets {
		if widget == "LatestComments" {
			if latest_comments, err := models.NewCommentModel().Latest(10); err == nil {
				this.Data["LatestComments"] = latest_comments
			}
		} else if widget == "MostPopular" {
			if posts, err := models.NewPostModel().MostPopular(10); err == nil {
				this.Data["MostPopular"] = posts
			}
		} else if widget == "Links" {
			if links, err := models.NewLinkModel().AllLinks(); err == nil {
				this.Data["Links"] = links
			}
		} else if widget == "TagCloud" {
			if tags, err := models.NewTagModel().MostPopular(20); err == nil {
				this.Data["TagCloud"] = tags
			}
		}
	}
}
Пример #3
0
func (this *CommentController) DoAddComment() {
	if cpt.VerifyReq(this.Ctx.Request) != true {
		panic(errors.New("error: wrong captcha"))
	}
	content := this.GetString("comment")
	if content == "" {
		panic(errors.New("error: empty comment"))
	}
	post_id := this.Input().Get("post_id")
	int_post_id, _ := strconv.Atoi(post_id)
	if int_post_id == 0 {
		this.StopRun()
	}

	comment_parent_id := this.Input().Get("comment_parent_id")
	int_comment_parent_id, _ := strconv.Atoi(comment_parent_id)

	comment := models.NewComment()
	logged_user := this.loggedUser
	if logged_user != nil {
		comment.CommentAuthor = logged_user.DisplayName
		comment.CommentAuthorMail = logged_user.AuthorMail
		comment.CommentAuthorUrl = logged_user.AuthorUrl
	} else {
		if this.GetString("comment_author") != "" {
			comment.CommentAuthor = this.GetString("comment_author")
		}
		if this.GetString("comment_author_mail") != "" {
			comment.CommentAuthorMail = this.GetString("comment_author_mail")
		}
		if this.GetString("comment_author_url") != "" {
			comment.CommentAuthorUrl = this.GetString("comment_author_url")
		}
	}
	comment.CommentAuthorIp = this.Ctx.Input.IP()
	comment.CommentContent = content
	comment.CommentAgent = this.Ctx.Request.UserAgent()
	comment.CommentParentId = int_comment_parent_id

	post := models.NewPost()
	post.PostId = int_post_id
	comment.Post = post

	comment_id, err := models.NewCommentModel().AddComment(comment)
	if err != nil {
		panic(err)
	}

	if logged_user == nil {
		this.Ctx.SetSecureCookie(COOKIE_SECURE_KEY_COMMENT, COOKIE_NAME_COMMENT_AUTHOR, comment.CommentAuthor)
		this.Ctx.SetSecureCookie(COOKIE_SECURE_KEY_COMMENT, COOKIE_NAME_COMMENT_AUTHOR_MAIL, comment.CommentAuthorMail)
		this.Ctx.SetSecureCookie(COOKIE_SECURE_KEY_COMMENT, COOKIE_NAME_COMMENT_AUTHOR_URL, comment.CommentAuthorUrl)
	}

	ret := struct {
		Code    int
		Message string
		Data    int64
	}{0, "success", comment_id}
	this.Data["json"] = &ret
	this.ServeJSON()
}