use of com.tale.model.Contents in project tale by otale.
the class Theme method current_article.
/**
* 获取当前上下文的文章对象
*
* @return
*/
private static Contents current_article() {
InterpretContext ctx = InterpretContext.current();
Object value = ctx.getValueStack().getValue("article");
if (null != value) {
return (Contents) value;
}
return null;
}
use of com.tale.model.Contents in project tale by otale.
the class ContentsServiceImpl method publish.
@Override
public Integer publish(Contents contents) {
if (null == contents)
throw new TipException("文章对象为空");
if (StringKit.isBlank(contents.getTitle()))
throw new TipException("文章标题不能为空");
if (contents.getTitle().length() > TaleConst.MAX_TITLE_COUNT) {
throw new TipException("文章标题最多可以输入" + TaleConst.MAX_TITLE_COUNT + "个字符");
}
if (StringKit.isBlank(contents.getContent()))
throw new TipException("文章内容不能为空");
// 最多可以输入5w个字
if (contents.getContent().length() > TaleConst.MAX_TEXT_COUNT)
throw new TipException("文章内容最多可以输入" + TaleConst.MAX_TEXT_COUNT + "个字符");
if (null == contents.getAuthor_id())
throw new TipException("请登录后发布文章");
if (StringKit.isNotBlank(contents.getSlug())) {
if (contents.getSlug().length() < 5) {
throw new TipException("路径太短了");
}
if (!TaleUtils.isPath(contents.getSlug()))
throw new TipException("您输入的路径不合法");
int count = activeRecord.count(new Take(Contents.class).eq("type", contents.getType()).eq("slug", contents.getSlug()));
if (count > 0)
throw new TipException("该路径已经存在,请重新输入");
}
contents.setContent(EmojiParser.parseToAliases(contents.getContent()));
int time = DateKit.getCurrentUnixTime();
contents.setCreated(time);
contents.setModified(time);
String tags = contents.getTags();
String categories = contents.getCategories();
Integer cid = activeRecord.insert(contents);
metasService.saveMetas(cid, tags, Types.TAG);
metasService.saveMetas(cid, categories, Types.CATEGORY);
return cid;
}
use of com.tale.model.Contents in project tale by otale.
the class ArticleController method index.
/**
* 文章管理首页
* @param page
* @param limit
* @param request
* @return
*/
@Route(value = "", method = HttpMethod.GET)
public String index(@QueryParam(value = "page", defaultValue = "1") int page, @QueryParam(value = "limit", defaultValue = "15") int limit, Request request) {
Paginator<Contents> contentsPaginator = contentsService.getArticles(new Take(Contents.class).eq("type", Types.ARTICLE).page(page, limit, "created desc"));
request.attribute("articles", contentsPaginator);
return "admin/article_list";
}
use of com.tale.model.Contents in project tale by otale.
the class ArticleController method editArticle.
/**
* 文章编辑页面
* @param cid
* @param request
* @return
*/
@Route(value = "/:cid", method = HttpMethod.GET)
public String editArticle(@PathParam String cid, Request request) {
Contents contents = contentsService.getContents(cid);
request.attribute("contents", contents);
List<Metas> categories = metasService.getMetas(Types.CATEGORY);
request.attribute("categories", categories);
request.attribute("active", "article");
request.attribute(Types.ATTACH_URL, Commons.site_option(Types.ATTACH_URL, Commons.site_url()));
return "admin/article_edit";
}
use of com.tale.model.Contents in project tale by otale.
the class IndexController method index.
/**
* 首页分页
*
* @param request
* @param pageIndex
* @param limit
* @return
*/
@Route(values = { "page/:p", "page/:pageIndex.html" }, method = HttpMethod.GET)
public String index(Request request, @PathParam int pageIndex, @QueryParam(value = "limit", defaultValue = "12") int limit) {
pageIndex = pageIndex < 0 || pageIndex > TaleConst.MAX_PAGE ? 1 : pageIndex;
Take take = new Take(Contents.class).eq("type", Types.ARTICLE).eq("status", Types.PUBLISH).page(pageIndex, limit, "created desc");
Paginator<Contents> articles = contentsService.getArticles(take);
request.attribute("articles", articles);
if (pageIndex > 1) {
this.title(request, "第" + pageIndex + "页");
}
request.attribute("is_home", true);
request.attribute("page_prefix", "/page");
return this.render("index");
}
Aggregations