Search in sources :

Example 16 with Contents

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;
}
Also used : Contents(com.tale.model.Contents) InterpretContext(jetbrick.template.runtime.InterpretContext)

Example 17 with Contents

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;
}
Also used : Take(com.blade.jdbc.core.Take) Contents(com.tale.model.Contents) TipException(com.tale.exception.TipException)

Example 18 with Contents

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";
}
Also used : Take(com.blade.jdbc.core.Take) Contents(com.tale.model.Contents)

Example 19 with Contents

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";
}
Also used : Metas(com.tale.model.Metas) Contents(com.tale.model.Contents)

Example 20 with Contents

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");
}
Also used : Take(com.blade.jdbc.core.Take) Contents(com.tale.model.Contents)

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