aboutsummaryrefslogtreecommitdiff
path: root/src/java/com
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2013-10-24 01:24:19 +0700
committerGravatar Ugnich Anton2013-10-24 01:24:19 +0700
commit19dbb5c44b3c32b894ed2c3c83d6c67aa69e7c17 (patch)
tree29bfc3ebc1f5d098143355eb2a17aff560378165 /src/java/com
parent1ff9fecd9342970bdc4a835ee5a57a5f27cdd206 (diff)
Home + Discover
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/juick/http/www/Discover.java (renamed from src/java/com/juick/http/www/Blogs.java)97
-rw-r--r--src/java/com/juick/http/www/Home.java121
-rw-r--r--src/java/com/juick/http/www/Main.java21
-rw-r--r--src/java/com/juick/http/www/PageTemplates.java17
4 files changed, 149 insertions, 107 deletions
diff --git a/src/java/com/juick/http/www/Blogs.java b/src/java/com/juick/http/www/Discover.java
index cf58ed4f..b76a1d77 100644
--- a/src/java/com/juick/http/www/Blogs.java
+++ b/src/java/com/juick/http/www/Discover.java
@@ -40,27 +40,13 @@ import javax.servlet.http.HttpServletResponse;
*
* @author Ugnich Anton
*/
-public class Blogs {
-
- protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
- String paramTagStrQuery = request.getParameter("tag");
- if (paramTagStrQuery != null) {
- String url = "/tag/" + URLEncoder.encode(paramTagStrQuery, "UTF-8");
- String paramBeforeStr = request.getParameter("before");
- if (paramBeforeStr != null) {
- url += "?before=" + paramBeforeStr;
- }
- Utils.sendPermanentRedirect(response, url);
- }
+public class Discover {
+ protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ com.juick.User visitor = Utils.getVisitorUser(sql, request);
Locale locale = request.getLocale();
ResourceBundle rb = ResourceBundle.getBundle("Blogs", locale);
- String title;
- ArrayList<Integer> mids;
-
- String paramShow = request.getParameter("show");
-
String requesturi = request.getRequestURI();
int paramTag = 0;
@@ -72,8 +58,6 @@ public class Blogs {
response.sendError(404);
return;
}
- } else if (requesturi.startsWith("/places/")) {
- //TODO перенести сюда блок, который страницей ниже
}
int paramBefore = 0;
@@ -90,9 +74,12 @@ public class Blogs {
paramSearch = null;
}
- com.juick.Place place = null;
int visitor_uid = visitor != null ? visitor.UID : 0;
+ String title;
+ ArrayList<Integer> mids;
+
+ String paramShow = request.getParameter("show");
if (paramShow == null) {
if (paramTag > 0) {
title = "*" + Utils.encodeHTML(paramTagStr);
@@ -100,59 +87,10 @@ public class Blogs {
} else if (paramSearch != null) {
title = rb.getString("Search") + ": " + Utils.encodeHTML(paramSearch);
mids = MessagesQueries.getSearch(sql, sqlSearch, Utils.encodeSphinx(paramSearch), paramBefore);
- } else if (requesturi.matches("^\\/places\\/\\d+$")) {
- int place_id = 0;
- try {
- place_id = Integer.parseInt(requesturi.substring(8));
- } catch (NumberFormatException e) {
- }
- place = com.juick.server.PlacesQueries.getPlace(sql, place_id);
- if (place != null) {
- title = place.name;
- mids = MessagesQueries.getPlace(sql, place_id, visitor_uid, paramBefore);
- } else {
- response.sendError(404);
- return;
- }
} else {
title = rb.getString("Last messages");
mids = MessagesQueries.getAll(sql, visitor_uid, paramBefore);
}
- } else if (paramShow.equals("my")) {
- if (visitor != null) {
- title = rb.getString("My feed");
- mids = MessagesQueries.getMyFeed(sql, visitor.UID, paramBefore);
- } else {
- response.sendError(404);
- return;
- }
- } else if (paramShow.equals("private")) {
- if (visitor != null) {
- title = rb.getString("Private");
- mids = MessagesQueries.getPrivate(sql, visitor.UID, paramBefore);
- } else {
- response.sendError(404);
- return;
- }
- } else if (paramShow.equals("discuss")) {
- if (visitor != null) {
- title = rb.getString("Discussions");
- mids = MessagesQueries.getDiscussions(sql, visitor.UID, paramBefore);
- } else {
- response.sendError(404);
- return;
- }
- } else if (paramShow.equals("recommended")) {
- if (visitor != null) {
- title = rb.getString("Recommended");
- mids = MessagesQueries.getRecommended(sql, visitor.UID, paramBefore);
- } else {
- response.sendError(404);
- return;
- }
- } else if (paramShow.equals("top")) {
- title = rb.getString("Popular");
- mids = MessagesQueries.getPopular(sql, paramBefore);
} else if (paramShow.equals("photos")) {
title = rb.getString("With photos");
mids = MessagesQueries.getPhotos(sql, visitor_uid, paramBefore);
@@ -171,10 +109,6 @@ public class Blogs {
out.println("<div id=\"wrapper\">");
out.println("<div id=\"content\">");
- if (place != null) {
- out.println("<div id=\"geomap\"><img src=\"http://maps.google.com/maps/api/staticmap?center=" + place.lat + "," + place.lon + "&amp;markers=color:orange|" + place.lat + "," + place.lon + "&amp;zoom=14&amp;size=600x300&amp;maptype=hybrid&amp;sensor=false\" width=\"600\" height=\"300\" alt=\"Map\"/></div>");
- }
-
if (mids.size() > 0) {
out.println("<ul>");
PageTemplates.printMessages(out, sql, null, mids, visitor, locale, visitor == null ? 2 : 3);
@@ -197,24 +131,11 @@ public class Blogs {
out.println("<div id=\"column\" class=\"abs\">");
- if (visitor != null) {
- out.println(" <ul>");
- out.println(" <li><a href=\"/?show=my\">" + rb.getString("My feed") + "</a></li>");
- out.println(" <li><a href=\"/?show=private\">" + rb.getString("Private") + "</a></li>");
- out.println(" <li><a href=\"/?show=discuss\">" + rb.getString("Discussions") + "</a></li>");
- out.println(" <li><a href=\"/?show=recommended\">" + rb.getString("Recommended") + "</a></li>");
- out.println(" </ul>");
- out.println(" <hr/>");
- }
out.println(" <ul>");
- out.println(" <li><a href=\"/\">" + rb.getString("All messages") + "</a></li>");
- out.println(" <li><a href=\"/?show=top\">" + rb.getString("Popular") + "</a></li>");
- out.println(" <li><a href=\"/?show=photos\">" + rb.getString("With photos") + "</a></li>");
+ out.println(" <li><a href=\"/discover\">" + rb.getString("All messages") + "</a></li>");
+ out.println(" <li><a href=\"/discover?show=photos\">" + rb.getString("With photos") + "</a></li>");
out.println(" </ul>");
out.println(" <hr/>");
- out.println(" <form action=\"/\">");
- out.println(" <p><input type=\"text\" name=\"search\" class=\"inp\" placeholder=\"" + rb.getString("Search") + "\"/></p>");
- out.println(" </form>");
out.println(" <p>" + getTags(sql, 45) + "</p>");
out.println("</div>");
diff --git a/src/java/com/juick/http/www/Home.java b/src/java/com/juick/http/www/Home.java
new file mode 100644
index 00000000..b9009a80
--- /dev/null
+++ b/src/java/com/juick/http/www/Home.java
@@ -0,0 +1,121 @@
+/*
+ * Juick
+ * Copyright (C) 2008-2011, Ugnich Anton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.juick.http.www;
+
+import com.juick.server.MessagesQueries;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author Ugnich Anton
+ */
+public class Home {
+
+ protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
+ Locale locale = request.getLocale();
+ ResourceBundle rb = ResourceBundle.getBundle("Blogs", locale);
+
+ int paramBefore = 0;
+ String paramBeforeStr = request.getParameter("before");
+ if (paramBeforeStr != null) {
+ try {
+ paramBefore = Integer.parseInt(paramBeforeStr);
+ } catch (NumberFormatException e) {
+ }
+ }
+
+ String title;
+ ArrayList<Integer> mids;
+
+ String paramShow = request.getParameter("show");
+ if (paramShow == null || paramShow.equals("my")) {
+ title = rb.getString("My feed");
+ mids = MessagesQueries.getMyFeed(sql, visitor.UID, paramBefore);
+ } else if (paramShow.equals("private")) {
+ title = rb.getString("Private");
+ mids = MessagesQueries.getPrivate(sql, visitor.UID, paramBefore);
+ } else if (paramShow.equals("discuss")) {
+ title = rb.getString("Discussions");
+ mids = MessagesQueries.getDiscussions(sql, visitor.UID, paramBefore);
+ } else if (paramShow.equals("recommended")) {
+ title = rb.getString("Recommended");
+ mids = MessagesQueries.getRecommended(sql, visitor.UID, paramBefore);
+ } else if (paramShow.equals("top")) {
+ title = rb.getString("Popular");
+ mids = MessagesQueries.getPopular(sql, paramBefore);
+ } else {
+ response.sendError(404);
+ return;
+ }
+
+ response.setContentType("text/html; charset=UTF-8");
+ PrintWriter out = response.getWriter();
+ try {
+ PageTemplates.pageHead(out, title, null);
+ PageTemplates.pageNavigation(out, locale, visitor, null);
+
+ out.println("<div id=\"topwrapper\">");
+ out.println("<div id=\"wrapper\">");
+ out.println("<div id=\"content\">");
+
+ if (mids.size() > 0) {
+ out.println("<ul>");
+ PageTemplates.printMessages(out, sql, null, mids, visitor, locale, visitor == null ? 2 : 3);
+ out.println("</ul>");
+ }
+
+ if (mids.size() == 20) {
+ String nextpage = "?before=" + mids.get(mids.size() - 1);
+ if (paramShow != null) {
+ nextpage += "&amp;show=" + paramShow;
+ }
+ out.println("<p class=\"page\"><a href=\"" + nextpage + "\">Older →</a></p>");
+ }
+ PageTemplates.pageFooter(request, out, locale, visitor, true);
+ out.println("</div>");
+ out.println("</div>"); // wrapper
+
+
+ out.println("<div id=\"column\" class=\"abs\">");
+ out.println(" <ul>");
+ out.println(" <li><a href=\"/?show=my\">" + rb.getString("My feed") + "</a></li>");
+ out.println(" <li><a href=\"/?show=private\">" + rb.getString("Private") + "</a></li>");
+ out.println(" <li><a href=\"/?show=discuss\">" + rb.getString("Discussions") + "</a></li>");
+ out.println(" <li><a href=\"/?show=recommended\">" + rb.getString("Recommended") + "</a></li>");
+ out.println(" <li class=\"margtop\"><a href=\"/?show=top\">" + rb.getString("Popular") + "</a></li>");
+ out.println(" </ul>");
+ out.println(" <hr/>");
+ out.println("</div>");
+
+ out.println("</div>"); // topwrapper
+
+ PageTemplates.pageDialogTemplate(out, locale);
+ PageTemplates.pageEnd(out);
+ } finally {
+ out.close();
+ }
+ }
+}
diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java
index 4c6e310b..8b760e44 100644
--- a/src/java/com/juick/http/www/Main.java
+++ b/src/java/com/juick/http/www/Main.java
@@ -41,7 +41,8 @@ public class Main extends HttpServlet {
Connection sql;
Connection sqlSearch;
Stream xmpp;
- Blogs blogs = new Blogs();
+ Home home = new Home();
+ Discover discover = new Discover();
Login login = new Login();
Help help = new Help();
User pagesUser = new User();
@@ -111,14 +112,10 @@ public class Main extends HttpServlet {
if (uri.equals("/")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request);
- if (request.getQueryString() == null) {
- if (visitor == null) {
- login.doGetLoginForm(sql, request, response);
- } else {
- blogs.doGet(sql, sqlSearch, request, response, visitor);
- }
+ if (visitor == null) {
+ login.doGetLoginForm(sql, request, response);
} else {
- blogs.doGet(sql, sqlSearch, request, response, visitor);
+ home.doGet(sql, sqlSearch, request, response, visitor);
}
} else if (uri.equals("/post")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request);
@@ -147,12 +144,10 @@ public class Main extends HttpServlet {
help.doRedirectToHelpIndex(sql, request, response);
} else if (uri.startsWith("/help/")) {
help.doGetHelp(sql, request, response);
+ } else if (uri.equals("/discover")) {
+ discover.doGet(sql, sqlSearch, request, response);
} else if (uri.startsWith("/tag/")) {
- com.juick.User visitor = Utils.getVisitorUser(sql, request);
- blogs.doGet(sql, sqlSearch, request, response, visitor);
- } else if (uri.startsWith("/places/")) {
- com.juick.User visitor = Utils.getVisitorUser(sql, request);
- blogs.doGet(sql, sqlSearch, request, response, visitor);
+ discover.doGet(sql, sqlSearch, request, response);
} else if (uri.matches("^/\\d+$")) {
String strID = request.getRequestURI().substring(1);
int mid = 0;
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java
index fc9bb1d5..0c98f26f 100644
--- a/src/java/com/juick/http/www/PageTemplates.java
+++ b/src/java/com/juick/http/www/PageTemplates.java
@@ -50,7 +50,7 @@ public class PageTemplates {
out.println("<!DOCTYPE html>");
out.print("<html>");
out.print("<head>");
- out.print("<link rel=\"stylesheet\" href=\"/style.2013102203.css\"/>");
+ out.print("<link rel=\"stylesheet\" href=\"/style.2013102401.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=\"//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js\" defer=\"defer\" async=\"async\"></script>");
out.print("<script type=\"text/javascript\" src=\"/scripts.2013072200.js\" defer=\"defer\"></script>");
@@ -69,14 +69,19 @@ public class PageTemplates {
ResourceBundle rb = ResourceBundle.getBundle("Global", loc);
out.println("<div id=\"hwrapper\">");
out.println("<ul id=\"header\">");
- out.println(" <li id=\"logo\"><a href=\"" + (user != null ? "/?show=my" : "/") + "\"><div class=\"head-ico\" id=\"hi-logo\"></div></a></li>");
- /*
- out.print(" <li id=\"search\"><form action=\"/\"><input type=\"text\" name=\"search\" class=\"text\" placeholder=\"" + rb.getString("Search") + "\"");
+ if (user != null) {
+ out.println(" <li><a href=\"/\"><div class=\"head-ico\" id=\"hi-home\"></div><label>" + rb.getString("Home") + "</label></a></li>");
+ out.println(" <li><a href=\"/discover\"><div class=\"head-ico\" id=\"hi-discover\"></div><label>" + rb.getString("Discover") + "</label></a></li>");
+ } else {
+ out.println(" <li><a href=\"/\"><div class=\"head-ico\" id=\"hi-logo\"></div></a></li>");
+ }
+
+ out.print(" <li id=\"search\"><form action=\"/discover\"><input type=\"text\" name=\"search\" class=\"text\" placeholder=\"" + rb.getString("Search") + "\"");
if (search != null) {
- out.print(" value=\"" + Utils.encodeHTML(search) + "\"");
+ out.print(" value=\"" + Utils.encodeHTML(search) + "\"");
}
out.println("/></form></li>");
- */
+
if (user != null) {
out.println(" <li class=\"right\"><a href=\"/logout\"><div class=\"head-ico\" id=\"hi-logout\"></div></a></li>");
out.println(" <li class=\"right\"><a href=\"/settings\"><div class=\"head-ico\" id=\"hi-settings\"></div></a></li>");