Search in sources :

Example 1 with PollDAO

use of net.jforum.dao.PollDAO 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)

Example 2 with PollDAO

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

the class PostAction method edit.

private void edit(boolean preview, Post p) {
    int userId = SessionFacade.getUserSession().getUserId();
    if (!preview) {
        PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
        p = pm.selectById(this.request.getIntParameter("post_id"));
        // The post exist?
        if (p.getId() == 0) {
            this.postNotFound();
            return;
        }
    }
    boolean isModerator = SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT);
    boolean canEdit = SessionFacade.isLogged() && (isModerator || p.getUserId() == userId);
    if (!canEdit) {
        this.setTemplateName(TemplateKeys.POSTS_EDIT_CANNOTEDIT);
        this.context.put("message", I18n.getMessage("CannotEditPost"));
    } else {
        Topic topic = TopicRepository.getTopic(new Topic(p.getTopicId()));
        if (topic == null) {
            topic = DataAccessDriver.getInstance().newTopicDAO().selectRaw(p.getTopicId());
        }
        if (!TopicsCommon.isTopicAccessible(topic.getForumId())) {
            return;
        }
        if (topic.getStatus() == Topic.STATUS_LOCKED && !isModerator) {
            this.topicLocked();
            return;
        }
        if (preview && this.request.getParameter("topic_type") != null) {
            topic.setType(this.request.getIntParameter("topic_type"));
        }
        if (p.hasAttachments()) {
            this.context.put("attachments", DataAccessDriver.getInstance().newAttachmentDAO().selectAttachments(p.getId()));
        }
        Poll poll = null;
        if (topic.isVote() && topic.getFirstPostId() == p.getId()) {
            // It has a poll associated with the topic
            PollDAO poolDao = DataAccessDriver.getInstance().newPollDAO();
            poll = poolDao.selectById(topic.getVoteId());
        }
        this.setTemplateName(TemplateKeys.POSTS_EDIT);
        this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(p.getForumId())));
        this.context.put("moderationLoggingEnabled", SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED));
        QuotaLimit ql = new AttachmentCommon(this.request, p.getForumId()).getQuotaLimit(userId);
        this.context.put("maxAttachmentsSize", new Long(ql != null ? ql.getSizeInBytes() : 1));
        this.context.put("isEdit", true);
        this.context.put("maxAttachments", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_MAX_POST));
        this.context.put("smilies", SmiliesRepository.getSmilies());
        this.context.put("forum", ForumRepository.getForum(p.getForumId()));
        this.context.put("action", "editSave");
        this.context.put("post", p);
        this.context.put("setType", p.getId() == topic.getFirstPostId());
        this.context.put("topic", topic);
        this.context.put("poll", poll);
        this.context.put("pageTitle", I18n.getMessage("PostShow.messageTitle") + " " + p.getSubject());
        this.context.put("isModerator", isModerator);
        this.context.put("start", this.request.getParameter("start"));
        this.context.put("htmlAllowed", SecurityRepository.canAccess(SecurityConstants.PERM_HTML_DISABLED, Integer.toString(topic.getForumId())));
        this.context.put("canCreateStickyOrAnnouncementTopics", SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_STICKY_ANNOUNCEMENT_TOPICS));
        this.context.put("canCreatePolls", SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_POLL));
    }
    UserDAO udao = DataAccessDriver.getInstance().newUserDAO();
    User u = udao.selectById(userId);
    ViewCommon.prepareUserSignature(u);
    if (preview) {
        u.setNotifyOnMessagesEnabled(this.request.getParameter("notify") != null);
        if (u.getId() != p.getUserId()) {
            // Probably a moderator is editing the message
            User previewUser = udao.selectById(p.getUserId());
            ViewCommon.prepareUserSignature(previewUser);
            this.context.put("previewUser", previewUser);
        }
    }
    this.context.put("user", u);
}
Also used : PollDAO(net.jforum.dao.PollDAO) User(net.jforum.entities.User) PostDAO(net.jforum.dao.PostDAO) UserDAO(net.jforum.dao.UserDAO) Poll(net.jforum.entities.Poll) Topic(net.jforum.entities.Topic) QuotaLimit(net.jforum.entities.QuotaLimit) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Example 3 with PollDAO

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

the class PostAction method list.

public void list() {
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    PollDAO pollDao = DataAccessDriver.getInstance().newPollDAO();
    TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
    UserSession us = SessionFacade.getUserSession();
    int anonymousUser = SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID);
    boolean logged = SessionFacade.isLogged();
    int topicId = this.request.getIntParameter("topic_id");
    Topic topic = TopicRepository.getTopic(new Topic(topicId));
    if (topic == null) {
        topic = topicDao.selectById(topicId);
    }
    // The topic exists?
    if (topic.getId() == 0) {
        this.topicNotFound();
        return;
    }
    // Shall we proceed?
    Forum forum = ForumRepository.getForum(topic.getForumId());
    if (!logged) {
        if (forum == null || !ForumRepository.isCategoryAccessible(forum.getCategoryId())) {
            this.setTemplateName(ViewCommon.contextToLogin());
            return;
        }
    } else if (!TopicsCommon.isTopicAccessible(topic.getForumId())) {
        return;
    }
    int count = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
    int start = ViewCommon.getStartPage();
    PermissionControl pc = SecurityRepository.get(us.getUserId());
    boolean moderatorCanEdit = false;
    if (pc.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT)) {
        moderatorCanEdit = true;
    }
    List helperList = PostCommon.topicPosts(postDao, moderatorCanEdit, us.getUserId(), topic.getId(), start, count);
    // Is moderation pending for the topic?
    if (topic.isModerated() && helperList.size() == 0) {
        this.notModeratedYet();
        return;
    }
    // Set the topic status as read
    if (logged) {
        topicDao.updateReadStatus(topic.getId(), us.getUserId(), true);
    }
    boolean canVoteOnPoll = logged && SecurityRepository.canAccess(SecurityConstants.PERM_VOTE);
    Poll poll = null;
    if (topic.isVote()) {
        // It has a poll associated with the topic
        poll = pollDao.selectById(topic.getVoteId());
        if (canVoteOnPoll) {
            canVoteOnPoll = !pollDao.hasUserVotedOnPoll(topic.getVoteId(), us.getUserId());
        }
    }
    topicDao.incrementTotalViews(topic.getId());
    topic.setTotalViews(topic.getTotalViews() + 1);
    if (us.getUserId() != anonymousUser) {
        SessionFacade.getTopicsReadTime().put(new Integer(topic.getId()), new Long(System.currentTimeMillis()));
    }
    boolean karmaEnabled = SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED);
    Map userVotes = new HashMap();
    if (logged && karmaEnabled) {
        userVotes = DataAccessDriver.getInstance().newKarmaDAO().getUserVotes(topic.getId(), us.getUserId());
    }
    this.setTemplateName(TemplateKeys.POSTS_LIST);
    this.context.put("attachmentsEnabled", pc.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(topic.getForumId())));
    this.context.put("canDownloadAttachments", pc.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD));
    this.context.put("thumbShowBox", SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_THUMB_BOX_SHOW));
    this.context.put("am", new AttachmentCommon(this.request, topic.getForumId()));
    this.context.put("karmaVotes", userVotes);
    this.context.put("rssEnabled", SystemGlobals.getBoolValue(ConfigKeys.RSS_ENABLED));
    this.context.put("canRemove", pc.canAccess(SecurityConstants.PERM_MODERATION_POST_REMOVE));
    this.context.put("moderatorCanEdit", moderatorCanEdit);
    this.context.put("allCategories", ForumCommon.getAllCategoriesAndForums(false));
    this.context.put("topic", topic);
    this.context.put("poll", poll);
    this.context.put("canVoteOnPoll", canVoteOnPoll);
    this.context.put("rank", new RankingRepository());
    this.context.put("posts", helperList);
    this.context.put("forum", forum);
    this.context.put("karmaMin", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MIN_POINTS)));
    this.context.put("karmaMax", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MAX_POINTS)));
    this.context.put("avatarAllowExternalUrl", SystemGlobals.getBoolValue(ConfigKeys.AVATAR_ALLOW_EXTERNAL_URL));
    this.context.put("moderationLoggingEnabled", SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED));
    this.context.put("needCaptcha", SystemGlobals.getBoolValue(ConfigKeys.CAPTCHA_POSTS));
    Map topicPosters = topicDao.topicPosters(topic.getId());
    for (Iterator iter = topicPosters.values().iterator(); iter.hasNext(); ) {
        ViewCommon.prepareUserSignature((User) iter.next());
    }
    this.context.put("users", topicPosters);
    this.context.put("anonymousPosts", pc.canAccess(SecurityConstants.PERM_ANONYMOUS_POST, Integer.toString(topic.getForumId())));
    this.context.put("watching", topicDao.isUserSubscribed(topicId, SessionFacade.getUserSession().getUserId()));
    this.context.put("pageTitle", topic.getTitle());
    this.context.put("isAdmin", pc.canAccess(SecurityConstants.PERM_ADMINISTRATION));
    this.context.put("readonly", !pc.canAccess(SecurityConstants.PERM_READ_ONLY_FORUMS, Integer.toString(topic.getForumId())));
    this.context.put("replyOnly", !pc.canAccess(SecurityConstants.PERM_REPLY_ONLY, Integer.toString(topic.getForumId())));
    this.context.put("isModerator", us.isModerator(topic.getForumId()));
    ViewCommon.contextToPagination(start, topic.getTotalReplies() + 1, count);
    TopicsCommon.topicListingBase();
    TopicRepository.updateTopic(topic);
}
Also used : PermissionControl(net.jforum.security.PermissionControl) HashMap(java.util.HashMap) TopicDAO(net.jforum.dao.TopicDAO) Forum(net.jforum.entities.Forum) PollDAO(net.jforum.dao.PollDAO) PostDAO(net.jforum.dao.PostDAO) UserSession(net.jforum.entities.UserSession) RankingRepository(net.jforum.repository.RankingRepository) Iterator(java.util.Iterator) Poll(net.jforum.entities.Poll) List(java.util.List) Topic(net.jforum.entities.Topic) Map(java.util.Map) HashMap(java.util.HashMap) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Example 4 with PollDAO

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

the class PostAction method vote.

/**
	 * Votes on a poll.
	 */
public void vote() {
    int pollId = this.request.getIntParameter("poll_id");
    int topicId = this.request.getIntParameter("topic_id");
    if (SessionFacade.isLogged() && this.request.getParameter("poll_option") != null) {
        Topic topic = TopicRepository.getTopic(new Topic(topicId));
        if (topic == null) {
            topic = DataAccessDriver.getInstance().newTopicDAO().selectRaw(topicId);
        }
        if (topic.getStatus() == Topic.STATUS_LOCKED) {
            this.topicLocked();
            return;
        }
        // They voted, save the value
        int optionId = this.request.getIntParameter("poll_option");
        PollDAO dao = DataAccessDriver.getInstance().newPollDAO();
        //vote on the poll
        UserSession user = SessionFacade.getUserSession();
        dao.voteOnPoll(pollId, optionId, user.getUserId(), request.getRemoteAddr());
    }
    JForumExecutionContext.setRedirect(this.request.getContextPath() + "/posts/list/" + topicId + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
}
Also used : PollDAO(net.jforum.dao.PollDAO) UserSession(net.jforum.entities.UserSession) Topic(net.jforum.entities.Topic)

Example 5 with PollDAO

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

the class PostAction method insertSave.

public void insertSave() {
    int forumId = this.request.getIntParameter("forum_id");
    boolean firstPost = false;
    if (!this.anonymousPost(forumId)) {
        return;
    }
    Topic t = new Topic(-1);
    t.setForumId(forumId);
    boolean newTopic = (this.request.getParameter("topic_id") == null);
    if (!TopicsCommon.isTopicAccessible(t.getForumId()) || this.isForumReadonly(t.getForumId(), newTopic)) {
        return;
    }
    TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    PollDAO poolDao = DataAccessDriver.getInstance().newPollDAO();
    ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
    if (!newTopic) {
        int topicId = this.request.getIntParameter("topic_id");
        t = TopicRepository.getTopic(new Topic(topicId));
        if (t == null) {
            t = topicDao.selectById(topicId);
        }
        // Could not find the topic. The topicId sent was invalid
        if (t == null || t.getId() == 0) {
            newTopic = true;
        } else {
            if (!TopicsCommon.isTopicAccessible(t.getForumId())) {
                return;
            }
            // Cannot insert new messages on locked topics
            if (t.getStatus() == Topic.STATUS_LOCKED) {
                this.topicLocked();
                return;
            }
        }
    }
    // checking above set the newTopic var to true
    if (newTopic) {
        if (this.isReplyOnly(forumId)) {
            this.replyOnly();
            return;
        }
        if (this.request.getParameter("topic_type") != null) {
            t.setType(this.request.getIntParameter("topic_type"));
            if (t.getType() != Topic.TYPE_NORMAL && !SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_STICKY_ANNOUNCEMENT_TOPICS)) {
                t.setType(Topic.TYPE_NORMAL);
            }
        }
    }
    UserSession us = SessionFacade.getUserSession();
    User u = DataAccessDriver.getInstance().newUserDAO().selectById(us.getUserId());
    if ("1".equals(this.request.getParameter("quick")) && SessionFacade.isLogged()) {
        this.request.addParameter("notify", u.isNotifyOnMessagesEnabled() ? "1" : null);
        this.request.addParameter("attach_sig", u.getAttachSignatureEnabled() ? "1" : "0");
    } else {
        u.setId(us.getUserId());
        u.setUsername(us.getUsername());
    }
    // Set the Post
    Post p = PostCommon.fillPostFromRequest();
    if (p.getText() == null || p.getText().trim().equals("")) {
        this.insert();
        return;
    }
    // Check the elapsed time since the last post from the user
    int delay = SystemGlobals.getIntValue(ConfigKeys.POSTS_NEW_DELAY);
    if (delay > 0) {
        Long lastPostTime = (Long) SessionFacade.getAttribute(ConfigKeys.LAST_POST_TIME);
        if (lastPostTime != null) {
            if (System.currentTimeMillis() < (lastPostTime.longValue() + delay)) {
                this.context.put("post", p);
                this.context.put("start", this.request.getParameter("start"));
                this.context.put("error", I18n.getMessage("PostForm.tooSoon"));
                this.insert();
                return;
            }
        }
    }
    p.setForumId(this.request.getIntParameter("forum_id"));
    if (StringUtils.isBlank(p.getSubject())) {
        p.setSubject(t.getTitle());
    }
    boolean needCaptcha = SystemGlobals.getBoolValue(ConfigKeys.CAPTCHA_POSTS) && request.getSessionContext().getAttribute(ConfigKeys.REQUEST_IGNORE_CAPTCHA) == null;
    if (needCaptcha) {
        if (!us.validateCaptchaResponse(this.request.getParameter("captcha_anwser"))) {
            this.context.put("post", p);
            this.context.put("start", this.request.getParameter("start"));
            this.context.put("error", I18n.getMessage("CaptchaResponseFails"));
            this.insert();
            return;
        }
    }
    boolean preview = "1".equals(this.request.getParameter("preview"));
    if (!preview) {
        AttachmentCommon attachments = new AttachmentCommon(this.request, forumId);
        try {
            attachments.preProcess();
        } catch (AttachmentException e) {
            JForumExecutionContext.enableRollback();
            p.setText(this.request.getParameter("message"));
            p.setId(0);
            this.context.put("errorMessage", e.getMessage());
            this.context.put("post", p);
            this.insert();
            return;
        }
        Forum forum = ForumRepository.getForum(forumId);
        PermissionControl pc = SecurityRepository.get(us.getUserId());
        // Moderators and admins don't need to have their messages moderated
        boolean moderate = (forum.isModerated() && !pc.canAccess(SecurityConstants.PERM_MODERATION) && !pc.canAccess(SecurityConstants.PERM_ADMINISTRATION));
        if (newTopic) {
            t.setTime(new Date());
            t.setTitle(this.request.getParameter("subject"));
            t.setModerated(moderate);
            t.setPostedBy(u);
            t.setFirstPostTime(ViewCommon.formatDate(t.getTime()));
            int topicId = topicDao.addNew(t);
            t.setId(topicId);
            firstPost = true;
        }
        if (!firstPost && pc.canAccess(SecurityConstants.PERM_REPLY_WITHOUT_MODERATION, Integer.toString(t.getForumId()))) {
            moderate = false;
        }
        // Topic watch
        if (this.request.getParameter("notify") != null) {
            this.watch(topicDao, t.getId(), u.getId());
        }
        p.setTopicId(t.getId());
        // add a poll
        Poll poll = PollCommon.fillPollFromRequest();
        if (poll != null && newTopic) {
            poll.setTopicId(t.getId());
            if (poll.getOptions().size() < 2) {
                //it is not a valid poll, cancel the post
                JForumExecutionContext.enableRollback();
                p.setText(this.request.getParameter("message"));
                p.setId(0);
                this.context.put("errorMessage", I18n.getMessage("PostForm.needMorePollOptions"));
                this.context.put("post", p);
                this.context.put("poll", poll);
                this.insert();
                return;
            }
            poolDao.addNew(poll);
            t.setVoteId(poll.getId());
        }
        // Save the remaining stuff
        p.setModerate(moderate);
        int postId = postDao.addNew(p);
        if (newTopic) {
            t.setFirstPostId(postId);
        }
        if (!moderate) {
            t.setLastPostId(postId);
            t.setLastPostBy(u);
            t.setLastPostDate(p.getTime());
            t.setLastPostTime(p.getFormatedTime());
        }
        topicDao.update(t);
        attachments.insertAttachments(p);
        if (!moderate) {
            StringBuffer path = new StringBuffer(512);
            path.append(this.request.getContextPath()).append("/posts/list/");
            int start = ViewCommon.getStartPage();
            path.append(this.startPage(t, start)).append("/").append(t.getId()).append(SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION)).append('#').append(postId);
            JForumExecutionContext.setRedirect(path.toString());
            if (newTopic) {
                // Notify "forum new topic" users
                ForumCommon.notifyUsers(forum, t, p);
            } else {
                t.setTotalReplies(t.getTotalReplies() + 1);
                TopicsCommon.notifyUsers(t, p);
            }
            // Update forum stats, cache and etc
            t.setTotalViews(t.getTotalViews() + 1);
            DataAccessDriver.getInstance().newUserDAO().incrementPosts(p.getUserId());
            TopicsCommon.updateBoardStatus(t, postId, firstPost, topicDao, forumDao);
            ForumRepository.updateForumStats(t, u, p);
            int anonymousUser = SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID);
            if (u.getId() != anonymousUser) {
                SessionFacade.getTopicsReadTime().put(new Integer(t.getId()), new Long(p.getTime().getTime()));
            }
            if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
                SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
                p.setFormatedTime(df.format(p.getTime()));
                PostRepository.append(p.getTopicId(), PostCommon.preparePostForDisplay(p));
            }
        } else {
            JForumExecutionContext.setRedirect(this.request.getContextPath() + "/posts/waitingModeration/" + (firstPost ? 0 : t.getId()) + "/" + t.getForumId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
        }
        if (delay > 0) {
            SessionFacade.setAttribute(ConfigKeys.LAST_POST_TIME, new Long(System.currentTimeMillis()));
        }
    } else {
        this.context.put("preview", true);
        this.context.put("post", p);
        this.context.put("start", this.request.getParameter("start"));
        Post postPreview = new Post(p);
        this.context.put("postPreview", PostCommon.preparePostForDisplay(postPreview));
        this.insert();
    }
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) User(net.jforum.entities.User) PermissionControl(net.jforum.security.PermissionControl) Post(net.jforum.entities.Post) TopicDAO(net.jforum.dao.TopicDAO) Date(java.util.Date) Forum(net.jforum.entities.Forum) AttachmentException(net.jforum.exceptions.AttachmentException) PollDAO(net.jforum.dao.PollDAO) PostDAO(net.jforum.dao.PostDAO) UserSession(net.jforum.entities.UserSession) Poll(net.jforum.entities.Poll) Topic(net.jforum.entities.Topic) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

PollDAO (net.jforum.dao.PollDAO)6 Topic (net.jforum.entities.Topic)6 PostDAO (net.jforum.dao.PostDAO)5 Poll (net.jforum.entities.Poll)4 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)4 TopicDAO (net.jforum.dao.TopicDAO)3 UserSession (net.jforum.entities.UserSession)3 Iterator (java.util.Iterator)2 ForumDAO (net.jforum.dao.ForumDAO)2 Forum (net.jforum.entities.Forum)2 Post (net.jforum.entities.Post)2 User (net.jforum.entities.User)2 AttachmentException (net.jforum.exceptions.AttachmentException)2 PermissionControl (net.jforum.security.PermissionControl)2 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1