X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FSoneTemplatePage.java;h=e18e1a418e6b429a0db56b4863dfa45cf8697ac5;hb=e1b8776c14874e9ae59b614b542255f72290dff1;hp=9eacaf858db62bee05542cca2ad297c22e161daa;hpb=c5e641893a2656ebf2c2c8c369fe75eaf3061b52;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index 9eacaf8..e18e1a4 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -1,5 +1,5 @@ /* - * Sone - SoneTemplatePage.java - Copyright © 2010 David Roden + * Sone - SoneTemplatePage.java - Copyright © 2010–2013 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,18 +21,22 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.main.SonePlugin; +import net.pterodactylus.sone.notify.ListNotificationFilters; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.sone.web.page.FreenetTemplatePage; -import net.pterodactylus.sone.web.page.Page; -import net.pterodactylus.util.collection.ListBuilder; -import net.pterodactylus.util.collection.MapBuilder; +import net.pterodactylus.util.notify.Notification; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; -import freenet.clients.http.SessionManager.Session; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + import freenet.clients.http.ToadletContext; import freenet.support.api.HTTPRequest; @@ -119,7 +123,6 @@ public class SoneTemplatePage extends FreenetTemplatePage { this.pageTitleKey = pageTitleKey; this.webInterface = webInterface; this.requireLogin = requireLogin; - template.getInitialContext().set("webInterface", webInterface); } // @@ -127,35 +130,6 @@ public class SoneTemplatePage extends FreenetTemplatePage { // /** - * Returns the current session, creating a new session if there is no - * current session. - * - * @param toadletContenxt - * The toadlet context - * @return The current session, or {@code null} if there is no current - * session - */ - protected Session getCurrentSession(ToadletContext toadletContenxt) { - return webInterface.getCurrentSession(toadletContenxt); - } - - /** - * Returns the current session, creating a new session if there is no - * current session and {@code create} is {@code true}. - * - * @param toadletContenxt - * The toadlet context - * @param create - * {@code true} to create a new session if there is no current - * session, {@code false} otherwise - * @return The current session, or {@code null} if there is no current - * session - */ - protected Session getCurrentSession(ToadletContext toadletContenxt, boolean create) { - return webInterface.getCurrentSession(toadletContenxt, create); - } - - /** * Returns the currently logged in Sone. * * @param toadletContext @@ -202,7 +176,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { * {@inheritDoc} */ @Override - protected String getPageTitle(Request request) { + protected String getPageTitle(FreenetRequest request) { if (pageTitleKey != null) { return webInterface.getL10n().getString(pageTitleKey); } @@ -213,8 +187,8 @@ public class SoneTemplatePage extends FreenetTemplatePage { * {@inheritDoc} */ @Override - protected List> getAdditionalLinkNodes(Request request) { - return new ListBuilder>().add(new MapBuilder().put("rel", "search").put("type", "application/opensearchdescription+xml").put("title", "Sone").put("href", "http://" + request.getHttpRequest().getHeader("host") + "/Sone/OpenSearch.xml").get()).get(); + protected List> getAdditionalLinkNodes(FreenetRequest request) { + return ImmutableList.> builder().add(ImmutableMap. builder().put("rel", "search").put("type", "application/opensearchdescription+xml").put("title", "Sone").put("href", "http://" + request.getHttpRequest().getHeader("host") + "/Sone/OpenSearch.xml").build()).build(); } /** @@ -247,9 +221,11 @@ public class SoneTemplatePage extends FreenetTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); - templateContext.set("currentSone", getCurrentSone(request.getToadletContext(), false)); + Sone currentSone = getCurrentSone(request.getToadletContext(), false); + templateContext.set("core", webInterface.getCore()); + templateContext.set("currentSone", currentSone); templateContext.set("localSones", webInterface.getCore().getLocalSones()); templateContext.set("request", request); templateContext.set("currentVersion", SonePlugin.VERSION); @@ -257,13 +233,17 @@ public class SoneTemplatePage extends FreenetTemplatePage { templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition()); templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion()); templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate()); + List notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone); + Collections.sort(notifications, Notification.CREATED_TIME_SORTER); + templateContext.set("notifications", notifications); + templateContext.set("notificationHash", notifications.hashCode()); } /** * {@inheritDoc} */ @Override - protected String getRedirectTarget(Page.Request request) { + protected String getRedirectTarget(FreenetRequest request) { if (requiresLogin() && (getCurrentSone(request.getToadletContext(), false) == null)) { HTTPRequest httpRequest = request.getHttpRequest(); String originalUrl = httpRequest.getPath(); @@ -293,7 +273,18 @@ public class SoneTemplatePage extends FreenetTemplatePage { * {@inheritDoc} */ @Override + protected boolean isFullAccessOnly() { + return webInterface.getCore().getPreferences().isRequireFullAccess(); + } + + /** + * {@inheritDoc} + */ + @Override public boolean isEnabled(ToadletContext toadletContext) { + if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) { + return false; + } if (requiresLogin()) { return getCurrentSone(toadletContext, false) != null; }