Search in sources :

Example 11 with Contents

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

the class ArticleController method publishArticle.

/**
     * 发布文章操作
     *
     * @param title
     * @param content
     * @param tags
     * @param categories
     * @param status
     * @param slug
     * @param allow_comment
     * @param allow_ping
     * @param allow_feed
     * @return
     */
@Route(value = "publish", method = HttpMethod.POST)
@JSON
public RestResponse publishArticle(@QueryParam String title, @QueryParam String content, @QueryParam String tags, @QueryParam String categories, @QueryParam String status, @QueryParam String slug, @QueryParam String fmt_type, @QueryParam String thumb_img, @QueryParam Boolean allow_comment, @QueryParam Boolean allow_ping, @QueryParam Boolean allow_feed) {
    Users users = this.user();
    Contents contents = new Contents();
    contents.setTitle(title);
    contents.setContent(content);
    contents.setStatus(status);
    contents.setSlug(slug);
    contents.setType(Types.ARTICLE);
    contents.setThumb_img(thumb_img);
    contents.setFmt_type(fmt_type);
    if (null != allow_comment) {
        contents.setAllow_comment(allow_comment);
    }
    if (null != allow_ping) {
        contents.setAllow_ping(allow_ping);
    }
    if (null != allow_feed) {
        contents.setAllow_feed(allow_feed);
    }
    contents.setAuthor_id(users.getUid());
    contents.setTags(tags);
    if (StringKit.isBlank(categories)) {
        categories = "默认分类";
    }
    contents.setCategories(categories);
    try {
        Integer cid = contentsService.publish(contents);
        siteService.cleanCache(Types.C_STATISTICS);
        return RestResponse.ok(cid);
    } catch (Exception e) {
        String msg = "文章发布失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}
Also used : Contents(com.tale.model.Contents) Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Example 12 with Contents

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

the class IndexController method index.

/**
     * 仪表盘
     */
@Route(value = { "/", "index" }, method = HttpMethod.GET)
public String index(Request request) {
    List<Comments> comments = siteService.recentComments(5);
    List<Contents> contents = siteService.getContens(Types.RECENT_ARTICLE, 5);
    Statistics statistics = siteService.getStatistics();
    // 取最新的20条日志
    List<Logs> logs = logService.getLogs(1, 20);
    request.attribute("comments", comments);
    request.attribute("articles", contents);
    request.attribute("statistics", statistics);
    request.attribute("logs", logs);
    return "admin/index";
}
Also used : Contents(com.tale.model.Contents) Comments(com.tale.model.Comments) Logs(com.tale.model.Logs) Statistics(com.tale.dto.Statistics) Route(com.blade.mvc.annotation.Route)

Example 13 with Contents

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

the class IndexController method feed.

/**
     * feed页
     *
     * @return
     */
@Route(values = { "feed", "feed.xml" }, method = HttpMethod.GET)
public void feed(Response response) {
    Paginator<Contents> contentsPaginator = contentsService.getArticles(new Take(Contents.class).eq("type", Types.ARTICLE).eq("status", Types.PUBLISH).eq("allow_feed", true).page(1, TaleConst.MAX_POSTS, "created desc"));
    try {
        String xml = TaleUtils.getRssXml(contentsPaginator.getList());
        response.xml(xml);
    } catch (Exception e) {
        LOGGER.error("生成RSS失败", e);
    }
}
Also used : Take(com.blade.jdbc.core.Take) Contents(com.tale.model.Contents) TipException(com.tale.exception.TipException)

Example 14 with Contents

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

the class IndexController method page.

/**
     * 自定义页面
     */
@Route(values = { "/:pagename", "/:pagename.html" }, method = HttpMethod.GET)
public String page(@PathParam String pagename, Request request) {
    Contents contents = contentsService.getContents(pagename);
    if (null == contents) {
        return this.render_404();
    }
    if (contents.getAllow_comment()) {
        int cp = request.queryInt("cp", 1);
        request.attribute("cp", cp);
    }
    request.attribute("article", contents);
    updateArticleHit(contents.getCid(), contents.getHits());
    if (Types.ARTICLE.equals(contents.getType())) {
        return this.render("post");
    }
    if (Types.PAGE.equals(contents.getType())) {
        return this.render("page");
    }
    return this.render_404();
}
Also used : Contents(com.tale.model.Contents)

Example 15 with Contents

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

the class IndexController method categories.

@Route(values = { "category/:keyword/:page", "category/:keyword/:page.html" }, method = HttpMethod.GET)
public String categories(Request request, @PathParam String keyword, @PathParam int page, @QueryParam(value = "limit", defaultValue = "12") int limit) {
    page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
    MetaDto metaDto = metasService.getMeta(Types.CATEGORY, keyword);
    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", keyword);
    request.attribute("is_category", true);
    request.attribute("page_prefix", "/category/" + keyword);
    return this.render("page-category");
}
Also used : MetaDto(com.tale.dto.MetaDto) 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