From 6856f7278584425b0cb6fc54d50f5d5cf4a3f88e Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Tue, 29 Jul 2014 17:50:17 +0700 Subject: formatTags --- src/java/com/juick/http/www/PageTemplates.java | 114 ++++++++++++++----------- 1 file changed, 64 insertions(+), 50 deletions(-) (limited to 'src/java/com/juick/http') diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index f0a87c42..afffc334 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -40,13 +40,13 @@ import ru.sape.Sape; * @author Ugnich Anton */ public class PageTemplates { - + public static Sape sape = null; private static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static SimpleDateFormat sdfSimple = new SimpleDateFormat("d MMM"); private static SimpleDateFormat sdfFull = new SimpleDateFormat("d MMM yyyy"); private static String tagsHTML = null; - + public static void pageHead(PrintWriter out, String title, String headers) { out.println(""); out.print(""); @@ -67,7 +67,7 @@ public class PageTemplates { out.flush(); out.println(""); } - + public static void pageNavigation(PrintWriter out, com.juick.User visitor, String search) { out.println("
"); out.println("
Juick
"); @@ -100,7 +100,7 @@ public class PageTemplates { out.println(" "); out.println("
"); } - + public static void pageYandexAd728(PrintWriter out, int YandexID) { /* out.println("
"); @@ -137,12 +137,12 @@ public class PageTemplates { out.println("(adsbygoogle = window.adsbygoogle || []).push({})"); out.println(""); } - + public static void pageHomeColumn(PrintWriter out, Connection sql, com.juick.User visitor) { if (tagsHTML == null) { tagsHTML = PageTemplates.getPopularTags(sql, 80); } - + out.println(""); } - + public static String getPopularTags(Connection sql, int cnt) { String ret = ""; - + PreparedStatement stmt = null; ResultSet rs = null; try { @@ -168,23 +168,23 @@ public class PageTemplates { ret += "" + Utils.encodeHTML(rs.getString(1)) + ""; } catch (UnsupportedEncodingException e) { } - + } } catch (SQLException e) { System.err.println(e); } finally { Utils.finishSQL(rs, stmt); } - + return ret; } - + public static void printContestRating(PrintWriter out, Connection sql) { out.println("
"); out.println(""); out.println("

Кто выиграет iPod?

"); out.println(""); - + int i = 0; PreparedStatement stmt = null; ResultSet rs = null; @@ -206,11 +206,11 @@ public class PageTemplates { } finally { Utils.finishSQL(rs, stmt); } - + out.println("
"); out.println(""); } - + public static void pageFooter(HttpServletRequest request, PrintWriter out, com.juick.User visitor, boolean sapeon) { out.println("
"); out.println("
Настройки · Контакты · Справка · Реклама
"); @@ -220,7 +220,7 @@ public class PageTemplates { out.print("Facebook"); out.println("
"); out.print("
juick.com © 2008-2014"); - + String queryString = request.getQueryString(); String requestURI = request.getRequestURI(); if (sapeon && sape != null && (visitor == null || visitor.UID == 1) && queryString == null) { @@ -232,16 +232,16 @@ public class PageTemplates { if ((visitor == null || visitor.UID == 1) && queryString != null && requestURI != null && requestURI.equals("/")) { out.print("
сиам"); } - + out.println("
"); out.println(""); - + if (visitor != null) { out.println(""); } - + out.println(""); } - + public static void pageEnd(PrintWriter out) { out.println(""); } - + + public static String formatTags(ArrayList tags) { + String ret = ""; + for (int i = 0; i < tags.size(); i++) { + com.juick.Tag tag = tags.get(i); + String tagName = tag.Name.replaceAll("<", "<").replaceAll(">", ">"); + if (tag.UsageCnt > 1) { + try { + ret += " *" + tagName + ""; + } catch (UnsupportedEncodingException e) { + } + } else { + ret += " *" + tagName; + } + } + + return ret; + } + public static String formatTags(ArrayList tags, com.juick.User user) { String ret = ""; for (int i = 0; i < tags.size(); i++) { @@ -283,10 +301,10 @@ public class PageTemplates { } catch (UnsupportedEncodingException e) { } } - + return ret; } - + public static String formatDate(int minutes, String fulldate) { if (minutes < 1) { return "сейчас"; @@ -345,7 +363,7 @@ public class PageTemplates { return ret; } } - + public static String formatJSLocalTime(String ts) { String ret = ""; synchronized (sdfSQL) { @@ -361,7 +379,7 @@ public class PageTemplates { } return ret; } - + public static String formatReplies(int replies) { int ld = replies % 10; int lh = replies % 100; @@ -374,7 +392,7 @@ public class PageTemplates { } } private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?" + msg + ""; } - + public static String formatMessage(String msg) { msg = msg.replaceAll("&", "&"); msg = msg.replaceAll("<", "<"); @@ -462,14 +480,14 @@ public class PageTemplates { // > citate msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))", "
$1
"); msg = msg.replaceAll("
", "\n"); - + msg = msg.replaceAll("\n", "
\n"); return msg; } - + public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, ArrayList mids, com.juick.User visitor, int YandexID, int ad_mid) { ArrayList msgs = MessagesQueries.getMessages(sql, mids); - + for (int i = 0; i < msgs.size(); i++) { com.juick.Message msg = msgs.get(i); if (msg.MID == ad_mid) { @@ -478,7 +496,7 @@ public class PageTemplates { break; } } - + ArrayList blUIDs = new ArrayList(20); if (visitor != null) { for (int i = 0; i < msgs.size(); i++) { @@ -486,41 +504,37 @@ public class PageTemplates { } blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs); } - + for (int i = 0; i < msgs.size(); i++) { - + if (i == 0 && YandexID > 0 && ad_mid == 0) { pageYandexAd728(out, YandexID); } - + com.juick.Message msg = msgs.get(i); - - String tags; - if (user == null) { - tags = msg.Tags.isEmpty() ? "" : formatTags(msg.Tags, null); - } else { - tags = msg.Tags.isEmpty() ? "" : formatTags(msg.Tags, null); //msg.User); - } + + ArrayList tags = MessagesQueries.getMessageTags(sql, msg.MID); + String tagsStr = formatTags(tags); if (msg.ReadOnly) { - tags += " *readonly"; + tagsStr += " *readonly"; } if (msg.Privacy < 0) { - tags += " *friends"; + tagsStr += " *friends"; } if (msg.MID == ad_mid) { - tags += " *реклама"; + tagsStr += " *реклама"; } - + String txt; if (!msg.Tags.isEmpty() && msg.Tags.contains("code")) { txt = formatMessageCode(msg.Text); } else { txt = formatMessage(msg.Text); } - + out.println("