use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class IndexProcessor method showRecent.
/**
* Shows recent articles.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = { "/recent", "/recent/hot", "/recent/good", "/recent/reply" }, method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, AnonymousViewCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showRecent(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("recent.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
String pageNumStr = request.getParameter("p");
if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
pageNumStr = "1";
}
final int pageNum = Integer.valueOf(pageNumStr);
int pageSize = Symphonys.getInt("indexArticlesCnt");
final JSONObject user = userQueryService.getCurrentUser(request);
if (null != user) {
pageSize = user.optInt(UserExt.USER_LIST_PAGE_SIZE);
if (!UserExt.finshedGuide(user)) {
response.sendRedirect(Latkes.getServePath() + "/guide");
return;
}
}
final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
String sortModeStr = StringUtils.substringAfter(request.getRequestURI(), "/recent");
int sortMode;
switch(sortModeStr) {
case "":
sortMode = 0;
break;
case "/hot":
sortMode = 1;
break;
case "/good":
sortMode = 2;
break;
case "/reply":
sortMode = 3;
break;
default:
sortMode = 0;
}
dataModel.put(Common.SELECTED, Common.RECENT);
final JSONObject result = articleQueryService.getRecentArticles(avatarViewMode, sortMode, pageNum, pageSize);
final List<JSONObject> allArticles = (List<JSONObject>) result.get(Article.ARTICLES);
final List<JSONObject> stickArticles = new ArrayList<>();
final Iterator<JSONObject> iterator = allArticles.iterator();
while (iterator.hasNext()) {
final JSONObject article = iterator.next();
final boolean stick = article.optInt(Article.ARTICLE_T_STICK_REMAINS) > 0;
article.put(Article.ARTICLE_T_IS_STICK, stick);
if (stick) {
stickArticles.add(article);
iterator.remove();
}
}
dataModel.put(Common.STICK_ARTICLES, stickArticles);
dataModel.put(Common.LATEST_ARTICLES, allArticles);
final JSONObject pagination = result.getJSONObject(Pagination.PAGINATION);
final int pageCount = pagination.optInt(Pagination.PAGINATION_PAGE_COUNT);
final List<Integer> pageNums = (List<Integer>) pagination.get(Pagination.PAGINATION_PAGE_NUMS);
if (!pageNums.isEmpty()) {
dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.get(0));
dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.get(pageNums.size() - 1));
}
dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
dataModel.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
dataModelService.fillRandomArticles(avatarViewMode, dataModel);
dataModelService.fillSideHotArticles(avatarViewMode, dataModel);
dataModelService.fillSideTags(dataModel);
dataModelService.fillLatestCmts(dataModel);
dataModel.put(Common.CURRENT, StringUtils.substringAfter(request.getRequestURI(), "/recent"));
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class IndexProcessor method showIndex.
/**
* Shows index.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = { "", "/" }, method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showIndex(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("index.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
final List<JSONObject> recentArticles = articleQueryService.getIndexRecentArticles(avatarViewMode);
dataModel.put(Common.RECENT_ARTICLES, recentArticles);
JSONObject currentUser = userQueryService.getCurrentUser(request);
if (null == currentUser) {
userMgmtService.tryLogInWithCookie(request, context.getResponse());
}
currentUser = userQueryService.getCurrentUser(request);
if (null != currentUser) {
if (!UserExt.finshedGuide(currentUser)) {
response.sendRedirect(Latkes.getServePath() + "/guide");
return;
}
final String userId = currentUser.optString(Keys.OBJECT_ID);
final int pageSize = Symphonys.getInt("indexArticlesCnt");
final List<JSONObject> followingTagArticles = articleQueryService.getFollowingTagArticles(avatarViewMode, userId, 1, pageSize);
dataModel.put(Common.FOLLOWING_TAG_ARTICLES, followingTagArticles);
final List<JSONObject> followingUserArticles = articleQueryService.getFollowingUserArticles(avatarViewMode, userId, 1, pageSize);
dataModel.put(Common.FOLLOWING_USER_ARTICLES, followingUserArticles);
} else {
dataModel.put(Common.FOLLOWING_TAG_ARTICLES, Collections.emptyList());
dataModel.put(Common.FOLLOWING_USER_ARTICLES, Collections.emptyList());
}
final List<JSONObject> perfectArticles = articleQueryService.getIndexPerfectArticles(avatarViewMode);
dataModel.put(Common.PERFECT_ARTICLES, perfectArticles);
dataModel.put(Common.SELECTED, Common.INDEX);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
dataModelService.fillIndexTags(dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class IndexProcessor method showB3log.
/**
* Shows b3log.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/b3log", method = HTTPRequestMethod.GET)
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showB3log(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("other/b3log.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModelService.fillHeaderAndFooter(request, response, dataModel);
final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
dataModelService.fillRandomArticles(avatarViewMode, dataModel);
dataModelService.fillSideHotArticles(avatarViewMode, dataModel);
dataModelService.fillSideTags(dataModel);
dataModelService.fillLatestCmts(dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class LinkForgeProcessor method showLinkForge.
/**
* Shows link forge.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/forge/link", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showLinkForge(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("other/link-forge.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
final List<JSONObject> tags = linkForgeQueryService.getForgedLinks();
dataModel.put(Tag.TAGS, (Object) tags);
dataModel.put(Common.SELECTED, Common.FORGE);
final JSONObject statistic = optionQueryService.getStatistic();
final int tagCnt = statistic.optInt(Option.ID_C_STATISTIC_TAG_COUNT);
dataModel.put(Tag.TAG_T_COUNT, tagCnt);
final int linkCnt = statistic.optInt(Option.ID_C_STATISTIC_LINK_COUNT);
dataModel.put(Link.LINK_T_COUNT, linkCnt);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class LoginProcessor method showGuide.
/**
* Shows login page.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/guide", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, LoginCheck.class })
@After(adviceClass = { CSRFToken.class, PermissionGrant.class, StopwatchEndAdvice.class })
public void showGuide(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
final int step = currentUser.optInt(UserExt.USER_GUIDE_STEP);
if (UserExt.USER_GUIDE_STEP_FIN == step) {
response.sendRedirect(Latkes.getServePath());
return;
}
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("/verify/guide.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Common.CURRENT_USER, currentUser);
final List<JSONObject> tags = tagQueryService.getTags(32);
dataModel.put(Tag.TAGS, tags);
final List<JSONObject> users = userQueryService.getNiceUsers(6);
final Iterator<JSONObject> iterator = users.iterator();
while (iterator.hasNext()) {
final JSONObject user = iterator.next();
if (user.optString(Keys.OBJECT_ID).equals(currentUser.optString(Keys.OBJECT_ID))) {
iterator.remove();
break;
}
}
dataModel.put(User.USERS, users);
// Qiniu file upload authenticate
final Auth auth = Auth.create(Symphonys.get("qiniu.accessKey"), Symphonys.get("qiniu.secretKey"));
final String uploadToken = auth.uploadToken(Symphonys.get("qiniu.bucket"));
dataModel.put("qiniuUploadToken", uploadToken);
dataModel.put("qiniuDomain", Symphonys.get("qiniu.domain"));
if (!Symphonys.getBoolean("qiniu.enabled")) {
dataModel.put("qiniuUploadToken", "");
}
final long imgMaxSize = Symphonys.getLong("upload.img.maxSize");
dataModel.put("imgMaxSize", imgMaxSize);
final long fileMaxSize = Symphonys.getLong("upload.file.maxSize");
dataModel.put("fileMaxSize", fileMaxSize);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Aggregations