1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*
* Juick
* Copyright (C) 2008-2011, Ugnich Anton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.juick.http.www;
import com.juick.Tag;
import com.juick.server.TagQueries;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.Connection;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Ugnich Anton
*/
public class NewMessage {
protected void doGetNewMessage(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
try {
PageTemplates.pageHead(out, "Написать", "<script src=\"//maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAVVtPtxkw4soCEHg44FsNChRB4OFYjAXt73He16Zkp6a_0tPs2RTU6i6UlcMs4QvPBYvIY8rWvcxqOg\" type=\"text/javascript\"></script>"
+ "<script src=\"//static.juick.com/mc.js\" type=\"text/javascript\" defer=\"defer\"></script>"
+ "<script src=\"//static.juick.com/maps.js?2010111500\" type=\"text/javascript\" defer=\"defer\"></script>"
+ "<script src=\"//static.juick.com/post3.js\" type=\"text/javascript\" defer=\"defer\"></script>");
PageTemplates.pageNavigation(out, visitor, null);
out.println("<section id=\"content\" class=\"pagetext\">");
out.println("<form action=\"/post\" method=\"post\" id=\"postmsg\" enctype=\"multipart/form-data\">");
out.println("<p style=\"text-align: left\"><b>Место: <span id=\"location\"></span></b> <span id=\"locationclear\">— <a href=\"#\" onclick=\"clearLocation()\">Отменить</a></span></p>");
out.println("<p style=\"text-align: left\"><b>Фото:</b> <span id=\"attachmentfile\"><input type=\"file\" name=\"attach\"/> <i>(JPG, PNG, до 10Мб)</i></span></p>");
String body = request.getParameter("body");
if (body == null) {
body = "";
} else {
if (body.length() > 4096) {
body = body.substring(0, 4096);
}
body = Utils.encodeHTML(body);
}
out.println("<p><textarea name=\"body\" class=\"newmessage\" rows=\"7\" cols=\"10\">" + body + "</textarea><br/>");
out.println("<input type=\"hidden\" name=\"place_id\"/>" + "" + "<input type=\"submit\" class=\"subm\" value=\" Отправить \"/></p>");
out.println("</form>");
out.println("<div id=\"geomap\"></div>");
out.println("<p style=\"text-align: left\"><b>Теги:</b></p>");
printUserTags(sql, out, visitor);
out.println("</section>");
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
} finally {
out.close();
}
}
void printUserTags(Connection sql, PrintWriter out, com.juick.User visitor) {
ArrayList<Tag> tags = TagQueries.getUserTagsAll(sql, visitor.UID);
if (tags.isEmpty()) {
return;
}
int min = tags.get(0).UsageCnt;
int max = tags.get(0).UsageCnt;
for (int i = 1; i < tags.size(); i++) {
int usagecnt = tags.get(i).UsageCnt;
if (usagecnt < min) {
min = usagecnt;
}
if (usagecnt > max) {
max = usagecnt;
}
}
max -= min;
out.print("<p style=\"text-align: justify\">");
for (int i = 0; i < tags.size(); i++) {
if (i > 0) {
out.print(" ");
}
String taglink = "";
try {
taglink = "<a onclick=\"return addTag('" + Utils.encodeHTML(tags.get(i).Name) + "')\" href=\"/" + visitor.UName + "/?tag=" + URLEncoder.encode(tags.get(i).Name, "utf-8") + "\" title=\"" + tags.get(i).UsageCnt + "\">" + Utils.encodeHTML(tags.get(i).Name) + "</a>";
} catch (UnsupportedEncodingException e) {
}
int usagecnt = tags.get(i).UsageCnt;
if (usagecnt <= max / 5 + min) {
out.print("<span style=\"font-size: small\">" + taglink + "</span>");
} else if (usagecnt <= max / 5 * 2 + min) {
out.print(taglink);
} else if (usagecnt <= max / 5 * 3 + min) {
out.print("<span style=\"font-size: large\">" + taglink + "</span>");
} else if (usagecnt <= max / 5 * 4 + min) {
out.print("<span style=\"font-size: x-large\">" + taglink + "</span>");
} else {
out.print("<span style=\"font-size: xx-large\">" + taglink + "</span>");
}
}
out.println("</p>");
}
protected void doPostNewMessage(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
|