import com.ecyrd.jspwiki.*; import com.ecyrd.jspwiki.plugin.*; import java.util.*; import java.sql.*; public class Forum implements WikiPlugin { public String execute (WikiContext Context, Map ParameterMap) throws PluginException { WikiEngine engine = Context.getEngine(); String return_html = ""; String title; String page = Context.getPage().getName(); if (ParameterMap != null || ParameterMap.size() > 0) { Iterator parmIter = ParameterMap.keySet().iterator(); if( ((String)parmIter.next()).equalsIgnoreCase("title")){ title = handleApostrophe((String)ParameterMap.get("title")); }else{ return errorMsg(); }; }else{ return errorMsg(); }; return_html += getHTML(Context, engine, title); return return_html; }; private String getHTML(WikiContext Context, WikiEngine engine, String title){ String html = ""; Connection conn = null; try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/forum", "root", ""); html += "
\n"; html += "\n"; html += "\n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += "
 \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += "
" + title + "
\n"; html += "
\n"; html += "
\n"; html += "
\n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; Statement stmt_topic = conn.createStatement(); ResultSet rs_topic = stmt_topic.executeQuery("SELECT topic.index, topic.title, topic.starter FROM topic WHERE topic.forum_title = '" + title + "'"); while(rs_topic.next()){ String topic_index = rs_topic.getString("topic.index"); String topic_title = rs_topic.getString("topic.title"); String topic_starter = rs_topic.getString("topic.starter"); Statement stmt_post = conn.createStatement(); ResultSet rs_post = stmt_post.executeQuery("SELECT COUNT(*), DATE_FORMAT(MAX(timestamp), '%m/%d/%y') AS timestamp FROM post WHERE post.topic_index = " + topic_index); rs_post.next(); String replies = rs_post.getString("COUNT(*)"); String last_action = rs_post.getString("timestamp"); if(last_action == null) last_action = ""; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; html += " \n"; }; html += "
\n"; html += "
\n"; html += "
Topic TitleTopic Starter

Replies

Views

Last Action
\n"; html += " \n"; html += " \n"; html += " " + topic_title + "\n"; html += " \n"; html += " \n"; html += " " + topic_starter + "\n"; html += " \n"; html += " " + replies + "\n"; html += "
\n"; html += "   \n"; html += " Last Post: " + last_action + "\n"; html += "
\n"; html += "
\n"; html += "
\n"; }catch (Exception e){ html += "Error: " + e; return html; }; return html; }; private String errorMsg(){ return "

Useage: [{Discuss title=<your_title>}]

"; }; private String handleApostrophe(String commentString) { for(int i_marker = 0; i_marker < commentString.length(); i_marker++){ if(commentString.substring(i_marker, i_marker + 1).equals("'")){ commentString = commentString.substring(0, i_marker) + "''" + commentString.substring(i_marker + 1, commentString.length()); i_marker++; } } if(commentString.length() > 255){ commentString = commentString.substring(0,255); } return commentString; }; };