Commit 6768e75e authored by Liang Ding's avatar Liang Ding

#12051

parent 5bcb95bd
......@@ -15,8 +15,10 @@
*/
package org.b3log.solo.processor;
import java.net.URL;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -40,6 +42,7 @@ import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.Statistic;
import org.b3log.solo.model.Tag;
import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.StatisticQueryService;
......@@ -48,12 +51,11 @@ import org.b3log.solo.service.UserQueryService;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* Blog processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.2.0.4, Nov 20, 2015
* @version 1.3.0.4, Dec 17, 2015
* @since 0.4.6
*/
@RequestProcessor
......@@ -165,7 +167,7 @@ public class BlogProcessor {
if (Latkes.getServePath().contains("localhost")) {
return;
}
final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) {
......@@ -178,7 +180,7 @@ public class BlogProcessor {
httpRequest.setRequestMethod(HTTPRequestMethod.POST);
final JSONObject requestJSONObject = new JSONObject();
final JSONObject admin = userQueryService.getAdmin();
final JSONObject admin = userQueryService.getAdmin();
requestJSONObject.put(User.USER_NAME, admin.getString(User.USER_NAME));
requestJSONObject.put(User.USER_EMAIL, admin.getString(User.USER_EMAIL));
......@@ -211,7 +213,7 @@ public class BlogProcessor {
*/
@RequestProcessing(value = "/blog/articles-tags", method = HTTPRequestMethod.GET)
public void getArticlesTags(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
throws Exception {
final String pwd = request.getParameter("pwd");
if (Strings.isEmptyOrNull(pwd)) {
......@@ -281,4 +283,41 @@ public class BlogProcessor {
}
}
}
/**
* Gets interest tags (top 10 and bottom 10).
*
* <pre>
* {
* "data": ["tag1", "tag2", ....]
* }
* </pre>
*
* @param context the specified context
* @param request the specified HTTP servlet request
* @param response the specified HTTP servlet response
* @throws Exception io exception
*/
@RequestProcessing(value = "/blog/interest-tags", method = HTTPRequestMethod.GET)
public void getInterestTags(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
final Set<String> tagTitles = new HashSet<String>();
final List<JSONObject> topTags = tagQueryService.getTopTags(10);
for (final JSONObject topTag : topTags) {
tagTitles.add(topTag.optString(Tag.TAG_TITLE));
}
final List<JSONObject> bottomTags = tagQueryService.getBottomTags(10);
for (final JSONObject bottomTag : bottomTags) {
tagTitles.add(bottomTag.optString(Tag.TAG_TITLE));
}
ret.put("data", tagTitles);
}
}
......@@ -15,7 +15,6 @@
*/
package org.b3log.solo.service;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
......@@ -24,6 +23,7 @@ import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.repository.Query;
import org.b3log.latke.repository.RepositoryException;
import org.b3log.latke.repository.SortDirection;
import org.b3log.latke.service.ServiceException;
import org.b3log.latke.service.annotation.Service;
import org.b3log.latke.util.CollectionUtils;
......@@ -33,12 +33,11 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Tag query service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.3, Jun 28, 2012
* @version 1.1.0.3, Dec 17, 2015
* @since 0.4.0
*/
@Service
......@@ -59,8 +58,7 @@ public class TagQueryService {
* Gets a tag by the specified tag title.
*
* @param tagTitle the specified tag title
* @return for example,
* <pre>
* @return for example, <pre>
* {
* "tag": {
* "oId": "",
......@@ -70,6 +68,7 @@ public class TagQueryService {
* }
* }
* </pre>, returns {@code null} if not found
*
* @throws ServiceException service exception
*/
public JSONObject getTagByTitle(final String tagTitle) throws ServiceException {
......@@ -95,7 +94,7 @@ public class TagQueryService {
/**
* Gets the count of tags.
*
*
* @return count of tags
* @throws ServiceException service exception
*/
......@@ -112,13 +111,13 @@ public class TagQueryService {
/**
* Gets all tags.
*
* @return for example,
* <pre>
* @return for example, <pre>
* [
* {"tagTitle": "", "tagReferenceCount": int, ....},
* ....
* ]
* </pre>, returns an empty list if not found
*
* @throws ServiceException service exception
*/
public List<JSONObject> getTags() throws ServiceException {
......@@ -136,6 +135,64 @@ public class TagQueryService {
}
}
/**
* Gets top (reference count descending) tags.
*
* @param fetchSize the specified fetch size
* @return for example, <pre>
* [
* {"tagTitle": "", "tagReferenceCount": int, ....},
* ....
* ]
* </pre>, returns an empty list if not found
*
* @throws ServiceException service exception
*/
public List<JSONObject> getTopTags(final int fetchSize) throws ServiceException {
try {
final Query query = new Query().setPageCount(1).setPageSize(fetchSize).
addSort(Tag.TAG_PUBLISHED_REFERENCE_COUNT, SortDirection.DESCENDING);
final JSONObject result = tagRepository.get(query);
final JSONArray tagArray = result.optJSONArray(Keys.RESULTS);
return CollectionUtils.jsonArrayToList(tagArray);
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Gets top tags failed", e);
throw new ServiceException(e);
}
}
/**
* Gets bottom (reference count ascending) tags.
*
* @param fetchSize the specified fetch size
* @return for example, <pre>
* [
* {"tagTitle": "", "tagReferenceCount": int, ....},
* ....
* ]
* </pre>, returns an empty list if not found
*
* @throws ServiceException service exception
*/
public List<JSONObject> getBottomTags(final int fetchSize) throws ServiceException {
try {
final Query query = new Query().setPageCount(1).setPageSize(fetchSize).
addSort(Tag.TAG_PUBLISHED_REFERENCE_COUNT, SortDirection.ASCENDING);
final JSONObject result = tagRepository.get(query);
final JSONArray tagArray = result.optJSONArray(Keys.RESULTS);
return CollectionUtils.jsonArrayToList(tagArray);
} catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Gets bottom tags failed", e);
throw new ServiceException(e);
}
}
/**
* Removes tags of unpublished articles from the specified tags.
*
......@@ -157,7 +214,7 @@ public class TagQueryService {
/**
* Sets the tag repository with the specified tag repository.
*
*
* @param tagRepository the specified tag repository
*/
public void setTagRepository(final TagRepository tagRepository) {
......
#
# Copyright (c) 2009, 2010, 2011, B3log Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Description: Language configurations(en_US) of plugin symphony-interest.
# Version: 1.0.0.0, Dec 17, 2015
# Author: Liang Ding
#
interestLabel=<a href="http://hacpai.com" target="_blank">Interest</a>
\ No newline at end of file
#
# Copyright (c) 2009, 2010, 2011, B3log Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Description: Language configurations(zh_CN) of plugin symphony-interest.
# Version: 1.0.0.0, Dec 17, 2015
# Author: Liang Ding
#
interestLabel=<a href="http://hacpai.com" target="_blank">\u793e\u533a\u63a8\u8350</a>
<link type="text/css" rel="stylesheet" href="${staticServePath}/plugins/symphony-interest/style.css"/>
<div id="symphonyInterestPanel">
<div class="module-panel">
<div class="module-header">
<h2>${interestLabel}</h2>
</div>
<div class="module-body padding12">
<div id="symphonyInterest">
</div>
</div>
</div>
</div>
<script type="text/javascript">
plugins.symphonyInterest = {
init: function () {
$("#loadMsg").text("${loadingLabel}");
$("#symphonyInterest").css("background",
"url(${staticServePath}/images/loader.gif) no-repeat scroll center center transparent");
$.ajax({
url: "${servePath}/blog/interest-tags",
type: "GET",
dataType: "json",
error: function () {
$("#symphonyInterest").html("Loading Interest failed :-(").css("background", "none");
},
success: function (result, textStatus) {
var tags = result.data;
if (0 === tags.length) {
return;
}
$.ajax({
url: "http://hacpai.com/apis/articles?p=1&size=7&tags=" + tags.join(),
type: "GET",
dataType: "jsonp",
jsonp: "callback",
error: function () {
$("#symphonyInterest").html("Loading Interest failed :-(").css("background", "none");
},
success: function (data, textStatus) {
var articles = data.articles;
if (0 === articles.length) {
return;
}
var listHTML = "<ul>";
for (var i = 0; i < articles.length; i++) {
var article = articles[i];
var articleLiHtml = "<li>"
+ "<a target='_blank' href='" + article.articlePermalink + "'>"
+ article.articleTitle + "</a>&nbsp; <span class='date'>" + $.bowknot.getDate(article.articleCreateTime, 1);
+"</span></li>"
listHTML += articleLiHtml
}
listHTML += "</ul>";
$("#symphonyInterest").html(listHTML).css("background", "none");
}
});
}
});
$("#loadMsg").text("");
}
};
/*
* 添加插件
*/
admin.plugin.add({
"id": "symphonyInterest",
"path": "/main/panel1",
"content": $("#symphonyInterestPanel").html()
});
// 移除现有内容
$("#symphonyInterestPanel").remove();
</script>
#
# Copyright (c) 2009, 2010, 2011, B3log Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Description: Description of plugin symphony-interest.
# Version: 1.0.0.0, Dec 17, 2015
# Author: Liang Ding
#
rendererId=admin-main.ftl
author=<a href="http://88250.b3log.org">88250</a>
name=Symphony Interest
version=0.0.1
types=ADMIN
classesDirPath=/WEB-INF/classes/
pluginClass=
eventListenerClasses=
\ No newline at end of file
/*
* plugin style for symphony-interest
*
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 1.0.0.1, Aug 9, 2011
*/
#symphonyInterest ul {
list-style: none;
}
#symphonyInterest a {
text-decoration: none;
}
#symphonyInterest .date {
color: #686868;
font-size: 12px;
}
\ No newline at end of file
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