コード例 #1
0
 public NutMap _topic(Topic topic, Map<Integer, UserProfile> authors, String mdrender) {
   yvrService.fillTopic(topic, authors);
   NutMap tp = new NutMap();
   tp.put("id", topic.getId());
   tp.put("author_id", "" + topic.getAuthor().getUserId());
   tp.put("tab", topic.getType().toString());
   tp.put(
       "content",
       "false".equals(mdrender)
           ? topic.getContent()
           : Markdowns.toHtml(topic.getContent(), urlbase));
   tp.put("title", StringEscapeUtils.unescapeHtml(topic.getTitle()));
   if (topic.getLastComment() != null)
     tp.put("last_reply_at", _time(topic.getLastComment().getCreateTime()));
   tp.put("good", topic.isGood());
   tp.put("top", topic.isTop());
   tp.put("reply_count", topic.getReplyCount());
   tp.put("visit_count", topic.getVisitCount());
   tp.put("create_at", _time(topic.getCreateTime()));
   UserProfile profile = topic.getAuthor();
   if (profile != null) {
     profile.setScore(yvrService.getUserScore(topic.getUserId()));
   }
   tp.put("author", _author(profile));
   return tp;
 }
コード例 #2
0
  /**
   * @api {get} /yvr/api/v1/topic/:id 获取帖子的详细数据
   * @apiGroup Topic
   * @apiVersion 1.0.0
   * @apiParam {String} id 帖子id
   * @apiParam {boolean} [mdrender=true] 是否渲染Markdown
   * @apiSuccess {Object[]} data 帖子数据
   * @apiSuccess {String} data.id 唯一标示符
   * @apiSuccess {String} data.title 标题
   * @apiSuccess {String} data.tab 类型
   * @apiSuccess {String} data.content 内容
   * @apiSuccess {String} [data.last_reply_at] 最后回复时间
   * @apiSuccess {boolean} data.top 是否置顶
   * @apiSuccess {boolean} data.good 是否为精华帖
   * @apiSuccess {int} data.reply_count 总回复数量
   * @apiSuccess {int} data.visit_count 总浏览数量
   * @apiSuccess {Object} data.author 作者信息
   * @apiSuccess {String} data.author.id 作者id
   * @apiSuccess {String} data.author.loginname 作者登陆名
   * @apiSuccess {Object[]} [data.replies] 回复列表
   * @apiSuccess {String} data.replies.id 回复id
   * @apiSuccess {String} data.replies.author 回复的作者
   * @apiSuccess {String} data.replies.author.id 回复的作者的id
   * @apiSuccess {String} data.replies.author.loginname 回复的作者的登陆名称
   * @apiSuccess {String} data.replies.content 回复的内容
   * @apiSuccess {String[]} data.replies.ups 点赞数
   * @apiSuccess {Object} data.replies.author 回帖作者信息
   * @apiSuccess {String} data.replies.create_at 回帖时间
   * @apiSuccess {String} data.replies.author.id 作者id
   * @apiSuccess {String} data.replies.author.loginname 作者登陆名
   * @apiError 404 The <code>id</code> of the Topic was not found.
   */
  @Aop("redis")
  @GET
  @At("/topic/?")
  public Object topic(String id, @Param("mdrender") String mdrender) {
    Topic topic = dao.fetch(Topic.class, id);
    if (id == null) {
      return HttpStatusView.HTTP_404;
    }
    NutMap tp = _topic(topic, new HashMap<Integer, UserProfile>(), mdrender);

    List<NutMap> replies = new ArrayList<NutMap>();
    for (TopicReply reply :
        dao.query(TopicReply.class, Cnd.where("topicId", "=", id).asc("createTime"))) {
      dao.fetchLinks(reply, null);
      reply.setUps(jedis().zrange(RKEY_REPLY_LIKE + reply.getId(), 0, System.currentTimeMillis()));

      NutMap re = new NutMap();
      re.put("id", reply.getId());
      re.put("author", _author(reply.getAuthor()));

      re.put(
          "content",
          "false".equals(mdrender)
              ? reply.getContent()
              : Markdowns.toHtml(reply.getContent(), urlbase));
      re.put("ups", new ArrayList<String>(reply.getUps()));
      re.put("create_at", _time(reply.getCreateTime()));
      replies.add(re);
    }

    tp.put("replies", replies);

    jedis().zincrby(RKEY_TOPIC_VISIT, 1, topic.getId());
    return _map("data", tp);
  }
コード例 #3
0
  /** 全文输出 */
  @At
  @Ok("raw:xml")
  public String rss() throws IOException, FeedException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    String urlbase = conf.get("website.urlbase", "https://nutz.cn");
    feed.setLink(urlbase);
    feed.setTitle(conf.get("website.title", "Nutz社区"));
    feed.setDescription(conf.get("website.description", "一个有爱的社区"));

    feed.setAuthor(conf.get("website.author", "wendal"));
    feed.setEncoding("UTF-8");
    feed.setLanguage("zh-cn");

    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    SyndEntry entry;
    SyndContent description;
    List<Topic> list =
        dao.query(Topic.class, Cnd.orderBy().desc("createTime"), dao.createPager(1, 10));
    for (Topic topic : list) {
      dao.fetchLinks(topic, "author");
      entry = new SyndEntryImpl();
      entry.setTitle(topic.getTitle());
      entry.setLink(urlbase + "/yvr/t/" + topic.getId());
      entry.setPublishedDate(topic.getCreateTime());
      description = new SyndContentImpl();
      description.setType("text/html");
      description.setValue(Markdowns.toHtml(topic.getContent(), urlbase));
      entry.setDescription(description);
      entry.setAuthor(topic.getAuthor().getLoginname());
      entries.add(entry);
    }

    feed.setEntries(entries);
    if (list.size() > 0) {
      feed.setPublishedDate(list.get(0).getCreateTime());
    }

    SyndFeedOutput output = new SyndFeedOutput();
    return output.outputString(feed, true);
  }