From b4a7601a14c9077fcfefc083ed39348409d57b76 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Tue, 6 Mar 2012 01:12:39 +0700 Subject: User tags, friends, readers --- src/java/User.properties | 1 + src/java/User_ru.properties | 1 + src/java/com/juick/http/www/Main.java | 6 + src/java/com/juick/http/www/NewMessage.java | 9 +- src/java/com/juick/http/www/PageTemplates.java | 8 +- src/java/com/juick/http/www/User.java | 177 ++++++++++++++++++++++--- web/style3.css | 7 +- 7 files changed, 181 insertions(+), 28 deletions(-) diff --git a/src/java/User.properties b/src/java/User.properties index aa2e0bcb..b91d4352 100644 --- a/src/java/User.properties +++ b/src/java/User.properties @@ -14,3 +14,4 @@ Expand\ all=Expand all View\ as\ list=View as list View\ as\ tree=View as tree +all=all diff --git a/src/java/User_ru.properties b/src/java/User_ru.properties index a5c6f3ef..3bf82875 100644 --- a/src/java/User_ru.properties +++ b/src/java/User_ru.properties @@ -14,3 +14,4 @@ Expand\ all=\u0420\u0430\u0441\u043a\u0440\u044b\u0442\u044c \u0432\u0441\u0435 View\ as\ list=\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043a\u043e\u043c View\ as\ tree=\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0435\u0440\u0435\u0432\u043e\u043c +all=\u0432\u0441\u0435 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("
"); 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("


"); 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("

"); out.println("
\""
"); out.println("
"); @@ -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$4$5"); } m.appendTail(sb); msg = sb.toString(); // > citate - msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))>\\s*(.*)(\\n|(?=\\Z))", "
$1
"); + msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "
$1
"); msg = msg.replaceAll("
", "\n"); msg = msg.replaceAll("\n", "
\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("
"); out.println("
"); out.println("
    "); - if (mids.size() > 0) { PageTemplates.printMessages(out, sql, mids, locale); } - out.println("
"); if (mids.size() == 20) { @@ -120,21 +118,41 @@ public class User { } out.println("

Older →

"); } + out.println("
"); + pageUserColumn(out, sql, user, visitor, locale); out.println("
"); - out.println("
"); - out.println("

" + rb.getString("(Menu) Messages") + "

"); - out.println(""); - out.println("

" + rb.getString("(Menu) Tags") + "

"); - pageUserTags(out, sql, user, visitor, 15); - out.println("

" + rb.getString("(Menu) Search") + "

"); - out.println("

"); + 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("
"); + out.println("
"); + + out.print("

"); + pageUserTags(out, sql, user, visitor, 0); + out.print("

"); + out.println("
"); + pageUserColumn(out, sql, user, visitor, locale); out.println("
"); 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("
"); + out.println("
"); + out.println(""); + + 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(""); + } + out.print(""); + cnt++; + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + out.println("
" + rs.getString(2) + "
"); + out.println("
"); + pageUserColumn(out, sql, user, visitor, locale); + out.println("
"); + + 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("
"); + out.println("
"); + out.println(""); + + 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(""); + } + out.print(""); + cnt++; + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + out.println("
" + rs.getString(2) + "
"); + out.println("
"); + pageUserColumn(out, sql, user, visitor, locale); + out.println("
"); + + 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("
"); + out.println("

" + rb.getString("(Menu) Messages") + "

"); + out.println(""); + out.println("

" + rb.getString("(Menu) Tags") + " " + rb.getString("all") + "

"); + pageUserTags(out, sql, user, visitor, 15); + out.println("

" + rb.getString("(Menu) Search") + "

"); + out.println("

"); + out.println("
"); } 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 = "" + tag + ""; + tag = "" + tag + ""; } catch (UnsupportedEncodingException e) { } diff --git a/web/style3.css b/web/style3.css index 0678dc02..fac16fdc 100644 --- a/web/style3.css +++ b/web/style3.css @@ -66,6 +66,10 @@ img { border: none; } #content textarea.newmessage { border: 1px solid; width: 640px; padding: 2px; resize: vertical; } +table.users { width: 100%; margin: 10px 0; } +table.users td { width: 33%; padding: 6px 0; overflow: hidden; } +table.users img { width: 32px; height: 32px; vertical-align: middle; margin-right: 6px; } + #chats li { margin: 16px; } .title2 { padding: 10px 20px; margin: 20px 0 10px 0; } @@ -85,7 +89,8 @@ img { border: none; } #column li { margin: 0; padding: 2px 0 2px 10px; } #column p { font-size: 14px; margin: 0 0 0 10px; } #column .inp { width: 195px; } -#column h2 { border-bottom: 1px solid; font-size: 18px; margin: 24px 0 8px 0; padding: 0 0 2px 2px; } +#column h2 { border-bottom: 1px solid; font-size: 18px; margin: 24px 0 8px 0; padding: 0 2px 2px 2px; } +#column h2>a { float: right; } /********/ -- cgit v1.2.3