Search in sources :

Example 11 with Post

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

the class GenericPostDAO 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 12 with Post

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

the class GenericModerationDAO method getPost.

protected Post getPost(ResultSet rs) throws SQLException {
    Post p = new Post();
    p.setPostUsername(rs.getString("username"));
    p.setId(rs.getInt("post_id"));
    p.setUserId(rs.getInt("user_id"));
    p.setBbCodeEnabled(rs.getInt("enable_bbcode") == 1);
    p.setHtmlEnabled(rs.getInt("enable_html") == 1);
    p.setSmiliesEnabled(rs.getInt("enable_smilies") == 1);
    p.setSubject(rs.getString("post_subject"));
    p.setText(this.getPostTextFromResultSet(rs));
    return p;
}
Also used : Post(net.jforum.entities.Post)

Example 13 with Post

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

the class GenericPrivateMessageDAO method getPm.

protected PrivateMessage getPm(ResultSet rs, boolean full) throws SQLException {
    PrivateMessage pm = new PrivateMessage();
    Post p = new Post();
    pm.setId(rs.getInt("privmsgs_id"));
    pm.setType(rs.getInt("privmsgs_type"));
    p.setTime(new Date(rs.getTimestamp("privmsgs_date").getTime()));
    p.setSubject(rs.getString("privmsgs_subject"));
    SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
    pm.setFormatedDate(df.format(p.getTime()));
    if (full) {
        UserDAO um = DataAccessDriver.getInstance().newUserDAO();
        pm.setFromUser(um.selectById(rs.getInt("privmsgs_from_userid")));
        pm.setToUser(um.selectById(rs.getInt("privmsgs_to_userid")));
        p.setBbCodeEnabled(rs.getInt("privmsgs_enable_bbcode") == 1);
        p.setSignatureEnabled(rs.getInt("privmsgs_attach_sig") == 1);
        p.setHtmlEnabled(rs.getInt("privmsgs_enable_html") == 1);
        p.setSmiliesEnabled(rs.getInt("privmsgs_enable_smilies") == 1);
        p.setText(this.getPmText(rs));
    }
    pm.setPost(p);
    return pm;
}
Also used : UserDAO(net.jforum.dao.UserDAO) Post(net.jforum.entities.Post) PrivateMessage(net.jforum.entities.PrivateMessage) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 14 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)

Example 15 with Post

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

the class PostAction method downloadAttach.

public void downloadAttach() {
    int id = this.request.getIntParameter("attach_id");
    if (!SessionFacade.isLogged() && !SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_ANONYMOUS)) {
        String referer = this.request.getHeader("Referer");
        if (referer != null) {
            this.setTemplateName(ViewCommon.contextToLogin(referer));
        } else {
            this.setTemplateName(ViewCommon.contextToLogin());
        }
        return;
    }
    AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
    Attachment a = am.selectAttachmentById(id);
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    Post post = postDao.selectById(a.getPostId());
    String forumId = Integer.toString(post.getForumId());
    boolean attachmentsEnabled = SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, forumId);
    boolean attachmentsDownload = SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD, forumId);
    if (!attachmentsEnabled && !attachmentsDownload) {
        this.setTemplateName(TemplateKeys.POSTS_CANNOT_DOWNLOAD);
        this.context.put("message", I18n.getMessage("Attachments.featureDisabled"));
        return;
    }
    String filename = SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_STORE_DIR) + "/" + a.getInfo().getPhysicalFilename();
    if (!new File(filename).exists()) {
        this.setTemplateName(TemplateKeys.POSTS_ATTACH_NOTFOUND);
        this.context.put("message", I18n.getMessage("Attachments.notFound"));
        return;
    }
    FileInputStream fis = null;
    OutputStream os = null;
    try {
        a.getInfo().setDownloadCount(a.getInfo().getDownloadCount() + 1);
        am.updateAttachment(a);
        fis = new FileInputStream(filename);
        os = response.getOutputStream();
        if (am.isPhysicalDownloadMode(a.getInfo().getExtension().getExtensionGroupId())) {
            this.response.setContentType("application/octet-stream");
        } else {
            this.response.setContentType(a.getInfo().getMimetype());
        }
        if (this.request.getHeader("User-Agent").indexOf("Firefox") != -1) {
            this.response.setHeader("Content-Disposition", "attachment; filename=\"" + new String(a.getInfo().getRealFilename().getBytes(SystemGlobals.getValue(ConfigKeys.ENCODING)), SystemGlobals.getValue(ConfigKeys.DEFAULT_CONTAINER_ENCODING)) + "\";");
        } else {
            this.response.setHeader("Content-Disposition", "attachment; filename=\"" + ViewCommon.toUtf8String(a.getInfo().getRealFilename()) + "\";");
        }
        this.response.setContentLength((int) a.getInfo().getFilesize());
        int c;
        byte[] b = new byte[4096];
        while ((c = fis.read(b)) != -1) {
            os.write(b, 0, c);
        }
        JForumExecutionContext.enableCustomContent(true);
    } catch (IOException e) {
        throw new ForumException(e);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (Exception e) {
            }
        }
    }
}
Also used : AttachmentDAO(net.jforum.dao.AttachmentDAO) Post(net.jforum.entities.Post) OutputStream(java.io.OutputStream) Attachment(net.jforum.entities.Attachment) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AttachmentException(net.jforum.exceptions.AttachmentException) ForumException(net.jforum.exceptions.ForumException) IOException(java.io.IOException) ForumException(net.jforum.exceptions.ForumException) PostDAO(net.jforum.dao.PostDAO) File(java.io.File)

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