| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- /**
- * Copyright (c) 2015-2016, Michael Yang 杨福海 (fuhai999@gmail.com).
- *
- * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.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.gnu.org/licenses/lgpl-3.0.txt
- *
- * 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.
- */
- package io.jpress.admin.controller;
- import com.jfinal.aop.Before;
- import com.jfinal.plugin.activerecord.Page;
- import io.jpress.core.JBaseCRUDController;
- import io.jpress.core.interceptor.ActionCacheClearInterceptor;
- import io.jpress.interceptor.UCodeInterceptor;
- import io.jpress.model.Comment;
- import io.jpress.model.Content;
- import io.jpress.model.User;
- import io.jpress.model.query.CommentQuery;
- import io.jpress.model.query.UserQuery;
- import io.jpress.router.RouterMapping;
- import io.jpress.router.RouterNotAllowConvert;
- import io.jpress.template.TemplateManager;
- import io.jpress.utils.JsoupUtils;
- import io.jpress.utils.StringUtils;
- import java.math.BigInteger;
- import java.util.Date;
- import java.util.List;
- @RouterMapping(url = "/admin/comment", viewPath = "/WEB-INF/admin/comment")
- @Before(ActionCacheClearInterceptor.class)
- @RouterNotAllowConvert
- public class _CommentController extends JBaseCRUDController<Comment> {
- private String getModule() {
- return getPara("m");
- }
- private String getType() {
- return getPara("t");
- }
- private boolean getSon() {
- return Boolean.parseBoolean(getPara("son"));
- }
- @Override
- public void index() {
- keepPara();
- setAttr("module", TemplateManager.me().currentTemplateModule(getModule()));
- if ("uuhelper".equals(getModule())) {
- setAttr("answered_count", CommentQuery.me().findCountByModuleAndSonAndContentId(getParaToBigInteger("cid"), getModule(), true));
- setAttr("unanswered_count", CommentQuery.me().findCountByModuleAndSonAndContentId(getParaToBigInteger("cid"), getModule(), false));
- setAttr("draft_count", CommentQuery.me().findCountByModuleAndStatusAndContentId(getParaToBigInteger("cid"), getModule(), Comment.STATUS_DRAFT));
- setAttr("normal_count", CommentQuery.me().findCountByModuleAndStatusAndContentId(getParaToBigInteger("cid"), getModule(), Comment.STATUS_NORMAL));
- setAttr("delete_count", CommentQuery.me().findCountByModuleAndStatusAndContentId(getParaToBigInteger("cid"), getModule(), Comment.STATUS_DELETE));
- } else {
- setAttr("delete_count", CommentQuery.me().findCountByModuleAndStatus(getModule(), Comment.STATUS_DELETE));
- setAttr("draft_count", CommentQuery.me().findCountByModuleAndStatus(getModule(), Comment.STATUS_DRAFT));
- setAttr("normal_count", CommentQuery.me().findCountByModuleAndStatus(getModule(), Comment.STATUS_NORMAL));
- setAttr("count", CommentQuery.me().findCountInNormalByModule(getModule()));
- }
- super.index();
- }
- @Override
- public Page<Comment> onIndexDataLoad(int pageNumber, int pageSize) {
- Page<Comment> page = null;
- BigInteger contentId = getParaToBigInteger("cid");
- BigInteger parentCommentId = getParaToBigInteger("pid");
- if (StringUtils.isNotBlank(getPara("s"))) {
- page = CommentQuery.me().paginateWithContent(pageNumber, pageSize, getModule(), getType(), contentId,
- parentCommentId, getPara("s"));
- } else if (StringUtils.isNotBlank(getPara("son"))) {
- page = CommentQuery.me().paginateWithContentAndSon(pageNumber, pageSize, getModule(), getType(), contentId,
- parentCommentId,getSon());
- }
- page = CommentQuery.me().paginateWithContentNotInDelete(pageNumber, pageSize, getModule(), getType(), contentId,
- parentCommentId);
- List<Comment> comments = page.getList();
- for (Comment comment : comments) {
- String userAvater = comment.getUuUserAvatar();
- if (!(StringUtils.isNotBlank(userAvater) && comment.isImageExist(userAvater))) {
- comment.setUuUserAvatar(null);
- }
- }
- return page;
- }
- @Override
- public void edit() {
- BigInteger id = getParaToBigInteger("id");
- Comment comment = CommentQuery.me().findById(id);
- setAttr("comment", comment);
- }
- @Before(UCodeInterceptor.class)
- public void trash() {
- Comment c = CommentQuery.me().findById(getParaToBigInteger("id"));
- if (c != null) {
- c.setStatus(Comment.STATUS_DELETE);
- if (c.saveOrUpdate()) {
- renderAjaxResultForSuccess();
- } else {
- renderAjaxResultForError("restore error!");
- }
- } else {
- renderAjaxResultForError("trash error!");
- }
- }
- @Before(UCodeInterceptor.class)
- public void restore() {
- BigInteger id = getParaToBigInteger("id");
- Comment c = CommentQuery.me().findById(id);
- if (c != null && c.isDelete()) {
- c.setStatus(Content.STATUS_DRAFT);
- if (c.saveOrUpdate()) {
- renderAjaxResultForSuccess("success");
- } else {
- renderAjaxResultForError("restore error!");
- }
- } else {
- renderAjaxResultForError("restore error!");
- }
- }
- @Before(UCodeInterceptor.class)
- public void pub() {
- BigInteger id = getParaToBigInteger("id");
- Comment c = CommentQuery.me().findById(id);
- if (c != null) {
- c.setStatus(Content.STATUS_NORMAL);
- if (c.saveOrUpdate()) {
- renderAjaxResultForSuccess("success");
- } else {
- renderAjaxResultForError("pub fail!");
- }
- } else {
- renderAjaxResultForError("pub error!");
- }
- }
- @Before(UCodeInterceptor.class)
- public void draft() {
- BigInteger id = getParaToBigInteger("id");
- Comment c = CommentQuery.me().findById(id);
- if (c != null) {
- c.setStatus(Content.STATUS_DRAFT);
- if (c.saveOrUpdate()) {
- renderAjaxResultForSuccess("success");
- } else {
- renderAjaxResultForError("draft fail!");
- }
- } else {
- renderAjaxResultForError("draft error!");
- }
- }
- @Before(UCodeInterceptor.class)
- public void delete() {
- BigInteger id = getParaToBigInteger("id");
- final Comment c = CommentQuery.me().findById(id);
- if (c != null) {
- if (c.delete()) {
- renderAjaxResultForSuccess();
- return;
- }
- }
- renderAjaxResultForError();
- }
- @Override
- public void save() {
- Comment comment = getModel(Comment.class);
- String username = getPara("username");
- if (StringUtils.isNotBlank(username)) {
- User user = UserQuery.me().findUserByUsername(username);
- if (user == null) {
- renderAjaxResultForError("系统没有该用户:" + username);
- return;
- }
- comment.setUserId(user.getId());
- }
- if (comment.saveOrUpdate()) {
- comment.updateCommentCount();
- renderAjaxResultForSuccess();
- } else {
- renderAjaxResultForError();
- }
- }
- public void reply_layer() {
- BigInteger id = getParaToBigInteger("id");
- setAttr("comment", CommentQuery.me().findById(id));
- }
- public void reply() {
- Comment comment = getModel(Comment.class);
- comment.setType(Comment.TYPE_COMMENT);
- comment.setIp(getIPAddress());
- comment.setAgent(getUserAgent());
- User user = getLoginedUser();
- String author = StringUtils.isNotBlank(user.getNickname()) ? user.getNickname() : user.getUsername();
- comment.setAuthor(author);
- comment.setEmail(user.getEmail());
- comment.setStatus(Comment.STATUS_NORMAL);
- comment.setUserId(user.getId());
- comment.setCreated(new Date());
- comment.setText(JsoupUtils.getBodyHtml(comment.getText()));
- comment.save();
- renderAjaxResultForSuccess();
- }
- @Before(UCodeInterceptor.class)
- public void changeCommentTopSataus() {
- BigInteger id = getParaToBigInteger("id");
- Comment c = CommentQuery.me().findById(id);
- String commentTopStatus = getPara("commentTopStatus");
- if (c != null) {
- if ("top".equals(commentTopStatus)) {
- c.setOrderNumber(Long.parseLong("1"));
- } else {
- c.setOrderNumber(Long.parseLong("0"));
- }
- if (c.saveOrUpdate()) {
- renderAjaxResultForSuccess("success");
- } else {
- renderAjaxResultForError("restore error!");
- }
- } else {
- renderAjaxResultForError("restore error!");
- }
- }
- }
|