From 19cf26ce2f8ee05fc8a9298e2c19b8fff589b8e6 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sat, 23 Feb 2013 14:51:10 +0700 Subject: Yandex.Direct --- src/java/com/juick/http/www/Blogs.java | 62 +++++++++++++------------- src/java/com/juick/http/www/Login.java | 2 +- src/java/com/juick/http/www/PageTemplates.java | 36 ++++++++++++++- src/java/com/juick/http/www/User.java | 8 ++-- 4 files changed, 70 insertions(+), 38 deletions(-) (limited to 'src/java/com') 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 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("
"); out.println("
"); out.println("
"); - + if (place != null) { out.println("
\"Map\"/
"); } - + if (mids.size() > 0) { out.println("
    "); - PageTemplates.printMessages(out, sql, null, mids, visitor, locale); + PageTemplates.printMessages(out, sql, null, mids, visitor, locale, visitor == null ? 2 : 3); out.println("
"); } - + if (mids.size() == 20) { String nextpage = "?before=" + mids.get(mids.size() - 1); if (paramShow != null) { @@ -214,7 +214,7 @@ public class Blogs { out.println("
"); out.println("
"); // wrapper - + out.println("
"); if (visitor != null) { out.println("
    "); @@ -233,9 +233,9 @@ public class Blogs { out.println("
    "); out.println("

    " + getTags(sql, 40) + "

    "); out.println("
"); - + out.println("
"); - 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("
"); - + out.println("
"); // 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 = "" + tag + ""; } catch (UnsupportedEncodingException e) { } - + if (tags[i].UsageCnt > maxUsageCnt / 3 * 2) { ret += "" + tag + " "; } 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(""); out.println(""); out.println(" " + title + ""); - out.println(" "); + out.println(" "); out.println(" "); out.println(" "); out.println(" "); @@ -351,7 +351,7 @@ public class PageTemplates { return msg; } - public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, ArrayList mids, com.juick.User visitor, Locale locale) { + public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, ArrayList mids, com.juick.User visitor, Locale locale, int YandexID) { ResourceBundle rb = ResourceBundle.getBundle("Global", locale); ArrayList 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("
  • "); + out.println(""); + } + 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("
    "); out.println("
      "); 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("
    "); @@ -138,9 +138,9 @@ public class User { pageUserColumn(out, sql, user, visitor, locale); out.println("
    "); - out.println("
    "); - PageTemplates.pageYandexAd(out, visitor == null ? 4 : 5); // разный ID для залогиненых и нет - out.println("
    "); + //out.println("
    "); + //PageTemplates.pageYandexAd(out, visitor == null ? 4 : 5); // разный ID для залогиненых и нет + //out.println("
    "); out.println(""); // topwrapper -- cgit v1.2.3