aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/juick/http/www/PageTemplates.java
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2012-11-02 18:33:10 +0700
committerGravatar Ugnich Anton2012-11-02 18:33:10 +0700
commit3b92419424bf770c6199b821ba0b7e98c7b1bd99 (patch)
tree56051d952599dc13a8c26d94fd9f4ac6d1d44651 /src/java/com/juick/http/www/PageTemplates.java
parentb895a6e7a29193754a97e33b6af8bd66f1006fc4 (diff)
BL-sensible comment form
Diffstat (limited to 'src/java/com/juick/http/www/PageTemplates.java')
-rw-r--r--src/java/com/juick/http/www/PageTemplates.java134
1 files changed, 55 insertions, 79 deletions
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java
index ba5665ed..41646e30 100644
--- a/src/java/com/juick/http/www/PageTemplates.java
+++ b/src/java/com/juick/http/www/PageTemplates.java
@@ -17,6 +17,7 @@
*/
package com.juick.http.www;
+import com.juick.server.MessagesQueries;
import com.juick.server.UserQueries;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
@@ -161,15 +162,14 @@ public class PageTemplates {
out.println("</div></div>");
}
- public static String formatTags(String tags) {
+ public static String formatTags(ArrayList<String> tags) {
String ret = "";
- String tagsarr[] = tags.split(" ");
- for (int i = 0; i < tagsarr.length; i++) {
- String tag = tagsarr[i];
+ for (int i = 0; i < tags.size(); i++) {
+ String tag = tags.get(i);
tag = tag.replaceAll("<", "&lt;");
tag = tag.replaceAll(">", "&gt;");
try {
- ret += " *<a href=\"/?tag=" + URLEncoder.encode(tagsarr[i], "utf-8") + "\">" + tag + "</a>";
+ ret += " *<a href=\"/?tag=" + URLEncoder.encode(tags.get(i), "utf-8") + "\">" + tag + "</a>";
} catch (UnsupportedEncodingException e) {
}
}
@@ -277,85 +277,61 @@ public class PageTemplates {
public static void printMessages(PrintWriter out, Connection sql, ArrayList<Integer> mids, com.juick.User visitor, Locale locale) {
ResourceBundle rb = ResourceBundle.getBundle("Global", locale);
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT STRAIGHT_JOIN messages.message_id,messages.user_id,users.nick,messages_txt.tags,messages.readonly,messages.privacy,messages_txt.txt,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),messages.ts,messages.replies,messages_txt.repliesby,messages.attach,messages.place_id,places.name,messages.lat,messages.lon FROM ((messages INNER JOIN messages_txt ON messages.message_id=messages_txt.message_id) INNER JOIN users ON messages.user_id=users.id) LEFT JOIN places ON messages.place_id=places.place_id WHERE messages.message_id IN (" + Utils.convertArray2String(mids) + ") ORDER BY messages.message_id DESC");
- rs = stmt.executeQuery();
- rs.beforeFirst();
- while (rs.next()) {
- int mid = rs.getInt(1);
- int uid = rs.getInt(2);
- String uname = rs.getString(3);
- String tags = rs.getString(4);
- String txt = rs.getString(7);
- // timediff
- // timestamp
- // replies
- // 11 repliesby
- // attach
- // pid
- // pname
- // lat
- // lon
-
- boolean cancomment = visitor != null;
-
- tags = (tags != null) ? formatTags(tags) : "";
- if (rs.getInt(5) == 1) {
- tags += " *readonly";
- if (visitor != null && visitor.UID != uid) {
- cancomment = false;
- }
- }
- switch (rs.getInt(6)) {
- case 2:
- tags += " *public";
- break;
- case -1:
- tags += " *friends";
- break;
- case -2:
- tags += " *private";
- break;
- }
+ ArrayList<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids);
- txt = formatMessage(txt);
+ ArrayList<Integer> blUIDs = new ArrayList<Integer>(20);
+ for (int i = 0; i < mids.size(); i++) {
+ blUIDs.add(msgs.get(i).User.UID);
+ }
+ blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs);
- out.println(" <li id=\"msg-" + mid + "\" class=\"msg\">");
- out.println(" <div class=\"msg-avatar\"><a href=\"/" + uname + "/\"><img src=\"//i.juick.com/a/" + uid + ".png\" alt=\"" + uname + "\"/></a></div>");
- out.println(" <div class=\"msg-ts\"><a href=\"/" + uname + "/" + mid + "\" title=\"" + rs.getString(9) + "\">" + formatDate(rs.getInt(8), rs.getString(9), locale) + "</a></div>");
- out.println(" <div class=\"msg-header\"><a href=\"/" + uname + "/\">@" + uname + "</a>:" + tags + "</div>");
- if (rs.getString(14) != null) {
- out.println(" <div class=\"msg-place\">" + rs.getString(14) + "</div>");
- }
- out.println(" <div class=\"msg-txt\">" + txt + "</div>");
-
- if (rs.getString(12) != null) {
- if (rs.getString(12).equals("jpg")) {
- out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/photos-1024/" + mid + ".jpg\"><img src=\"//i.juick.com/photos-512/" + mid + ".jpg\" alt=\"\"/></a></div>");
- } else {
- out.println(" <div class=\"msg-media\"><div id=\"video-" + mid + "\"><a href=\"//i.juick.com/video/" + mid + ".mp4\" onclick=\"inlinevideo(" + mid + "); return false\"><img src=\"//i.juick.com/thumbs/" + mid + ".jpg\" alt=\"\"/></a></div></div>");
- }
- }
+ for (int i = 0; i < msgs.size(); i++) {
+ com.juick.Message msg = msgs.get(i);
+
+ String tags = msg.Tags.isEmpty() ? "" : formatTags(msg.Tags);
+ if (msg.ReadOnly) {
+ tags += " *readonly";
+ }
+ switch (msg.Privacy) {
+ case 2:
+ tags += " *public";
+ break;
+ case -1:
+ tags += " *friends";
+ break;
+ case -2:
+ tags += " *private";
+ break;
+ }
+
+ 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-ts\"><a href=\"/" + msg.User.UName + "/" + msg.MID + "\" title=\"" + msg.TimestampString + "\">" + formatDate(msg.TimeAgo, msg.TimestampString, locale) + "</a></div>");
+ out.println(" <div class=\"msg-header\"><a href=\"/" + msg.User.UName + "/\">@" + msg.User.UName + "</a>:" + tags + "</div>");
+ if (msg.Place != null) {
+ out.println(" <div class=\"msg-place\">" + msg.Place.name + "</div>");
+ }
+ out.println(" <div class=\"msg-txt\">" + formatMessage(msg.Text) + "</div>");
- if (rs.getInt(10) > 0) {
- String repliesby = rs.getString(11);
- if (repliesby == null) {
- repliesby = "...";
- }
- out.println(" <div class=\"msg-comments\"><a href=\"/" + uname + "/" + mid + "\">" + formatReplies(rs.getInt(10), locale) + "</a> " + rb.getString("(replies) by") + " " + repliesby + "</div>");
- } else if (cancomment) {
- out.println(" <form action=\"/post\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"mid\" value=\"" + mid + "\"/>");
- out.println(" <div class=\"msg-comment\"><textarea name=\"body\" rows=\"1\" class=\"reply\" placeholder=\"" + rb.getString("Add a comment") + "\" onkeypress=\"postformListener(this.form,event)\"></textarea></div>");
- out.println(" </form>");
+ if (msg.AttachmentType != null) {
+ if (msg.AttachmentType.equals("jpg")) {
+ out.println(" <div class=\"msg-media\"><a href=\"//i.juick.com/photos-1024/" + msg.MID + ".jpg\"><img src=\"//i.juick.com/photos-512/" + msg.MID + ".jpg\" alt=\"\"/></a></div>");
+ } else {
+ out.println(" <div class=\"msg-media\"><div id=\"video-" + msg.MID + "\"><a href=\"//i.juick.com/video/" + msg.MID + ".mp4\" onclick=\"inlinevideo(" + msg.MID + "); return false\"><img src=\"//i.juick.com/thumbs/" + msg.MID + ".jpg\" alt=\"\"/></a></div></div>");
}
- out.println(" </li>");
}
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
+
+ msg.ReadOnly |= blUIDs.contains(msg.User.UID);
+
+ if (msg.Replies > 0) {
+ String repliesby = (msg.RepliesBy != null) ? msg.RepliesBy : "...";
+ out.println(" <div class=\"msg-comments\"><a href=\"/" + msg.User.UName + "/" + msg.MID + "\">" + formatReplies(msg.Replies, locale) + "</a> " + rb.getString("(replies) by") + " " + repliesby + "</div>");
+ } else if (visitor != null && (msg.ReadOnly == false || visitor.UID == msg.User.UID)) {
+ out.println(" <form action=\"/post\" method=\"POST\" enctype=\"multipart/form-data\"><input type=\"hidden\" name=\"mid\" value=\"" + msg.MID + "\"/>");
+ out.println(" <div class=\"msg-comment\"><textarea name=\"body\" rows=\"1\" class=\"reply\" placeholder=\"" + rb.getString("Add a comment") + "\" onkeypress=\"postformListener(this.form,event)\"></textarea></div>");
+ out.println(" </form>");
+ }
+ out.println(" </li>");
}
}
}