Search in sources :

Example 21 with Forum

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

the class ForumRepository method reloadForum.

/**
	 * Reloads a forum.
	 * The forum should already be in the cache and <b>SHOULD NOT</b>
	 * have its order changed. If the forum's order was changed, 
	 * then you <b>MUST CALL</b> @link Category#changeForumOrder(Forum) <b>BEFORE</b>
	 * calling this method.
	 * 
	 * @param forumId int The forum to reload its information
	 */
public static synchronized void reloadForum(int forumId) {
    Forum f = DataAccessDriver.getInstance().newForumDAO().selectById(forumId);
    if (((Map) cache.get(FQN, RELATION)).containsKey(Integer.toString(forumId))) {
        String id = Integer.toString(f.getCategoryId());
        Category c = (Category) cache.get(FQN, id);
        f.setLastPostInfo(null);
        f.setLastPostInfo(ForumRepository.getLastPostInfo(f));
        c.reloadForum(f);
        cache.add(FQN, id, c);
        Set s = (Set) cache.get(FQN, CATEGORIES_SET);
        cache.add(FQN, CATEGORIES_SET, s);
    }
    getTotalMessages(true);
}
Also used : Category(net.jforum.entities.Category) TreeSet(java.util.TreeSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map) Forum(net.jforum.entities.Forum)

Example 22 with Forum

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

the class GenericForumDAO method selectById.

/**
	 * @see net.jforum.dao.ForumDAO#selectById(int)
	 */
public Forum selectById(int forumId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.selectById"));
        p.setInt(1, forumId);
        rs = p.executeQuery();
        Forum f = new Forum();
        if (rs.next()) {
            f = this.fillForum(rs);
        }
        return f;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) Forum(net.jforum.entities.Forum)

Example 23 with Forum

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

the class HottestTopicsAction method topics.

List topics() {
    int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
    List tmpTopics = TopicRepository.getHottestTopics();
    this.forums = new ArrayList(postsPerPage);
    for (Iterator iter = tmpTopics.iterator(); iter.hasNext(); ) {
        Topic t = (Topic) iter.next();
        if (TopicsCommon.isTopicAccessible(t.getForumId())) {
            // Get name of forum that the topic refers to
            Forum f = ForumRepository.getForum(t.getForumId());
            forums.add(f);
        } else {
            iter.remove();
        }
    }
    JForumExecutionContext.getRequest().removeAttribute("template");
    return TopicsCommon.prepareTopics(tmpTopics);
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Topic(net.jforum.entities.Topic) Forum(net.jforum.entities.Forum)

Example 24 with Forum

use of net.jforum.entities.Forum 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 25 with Forum

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

the class PostAction method insert.

public void insert() {
    int forumId;
    // If we have a topic_id, then it should be a reply
    if (this.request.getParameter("topic_id") != null) {
        int topicId = this.request.getIntParameter("topic_id");
        Topic t = TopicRepository.getTopic(new Topic(topicId));
        if (t == null) {
            t = DataAccessDriver.getInstance().newTopicDAO().selectRaw(topicId);
            if (t == null) {
                throw new ForumException("Could not find a topic with id #" + topicId);
            }
        }
        forumId = t.getForumId();
        if (!TopicsCommon.isTopicAccessible(t.getForumId())) {
            return;
        }
        if (t.getStatus() == Topic.STATUS_LOCKED) {
            this.topicLocked();
            return;
        }
        this.context.put("topic", t);
        this.context.put("setType", false);
        this.context.put("pageTitle", I18n.getMessage("PostForm.reply") + " " + t.getTitle());
    } else {
        forumId = this.request.getIntParameter("forum_id");
        if (this.isReplyOnly(forumId)) {
            this.replyOnly();
            return;
        }
        this.context.put("setType", true);
        this.context.put("pageTitle", I18n.getMessage("PostForm.title"));
    }
    Forum forum = ForumRepository.getForum(forumId);
    if (forum == null) {
        throw new ForumException("Could not find a forum with id #" + forumId);
    }
    if (!TopicsCommon.isTopicAccessible(forumId)) {
        return;
    }
    if (!this.anonymousPost(forumId) || this.isForumReadonly(forumId, this.request.getParameter("topic_id") != null)) {
        return;
    }
    int userId = SessionFacade.getUserSession().getUserId();
    this.setTemplateName(TemplateKeys.POSTS_INSERT);
    // Attachments
    boolean attachmentsEnabled = SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(forumId));
    if (attachmentsEnabled && !SessionFacade.isLogged() && !SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_ANONYMOUS)) {
        attachmentsEnabled = false;
    }
    this.context.put("attachmentsEnabled", attachmentsEnabled);
    if (attachmentsEnabled) {
        QuotaLimit ql = new AttachmentCommon(this.request, forumId).getQuotaLimit(userId);
        this.context.put("maxAttachmentsSize", new Long(ql != null ? ql.getSizeInBytes() : 1));
        this.context.put("maxAttachments", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_MAX_POST));
    }
    boolean needCaptcha = SystemGlobals.getBoolValue(ConfigKeys.CAPTCHA_POSTS);
    this.context.put("moderationLoggingEnabled", SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED));
    this.context.put("smilies", SmiliesRepository.getSmilies());
    this.context.put("forum", forum);
    this.context.put("action", "insertSave");
    this.context.put("start", this.request.getParameter("start"));
    this.context.put("isNewPost", true);
    this.context.put("needCaptcha", needCaptcha);
    this.context.put("htmlAllowed", SecurityRepository.canAccess(SecurityConstants.PERM_HTML_DISABLED, Integer.toString(forumId)));
    this.context.put("canCreateStickyOrAnnouncementTopics", SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_STICKY_ANNOUNCEMENT_TOPICS));
    this.context.put("canCreatePolls", SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_POLL));
    User user = DataAccessDriver.getInstance().newUserDAO().selectById(userId);
    ViewCommon.prepareUserSignature(user);
    if (this.request.getParameter("preview") != null) {
        user.setNotifyOnMessagesEnabled(this.request.getParameter("notify") != null);
    }
    this.context.put("user", user);
}
Also used : ForumException(net.jforum.exceptions.ForumException) User(net.jforum.entities.User) Topic(net.jforum.entities.Topic) QuotaLimit(net.jforum.entities.QuotaLimit) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon) Forum(net.jforum.entities.Forum)

Aggregations

Forum (net.jforum.entities.Forum)28 List (java.util.List)14 Iterator (java.util.Iterator)13 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Topic (net.jforum.entities.Topic)8 Category (net.jforum.entities.Category)7 ForumDAO (net.jforum.dao.ForumDAO)5 TopicDAO (net.jforum.dao.TopicDAO)5 User (net.jforum.entities.User)5 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)4 PostDAO (net.jforum.dao.PostDAO)3 UserDAO (net.jforum.dao.UserDAO)3 UserSession (net.jforum.entities.UserSession)3 PermissionControl (net.jforum.security.PermissionControl)3 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Set (java.util.Set)2