diff options
Diffstat (limited to 'src/main/java/com/juick/http/www/User.java')
-rw-r--r-- | src/main/java/com/juick/http/www/User.java | 105 |
1 files changed, 47 insertions, 58 deletions
diff --git a/src/main/java/com/juick/http/www/User.java b/src/main/java/com/juick/http/www/User.java index 83601ade..84d1ad9a 100644 --- a/src/main/java/com/juick/http/www/User.java +++ b/src/main/java/com/juick/http/www/User.java @@ -30,6 +30,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -44,7 +45,7 @@ public class User { protected void doGetBlog(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - ArrayList<Integer> mids; + List<Integer> mids; String paramShow = request.getParameter("show"); @@ -58,7 +59,7 @@ public class User { Errors.doGet404(sql, request, response); return; } else if (!paramTag.Name.equals(paramTagStr)) { - String url = "/" + user.UName + "/?tag=" + URLEncoder.encode(paramTag.Name, "UTF-8"); + String url = "/" + user.getUName() + "/?tag=" + URLEncoder.encode(paramTag.Name, "UTF-8"); Utils.sendPermanentRedirect(response, url); return; } @@ -80,9 +81,9 @@ public class User { int privacy = 0; if (visitor != null) { - if (user.UID == visitor.UID || visitor.UID == 1) { + if (user.getUID() == visitor.getUID() || visitor.getUID() == 1) { privacy = -3; - } else if (UserQueries.isInWL(sql, user.UID, visitor.UID)) { + } else if (UserQueries.isInWL(sql, user.getUID(), visitor.getUID())) { privacy = -2; } } @@ -90,34 +91,33 @@ public class User { String title; if (paramShow == null) { if (paramTag != null) { - title = "Блог " + user.UName + ": *" + Utils.encodeHTML(paramTag.Name); - mids = MessagesQueries.getUserTag(sql, user.UID, paramTag.TID, privacy, paramBefore); + title = "Блог " + user.getUName() + ": *" + Utils.encodeHTML(paramTag.Name); + mids = MessagesQueries.getUserTag(sql, user.getUID(), paramTag.TID, privacy, paramBefore); } else if (paramSearch != null) { - title = "Блог " + user.UName + ": " + Utils.encodeHTML(paramSearch); - mids = MessagesQueries.getUserSearch(sql, sqlSearch, user.UID, Utils.encodeSphinx(paramSearch), privacy, paramBefore); + title = "Блог " + user.getUName() + ": " + Utils.encodeHTML(paramSearch); + mids = MessagesQueries.getUserSearch(sql, sqlSearch, user.getUID(), Utils.encodeSphinx(paramSearch), privacy, paramBefore); } else { - title = "Блог " + user.UName; - mids = MessagesQueries.getUserBlog(sql, user.UID, privacy, paramBefore); + title = "Блог " + user.getUName(); + mids = MessagesQueries.getUserBlog(sql, user.getUID(), privacy, paramBefore); } } else if (paramShow.equals("recomm")) { - title = "Рекомендации " + user.UName; - mids = MessagesQueries.getUserRecommendations(sql, user.UID, paramBefore); + title = "Рекомендации " + user.getUName(); + mids = MessagesQueries.getUserRecommendations(sql, user.getUID(), paramBefore); } else if (paramShow.equals("photos")) { - title = "Фотографии " + user.UName; - mids = MessagesQueries.getUserPhotos(sql, user.UID, privacy, paramBefore); + title = "Фотографии " + user.getUName(); + mids = MessagesQueries.getUserPhotos(sql, user.getUID(), privacy, paramBefore); } else { Errors.doGet404(sql, request, response); return; } if (visitor == null) { - pageUserRefCookie(request, response, user.UID); + pageUserRefCookie(request, response, user.getUID()); } response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { - String head = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + user.UName + "\" href=\"//rss.juick.com/" + user.UName + "/blog\"/>"; + try (PrintWriter out = response.getWriter()) { + String head = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + user.getUName() + "\" href=\"//rss.juick.com/" + user.getUName() + "/blog\"/>"; if (paramTag != null && TagQueries.getTagNoIndex(sql, paramTag.TID)) { head += "<meta name=\"robots\" content=\"noindex,nofollow\"/>"; } else if (paramBefore > 0 || paramShow != null) { @@ -155,8 +155,6 @@ public class User { PageTemplates.pageFooter(request, out, visitor, true); PageTemplates.pageEnd(out); - } finally { - out.close(); } } @@ -164,14 +162,13 @@ public class User { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); if (visitor == null) { - pageUserRefCookie(request, response, user.UID); + pageUserRefCookie(request, response, user.getUID()); } response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { + try (PrintWriter out = response.getWriter()) { String head = "<meta name=\"robots\" content=\"noindex,nofollow\"/>"; - PageTemplates.pageHead(out, "Теги " + user.UName, head); + PageTemplates.pageHead(out, "Теги " + user.getUName(), head); PageTemplates.pageNavigation(out, visitor, null); pageUserColumn(out, sql, user, visitor); @@ -181,8 +178,6 @@ public class User { PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); - } finally { - out.close(); } } @@ -190,14 +185,13 @@ public class User { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); if (visitor == null) { - pageUserRefCookie(request, response, user.UID); + pageUserRefCookie(request, response, user.getUID()); } response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { + try (PrintWriter out = response.getWriter()) { String head = "<meta name=\"robots\" content=\"noindex\"/>"; - PageTemplates.pageHead(out, "Подписки " + user.UName, head); + PageTemplates.pageHead(out, "Подписки " + user.getUName(), head); PageTemplates.pageNavigation(out, visitor, null); pageUserColumn(out, sql, user, visitor); @@ -208,7 +202,7 @@ public class User { 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); + stmt.setInt(1, user.getUID()); rs = stmt.executeQuery(); rs.beforeFirst(); int cnt = 0; @@ -230,8 +224,6 @@ public class User { PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); - } finally { - out.close(); } } @@ -239,14 +231,13 @@ public class User { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); if (visitor == null) { - pageUserRefCookie(request, response, user.UID); + pageUserRefCookie(request, response, user.getUID()); } response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { + try (PrintWriter out = response.getWriter()) { String head = "<meta name=\"robots\" content=\"noindex\"/>"; - PageTemplates.pageHead(out, "Читатели " + user.UName, head); + PageTemplates.pageHead(out, "Читатели " + user.getUName(), head); PageTemplates.pageNavigation(out, visitor, null); pageUserColumn(out, sql, user, visitor); @@ -257,7 +248,7 @@ public class User { 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); + stmt.setInt(1, user.getUID()); rs = stmt.executeQuery(); rs.beforeFirst(); int cnt = 0; @@ -279,8 +270,6 @@ public class User { PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); - } finally { - out.close(); } } @@ -298,21 +287,21 @@ public class User { public static void pageUserColumn(PrintWriter out, Connection sql, com.juick.User user, com.juick.User visitor) { out.println("<aside id=\"column\">"); - out.println(" <div id=\"ctitle\"><a href=\"./\"><img src=\"//i.juick.com/as/" + user.UID + ".png\" alt=\"\"/>" + user.UName + "</a></div>"); - if (visitor != null && visitor.UID > 0 && visitor.UID != user.UID) { + out.println(" <div id=\"ctitle\"><a href=\"./\"><img src=\"//i.juick.com/as/" + user.getUID() + ".png\" alt=\"\"/>" + user.getUName() + "</a></div>"); + if (visitor != null && visitor.getUID() > 0 && visitor.getUID() != user.getUID()) { out.println(" <ul id=\"ctoolbar\">"); - if (UserQueries.isSubscribed(sql, visitor.UID, user.UID)) { - out.println(" <li><a href=\"/post?body=U+%40" + user.UName + "\" title=\"Подписан\"><div style=\"background-position: -48px 0\"></div></a></li>"); + if (UserQueries.isSubscribed(sql, visitor.getUID(), user.getUID())) { + out.println(" <li><a href=\"/post?body=U+%40" + user.getUName() + "\" title=\"Подписан\"><div style=\"background-position: -48px 0\"></div></a></li>"); } else { - out.println(" <li><a href=\"/post?body=S+%40" + user.UName + "\" title=\"Подписаться\"><div style=\"background-position: -16px 0\"></div></a></li>"); + out.println(" <li><a href=\"/post?body=S+%40" + user.getUName() + "\" title=\"Подписаться\"><div style=\"background-position: -16px 0\"></div></a></li>"); } - if (UserQueries.isInBL(sql, visitor.UID, user.UID)) { - out.println(" <li><a href=\"/post?body=BL+%40" + user.UName + "\" title=\"Разблокировать\"><div style=\"background-position: -96px 0\"></div></a></li>"); + if (UserQueries.isInBL(sql, visitor.getUID(), user.getUID())) { + out.println(" <li><a href=\"/post?body=BL+%40" + user.getUName() + "\" title=\"Разблокировать\"><div style=\"background-position: -96px 0\"></div></a></li>"); } else { - out.println(" <li><a href=\"/post?body=BL+%40" + user.UName + "\" title=\"Заблокировать\"><div style=\"background-position: -80px 0\"></div></a></li>"); + out.println(" <li><a href=\"/post?body=BL+%40" + user.getUName() + "\" title=\"Заблокировать\"><div style=\"background-position: -80px 0\"></div></a></li>"); } - if (!UserQueries.isInBLAny(sql, user.UID, visitor.UID)) { - out.println(" <li><a href=\"/pm/sent?uname=" + user.UName + "\" title=\"Написать приватное сообщение\"><div style=\"background-position: -112px 0\"></div></a></li>"); + if (!UserQueries.isInBLAny(sql, user.getUID(), visitor.getUID())) { + out.println(" <li><a href=\"/pm/sent?uname=" + user.getUName() + "\" title=\"Написать приватное сообщение\"><div style=\"background-position: -112px 0\"></div></a></li>"); } out.println(" </ul>"); } else { @@ -330,13 +319,13 @@ public class User { out.println(" <p class=\"tags\">" + pageUserTags(sql, user, visitor, 20) + "<a href=\"./tags\" rel=\"nofollow\">...</a></p>"); out.println(" <hr/>"); out.println(" <div id=\"ustats\"><ul>"); - out.println(" <li><a href=\"./friends\">Я читаю: " + UserQueries.getStatsIRead(sql, user.UID) + "</a></li>"); - out.println(" <li><a href=\"./readers\">Мои подписчики: " + UserQueries.getStatsMyReaders(sql, user.UID) + "</a></li>"); - out.println(" <li>Сообщений: " + UserQueries.getStatsMessages(sql, user.UID) + "</li>"); - out.println(" <li>Комментариев: " + UserQueries.getStatsReplies(sql, user.UID) + "</li>"); + out.println(" <li><a href=\"./friends\">Я читаю: " + UserQueries.getStatsIRead(sql, user.getUID()) + "</a></li>"); + out.println(" <li><a href=\"./readers\">Мои подписчики: " + UserQueries.getStatsMyReaders(sql, user.getUID()) + "</a></li>"); + out.println(" <li>Сообщений: " + UserQueries.getStatsMessages(sql, user.getUID()) + "</li>"); + out.println(" <li>Комментариев: " + UserQueries.getStatsReplies(sql, user.getUID()) + "</li>"); out.println(" </ul>"); - ArrayList<com.juick.User> iread = UserQueries.getUserReadLeastPopular(sql, user.UID, 8); + List<com.juick.User> iread = UserQueries.getUserReadLeastPopular(sql, user.getUID(), 8); if (!iread.isEmpty()) { out.println("<table class=\"iread\"><tr>"); for (int i = 0; i < iread.size(); i++) { @@ -344,7 +333,7 @@ public class User { out.println("</tr><tr>"); } com.juick.User u = iread.get(i); - out.println("<td><a href=\"/" + u.UName + "/\"><img src=\"//i.juick.com/a/" + u.UID + ".png\" alt=\"" + u.UName + "\"/></a></td>"); + out.println("<td><a href=\"/" + u.getUName() + "/\"><img src=\"//i.juick.com/a/" + u.getUID() + ".png\" alt=\"" + u.getUName() + "\"/></a></td>"); } out.println("</tr></table>"); } @@ -362,11 +351,11 @@ public class User { try { 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(1, user.getUID()); 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); + stmt.setInt(1, user.getUID()); } rs = stmt.executeQuery(); rs.last(); |