diff options
author | 2012-03-06 01:12:39 +0700 | |
---|---|---|
committer | 2012-03-06 01:12:39 +0700 | |
commit | b4a7601a14c9077fcfefc083ed39348409d57b76 (patch) | |
tree | 956047a7b6d7be1069814db848278b1ddc0c9dfd /src/java/com/juick/http/www/User.java | |
parent | faf709b4141f52cdd04a02edad31bf62a32af824 (diff) |
User tags, friends, readers
Diffstat (limited to 'src/java/com/juick/http/www/User.java')
-rw-r--r-- | src/java/com/juick/http/www/User.java | 177 |
1 files changed, 157 insertions, 20 deletions
diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java index 940cbfc4..73dd5827 100644 --- a/src/java/com/juick/http/www/User.java +++ b/src/java/com/juick/http/www/User.java @@ -103,11 +103,9 @@ public class User { out.println("<div id=\"wrapper\">"); out.println("<div id=\"content\">"); out.println("<ul>"); - if (mids.size() > 0) { PageTemplates.printMessages(out, sql, mids, locale); } - out.println("</ul>"); if (mids.size() == 20) { @@ -120,21 +118,41 @@ public class User { } out.println("<p class=\"page\"><a href=\"" + nextpage + "\">Older →</a></p>"); } + out.println("</div>"); + pageUserColumn(out, sql, user, visitor, locale); out.println("</div>"); - out.println("<div id=\"column\">"); - out.println("<h2>" + rb.getString("(Menu) Messages") + "</h2>"); - out.println("<ul>"); - out.println(" <li><a href=\"?\">" + rb.getString("(Menu) Blog") + "</a></li>"); - out.println(" <li><a href=\"?show=recomm\">" + rb.getString("(Menu) Recommendations") + "</a></li>"); - out.println(" <li><a href=\"?show=photos\">" + rb.getString("(Menu) Photos") + "</a></li>"); - out.println("</ul>"); - out.println("<h2>" + rb.getString("(Menu) Tags") + "</h2>"); - pageUserTags(out, sql, user, visitor, 15); - out.println("<h2>" + rb.getString("(Menu) Search") + "</h2>"); - out.println("<form action=\"./\" id=\"search\"><p><input type=\"text\" name=\"search\" class=\"inp\"/></p></form>"); + PageTemplates.pageFooter(request, out, locale, visitor); + } finally { + out.close(); + } + } + + protected void doGetInfo(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { + } + + protected void doGetTags(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { + com.juick.User visitor = Utils.getVisitorUser(sql, request); + Locale locale = request.getLocale(); + ResourceBundle rb = ResourceBundle.getBundle("User", locale); + + response.setContentType("text/html; charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Menu) Tags"), null); + PageTemplates.pageNavigation(out, locale, visitor); + PageTemplates.pageUserTitle(out, sql, locale, user, visitor); + + out.println("<div id=\"wrapper\">"); + out.println("<div id=\"content\">"); + + out.print("<p>"); + pageUserTags(out, sql, user, visitor, 0); + out.print("</p>"); + out.println("</div>"); + pageUserColumn(out, sql, user, visitor, locale); out.println("</div>"); PageTemplates.pageFooter(request, out, locale, visitor); @@ -143,20 +161,137 @@ public class User { } } - protected void doGetInfo(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { + protected void doGetFriends(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { + com.juick.User visitor = Utils.getVisitorUser(sql, request); + Locale locale = request.getLocale(); + ResourceBundle rb = ResourceBundle.getBundle("User", locale); + + response.setContentType("text/html; charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Stats) I read"), null); + PageTemplates.pageNavigation(out, locale, visitor); + PageTemplates.pageUserTitle(out, sql, locale, user, visitor); + + out.println("<div id=\"wrapper\">"); + out.println("<div id=\"content\">"); + out.println("<table class=\"users\"><tr>"); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT users.id,users.nick FROM subscr_users INNER JOIN users ON subscr_users.user_id=users.id WHERE subscr_users.suser_id=? ORDER BY users.nick"); + stmt.setInt(1, user.UID); + rs = stmt.executeQuery(); + rs.beforeFirst(); + int cnt = 0; + while (rs.next()) { + if (cnt % 3 == 0 && cnt > 0) { + out.print("</tr><tr>"); + } + out.print("<td><a href=\"/" + rs.getString(2) + "/\"><img src=\"http://i.juick.com/as/" + rs.getInt(1) + ".png\"/>" + rs.getString(2) + "</a></td>"); + cnt++; + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + out.println("</tr></table>"); + out.println("</div>"); + pageUserColumn(out, sql, user, visitor, locale); + out.println("</div>"); + + PageTemplates.pageFooter(request, out, locale, visitor); + } finally { + out.close(); + } + } + + protected void doGetReaders(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { + com.juick.User visitor = Utils.getVisitorUser(sql, request); + Locale locale = request.getLocale(); + ResourceBundle rb = ResourceBundle.getBundle("User", locale); + + response.setContentType("text/html; charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Stats) I read"), null); + PageTemplates.pageNavigation(out, locale, visitor); + PageTemplates.pageUserTitle(out, sql, locale, user, visitor); + + out.println("<div id=\"wrapper\">"); + out.println("<div id=\"content\">"); + out.println("<table class=\"users\"><tr>"); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT users.id,users.nick FROM subscr_users INNER JOIN users ON subscr_users.suser_id=users.id WHERE subscr_users.user_id=? ORDER BY users.nick"); + stmt.setInt(1, user.UID); + rs = stmt.executeQuery(); + rs.beforeFirst(); + int cnt = 0; + while (rs.next()) { + if (cnt % 3 == 0 && cnt > 0) { + out.print("</tr><tr>"); + } + out.print("<td><a href=\"/" + rs.getString(2) + "/\"><img src=\"http://i.juick.com/as/" + rs.getInt(1) + ".png\"/>" + rs.getString(2) + "</a></td>"); + cnt++; + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + out.println("</tr></table>"); + out.println("</div>"); + pageUserColumn(out, sql, user, visitor, locale); + out.println("</div>"); + + PageTemplates.pageFooter(request, out, locale, visitor); + } finally { + out.close(); + } + } + + public static void pageUserColumn(PrintWriter out, Connection sql, com.juick.User user, com.juick.User visitor, Locale locale) { + ResourceBundle rb = ResourceBundle.getBundle("User", locale); + + out.println("<div id=\"column\">"); + out.println("<h2>" + rb.getString("(Menu) Messages") + "</h2>"); + out.println("<ul>"); + out.println(" <li><a href=\"?\">" + rb.getString("(Menu) Blog") + "</a></li>"); + out.println(" <li><a href=\"?show=recomm\">" + rb.getString("(Menu) Recommendations") + "</a></li>"); + out.println(" <li><a href=\"?show=photos\">" + rb.getString("(Menu) Photos") + "</a></li>"); + out.println("</ul>"); + out.println("<h2>" + rb.getString("(Menu) Tags") + " <a href=\"./tags\">" + rb.getString("all") + "</a></h2>"); + pageUserTags(out, sql, user, visitor, 15); + out.println("<h2>" + rb.getString("(Menu) Search") + "</h2>"); + out.println("<form action=\"./\" id=\"search\"><p><input type=\"text\" name=\"search\" class=\"inp\"/></p></form>"); + out.println("</div>"); } public static void pageUserTags(PrintWriter out, Connection sql, com.juick.User user, com.juick.User visitor, int cnt) { - com.juick.Tag tags[] = new com.juick.Tag[cnt]; + com.juick.Tag tags[] = null; int maxUsageCnt = 0; PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT tags.name AS name,COUNT(DISTINCT messages_tags.message_id) AS cnt FROM (messages INNER JOIN messages_tags ON (messages.message_id=messages_tags.message_id)) INNER JOIN tags ON messages_tags.tag_id=tags.tag_id WHERE messages.user_id=? GROUP BY messages_tags.tag_id ORDER BY cnt DESC LIMIT ?"); - stmt.setInt(1, user.UID); - stmt.setInt(2, cnt); + if (cnt > 0) { + stmt = sql.prepareStatement("SELECT tags.name AS name,COUNT(DISTINCT messages_tags.message_id) AS cnt FROM (messages INNER JOIN messages_tags ON (messages.message_id=messages_tags.message_id)) INNER JOIN tags ON messages_tags.tag_id=tags.tag_id WHERE messages.user_id=? GROUP BY messages_tags.tag_id ORDER BY cnt DESC LIMIT ?", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + stmt.setInt(1, user.UID); + stmt.setInt(2, cnt); + } else { + stmt = sql.prepareStatement("SELECT tags.name AS name,COUNT(DISTINCT messages_tags.message_id) AS cnt FROM (messages INNER JOIN messages_tags ON (messages.message_id=messages_tags.message_id)) INNER JOIN tags ON messages_tags.tag_id=tags.tag_id WHERE messages.user_id=? GROUP BY messages_tags.tag_id ORDER BY cnt DESC", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + stmt.setInt(1, user.UID); + } rs = stmt.executeQuery(); + rs.last(); + tags = new com.juick.Tag[rs.getRow()]; rs.beforeFirst(); cnt = 0; while (rs.next()) { @@ -174,12 +309,14 @@ public class User { Utils.finishSQL(rs, stmt); } - Arrays.sort(tags, 0, cnt); + if (tags != null && cnt > 0) { + Arrays.sort(tags, 0, cnt); + } for (int i = 0; i < cnt; i++) { String tag = Utils.encodeHTML(tags[i].Name); try { - tag = "<a href=\"?tag=" + URLEncoder.encode(tags[i].Name, "UTF-8") + "\" title=\"" + tags[i].UsageCnt + "\">" + tag + "</a>"; + tag = "<a href=\"./?tag=" + URLEncoder.encode(tags[i].Name, "UTF-8") + "\" title=\"" + tags[i].UsageCnt + "\">" + tag + "</a>"; } catch (UnsupportedEncodingException e) { } |