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);
}
}
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");
}
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");
}
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");
}
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();
}
Aggregations