Search in sources :

Example 1 with Contents

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

the class IndexController method index.

/**
 * 仪表盘
 */
@GetRoute(value = { "/", "index" })
public String index(Request request) {
    List<Comments> comments = siteService.recentComments(5);
    List<Contents> contents = siteService.getContens(Types.RECENT_ARTICLE, 5);
    Statistics statistics = siteService.getStatistics();
    request.attribute("comments", comments);
    request.attribute("articles", contents);
    request.attribute("statistics", statistics);
    return "admin/index";
}
Also used : Contents(com.tale.model.entity.Contents) Comments(com.tale.model.entity.Comments) Statistics(com.tale.model.dto.Statistics) GetRoute(com.blade.mvc.annotation.GetRoute)

Example 2 with Contents

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

the class Theme method comments.

/**
 * 获取当前文章/页面的评论
 *
 * @param limit
 * @return
 */
public static Page<Comment> comments(int limit) {
    Contents contents = current_article();
    if (null == contents) {
        return new Page<>();
    }
    InterpretContext ctx = InterpretContext.current();
    Object value = ctx.getValueStack().getValue("cp");
    int page = 1;
    if (null != value) {
        page = (int) value;
    }
    Page<Comment> comments = siteService.getComments(contents.getCid(), page, limit);
    return comments;
}
Also used : Comment(com.tale.model.dto.Comment) Contents(com.tale.model.entity.Contents) InterpretContext(jetbrick.template.runtime.InterpretContext) Page(io.github.biezhi.anima.page.Page)

Example 3 with Contents

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

the class Theme method show_tags.

/**
 * 显示标签
 *
 * @param split 每个标签之间的分隔符
 * @return
 */
public static String show_tags(String split) throws UnsupportedEncodingException {
    Contents contents = current_article();
    if (StringKit.isNotBlank(contents.getTags())) {
        String[] arr = contents.getTags().split(",");
        StringBuffer sbuf = new StringBuffer();
        for (String c : arr) {
            sbuf.append(split).append("<a href=\"/tag/" + URLEncoder.encode(c, "UTF-8") + "\">" + c + "</a>");
        }
        return split.length() > 0 ? sbuf.substring(split.length() - 1) : sbuf.toString();
    }
    return "";
}
Also used : Contents(com.tale.model.entity.Contents)

Example 4 with Contents

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

the class Theme method articles.

/**
 * 分页
 *
 * @param limit
 * @return
 */
public static Page<Contents> articles(int limit) {
    Request request = WebContext.request();
    Integer page = request.attribute("page_num");
    page = null == page ? request.queryInt("page", 1) : page;
    page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
    Page<Contents> articles = select().from(Contents.class).where(Contents::getType, Types.ARTICLE).and("status", Types.PUBLISH).order(Contents::getCreated, OrderBy.DESC).page(page, limit);
    request.attribute("articles", articles);
    if (page > 1) {
        WebContext.request().attribute("title", "第" + page + "页");
    }
    request.attribute("is_home", true);
    request.attribute("page_prefix", "/page");
    return articles;
}
Also used : Contents(com.tale.model.entity.Contents) Request(com.blade.mvc.http.Request)

Example 5 with Contents

use of com.tale.model.entity.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.entity.Contents) InterpretContext(jetbrick.template.runtime.InterpretContext)

Aggregations

Contents (com.tale.model.entity.Contents)14 GetRoute (com.blade.mvc.annotation.GetRoute)3 ValidatorException (com.blade.exception.ValidatorException)2 Comments (com.tale.model.entity.Comments)2 Metas (com.tale.model.entity.Metas)2 InterpretContext (jetbrick.template.runtime.InterpretContext)2 Request (com.blade.mvc.http.Request)1 Comment (com.tale.model.dto.Comment)1 Statistics (com.tale.model.dto.Statistics)1 Page (io.github.biezhi.anima.page.Page)1