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);
}
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);
}
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);
}
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;
}
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));
}
Aggregations