diff options
author | Ugnich Anton | 2014-07-30 16:47:29 +0700 |
---|---|---|
committer | Ugnich Anton | 2014-07-30 16:47:29 +0700 |
commit | c4eebb74f520c122800c000c2329d3b6b7520c65 (patch) | |
tree | 99fa7c755ed488c4e566c9a2c14c37e079fdb9ae /src/java/com/juick/http/www/Reader.java | |
parent | 6856f7278584425b0cb6fc54d50f5d5cf4a3f88e (diff) |
Reader link tracking
Diffstat (limited to 'src/java/com/juick/http/www/Reader.java')
-rw-r--r-- | src/java/com/juick/http/www/Reader.java | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/java/com/juick/http/www/Reader.java b/src/java/com/juick/http/www/Reader.java index dc356482..75a0e774 100644 --- a/src/java/com/juick/http/www/Reader.java +++ b/src/java/com/juick/http/www/Reader.java @@ -54,11 +54,11 @@ public class Reader { PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT rss_id,url,title FROM reader_links ORDER BY ts DESC LIMIT 100"); + stmt = sql.prepareStatement("SELECT link_id,rss_id,url,title FROM reader_links ORDER BY ts DESC LIMIT 100"); rs = stmt.executeQuery(); rs.beforeFirst(); while (rs.next()) { - out.println("<li><img src=\"//i.juick.com/rss-icons/" + rs.getInt(1) + ".png\" width=\"16\" height=\"16\"/><a href=\"" + rs.getString(2) + "\" rel=\"nofollow\" target=\"_blank\">" + rs.getString(3) + "</a></li>"); + out.println("<li><img src=\"//i.juick.com/rss-icons/" + rs.getInt(2) + ".png\" width=\"16\" height=\"16\"/><a href=\"" + rs.getString(3) + "\" data-lid=\""+rs.getInt(1)+"\" onmousedown=\"readerLinkReplace(this)\" rel=\"nofollow\" target=\"_blank\">" + rs.getString(4) + "</a></li>"); } } catch (SQLException e) { System.err.println(e); @@ -75,4 +75,37 @@ public class Reader { out.close(); } } + + protected void doGetOut(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + com.juick.User visitor = Utils.getVisitorUser(sql, request, response); + int lid = Utils.parseInt(request.getParameter("lid"), 0); + if (lid == 0) { + response.sendError(404); + return; + } + + String url = null; + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT url FROM reader_links WHERE link_id=?"); + stmt.setInt(1, lid); + rs = stmt.executeQuery(); + if (rs.first()) { + url = rs.getString(1); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + if (url == null) { + response.sendError(404); + return; + } + + Utils.sendTemporaryRedirect(response, url); + } } |