diff options
author | Ugnich Anton | 2013-02-23 14:51:10 +0700 |
---|---|---|
committer | Ugnich Anton | 2013-02-23 14:51:10 +0700 |
commit | 19cf26ce2f8ee05fc8a9298e2c19b8fff589b8e6 (patch) | |
tree | 795b1a6bcdc3946c444709a3e1c68d67a64d5bb9 /src/java/com/juick/http/www | |
parent | cdbf949013fe140fed0e5ad79ad6111c97ea07ad (diff) |
Yandex.Direct
Diffstat (limited to 'src/java/com/juick/http/www')
-rw-r--r-- | src/java/com/juick/http/www/Blogs.java | 62 | ||||
-rw-r--r-- | src/java/com/juick/http/www/Login.java | 2 | ||||
-rw-r--r-- | src/java/com/juick/http/www/PageTemplates.java | 36 | ||||
-rw-r--r-- | src/java/com/juick/http/www/User.java | 8 |
4 files changed, 70 insertions, 38 deletions
diff --git a/src/java/com/juick/http/www/Blogs.java b/src/java/com/juick/http/www/Blogs.java index 5acc8947..4f455760 100644 --- a/src/java/com/juick/http/www/Blogs.java +++ b/src/java/com/juick/http/www/Blogs.java @@ -41,9 +41,9 @@ import javax.servlet.http.HttpServletResponse; * @author Ugnich Anton */ public class Blogs { - + private int relatedTagsStartMID = 0; - + public Blogs(Connection sql) { PreparedStatement stmt = null; ResultSet rs = null; @@ -59,7 +59,7 @@ public class Blogs { Utils.finishSQL(rs, stmt); } } - + protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String paramTagStrQuery = request.getParameter("tag"); if (paramTagStrQuery != null) { @@ -70,18 +70,18 @@ public class Blogs { } Utils.sendPermanentRedirect(response, url); } - + com.juick.User visitor = Utils.getVisitorUser(sql, request); Locale locale = request.getLocale(); ResourceBundle rb = ResourceBundle.getBundle("Blogs", locale); - + String title; ArrayList<Integer> mids; - + String paramShow = request.getParameter("show"); - + String requesturi = request.getRequestURI(); - + int paramTag = 0; String paramTagStr = null; if (requesturi.startsWith("/tag/")) { @@ -94,7 +94,7 @@ public class Blogs { } else if (requesturi.startsWith("/places/")) { //TODO перенести сюда блок, который страницей ниже } - + int paramBefore = 0; String paramBeforeStr = request.getParameter("before"); if (paramBeforeStr != null) { @@ -103,15 +103,15 @@ public class Blogs { } catch (NumberFormatException e) { } } - + String paramSearch = request.getParameter("search"); if (paramSearch != null && paramSearch.length() > 64) { paramSearch = null; } - + com.juick.Place place = null; int visitor_uid = visitor != null ? visitor.UID : 0; - + if (paramShow == null) { if (paramTag > 0) { title = "*" + Utils.encodeHTML(paramTagStr); @@ -179,27 +179,27 @@ public class Blogs { response.sendError(404); return; } - + response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { PageTemplates.pageHead(out, title, null); PageTemplates.pageNavigation(out, locale, visitor, paramSearch); - + out.println("<div id=\"topwrapper\">"); out.println("<div id=\"wrapper\">"); out.println("<div id=\"content\">"); - + if (place != null) { out.println("<div id=\"geomap\"><img src=\"http://maps.google.com/maps/api/staticmap?center=" + place.lat + "," + place.lon + "&markers=color:orange|" + place.lat + "," + place.lon + "&zoom=14&size=600x300&maptype=hybrid&sensor=false\" width=\"600\" height=\"300\" alt=\"Map\"/></div>"); } - + if (mids.size() > 0) { out.println("<ul>"); - PageTemplates.printMessages(out, sql, null, mids, visitor, locale); + PageTemplates.printMessages(out, sql, null, mids, visitor, locale, visitor == null ? 2 : 3); out.println("</ul>"); } - + if (mids.size() == 20) { String nextpage = "?before=" + mids.get(mids.size() - 1); if (paramShow != null) { @@ -214,7 +214,7 @@ public class Blogs { out.println("</div>"); out.println("</div>"); // wrapper - + out.println("<div id=\"column\" class=\"abs\">"); if (visitor != null) { out.println(" <ul>"); @@ -233,9 +233,9 @@ public class Blogs { out.println(" <hr/>"); out.println(" <p>" + getTags(sql, 40) + "</p>"); out.println("</div>"); - + out.println("<div id=\"rcol\" class=\"abs\">"); - PageTemplates.pageYandexAd(out, visitor == null ? 2 : 3); // разный ID для залогиненых и нет + //PageTemplates.pageYandexAd(out, visitor == null ? 2 : 3); // разный ID для залогиненых и нет if (paramTag > 0 && relatedTagsStartMID > 0) { String related = getRelatedTags(sql, paramTag, 15); if (!related.isEmpty()) { @@ -244,7 +244,7 @@ public class Blogs { } } out.println("</div>"); - + out.println("</div>"); // topwrapper PageTemplates.pageDialogTemplate(out, locale); @@ -253,11 +253,11 @@ public class Blogs { out.close(); } } - + private String getTags(Connection sql, int cnt) { String ret = ""; com.juick.Tag tags[] = new com.juick.Tag[cnt]; - + int maxUsageCnt = 0; PreparedStatement stmt = null; ResultSet rs = null; @@ -281,16 +281,16 @@ public class Blogs { } finally { Utils.finishSQL(rs, stmt); } - + Arrays.sort(tags, 0, cnt); - + for (int i = 0; i < cnt; i++) { String tag = Utils.encodeHTML(tags[i].Name); try { tag = "<a href=\"/tag/" + URLEncoder.encode(tags[i].Name, "UTF-8") + "\">" + tag + "</a>"; } catch (UnsupportedEncodingException e) { } - + if (tags[i].UsageCnt > maxUsageCnt / 3 * 2) { ret += "<big>" + tag + "</big> "; } else if (tags[i].UsageCnt > maxUsageCnt / 3) { @@ -299,13 +299,13 @@ public class Blogs { ret += tag + " "; } } - + return ret; } - + private String getRelatedTags(Connection sql, int tag_id, int cnt) { String ret = ""; - + PreparedStatement stmt = null; ResultSet rs = null; try { @@ -325,7 +325,7 @@ public class Blogs { } finally { Utils.finishSQL(rs, stmt); } - + return ret; } } diff --git a/src/java/com/juick/http/www/Login.java b/src/java/com/juick/http/www/Login.java index d50e6115..ba8fac7e 100644 --- a/src/java/com/juick/http/www/Login.java +++ b/src/java/com/juick/http/www/Login.java @@ -87,7 +87,7 @@ public class Login { protected void doPostLogin(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); - if (username == null || password == null || username.length() > 32) { + if (username == null || password == null || username.length() > 32 || password.isEmpty()) { response.sendError(400); return; } diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index 42fafaf7..70f4d1ef 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.2013012601.css\"/>"); + out.println(" <link rel=\"stylesheet\" href=\"//static.juick.com/style3.2013022002.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>"); @@ -351,7 +351,7 @@ public class PageTemplates { return msg; } - public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, ArrayList<Integer> mids, com.juick.User visitor, Locale locale) { + public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, ArrayList<Integer> mids, com.juick.User visitor, Locale locale, int YandexID) { ResourceBundle rb = ResourceBundle.getBundle("Global", locale); ArrayList<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids); @@ -365,6 +365,38 @@ public class PageTemplates { } for (int i = 0; i < msgs.size(); i++) { + + if (i == 1 && YandexID > 0) { + out.println(" <li class=\"ads\"><div id=\"yandex_ad\"></div></li>"); + out.println("<script type=\"text/javascript\">"); + out.println("(function(w, d, n, s, t) {"); + out.println("w[n] = w[n] || [];"); + out.println("w[n].push(function() {"); + out.println("Ya.Direct.insertInto(84715, \"yandex_ad\", {"); + out.println("stat_id: " + YandexID + ","); + out.println("site_charset: \"utf-8\","); + out.println("ad_format: \"direct\","); + out.println("font_size: 1,"); + out.println("type: \"flat\","); + out.println("limit: 1,"); + out.println("title_font_size: 2,"); + out.println("site_bg_color: \"FFFFFF\","); + out.println("title_color: \"006699\","); + out.println("url_color: \"000000\","); + out.println("text_color: \"000000\","); + out.println("hover_color: \"006699\""); + out.println("});"); + out.println("});"); + out.println("t = d.documentElement.firstChild;"); + out.println("s = d.createElement(\"script\");"); + out.println("s.type = \"text/javascript\";"); + out.println("s.src = \"http://an.yandex.ru/system/context.js\";"); + out.println("s.setAttribute(\"async\", \"true\");"); + out.println("t.insertBefore(s, t.firstChild);"); + out.println("})(window, document, \"yandex_context_callbacks\");"); + out.println("</script>"); + } + com.juick.Message msg = msgs.get(i); String tags = msg.Tags.isEmpty() ? "" : formatTags(msg.Tags, user); diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java index 2faf695b..3f1fe4a3 100644 --- a/src/java/com/juick/http/www/User.java +++ b/src/java/com/juick/http/www/User.java @@ -115,7 +115,7 @@ public class User { out.println("<div id=\"content\">"); out.println("<ul>"); if (mids.size() > 0) { - PageTemplates.printMessages(out, sql, user, mids, visitor, locale); + PageTemplates.printMessages(out, sql, user, mids, visitor, locale, visitor == null ? 4 : 5); } out.println("</ul>"); @@ -138,9 +138,9 @@ public class User { pageUserColumn(out, sql, user, visitor, locale); out.println("</div>"); - out.println("<div id=\"rcol\" class=\"abs\">"); - PageTemplates.pageYandexAd(out, visitor == null ? 4 : 5); // разный ID для залогиненых и нет - out.println("</div>"); + //out.println("<div id=\"rcol\" class=\"abs\">"); + //PageTemplates.pageYandexAd(out, visitor == null ? 4 : 5); // разный ID для залогиненых и нет + //out.println("</div>"); out.println("</div>"); // topwrapper |