aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-api/src/main/java/com/juick/api/ApiServer.java3
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java11
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java6
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java6
-rw-r--r--juick-server/src/main/java/com/juick/service/AdsService.java11
-rw-r--r--juick-server/src/main/java/com/juick/service/AdsServiceImpl.java51
-rw-r--r--juick-server/src/test/java/com/juick/configuration/MockDataConfiguration.java4
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Home.java138
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/NewMessage.java6
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java24
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Tags.java14
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/User.java18
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/UserThread.java7
-rw-r--r--juick-www/src/main/java/ru/sape/Sape.java6
-rw-r--r--juick-www/src/main/java/ru/sape/SapePageLinks.java23
-rw-r--r--juick-www/src/main/webapp/WEB-INF/views/index.html75
-rw-r--r--juick-www/src/main/webapp/WEB-INF/views/macros/tags.html5
-rw-r--r--juick-www/src/main/webapp/WEB-INF/views/partial/footer.html2
-rw-r--r--juick-www/src/main/webapp/WEB-INF/views/partial/newmessage.html14
19 files changed, 186 insertions, 238 deletions
diff --git a/juick-api/src/main/java/com/juick/api/ApiServer.java b/juick-api/src/main/java/com/juick/api/ApiServer.java
index b59010b3..097dda58 100644
--- a/juick-api/src/main/java/com/juick/api/ApiServer.java
+++ b/juick-api/src/main/java/com/juick/api/ApiServer.java
@@ -17,12 +17,9 @@
*/
package com.juick.api;
-import org.apache.commons.lang3.BooleanUtils;
-import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.core.env.Environment;
import rocks.xmpp.core.XmppException;
import rocks.xmpp.core.session.Extension;
import rocks.xmpp.core.session.XmppSessionConfiguration;
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
index e987893d..b6ba9282 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
@@ -1,15 +1,9 @@
package com.juick.api.configuration;
-import com.juick.api.ApiServer;
-import com.juick.api.MessengerBot;
import com.juick.api.TGBot;
-import com.pengrad.telegrambot.TelegramBot;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
-import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
@@ -26,11 +20,6 @@ public class ApiAppConfiguration {
@Inject
TGBot tgBot;
- @Bean
- public ApiServer apiServer() {
- return new ApiServer();
- }
-
private static final String WS_URI = "wss://ws.juick.com/";
@Bean
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java
index 37c07434..adff42a7 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java
@@ -2,6 +2,7 @@ package com.juick.api.configuration;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.juick.api.ApiServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -22,6 +23,11 @@ import java.util.List;
@ComponentScan(basePackages = {"com.juick.api.controllers"})
public class ApiMvcConfiguration extends WebMvcConfigurationSupport {
+ @Bean
+ public ApiServer apiServer() {
+ return new ApiServer();
+ }
+
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
index 61d1b008..af1e49a4 100644
--- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
+++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
@@ -3,9 +3,10 @@ package com.juick.api.tests;
import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
-import com.juick.api.configuration.ApiAppConfiguration;
import com.juick.api.configuration.ApiMvcConfiguration;
import com.juick.api.configuration.ApiSecurityConfig;
+import com.juick.api.configuration.MessengerConfiguration;
+import com.juick.api.configuration.TelegramConfiguration;
import com.juick.configuration.MockDataConfiguration;
import com.juick.server.helpers.TagStats;
import com.juick.service.MessagesService;
@@ -44,7 +45,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@WebAppConfiguration
public class MessagesTests {
@Configuration
- @Import(value = {ApiMvcConfiguration.class, ApiAppConfiguration.class, ApiSecurityConfig.class, MockDataConfiguration.class})
+ @Import(value = {ApiMvcConfiguration.class, ApiSecurityConfig.class,
+ MockDataConfiguration.class, MessengerConfiguration.class, TelegramConfiguration.class})
static class Config {}
private MockMvc mockMvc;
diff --git a/juick-server/src/main/java/com/juick/service/AdsService.java b/juick-server/src/main/java/com/juick/service/AdsService.java
deleted file mode 100644
index f8a0f5cf..00000000
--- a/juick-server/src/main/java/com/juick/service/AdsService.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.juick.service;
-
-/**
- * Created by aalexeev on 11/13/16.
- */
-public interface AdsService {
-
- int getAdMid(int uid);
-
- int logAdMid(int uid, int mid);
-}
diff --git a/juick-server/src/main/java/com/juick/service/AdsServiceImpl.java b/juick-server/src/main/java/com/juick/service/AdsServiceImpl.java
deleted file mode 100644
index f515e437..00000000
--- a/juick-server/src/main/java/com/juick/service/AdsServiceImpl.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.juick.service;
-
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.PlatformTransactionManager;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.inject.Inject;
-import java.util.List;
-
-/**
- * Created by aalexeev on 11/13/16.
- */
-@Repository
-public class AdsServiceImpl extends BaseJdbcService implements AdsService {
-
- @Inject
- public AdsServiceImpl(JdbcTemplate jdbcTemplate) {
- super(jdbcTemplate, null);
- }
-
- @Transactional(readOnly = true)
- @Override
- public int getAdMid(final int uid) {
- List<Integer> list;
-
- if (uid > 0)
- list = getJdbcTemplate().queryForList(
- "SELECT message_id FROM ads_messages " +
- "WHERE message_id NOT IN (SELECT message_id FROM ads_messages_log WHERE user_id = ? " +
- "AND ts > UNIX_TIMESTAMP() - 60*60*24 GROUP BY message_id HAVING COUNT(*) > 2) ORDER BY RAND() LIMIT 1",
- Integer.class,
- uid);
-
- else
- list = getJdbcTemplate().queryForList(
- "SELECT message_id FROM ads_messages ORDER BY RAND() LIMIT 1",
- Integer.class);
-
- return list.isEmpty() ?
- 0 : list.get(0);
- }
-
- @Transactional
- @Override
- public int logAdMid(final int uid, final int mid) {
- return getJdbcTemplate().update(
- "INSERT INTO ads_messages_log(user_id, message_id, ts) VALUES (?, ?, UNIX_TIMESTAMP())",
- uid, mid);
- }
-}
diff --git a/juick-server/src/test/java/com/juick/configuration/MockDataConfiguration.java b/juick-server/src/test/java/com/juick/configuration/MockDataConfiguration.java
index be72f6ca..bd2f3f50 100644
--- a/juick-server/src/test/java/com/juick/configuration/MockDataConfiguration.java
+++ b/juick-server/src/test/java/com/juick/configuration/MockDataConfiguration.java
@@ -37,10 +37,6 @@ public class MockDataConfiguration {
return Mockito.mock(TelegramService.class);
}
@Bean
- AdsService adsService() {
- return Mockito.mock(AdsService.class);
- }
- @Bean
CrosspostService crosspostService() {
return Mockito.mock(CrosspostService.class);
}
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Home.java b/juick-www/src/main/java/com/juick/www/controllers/Home.java
index 4e6330a8..a36d0d09 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Home.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Home.java
@@ -18,8 +18,8 @@
package com.juick.www.controllers;
import com.juick.server.util.HttpNotFoundException;
-import com.juick.service.AdsService;
import com.juick.service.MessagesService;
+import com.juick.service.TagService;
import com.juick.service.UserService;
import com.juick.util.UserUtils;
import com.juick.util.WebUtils;
@@ -30,13 +30,17 @@ import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.CookieValue;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+import org.springframework.web.util.UriComponents;
+import ru.sape.Sape;
import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.List;
@@ -51,9 +55,9 @@ public class Home {
@Inject
MessagesService messagesService;
@Inject
- AdsService adsService;
+ TagService tagService;
@Inject
- PageTemplates templates;
+ private Sape sape;
@Inject
WebApp webApp;
@@ -89,15 +93,18 @@ public class Home {
}
@GetMapping("/")
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
- String tag = request.getParameter("tag");
+ protected String doGet(
+ @RequestParam(required = false) String tag,
+ @RequestParam(name = "show", required = false) String paramShow,
+ @RequestParam(name = "search", required = false) String paramSearch,
+ @RequestParam(name = "before", required = false, defaultValue = "0") Integer paramBefore,
+ @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie,
+ ModelMap model) throws IOException {
if (tag != null) {
- Utils.sendPermanentRedirect(response, "/tag/" + URLEncoder.encode(tag, CharEncoding.UTF_8));
+ return "redirect:/tag/" + URLEncoder.encode(tag, CharEncoding.UTF_8);
}
com.juick.User visitor = UserUtils.getCurrentUser();
- int paramBefore = NumberUtils.toInt(request.getParameter("before"), 0);
- String paramSearch = request.getParameter("search");
if (paramSearch != null && paramSearch.length() > 64) {
paramSearch = null;
}
@@ -105,7 +112,6 @@ public class Home {
String title;
List<Integer> mids;
- String paramShow = request.getParameter("show");
if (paramSearch != null) {
title = "Поиск: " + StringEscapeUtils.escapeHtml4(paramSearch);
mids = messagesService.getSearch(Utils.encodeSphinx(paramSearch), paramBefore);
@@ -119,8 +125,7 @@ public class Home {
}
} else if (paramShow.equals("top")) {
- Utils.sendPermanentRedirect(response, "/");
- return;
+ return "redirect:/";
} else if (paramShow.equals("my") && visitor != null) {
title = "Моя лента";
mids = messagesService.getMyFeed(visitor.getUid(), paramBefore);
@@ -148,83 +153,42 @@ public class Home {
mids = messagesService.getAll(0, paramBefore);
}
} else {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- return;
+ throw new HttpNotFoundException();
}
- response.setContentType("text/html; charset=UTF-8");
- try (PrintWriter out = response.getWriter()) {
- String head = StringUtils.EMPTY;
- if (paramBefore > 0 || paramShow != null) {
- head = "<meta name=\"robots\" content=\"noindex\"/>";
- }
- templates.pageHead(out, visitor, title, head);
- templates.pageNavigation(out, visitor, paramSearch);
-
- out.println("<section id=\"content\">");
-
- if (paramShow == null && paramBefore == 0) {
- out.println("<!--noindex-->");
- }
-
- if (visitor.getUid() > 0) {
- out.println("<form action=\"/post\" method=\"post\" enctype=\"multipart/form-data\">");
- out.println("<section id=\"newmessage\">");
- if (messagesService.isReadonly()) {
- out.println("<p>Комментирование временно недоступно</p>");
- } else {
- out.println(" <textarea name=\"body\" placeholder=\"Новое сообщение...\"></textarea>");
- out.println(" <div>");
- out.println(" <input type=\"text\" class=\"img\" name=\"img\" " +
- "placeholder=\"Ссылка на изображение (JPG/PNG, до 10Мб)\"/> " +
- "или <a href=\"#\">загрузить</a><br/>");
- out.println(" <input type=\"text\" class=\"tags\" name=\"tags\" " +
- "placeholder=\"Теги (через пробел)\"/><br/>");
- out.println(" <input type=\"submit\" class=\"subm\" value=\"Отправить\"/>");
- out.println(" </div>");
- }
- out.println("</section>");
- out.println("</form>");
- }
-
- if (mids.size() > 0) {
- int ad_mid = 0;
- if (paramShow == null || paramShow.equals("top") || paramShow.equals("all")) {
- int vuid = visitor.getUid();
- ad_mid = adsService.getAdMid(vuid);
- if (ad_mid > 0 && mids.indexOf(ad_mid) == -1) {
- mids.add(0, ad_mid);
- adsService.logAdMid(vuid, ad_mid);
- } else {
- ad_mid = 0;
- }
- }
-
- templates.printMessages(out, null, mids, visitor, visitor.getUid() == 0 ? 2 : 3, ad_mid);
- }
-
- if (mids.size() >= 20) {
- String nextpage = "?before=" + mids.get(mids.size() - 1);
- if (paramShow != null) {
- nextpage += "&amp;show=" + paramShow;
- }
- if (paramSearch != null) {
- nextpage += "&amp;search=" + URLEncoder.encode(paramSearch, CharEncoding.UTF_8);
- }
-
- out.println("<p class=\"page\"><a href=\"" + nextpage + "\" rel=\"prev\">Читать дальше →</a></p>");
+ String head = StringUtils.EMPTY;
+ if (paramBefore > 0 || paramShow != null) {
+ head = "<meta name=\"robots\" content=\"noindex\"/>";
+ }
+ model.addAttribute("title", title);
+ model.addAttribute("headers", head);
+ model.addAttribute("visitor", visitor);
+ model.addAttribute("readonly", messagesService.isReadonly());
+ model.addAttribute("noindex", paramShow == null && paramBefore == 0);
+ model.addAttribute("msgs", messagesService.getMessages(mids));
+ model.addAttribute("tags", tagService.getPopularTags());
+ model.addAttribute("headers", head);
+ model.addAttribute("showAdv",
+ paramShow == null && paramBefore == 0 && paramSearch == null && visitor.getUid() == 0);
+ if (mids.size() >= 20) {
+ String nextpage = "?before=" + mids.get(mids.size() - 1);
+ if (paramShow != null) {
+ nextpage += "&amp;show=" + paramShow;
}
-
- if (paramShow == null && paramBefore == 0) {
- out.println("<!--/noindex-->");
+ if (paramSearch != null) {
+ nextpage += "&amp;search=" + URLEncoder.encode(paramSearch, CharEncoding.UTF_8);
}
- out.println("</section>");
-
- templates.pageHomeColumn(out, visitor, paramShow == null && paramBefore == 0 && paramSearch == null && visitor.getUid() == 0);
-
- templates.pageFooter(request, out, visitor, true);
- templates.pageEnd(out);
+ String next = "<p class=\"page\"><a href=\"" + nextpage + "\" rel=\"prev\">Читать дальше →</a></p>";
+ model.addAttribute("next", next);
+ }
+ UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build();
+ String queryString = builder.getQuery();
+ String requestURI = builder.toUri().toString();
+ if (sape != null && visitor.getUid() == 0 && queryString == null) {
+ String links = sape.getPageLinks(requestURI, sapeCookie).render();
+ model.addAttribute("links", links);
}
+ return "views/index";
}
}
diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
index f7279fb8..d23544ba 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
@@ -185,15 +185,14 @@ public class NewMessage {
}
@PostMapping("/post")
- public void doPostMessage(HttpServletRequest request, HttpServletResponse response,
- @RequestParam(required = false) String img,
+ public void doPostMessage(HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false) String img,
+ @RequestParam String body,
@RequestParam(required = false) MultipartFile attach) throws IOException {
com.juick.User visitor = UserUtils.getCurrentUser();
if (visitor.getUid() == 0) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
- String body = request.getParameter("body");
if (body == null || body.length() < 1 || body.length() > 4096) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
@@ -318,6 +317,7 @@ public class NewMessage {
}
@PostMapping("/comment")
+ @ResponseBody
public String doPostComment(
@RequestParam(required = false, defaultValue = "0") Integer mid,
@RequestParam(required = false, defaultValue = "0") Integer rid,
diff --git a/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java b/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java
index 27ad35b8..261efff3 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java
@@ -28,9 +28,11 @@ import org.apache.commons.lang3.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
+import org.springframework.web.util.WebUtils;
import ru.sape.Sape;
import javax.inject.Inject;
+import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
@@ -163,7 +165,12 @@ public class PageTemplates {
String queryString = request.getQueryString();
String requestURI = request.getRequestURI();
if (sapeon && sape != null && (visitor.getUid() == 0 || visitor.getUid() == 1) && queryString == null) {
- String links = sape.getPageLinks(requestURI, request.getCookies()).render();
+ String cookieValue = null;
+ Cookie sapeCookie = WebUtils.getCookie(request, "sape_cookie");
+ if (sapeCookie != null) {
+ cookieValue = sapeCookie.getValue();
+ }
+ String links = sape.getPageLinks(requestURI, cookieValue).render();
if (links != null && !links.isEmpty()) {
out.print("<br/>Спонсоры: " + links);
}
@@ -290,18 +297,9 @@ public class PageTemplates {
}
}
- public void printMessages(PrintWriter out, com.juick.User user, List<Integer> mids, com.juick.User visitor, int YandexID, int ad_mid) {
+ public void printMessages(PrintWriter out, com.juick.User user, List<Integer> mids, com.juick.User visitor) {
List<com.juick.Message> msgs = messagesService.getMessages(mids);
- for (int i = 0; i < msgs.size(); i++) {
- com.juick.Message msg = msgs.get(i);
- if (msg.getMid() == ad_mid) {
- msgs.remove(i);
- msgs.add(0, msg);
- break;
- }
- }
-
List<Integer> blUIDs = new ArrayList<Integer>(20);
if (visitor != null) {
for (Message msg : msgs) {
@@ -320,10 +318,6 @@ public class PageTemplates {
if (msg.getPrivacy() < 0) {
tagsStr += "<a>friends</a>";
}
- if (msg.getMid() == ad_mid) {
- tagsStr += "<a>реклама</a>";
- }
-
String txt;
if (msg.getTags().stream().anyMatch(t -> t.getName().equals("code"))) {
txt = MessageUtils.formatMessageCode(msg.getText());
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Tags.java b/juick-www/src/main/java/com/juick/www/controllers/Tags.java
index 3116fd93..bc2679ef 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Tags.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Tags.java
@@ -17,7 +17,6 @@
*/
package com.juick.www.controllers;
-import com.juick.service.AdsService;
import com.juick.service.MessagesService;
import com.juick.service.TagService;
import com.juick.util.UserUtils;
@@ -52,8 +51,6 @@ public class Tags {
@Inject
TagService tagService;
@Inject
- AdsService adsService;
- @Inject
PageTemplates templates;
@GetMapping("/tag/{tagName}")
@@ -104,16 +101,7 @@ public class Tags {
out.println("<section id=\"content\">");
if (mids.size() > 0) {
- int vuid = visitor.getUid();
- int ad_mid = adsService.getAdMid(vuid);
- if (ad_mid > 0 && mids.indexOf(ad_mid) == -1) {
- mids.add(0, ad_mid);
- adsService.logAdMid(vuid, ad_mid);
- } else {
- ad_mid = 0;
- }
-
- templates.printMessages(out, null, mids, visitor, visitor_uid == 0 ? 2 : 3, ad_mid);
+ templates.printMessages(out, null, mids, visitor);
}
if (mids.size() >= 20) {
diff --git a/juick-www/src/main/java/com/juick/www/controllers/User.java b/juick-www/src/main/java/com/juick/www/controllers/User.java
index 3e566df9..bc5ebfe3 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/User.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/User.java
@@ -18,6 +18,7 @@
package com.juick.www.controllers;
import com.juick.server.helpers.TagStats;
+import com.juick.server.util.HttpForbiddenException;
import com.juick.service.MessagesService;
import com.juick.service.TagService;
import com.juick.service.UserService;
@@ -28,10 +29,11 @@ import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestParam;
import javax.inject.Inject;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@@ -150,7 +152,7 @@ public class User {
StringEscapeUtils.escapeHtml4(paramTag.getName()) + "</b></a></p>");
}
- templates.printMessages(out, user, mids, visitor, visitor.getUid() == 0 ? 4 : 5, 0);
+ templates.printMessages(out, user, mids, visitor);
if (mids.size() >= 20) {
String nextpage = "?before=" + mids.get(mids.size() - 1);
@@ -202,12 +204,11 @@ public class User {
@GetMapping("/{uname}/friends")
protected void doGetFriends(HttpServletRequest request, HttpServletResponse response,
- @PathVariable String uname) throws ServletException, IOException {
+ @PathVariable String uname) throws IOException {
com.juick.User user = userService.getUserByName(uname);
com.juick.User visitor = UserUtils.getCurrentUser();
if (visitor.isBanned()) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- return;
+ throw new HttpForbiddenException();
}
response.setContentType("text/html; charset=UTF-8");
@@ -240,12 +241,11 @@ public class User {
@GetMapping("/{uname}/readers")
protected void doGetReaders(HttpServletRequest request, HttpServletResponse response,
- @PathVariable String uname) throws ServletException, IOException {
+ @PathVariable String uname) throws IOException {
com.juick.User user = userService.getUserByName(uname);
com.juick.User visitor = UserUtils.getCurrentUser();
if (visitor.isBanned()) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- return;
+ throw new HttpForbiddenException();
}
response.setContentType("text/html; charset=UTF-8");
diff --git a/juick-www/src/main/java/com/juick/www/controllers/UserThread.java b/juick-www/src/main/java/com/juick/www/controllers/UserThread.java
index 0899f928..25460666 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/UserThread.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/UserThread.java
@@ -29,12 +29,9 @@ import com.juick.www.WebApp;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.*;
import javax.inject.Inject;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@@ -63,7 +60,7 @@ public class UserThread {
@GetMapping("/{uname}/{mid}")
protected void doGetThread(HttpServletRequest request, HttpServletResponse response,
@PathVariable String uname,
- @PathVariable int mid) throws ServletException, IOException {
+ @PathVariable int mid) throws IOException {
com.juick.User visitor = UserUtils.getCurrentUser();
if (!messagesService.canViewThread(mid, visitor.getUid())) {
diff --git a/juick-www/src/main/java/ru/sape/Sape.java b/juick-www/src/main/java/ru/sape/Sape.java
index c00054ae..38577c45 100644
--- a/juick-www/src/main/java/ru/sape/Sape.java
+++ b/juick-www/src/main/java/ru/sape/Sape.java
@@ -3,8 +3,6 @@
*/
package ru.sape;
-import javax.servlet.http.Cookie;
-
public class Sape {
private final String sapeUser;
@@ -19,7 +17,7 @@ public class Sape {
}
public boolean debug = false;
- public SapePageLinks getPageLinks(String requestUri, Cookie[] cookies) {
- return new SapePageLinks(sapePageLinkConnection, sapeUser, requestUri, cookies, debug);
+ public SapePageLinks getPageLinks(String requestUri, String cookie) {
+ return new SapePageLinks(sapePageLinkConnection, sapeUser, requestUri, cookie, debug);
}
}
diff --git a/juick-www/src/main/java/ru/sape/SapePageLinks.java b/juick-www/src/main/java/ru/sape/SapePageLinks.java
index 458358b8..e89b4e71 100644
--- a/juick-www/src/main/java/ru/sape/SapePageLinks.java
+++ b/juick-www/src/main/java/ru/sape/SapePageLinks.java
@@ -1,19 +1,18 @@
package ru.sape;
import java.util.*;
-import javax.servlet.http.Cookie;
public class SapePageLinks {
private boolean showCode;
- public SapePageLinks(SapeConnection sapeConnection, String sapeUser, String requestUri, Cookie[] cookies) {
- this(sapeConnection, sapeUser, requestUri, cookies, false);
+ public SapePageLinks(SapeConnection sapeConnection, String sapeUser, String requestUri, String sapeCookie) {
+ this(sapeConnection, sapeUser, requestUri, sapeCookie, false);
}
@SuppressWarnings("unchecked")
- public SapePageLinks(SapeConnection sapeConnection, String sapeUser, String requestUri, Cookie[] cookies, boolean showCode) {
- if (sapeUser.equals(getCookieValue(cookies, "sape_cookie"))) {
+ public SapePageLinks(SapeConnection sapeConnection, String sapeUser, String requestUri, String sapeCookie, boolean showCode) {
+ if (sapeUser.equals(sapeCookie)) {
showCode = true;
}
@@ -74,18 +73,4 @@ public class SapePageLinks {
return s.toString();
}
-
- private static String getCookieValue(Cookie[] cookies, String name) {
- if (cookies == null) {
- return null;
- }
-
- for (Cookie cookie : cookies) {
- if (cookie.getName().equals(name)) {
- return cookie.getValue();
- }
- }
-
- return null;
- }
}
diff --git a/juick-www/src/main/webapp/WEB-INF/views/index.html b/juick-www/src/main/webapp/WEB-INF/views/index.html
new file mode 100644
index 00000000..09297ef9
--- /dev/null
+++ b/juick-www/src/main/webapp/WEB-INF/views/index.html
@@ -0,0 +1,75 @@
+{% extends "layouts/content" %}
+{% import "views/macros/tags" %}
+{% block content %}
+{% if noindex %}
+<!--noindex-->
+{% endif %}
+{% if visitor.getUid() > 0 %}
+{% include "views/partial/newmessage" %}
+{% endif %}
+{% for msg in msgs %}
+<article data-mid="{{ msg.getMid() }}">
+ <header class="h">@<a href="/{{ msg.getUser().getName() }}/">{{ msg.getUser().getName() }}</a>:
+ <div class="msg-avatar"><a href="/{{ msg.getUser().getName() }}/">
+ <img src="//i.juick.com/a/{{ msg.getUser().getUid() }}.png" alt="{{ msg.getUser().getName() }}"/></a></div>
+ <div class="msg-menu"><a href="#"></a></div>
+ <div class="msg-ts">
+ <a href="/{{ msg.getUser().getName() }}/{{ msg.getMid() }}">
+ <time>
+ {{ msg.getDate() }}
+ </time>
+ </a>
+ </div>
+ <div class="msg-tags">
+ {{ tags(msg.getUser().getName(), msg.getTags()) }}
+ </div>
+ </header>
+
+ {%if msg.AttachmentType is not empty %}
+ <p class="ir"><a href="//i.juick.com/photos-512/{{ msg.getMid() }}.{{ msg.AttachmentType }}"
+ onclick="return showPhotoDialog('{{ msg.getMid() }}.{{ msg.AttachmentType }}')">
+ <img src="//i.juick.com/photos-512/{{ msg.getMid() }}.{{ msg.AttachmentType }}" alt=""/></a>
+ </p>
+ {% endif %}
+ <p>{{ msg.getText() | raw }}</p>
+ {%if msg.AttachmentType is not empty %}
+ <div class="irbr"></div>
+ {% endif %}
+ {% if not readonly %}
+ <nav class="l">
+ <a href="#" class="a-like">Мне нравится</a>
+ {% if msg.VisitorCanComment %}
+ <a href="#" class="a-comment">Комментировать</a>
+ {% endif %}
+ {% if msg.FriendsOnly %}
+ <a href="#" class="a-privacy">Открыть доступ</a>
+ {% endif %}
+ {% if isModerator %}
+ <a href="#" class="a-popular-plus">+</a>
+ <a href="#" class="a-popular-minus">-</a>
+ <a href="#" class="a-popular-delete">x</a>
+ {% endif %}
+ </nav>
+ {% endif %}
+ <nav class="s">
+ {% if msg.Likes > 0 %}
+ <a href="/{{ msg.getUser().getName() }}/{{ msg.getMid() }}" class="likes">
+ <i data-icon="ei-heart" data-size="s"></i>&nbsp;{{ msg.Likes }}</a>
+ {% endif %}
+ {% if msg.Replies > 0 %}
+ <a href="/{{ msg.getUser().getName() }}/{{ msg.getMid() }}" class="replies">
+ <i data-icon="ei-comment" data-size="s"></i>&nbsp;&nbsp;{{ msg.Replies }}</a>
+ {% endif %}
+ </nav>
+</article>
+{% endfor %}
+{% if next is not empty %}
+{{ next | raw }}
+{% endif %}
+{% endblock %}
+{% block "column" %}
+{% include "views/partial/homecolumn" %}
+{% if noindex %}
+<!--/noindex-->
+{% endif %}
+{% endblock %} \ No newline at end of file
diff --git a/juick-www/src/main/webapp/WEB-INF/views/macros/tags.html b/juick-www/src/main/webapp/WEB-INF/views/macros/tags.html
new file mode 100644
index 00000000..ffd81ddd
--- /dev/null
+++ b/juick-www/src/main/webapp/WEB-INF/views/macros/tags.html
@@ -0,0 +1,5 @@
+{% macro tags(uname="", tagsList) %}
+{% for tag in tagsList %}
+<a href="/{{ uname }}/?tag={{ tag }}">{{ tag }}</a>
+{% endfor %}
+{% endmacro %} \ No newline at end of file
diff --git a/juick-www/src/main/webapp/WEB-INF/views/partial/footer.html b/juick-www/src/main/webapp/WEB-INF/views/partial/footer.html
index 71d675de..491cf140 100644
--- a/juick-www/src/main/webapp/WEB-INF/views/partial/footer.html
+++ b/juick-www/src/main/webapp/WEB-INF/views/partial/footer.html
@@ -11,7 +11,7 @@
<a href="https://www.facebook.com/JuickCom" rel="nofollow" class="ico32-fb">Facebook</a>
</div>
<div id="footer-left">juick.com &copy; 2008-2017
- {% if links %}
+ {% if links is not empty %}
<br/>{{ i18n("messages","label.sponsors") }}: {{ links }}
{% endif %}
</div>
diff --git a/juick-www/src/main/webapp/WEB-INF/views/partial/newmessage.html b/juick-www/src/main/webapp/WEB-INF/views/partial/newmessage.html
new file mode 100644
index 00000000..452d1267
--- /dev/null
+++ b/juick-www/src/main/webapp/WEB-INF/views/partial/newmessage.html
@@ -0,0 +1,14 @@
+<form action="/post" method="post" enctype="multipart/form-data">
+ <section id="newmessage">
+ {% if readonly %}
+ <p>Комментирование временно недоступно</p>
+ {% else %}
+ <textarea name="body" placeholder="Новое сообщение..."></textarea>
+ <div>
+ <input type="text" class="img" name="img" placeholder="Ссылка на изображение (JPG/PNG, до 10Мб)"/> или <a href="#">загрузить</a><br/>
+ <input type="text" class="tags" name="tags" placeholder="Теги (через пробел)"/><br/>
+ <input type="submit" class="subm" value="Отправить"/>
+ </div>
+ {% endif %}
+ </section>
+</form> \ No newline at end of file