diff options
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/com/juick/http/www/Main.java | 26 | ||||
-rw-r--r-- | src/java/com/juick/http/www/PageTemplates.java | 2 | ||||
-rw-r--r-- | src/java/com/juick/http/www/Reader.java | 37 |
3 files changed, 50 insertions, 15 deletions
diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java index 1d5e64d32..0fe93173f 100644 --- a/src/java/com/juick/http/www/Main.java +++ b/src/java/com/juick/http/www/Main.java @@ -43,7 +43,7 @@ import ru.sape.Sape; @WebServlet(name = "Main", urlPatterns = {"/"}) @MultipartConfig(fileSizeThreshold = 1024 * 1024, maxRequestSize = 1024 * 1024 * 10) public class Main extends HttpServlet implements Stream.StreamListener { - + Connection sql; Connection sqlSearch; Stream xmpp; @@ -60,29 +60,29 @@ public class Main extends HttpServlet implements Stream.StreamListener { VKontakteLogin loginVK = new VKontakteLogin(); SignUp signup = new SignUp(); Settings settings = new Settings(); - + @Override public void init() throws ServletException { super.init(); try { Properties conf = new Properties(); conf.load(new FileInputStream("/etc/juick/www.conf")); - + Class.forName("com.mysql.jdbc.Driver"); sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", "")); sqlSearch = DriverManager.getConnection("jdbc:mysql://127.0.0.1:9306?autoReconnect=true&characterEncoding=utf8&maxAllowedPacket=512000", "", ""); - + setupXmppComponent(conf.getProperty("xmpp_password")); - + PageTemplates.sape = new Sape(conf.getProperty("sape_user"), "juick.com", 2000, 3600); } catch (Exception e) { log(null, e); } } - + public void setupXmppComponent(final String password) { Thread thr = new Thread(new Runnable() { - + @Override public void run() { try { @@ -97,17 +97,17 @@ public class Main extends HttpServlet implements Stream.StreamListener { }); thr.start(); } - + @Override public void onStreamFail(String msg) { System.err.println("XMPP STREAM FAIL: " + msg); } - + @Override public void onStreamReady() { System.err.println("XMPP STREAM READY"); } - + @Override public void destroy() { super.destroy(); @@ -142,7 +142,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { request.setCharacterEncoding("UTF-8"); } String uri = request.getRequestURI(); - + if (uri.equals("/")) { String tag = request.getParameter("tag"); if (tag != null) { @@ -153,6 +153,8 @@ public class Main extends HttpServlet implements Stream.StreamListener { } } else if (uri.equals("/reader")) { reader.doGet(sql, request, response); + } else if (uri.equals("/_out")) { + reader.doGetOut(sql, request, response); } else if (uri.equals("/post")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); if (visitor != null) { @@ -272,7 +274,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("UTF-8"); } - + String uri = request.getRequestURI(); if (uri.equals("/post")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index afffc3345..dc8c7c595 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -53,7 +53,7 @@ public class PageTemplates { out.print("<head>"); out.print("<link rel=\"stylesheet\" href=\"/style.2014072500.css\"/>"); out.print("<script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js\"></script>"); - out.print("<script type=\"text/javascript\" src=\"/scripts.2014071701.js\"></script>"); + out.print("<script type=\"text/javascript\" src=\"/scripts.2014072900.js\"></script>"); if (headers != null) { out.print(headers); } diff --git a/src/java/com/juick/http/www/Reader.java b/src/java/com/juick/http/www/Reader.java index dc356482b..75a0e7745 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); + } } |