diff options
Diffstat (limited to 'src/java/com/juick/http')
-rw-r--r-- | src/java/com/juick/http/www/PageTemplates.java | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index e9de8edb..169cec8d 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -146,25 +146,22 @@ public class PageTemplates { 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); + stmt = sql.prepareStatement("SELECT name FROM tags WHERE top=1 ORDER BY name ASC"); 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; + if (!ret.isEmpty()) { + ret += " "; } - cnt++; + try { + ret += "<a href=\"/tag/" + URLEncoder.encode(rs.getString(1), "UTF-8") + "\">" + Utils.encodeHTML(rs.getString(1)) + "</a>"; + } catch (UnsupportedEncodingException e) { + } + } } catch (SQLException e) { System.err.println(e); @@ -172,24 +169,6 @@ public class PageTemplates { 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; } |