Search in sources :

Example 16 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class AjaxAction method loadPostContents.

public void loadPostContents() {
    int postId = this.request.getIntParameter("id");
    PostDAO dao = DataAccessDriver.getInstance().newPostDAO();
    Post post = dao.selectById(postId);
    this.setTemplateName(TemplateKeys.AJAX_LOAD_POST);
    this.context.put("post", post);
}
Also used : PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post)

Example 17 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class AjaxAction method savePost.

public void savePost() {
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    Post post = postDao.selectById(this.request.getIntParameter("id"));
    String originalMessage = post.getText();
    if (!PostCommon.canEditPost(post)) {
        post = PostCommon.preparePostForDisplay(post);
    } else {
        post.setText(this.request.getParameter("value"));
        postDao.update(post);
        SearchFacade.update(post);
        post = PostCommon.preparePostForDisplay(post);
    }
    boolean isModerator = SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT);
    if (SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED) && isModerator && post.getUserId() != SessionFacade.getUserSession().getUserId()) {
        ModerationHelper helper = new ModerationHelper();
        this.request.addParameter("log_original_message", originalMessage);
        this.request.addParameter("post_id", String.valueOf(post.getId()));
        this.request.addParameter("topic_id", String.valueOf(post.getTopicId()));
        ModerationLog log = helper.buildModerationLogFromRequest();
        log.getPosterUser().setId(post.getUserId());
        helper.saveModerationLog(log);
    }
    if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
        PostRepository.update(post.getTopicId(), PostCommon.preparePostForDisplay(post));
    }
    this.setTemplateName(TemplateKeys.AJAX_LOAD_POST);
    this.context.put("post", post);
}
Also used : PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) ModerationLog(net.jforum.entities.ModerationLog)

Example 18 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class AjaxAction method previewPost.

public void previewPost() {
    Post post = new Post();
    post.setText(this.request.getParameter("text"));
    post.setSubject(this.request.getParameter("subject"));
    post.setHtmlEnabled("true".equals(this.request.getParameter("html")));
    post.setBbCodeEnabled("true".equals(this.request.getParameter("bbcode")));
    post.setSmiliesEnabled("true".equals(this.request.getParameter("smilies")));
    if (post.isHtmlEnabled()) {
        post.setText(new SafeHtml().makeSafe(post.getText()));
    }
    post = PostCommon.preparePostForDisplay(post);
    post.setSubject(StringEscapeUtils.escapeJavaScript(post.getSubject()));
    post.setText(StringEscapeUtils.escapeJavaScript(post.getText()));
    this.setTemplateName(TemplateKeys.AJAX_PREVIEW_POST);
    this.context.put("post", post);
}
Also used : Post(net.jforum.entities.Post) SafeHtml(net.jforum.util.SafeHtml)

Example 19 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class SqlServer2000PostDAO method buildPostForRSS.

private Post buildPostForRSS(ResultSet rs) throws SQLException {
    Post post = new Post();
    post.setId(rs.getInt("post_id"));
    post.setSubject(rs.getString("subject"));
    post.setText(rs.getString("post_text"));
    post.setTopicId(rs.getInt("topic_id"));
    post.setForumId(rs.getInt("forum_id"));
    post.setUserId(rs.getInt("user_id"));
    post.setPostUsername(rs.getString("username"));
    post.setTime(new Date(rs.getTimestamp("post_time").getTime()));
    return post;
}
Also used : Post(net.jforum.entities.Post) Date(java.util.Date)

Example 20 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class KarmaAction method insert.

public void insert() {
    if (!SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED)) {
        this.error("Karma.featureDisabled", null);
        return;
    }
    int postId = this.request.getIntParameter("post_id");
    int fromUserId = SessionFacade.getUserSession().getUserId();
    PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
    Post p = pm.selectById(postId);
    if (fromUserId == SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
        this.error("Karma.anonymousIsDenied", p);
        return;
    }
    if (p.getUserId() == fromUserId) {
        this.error("Karma.cannotSelfVote", p);
        return;
    }
    KarmaDAO km = DataAccessDriver.getInstance().newKarmaDAO();
    if (!km.userCanAddKarma(fromUserId, postId)) {
        this.error("Karma.alreadyVoted", p);
        return;
    }
    // Check range
    int points = this.request.getIntParameter("points");
    if (points < SystemGlobals.getIntValue(ConfigKeys.KARMA_MIN_POINTS) || points > SystemGlobals.getIntValue(ConfigKeys.KARMA_MAX_POINTS)) {
        this.error("Karma.invalidRange", p);
        return;
    }
    Karma karma = new Karma();
    karma.setFromUserId(fromUserId);
    karma.setPostUserId(p.getUserId());
    karma.setPostId(postId);
    karma.setTopicId(p.getTopicId());
    karma.setPoints(points);
    km.addKarma(karma);
    p.setKarma(new KarmaStatus(p.getId(), points));
    if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
        PostRepository.update(p.getTopicId(), PostCommon.preparePostForDisplay(p));
    }
    JForumExecutionContext.setRedirect(this.urlToTopic(p));
}
Also used : PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) KarmaDAO(net.jforum.dao.KarmaDAO) Karma(net.jforum.entities.Karma) KarmaStatus(net.jforum.entities.KarmaStatus)

Aggregations

Post (net.jforum.entities.Post)47 List (java.util.List)20 PostDAO (net.jforum.dao.PostDAO)15 ArrayList (java.util.ArrayList)13 Date (java.util.Date)11 PreparedStatement (java.sql.PreparedStatement)9 SQLException (java.sql.SQLException)9 Iterator (java.util.Iterator)9 DatabaseException (net.jforum.exceptions.DatabaseException)9 ResultSet (java.sql.ResultSet)8 Topic (net.jforum.entities.Topic)8 User (net.jforum.entities.User)8 TopicDAO (net.jforum.dao.TopicDAO)7 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)6 UserDAO (net.jforum.dao.UserDAO)5 SimpleDateFormat (java.text.SimpleDateFormat)4 ModerationLog (net.jforum.entities.ModerationLog)4 ForumDAO (net.jforum.dao.ForumDAO)3 AttachmentException (net.jforum.exceptions.AttachmentException)3 IOException (java.io.IOException)2