Commit 58fa56fb authored by Liang Ding's avatar Liang Ding

Fix #12026

parent 5dcf074a
......@@ -412,12 +412,12 @@ public class ArticleProcessor {
final boolean hasMultipleUsers = userQueryService.hasMultipleUsers();
if (hasMultipleUsers) {
filler.setArticlesExProperties(articles, preference);
filler.setArticlesExProperties(request, articles, preference);
} else {
if (!articles.isEmpty()) {
final JSONObject author = articleQueryService.getAuthor(articles.get(0));
filler.setArticlesExProperties(articles, author, preference);
filler.setArticlesExProperties(request, articles, author, preference);
}
}
......@@ -480,12 +480,12 @@ public class ArticleProcessor {
final boolean hasMultipleUsers = userQueryService.hasMultipleUsers();
if (hasMultipleUsers) {
filler.setArticlesExProperties(articles, preference);
filler.setArticlesExProperties(request, articles, preference);
} else {
if (!articles.isEmpty()) {
final JSONObject author = articleQueryService.getAuthor(articles.get(0));
filler.setArticlesExProperties(articles, author, preference);
filler.setArticlesExProperties(request, articles, author, preference);
}
}
......@@ -551,12 +551,12 @@ public class ArticleProcessor {
final boolean hasMultipleUsers = userQueryService.hasMultipleUsers();
if (hasMultipleUsers) {
filler.setArticlesExProperties(articles, preference);
filler.setArticlesExProperties(request, articles, preference);
} else {
if (!articles.isEmpty()) {
final JSONObject author = articleQueryService.getAuthor(articles.get(0));
filler.setArticlesExProperties(articles, author, preference);
filler.setArticlesExProperties(request, articles, author, preference);
}
}
......@@ -620,7 +620,7 @@ public class ArticleProcessor {
final List<JSONObject> articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize);
if (!articles.isEmpty()) {
filler.setArticlesExProperties(articles, author, preference);
filler.setArticlesExProperties(request, articles, author, preference);
}
final int articleCount = author.getInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT);
......@@ -718,7 +718,7 @@ public class ArticleProcessor {
}
}
filler.setArticlesExProperties(articles, author, preference);
filler.setArticlesExProperties(request, articles, author, preference);
if (preference.optBoolean(Preference.ENABLE_ARTICLE_UPDATE_HINT)) {
Collections.sort(articles, Comparators.ARTICLE_UPDATE_DATE_COMPARATOR);
......@@ -814,12 +814,12 @@ public class ArticleProcessor {
final boolean hasMultipleUsers = userQueryService.hasMultipleUsers();
if (hasMultipleUsers) {
filler.setArticlesExProperties(articles, preference);
filler.setArticlesExProperties(request, articles, preference);
} else {
if (!articles.isEmpty()) {
final JSONObject author = articleQueryService.getAuthor(articles.get(0));
filler.setArticlesExProperties(articles, author, preference);
filler.setArticlesExProperties(request, articles, author, preference);
}
}
......
......@@ -15,7 +15,6 @@
*/
package org.b3log.solo.processor;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
......@@ -56,7 +55,6 @@ import org.b3log.solo.util.comparator.Comparators;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Tag processor.
*
......@@ -147,7 +145,7 @@ public class TagProcessor {
return;
}
LOGGER.log(Level.DEBUG, "Tag[title={0}, currentPageNum={1}]", new Object[] {tagTitle, currentPageNum});
LOGGER.log(Level.DEBUG, "Tag[title={0}, currentPageNum={1}]", new Object[]{tagTitle, currentPageNum});
tagTitle = URLDecoder.decode(tagTitle, "UTF-8");
final JSONObject result = tagQueryService.getTagByTitle(tagTitle);
......@@ -181,19 +179,19 @@ public class TagProcessor {
final boolean hasMultipleUsers = userQueryService.hasMultipleUsers();
if (hasMultipleUsers) {
filler.setArticlesExProperties(articles, preference);
filler.setArticlesExProperties(request, articles, preference);
} else {
// All articles composed by the same author
final JSONObject author = articleQueryService.getAuthor(articles.get(0));
filler.setArticlesExProperties(articles, author, preference);
filler.setArticlesExProperties(request, articles, author, preference);
}
final int tagArticleCount = tag.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT);
final int pageCount = (int) Math.ceil((double) tagArticleCount / (double) pageSize);
LOGGER.log(Level.TRACE, "Paginate tag-articles[currentPageNum={0}, pageSize={1}, pageCount={2}, windowSize={3}]",
new Object[] {currentPageNum, pageSize, pageCount, windowSize});
new Object[]{currentPageNum, pageSize, pageCount, windowSize});
final List<Integer> pageNums = Paginator.paginate(currentPageNum, pageSize, pageCount, windowSize);
LOGGER.log(Level.TRACE, "tag-articles[pageNums={0}]", pageNums);
......@@ -208,7 +206,7 @@ public class TagProcessor {
filler.fillSide(request, dataModel, preference);
filler.fillBlogHeader(request, response, dataModel, preference);
filler.fillBlogFooter(request, dataModel, preference);
statisticMgmtService.incBlogViewCount(request, response);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......@@ -239,9 +237,9 @@ public class TagProcessor {
* @param pageNums the specified page numbers
*/
private void fillPagination(final Map<String, Object> dataModel,
final int pageCount, final int currentPageNum,
final List<JSONObject> articles,
final List<Integer> pageNums) {
final int pageCount, final int currentPageNum,
final List<JSONObject> articles,
final List<Integer> pageNums) {
final String previousPageNum = Integer.toString(currentPageNum > 1 ? currentPageNum - 1 : 0);
dataModel.put(Pagination.PAGINATION_PREVIOUS_PAGE_NUM, "0".equals(previousPageNum) ? "" : previousPageNum);
......
......@@ -39,6 +39,7 @@ import org.b3log.latke.model.Plugin;
import org.b3log.latke.model.User;
import org.b3log.latke.plugin.ViewLoadEventData;
import org.b3log.latke.repository.*;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.service.ServiceException;
import org.b3log.latke.service.annotation.Service;
import org.b3log.latke.user.UserService;
......@@ -47,6 +48,7 @@ import org.b3log.latke.util.*;
import org.b3log.latke.util.freemarker.Templates;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.*;
import static org.b3log.solo.model.Article.ARTICLE_CONTENT;
import org.b3log.solo.repository.ArchiveDateRepository;
import org.b3log.solo.repository.ArticleRepository;
import org.b3log.solo.repository.CommentRepository;
......@@ -68,7 +70,7 @@ import org.json.JSONObject;
* Filler utilities.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.10.11, Jul 2, 2015
* @version 1.3.11.11, Aug 3, 2015
* @since 0.3.1
*/
@Service
......@@ -173,6 +175,12 @@ public class Filler {
@Inject
private EventManager eventManager;
/**
* Language service.
*/
@Inject
private LangPropsService langPropsService;
/**
* Fills articles in index.ftl.
*
......@@ -238,12 +246,12 @@ public class Filler {
final boolean hasMultipleUsers = userQueryService.hasMultipleUsers();
if (hasMultipleUsers) {
setArticlesExProperties(articles, preference);
setArticlesExProperties(request, articles, preference);
} else {
if (!articles.isEmpty()) {
final JSONObject author = articleQueryService.getAuthor(articles.get(0));
setArticlesExProperties(articles, author, preference);
setArticlesExProperties(request, articles, author, preference);
}
}
......@@ -883,13 +891,15 @@ public class Filler {
* }
* </pre> </p>
*
* @param request the specified HTTP servlet request
* @param article the specified article
* @param author the specified author
* @param preference the specified preference
* @throws ServiceException service exception
* @see #setArticlesExProperties(java.util.List, org.json.JSONObject)
*/
private void setArticleExProperties(final JSONObject article, final JSONObject author, final JSONObject preference)
private void setArticleExProperties(final HttpServletRequest request,
final JSONObject article, final JSONObject author, final JSONObject preference)
throws ServiceException {
try {
final String authorName = author.getString(User.USER_NAME);
......@@ -908,6 +918,12 @@ public class Filler {
article.put(Common.HAS_UPDATED, false);
}
if (articleQueryService.needViewPwd(request, article)) {
final String content = langPropsService.get("articleContentPwd");
article.put(ARTICLE_CONTENT, content);
}
processArticleAbstract(preference, article);
articleQueryService.markdown(article);
......@@ -933,12 +949,14 @@ public class Filler {
* }
* </pre> </p>
*
* @param request the specified HTTP servlet request
* @param article the specified article
* @param preference the specified preference
* @throws ServiceException service exception
* @see #setArticlesExProperties(java.util.List, org.json.JSONObject)
*/
private void setArticleExProperties(final JSONObject article, final JSONObject preference) throws ServiceException {
private void setArticleExProperties(final HttpServletRequest request,
final JSONObject article, final JSONObject preference) throws ServiceException {
try {
final JSONObject author = articleQueryService.getAuthor(article);
final String authorName = author.getString(User.USER_NAME);
......@@ -957,6 +975,12 @@ public class Filler {
article.put(Common.HAS_UPDATED, false);
}
if (articleQueryService.needViewPwd(request, article)) {
final String content = langPropsService.get("articleContentPwd");
article.put(ARTICLE_CONTENT, content);
}
processArticleAbstract(preference, article);
articleQueryService.markdown(article);
......@@ -984,16 +1008,18 @@ public class Filler {
* }
* </pre> </p>
*
* @param request the specified HTTP servlet request
* @param articles the specified articles
* @param author the specified author
* @param preference the specified preference
* @throws ServiceException service exception
* @see #setArticleExProperties(org.json.JSONObject, org.json.JSONObject)
*/
public void setArticlesExProperties(final List<JSONObject> articles, final JSONObject author, final JSONObject preference)
public void setArticlesExProperties(final HttpServletRequest request,
final List<JSONObject> articles, final JSONObject author, final JSONObject preference)
throws ServiceException {
for (final JSONObject article : articles) {
setArticleExProperties(article, author, preference);
setArticleExProperties(request, article, author, preference);
}
}
......@@ -1015,15 +1041,17 @@ public class Filler {
* }
* </pre> </p>
*
* @param request the specified HTTP servlet request
* @param articles the specified articles
* @param preference the specified preference
* @throws ServiceException service exception
* @see #setArticleExProperties(org.json.JSONObject, org.json.JSONObject)
*/
public void setArticlesExProperties(final List<JSONObject> articles, final JSONObject preference)
public void setArticlesExProperties(final HttpServletRequest request,
final List<JSONObject> articles, final JSONObject preference)
throws ServiceException {
for (final JSONObject article : articles) {
setArticleExProperties(article, preference);
setArticleExProperties(request, article, preference);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment