From 3ba6237fa51d77bd6da0557a19ca729e70d76d1c Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Tue, 17 Jun 2014 16:29:44 +0700 Subject: - isMobileRequest; - Dev * blockquote -> q --- src/java/com/juick/http/www/Dev.java | 101 ------------------------- src/java/com/juick/http/www/Discover.java | 11 +-- src/java/com/juick/http/www/Home.java | 12 +-- src/java/com/juick/http/www/Main.java | 8 -- src/java/com/juick/http/www/NewMessage.java | 10 +-- src/java/com/juick/http/www/PM.java | 13 +--- src/java/com/juick/http/www/PageTemplates.java | 8 +- src/java/com/juick/http/www/User.java | 44 ++--------- src/java/com/juick/http/www/UserThread.java | 10 +-- src/java/com/juick/http/www/Utils.java | 5 -- 10 files changed, 25 insertions(+), 197 deletions(-) delete mode 100644 src/java/com/juick/http/www/Dev.java (limited to 'src/java') diff --git a/src/java/com/juick/http/www/Dev.java b/src/java/com/juick/http/www/Dev.java deleted file mode 100644 index d51ef95f..00000000 --- a/src/java/com/juick/http/www/Dev.java +++ /dev/null @@ -1,101 +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 . - */ -package com.juick.http.www; - -import com.juick.server.MessagesQueries; -import com.juick.server.TagQueries; -import java.io.IOException; -import java.io.PrintWriter; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.sql.Connection; -import java.util.ArrayList; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * - * @author Ugnich Anton - */ -public class Dev { - - protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - - String paramTagStr = URLDecoder.decode(request.getRequestURI().substring(5), "UTF-8"); - com.juick.Tag paramTag = TagQueries.getTag(sql, paramTagStr, false); - if (paramTag == null) { - Errors.doGet404(sql, request, response); - return; - } else if (!paramTag.Name.equals(paramTagStr)) { - String url = "/tag/" + URLEncoder.encode(paramTag.Name, "UTF-8"); - if (request.getQueryString() != null) { - url += "?" + request.getQueryString(); - } - Utils.sendPermanentRedirect(response, url); - return; - } - - int paramBefore = 0; - String paramBeforeStr = request.getParameter("before"); - if (paramBeforeStr != null) { - try { - paramBefore = Integer.parseInt(paramBeforeStr); - } catch (NumberFormatException e) { - } - } - - int visitor_uid = visitor != null ? visitor.UID : 0; - - String title = "*" + Utils.encodeHTML(paramTag.Name); - ArrayList mids = MessagesQueries.getTag(sql, paramTag.TID, visitor_uid, paramBefore, (visitor == null) ? 40 : 20); - - response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { - PageTemplates.pageHead(out, title, null); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageNavigation(out, visitor, null); - PageTemplates.pageHomeColumn(out, sql, visitor); - } - - out.println("
"); - - if (mids.size() > 0) { - PageTemplates.printMessages(out, sql, null, mids, visitor, visitor == null ? 2 : 3, 0); - } - - if (mids.size() >= 20) { - String nextpage = "/tag/" + URLEncoder.encode(paramTag.Name, "UTF-8") + "?before=" + mids.get(mids.size() - 1); - out.println("

Читать дальше →

"); - } - - out.println("
"); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageFooter(request, out, visitor, true); - } - - PageTemplates.pageEnd(out); - } finally { - out.close(); - } - } -} diff --git a/src/java/com/juick/http/www/Discover.java b/src/java/com/juick/http/www/Discover.java index 08930e27..dcc0c441 100644 --- a/src/java/com/juick/http/www/Discover.java +++ b/src/java/com/juick/http/www/Discover.java @@ -70,11 +70,8 @@ public class Discover { PrintWriter out = response.getWriter(); try { PageTemplates.pageHead(out, title, null); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageNavigation(out, visitor, null); - PageTemplates.pageHomeColumn(out, sql, visitor); - } + PageTemplates.pageNavigation(out, visitor, null); + PageTemplates.pageHomeColumn(out, sql, visitor); out.println("
"); @@ -89,9 +86,7 @@ public class Discover { out.println("
"); - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageFooter(request, out, visitor, true); - } + PageTemplates.pageFooter(request, out, visitor, true); PageTemplates.pageEnd(out); } finally { diff --git a/src/java/com/juick/http/www/Home.java b/src/java/com/juick/http/www/Home.java index 3931fd24..db8b0b2c 100644 --- a/src/java/com/juick/http/www/Home.java +++ b/src/java/com/juick/http/www/Home.java @@ -94,11 +94,8 @@ public class Home { PrintWriter out = response.getWriter(); try { PageTemplates.pageHead(out, title, null); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageNavigation(out, visitor, paramSearch); - PageTemplates.pageHomeColumn(out, sql, visitor); - } + PageTemplates.pageNavigation(out, visitor, paramSearch); + PageTemplates.pageHomeColumn(out, sql, visitor); out.println("
"); @@ -153,10 +150,7 @@ public class Home { out.println("
"); - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageFooter(request, out, visitor, true); - } - + PageTemplates.pageFooter(request, out, visitor, true); 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 a81c1ba1..ec7c4e1e 100644 --- a/src/java/com/juick/http/www/Main.java +++ b/src/java/com/juick/http/www/Main.java @@ -49,7 +49,6 @@ public class Main extends HttpServlet implements Stream.StreamListener { Stream xmpp; Home home = new Home(); Discover discover = new Discover(); - Dev dev = new Dev(); PM pm = new PM(); Login login = new Login(); Help help = new Help(); @@ -193,13 +192,6 @@ public class Main extends HttpServlet implements Stream.StreamListener { help.doGetHelp(sql, request, response); } else if (uri.startsWith("/tag/")) { discover.doGet(sql, sqlSearch, request, response); - } else if (uri.equals("/dev")) { - com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - if (visitor != null && visitor.UID == 1) { - dev.doGet(sql, request, response); - } else { - Errors.doGet404(sql, 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/NewMessage.java b/src/java/com/juick/http/www/NewMessage.java index 4bb87404..2072e41f 100644 --- a/src/java/com/juick/http/www/NewMessage.java +++ b/src/java/com/juick/http/www/NewMessage.java @@ -53,10 +53,7 @@ public class NewMessage { + "" + "" + ""); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageNavigation(out, visitor, null); - } + PageTemplates.pageNavigation(out, visitor, null); out.println("
"); out.println("
"); @@ -81,10 +78,7 @@ public class NewMessage { printUserTags(sql, out, visitor); out.println("
"); - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageFooter(request, out, visitor, false); - } - + PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); } finally { out.close(); diff --git a/src/java/com/juick/http/www/PM.java b/src/java/com/juick/http/www/PM.java index 2aa0e0f2..c587e5b1 100644 --- a/src/java/com/juick/http/www/PM.java +++ b/src/java/com/juick/http/www/PM.java @@ -56,11 +56,8 @@ public class PM { PrintWriter out = response.getWriter(); try { PageTemplates.pageHead(out, title, null); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageNavigation(out, visitor, null); - PageTemplates.pageHomeColumn(out, sql, visitor); - } + PageTemplates.pageNavigation(out, visitor, null); + PageTemplates.pageHomeColumn(out, sql, visitor); out.println("
"); @@ -97,10 +94,7 @@ public class PM { out.println("
"); - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageFooter(request, out, visitor, true); - } - + PageTemplates.pageFooter(request, out, visitor, true); PageTemplates.pageEnd(out); } finally { out.close(); @@ -132,7 +126,6 @@ public class PM { try { PageTemplates.pageHead(out, title, null); PageTemplates.pageNavigation(out, visitor, null); - PageTemplates.pageHomeColumn(out, sql, visitor); out.println("
"); diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index a7b2daf9..e9de8edb 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(""); out.print(""); out.print(""); - out.print(""); + out.print(""); out.print(""); out.print(""); if (headers != null) { @@ -457,8 +457,8 @@ public class PageTemplates { msg = sb.toString(); // > citate - msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "
$1
"); - msg = msg.replaceAll("
", "\n"); + msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "$1"); + msg = msg.replaceAll("", "\n"); msg = msg.replaceAll("\n", "
\n"); return msg; @@ -550,7 +550,7 @@ public class PageTemplates { out.print("" + msg.Replies + ""); } out.println(""); - out.println(""); + out.print(""); } } } diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java index 7ce89895..382d3be9 100644 --- a/src/java/com/juick/http/www/User.java +++ b/src/java/com/juick/http/www/User.java @@ -118,11 +118,7 @@ public class User { PrintWriter out = response.getWriter(); try { PageTemplates.pageHead(out, title, ""); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageNavigation(out, visitor, null); - } - + PageTemplates.pageNavigation(out, visitor, null); pageUserColumn(out, sql, user, visitor); if (mids.size() > 0) { @@ -151,10 +147,7 @@ public class User { out.println("
"); } - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageFooter(request, out, visitor, true); - } - + PageTemplates.pageFooter(request, out, visitor, true); PageTemplates.pageEnd(out); } finally { out.close(); @@ -172,21 +165,14 @@ public class User { PrintWriter out = response.getWriter(); try { PageTemplates.pageHead(out, "Теги " + user.UName, null); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageNavigation(out, visitor, null); - } - + PageTemplates.pageNavigation(out, visitor, null); pageUserColumn(out, sql, user, visitor); out.println("
"); out.println("

" + pageUserTags(sql, user, visitor, 0) + "

"); out.println("
"); - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageFooter(request, out, visitor, false); - } - + PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); } finally { out.close(); @@ -204,11 +190,7 @@ public class User { PrintWriter out = response.getWriter(); try { PageTemplates.pageHead(out, "Подписки " + user.UName, null); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageNavigation(out, visitor, null); - } - + PageTemplates.pageNavigation(out, visitor, null); pageUserColumn(out, sql, user, visitor); out.println("
"); @@ -238,10 +220,7 @@ public class User { out.println(""); out.println("
"); - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageFooter(request, out, visitor, false); - } - + PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); } finally { out.close(); @@ -259,11 +238,7 @@ public class User { PrintWriter out = response.getWriter(); try { PageTemplates.pageHead(out, "Читатели " + user.UName, null); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageNavigation(out, visitor, null); - } - + PageTemplates.pageNavigation(out, visitor, null); pageUserColumn(out, sql, user, visitor); out.println("
"); @@ -293,10 +268,7 @@ public class User { out.println(""); out.println("
"); - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageFooter(request, out, visitor, false); - } - + PageTemplates.pageFooter(request, out, 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 efec8899..42cb5541 100644 --- a/src/java/com/juick/http/www/UserThread.java +++ b/src/java/com/juick/http/www/UserThread.java @@ -72,20 +72,14 @@ public class UserThread { headers += ""; } PageTemplates.pageHead(out, title, headers); - - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageNavigation(out, visitor, null); - } + PageTemplates.pageNavigation(out, visitor, null); out.println("
"); printMessage(out, sql, msg, visitor); printReplies(out, sql, msg, visitor, listview); out.println("
"); - if (!Utils.isMobileRequest(request)) { - PageTemplates.pageFooter(request, out, visitor, false); - } - + PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); } finally { out.close(); diff --git a/src/java/com/juick/http/www/Utils.java b/src/java/com/juick/http/www/Utils.java index 271252c7..e20be893 100644 --- a/src/java/com/juick/http/www/Utils.java +++ b/src/java/com/juick/http/www/Utils.java @@ -88,11 +88,6 @@ public class Utils { } } - public static boolean isMobileRequest(HttpServletRequest request) { - String ua = request.getHeader("User-Agent"); - return ua != null && ua.contains(" Juick/"); - } - public static void sendTemporaryRedirect(HttpServletResponse response, String location) { response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", location); -- cgit v1.2.3