aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/juick/http/www
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2014-07-29 17:50:17 +0700
committerGravatar Ugnich Anton2014-07-29 17:50:17 +0700
commit6856f7278584425b0cb6fc54d50f5d5cf4a3f88e (patch)
treef9c819a0895ff964f63b77275c95ca805fcd89f4 /src/java/com/juick/http/www
parent21847edc8b557f795bc6e64ca1f84c23252ab314 (diff)
formatTags
Diffstat (limited to 'src/java/com/juick/http/www')
-rw-r--r--src/java/com/juick/http/www/PageTemplates.java114
1 files changed, 64 insertions, 50 deletions
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("<!DOCTYPE html>");
out.print("<html>");
@@ -67,7 +67,7 @@ public class PageTemplates {
out.flush();
out.println("<body>");
}
-
+
public static void pageNavigation(PrintWriter out, com.juick.User visitor, String search) {
out.println("<header>");
out.println(" <div id=\"logo\"><a href=\"/\">Juick</a></div>");
@@ -100,7 +100,7 @@ public class PageTemplates {
out.println(" </section>");
out.println("</header>");
}
-
+
public static void pageYandexAd728(PrintWriter out, int YandexID) {
/*
out.println("<div id=\"yandex_ad_728\"></div>");
@@ -137,12 +137,12 @@ public class PageTemplates {
out.println("(adsbygoogle = window.adsbygoogle || []).push({})");
out.println("</script>");
}
-
+
public static void pageHomeColumn(PrintWriter out, Connection sql, com.juick.User visitor) {
if (tagsHTML == null) {
tagsHTML = PageTemplates.getPopularTags(sql, 80);
}
-
+
out.println("<aside id=\"column\">");
out.println(" <p class=\"tags\">" + tagsHTML + "</p>");
// if (visitor != null) {
@@ -150,10 +150,10 @@ public class PageTemplates {
// }
out.println("</aside>");
}
-
+
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 += "<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);
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
return ret;
}
-
+
public static void printContestRating(PrintWriter out, Connection sql) {
out.println("<hr/>");
out.println("<!--noindex-->");
out.println("<p style=\"font-size: 14pt\">Кто <a href=\"/help/ru/contest\">выиграет iPod</a>?</p>");
out.println("<table width=\"100%\">");
-
+
int i = 0;
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -206,11 +206,11 @@ public class PageTemplates {
} finally {
Utils.finishSQL(rs, stmt);
}
-
+
out.println("</table>");
out.println("<!--/noindex-->");
}
-
+
public static void pageFooter(HttpServletRequest request, PrintWriter out, com.juick.User visitor, boolean sapeon) {
out.println("<div id=\"footer\">");
out.println(" <div id=\"footer-right\"><a href=\"/settings\" rel=\"nofollow\">Настройки</a> &#183; <a href=\"/help/ru/contacts\" rel=\"nofollow\">Контакты</a> &#183; <a href=\"/help/\" rel=\"nofollow\">Справка</a> &#183; <a href=\"/help/ru/adv\" rel=\"nofollow\">Реклама</a></div>");
@@ -220,7 +220,7 @@ public class PageTemplates {
out.print("<a href=\"https://www.facebook.com/JuickCom\" rel=\"nofollow\" class=\"ico32-fb\">Facebook</a>");
out.println("</div>");
out.print(" <div id=\"footer-left\">juick.com &copy; 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("<br/><a href=\"http://siam.li/\">сиам</a>");
}
-
+
out.println("</div>");
out.println("</div>");
-
+
if (visitor != null) {
out.println("<script type=\"text/javascript\">");
out.println("var hash=\"" + visitor.AuthHash + "\";");
out.println("</script>");
}
-
+
out.println("<script>");
out.println("(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){");
out.println("(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),");
@@ -250,7 +250,7 @@ public class PageTemplates {
out.println("ga('create','UA-385578-4','juick.com');");
out.println("ga('require','displayfeatures');");
out.println("ga('send','pageview');");
-
+
if (sapeon) {
out.println("var _acic={dataProvider:10};");
out.println("(function(){");
@@ -258,14 +258,32 @@ public class PageTemplates {
out.println("var t=document.getElementsByTagName('script')[0];t.parentNode.insertBefore(e,t);");
out.println("})();");
}
-
+
out.println("</script>");
}
-
+
public static void pageEnd(PrintWriter out) {
out.println("</body></html>");
}
-
+
+ public static String formatTags(ArrayList<com.juick.Tag> tags) {
+ String ret = "";
+ for (int i = 0; i < tags.size(); i++) {
+ com.juick.Tag tag = tags.get(i);
+ String tagName = tag.Name.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
+ if (tag.UsageCnt > 1) {
+ try {
+ ret += " *<a href=\"/tag/" + URLEncoder.encode(tag.Name, "utf-8") + "\">" + tagName + "</a>";
+ } catch (UnsupportedEncodingException e) {
+ }
+ } else {
+ ret += " *" + tagName;
+ }
+ }
+
+ return ret;
+ }
+
public static String formatTags(ArrayList<String> 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))([\\[\\{]|&lt;)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?<!&gt;))*)([\\]\\}]|&gt;)");
-
+
public static String formatMessageCode(String msg) {
msg = msg.replaceAll("&", "&amp;");
msg = msg.replaceAll("<", "&lt;");
@@ -394,10 +412,10 @@ public class PageTemplates {
}
m.appendTail(sb);
msg = sb.toString();
-
+
return "<pre>" + msg + "</pre>";
}
-
+
public static String formatMessage(String msg) {
msg = msg.replaceAll("&", "&amp;");
msg = msg.replaceAll("<", "&lt;");
@@ -462,14 +480,14 @@ public class PageTemplates {
// > citate
msg = msg.replaceAll("(?:(?<=\\n)|(?<=\\A))&gt; *(.*)?(\\n|(?=\\Z))", "<blockquote>$1</blockquote>");
msg = msg.replaceAll("</blockquote><blockquote>", "\n");
-
+
msg = msg.replaceAll("\n", "<br/>\n");
return msg;
}
-
+
public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, ArrayList<Integer> mids, com.juick.User visitor, int YandexID, int ad_mid) {
ArrayList<com.juick.Message> 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<Integer> blUIDs = new ArrayList<Integer>(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<com.juick.Tag> 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("<article data-mid=\"" + msg.MID + "\">");
out.println(" <aside><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\" alt=\"" + msg.User.UName + "\"/></a></aside>");
- out.println(" <header class=\"u\">@<a href=\"/" + msg.User.UName + "/\">" + msg.User.UName + "</a>:" + tags + "</header>");
+ out.println(" <header class=\"u\">@<a href=\"/" + msg.User.UName + "/\">" + msg.User.UName + "</a>:" + tagsStr + "</header>");
out.println(" <header class=\"t\"><a href=\"/" + msg.User.UName + "/" + msg.MID + "\"><time datetime=\"" + msg.TimestampString + "Z\" title=\"" + msg.TimestampString + " GMT\">" + formatDate(msg.TimeAgo, msg.TimestampString) + "</time></a></header>");
if (msg.AttachmentType != null) {
String fname = msg.MID + "." + msg.AttachmentType;
@@ -547,7 +561,7 @@ public class PageTemplates {
out.print(" <a href=\"#\" onclick=\"return setPopular(this," + msg.MID + ",-2)\">x</a>");
}
out.println("</nav>");
-
+
out.print(" <nav class=\"s\">");
if (msg.Likes > 0) {
out.print("<a href=\"/" + msg.User.UName + "/" + msg.MID + "\" class=\"likes\">" + msg.Likes + "</a>");