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/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 ++++++++++++++++++++++--- 4 files changed, 173 insertions(+), 27 deletions(-) (limited to 'src/java/com/juick/http/www') 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) { } -- cgit v1.2.3