diff options
author | Ugnich Anton | 2013-01-05 03:59:25 +0700 |
---|---|---|
committer | Ugnich Anton | 2013-01-05 03:59:25 +0700 |
commit | fc53fd7d63c703b2664e5cb0cbd6360e4b3f7bd5 (patch) | |
tree | 092443ac6bffcb9cd9de3ca9249f7a14cfee9c24 /src | |
parent | 6df23a2abefb11b694afc359358a450f704d41bf (diff) |
Tag *code
Diffstat (limited to 'src')
-rw-r--r-- | src/java/com/juick/http/www/PageTemplates.java | 34 | ||||
-rw-r--r-- | src/java/com/juick/http/www/UserThread.java | 9 |
2 files changed, 40 insertions, 3 deletions
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index 80b5a22e..11d20f32 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -52,7 +52,7 @@ public class PageTemplates { out.println("<html>"); out.println("<head>"); out.println(" <title>" + title + "</title>"); - out.println(" <link rel=\"stylesheet\" href=\"//static.juick.com/style3.2013010301.css\"/>"); + out.println(" <link rel=\"stylesheet\" href=\"//static.juick.com/style3.2013010500.css\"/>"); out.println(" <link rel=\"icon\" type=\"image/png\" href=\"//static.juick.com/favicon.png\"/>"); out.println(" <script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js\" defer=\"defer\"></script>"); out.println(" <script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js\" defer=\"defer\" async=\"async\"></script>"); @@ -261,6 +261,29 @@ public class PageTemplates { } private static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|<)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?<!>))*)([\\]\\}]|>)"); + public static String formatMessageCode(String msg) { + msg = msg.replaceAll("&", "&"); + msg = msg.replaceAll("<", "<"); + msg = msg.replaceAll(">", ">"); + + // http://juick.com/last?page=2 + // <a href="http://juick.com/last?page=2" rel="nofollow">http://juick.com/last?page=2</a> + msg = msg.replaceAll("((?<=\\s)|(?<=\\A))((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\s\\n\\\"]*)", "$1<a href=\"$2\" rel=\"nofollow\">$2</a>"); + + // (http://juick.com/last?page=2) + // (<a href="http://juick.com/last?page=2" rel="nofollow">http://juick.com/last?page=2</a>) + Matcher m = regexLinks2.matcher(msg); + StringBuffer sb = new StringBuffer(); + while (m.find()) { + String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", ""); + m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">" + url + "</a>$5"); + } + m.appendTail(sb); + msg = sb.toString(); + + return "<pre>" + msg + "</pre>"; + } + public static String formatMessage(String msg) { msg = msg.replaceAll("&", "&"); msg = msg.replaceAll("<", "<"); @@ -360,6 +383,13 @@ public class PageTemplates { break; } + String txt; + if (!msg.Tags.isEmpty() && msg.Tags.contains("code")) { + txt = formatMessageCode(msg.Text); + } else { + txt = formatMessage(msg.Text); + } + out.println(" <li id=\"msg-" + msg.MID + "\" class=\"msg\">"); 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-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:" + tags + "</div>"); @@ -367,7 +397,7 @@ public class PageTemplates { if (msg.Place != null) { out.println(" <div class=\"msg-place\"><a href=\"/places/" + msg.Place.pid + "\">" + msg.Place.name + "</a></div>"); } - out.println(" <div class=\"msg-txt\">" + formatMessage(msg.Text) + "</div>"); + out.print(" <div class=\"msg-txt\">" + txt + "</div>"); if (msg.AttachmentType != null) { if (msg.AttachmentType.equals("jpg")) { diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java index 9001bd17..3b315be2 100644 --- a/src/java/com/juick/http/www/UserThread.java +++ b/src/java/com/juick/http/www/UserThread.java @@ -114,6 +114,13 @@ public class UserThread { break; } + String txt; + if (!msg.Tags.isEmpty() && msg.Tags.contains("code")) { + txt = PageTemplates.formatMessageCode(msg.Text); + } else { + txt = PageTemplates.formatMessage(msg.Text); + } + out.println("<ul>"); out.println(" <li id=\"msg-" + mid + "\" class=\"msg msgthread\">"); 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>"); @@ -122,7 +129,7 @@ public class UserThread { if (msg.Place != null) { out.println(" <div class=\"msg-place\"><a href=\"/places/" + msg.Place.pid + "\">" + msg.Place.name + "</a></div>"); } - out.println(" <div class=\"msg-txt\">" + PageTemplates.formatMessage(msg.Text) + "</div>"); + out.println(" <div class=\"msg-txt\">" + txt + "</div>"); if (msg.AttachmentType != null) { if (msg.AttachmentType.equals("jpg")) { |