aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/juick/http/www/PageTemplates.java
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2014-01-27 05:59:17 +0700
committerGravatar Ugnich Anton2014-01-27 05:59:17 +0700
commit3b388f8b3add54e794bd37172a6973e69a55778d (patch)
tree557ad56c8544302dfb97ef6cb2dbfff0e3582430 /src/java/com/juick/http/www/PageTemplates.java
parenta5b5fe42c3ccef860ac56527dfcb79a3a0ecbfa4 (diff)
- discover, pageHomeColumn
Diffstat (limited to 'src/java/com/juick/http/www/PageTemplates.java')
-rw-r--r--src/java/com/juick/http/www/PageTemplates.java82
1 files changed, 78 insertions, 4 deletions
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java
index 3718bc9e..f1a1b29d 100644
--- a/src/java/com/juick/http/www/PageTemplates.java
+++ b/src/java/com/juick/http/www/PageTemplates.java
@@ -23,8 +23,12 @@ 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.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
@@ -45,14 +49,15 @@ public class PageTemplates {
private static SimpleDateFormat sdfSimple = new SimpleDateFormat("d MMM");
private static SimpleDateFormat sdfFull = new SimpleDateFormat("d MMM yyyy");
private static SimpleDateFormat sdfJS = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss");
+ private static String tagsHTML = null;
public static void pageHead(PrintWriter out, String title, String headers) {
out.println("<!DOCTYPE html>");
out.print("<html>");
out.print("<head>");
- out.print("<link rel=\"stylesheet\" href=\"/style.2013120400.css\"/>");
+ out.print("<link rel=\"stylesheet\" href=\"/style.2014012700.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=\"/scripts.2013120801.js\" defer=\"defer\"></script>");
+ out.print("<script type=\"text/javascript\" src=\"/scripts.2014012700.js\" defer=\"defer\"></script>");
if (headers != null) {
out.print(headers);
}
@@ -70,12 +75,11 @@ public class PageTemplates {
out.println("<ul id=\"header\">");
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") + "\"");
+ out.print(" <li id=\"search\"><form action=\"/\"><input type=\"text\" name=\"search\" class=\"text\" placeholder=\"" + rb.getString("Search") + "\"");
if (search != null) {
out.print(" value=\"" + Utils.encodeHTML(search) + "\"");
}
@@ -166,6 +170,76 @@ public class PageTemplates {
out.println("</script>");
}
+ public static void pageHomeColumn(PrintWriter out, Connection sql, Locale locale) {
+ ResourceBundle rb = ResourceBundle.getBundle("Blogs", locale);
+
+ if (tagsHTML == null) {
+ tagsHTML = PageTemplates.getPopularTags(sql, 60);
+ }
+
+ out.println("<div id=\"column\" class=\"abs\">");
+ out.println(" <ul>");
+ out.println(" <li><a href=\"/\">" + rb.getString("My feed") + "</a></li>");
+ out.println(" <li><a href=\"/pm/inbox\">" + rb.getString("Private") + "</a> ยท <a href=\"/pm/sent\">" + rb.getString("Private sent") + "</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(" <li><a href=\"/?show=all\">" + rb.getString("All messages") + "</a></li>");
+ out.println(" </ul>");
+ out.println(" <hr/>");
+ out.println(" <p>" + tagsHTML + "</p>");
+ out.println("</div>");
+ }
+
+ public static String getPopularTags(Connection sql, int cnt) {
+ String ret = "";
+ 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(MONTH,-1,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) {
+ ret += "<big>" + tag + "</big> ";
+ } else if (tags[i].UsageCnt > maxUsageCnt / 3) {
+ ret += "<small>" + tag + "</small> ";
+ } else {
+ ret += tag + " ";
+ }
+ }
+
+ return ret;
+ }
+
public static void pageDialogTemplate(PrintWriter out, Locale locale) {
ResourceBundle rb = ResourceBundle.getBundle("Global", locale);
out.println("<div id=\"dialogb\" onclick=\"$('#dialogb').hide();$('#dialogw').hide()\"></div>");