diff options
Diffstat (limited to 'src/java/com')
-rw-r--r-- | src/java/com/juick/http/www/Main.java | 6 | ||||
-rw-r--r-- | src/java/com/juick/http/www/NewMessage.java | 9 | ||||
-rw-r--r-- | src/java/com/juick/http/www/PageTemplates.java | 8 | ||||
-rw-r--r-- | src/java/com/juick/http/www/User.java | 177 |
4 files changed, 173 insertions, 27 deletions
diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java index 910a554f..256e70f9 100644 --- a/src/java/com/juick/http/www/Main.java +++ b/src/java/com/juick/http/www/Main.java @@ -159,6 +159,12 @@ public class Main extends HttpServlet implements XmppListener { pagesUser.doGetBlog(sql, sqlSearch, request, response, user); } else if (uriparts[2].equals("info")) { pagesUser.doGetInfo(sql, request, response, user); + } else if (uriparts[2].equals("tags")) { + pagesUser.doGetTags(sql, request, response, user); + } else if (uriparts[2].equals("friends")) { + pagesUser.doGetFriends(sql, request, response, user); + } else if (uriparts[2].equals("readers")) { + pagesUser.doGetReaders(sql, request, response, user); } else { int mid = 0; try { diff --git a/src/java/com/juick/http/www/NewMessage.java b/src/java/com/juick/http/www/NewMessage.java index d35af8f3..1efb753d 100644 --- a/src/java/com/juick/http/www/NewMessage.java +++ b/src/java/com/juick/http/www/NewMessage.java @@ -59,10 +59,13 @@ public class NewMessage { out.println("<div id=\"webcamwrap\" style=\"width: 320px; margin: 0 auto\"><div id=\"webcam\"></div></div>"); String body = request.getParameter("body"); - if (body != null && body.length() < 4096) { - body = Utils.encodeHTML(body); - } else { + if (body == null) { body = ""; + } else { + if (body.length() > 4096) { + body = body.substring(0, 4096); + } + body = Utils.encodeHTML(body); } out.println("<p><textarea name=\"body\" class=\"newmessage\" rows=\"7\" cols=\"10\">" + body + "</textarea><br/>"); diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index 90246e76..a07d5ed8 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -183,8 +183,8 @@ public class PageTemplates { out.println("<div id=\"title\"><div id=\"title-container\">"); out.println(" <div id=\"title-av\"><a href=\"/" + user.UName + "/\"><img src=\"http://i.juick.com/a/" + user.UID + ".png\" width=\"96\" height=\"96\" alt=\"" + user.UName + "\"/></a></div>"); out.println(" <div id=\"title-stats\"><ul>"); - out.println(" <li>" + rb.getString("(Stats) I read") + ": " + iread + "</li>"); - out.println(" <li>" + rb.getString("(Stats) My readers") + ": " + myreaders + "</li>"); + out.println(" <li><a href=\"/" + user.UName + "/friends\">" + rb.getString("(Stats) I read") + ": " + iread + "</a></li>"); + out.println(" <li><a href=\"/" + user.UName + "/readers\">" + rb.getString("(Stats) My readers") + ": " + myreaders + "</a></li>"); out.println(" <li>" + rb.getString("(Stats) Messages") + ": " + messages + "</li>"); out.println(" <li>" + rb.getString("(Stats) Replies") + ": " + replies + "</li>"); out.println(" </ul></div>"); @@ -295,14 +295,14 @@ public class PageTemplates { Matcher m = regexLinks2.matcher(msg); StringBuffer sb = new StringBuffer(); while (m.find()) { - String url = m.group(3).replace(" ", "%20").replaceAll("\\s", ""); + String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", ""); m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">$4</a>$5"); } m.appendTail(sb); msg = sb.toString(); // > citate - msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))>\\s*(.*)(\\n|(?=\\Z))", "<blockquote>$1</blockquote>"); + msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "<blockquote>$1</blockquote>"); msg = msg.replaceAll("</blockquote><blockquote>", "\n"); msg = msg.replaceAll("\n", "<br/>\n"); 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) { } |