From 98f036ae01fe90ad9d5853918602b705fdd41f02 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sun, 14 Oct 2012 11:32:58 +0700 Subject: A lot of changes. --- nbproject/project.properties | 2 +- src/java/Blogs.properties | 2 +- src/java/Blogs_ru.properties | 2 +- src/java/Global.properties | 1 + src/java/Global_ru.properties | 1 + src/java/User.properties | 1 + src/java/User_ru.properties | 1 + src/java/com/juick/http/www/Blogs.java | 41 +++++--- src/java/com/juick/http/www/Chats.java | 77 -------------- src/java/com/juick/http/www/Login.java | 1 - src/java/com/juick/http/www/Main.java | 13 +-- src/java/com/juick/http/www/Map.java | 64 ------------ src/java/com/juick/http/www/NewMessage.java | 1 - src/java/com/juick/http/www/PageTemplates.java | 134 +++++++++++++++++++------ src/java/com/juick/http/www/Photos.java | 100 ------------------ src/java/com/juick/http/www/Tags.java | 87 ++++++++++++++++ src/java/com/juick/http/www/User.java | 38 +++---- src/java/com/juick/http/www/UserThread.java | 28 ++---- web/post3.js | 7 +- web/scripts3.js | 24 ++++- web/style3.css | 112 +++++++++++++-------- 21 files changed, 355 insertions(+), 382 deletions(-) delete mode 100644 src/java/com/juick/http/www/Chats.java delete mode 100644 src/java/com/juick/http/www/Map.java delete mode 100644 src/java/com/juick/http/www/Photos.java create mode 100644 src/java/com/juick/http/www/Tags.java diff --git a/nbproject/project.properties b/nbproject/project.properties index 3855d649..1b4e5382 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -30,7 +30,7 @@ includes=** j2ee.compile.on.save=true j2ee.deploy.on.save=true j2ee.platform=1.6-web -j2ee.platform.classpath=${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/ecj-3.7.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/annotations-api.jar +j2ee.platform.classpath=${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/ecj-3.7.1.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/annotations-api.jar j2ee.server.type=Tomcat jar.compress=false javac.classpath=\ diff --git a/src/java/Blogs.properties b/src/java/Blogs.properties index 3b596f77..d5c6fd26 100644 --- a/src/java/Blogs.properties +++ b/src/java/Blogs.properties @@ -7,7 +7,7 @@ Tags=Tags Search=Search My\ feed=My feed Private=Private -Incoming=Incoming +Discussions=Discussions Recommended=Recommended All\ messages=All messages Popular=Popular diff --git a/src/java/Blogs_ru.properties b/src/java/Blogs_ru.properties index f5fe415f..b42f32f5 100644 --- a/src/java/Blogs_ru.properties +++ b/src/java/Blogs_ru.properties @@ -7,7 +7,7 @@ Tags=\u0422\u0435\u0433\u0438 Search=\u041f\u043e\u0438\u0441\u043a My\ feed=\u041c\u043e\u044f \u043b\u0435\u043d\u0442\u0430 Private=\u041f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 -Incoming=\u0412\u0445\u043e\u0434\u044f\u0449\u0438\u0435 +Discussions=\u041e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f Recommended=\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043d\u043e\u0435 All\ messages=\u0412\u0441\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f Popular=\u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 diff --git a/src/java/Global.properties b/src/java/Global.properties index 9f618c91..b0e9525e 100644 --- a/src/java/Global.properties +++ b/src/java/Global.properties @@ -1,6 +1,7 @@ # To change this template, choose Tools | Templates # and open the template in the editor. +Search=Search Blogs=Blogs Chats=Chats Photos=Photos diff --git a/src/java/Global_ru.properties b/src/java/Global_ru.properties index f87f4c75..8d315dbf 100644 --- a/src/java/Global_ru.properties +++ b/src/java/Global_ru.properties @@ -1,6 +1,7 @@ # To change this template, choose Tools | Templates # and open the template in the editor. +Search=\u041f\u043e\u0438\u0441\u043a Blogs=\u0411\u043b\u043e\u0433\u0438 Chats=\u0427\u0430\u0442\u044b Photos=\u0424\u043e\u0442\u043e diff --git a/src/java/User.properties b/src/java/User.properties index b91d4352..4d54c498 100644 --- a/src/java/User.properties +++ b/src/java/User.properties @@ -15,3 +15,4 @@ Expand\ all=Expand all View\ as\ list=View as list View\ as\ tree=View as tree all=all +Search=Search diff --git a/src/java/User_ru.properties b/src/java/User_ru.properties index 3bf82875..6a257a49 100644 --- a/src/java/User_ru.properties +++ b/src/java/User_ru.properties @@ -15,3 +15,4 @@ Expand\ all=\u0420\u0430\u0441\u043a\u0440\u044b\u0442\u044c \u0432\u0441\u0435 View\ as\ list=\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043a\u043e\u043c View\ as\ tree=\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0435\u0440\u0435\u0432\u043e\u043c all=\u0432\u0441\u0435 +Search=\u041f\u043e\u0438\u0441\u043a diff --git a/src/java/com/juick/http/www/Blogs.java b/src/java/com/juick/http/www/Blogs.java index a1cfdeb0..ea728eab 100644 --- a/src/java/com/juick/http/www/Blogs.java +++ b/src/java/com/juick/http/www/Blogs.java @@ -98,10 +98,10 @@ public class Blogs { response.sendError(404); return; } - } else if (paramShow.equals("incoming")) { + } else if (paramShow.equals("discuss")) { if (visitor != null) { - title = rb.getString("Incoming"); - mids = MessagesQueries.getIncoming(sql, visitor.UID, paramBefore); + title = rb.getString("Discussions"); + mids = MessagesQueries.getDiscussions(sql, visitor.UID, paramBefore); } else { response.sendError(404); return; @@ -130,18 +130,27 @@ public class Blogs { try { PageTemplates.pageHead(out, title, null); PageTemplates.pageNavigation(out, locale, visitor); - PageTemplates.pageTitle(out, title); + out.println("
"); out.println("
"); out.println("
"); - out.println("
    "); + + PageTemplates.pageFilters(out, locale, visitor); if (mids.size() > 0) { + /* + if (paramShow != null && paramShow.equals("photos")) { + PageTemplates.printPhotos(out, sql, mids, locale); + } else { + */ + out.println("
      "); PageTemplates.printMessages(out, sql, mids, locale); + out.println("
    "); + /* + } + */ } - out.println("
"); - if (mids.size() == 20) { String nextpage = "?before=" + mids.get(mids.size() - 1); if (paramShow != null) { @@ -154,29 +163,33 @@ public class Blogs { } out.println("
"); + out.println("
"); // wrapper + - out.println("
"); + out.println("
"); out.println("

" + rb.getString("Lists") + "

"); if (visitor != null) { out.println(""); + out.println("
"); } out.println(""); - out.println("

" + rb.getString("Tags") + "

"); - out.println("

" + getTags(sql, 30) + "

"); - out.println("

" + rb.getString("Search") + "

"); - out.println("

"); - out.println("
"); + out.println("
"); + out.println("

" + getTags(sql, 30) + "

"); out.println("
"); + out.println("
"); + + out.println("
"); // topwrapper + PageTemplates.pageFooter(request, out, locale, visitor); } finally { out.close(); diff --git a/src/java/com/juick/http/www/Chats.java b/src/java/com/juick/http/www/Chats.java deleted file mode 100644 index d15bb271..00000000 --- a/src/java/com/juick/http/www/Chats.java +++ /dev/null @@ -1,77 +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 java.io.IOException; -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -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 Chats { - - protected void doGet(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("Chats", locale); - - response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { - PageTemplates.pageHead(out, rb.getString("Active chats"), ""); - PageTemplates.pageNavigation(out, locale, visitor); - PageTemplates.pageTitle(out, rb.getString("Active chats")); - - out.println("
"); - out.println("
    "); - - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT chats.chat_id,chats.subject,COUNT(chat_users.user_id) AS cnt FROM chats INNER JOIN chat_users USING(chat_id) GROUP BY chat_id ORDER BY cnt DESC"); - rs = stmt.executeQuery(); - rs.beforeFirst(); - while (rs.next()) { - String chatid = Integer.toString(rs.getInt(1), Character.MAX_RADIX); - out.println("
  • " + Utils.encodeHTML(rs.getString(2)) + "
    " + rb.getString("Users online") + ": " + rs.getInt(3) + "
    " + chatid + "@chat.juick.com
  • "); - } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - - out.println("
"); - out.println("
"); - - PageTemplates.pageFooter(request, out, locale, visitor); - } finally { - out.close(); - } - } -} diff --git a/src/java/com/juick/http/www/Login.java b/src/java/com/juick/http/www/Login.java index 0006f9d0..3cf4a318 100644 --- a/src/java/com/juick/http/www/Login.java +++ b/src/java/com/juick/http/www/Login.java @@ -45,7 +45,6 @@ public class Login { try { PageTemplates.pageHead(out, rb.getString("Login"), ""); PageTemplates.pageNavigation(out, locale, visitor); - PageTemplates.pageTitle(out, rb.getString("Login")); out.println("
"); out.println("
"); diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java index 256e70f9..055327dd 100644 --- a/src/java/com/juick/http/www/Main.java +++ b/src/java/com/juick/http/www/Main.java @@ -42,10 +42,8 @@ public class Main extends HttpServlet implements XmppListener { Connection sqlSearch; XmppConnection xmpp; Blogs blogs = new Blogs(); - Chats chats = new Chats(); - Photos photos = new Photos(); + Tags tags = new Tags(); RootRedirects rootRedirects = new RootRedirects(); - Map map = new Map(); Login login = new Login(); User pagesUser = new User(); UserThread pagesUserThread = new UserThread(); @@ -124,12 +122,9 @@ public class Main extends HttpServlet implements XmppListener { String uri = request.getRequestURI(); if (uri.equals("/")) { blogs.doGet(sql, sqlSearch, request, response); - } else if (uri.equals("/chats")) { - chats.doGet(sql, request, response); - } else if (uri.equals("/photos")) { - photos.doGet(sql, request, response); - } else if (uri.equals("/map")) { - map.doGet(sql, request, response); + } else if (uri.equals("/tags")) { + com.juick.User visitor = Utils.getVisitorUser(sql, request); + tags.doGetTags(sql, request, response, visitor); } else if (uri.equals("/post")) { com.juick.User visitor = Utils.getVisitorUser(sql, request); if (visitor != null) { diff --git a/src/java/com/juick/http/www/Map.java b/src/java/com/juick/http/www/Map.java deleted file mode 100644 index 96524ac0..00000000 --- a/src/java/com/juick/http/www/Map.java +++ /dev/null @@ -1,64 +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 java.io.IOException; -import java.io.PrintWriter; -import java.sql.Connection; -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 Map { - - protected void doGet(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("Map", locale); - - response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { - PageTemplates.pageHead(out, rb.getString("Messages on map"), "" - + "" - + ""); - PageTemplates.pageNavigation(out, locale, visitor); - PageTemplates.pageTitle(out, rb.getString("Messages on map")); - - out.println("
"); - out.println("
"); - out.println("
    "); - out.println("

    " + rb.getString("Popular places") + "

      "); - out.println("
      "); - out.println(""); - - PageTemplates.pageFooter(request, out, locale, visitor); - } finally { - out.close(); - } - } -} diff --git a/src/java/com/juick/http/www/NewMessage.java b/src/java/com/juick/http/www/NewMessage.java index 1efb753d..1e00a553 100644 --- a/src/java/com/juick/http/www/NewMessage.java +++ b/src/java/com/juick/http/www/NewMessage.java @@ -49,7 +49,6 @@ public class NewMessage { + "" + ""); PageTemplates.pageNavigation(out, locale, visitor); - PageTemplates.pageTitle(out, rbnm.getString("New message")); out.println("
      "); out.println("
      "); diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index a76e0280..08e88342 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -24,7 +24,11 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.Locale; import java.util.ResourceBundle; import java.util.regex.Matcher; @@ -39,6 +43,9 @@ import ru.sape.Sape; public class PageTemplates { public static Sape sape = null; + private static SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); + private static SimpleDateFormat sdfSimple = new SimpleDateFormat("d MMM"); + private static SimpleDateFormat sdfFull = new SimpleDateFormat("d MMM yyyy"); public static void pageHead(PrintWriter out, String title, String headers) { out.println(""); @@ -46,10 +53,10 @@ public class PageTemplates { out.println(""); out.println(" "); out.println(" " + title + ""); - out.println(" "); + out.println(" "); out.println(" "); - out.println(" "); - out.println(" "); + out.println(" "); + out.println(" "); out.println(" "); out.println(" "); out.println(" "); @@ -63,18 +70,16 @@ public class PageTemplates { public static void pageNavigation(PrintWriter out, Locale loc, com.juick.User user) { ResourceBundle rb = ResourceBundle.getBundle("Global", loc); + out.println("
      "); out.println("
      "); - out.println("
      \"Juick\"/
      "); - out.println(" "); + out.println("
      \"Juick\"/
      "); + out.println(" "); + out.println("
      \">
      "); + out.println(" "); out.println("
      "); + out.println("
      "); } - public static void pageTitle(PrintWriter out, String title) { - out.println("
      "); - out.println("

      " + title + "

      "); + public static void pageFilters(PrintWriter out, Locale loc, com.juick.User user) { + ResourceBundle rb = ResourceBundle.getBundle("Global", loc); + + out.println("
      "); + out.println(""); out.println("
      "); } @@ -236,7 +251,19 @@ public class PageTemplates { int days = (minsago / 1440); return days + " day" + ((days % 10 == 1) ? "" : "s") + " ago"; } else { - return fulldate; + try { + Date pDate = sdfSQL.parse(fulldate); + Calendar c = Calendar.getInstance(); + int curyear = c.get(Calendar.YEAR); + c.setTime(pDate); + if (c.get(Calendar.YEAR) == curyear) { + return sdfSimple.format(pDate); + } else { + return sdfFull.format(pDate); + } + } catch (ParseException e) { + return fulldate; + } } } @@ -355,11 +382,11 @@ public class PageTemplates { txt = formatMessage(txt); - out.print("
    • "); + out.println("
    • "); + out.println("
      \""
      "); + out.println(" "); + out.println("
      @" + uname + ":" + tags + "
      "); + out.println("
      " + txt + "
      "); if (rs.getString(12) != null) { if (rs.getString(12).equals("jpg")) { @@ -372,15 +399,6 @@ public class PageTemplates { } } - out.println("
      \""
      "); - out.println(" "); - out.println("
      @" + uname + ":" + tags + "
      "); - out.println("
      " + txt + "
      "); - if (rs.getInt(10) > 0) { String repliesby = rs.getString(11); if (repliesby == null) { @@ -389,7 +407,7 @@ public class PageTemplates { out.println("
      " + formatReplies(rs.getInt(10), locale) + " " + rb.getString("(replies) by") + " " + repliesby + "
      "); } else if (cancomment) { out.println("
      "); - out.println("
      "); + out.println("
      "); out.println("
      "); } out.println("
    • "); @@ -400,4 +418,60 @@ public class PageTemplates { Utils.finishSQL(rs, stmt); } } + /* + public static void printPhotos(PrintWriter out, Connection sql, ArrayList mids, Locale locale) { + ResourceBundle rb = ResourceBundle.getBundle("Global", locale); + + out.println(""); + out.println(" "); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT STRAIGHT_JOIN messages.message_id,messages.user_id,users.nick,messages_txt.tags,messages.readonly,messages.privacy,messages_txt.txt,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),messages.ts,messages.replies,messages_txt.repliesby,messages.attach,messages.place_id,places.name,messages.lat,messages.lon FROM ((messages INNER JOIN messages_txt ON messages.message_id=messages_txt.message_id) INNER JOIN users ON messages.user_id=users.id) LEFT JOIN places ON messages.place_id=places.place_id WHERE messages.message_id IN (" + Utils.convertArray2String(mids) + ") ORDER BY messages.message_id DESC"); + rs = stmt.executeQuery(); + rs.beforeFirst(); + int cnt = 0; + while (rs.next()) { + int mid = rs.getInt(1); + int uid = rs.getInt(2); + String uname = rs.getString(3); + String tags = rs.getString(4); + String txt = rs.getString(7); + + txt = formatMessage(txt); + + if (cnt % 2 == 0 && cnt > 0) { + out.println(" "); + out.println(" "); + } + + out.print(" "); + + cnt++; + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + out.println(" "); + out.println("
      "); + + out.println("
      "); + out.println(" \"\"/"); + out.println("
      " + formatDate(rs.getInt(8), rs.getString(9), locale) + "
      "); + out.println("
      @" + uname + "
      "); + if (rs.getInt(10) > 0) { + out.println("
      " + rs.getInt(10) + "
      "); + } + out.println("
      " + txt + "
      "); + out.println("
      "); + } + */ } diff --git a/src/java/com/juick/http/www/Photos.java b/src/java/com/juick/http/www/Photos.java deleted file mode 100644 index a2665501..00000000 --- a/src/java/com/juick/http/www/Photos.java +++ /dev/null @@ -1,100 +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 java.io.IOException; -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -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 Photos { - - protected void doGet(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("Photos", locale); - - response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { - PageTemplates.pageHead(out, rb.getString("Last photos and videos"), "" - + "" - + "" - + ""); - PageTemplates.pageNavigation(out, locale, visitor); - PageTemplates.pageTitle(out, rb.getString("Last photos and videos")); - - out.println("
      "); - out.println("
      Loading...
      "); - out.println("
        "); - - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT messages.message_id,messages.attach,users.nick FROM messages INNER JOIN users ON messages.user_id=users.id WHERE messages.attach IS NOT NULL ORDER BY message_id DESC LIMIT 20"); - rs = stmt.executeQuery(); - rs.beforeFirst(); - while (rs.next()) { - if (rs.getString(2).equals("jpg")) { - out.println("
      • \"\"
      • "); - } else { - out.println("
      • \"\"
      • "); - } - } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - - out.println("
      "); - out.println("
      "); - out.println(""); - - PageTemplates.pageFooter(request, out, locale, visitor); - } finally { - out.close(); - } - } -} diff --git a/src/java/com/juick/http/www/Tags.java b/src/java/com/juick/http/www/Tags.java new file mode 100644 index 00000000..07cff582 --- /dev/null +++ b/src/java/com/juick/http/www/Tags.java @@ -0,0 +1,87 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.juick.http.www; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.Locale; +import java.util.ResourceBundle; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author ugnich + */ +public class Tags { + + protected void doGetTags(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException { + Locale locale = request.getLocale(); + ResourceBundle rbnm = ResourceBundle.getBundle("Blogs", locale); + + response.setContentType("text/html; charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + PageTemplates.pageHead(out, rbnm.getString("Tags"), null); + PageTemplates.pageNavigation(out, locale, visitor); + + int cnt = 30; + com.juick.Tag tags[] = new com.juick.Tag[cnt]; + int maxUsageCnt = 0; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT tags.name AS name,COUNT(DISTINCT messages.user_id) AS cnt FROM (messages INNER JOIN messages_tags ON (messages.ts>TIMESTAMPADD(DAY,-3,NOW()) AND messages.message_id=messages_tags.message_id)) INNER JOIN tags ON messages_tags.tag_id=tags.tag_id GROUP BY tags.tag_id ORDER BY cnt DESC LIMIT ?"); + stmt.setInt(1, cnt); + rs = stmt.executeQuery(); + rs.beforeFirst(); + cnt = 0; + while (rs.next()) { + tags[cnt] = new com.juick.Tag(); + tags[cnt].Name = rs.getString(1); + tags[cnt].UsageCnt = rs.getInt(2); + if (tags[cnt].UsageCnt > maxUsageCnt) { + maxUsageCnt = tags[cnt].UsageCnt; + } + cnt++; + } + } catch (SQLException e) { + System.err.println(e); + } 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 = "" + tag + ""; + } catch (UnsupportedEncodingException e) { + } + + if (tags[i].UsageCnt > maxUsageCnt / 3 * 2) { + out.print("" + tag + " "); + } else if (tags[i].UsageCnt > maxUsageCnt / 3) { + out.print("" + tag + " "); + } else { + out.print(tag + " "); + } + } + + PageTemplates.pageFooter(request, out, locale, visitor); + } finally { + out.close(); + } + } +} diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java index 73dd5827..0ddac42d 100644 --- a/src/java/com/juick/http/www/User.java +++ b/src/java/com/juick/http/www/User.java @@ -100,6 +100,7 @@ public class User { PageTemplates.pageNavigation(out, locale, visitor); PageTemplates.pageUserTitle(out, sql, locale, user, visitor); + out.println("
      "); out.println("
      "); out.println("
      "); out.println("
        "); @@ -122,6 +123,7 @@ public class User { pageUserColumn(out, sql, user, visitor, locale); out.println("
      "); + out.println("
      "); // topwrapper PageTemplates.pageFooter(request, out, locale, visitor); } finally { @@ -146,11 +148,7 @@ public class User { out.println("
      "); out.println("
      "); - - out.print("

      "); - pageUserTags(out, sql, user, visitor, 0); - out.print("

      "); - + out.println("

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

      "); out.println("
      "); pageUserColumn(out, sql, user, visitor, locale); out.println("
      "); @@ -219,7 +217,7 @@ public class User { try { PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Stats) I read"), null); PageTemplates.pageNavigation(out, locale, visitor); - PageTemplates.pageUserTitle(out, sql, locale, user, visitor); + //PageTemplates.pageUserTitle(out, sql, locale, user, visitor); out.println("
      "); out.println("
      "); @@ -260,21 +258,21 @@ public class User { public static void pageUserColumn(PrintWriter out, Connection sql, com.juick.User user, com.juick.User visitor, Locale locale) { ResourceBundle rb = ResourceBundle.getBundle("User", locale); - out.println("
      "); - out.println("

      " + rb.getString("(Menu) Messages") + "

      "); + out.println("
      "); out.println(""); - out.println("

      " + rb.getString("(Menu) Tags") + " " + rb.getString("all") + "

      "); - pageUserTags(out, sql, user, visitor, 15); - out.println("

      " + rb.getString("(Menu) Search") + "

      "); - out.println("

      "); + out.println("
      "); + out.println("

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

      "); + out.println("
      "); + out.println("

      "); + out.println("
      "); out.println("
      "); } - public static void pageUserTags(PrintWriter out, Connection sql, com.juick.User user, com.juick.User visitor, int cnt) { + public static String pageUserTags(Connection sql, com.juick.User user, com.juick.User visitor, int cnt) { com.juick.Tag tags[] = null; int maxUsageCnt = 0; @@ -313,6 +311,7 @@ public class User { Arrays.sort(tags, 0, cnt); } + String ret = ""; for (int i = 0; i < cnt; i++) { String tag = Utils.encodeHTML(tags[i].Name); try { @@ -321,12 +320,13 @@ public class User { } if (tags[i].UsageCnt > maxUsageCnt / 3 * 2) { - out.print("" + tag + " "); + ret += "" + tag + " "; } else if (tags[i].UsageCnt > maxUsageCnt / 3) { - out.print("" + tag + " "); + ret += "" + tag + " "; } else { - out.print(tag + " "); + ret += tag + " "; } } + return ret; } } diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java index e64b4437..1680ca8e 100644 --- a/src/java/com/juick/http/www/UserThread.java +++ b/src/java/com/juick/http/www/UserThread.java @@ -71,7 +71,7 @@ public class UserThread { PageTemplates.pageNavigation(out, locale, visitor); PageTemplates.pageUserTitle(out, sql, locale, user, visitor); - + out.println("
      "); out.println("
      "); out.println("
      "); @@ -80,8 +80,8 @@ public class UserThread { printReplies(out, sql, MID, locale, listview); out.println("
      "); - out.println("
      "); + out.println("
      "); // topwrapper out.println("