Search in sources :

Example 11 with TopicDAO

use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.

the class RSSAction method topicPosts.

/**
	 * RSS for all N first posts for some given topic
	 */
public void topicPosts() {
    int topicId = this.request.getIntParameter("topic_id");
    PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
    TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
    Topic topic = tm.selectById(topicId);
    if (!TopicsCommon.isTopicAccessible(topic.getForumId()) || topic.getId() == 0) {
        JForumExecutionContext.requestBasicAuthentication();
        return;
    }
    tm.incrementTotalViews(topic.getId());
    List posts = pm.selectAllByTopic(topicId);
    String[] p = { topic.getTitle() };
    String title = I18n.getMessage("RSS.TopicPosts.title", p);
    String description = I18n.getMessage("RSS.TopicPosts.description", p);
    RSSAware rss = new TopicPostsRSS(title, description, topic.getForumId(), posts);
    this.context.put("rssContents", rss.createRSS());
}
Also used : PostDAO(net.jforum.dao.PostDAO) TopicDAO(net.jforum.dao.TopicDAO) List(java.util.List) Topic(net.jforum.entities.Topic) TopicPostsRSS(net.jforum.util.rss.TopicPostsRSS) RSSAware(net.jforum.util.rss.RSSAware)

Example 12 with TopicDAO

use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.

the class InstallAction method storeSupportProjectMessage.

private void storeSupportProjectMessage(Connection connection) {
    StringBuffer message = new StringBuffer("[color=#3AA315][size=18][b]Support JForum - Help the project[/b][/size][/color]").append("<hr>").append("This project is Open Source, and maintained by at least one full time Senior Developer, [i]which costs US$ 3,000.00 / month[/i]. ").append("If it helped you, please consider helping this project - especially with some [b][url=http://www.jforum.net/contribute.jsp]donation[/url][/b].").append('\n').append('\n').append("[color=#137C9F][size=14][b]Why supporting this project is a good thing[/b][/size][/color]").append("<hr>").append("The JForum Project started four years ago as a completely free and Open Source program, initially entirely developed on my (Rafael Steil) ").append("free time. Today, with the help of some very valuable people, I can spend more time on JForum, to improve it and implement new features ").append("(lots of things, requested either on the [url=http://www.jforum.net/forums/list.page]forums[/url] or registered in the ").append("[url=http://www.jforum.net/jira]bug tracker[/url]).").append('\n').append("That's why I'm asking you to financially support this work. I love Open Source. I love to use good products without having to pay for it too. ").append("But when I see some program that is valuable to my work, that helps me making money, I think it's a good idea to support this project.").append('\n').append('\n').append("[b]Some reasons to support open projects[/b]:").append("<ul><li>Because Open Source is cool? Yes").append("<li>To thank for a great tool? Yes").append("<li>To help the project evolve because this will help my work and my earnings? Yes</ul>").append("Also, as the project grows more and more, it would be great to, sometimes, reward some of the great people who help JForum.").append('\n').append('\n').append("So, that's what I'm asking you: if JForum helps your work, saves your time (time is money, remember?) and increase your earnings, support ").append("this project. The simpler way is to make [url=http://www.jforum.net/contribute.jsp]any donation[/url] via PayPal.").append('\n').append('\n').append("JForum has grown a lot every day, since four years ago, which is a great thing, and initially it wasn't my intention to fully work on this tool. ").append("Lately, I'm spending a lot of time on it, specially to make JForum 3 a reality, to help users, to improve the program, to research about ").append("better solutions. So, your support is very welcome!").append('\n').append('\n').append("Thanks!").append('\n').append('\n').append(":arrow: [size=16][b][url=http://www.jforum.net/contribute.jsp]Click here[/url][/b] to go to the [i][b][url=http://www.jforum.net/contribute.jsp]").append("\"Support JForum\"[/url][/b][/i] page.[/size]").append('\n').append('\n');
    try {
        ConfigLoader.createLoginAuthenticator();
        ConfigLoader.loadDaoImplementation();
        SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_GENERIC));
        SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_DRIVER));
        SystemGlobals.setValue(ConfigKeys.SEARCH_INDEXING_ENABLED, "false");
        JForumExecutionContext ex = JForumExecutionContext.get();
        ex.setConnection(connection);
        JForumExecutionContext.set(ex);
        User user = new User(2);
        // Create topic
        Topic topic = new Topic();
        topic.setPostedBy(user);
        topic.setTitle("Support JForum - Please read");
        topic.setTime(new Date());
        topic.setType(Topic.TYPE_ANNOUNCE);
        topic.setForumId(1);
        TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
        topicDao.addNew(topic);
        // Create post
        Post post = new Post();
        post.setSubject(topic.getTitle());
        post.setTime(topic.getTime());
        post.setUserId(user.getId());
        post.setText(message.toString());
        post.setForumId(topic.getForumId());
        post.setSmiliesEnabled(true);
        post.setHtmlEnabled(true);
        post.setBbCodeEnabled(true);
        post.setUserIp("127.0.0.1");
        post.setTopicId(topic.getId());
        PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
        postDao.addNew(post);
        // Update topic
        topic.setFirstPostId(post.getId());
        topic.setLastPostId(post.getId());
        topicDao.update(topic);
        // Update forum stats
        ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
        forumDao.incrementTotalTopics(1, 1);
        forumDao.setLastPost(1, post.getId());
    } finally {
        SystemGlobals.setValue(ConfigKeys.SEARCH_INDEXING_ENABLED, "true");
        JForumExecutionContext ex = JForumExecutionContext.get();
        ex.setConnection(null);
        JForumExecutionContext.set(ex);
    }
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) User(net.jforum.entities.User) PostDAO(net.jforum.dao.PostDAO) JForumExecutionContext(net.jforum.JForumExecutionContext) Post(net.jforum.entities.Post) TopicDAO(net.jforum.dao.TopicDAO) Topic(net.jforum.entities.Topic) Date(java.util.Date)

Example 13 with TopicDAO

use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.

the class ForumAction method delete.

// Delete
public void delete() {
    String[] ids = this.request.getParameterValues("forum_id");
    ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
    TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
    if (ids != null) {
        for (int i = 0; i < ids.length; i++) {
            int forumId = Integer.parseInt(ids[i]);
            topicDao.deleteByForum(forumId);
            forumDao.delete(forumId);
            Forum f = new Forum(ForumRepository.getForum(forumId));
            ForumRepository.removeForum(f);
        }
        SecurityRepository.clean();
        RolesRepository.clear();
    }
    this.list();
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) TopicDAO(net.jforum.dao.TopicDAO) Forum(net.jforum.entities.Forum)

Example 14 with TopicDAO

use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.

the class TopicsCommon method deleteTopic.

/**
	 * Deletes a topic.
	 * This method will remove the topic from the database,
	 * clear the entry frm the cache and update the last 
	 * post info for the associated forum.
	 * @param topicId The topic id to remove
	 * @param fromModeration boolean 
     * @param forumId int
	 */
public static synchronized void deleteTopic(int topicId, int forumId, boolean fromModeration) {
    TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
    Topic topic = new Topic();
    topic.setId(topicId);
    topic.setForumId(forumId);
    topicDao.delete(topic, fromModeration);
    if (!fromModeration) {
        // Updates the Recent Topics if it contains this topic
        TopicRepository.loadMostRecentTopics();
        // Updates the Hottest Topics if it contains this topic
        TopicRepository.loadHottestTopics();
        TopicRepository.clearCache(forumId);
        topicDao.removeSubscriptionByTopic(topicId);
    }
}
Also used : TopicDAO(net.jforum.dao.TopicDAO) Topic(net.jforum.entities.Topic)

Example 15 with TopicDAO

use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.

the class TopicsCommon method topicsByForum.

/**
	 * List all first 'n' topics of a given forum.
	 * This method returns no more than <code>ConfigKeys.TOPICS_PER_PAGE</code>
	 * topics for the forum. 
	 * 
	 * @param forumId The forum id to which the topics belongs to
	 * @param start The start fetching index
	 * @return <code>java.util.List</code> containing the topics found.
	 */
public static List topicsByForum(int forumId, int start) {
    TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
    int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
    List topics;
    // Try to get the first's page of topics from the cache
    if (start == 0 && SystemGlobals.getBoolValue(ConfigKeys.TOPIC_CACHE_ENABLED)) {
        topics = TopicRepository.getTopics(forumId);
        if (topics.size() == 0 || !TopicRepository.isLoaded(forumId)) {
            synchronized (MUTEXT) {
                if (topics.size() == 0 || !TopicRepository.isLoaded(forumId)) {
                    topics = tm.selectAllByForumByLimit(forumId, start, topicsPerPage);
                    TopicRepository.addAll(forumId, topics);
                }
            }
        }
    } else {
        topics = tm.selectAllByForumByLimit(forumId, start, topicsPerPage);
    }
    return topics;
}
Also used : TopicDAO(net.jforum.dao.TopicDAO) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

TopicDAO (net.jforum.dao.TopicDAO)21 Topic (net.jforum.entities.Topic)14 List (java.util.List)10 PostDAO (net.jforum.dao.PostDAO)10 Post (net.jforum.entities.Post)7 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)6 ArrayList (java.util.ArrayList)5 ForumDAO (net.jforum.dao.ForumDAO)5 Forum (net.jforum.entities.Forum)5 Iterator (java.util.Iterator)4 ModerationLog (net.jforum.entities.ModerationLog)4 User (net.jforum.entities.User)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 PollDAO (net.jforum.dao.PollDAO)3 Poll (net.jforum.entities.Poll)3 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2