diff options
author | 2014-03-08 16:26:50 +0700 | |
---|---|---|
committer | 2014-03-08 16:26:50 +0700 | |
commit | 88f3693c53e70ad064ccc1466ddf27cae98db49a (patch) | |
tree | fbc0aa93af928137ae822017c6998519767b8cfa /src/java | |
parent | a573191fa752c0d9155f1c9f0d8a89f044c7af7a (diff) |
iPod contest
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/com/juick/http/www/PageTemplates.java | 35 | ||||
-rw-r--r-- | src/java/com/juick/http/www/SignUp.java | 30 | ||||
-rw-r--r-- | src/java/com/juick/http/www/User.java | 29 | ||||
-rw-r--r-- | src/java/com/juick/http/www/UserThread.java | 4 |
4 files changed, 97 insertions, 1 deletions
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index c76ded41..f9cce99e 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -52,7 +52,7 @@ public class PageTemplates { out.println("<!DOCTYPE html>"); out.print("<html>"); out.print("<head>"); - out.print("<link rel=\"stylesheet\" href=\"/style.2014022100.css\"/>"); + out.print("<link rel=\"stylesheet\" href=\"/style.2014030800.css\"/>"); out.print("<script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js\" defer=\"defer\"></script>"); out.print("<script type=\"text/javascript\" src=\"/scripts.2014021500.js\" defer=\"defer\"></script>"); if (headers != null) { @@ -136,6 +136,7 @@ public class PageTemplates { out.println("<aside id=\"column\">"); out.println(" <p class=\"tags\">" + tagsHTML + "</p>"); + printContestRating(out, sql); out.println("</aside>"); } @@ -188,6 +189,38 @@ public class PageTemplates { return ret; } + public static void printContestRating(PrintWriter out, Connection sql) { + out.println("<hr/>"); + out.println("<!--noindex-->"); + out.println("<p style=\"font-size: 14pt\">Кто <a href=\"/help/ru/contest\">выиграет iPod</a>?</p>"); + out.println("<table width=\"100%\">"); + + int i = 0; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT users.id,users.nick,COUNT(users_refs.user_id) AS cnt FROM users INNER JOIN users_refs ON users.id=users_refs.ref GROUP BY users_refs.ref ORDER BY cnt DESC LIMIT 10"); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + String uname = rs.getString(2); + if (i == 0) { + out.println(" <tr><td><b><a href=\"/" + uname + "/\">" + uname + "</a></b></td><td align=\"right\"><b>" + rs.getInt(3) + "</b></td></tr>"); + } else { + out.println(" <tr><td><a href=\"/" + uname + "/\">" + uname + "</a></td><td align=\"right\">" + rs.getInt(3) + "</td></tr>"); + } + i++; + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + out.println("</table>"); + out.println("<!--/noindex-->"); + } + public static void pageDialogTemplate(PrintWriter out) { out.println("<div id=\"dialogb\" onclick=\"$('#dialogb').hide();$('#dialogw').hide()\"></div>"); out.println("<div id=\"dialogw\">Ссылка на сообщение:"); diff --git a/src/java/com/juick/http/www/SignUp.java b/src/java/com/juick/http/www/SignUp.java index 2fbe2e2d..cf6679ce 100644 --- a/src/java/com/juick/http/www/SignUp.java +++ b/src/java/com/juick/http/www/SignUp.java @@ -172,6 +172,19 @@ public class SignUp { return; } + int ref = 0; + String sRef = Utils.getCookie(request, "ref"); + if (sRef != null) { + try { + ref = Integer.parseInt(sRef); + } catch (Exception e) { + } + } + + if (ref > 0) { + setUserRef(sql, uid, ref); + } + visitor = null; } @@ -185,6 +198,23 @@ public class SignUp { response.sendRedirect("/"); } + private boolean setUserRef(Connection sql, int uid, int ref) { + boolean ret = false; + PreparedStatement stmt = null; + try { + stmt = sql.prepareStatement("INSERT INTO users_refs(user_id,ref) VALUES (?,?)"); + stmt.setInt(1, uid); + stmt.setInt(2, ref); + stmt.executeUpdate(); + ret = true; + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(null, stmt); + } + return ret; + } + private String getFacebookNameByHash(Connection sql, String hash) { String ret = null; diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java index 90a558cc..b517af8e 100644 --- a/src/java/com/juick/http/www/User.java +++ b/src/java/com/juick/http/www/User.java @@ -31,6 +31,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import javax.servlet.ServletException; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -105,6 +106,10 @@ public class User { return; } + if (visitor == null) { + pageUserRefCookie(request, response, user.UID); + } + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { @@ -151,6 +156,10 @@ public class User { protected void doGetTags(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); + if (visitor == null) { + pageUserRefCookie(request, response, user.UID); + } + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { @@ -180,6 +189,10 @@ public class User { protected void doGetFriends(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); + if (visitor == null) { + pageUserRefCookie(request, response, user.UID); + } + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { @@ -232,6 +245,10 @@ public class User { protected void doGetReaders(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); + if (visitor == null) { + pageUserRefCookie(request, response, user.UID); + } + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { @@ -281,6 +298,18 @@ public class User { } } + public static void pageUserRefCookie(HttpServletRequest request, HttpServletResponse response, int uid) { + String hReferer = request.getHeader("Referer"); + String ref = Utils.getCookie(request, "ref"); + + if (ref == null && (hReferer == null || !(hReferer.startsWith("http://juick.com/") || hReferer.startsWith("https://juick.com/")))) { + Cookie c = new Cookie("ref", Integer.toString(uid)); + c.setMaxAge(7 * 24 * 60 * 60); + c.setPath("/"); + response.addCookie(c); + } + } + 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>"); diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java index cf1ae76a..541af344 100644 --- a/src/java/com/juick/http/www/UserThread.java +++ b/src/java/com/juick/http/www/UserThread.java @@ -60,6 +60,10 @@ public class UserThread { String title = msg.User.UName + ": " + msg.getTagsString(); + if (visitor == null) { + User.pageUserRefCookie(request, response, msg.User.UID); + } + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { |