diff --git a/pom.xml b/pom.xml index 7205c2f6..723d3f91 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ - 4.0.0 @@ -9,11 +9,11 @@ war Zblog - + UTF-8 - + javax.servlet.jsp @@ -32,7 +32,12 @@ jstl 1.2 - + + javax.mail + mail + 1.4.7 + + org.springframework @@ -85,14 +90,14 @@ 3.2.5.RELEASE test - + org.jsoup jsoup 1.8.1 - + org.apache.lucene @@ -125,7 +130,7 @@ IKAnalyzer 2012FF_u1 - + org.mybatis @@ -137,20 +142,20 @@ mybatis-spring 1.2.0 - + net.sf.ehcache ehcache-core 2.6.8 - + org.freemarker freemarker 2.3.19 - + commons-dbcp @@ -167,7 +172,7 @@ commons-fileupload 1.2.2 - + log4j log4j @@ -179,7 +184,7 @@ slf4j-log4j12 1.7.5 - + mysql @@ -195,7 +200,7 @@ test - + org.aspectj aspectjweaver @@ -208,7 +213,7 @@ fastjson 1.1.31 - + org.apache.shiro @@ -225,18 +230,19 @@ shiro-web 1.2.3 - + org.kohsuke.redstone redstone 1.1.1 - + + org.apache.maven.plugins maven-compiler-plugin 2.3.2 @@ -245,12 +251,16 @@ + org.apache.maven.plugins maven-war-plugin - 2.2 + 2.4 3.0 false zblog + + log/**,post/** + true @@ -262,7 +272,7 @@ 9080 - 20 + 10 / diff --git a/src/main/java/com/zblog/biz/CommentManager.java b/src/main/java/com/zblog/biz/CommentManager.java index ee796d21..304fee51 100644 --- a/src/main/java/com/zblog/biz/CommentManager.java +++ b/src/main/java/com/zblog/biz/CommentManager.java @@ -53,6 +53,9 @@ public void setStatus(String commentid, String newStatus){ commentService.setStatus(commentid, newStatus); int count = CommentConstants.TYPE_APPROVE.equals(newStatus) ? 1 : -1; postService.addCcount(commentid, count); + if(count > 1){ + + } } /** diff --git a/src/main/java/com/zblog/core/dal/entity/Post.java b/src/main/java/com/zblog/core/dal/entity/Post.java index 3de1c3ac..956843d4 100644 --- a/src/main/java/com/zblog/core/dal/entity/Post.java +++ b/src/main/java/com/zblog/core/dal/entity/Post.java @@ -22,7 +22,7 @@ public class Post extends BaseEntity{ /* 文章状态 */ private String pstatus = PostConstants.POST_PUBLISH; /* 评论状态 */ - private String cstatus = PostConstants.COMMENT_CLOSE; + private String cstatus = PostConstants.COMMENT_OPEN; /* 评论数 */ private int ccount = 0; /* 阅读数 */ diff --git a/src/main/java/com/zblog/core/dal/mapper/CommentMapper.java b/src/main/java/com/zblog/core/dal/mapper/CommentMapper.java index a7bf1014..97c078ae 100644 --- a/src/main/java/com/zblog/core/dal/mapper/CommentMapper.java +++ b/src/main/java/com/zblog/core/dal/mapper/CommentMapper.java @@ -11,7 +11,7 @@ public interface CommentMapper extends BaseMapper{ List listRecent(); - public List listCountByGroupStatus(); + List listCountByGroupStatus(); /** * 根据postid获取被批准的评论和指定creator的评论 @@ -27,6 +27,6 @@ public interface CommentMapper extends BaseMapper{ * * @param commentid */ - void setStatus(@Param("commentid") String commentid, @Param("status") String status); + int setStatus(@Param("commentid") String commentid, @Param("status") String status); } diff --git a/src/main/java/com/zblog/core/dal/mybatis/PostMapper.xml b/src/main/java/com/zblog/core/dal/mybatis/PostMapper.xml index 5f913264..863366c0 100644 --- a/src/main/java/com/zblog/core/dal/mybatis/PostMapper.xml +++ b/src/main/java/com/zblog/core/dal/mybatis/PostMapper.xml @@ -65,7 +65,8 @@ - update post set title=#{title},excerpt=#{excerpt}, content=#{content, jdbcType=CLOB},parent=#{parent}, pstatus=#{pstatus}, categoryid=#{categoryid},lastUpdate=#{lastUpdate} + update post set title=#{title},excerpt=#{excerpt}, content=#{content, jdbcType=CLOB},parent=#{parent}, pstatus=#{pstatus}, + cstatus=#{cstatus},categoryid=#{categoryid},lastUpdate=#{lastUpdate} where id=#{id} diff --git a/src/main/java/com/zblog/core/util/ServletUtils.java b/src/main/java/com/zblog/core/util/ServletUtils.java index 56f4d577..701bcf5e 100644 --- a/src/main/java/com/zblog/core/util/ServletUtils.java +++ b/src/main/java/com/zblog/core/util/ServletUtils.java @@ -15,7 +15,7 @@ public static boolean isMultipartContent(HttpServletRequest request){ if(!"post".equals(request.getMethod().toLowerCase())){ return false; } - + String contentType = request.getContentType(); return contentType != null && contentType.toLowerCase().startsWith("multipart/"); } diff --git a/src/main/java/com/zblog/core/util/constants/PostConstants.java b/src/main/java/com/zblog/core/util/constants/PostConstants.java index c552b712..40e061e1 100644 --- a/src/main/java/com/zblog/core/util/constants/PostConstants.java +++ b/src/main/java/com/zblog/core/util/constants/PostConstants.java @@ -8,7 +8,7 @@ private PostConstants(){ public static final String TYPE_POST = "post"; public static final String TYPE_PAGE = "page"; /* 文章评论状态 */ - public static final String COMMENT_POST = "open"; + public static final String COMMENT_OPEN = "open"; public static final String COMMENT_CLOSE = "close"; /* 文章状态,发布、回收站 */ public static final String POST_PUBLISH = "publish"; diff --git a/src/main/java/com/zblog/core/util/web/ServletRequestReader.java b/src/main/java/com/zblog/core/util/web/ServletRequestReader.java index ee2ffb22..32389b46 100644 --- a/src/main/java/com/zblog/core/util/web/ServletRequestReader.java +++ b/src/main/java/com/zblog/core/util/web/ServletRequestReader.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.Map; +import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import org.springframework.web.multipart.MultipartFile; @@ -21,9 +22,9 @@ * */ public class ServletRequestReader{ - HttpServletRequest request; + ServletRequest request; - public ServletRequestReader(HttpServletRequest request){ + public ServletRequestReader(ServletRequest request){ this.request = request; } @@ -96,11 +97,11 @@ public boolean getAsBoolean(String key, boolean defaults){ // 获取基于虚拟路径的绝对路径 public String getRealPath(String path){ // 注: request.getServletContext().getRealPath(path);在Servlet3.0规范下才定义的 - return request.getSession(true).getServletContext().getRealPath(path); + return request.getServletContext().getRealPath(path); } public String getDomain(){ - return ServletUtils.getDomain(request); + return ServletUtils.getDomain((HttpServletRequest) request); } public Map getQuerys(){ diff --git a/src/main/java/com/zblog/service/CommentService.java b/src/main/java/com/zblog/service/CommentService.java index bb426078..ee55b2a9 100644 --- a/src/main/java/com/zblog/service/CommentService.java +++ b/src/main/java/com/zblog/service/CommentService.java @@ -68,8 +68,8 @@ public List listByPost(String postid, String creator){ return commentMapper.listByPost(postid, creator); } - public void setStatus(String commentid, String newStatus){ - commentMapper.setStatus(commentid, newStatus); + public int setStatus(String commentid, String newStatus){ + return commentMapper.setStatus(commentid, newStatus); } @Override diff --git a/src/main/java/com/zblog/web/backend/controller/BackendController.java b/src/main/java/com/zblog/web/backend/controller/BackendController.java index a99274ef..8c8df58e 100644 --- a/src/main/java/com/zblog/web/backend/controller/BackendController.java +++ b/src/main/java/com/zblog/web/backend/controller/BackendController.java @@ -28,7 +28,7 @@ import com.zblog.service.vo.OSInfo; import com.zblog.web.backend.form.LoginForm; import com.zblog.web.backend.form.validator.LoginFormValidator; -import com.zblog.web.filter.CookieRemberManager; +import com.zblog.web.support.CookieRemberManager; @Controller @RequestMapping("/backend") diff --git a/src/main/java/com/zblog/web/filter/LoginFilter.java b/src/main/java/com/zblog/web/filter/LoginFilter.java index 5612304c..22c2f2b2 100644 --- a/src/main/java/com/zblog/web/filter/LoginFilter.java +++ b/src/main/java/com/zblog/web/filter/LoginFilter.java @@ -18,6 +18,8 @@ import com.zblog.core.util.web.WebContext; import com.zblog.core.util.web.WebContextFactory; import com.zblog.service.shiro.StatelessToken; +import com.zblog.web.support.CookieRemberManager; +import com.zblog.web.support.Global; /** * 继承OncePerRequestFilter保证一次请求只过滤一次(以兼容不同的servlet container) diff --git a/src/main/java/com/zblog/web/front/controller/CommentController.java b/src/main/java/com/zblog/web/front/controller/CommentController.java index a1a33c1f..51af95aa 100644 --- a/src/main/java/com/zblog/web/front/controller/CommentController.java +++ b/src/main/java/com/zblog/web/front/controller/CommentController.java @@ -13,6 +13,7 @@ import org.springframework.web.util.HtmlUtils; import com.zblog.core.dal.entity.Comment; +import com.zblog.core.dal.entity.Post; import com.zblog.core.plugin.MapContainer; import com.zblog.core.util.CookieUtil; import com.zblog.core.util.IdGenerator; @@ -20,8 +21,10 @@ import com.zblog.core.util.ServletUtils; import com.zblog.core.util.StringUtils; import com.zblog.core.util.constants.OptionConstants; +import com.zblog.core.util.constants.PostConstants; import com.zblog.service.CommentService; import com.zblog.service.OptionsService; +import com.zblog.service.PostService; import com.zblog.web.front.validator.CommentValidator; @Controller @@ -30,14 +33,13 @@ public class CommentController{ @Autowired private CommentService commentService; @Autowired + private PostService postService; + @Autowired private OptionsService optionsService; @ResponseBody @RequestMapping(method = RequestMethod.POST) public Object post(Comment comment, HttpServletRequest request, HttpServletResponse response){ - if(!"true".equals(optionsService.getOptionValue(OptionConstants.ALLOW_COMMENT))) - return new MapContainer("success", false).put("msg", "当前禁止评论"); - CookieUtil cookieUtil = new CookieUtil(request, response); if(StringUtils.isBlank(comment.getCreator())){ comment.setCreator(cookieUtil.getCookie("comment_author")); @@ -47,11 +49,20 @@ public Object post(Comment comment, HttpServletRequest request, HttpServletRespo MapContainer form = CommentValidator.validate(comment); if(!form.isEmpty()){ - return form.put("success", true); + return form.put("success", false); } - if(StringUtils.isBlank(comment.getParent())) + if(!"true".equals(optionsService.getOptionValue(OptionConstants.ALLOW_COMMENT))) + return new MapContainer("success", false).put("msg", "当前禁止评论"); + + Post post = postService.loadById(comment.getPostid()); + if(post == null || PostConstants.COMMENT_CLOSE.equals(post.getCstatus())){ + return new MapContainer("success", false).put("msg", "当前禁止评论"); + } + + if(StringUtils.isBlank(comment.getParent())){ comment.setParent(null); + } /* 根据RFC-2109中的规定,在Cookie中只能包含ASCII的编码 */ cookieUtil.setCookie("comment_author", comment.getCreator(), "/", false, 365 * 24 * 3600, true); diff --git a/src/main/java/com/zblog/web/listener/InitApplicationListener.java b/src/main/java/com/zblog/web/listener/InitApplicationListener.java index e3008c04..9d235b3f 100644 --- a/src/main/java/com/zblog/web/listener/InitApplicationListener.java +++ b/src/main/java/com/zblog/web/listener/InitApplicationListener.java @@ -3,24 +3,14 @@ import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; -import com.zblog.core.plugin.ApplicationContextUtil; -import com.zblog.core.util.constants.CategoryConstants; import com.zblog.core.util.constants.WebConstants; -import com.zblog.service.CategoryService; public class InitApplicationListener implements ServletContextListener{ @Override public void contextInitialized(ServletContextEvent sce){ WebConstants.APPLICATION_PATH = sce.getServletContext().getRealPath("/"); - - initApp(); - } - - private void initApp(){ - CategoryService categoryService = ApplicationContextUtil.getBean(CategoryService.class); - if(categoryService.loadByName(CategoryConstants.ROOT) == null){ - categoryService.init(); - } + /* 给log4j设置环境变量,必须要在jvm加载log4j.properties前设置 */ + System.setProperty("log4jHome", WebConstants.APPLICATION_PATH); } @Override diff --git a/src/main/java/com/zblog/web/listener/Log4jConfigureListener.java b/src/main/java/com/zblog/web/listener/Log4jConfigureListener.java deleted file mode 100644 index 2967dc00..00000000 --- a/src/main/java/com/zblog/web/listener/Log4jConfigureListener.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.zblog.web.listener; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -public class Log4jConfigureListener implements ServletContextListener{ - - @Override - public void contextInitialized(ServletContextEvent sce){ - /* 给log4j设置环境变量,必须要在jvm加载log4j.properties前设置 */ - System.setProperty("log4jHome", sce.getServletContext().getRealPath("/")); - } - - @Override - public void contextDestroyed(ServletContextEvent sce){ - - } - -} diff --git a/src/main/java/com/zblog/web/filter/CookieRemberManager.java b/src/main/java/com/zblog/web/support/CookieRemberManager.java similarity index 99% rename from src/main/java/com/zblog/web/filter/CookieRemberManager.java rename to src/main/java/com/zblog/web/support/CookieRemberManager.java index 0c06ba92..965b9949 100644 --- a/src/main/java/com/zblog/web/filter/CookieRemberManager.java +++ b/src/main/java/com/zblog/web/support/CookieRemberManager.java @@ -1,4 +1,4 @@ -package com.zblog.web.filter; +package com.zblog.web.support; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/src/main/java/com/zblog/web/filter/Global.java b/src/main/java/com/zblog/web/support/Global.java similarity index 93% rename from src/main/java/com/zblog/web/filter/Global.java rename to src/main/java/com/zblog/web/support/Global.java index 31f97319..8caa4cf9 100644 --- a/src/main/java/com/zblog/web/filter/Global.java +++ b/src/main/java/com/zblog/web/support/Global.java @@ -1,4 +1,4 @@ -package com.zblog.web.filter; +package com.zblog.web.support; import java.util.Calendar; import java.util.Date; diff --git a/src/main/java/com/zblog/web/resovler/ServletRequestReaderArgumentsResolver.java b/src/main/java/com/zblog/web/support/ServletRequestReaderArgumentsResolver.java similarity index 96% rename from src/main/java/com/zblog/web/resovler/ServletRequestReaderArgumentsResolver.java rename to src/main/java/com/zblog/web/support/ServletRequestReaderArgumentsResolver.java index 075b88c0..f7638d25 100644 --- a/src/main/java/com/zblog/web/resovler/ServletRequestReaderArgumentsResolver.java +++ b/src/main/java/com/zblog/web/support/ServletRequestReaderArgumentsResolver.java @@ -1,4 +1,4 @@ -package com.zblog.web.resovler; +package com.zblog.web.support; import javax.servlet.http.HttpServletRequest; diff --git a/src/main/java/com/zblog/web/resovler/XssHandlerMappingPostProcessor.java b/src/main/java/com/zblog/web/support/XssHandlerMappingPostProcessor.java similarity index 98% rename from src/main/java/com/zblog/web/resovler/XssHandlerMappingPostProcessor.java rename to src/main/java/com/zblog/web/support/XssHandlerMappingPostProcessor.java index 82e5390d..25f1f5f8 100644 --- a/src/main/java/com/zblog/web/resovler/XssHandlerMappingPostProcessor.java +++ b/src/main/java/com/zblog/web/support/XssHandlerMappingPostProcessor.java @@ -1,4 +1,4 @@ -package com.zblog.web.resovler; +package com.zblog.web.support; import java.util.List; import java.util.Map; diff --git a/src/main/resources/config/spring-servlet.xml b/src/main/resources/config/spring-servlet.xml index 4368f502..89a1181f 100644 --- a/src/main/resources/config/spring-servlet.xml +++ b/src/main/resources/config/spring-servlet.xml @@ -22,7 +22,7 @@ - + @@ -31,7 +31,7 @@ - + - com.zblog.web.listener.Log4jConfigureListener + com.zblog.web.listener.InitApplicationListener @@ -33,9 +33,6 @@ org.springframework.web.context.ContextLoaderListener - - com.zblog.web.listener.InitApplicationListener - diff --git a/src/main/webapp/resource/css/style.css b/src/main/webapp/resource/css/style.css index 69664dcc..919b4a01 100644 --- a/src/main/webapp/resource/css/style.css +++ b/src/main/webapp/resource/css/style.css @@ -88,7 +88,7 @@ a:hover{color: #009dc4;} #content{min-height: 100%;position: absolute;top: 0;width: 100%;} #post_mask{box-shadow:-1px 0px 3px 0px #888; position:absolute; top:0; right:0; width:86%; height:100%; background:#fff url(../img/right_bg.gif) repeat-y right top; z-index:2;} -#left_col{float: left;margin: 230px -340px 0 0;width: 100%;z-index: 1000;} +#left_col{float: left;margin: 230px -340px 0 0;width: 100%;} #archive_headline{float: right;position: relative;width: 86%;z-index: 3;} #archive_headline h2{font-size: 14px;margin: 0 340px 0 0;padding: 45px 4%;} #archive_headline h2 span{color: #00a19e;} diff --git a/src/main/webapp/resource/js/backend/admin.page.js b/src/main/webapp/resource/js/backend/admin.page.js index b435944b..01442939 100644 --- a/src/main/webapp/resource/js/backend/admin.page.js +++ b/src/main/webapp/resource/js/backend/admin.page.js @@ -65,7 +65,8 @@ zblog.page.insert=function(){ var postid=$("#postid").val(); var data={title : title, content : _getText(), - parent : $("#parent").val() + parent : $("#parent").val(), + cstatus : $("input:radio[name=cstatus]:checked").val() }; if(postid.length>0) data.id=postid; diff --git a/src/main/webapp/resource/js/backend/admin.post.js b/src/main/webapp/resource/js/backend/admin.post.js index 5ab4fe57..13310435 100644 --- a/src/main/webapp/resource/js/backend/admin.post.js +++ b/src/main/webapp/resource/js/backend/admin.post.js @@ -66,7 +66,8 @@ zblog.post.insert=function(){ content : _getText(), tags : $("#tags").val(), categoryid : $("#category").val(), - pstatus : $("input:radio[name=pstatus]:checked").val() + pstatus : $("input:radio[name=pstatus]:checked").val(), + cstatus : $("input:radio[name=cstatus]:checked").val() }; if(postid.length>0) data.id=postid;