diff options
20 files changed, 267 insertions, 83 deletions
diff --git a/juick-server/src/main/resources/juick.conf.example b/juick-server/src/main/resources/juick.conf.example index 284d86a5..c91a42d2 100644 --- a/juick-server/src/main/resources/juick.conf.example +++ b/juick-server/src/main/resources/juick.conf.example @@ -33,6 +33,14 @@ web_domain=juick.com auth_cookie_name=hash +### Template Settings (web page templates) +# Show sponsors block +template.showSponsors=false + +# Show Sape scripts +template.showSape=true + + twitter_consumer_key= twitter_consumer_secret= diff --git a/juick-server/src/test/java/.empty b/juick-server/src/test/java/.empty new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/juick-server/src/test/java/.empty diff --git a/juick-server/src/test/resources/.empty b/juick-server/src/test/resources/.empty new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/juick-server/src/test/resources/.empty diff --git a/juick-spring-www/build.gradle b/juick-spring-www/build.gradle index f48f9d17..e405506b 100644 --- a/juick-spring-www/build.gradle +++ b/juick-spring-www/build.gradle @@ -30,6 +30,7 @@ dependencies { compile "org.thymeleaf:thymeleaf:${thymeleafVersion}" compile "org.thymeleaf:thymeleaf-spring4:${thymeleafVersion}" compile "org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.0.RELEASE" + compile "nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.1.1" compile "org.springframework.security:spring-security-web:${springSecurityVersion}" compile "org.springframework.security:spring-security-config:${springSecurityVersion}" testRuntime "org.thymeleaf:thymeleaf-testing:3.0.1.RELEASE" diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java new file mode 100644 index 00000000..5fb7848d --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java @@ -0,0 +1,37 @@ +package com.juick.www.configuration; + +import com.juick.www.settings.TemplateSettingsHolder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.core.env.Environment; + +import javax.annotation.Resource; + +/** + * Created by aalexeev on 11/22/16. + */ +@Configuration +@PropertySource("classpath:juick.conf") +public class WebAppConfiguration { + @Resource + private Environment env; + + @Bean + public ResourceBundleMessageSource messageSource() { + ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); + + messageSource.setBasenames("messages", "errors"); + messageSource.setDefaultEncoding("UTF-8"); + messageSource.setFallbackToSystemLocale(false); + messageSource.setUseCodeAsDefaultMessage(true); + + return messageSource; + } + + @Bean + public TemplateSettingsHolder settingsHolder() { + return new TemplateSettingsHolder(env); + } +} diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java index 6abb9f79..d5a3bbef 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwInitializer.java @@ -16,7 +16,8 @@ public class WwwInitializer extends AbstractAnnotationConfigDispatcherServletIni @Override protected Class<?>[] getRootConfigClasses() { - return new Class<?>[]{DataConfiguration.class, SearchConfiguration.class, WebSecurityConfig.class}; + return new Class<?>[]{ + WebAppConfiguration.class, DataConfiguration.class, SearchConfiguration.class, WebSecurityConfig.class}; } @Override diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java index 869fd651..089e43a8 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java @@ -2,11 +2,13 @@ package com.juick.www.configuration; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.juick.www.formatter.DateFormatter; +import nz.net.ultraq.thymeleaf.LayoutDialect; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.format.FormatterRegistry; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -57,6 +59,9 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { // across different data types, so this flag is "false" by default // for safer backwards compatibility. templateEngine.setEnableSpringELCompiler(true); + // Thymeleaf Layout Dialect + templateEngine.addDialect(new LayoutDialect()); + return templateEngine; } @@ -93,17 +98,7 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { .addResourceLocations("/") .resourceChain(true) .addResolver(new PathResourceResolver()); - } - - @Bean - public ResourceBundleMessageSource messageSource() { - ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); - - messageSource.setBasenames("messages", "errors"); - messageSource.setDefaultEncoding("UTF-8"); - messageSource.setFallbackToSystemLocale(false); - - return messageSource; + registry.addResourceHandler("/static/**").addResourceLocations("/static/"); } @Override @@ -114,4 +109,14 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { return result; } + + @Override + public void addFormatters(final FormatterRegistry registry) { + registry.addFormatter(dateFormatter()); + } + + @Bean + public DateFormatter dateFormatter() { + return new DateFormatter(); + } } diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/DivideByZeroController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/DivideByZeroController.java deleted file mode 100644 index 07266adc..00000000 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/DivideByZeroController.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.juick.www.controllers; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * Created by aalexeev on 11/21/16. - */ -@Controller -public class DivideByZeroController { - - @RequestMapping("/divideByZero") - public String getPage() { - return "divideByZero"; - } -} diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java index b8c25135..59ab52c2 100644 --- a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java +++ b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java @@ -55,10 +55,10 @@ public class ShowMessageController { if (isPostNumber && anything.equals(Integer.toString(messageId))) { if (messageId > 0) { com.juick.User author = messagesService.getMessageAuthor(messageId); + if (author != null) return "redirect:/" + author.getName() + "/" + anything; - } else if (messageId == 0) - return "forward:/divideByZero.html"; + } model.addAttribute("messageId", anything); diff --git a/juick-spring-www/src/main/java/com/juick/www/formatter/DateFormatter.java b/juick-spring-www/src/main/java/com/juick/www/formatter/DateFormatter.java new file mode 100644 index 00000000..74596fc5 --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/formatter/DateFormatter.java @@ -0,0 +1,43 @@ +package com.juick.www.formatter; + +import org.springframework.context.MessageSource; +import org.springframework.format.Formatter; + +import javax.annotation.Resource; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +/** + * Created by aalexeev on 11/22/16. + */ +public class DateFormatter implements Formatter<Date> { + @Resource + private MessageSource messageSource; + + + public DateFormatter() { + super(); + } + + @Override + public Date parse(final String text, final Locale locale) throws ParseException { + final SimpleDateFormat dateFormat = createDateFormat(locale); + return dateFormat.parse(text); + } + + @Override + public String print(final Date object, final Locale locale) { + final SimpleDateFormat dateFormat = createDateFormat(locale); + return dateFormat.format(object); + } + + private SimpleDateFormat createDateFormat(final Locale locale) { + final String format = this.messageSource.getMessage("date.format", null, locale); + final SimpleDateFormat dateFormat = new SimpleDateFormat(format); + dateFormat.setLenient(false); + return dateFormat; + } + +} diff --git a/juick-spring-www/src/main/java/com/juick/www/settings/TemplateSettingsHolder.java b/juick-spring-www/src/main/java/com/juick/www/settings/TemplateSettingsHolder.java new file mode 100644 index 00000000..c6df73da --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/settings/TemplateSettingsHolder.java @@ -0,0 +1,35 @@ +package com.juick.www.settings; + +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.springframework.core.env.Environment; + +/** + * Created by aalexeev on 11/22/16. + */ +public class TemplateSettingsHolder { + private final boolean showSponsors; + private final boolean showSape; + + + public TemplateSettingsHolder(Environment settingsEnv) { + showSponsors = BooleanUtils.toBoolean(settingsEnv.getProperty("template.showSponsors", "false")); + showSape = BooleanUtils.toBoolean(settingsEnv.getProperty("template.showSape", "true")); + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("showSponsors", showSponsors) + .append("showSape", showSape) + .toString(); + } + + public boolean isShowSponsors() { + return showSponsors; + } + + public boolean isShowSape() { + return showSape; + } +} diff --git a/juick-spring-www/src/main/resources/messages.properties b/juick-spring-www/src/main/resources/messages.properties index 9749ddef..29715d5d 100644 --- a/juick-spring-www/src/main/resources/messages.properties +++ b/juick-spring-www/src/main/resources/messages.properties @@ -1 +1,10 @@ -return.toMain=Вернуться на главную
\ No newline at end of file +date.format=dd.MM.yyyy + +link.settings = Настройки +link.returnToMain =Вернуться на главную +link.contacts=Контакты +link.help=Помощь +link.adv=Реклама + +label.sponsor=Спонсор +label.sponsors=Спонсоры
\ No newline at end of file diff --git a/juick-spring-www/src/main/resources/messages_en.properties b/juick-spring-www/src/main/resources/messages_en.properties index 67fbb7d7..9efa2cbb 100644 --- a/juick-spring-www/src/main/resources/messages_en.properties +++ b/juick-spring-www/src/main/resources/messages_en.properties @@ -1 +1,10 @@ -return.toMain=Return to main
\ No newline at end of file +date.format=MM/dd/yyyy + +link.settings=Settings +link.returnToMain=Return to home +link.contacts=Contacts +link.help=Help +link.adv=Advertisement + +label.sponsor=Sponsor +label.sponsors=Sponsors
\ No newline at end of file diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/divideByZero.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/divideByZero.html deleted file mode 100644 index 7e03d74a..00000000 --- a/juick-spring-www/src/main/webapp/WEB-INF/templates/divideByZero.html +++ /dev/null @@ -1,11 +0,0 @@ -<!DOCTYPE html> -<html xmlns:th="http://www.thymeleaf.org"> -<head> - <meta charset="UTF-8"> - <title>Title</title> -</head> -<body> -00000000000000000000000000000000000000000000000000000000000000000000000 - -</body> -</html>
\ No newline at end of file diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html index a5c5b348..5687985d 100644 --- a/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html +++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/index.html @@ -1,11 +1,15 @@ <!DOCTYPE html> -<html xmlns:th="http://www.thymeleaf.org"> +<html xmlns:th="http://www.thymeleaf.org" + xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" + layout:decorate="~{layout/mainLayout}"> <head> - <meta charset="UTF-8"> - <title>Title</title> + <title>Главная страница</title> </head> + <body> -<h1>Index page</h1> +<section layout:fragment="content"> + <p>Главная страница !</p> +</section> </body> </html>
\ No newline at end of file diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/footer.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/footer.html deleted file mode 100644 index 1182e61d..00000000 --- a/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/footer.html +++ /dev/null @@ -1,3 +0,0 @@ -<!DOCTYPE html> -<html xmlns:th="http://www.thymeleaf.org"> -</html>
\ No newline at end of file diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/mainLayout.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/mainLayout.html index 659a3fb0..34891b45 100644 --- a/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/mainLayout.html +++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/mainLayout.html @@ -1,12 +1,65 @@ <!DOCTYPE html> -<html xmlns:th="http://www.thymeleaf.org"> +<html xmlns:th="http://www.thymeleaf.org" + xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> <head> - <meta charset="utf-8" /> - <meta http-equiv="X-UA-Compatible" content="IE=edge" /> - <script type="text/javascript" src="/scripts.js"></script> - <link rel="stylesheet" type="text/css" href="/style.css" /> + <meta charset="UTF-8" /> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/> + + <link rel="stylesheet" href="/style.css" th:href="@{/style.css}"/> + + <script type="text/javascript" src="/scripts.js" th:href="@{/scripts.js}"></script> + + <title>Layout title</title> + + <link rel="icon" href="//i.juick.com/favicon.png"/> + <!--[if lt IE 9 & (!IEMobile 7)]> + <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script> + <![endif]--> </head> + <body> +<section layout:fragment="content"> + <p>Page content goes here</p> +</section> + +<footer> + <div layout:fragment="custom-footer">Custom footer here</div> + <div id="footer"> + <div id="footer-right"> + <a href="/settings" th:href="@{/settings}" rel="nofollow" th:text="#{link.settings}">Настройки</a> · + <a href="/help/contacts" th:href="@{/help/contacts}" rel="nofollow" th:text="#{link.contacts}">Контакты</a> · + <a href="/help/" th:href="@{/help}" rel="nofollow" th:text="#{link.help}">Справка</a> · + <a href="/help/adv" th:href="@{/help/adv}" rel="nofollow" th:text="#{link.adv}">Реклама</a> + </div> + <div id="footer-social"> + <a href="https://twitter.com/Juick" rel="nofollow" class="ico32-twi">Twitter</a> + <a href="https://vk.com/juick" rel="nofollow" class="ico32-vk">VK</a> + <a href="https://www.facebook.com/JuickCom" rel="nofollow" class="ico32-fb">Facebook</a> + </div> + <div id="footer-left"> + juick.com © 2008-2016 + <div th:replace="${@settingsHolder.isShowSponsors()} ? ~{layout/sponsors :: sponsors} : _"></div> + </div> + </div> + <script> + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + ga('create','UA-385578-4','juick.com'); + ga('require','displayfeatures'); + ga('send','pageview'); + </script> + <script th:if="${@settingsHolder.isShowSape()}"> + var _acic={dataProvider:10}; + (function(){ + var e=document.createElement('script');e.type='text/javascript';e.async=true;e.src='//www2.aci'+'nt.net/aci.js'; + var t=document.getElementsByTagName('script')[0];t.parentNode.insertBefore(e,t); + })(); + </script> + </div> +</footer> </body> </html>
\ No newline at end of file diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/sponsors.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/sponsors.html new file mode 100644 index 00000000..6c68a867 --- /dev/null +++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/layout/sponsors.html @@ -0,0 +1,8 @@ +<!DOCTYPE html> +<html xmlns:th="http://www.thymeleaf.org"> +<body> +<div th:fragment="sponsors"> + <span th:text="#{label.sponsors}">Спонсоры:</span> +</div> +</body> +</html>
\ No newline at end of file diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/postNotFound.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/postNotFound.html index c8712c9f..4162aa8b 100644 --- a/juick-spring-www/src/main/webapp/WEB-INF/templates/postNotFound.html +++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/postNotFound.html @@ -1,22 +1,23 @@ <!DOCTYPE html> -<html xmlns:th="http://www.thymeleaf.org"> +<html xmlns:th="http://www.thymeleaf.org" + xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" + layout:decorate="~{layout/mainLayout}"> <head> - <meta charset="UTF-8"> <title th:text="#{error.pageNotFound}">Страница не найдена</title> - <link rel="stylesheet" type="text/css" href="/style.css" th:href="@{/style.css}"/> </head> - <body> -<div id="pagetitle"> - <h1 th:text="#{error.pageNotFound}">Страница не найдена</h1> -</div> +<section layout:fragment="content"> + <div id="pagetitle"> + <h1 th:text="#{error.pageNotFound}">Страница не найдена</h1> + </div> -<div id="wrapper"> - <p th:text="#{errors.pageNotFound.extended(${messageId})}">Похоже, пользователь удалил страницу, возможна она и не была создана.</p> -</div> -<div> - <a th:href="@{/}" href="/"><span th:text="#{return.toMain}">Вернуться на главную</span></a> -</div> + <div id="wrapper"> + <p th:text="#{errors.pageNotFound.extended(${messageId})}">Похоже, пользователь удалил страницу, возможна она и не была создана.</p> + </div> + <div> + <a th:href="@{/}" href="/"><span th:text="#{link.returnToMain}">Вернуться на главную</span></a> + </div> +</section> </body> </html>
\ No newline at end of file diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/userNotFound.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/userNotFound.html index 300b7730..de1a97a0 100644 --- a/juick-spring-www/src/main/webapp/WEB-INF/templates/userNotFound.html +++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/userNotFound.html @@ -1,22 +1,22 @@ <!DOCTYPE html> -<html xmlns:th="http://www.thymeleaf.org"> +<html xmlns:th="http://www.thymeleaf.org" + xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" + layout:decorate="~{layout/mainLayout}"> <head> - <meta charset="UTF-8"> <title th:text="#{error.userNotFound}">Пользователь не найден</title> - <link rel="stylesheet" type="text/css" href="/style.css" th:href="@{/style.css}"/> </head> - <body> +<section layout:fragment="content"> + <div id="pagetitle"> + <h1 th:text="#{error.userNotFound}">Пользователь не найден</h1> + </div> -<div id="pagetitle"> - <h1 th:text="#{error.userNotFound}">Пользователь не найден</h1> -</div> - -<div id="wrapper"> - <p th:text="#{errors.userNotFound.extended(${userName})}">Пользователь не найден.</p> -</div> -<div> - <a th:href="@{/}" href="/"><span th:text="#{return.toMain}">Вернуться на главную</span></a> -</div> + <div id="wrapper"> + <p th:text="#{errors.userNotFound.extended(${userName})}">Пользователь не найден.</p> + </div> + <div> + <a th:href="@{/}" href="/"><span th:text="#{link.returnToMain}">Вернуться на главную</span></a> + </div> +</section> </body> </html>
\ No newline at end of file |