Search in sources :

Example 6 with TopicDAO

use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.

the class TopicsCommon method notifyUsers.

/**
	 * Sends a "new post" notification message to all users watching the topic.
	 * 
	 * @param t The changed topic
	 * @param p The new message
	 */
public static void notifyUsers(Topic t, Post p) {
    if (SystemGlobals.getBoolValue(ConfigKeys.MAIL_NOTIFY_ANSWERS)) {
        TopicDAO dao = DataAccessDriver.getInstance().newTopicDAO();
        List usersToNotify = dao.notifyUsers(t);
        // subscribed to the topic
        if (usersToNotify != null && usersToNotify.size() > 0) {
            Executor.execute(new EmailSenderTask(new TopicReplySpammer(t, p, usersToNotify)));
        }
    }
}
Also used : EmailSenderTask(net.jforum.util.mail.EmailSenderTask) TopicDAO(net.jforum.dao.TopicDAO) ArrayList(java.util.ArrayList) List(java.util.List) TopicReplySpammer(net.jforum.util.mail.TopicReplySpammer)

Example 7 with TopicDAO

use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.

the class ModerationAction method doSave.

public void doSave() {
    String[] posts = this.request.getParameterValues("post_id");
    if (posts != null) {
        TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
        for (int i = 0; i < posts.length; i++) {
            int postId = Integer.parseInt(posts[i]);
            String status = this.request.getParameter("status_" + postId);
            if ("defer".startsWith(status)) {
                continue;
            }
            if ("aprove".startsWith(status)) {
                Post p = DataAccessDriver.getInstance().newPostDAO().selectById(postId);
                // Check is the post is in fact waiting for moderation
                if (!p.isModerationNeeded()) {
                    continue;
                }
                UserDAO userDao = DataAccessDriver.getInstance().newUserDAO();
                User u = userDao.selectById(p.getUserId());
                boolean first = false;
                Topic t = TopicRepository.getTopic(new Topic(p.getTopicId()));
                if (t == null) {
                    t = topicDao.selectById(p.getTopicId());
                    if (t.getId() == 0) {
                        first = true;
                        t = topicDao.selectRaw(p.getTopicId());
                    }
                }
                DataAccessDriver.getInstance().newModerationDAO().aprovePost(postId);
                boolean firstPost = (t.getFirstPostId() == postId);
                if (!firstPost) {
                    t.setTotalReplies(t.getTotalReplies() + 1);
                }
                t.setLastPostId(postId);
                t.setLastPostBy(u);
                t.setLastPostDate(p.getTime());
                t.setLastPostTime(p.getFormatedTime());
                topicDao.update(t);
                if (first) {
                    t = topicDao.selectById(t.getId());
                }
                TopicsCommon.updateBoardStatus(t, postId, firstPost, topicDao, DataAccessDriver.getInstance().newForumDAO());
                ForumRepository.updateForumStats(t, u, p);
                TopicsCommon.notifyUsers(t, p);
                userDao.incrementPosts(p.getUserId());
                if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
                    PostRepository.append(p.getTopicId(), PostCommon.preparePostForDisplay(p));
                }
            } else {
                PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
                Post post = pm.selectById(postId);
                if (post == null || !post.isModerationNeeded()) {
                    continue;
                }
                pm.delete(post);
                new AttachmentCommon(this.request, post.getForumId()).deleteAttachments(postId, post.getForumId());
                int totalPosts = topicDao.getTotalPosts(post.getTopicId());
                if (totalPosts == 0) {
                    TopicsCommon.deleteTopic(post.getTopicId(), post.getForumId(), true);
                }
            }
        }
    }
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) TopicDAO(net.jforum.dao.TopicDAO) Topic(net.jforum.entities.Topic) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Example 8 with TopicDAO

use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.

the class TopicRepository method loadMostRecentTopics.

/**
	 * Add recent topics to the cache
	 */
public static synchronized List loadMostRecentTopics() {
    TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
    int limit = SystemGlobals.getIntValue(ConfigKeys.RECENT_TOPICS);
    List l = tm.selectRecentTopics(limit);
    cache.add(FQN, RECENT, new LinkedList(l));
    return l;
}
Also used : TopicDAO(net.jforum.dao.TopicDAO) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 9 with TopicDAO

use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.

the class TopicRepository method loadHottestTopics.

/**
	 * Add hottest topics to the cache
	 */
public static synchronized List loadHottestTopics() {
    TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
    int limit = SystemGlobals.getIntValue(ConfigKeys.HOTTEST_TOPICS);
    List l = tm.selectHottestTopics(limit);
    cache.add(FQN, HOTTEST, new LinkedList(l));
    return l;
}
Also used : TopicDAO(net.jforum.dao.TopicDAO) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 10 with TopicDAO

use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.

the class PostAction method editSave.

public void editSave() {
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    PollDAO pollDao = DataAccessDriver.getInstance().newPollDAO();
    TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
    Post post = postDao.selectById(this.request.getIntParameter("post_id"));
    if (!PostCommon.canEditPost(post)) {
        this.cannotEdit();
        return;
    }
    boolean isModerator = SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT);
    String originalMessage = post.getText();
    post = PostCommon.fillPostFromRequest(post, true);
    // The user wants to preview the message before posting it?
    if ("1".equals(this.request.getParameter("preview"))) {
        this.context.put("preview", true);
        Post postPreview = new Post(post);
        this.context.put("postPreview", PostCommon.preparePostForDisplay(postPreview));
        this.edit(true, post);
    } else {
        AttachmentCommon attachments = new AttachmentCommon(this.request, post.getForumId());
        try {
            attachments.preProcess();
        } catch (AttachmentException e) {
            JForumExecutionContext.enableRollback();
            post.setText(this.request.getParameter("message"));
            this.context.put("errorMessage", e.getMessage());
            this.context.put("post", post);
            this.edit(false, post);
            return;
        }
        Topic t = TopicRepository.getTopic(new Topic(post.getTopicId()));
        if (t == null) {
            t = topicDao.selectById(post.getTopicId());
        }
        if (!TopicsCommon.isTopicAccessible(t.getForumId())) {
            return;
        }
        if (t.getStatus() == Topic.STATUS_LOCKED && !SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT)) {
            this.topicLocked();
            return;
        }
        postDao.update(post);
        // Attachments
        attachments.editAttachments(post.getId(), post.getForumId());
        attachments.insertAttachments(post);
        // The first message (the one which originated the topic) was changed
        if (t.getFirstPostId() == post.getId()) {
            t.setTitle(post.getSubject());
            int newType = this.request.getIntParameter("topic_type");
            boolean changeType = SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_STICKY_ANNOUNCEMENT_TOPICS) && newType != t.getType();
            if (changeType) {
                t.setType(newType);
            }
            // Poll
            Poll poll = PollCommon.fillPollFromRequest();
            if (poll != null && !t.isVote()) {
                // They added a poll
                poll.setTopicId(t.getId());
                if (!this.ensurePollMinimumOptions(post, poll)) {
                    return;
                }
                pollDao.addNew(poll);
                t.setVoteId(poll.getId());
            } else if (poll != null) {
                if (!this.ensurePollMinimumOptions(post, poll)) {
                    return;
                }
                // They edited the poll in the topic
                Poll existing = pollDao.selectById(t.getVoteId());
                PollChanges changes = new PollChanges(existing, poll);
                if (changes.hasChanges()) {
                    poll.setId(existing.getId());
                    poll.setChanges(changes);
                    pollDao.update(poll);
                }
            } else if (t.isVote()) {
                // They deleted the poll from the topic
                pollDao.delete(t.getVoteId());
                t.setVoteId(0);
            }
            topicDao.update(t);
            if (changeType) {
                TopicRepository.addTopic(t);
            } else {
                TopicRepository.updateTopic(t);
            }
        }
        if (SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED) && isModerator && post.getUserId() != SessionFacade.getUserSession().getUserId()) {
            ModerationHelper helper = new ModerationHelper();
            this.request.addParameter("log_original_message", originalMessage);
            ModerationLog log = helper.buildModerationLogFromRequest();
            log.getPosterUser().setId(post.getUserId());
            helper.saveModerationLog(log);
        }
        if (this.request.getParameter("notify") == null) {
            topicDao.removeSubscription(post.getTopicId(), SessionFacade.getUserSession().getUserId());
        }
        String path = this.request.getContextPath() + "/posts/list/";
        int start = ViewCommon.getStartPage();
        if (start > 0) {
            path += start + "/";
        }
        path += post.getTopicId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) + "#" + post.getId();
        JForumExecutionContext.setRedirect(path);
        if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
            PostRepository.update(post.getTopicId(), PostCommon.preparePostForDisplay(post));
        }
    }
}
Also used : Post(net.jforum.entities.Post) ModerationLog(net.jforum.entities.ModerationLog) TopicDAO(net.jforum.dao.TopicDAO) AttachmentException(net.jforum.exceptions.AttachmentException) PollDAO(net.jforum.dao.PollDAO) PostDAO(net.jforum.dao.PostDAO) PollChanges(net.jforum.entities.PollChanges) Poll(net.jforum.entities.Poll) Topic(net.jforum.entities.Topic) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Aggregations

TopicDAO (net.jforum.dao.TopicDAO)21 Topic (net.jforum.entities.Topic)14 List (java.util.List)10 PostDAO (net.jforum.dao.PostDAO)10 Post (net.jforum.entities.Post)7 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)6 ArrayList (java.util.ArrayList)5 ForumDAO (net.jforum.dao.ForumDAO)5 Forum (net.jforum.entities.Forum)5 Iterator (java.util.Iterator)4 ModerationLog (net.jforum.entities.ModerationLog)4 User (net.jforum.entities.User)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 PollDAO (net.jforum.dao.PollDAO)3 Poll (net.jforum.entities.Poll)3 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2