aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2014-07-30 17:53:19 +0700
committerGravatar Ugnich Anton2014-07-30 17:53:19 +0700
commit565b8f0b25c9215687ddd4c84f236e1d1696b93d (patch)
treef9c7a176a56791b8e007ff9dcb877666c0fc468c
parentc4eebb74f520c122800c000c2329d3b6b7520c65 (diff)
formatTags rel=nofollow
-rw-r--r--src/java/com/juick/http/www/PageTemplates.java96
-rw-r--r--src/java/com/juick/http/www/UserThread.java24
2 files changed, 55 insertions, 65 deletions
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java
index dc8c7c59..686971e8 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,32 +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) {
+ try {
+ ret += " *<a href=\"/tag/" + URLEncoder.encode(tag.Name, "utf-8") + "\"";
+ if (tag.UsageCnt < 2) {
+ ret += " rel=\"nofollow\"";
}
- } else {
- ret += " *" + tagName;
+ ret += ">" + tagName + "</a>";
+ } catch (UnsupportedEncodingException e) {
}
}
-
+
return ret;
}
-
+
public static String formatTags(ArrayList<String> tags, com.juick.User user) {
String ret = "";
for (int i = 0; i < tags.size(); i++) {
@@ -301,10 +301,10 @@ public class PageTemplates {
} catch (UnsupportedEncodingException e) {
}
}
-
+
return ret;
}
-
+
public static String formatDate(int minutes, String fulldate) {
if (minutes < 1) {
return "сейчас";
@@ -363,7 +363,7 @@ public class PageTemplates {
return ret;
}
}
-
+
public static String formatJSLocalTime(String ts) {
String ret = "";
synchronized (sdfSQL) {
@@ -379,7 +379,7 @@ public class PageTemplates {
}
return ret;
}
-
+
public static String formatReplies(int replies) {
int ld = replies % 10;
int lh = replies % 100;
@@ -392,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;");
@@ -412,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;");
@@ -480,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) {
@@ -496,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++) {
@@ -504,15 +504,15 @@ 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);
-
+
ArrayList<com.juick.Tag> tags = MessagesQueries.getMessageTags(sql, msg.MID);
String tagsStr = formatTags(tags);
if (msg.ReadOnly) {
@@ -524,14 +524,14 @@ public class PageTemplates {
if (msg.MID == ad_mid) {
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>:" + tagsStr + "</header>");
@@ -561,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>");
diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java
index 46242e2b..1dd1df69 100644
--- a/src/java/com/juick/http/www/UserThread.java
+++ b/src/java/com/juick/http/www/UserThread.java
@@ -98,24 +98,14 @@ public class UserThread {
public static com.juick.Message printMessage(PrintWriter out, Connection sql, com.juick.Message msg, com.juick.User visitor) {
msg.VisitorCanComment = visitor != null;
- String tags = (msg.Tags.isEmpty()) ? "" : PageTemplates.formatTags(msg.Tags, null); //msg.User);
+ ArrayList<com.juick.Tag> tags = MessagesQueries.getMessageTags(sql, msg.MID);
+ String tagsStr = PageTemplates.formatTags(tags);
if (msg.ReadOnly) {
- tags += " *readonly";
+ tagsStr += " *readonly";
msg.VisitorCanComment = false;
}
- switch (msg.Privacy) {
- case 2:
- tags += " *public";
- break;
- case -1:
- tags += " *friends";
- break;
- case -2:
- tags += " *friends";
- break;
- case -3:
- tags += " *private";
- break;
+ if (msg.Privacy < 0) {
+ tagsStr += " *friends";
}
String txt;
@@ -126,7 +116,7 @@ public class UserThread {
}
if (!tags.isEmpty()) {
- tags = "<span class=\"msg-tags\">" + tags + "</span>";
+ tagsStr = "<span class=\"msg-tags\">" + tagsStr + "</span>";
}
out.println("<ul>");
@@ -134,7 +124,7 @@ public class UserThread {
out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.User.UName + "/\"><img src=\"//i.juick.com/a/" + msg.User.UID + ".png\" alt=\"" + msg.User.UName + "\"/></a></div>");
out.println(" <div class=\"msg-cont\">");
out.println(" <div class=\"msg-menu\"><a href=\"#\" onclick=\"showMessageLinksDialog(" + msg.MID + "); return false\"></a></div>");
- out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:" + tags + "</div>");
+ out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:" + tagsStr + "</div>");
out.println(" <div class=\"msg-ts\">" + PageTemplates.formatJSLocalTime(msg.TimestampString) + "</div>");
out.println(" <div class=\"msg-txt\">" + txt + "</div>");