1 43 package net.jforum.view.admin; 44 45 import net.jforum.ActionServletRequest; 46 import net.jforum.dao.DataAccessDriver; 47 import net.jforum.dao.PostDAO; 48 import net.jforum.dao.TopicDAO; 49 import net.jforum.dao.UserDAO; 50 import net.jforum.entities.Post; 51 import net.jforum.entities.Topic; 52 import net.jforum.entities.User; 53 import net.jforum.repository.ForumRepository; 54 import net.jforum.repository.PostRepository; 55 import net.jforum.repository.TopicRepository; 56 import net.jforum.util.preferences.ConfigKeys; 57 import net.jforum.util.preferences.SystemGlobals; 58 import net.jforum.util.preferences.TemplateKeys; 59 import net.jforum.view.forum.common.AttachmentCommon; 60 import net.jforum.view.forum.common.PostCommon; 61 import net.jforum.view.forum.common.TopicsCommon; 62 import freemarker.template.SimpleHash; 63 64 68 public class ModerationAction extends AdminCommand 69 { 70 public ModerationAction() {} 71 72 public ModerationAction(SimpleHash context, ActionServletRequest request) 73 { 74 this.context = context; 75 this.request = request; 76 } 77 78 81 public void list() throws Exception 82 { 83 this.setTemplateName(TemplateKeys.MODERATION_ADMIN_LIST); 84 this.context.put("infoList", DataAccessDriver.getInstance().newModerationDAO().categoryPendingModeration()); 85 } 86 87 public void view() throws Exception 88 { 89 int forumId = this.request.getIntParameter("forum_id"); 90 91 this.setTemplateName(TemplateKeys.MODERATION_ADMIN_VIEW); 92 this.context.put("forum", ForumRepository.getForum(forumId)); 93 this.context.put("topics", DataAccessDriver.getInstance().newModerationDAO().topicsByForum( 94 forumId)); 95 } 96 97 public void doSave() throws Exception 98 { 99 String [] posts = this.request.getParameterValues("post_id"); 100 101 if (posts != null) { 102 TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO(); 103 104 for (int i = 0; i < posts.length; i++) { 105 int postId = Integer.parseInt(posts[i]); 106 107 String status = this.request.getParameter("status_" + postId); 108 109 if ("defer".startsWith(status)) { 110 continue; 111 } 112 113 if ("aprove".startsWith(status)) { 114 Post p = DataAccessDriver.getInstance().newPostDAO().selectById(postId); 115 116 UserDAO udao = DataAccessDriver.getInstance().newUserDAO(); 117 User u = udao.selectById(p.getUserId()); 118 119 if (!p.isModerationNeeded()) { 121 continue; 122 } 123 124 boolean first = false; 125 Topic t = TopicRepository.getTopic(new Topic(p.getTopicId())); 126 127 if (t == null) { 128 t = tm.selectById(p.getTopicId()); 129 130 if (t.getId() == 0) { 131 first = true; 132 t = tm.selectRaw(p.getTopicId()); 133 } 134 } 135 136 DataAccessDriver.getInstance().newModerationDAO().aprovePost(postId); 137 138 boolean firstPost = (t.getFirstPostId() == postId); 139 140 if (!firstPost) { 141 t.setTotalReplies(t.getTotalReplies() + 1); 142 } 143 144 t.setLastPostId(postId); 145 t.setLastPostBy(u); 146 t.setLastPostDate(p.getTime()); 147 t.setLastPostTime(p.getFormatedTime()); 148 149 tm.update(t); 150 151 if (first) { 152 t = tm.selectById(t.getId()); 153 } 154 155 TopicsCommon.updateBoardStatus(t, postId, firstPost, 156 tm, DataAccessDriver.getInstance().newForumDAO()); 157 158 ForumRepository.updateForumStats(t, u, p); 159 TopicsCommon.notifyUsers(t, tm); 160 161 udao.incrementPosts(p.getUserId()); 162 163 if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) { 164 PostRepository.append(p.getTopicId(), PostCommon.preparePostForDisplay(p)); 165 } 166 } 167 else { 168 PostDAO pm = DataAccessDriver.getInstance().newPostDAO(); 169 Post post = pm.selectById(postId); 170 171 if (post == null || !post.isModerationNeeded()) { 172 continue; 173 } 174 175 pm.delete(post); 176 177 new AttachmentCommon(this.request, post.getForumId()).deleteAttachments(postId, post.getForumId()); 178 179 int totalPosts = tm.getTotalPosts(post.getTopicId()); 180 181 if (totalPosts == 0) { 182 TopicsCommon.deleteTopic(post.getTopicId(), post.getForumId(), true); 183 } 184 } 185 } 186 } 187 } 188 189 public void save() throws Exception 190 { 191 this.doSave(); 192 this.view(); 193 } 194 } 195 | Popular Tags |