aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2013-01-29 23:45:00 +0700
committerGravatar Ugnich Anton2013-01-29 23:45:00 +0700
commitcdbf949013fe140fed0e5ad79ad6111c97ea07ad (patch)
treef6ce3225d78eacca649fe219f0aded18f718d864
parent6a6b574cd010f01b4d26907707a28e70d3e384c6 (diff)
Sape optimization
-rw-r--r--src/java/com/juick/http/www/Blogs.java66
-rw-r--r--src/java/com/juick/http/www/Help.java23
-rw-r--r--src/java/com/juick/http/www/Login.java1
-rw-r--r--src/java/com/juick/http/www/Main.java24
-rw-r--r--src/java/com/juick/http/www/NewMessage.java1
-rw-r--r--src/java/com/juick/http/www/PageTemplates.java9
-rw-r--r--src/java/com/juick/http/www/RootRedirects.java57
-rw-r--r--src/java/com/juick/http/www/User.java17
-rw-r--r--src/java/com/juick/http/www/UserThread.java1
-rw-r--r--web/style3.css3
10 files changed, 90 insertions, 112 deletions
diff --git a/src/java/com/juick/http/www/Blogs.java b/src/java/com/juick/http/www/Blogs.java
index 527009a1..5acc8947 100644
--- a/src/java/com/juick/http/www/Blogs.java
+++ b/src/java/com/juick/http/www/Blogs.java
@@ -41,9 +41,9 @@ import javax.servlet.http.HttpServletResponse;
* @author Ugnich Anton
*/
public class Blogs {
-
+
private int relatedTagsStartMID = 0;
-
+
public Blogs(Connection sql) {
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -59,7 +59,7 @@ public class Blogs {
Utils.finishSQL(rs, stmt);
}
}
-
+
protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String paramTagStrQuery = request.getParameter("tag");
if (paramTagStrQuery != null) {
@@ -70,18 +70,18 @@ public class Blogs {
}
Utils.sendPermanentRedirect(response, url);
}
-
+
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;
String paramTagStr = null;
if (requesturi.startsWith("/tag/")) {
@@ -94,7 +94,7 @@ public class Blogs {
} else if (requesturi.startsWith("/places/")) {
//TODO перенести сюда блок, который страницей ниже
}
-
+
int paramBefore = 0;
String paramBeforeStr = request.getParameter("before");
if (paramBeforeStr != null) {
@@ -103,15 +103,15 @@ public class Blogs {
} catch (NumberFormatException e) {
}
}
-
+
String paramSearch = request.getParameter("search");
if (paramSearch != null && paramSearch.length() > 64) {
paramSearch = null;
}
-
+
com.juick.Place place = null;
int visitor_uid = visitor != null ? visitor.UID : 0;
-
+
if (paramShow == null) {
if (paramTag > 0) {
title = "*" + Utils.encodeHTML(paramTagStr);
@@ -179,27 +179,27 @@ public class Blogs {
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, paramSearch);
-
+
out.println("<div id=\"topwrapper\">");
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);
out.println("</ul>");
}
-
+
if (mids.size() == 20) {
String nextpage = "?before=" + mids.get(mids.size() - 1);
if (paramShow != null) {
@@ -210,11 +210,11 @@ public class Blogs {
}
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\">");
if (visitor != null) {
out.println(" <ul>");
@@ -231,33 +231,33 @@ public class Blogs {
out.println(" <li><a href=\"/?show=photos\">" + rb.getString("With photos") + "</a></li>");
out.println(" </ul>");
out.println(" <hr/>");
- out.println(" <p>" + getTags(sql, 36) + "</p>");
+ out.println(" <p>" + getTags(sql, 40) + "</p>");
out.println("</div>");
-
+
out.println("<div id=\"rcol\" class=\"abs\">");
PageTemplates.pageYandexAd(out, visitor == null ? 2 : 3); // разный ID для залогиненых и нет
if (paramTag > 0 && relatedTagsStartMID > 0) {
- String related = getRelatedTags(sql, paramTag, 10);
+ String related = getRelatedTags(sql, paramTag, 15);
if (!related.isEmpty()) {
out.println("<h3>Related tags:</h3>");
out.println("<ul id=\"reltags\">" + related + "</ul>");
}
}
out.println("</div>");
-
+
out.println("</div>"); // topwrapper
PageTemplates.pageDialogTemplate(out, locale);
- PageTemplates.pageFooter(request, out, locale, visitor, true);
+ PageTemplates.pageEnd(out);
} finally {
out.close();
}
}
-
+
private String getTags(Connection sql, int cnt) {
String ret = "";
com.juick.Tag tags[] = new com.juick.Tag[cnt];
-
+
int maxUsageCnt = 0;
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -281,16 +281,16 @@ public class Blogs {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
Arrays.sort(tags, 0, cnt);
-
+
for (int i = 0; i < cnt; i++) {
String tag = Utils.encodeHTML(tags[i].Name);
try {
tag = "<a href=\"/tag/" + URLEncoder.encode(tags[i].Name, "UTF-8") + "\">" + tag + "</a>";
} catch (UnsupportedEncodingException e) {
}
-
+
if (tags[i].UsageCnt > maxUsageCnt / 3 * 2) {
ret += "<big>" + tag + "</big> ";
} else if (tags[i].UsageCnt > maxUsageCnt / 3) {
@@ -299,13 +299,13 @@ public class Blogs {
ret += tag + " ";
}
}
-
+
return ret;
}
-
+
private String getRelatedTags(Connection sql, int tag_id, int cnt) {
String ret = "";
-
+
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -325,7 +325,7 @@ public class Blogs {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
return ret;
}
}
diff --git a/src/java/com/juick/http/www/Help.java b/src/java/com/juick/http/www/Help.java
index 3dfe1f80..9fc21aad 100644
--- a/src/java/com/juick/http/www/Help.java
+++ b/src/java/com/juick/http/www/Help.java
@@ -34,7 +34,7 @@ import javax.servlet.http.HttpServletResponse;
* @author Ugnich Anton
*/
public class Help {
-
+
protected void doRedirectToHelpIndex(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String lang = request.getLocale().getLanguage();
if (!(lang.equals("ru") || lang.equals("fr"))) {
@@ -42,19 +42,19 @@ public class Help {
}
Utils.sendTemporaryRedirect(response, "/help/" + lang + "/");
}
-
+
protected void doGetHelp(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request);
Locale locale = request.getLocale();
ResourceBundle rb = ResourceBundle.getBundle("Global", locale);
-
+
String path[] = request.getRequestURI().split("/");
String page;
if (path.length < 3 || path.length > 4 || path[2].length() != 2 || !path[2].matches("^[a-z]+$")) {
response.sendError(404);
return;
}
-
+
if (path.length == 4) {
page = path[3];
if (!page.matches("^[a-zA-Z0-9\\-]*$") || page.equals("navigation") || page.equals("index")) {
@@ -64,40 +64,41 @@ public class Help {
} else {
page = "index";
}
-
+
File f = new File("/var/www/juick.com/help3/" + path[2] + "/" + page);
if (!f.isFile()) {
response.sendError(404);
return;
}
-
+
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
try {
PageTemplates.pageHead(out, rb.getString("Help"), "");
PageTemplates.pageNavigation(out, locale, visitor, null);
-
+
out.println("<div id=\"topwrapper\">");
out.println("<div id=\"wrapper\">");
out.println("<div id=\"content\">");
printFile(out, f);
out.println("</div>");
out.println("</div>");
-
+
out.println("<div id=\"column\" class=\"abs\">");
printFile(out, new File("/var/www/juick.com/help3/" + path[2] + "/navigation"));
out.println("<hr/>");
printFile(out, new File("/var/www/juick.com/help3/langs"));
out.println("</div>");
-
+
out.println("</div>");
-
+
PageTemplates.pageFooter(request, out, locale, visitor, false);
+ PageTemplates.pageEnd(out);
} finally {
out.close();
}
}
-
+
private void printFile(PrintWriter out, File f) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(f));
String str;
diff --git a/src/java/com/juick/http/www/Login.java b/src/java/com/juick/http/www/Login.java
index e2585909..d50e6115 100644
--- a/src/java/com/juick/http/www/Login.java
+++ b/src/java/com/juick/http/www/Login.java
@@ -59,6 +59,7 @@ public class Login {
out.println("</div>"); // topwrapper
PageTemplates.pageFooter(request, out, locale, visitor, false);
+ 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 226ac729..a41ccf9b 100644
--- a/src/java/com/juick/http/www/Main.java
+++ b/src/java/com/juick/http/www/Main.java
@@ -42,7 +42,6 @@ public class Main extends HttpServlet implements XmppListener {
Connection sqlSearch;
XmppConnection xmpp;
Blogs blogs;
- RootRedirects rootRedirects = new RootRedirects();
Login login = new Login();
Help help = new Help();
User pagesUser = new User();
@@ -122,6 +121,7 @@ public class Main extends HttpServlet implements XmppListener {
request.setCharacterEncoding("UTF-8");
}
String uri = request.getRequestURI();
+
if (uri.equals("/")) {
blogs.doGet(sql, sqlSearch, request, response);
} else if (uri.equals("/post")) {
@@ -150,9 +150,27 @@ public class Main extends HttpServlet implements XmppListener {
} else if (uri.startsWith("/places/")) {
blogs.doGet(sql, sqlSearch, request, response);
} else if (uri.matches("^/\\d+$")) {
- rootRedirects.doGetPostID(sql, request, response);
+ String strID = request.getRequestURI().substring(1);
+ int mid = 0;
+ try {
+ mid = Integer.parseInt(strID);
+ } catch (NumberFormatException e) {
+ }
+ if (mid > 0) {
+ com.juick.User author = com.juick.server.MessagesQueries.getMessageAuthor(sql, mid);
+ if (author != null) {
+ Utils.sendPermanentRedirect(response, "/" + author.UName + "/" + mid);
+ return;
+ }
+ }
+ response.sendError(404);
} else if (uri.matches("^/[^/]+$")) {
- rootRedirects.doGetUsername(sql, request, response);
+ com.juick.User user = com.juick.server.UserQueries.getUserByNick(sql, request.getRequestURI().substring(1));
+ if (user != null) {
+ Utils.sendPermanentRedirect(response, "/" + user.UName + "/");
+ } else {
+ response.sendError(404);
+ }
} else if (uri.matches("^/.+/.*")) {
String uriparts[] = uri.split("/");
com.juick.User user = com.juick.server.UserQueries.getUserByNick(sql, uriparts[1]);
diff --git a/src/java/com/juick/http/www/NewMessage.java b/src/java/com/juick/http/www/NewMessage.java
index 369e9de3..3f1c0ac0 100644
--- a/src/java/com/juick/http/www/NewMessage.java
+++ b/src/java/com/juick/http/www/NewMessage.java
@@ -77,6 +77,7 @@ public class NewMessage {
out.println("</div>");
PageTemplates.pageFooter(request, out, locale, visitor, false);
+ PageTemplates.pageEnd(out);
} finally {
out.close();
}
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java
index 5851a3ee..42fafaf7 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("<html>");
out.println("<head>");
out.println(" <title>" + title + "</title>");
- out.println(" <link rel=\"stylesheet\" href=\"//static.juick.com/style3.2013010900.css\"/>");
+ out.println(" <link rel=\"stylesheet\" href=\"//static.juick.com/style3.2013012601.css\"/>");
out.println(" <link rel=\"icon\" type=\"image/png\" href=\"//static.juick.com/favicon.png\"/>");
out.println(" <script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js\" defer=\"defer\"></script>");
out.println(" <script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js\" defer=\"defer\" async=\"async\"></script>");
@@ -60,7 +60,7 @@ public class PageTemplates {
if (headers != null) {
out.println(headers);
}
- out.println(" <meta name=\"viewport\" content=\"width=device-width,initial-scale=1,user-scalable=no\">");
+ out.println(" <meta name=\"viewport\" content=\"width=device-width,initial-scale=1,user-scalable=no\"/>");
out.println("</head>");
out.println();
out.println("<body>");
@@ -183,7 +183,7 @@ public class PageTemplates {
out.println("<div id=\"fwrapper\"><div id=\"footer\">");
out.println(" <div id=\"footer-right\"><a href=\"/help/ru/contacts\" rel=\"nofollow\">" + rb.getString("Contacts") + "</a> &#183; <a href=\"/help/\" rel=\"nofollow\">" + rb.getString("Help") + "</a></div>");
out.print(" <div id=\"footer-left\">juick.com &copy; 2008-2013");
- if (sapeon && sape != null && (visitor == null || visitor.UID == 1)) {
+ if (sapeon && sape != null && (visitor == null || visitor.UID == 1) && request.getQueryString() == null) {
String links = sape.getPageLinks(request.getRequestURI(), request.getCookies()).render();
if (links != null && !links.isEmpty()) {
out.print("<br/>" + rb.getString("Sponsored by") + ": " + links);
@@ -191,6 +191,9 @@ public class PageTemplates {
}
out.println("</div>");
out.println("</div></div>");
+ }
+
+ public static void pageEnd(PrintWriter out) {
out.println("</body></html>");
}
diff --git a/src/java/com/juick/http/www/RootRedirects.java b/src/java/com/juick/http/www/RootRedirects.java
deleted file mode 100644
index 21b0077e..00000000
--- a/src/java/com/juick/http/www/RootRedirects.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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 java.io.IOException;
-import java.sql.Connection;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- *
- * @author Ugnich Anton
- */
-public class RootRedirects {
-
- protected void doGetPostID(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- String strID = request.getRequestURI().substring(1);
- int mid = 0;
- try {
- mid = Integer.parseInt(strID);
- } catch (NumberFormatException e) {
- }
- if (mid > 0) {
- com.juick.User author = com.juick.server.MessagesQueries.getMessageAuthor(sql, mid);
- if (author != null) {
- Utils.sendPermanentRedirect(response, "/" + author.UName + "/" + mid);
- return;
- }
- }
- response.sendError(404);
- }
-
- protected void doGetUsername(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- com.juick.User user = com.juick.server.UserQueries.getUserByNick(sql, request.getRequestURI().substring(1));
- if (user != null) {
- Utils.sendPermanentRedirect(response, "/" + user.UName + "/");
- } else {
- response.sendError(404);
- }
- }
-}
diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java
index 8574eaab..2faf695b 100644
--- a/src/java/com/juick/http/www/User.java
+++ b/src/java/com/juick/http/www/User.java
@@ -132,14 +132,20 @@ public class User {
}
out.println("<p class=\"page\"><a href=\"" + nextpage + "\">Older →</a></p>");
}
+ PageTemplates.pageFooter(request, out, locale, visitor, true);
out.println("</div>");
pageUserColumn(out, sql, user, visitor, locale);
out.println("</div>");
+
+ out.println("<div id=\"rcol\" class=\"abs\">");
+ PageTemplates.pageYandexAd(out, visitor == null ? 4 : 5); // разный ID для залогиненых и нет
+ out.println("</div>");
+
out.println("</div>"); // topwrapper
PageTemplates.pageDialogTemplate(out, locale);
- PageTemplates.pageFooter(request, out, locale, visitor, true);
+ PageTemplates.pageEnd(out);
} finally {
out.close();
}
@@ -164,13 +170,14 @@ public class User {
out.println("<div id=\"wrapper\">");
out.println("<div id=\"content\">");
out.println("<p>" + pageUserTags(sql, user, visitor, 0) + "</p>");
+ PageTemplates.pageFooter(request, out, locale, visitor, false);
out.println("</div>");
pageUserColumn(out, sql, user, visitor, locale);
out.println("</div>");
out.println("</div>");
PageTemplates.pageDialogTemplate(out, locale);
- PageTemplates.pageFooter(request, out, locale, visitor, false);
+ PageTemplates.pageEnd(out);
} finally {
out.close();
}
@@ -215,13 +222,14 @@ public class User {
}
out.println("</tr></table>");
+ PageTemplates.pageFooter(request, out, locale, visitor, false);
out.println("</div>");
pageUserColumn(out, sql, user, visitor, locale);
out.println("</div>");
out.println("</div>");
PageTemplates.pageDialogTemplate(out, locale);
- PageTemplates.pageFooter(request, out, locale, visitor, false);
+ PageTemplates.pageEnd(out);
} finally {
out.close();
}
@@ -266,13 +274,14 @@ public class User {
}
out.println("</tr></table>");
+ PageTemplates.pageFooter(request, out, locale, visitor, false);
out.println("</div>");
pageUserColumn(out, sql, user, visitor, locale);
out.println("</div>");
out.println("</div>");
PageTemplates.pageDialogTemplate(out, locale);
- PageTemplates.pageFooter(request, out, locale, visitor, false);
+ PageTemplates.pageEnd(out);
} finally {
out.close();
}
diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java
index 3b315be2..aba97a85 100644
--- a/src/java/com/juick/http/www/UserThread.java
+++ b/src/java/com/juick/http/www/UserThread.java
@@ -81,6 +81,7 @@ public class UserThread {
PageTemplates.pageDialogTemplate(out, locale);
PageTemplates.pageFooter(request, out, locale, visitor, false);
+ PageTemplates.pageEnd(out);
} finally {
out.close();
}
diff --git a/web/style3.css b/web/style3.css
index 2e8efe5e..73f0b70c 100644
--- a/web/style3.css
+++ b/web/style3.css
@@ -7,6 +7,7 @@ a { text-decoration: none; color: #069; }
img,hr { border: none; }
hr { height: 1px; background: #CCC; }
pre { white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word; }
+.u { text-decoration: underline; }
#header, #topwrapper { width: 1000px; margin: 0 auto; }
#content, #footer { width: 600px; margin: 0 auto; }
@@ -112,7 +113,7 @@ blockquote { border-left: 1px dashed #CCC; margin: 10px 0 10px 10px; padding-lef
/********/
-#footer { clear: both; font-size: small; padding: 10px; color: #999; }
+#footer { clear: both; font-size: small; padding: 10px 0; color: #999; }
#footer-right { float: right; }
/******************************************************************************/