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/java/com/juick/http/www/PageTemplates.java | |
parent | 6df23a2abefb11b694afc359358a450f704d41bf (diff) |
Tag *code
Diffstat (limited to 'src/java/com/juick/http/www/PageTemplates.java')
-rw-r--r-- | src/java/com/juick/http/www/PageTemplates.java | 34 |
1 files changed, 32 insertions, 2 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")) { |