func link_showWithComments(ctx *goku.HttpContext, slinkId, scommentId string) goku.ActionResulter { linkId, err1 := strconv.ParseInt(slinkId, 10, 64) commentId, err2 := strconv.ParseInt(scommentId, 10, 64) if err1 != nil || err2 != nil { ctx.ViewData["errorMsg"] = "参数错误" return ctx.Render("error", nil) } link, err := models.Link_GetById(linkId) if err != nil { ctx.ViewData["errorMsg"] = "服务器开小差了 >_<!!" return ctx.Render("error", nil) } if link == nil { ctx.ViewData["errorMsg"] = "内容不存在,去首页逛逛吧" return ctx.Render("error", nil) } if link.Deleted() { ctx.ViewData["errorMsg"] = "内容已被摧毁,去首页逛逛吧" return ctx.Render("error", nil) } if !utils.IsSpider(ctx.Request.UserAgent()) { // 更新链接的评论查看计数 models.Link_IncViewCount(link.Id, 1) } vlink := models.Link_ToVLink([]models.Link{*link}, ctx) sortType := strings.ToLower(ctx.Get("cm_order")) //"hot":热门;"hotc":热议;"time":最新;"vote":得分;"ctvl":"争议" if sortType == "" { sortType = "hot" } var comments string if commentId > 0 { comments = models.GetPermalinkComment(linkId, commentId, sortType) ctx.ViewData["SubLinkUrl"] = fmt.Sprintf("permacoment/%d/%d/", linkId, commentId) } else { comments = models.GetSortComments("", "/", int64(0), linkId, sortType, "", false) //models.Comment_SortForLink(link.Id, "hot") ctx.ViewData["SubLinkUrl"] = linkId } ctx.ViewData["Comments"] = template.HTML(comments) ctx.ViewData["SortType"] = sortType ctx.ViewData["SortTypeName"] = ORDER_NAMES[sortType] return ctx.Render("/link/show", vlink[0]) }
/** * 加载更多评论 */ func comment_LoadMore(ctx *goku.HttpContext) goku.ActionResulter { htmlObject := CommentHtml{""} exceptIds := ctx.Get("except_ids") fmt.Println("exceptIds:", exceptIds) parentPath := ctx.Get("parent_path") sortType := ctx.Get("sort_type") topId, err1 := strconv.ParseInt(ctx.Get("top_parent_id"), 10, 64) linkId, err2 := strconv.ParseInt(ctx.Get("link_id"), 10, 64) if err1 == nil && err2 == nil { htmlObject.Html = models.GetSortComments(exceptIds, parentPath, topId, linkId, sortType, "", true) } return ctx.Json(htmlObject) }
//"github.com/QLeelulu/ohlala/golink" //"html/template" ) type CommentHtml struct { Html string } /** * 追加评论 */ var _ = goku.Controller("comment"). /** * 追加评论 */ Post("loadmore", func(ctx *goku.HttpContext) goku.ActionResulter { htmlObject := CommentHtml{""} exceptIds := ctx.Get("except_ids") fmt.Println("exceptIds:", exceptIds) parentPath := ctx.Get("parent_path") sortType := ctx.Get("sort_type") topId, err1 := strconv.ParseInt(ctx.Get("top_parent_id"), 10, 64) linkId, err2 := strconv.ParseInt(ctx.Get("link_id"), 10, 64) if err1 == nil && err2 == nil { htmlObject.Html = models.GetSortComments(exceptIds, parentPath, topId, linkId, sortType, "", true) } return ctx.Json(htmlObject) })