func (as *ArticleService) msgDelete(id int64) { article := new(model.Article) if _, err := core.Db.Where("id = ?", id).Get(article); err != nil { return } if article == nil || article.Id != id { return } data := map[string]string{ "type": fmt.Sprint(model.MESSAGE_TYPE_ARTICLE_REMOVE), "author": article.User().Name, "title": article.Title, "time": utils.TimeUnixFormat(article.CreateTime, "01/02 15:04:05"), } body := com.Expand(MessageArticleRemoveTemplate, data) message := &model.Message{ UserId: article.UserId, From: model.MESSAGE_FROM_ARTICLE, FromId: article.Id, Type: model.MESSAGE_TYPE_ARTICLE_REMOVE, Body: body, CreateTime: article.CreateTime, } Message.Save(message) }
func (as *ArticleService) msgWrite(isUpdate bool, article *model.Article) { data := map[string]string{ "type": fmt.Sprint(model.MESSAGE_TYPE_ARTICLE_CREATE), "author": article.User().Name, "link": article.Href(), "title": article.Title, "time": utils.TimeUnixFormat(article.CreateTime, "01/02 15:04:05"), } var body string if isUpdate { data["type"] = fmt.Sprint(model.MESSAGE_TYPE_ARTICLE_UPDATE) data["time"] = utils.TimeUnixFormat(article.UpdateTime, "01/02 15:04:05") body = com.Expand(MessageArticleUpdateTemplate, data) } else { body = com.Expand(MessageArticleCreateTemplate, data) } message := &model.Message{ UserId: article.UserId, From: model.MESSAGE_FROM_ARTICLE, FromId: article.Id, Type: model.MESSAGE_TYPE_ARTICLE_CREATE, Body: body, CreateTime: article.CreateTime, } if isUpdate { message.Type = model.MESSAGE_TYPE_ARTICLE_UPDATE } Message.Save(message) }
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") }
func (as *ArticleService) Read(v interface{}) (*Result, error) { opt, ok := v.(ArticleReadOption) if !ok { return nil, ErrServiceFuncNeedType(as.Read, opt) } whereStr, whereArgs := opt.toWhereString() a := new(model.Article) if _, err := core.Db.Where(whereStr, whereArgs...).Get(a); err != nil { return nil, err } if a.Id == 0 { return nil, ErrArticleNotFound } if opt.IsPublish && !a.IsPublish() { return nil, ErrArticleNotFound } if opt.IsHit { if _, err := core.Db.Exec("UPDATE article SET hits = hits + 1 WHERE id = ?", a.Id); err != nil { return nil, err } } return newResult(as.Read, a), nil }