// 删除link func link_ajaxDel(ctx *goku.HttpContext) goku.ActionResulter { var errs string var ok = false linkId, err := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64) if err == nil { user := ctx.Data["user"].(*models.User) link, err := models.Link_GetById(linkId) if err == nil { // 只可以删除自己的链接 if link.UserId == user.Id { err = models.Link_DelById(linkId) if err == nil { ok = true } } else { errs = "不允许的操作" } } } if err != nil { errs = err.Error() } r := map[string]interface{}{ "success": ok, "errors": errs, } return ctx.Json(r) }
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]) }