Example #1
0
func CommentCreate(rw http.ResponseWriter, req *http.Request) {
	fmt.Println("path", req.URL.Path)

	req.ParseForm()
	postId := hgForm.GetInt64(req, "postId", 0)
	people := isLogin(req)

	content := req.FormValue("content")
	post := postModel.Find(postId)

	if people == nil || post == nil {
		http.Redirect(rw, req, "/post/item/?postId="+req.FormValue("postId"), http.StatusFound)
		return
	}

	var comment model.Comment
	comment.Idpost = postId
	comment.Content = content
	comment.Author.Idpeople = people.Idpeople
	comment.Parent = 0
	commentModel.Insert(comment)

	http.Redirect(rw, req, "/post/item/?postId="+req.FormValue("postId"), http.StatusFound)
	//更新回复数
	postModel.UpdateReplyNum(*post)
}
Example #2
0
func PeopleUcenter(rw http.ResponseWriter, req *http.Request) {
	people := isLogin(req)

	idpeople := hgForm.GetInt64(req, "idpeople", 0)

	tmpl := template.New("people-ucenter")
	tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal})
	tmpl.ParseFiles(
		"template/front/header.tmpl",
		"template/front/people-ucenter.tmpl",
		"template/front/footer.tmpl",
		"template/front/people-ucenter-sidebar.tmpl")

	tmplInfo := hgTemplate.TmplInfo{}
	tmplInfo.AddData("people", people)

	if idpeople != 0 {
		vpeople := peopleModel.Find(idpeople)
		tmplInfo.AddData("vpeople", vpeople)
	} else {
		tmplInfo.AddData("vpeople", people)
	}

	tmplInfo.Js = []string{
		"js/jquery.validate.js"}

	tmpl.ExecuteTemplate(rw, "people-ucenter", map[string]interface{}{"tmplInfo": tmplInfo})

}
Example #3
0
/*
 *	文章分页列表
 */
func PostPage(rw http.ResponseWriter, req *http.Request) {
	postClasses := postClassModel.FindAll()
	people := isLogin(req)

	req.ParseForm()
	pageSize := 10
	page := hgForm.GetInt(req, "page", 1)

	conditions := make(map[string]string)
	pageHelper := hgPageination.Page{}

	//IdpostClass, err := strconv.ParseInt(req.FormValue("cat"), 10, 64)
	IdpostClass := hgForm.GetInt64(req, "cat", 0)

	if IdpostClass != 0 {
		conditions["post.idpost_class ="] = req.FormValue("cat")
		pageHelper.BaseUrl = "/post/?cat=" + req.FormValue("cat") + "&page="
	} else {
		pageHelper.BaseUrl = "/post/?page="
	}

	postClass := postClassModel.Find(IdpostClass)

	if postClass == nil {
		//出错处理
	}

	posts, count := postModel.FindAll(page, pageSize, conditions)

	pageHelper.Count = count
	pageHelper.PageSize = pageSize
	pageHelper.PageNum = page
	pageHelper.Compute()

	tmpl := template.New("post-pageView")
	tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal, "IntEqual": hgTemplate.IntEqual, "RemoveHtmlTag": hgTemplate.RemoveHtmlTag})
	tmpl.ParseFiles(
		"template/front/header.tmpl",
		"template/front/post-list.tmpl",
		"template/front/footer.tmpl",
		"template/front/page.tmpl",
		"template/front/sidebar.tmpl")

	tmplInfo := hgTemplate.TmplInfo{}
	tmplInfo.Js = []string{
		"kindeditor/kindeditor-min.js",
		"kindeditor/lang/zh_CN.js"}
	tmplInfo.CurrentNav = "article"
	tmplInfo.Title = "Hello Golang -文章"
	tmplInfo.Description = "全新的go语言资讯!精选的go语言教程!经典的go语言代码!"

	tmplInfo.AddData("people", people)
	tmplInfo.AddData("posts", posts)
	tmplInfo.AddData("pageHelper", pageHelper)
	tmplInfo.AddData("postClasses", postClasses)
	tmplInfo.AddData("postClass", postClass)

	tmpl.ExecuteTemplate(rw, "post-list", map[string]interface{}{"tmplInfo": tmplInfo})
	tmpl.Execute(rw, nil)

}
Example #4
0
/*
 *	查看单个文章页
 */
func PostItem(rw http.ResponseWriter, req *http.Request) {
	postClasses := postClassModel.FindAll()

	req.ParseForm()
	people := isLogin(req)

	page := hgForm.GetInt(req, "page", 1)

	postId := hgForm.GetInt64(req, "postId", 0)
	if postId == 0 {
		//出错
	}

	pageSize := 10
	post := postModel.Find(postId)

	if post == nil {
		fmt.Println("post is nil...")
		//文章不存在
	}

	comments, count := commentModel.FindAllByPostID(postId, page, pageSize)

	pageHelper := hgPageination.Page{}

	pageHelper.BaseUrl = "/post/item/?postId=" + strconv.FormatInt(postId, 10) + "&page="
	pageHelper.Count = count
	pageHelper.PageSize = pageSize
	pageHelper.PageNum = page
	pageHelper.Compute()

	tmpl := template.New("post-itemView")
	tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal, "IntEqual": hgTemplate.IntEqual})
	tmpl.ParseFiles(
		"template/front/header.tmpl",
		"template/front/post-item.tmpl",
		"template/front/footer.tmpl",
		"template/front/page.tmpl",
		"template/front/sidebar.tmpl")

	tmplInfo := hgTemplate.TmplInfo{}
	tmplInfo.Js = []string{
		"js/jquery.validate.js"}

	tmplInfo.CurrentNav = "article"

	tmplInfo.Title = "Hello Golang -" + post.Title
	tmplInfo.Description = post.Title

	tmplInfo.AddData("people", people)
	tmplInfo.AddData("post", post)
	tmplInfo.AddData("pageHelper", pageHelper)
	tmplInfo.AddData("postClasses", postClasses)
	tmplInfo.AddData("comments", comments)

	tmpl.ExecuteTemplate(rw, "post-item", map[string]interface{}{"tmplInfo": tmplInfo})
	tmpl.Execute(rw, nil)

	//更新阅读数
	postModel.UpdateReadNum(*post)
}