Search in sources :

Example 21 with Contents

use of com.tale.model.Contents in project tale by otale.

the class IndexController method updateArticleHit.

private void updateArticleHit(Integer cid, Integer chits) {
    Integer hits = cache.hget(Types.C_ARTICLE_HITS, cid.toString());
    hits = null == hits ? 1 : hits + 1;
    if (hits >= TaleConst.HIT_EXCEED) {
        Contents temp = new Contents();
        temp.setCid(cid);
        temp.setHits(chits + hits);
        contentsService.update(temp);
        cache.hset(Types.C_ARTICLE_HITS, cid.toString(), 1);
    } else {
        cache.hset(Types.C_ARTICLE_HITS, cid.toString(), hits);
    }
}
Also used : Contents(com.tale.model.Contents)

Example 22 with Contents

use of com.tale.model.Contents in project tale by otale.

the class IndexController method post.

/**
     * 文章页
     */
@Route(values = { "article/:cid", "article/:cid.html" }, method = HttpMethod.GET)
public String post(Request request, @PathParam String cid) {
    Contents contents = contentsService.getContents(cid);
    if (null == contents) {
        return this.render_404();
    }
    request.attribute("article", contents);
    request.attribute("is_post", true);
    if (contents.getAllow_comment()) {
        int cp = request.queryInt("cp", 1);
        request.attribute("cp", cp);
    }
    updateArticleHit(contents.getCid(), contents.getHits());
    return this.render("post");
}
Also used : Contents(com.tale.model.Contents)

Example 23 with Contents

use of com.tale.model.Contents in project tale by otale.

the class IndexController method search.

@Route(values = { "search/:keyword/:page", "search/:keyword/:page.html" }, method = HttpMethod.GET)
public String search(Request request, @PathParam String keyword, @PathParam int page, @QueryParam(value = "limit", defaultValue = "12") int limit) {
    page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
    Take take = new Take(Contents.class).eq("type", Types.ARTICLE).eq("status", Types.PUBLISH).like("title", "%" + keyword + "%").page(page, limit, "created desc");
    Paginator<Contents> articles = contentsService.getArticles(take);
    request.attribute("articles", articles);
    request.attribute("type", "搜索");
    request.attribute("keyword", keyword);
    request.attribute("page_prefix", "/search/" + keyword);
    return this.render("page-category");
}
Also used : Take(com.blade.jdbc.core.Take) Contents(com.tale.model.Contents)

Example 24 with Contents

use of com.tale.model.Contents in project tale by otale.

the class IndexController method tags.

/**
     * 标签分页
     *
     * @param request
     * @param name
     * @param page
     * @param limit
     * @return
     */
@Route(values = { "tag/:name/:page", "tag/:name/:page.html" }, method = HttpMethod.GET)
public String tags(Request request, @PathParam String name, @PathParam int page, @QueryParam(value = "limit", defaultValue = "12") int limit) {
    page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
    MetaDto metaDto = metasService.getMeta(Types.TAG, name);
    if (null == metaDto) {
        return this.render_404();
    }
    Paginator<Contents> contentsPaginator = contentsService.getArticles(metaDto.getMid(), page, limit);
    request.attribute("articles", contentsPaginator);
    request.attribute("meta", metaDto);
    request.attribute("type", "标签");
    request.attribute("keyword", name);
    request.attribute("is_tag", true);
    request.attribute("page_prefix", "/tag/" + name);
    return this.render("page-category");
}
Also used : MetaDto(com.tale.dto.MetaDto) Contents(com.tale.model.Contents)

Example 25 with Contents

use of com.tale.model.Contents in project tale by otale.

the class PageController method publishPage.

@Route(value = "publish", method = HttpMethod.POST)
@JSON
public RestResponse publishPage(@QueryParam String title, @QueryParam String content, @QueryParam String status, @QueryParam String slug, @QueryParam String fmt_type, @QueryParam Boolean allow_comment) {
    Users users = this.user();
    Contents contents = new Contents();
    contents.setTitle(title);
    contents.setContent(content);
    contents.setStatus(status);
    contents.setSlug(slug);
    contents.setFmt_type(fmt_type);
    contents.setType(Types.PAGE);
    contents.setAllow_comment(allow_comment);
    contents.setAllow_ping(true);
    contents.setAuthor_id(users.getUid());
    try {
        contentsService.publish(contents);
        siteService.cleanCache(Types.C_STATISTICS);
    } catch (Exception e) {
        String msg = "页面发布失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Contents(com.tale.model.Contents) Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Aggregations

Contents (com.tale.model.Contents)26 TipException (com.tale.exception.TipException)8 Take (com.blade.jdbc.core.Take)7 Users (com.tale.model.Users)4 Paginator (com.blade.jdbc.model.Paginator)2 MetaDto (com.tale.dto.MetaDto)2 Metas (com.tale.model.Metas)2 InterpretContext (jetbrick.template.runtime.InterpretContext)2 PageRow (com.blade.jdbc.model.PageRow)1 Route (com.blade.mvc.annotation.Route)1 Statistics (com.tale.dto.Statistics)1 Comments (com.tale.model.Comments)1 Logs (com.tale.model.Logs)1 Relationships (com.tale.model.Relationships)1