Search in sources :

Example 41 with Post

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

the class ModerationAction method showActivityLog.

public void showActivityLog() {
    if (!SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_LOG)) {
        this.denied();
        return;
    }
    ModerationLogDAO dao = DataAccessDriver.getInstance().newModerationLogDAO();
    int start = ViewCommon.getStartPage();
    int recordsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
    List list = dao.selectAll(start, recordsPerPage);
    boolean canAccessFullModerationLog = SecurityRepository.canAccess(SecurityConstants.PERM_FULL_MODERATION_LOG);
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
    for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        ModerationLog log = (ModerationLog) iter.next();
        if (log.getPostId() > 0) {
            Post post = postDao.selectById(log.getPostId());
            if (post.getId() > 0 && ForumRepository.getForum(post.getForumId()) == null) {
                iter.remove();
                continue;
            }
        } else if (log.getTopicId() > 0) {
            Topic topic = topicDao.selectRaw(log.getTopicId());
            if (topic.getId() > 0 && ForumRepository.getForum(topic.getForumId()) == null) {
                iter.remove();
                continue;
            }
        }
        if (log.getOriginalMessage() != null && canAccessFullModerationLog) {
            Post post = new Post();
            post.setText(log.getOriginalMessage());
            log.setOriginalMessage(PostCommon.preparePostForDisplay(post).getText());
        }
    }
    this.setTemplateName(TemplateKeys.MODERATION_SHOW_ACTIVITY_LOG);
    this.context.put("activityLog", list);
    this.context.put("canAccessFullModerationLog", canAccessFullModerationLog);
    int totalRecords = dao.totalRecords();
    ViewCommon.contextToPagination(start, totalRecords, recordsPerPage);
}
Also used : PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) ModerationLog(net.jforum.entities.ModerationLog) Iterator(java.util.Iterator) TopicDAO(net.jforum.dao.TopicDAO) List(java.util.List) ModerationLogDAO(net.jforum.dao.ModerationLogDAO) Topic(net.jforum.entities.Topic)

Example 42 with Post

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

the class PostAction method listByUser.

public void listByUser() {
    PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
    UserDAO um = DataAccessDriver.getInstance().newUserDAO();
    TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
    User u = um.selectById(this.request.getIntParameter("user_id"));
    if (u.getId() == 0) {
        this.context.put("message", I18n.getMessage("User.notFound"));
        this.setTemplateName(TemplateKeys.USER_NOT_FOUND);
        return;
    }
    int count = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
    int start = ViewCommon.getStartPage();
    int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
    List posts = pm.selectByUserByLimit(u.getId(), start, postsPerPage);
    int totalMessages = pm.countUserPosts(u.getId());
    // get list of forums
    Map topics = new HashMap();
    Map forums = new HashMap();
    for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
        Post p = (Post) iter.next();
        if (!topics.containsKey(new Integer(p.getTopicId()))) {
            Topic t = TopicRepository.getTopic(new Topic(p.getTopicId()));
            if (t == null) {
                t = tm.selectRaw(p.getTopicId());
            }
            this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(t.getForumId())));
            this.context.put("am", new AttachmentCommon(this.request, t.getForumId()));
            topics.put(new Integer(t.getId()), t);
        }
        if (!forums.containsKey(new Integer(p.getForumId()))) {
            Forum f = ForumRepository.getForum(p.getForumId());
            if (f == null) {
                // Ok, probably the user does not have permission to see this forum
                iter.remove();
                totalMessages--;
                continue;
            }
            forums.put(new Integer(f.getId()), f);
        }
        PostCommon.preparePostForDisplay(p);
    }
    this.setTemplateName(TemplateKeys.POSTS_USER_POSTS_LIST);
    this.context.put("canDownloadAttachments", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD));
    this.context.put("rssEnabled", SystemGlobals.getBoolValue(ConfigKeys.RSS_ENABLED));
    this.context.put("allCategories", ForumCommon.getAllCategoriesAndForums(false));
    this.context.put("posts", posts);
    this.context.put("topics", topics);
    this.context.put("forums", forums);
    this.context.put("u", u);
    this.context.put("pageTitle", I18n.getMessage("PostShow.userPosts") + " " + u.getUsername());
    this.context.put("karmaMin", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MIN_POINTS)));
    this.context.put("karmaMax", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MAX_POINTS)));
    ViewCommon.contextToPagination(start, totalMessages, count);
}
Also used : User(net.jforum.entities.User) HashMap(java.util.HashMap) Post(net.jforum.entities.Post) TopicDAO(net.jforum.dao.TopicDAO) Forum(net.jforum.entities.Forum) PostDAO(net.jforum.dao.PostDAO) UserDAO(net.jforum.dao.UserDAO) Iterator(java.util.Iterator) 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 43 with Post

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

the class PostAction method quote.

public void quote() {
    PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
    Post p = pm.selectById(this.request.getIntParameter("post_id"));
    if (p.getId() == 0) {
        this.postNotFound();
        return;
    }
    if (p.isModerationNeeded()) {
        this.notModeratedYet();
        return;
    }
    if (!this.anonymousPost(p.getForumId())) {
        return;
    }
    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) {
        this.topicLocked();
        return;
    }
    this.setTemplateName(TemplateKeys.POSTS_QUOTE);
    this.context.put("forum", ForumRepository.getForum(p.getForumId()));
    this.context.put("action", "insertSave");
    this.context.put("post", p);
    UserDAO um = DataAccessDriver.getInstance().newUserDAO();
    User u = um.selectById(p.getUserId());
    int userId = SessionFacade.getUserSession().getUserId();
    this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(topic.getForumId())));
    QuotaLimit ql = new AttachmentCommon(this.request, topic.getForumId()).getQuotaLimit(userId);
    this.context.put("maxAttachmentsSize", new Long(ql != null ? ql.getSizeInBytes() : 1));
    this.context.put("moderationLoggingEnabled", SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED));
    this.context.put("maxAttachments", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_MAX_POST));
    this.context.put("isNewPost", true);
    this.context.put("topic", topic);
    this.context.put("quote", "true");
    this.context.put("quoteUser", u.getUsername());
    this.context.put("setType", false);
    this.context.put("htmlAllowed", SecurityRepository.canAccess(SecurityConstants.PERM_HTML_DISABLED, Integer.toString(topic.getForumId())));
    this.context.put("start", this.request.getParameter("start"));
    this.context.put("user", DataAccessDriver.getInstance().newUserDAO().selectById(userId));
    this.context.put("pageTitle", I18n.getMessage("PostForm.reply") + " " + topic.getTitle());
    this.context.put("smilies", SmiliesRepository.getSmilies());
    boolean needCaptcha = SystemGlobals.getBoolValue(ConfigKeys.CAPTCHA_POSTS);
    if (needCaptcha) {
        SessionFacade.getUserSession().createNewCaptcha();
    }
    this.context.put("needCaptcha", needCaptcha);
}
Also used : User(net.jforum.entities.User) PostDAO(net.jforum.dao.PostDAO) UserDAO(net.jforum.dao.UserDAO) Post(net.jforum.entities.Post) Topic(net.jforum.entities.Topic) QuotaLimit(net.jforum.entities.QuotaLimit) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Example 44 with Post

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

the class PrivateMessageAction method sendSave.

public void sendSave() {
    if (!SessionFacade.isLogged()) {
        this.setTemplateName(ViewCommon.contextToLogin());
        return;
    }
    UserDAO userDao = DataAccessDriver.getInstance().newUserDAO();
    String toUserIdStr = this.request.getParameter("toUserId");
    String toUsername = this.request.getParameter("toUsername");
    int toUserId = -1;
    // inserted the username by hand in the form's field
    if (toUserIdStr == null || "".equals(toUserIdStr.trim())) {
        List l = userDao.findByName(toUsername, true);
        if (l.size() > 0) {
            User u = (User) l.get(0);
            toUserId = u.getId();
        }
    } else {
        toUserId = Integer.parseInt(toUserIdStr);
    }
    // We failed to get the user id?
    if (toUserId == -1) {
        this.setTemplateName(TemplateKeys.PM_SENDSAVE_USER_NOTFOUND);
        this.context.put("message", I18n.getMessage("PrivateMessage.userIdNotFound"));
        return;
    }
    PrivateMessage pm = new PrivateMessage();
    pm.setPost(PostCommon.fillPostFromRequest());
    // Sender
    User fromUser = new User();
    fromUser.setId(SessionFacade.getUserSession().getUserId());
    pm.setFromUser(fromUser);
    // Recipient
    User toUser = userDao.selectById(toUserId);
    pm.setToUser(toUser);
    boolean preview = ("1".equals(this.request.getParameter("preview")));
    if (!preview) {
        DataAccessDriver.getInstance().newPrivateMessageDAO().send(pm);
        this.setTemplateName(TemplateKeys.PM_SENDSAVE);
        this.context.put("message", I18n.getMessage("PrivateMessage.messageSent", new String[] { this.request.getContextPath() + "/pm/inbox" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) }));
        // If the target user if in the forum, then increments its 
        // private messate count
        String sid = SessionFacade.isUserInSession(toUserId);
        if (sid != null) {
            UserSession us = SessionFacade.getUserSession(sid);
            us.setPrivateMessages(us.getPrivateMessages() + 1);
        }
        if (toUser.getEmail() != null && toUser.getEmail().trim().length() > 0 && SystemGlobals.getBoolValue(ConfigKeys.MAIL_NOTIFY_ANSWERS)) {
            Executor.execute(new EmailSenderTask(new PrivateMessageSpammer(toUser)));
        }
    } else {
        this.context.put("preview", true);
        this.context.put("post", pm.getPost());
        Post postPreview = new Post(pm.getPost());
        this.context.put("postPreview", PostCommon.preparePostForDisplay(postPreview));
        this.context.put("pm", pm);
        this.send();
    }
}
Also used : EmailSenderTask(net.jforum.util.mail.EmailSenderTask) User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) Post(net.jforum.entities.Post) UserSession(net.jforum.entities.UserSession) List(java.util.List) PrivateMessageSpammer(net.jforum.util.mail.PrivateMessageSpammer) PrivateMessage(net.jforum.entities.PrivateMessage)

Example 45 with Post

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

the class LuceneReindexer method reindex.

private void reindex() {
    try {
        if (recreate) {
            this.settings.createIndexDirectory(SystemGlobals.getValue(ConfigKeys.LUCENE_INDEX_WRITE_PATH));
        }
    } catch (IOException e) {
        throw new ForumException(e);
    }
    LuceneDAO dao = DataAccessDriver.getInstance().newLuceneDAO();
    IndexSearcher searcher = null;
    LuceneSearch luceneSearch = ((LuceneManager) SearchFacade.manager()).luceneSearch();
    LuceneIndexer luceneIndexer = ((LuceneManager) SearchFacade.manager()).luceneIndexer();
    int fetchCount = SystemGlobals.getIntValue(ConfigKeys.LUCENE_INDEXER_DB_FETCH_COUNT);
    try {
        if (!recreate) {
            searcher = new IndexSearcher(this.settings.directory());
        }
        boolean hasMorePosts = true;
        long processStart = System.currentTimeMillis();
        int firstPostId = args.filterByMessage() ? args.getFirstPostId() : dao.firstPostIdByDate(args.getFromDate());
        if (args.filterByMessage()) {
            int dbFirstPostId = dao.firstPostId();
            if (firstPostId < dbFirstPostId) {
                firstPostId = dbFirstPostId;
            }
        }
        int lastPostId = args.filterByMessage() ? args.getLastPostId() : dao.lastPostIdByDate(args.getToDate());
        int counter = 1;
        int indexTotal = 0;
        long indexRangeStart = System.currentTimeMillis();
        while (hasMorePosts) {
            boolean contextFinished = false;
            int toPostId = firstPostId + fetchCount < lastPostId ? firstPostId + fetchCount : lastPostId;
            try {
                JForumExecutionContext ex = JForumExecutionContext.get();
                JForumExecutionContext.set(ex);
                List l = dao.getPostsToIndex(firstPostId, toPostId);
                if (counter >= 5000) {
                    long end = System.currentTimeMillis();
                    System.out.println("Indexed ~5000 documents in " + (end - indexRangeStart) + " ms (" + indexTotal + " so far)");
                    indexRangeStart = end;
                    counter = 0;
                }
                JForumExecutionContext.finish();
                contextFinished = true;
                for (Iterator iter = l.iterator(); iter.hasNext(); ) {
                    if ("0".equals(SystemGlobals.getValue(ConfigKeys.LUCENE_CURRENTLY_INDEXING))) {
                        hasMorePosts = false;
                        break;
                    }
                    Post post = (Post) iter.next();
                    if (!recreate && args.avoidDuplicatedRecords()) {
                        if (luceneSearch.findDocumentByPostId(post.getId()) != null) {
                            continue;
                        }
                    }
                    luceneIndexer.batchCreate(post);
                    counter++;
                    indexTotal++;
                }
                firstPostId += fetchCount;
                hasMorePosts = hasMorePosts && l.size() > 0;
            } finally {
                if (!contextFinished) {
                    JForumExecutionContext.finish();
                }
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("**** Total: " + (end - processStart) + " ms");
    } catch (IOException e) {
        throw new ForumException(e);
    } finally {
        SystemGlobals.setValue(ConfigKeys.LUCENE_CURRENTLY_INDEXING, "0");
        luceneIndexer.flushRAMDirectory();
        if (searcher != null) {
            try {
                searcher.close();
            } catch (Exception e) {
            }
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) JForumExecutionContext(net.jforum.JForumExecutionContext) Post(net.jforum.entities.Post) LuceneDAO(net.jforum.dao.LuceneDAO) IOException(java.io.IOException) IOException(java.io.IOException) ForumException(net.jforum.exceptions.ForumException) ForumException(net.jforum.exceptions.ForumException) Iterator(java.util.Iterator) List(java.util.List)

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