From c71e860755a06aa0eb5a5b6483df461f4a23ccd3 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 20 Oct 2020 23:45:02 +0300 Subject: Revert "/user/tag? => /user/search?" This reverts commit aa0070140058603de7d60c8e039bb4a535399f3a. --- src/main/java/com/juick/www/controllers/Site.java | 26 +++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/juick') diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java index dc037073..57115629 100644 --- a/src/main/java/com/juick/www/controllers/Site.java +++ b/src/main/java/com/juick/www/controllers/Site.java @@ -185,6 +185,7 @@ public class Site { @RequestParam(required = false, name = "page", defaultValue = "0") Integer page, @PathVariable String uname, @RequestParam(required = false, defaultValue = "0") Integer before, + @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie, ModelMap model) { User user = userService.getUserByName(uname); if (user.isBanned() || user.isAnonymous()) { @@ -194,8 +195,17 @@ public class Site { List mids; + Tag paramTag = null; if (paramTagStr != null) { - paramSearch = paramTagStr; + if (paramTagStr.length() < 64) { + paramTag = tagService.getTag(paramTagStr, false); + } + if (paramTag == null) { + throw new HttpNotFoundException(); + } else if (!paramTag.getName().equals(paramTagStr)) { + String url = user.getName() + "/?tag=" + URLEncoder.encode(paramTag.getName(), StandardCharsets.UTF_8); + return "redirect:/" + url; + } } if (paramSearch != null && paramSearch.length() > 64) { paramSearch = null; @@ -212,7 +222,10 @@ public class Site { String title; if (paramShow == null) { - if (paramSearch != null) { + if (paramTag != null) { + title = "Блог " + user.getName() + ": *" + StringEscapeUtils.escapeHtml4(paramTag.getName()); + mids = messagesService.getUserTag(user.getUid(), paramTag.TID, privacy, before); + } else if (paramSearch != null) { title = "Блог " + user.getName() + ": " + StringEscapeUtils.escapeHtml4(paramSearch); mids = messagesService.getUserSearch(visitor, user.getUid(), WebUtils.encodeSphinx(paramSearch), privacy, page); } else { @@ -232,7 +245,9 @@ public class Site { String head = ""; head += "\n"; - if (before > 0 || paramShow != null) { + if (paramTag != null && tagService.getTagNoIndex(paramTag.TID)) { + head += ""; + } else if (before > 0 || paramShow != null) { head += ""; } model.addAttribute("pageUrl", "http://juick.com/" + user.getName()); @@ -241,7 +256,7 @@ public class Site { model.addAttribute("visitor", visitor); model.addAttribute("noindex", paramShow == null && before == 0); fillUserModel(model, user, visitor); - model.addAttribute("paramTag", paramSearch); + model.addAttribute("paramTag", paramTag); List msgs = messagesService.getMessages(visitor, mids); msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser()))); if (!visitor.isAnonymous()) { @@ -261,6 +276,9 @@ public class Site { if (paramSearch != null) { nextpage += "&search=" + URLEncoder.encode(paramSearch, StandardCharsets.UTF_8); } + if (paramTag != null) { + nextpage += "&tag=" + URLEncoder.encode(paramTag.getName(), StandardCharsets.UTF_8); + } model.addAttribute("nextpage", nextpage); } return "views/blog"; -- cgit v1.2.3