aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/java/com/juick/http/www/Blogs.java53
-rw-r--r--src/java/com/juick/http/www/Main.java6
-rw-r--r--src/java/com/juick/http/www/NewMessage.java8
-rw-r--r--src/java/com/juick/http/www/PageTemplates.java14
-rw-r--r--src/java/com/juick/http/www/Tags.java87
-rw-r--r--src/java/com/juick/http/www/User.java2
-rw-r--r--src/java/com/juick/http/www/UserThread.java6
7 files changed, 48 insertions, 128 deletions
diff --git a/src/java/com/juick/http/www/Blogs.java b/src/java/com/juick/http/www/Blogs.java
index 0250a1577..fb0657ad2 100644
--- a/src/java/com/juick/http/www/Blogs.java
+++ b/src/java/com/juick/http/www/Blogs.java
@@ -22,6 +22,7 @@ import com.juick.server.TagQueries;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -42,6 +43,16 @@ import javax.servlet.http.HttpServletResponse;
public class Blogs {
protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response) 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);
+ }
+
com.juick.User visitor = Utils.getVisitorUser(sql, request);
Locale locale = request.getLocale();
ResourceBundle rb = ResourceBundle.getBundle("Blogs", locale);
@@ -52,9 +63,14 @@ public class Blogs {
String paramShow = request.getParameter("show");
int paramTag = 0;
- String paramTagStr = request.getParameter("tag");
- if (paramTagStr != null && paramTagStr.length() < 64) {
+ String paramTagStr = null;
+ if (request.getRequestURI().startsWith("/tag/")) {
+ paramTagStr = URLDecoder.decode(request.getRequestURI().substring(5), "UTF-8");
paramTag = TagQueries.getTagID(sql, paramTagStr, false);
+ if (paramTag == 0) {
+ response.sendError(404);
+ return;
+ }
}
int paramBefore = 0;
@@ -135,20 +151,10 @@ public class Blogs {
out.println("<div id=\"wrapper\">");
out.println("<div id=\"content\">");
- //PageTemplates.pageFilters(out, locale, visitor);
-
if (mids.size() > 0) {
- /*
- if (paramShow != null && paramShow.equals("photos")) {
- PageTemplates.printPhotos(out, sql, mids, locale);
- } else {
- */
out.println("<ul>");
- PageTemplates.printMessages(out, sql, mids, visitor, locale);
+ PageTemplates.printMessages(out, sql, null, mids, visitor, locale);
out.println("</ul>");
- /*
- }
- */
}
if (mids.size() == 20) {
@@ -156,9 +162,6 @@ public class Blogs {
if (paramShow != null) {
nextpage += "&amp;show=" + paramShow;
}
- if (paramTag > 0) {
- nextpage += "&amp;tag=" + URLEncoder.encode(paramTagStr, "UTF-8");
- }
out.println("<p class=\"page\"><a href=\"" + nextpage + "\">Older →</a></p>");
}
@@ -169,20 +172,20 @@ public class Blogs {
out.println("<div id=\"column\" class=\"stickya\">");
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(" <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=\"/\">" + 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(" </ul>");
out.println(" <hr/>");
- out.println(" <p>" + getTags(sql, 30) + "</p>");
+ out.println(" <p>" + getTags(sql, 36) + "</p>");
out.println("</div>");
out.println("<div id=\"rcol\"></div>");
@@ -229,7 +232,7 @@ public class Blogs {
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>";
+ tag = "<a href=\"/tag/" + URLEncoder.encode(tags[i].Name, "UTF-8") + "\">" + tag + "</a>";
} catch (UnsupportedEncodingException e) {
}
diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java
index 208859066..ee601eded 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 = new Blogs();
- Tags tags = new Tags();
RootRedirects rootRedirects = new RootRedirects();
Login login = new Login();
Help help = new Help();
@@ -123,9 +122,6 @@ public class Main extends HttpServlet implements XmppListener {
String uri = request.getRequestURI();
if (uri.equals("/")) {
blogs.doGet(sql, sqlSearch, 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) {
@@ -147,6 +143,8 @@ public class Main extends HttpServlet implements XmppListener {
help.doRedirectToHelpIndex(sql, request, response);
} else if (uri.startsWith("/help/")) {
help.doGetHelp(sql, request, response);
+ } else if (uri.startsWith("/tag/")) {
+ blogs.doGet(sql, sqlSearch, request, response);
} else if (uri.matches("^/\\d+$")) {
rootRedirects.doGetPostID(sql, request, response);
} else if (uri.matches("^/[^/]+$")) {
diff --git a/src/java/com/juick/http/www/NewMessage.java b/src/java/com/juick/http/www/NewMessage.java
index 40ffeb463..9ca7e7ed9 100644
--- a/src/java/com/juick/http/www/NewMessage.java
+++ b/src/java/com/juick/http/www/NewMessage.java
@@ -72,7 +72,7 @@ public class NewMessage {
out.println("</form>");
out.println("<div id=\"geomap\"></div>");
out.println("<p style=\"text-align: left\"><b>" + rbnm.getString("Tags") + ":</b></p>");
- printUserTags(sql, out, visitor.UID);
+ printUserTags(sql, out, visitor);
out.println("</div>");
out.println("</div>");
@@ -82,8 +82,8 @@ public class NewMessage {
}
}
- void printUserTags(Connection sql, PrintWriter out, int uid) {
- ArrayList<Tag> tags = TagQueries.getUserTagsAll(sql, uid);
+ void printUserTags(Connection sql, PrintWriter out, com.juick.User visitor) {
+ ArrayList<Tag> tags = TagQueries.getUserTagsAll(sql, visitor.UID);
if (tags.isEmpty()) {
return;
@@ -109,7 +109,7 @@ public class NewMessage {
}
String taglink = "";
try {
- taglink = "<a onclick=\"return addTag('" + Utils.encodeHTML(tags.get(i).Name) + "')\" href=\"/?tag=" + URLEncoder.encode(tags.get(i).Name, "utf-8") + "\" title=\"" + tags.get(i).UsageCnt + "\">" + Utils.encodeHTML(tags.get(i).Name) + "</a>";
+ taglink = "<a onclick=\"return addTag('" + Utils.encodeHTML(tags.get(i).Name) + "')\" href=\"/" + visitor.UName + "/?tag=" + URLEncoder.encode(tags.get(i).Name, "utf-8") + "\" title=\"" + tags.get(i).UsageCnt + "\">" + Utils.encodeHTML(tags.get(i).Name) + "</a>";
} catch (UnsupportedEncodingException e) {
}
int usagecnt = tags.get(i).UsageCnt;
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java
index 5032cbf5a..4e4993440 100644
--- a/src/java/com/juick/http/www/PageTemplates.java
+++ b/src/java/com/juick/http/www/PageTemplates.java
@@ -179,14 +179,20 @@ public class PageTemplates {
out.println("</div></div>");
}
- public static String formatTags(ArrayList<String> tags) {
+ public static String formatTags(ArrayList<String> tags, com.juick.User user) {
String ret = "";
for (int i = 0; i < tags.size(); i++) {
String tag = tags.get(i);
tag = tag.replaceAll("<", "&lt;");
tag = tag.replaceAll(">", "&gt;");
try {
- ret += " *<a href=\"/?tag=" + URLEncoder.encode(tags.get(i), "utf-8") + "\">" + tag + "</a>";
+ ret += " *<a href=\"";
+ if (user == null) {
+ ret += "/tag/";
+ } else {
+ ret += "./?tag=";
+ }
+ ret += URLEncoder.encode(tags.get(i), "utf-8") + "\">" + tag + "</a>";
} catch (UnsupportedEncodingException e) {
}
}
@@ -304,7 +310,7 @@ public class PageTemplates {
return msg;
}
- public static void printMessages(PrintWriter out, Connection sql, ArrayList<Integer> mids, com.juick.User visitor, Locale locale) {
+ public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, ArrayList<Integer> mids, com.juick.User visitor, Locale locale) {
ResourceBundle rb = ResourceBundle.getBundle("Global", locale);
ArrayList<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids);
@@ -320,7 +326,7 @@ public class PageTemplates {
for (int i = 0; i < msgs.size(); i++) {
com.juick.Message msg = msgs.get(i);
- String tags = msg.Tags.isEmpty() ? "" : formatTags(msg.Tags);
+ String tags = msg.Tags.isEmpty() ? "" : formatTags(msg.Tags, user);
if (msg.ReadOnly) {
tags += " *readonly";
}
diff --git a/src/java/com/juick/http/www/Tags.java b/src/java/com/juick/http/www/Tags.java
deleted file mode 100644
index 534ca8efa..000000000
--- a/src/java/com/juick/http/www/Tags.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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 WHERE tags.tag_id NOT IN (SELECT tag_id FROM tags_ignore) 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 = "<a href=\"/?tag=" + URLEncoder.encode(tags[i].Name, "UTF-8") + "\">" + tag + "</a>";
- } catch (UnsupportedEncodingException e) {
- }
-
- if (tags[i].UsageCnt > maxUsageCnt / 3 * 2) {
- out.print("<big>" + tag + "</big> ");
- } else if (tags[i].UsageCnt > maxUsageCnt / 3) {
- out.print("<small>" + tag + "</small> ");
- } 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 d8c179b50..b60afd0e1 100644
--- a/src/java/com/juick/http/www/User.java
+++ b/src/java/com/juick/http/www/User.java
@@ -106,7 +106,7 @@ public class User {
out.println("<div id=\"content\">");
out.println("<ul>");
if (mids.size() > 0) {
- PageTemplates.printMessages(out, sql, mids, visitor, locale);
+ PageTemplates.printMessages(out, sql, user, mids, visitor, locale);
}
out.println("</ul>");
diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java
index c796767af..dcdb66da9 100644
--- a/src/java/com/juick/http/www/UserThread.java
+++ b/src/java/com/juick/http/www/UserThread.java
@@ -72,7 +72,7 @@ public class UserThread {
out.println("<div id=\"wrapper\">");
out.println("<div id=\"content\" style=\"margin-left: 0; width: 100%\">");
- com.juick.Message msg = printMessage(out, sql, MID, visitor, locale);
+ com.juick.Message msg = printMessage(out, sql, user, MID, visitor, locale);
printReplies(out, sql, msg, visitor, locale, listview);
out.println("</div>");
@@ -86,7 +86,7 @@ public class UserThread {
}
}
- public static com.juick.Message printMessage(PrintWriter out, Connection sql, int mid, com.juick.User visitor, Locale locale) {
+ public static com.juick.Message printMessage(PrintWriter out, Connection sql, com.juick.User user, int mid, com.juick.User visitor, Locale locale) {
ResourceBundle rb = ResourceBundle.getBundle("Global", locale);
ResourceBundle rbthread = ResourceBundle.getBundle("UserThread", locale);
@@ -94,7 +94,7 @@ public class UserThread {
msg.VisitorCanComment = visitor != null;
- String tags = (msg.Tags.isEmpty()) ? "" : PageTemplates.formatTags(msg.Tags);
+ String tags = (msg.Tags.isEmpty()) ? "" : PageTemplates.formatTags(msg.Tags, user);
if (msg.ReadOnly) {
tags += " *readonly";
msg.VisitorCanComment = false;