Show linked images under posts and replies
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 11 Nov 2016 19:20:31 +0000 (20:20 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 11 Nov 2016 19:20:31 +0000 (20:20 +0100)
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/static/css/sone.css
src/main/resources/templates/include/viewPost.html
src/main/resources/templates/include/viewReply.html

index 45b8307..046a377 100644 (file)
@@ -40,6 +40,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.core.ImageLoader;
 import net.pterodactylus.sone.core.event.ImageInsertAbortedEvent;
 import net.pterodactylus.sone.core.event.ImageInsertFailedEvent;
 import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
@@ -84,6 +85,7 @@ import net.pterodactylus.sone.template.IdentityAccessor;
 import net.pterodactylus.sone.template.ImageAccessor;
 import net.pterodactylus.sone.template.ImageLinkFilter;
 import net.pterodactylus.sone.template.JavascriptFilter;
+import net.pterodactylus.sone.template.LinkedImagesFilter;
 import net.pterodactylus.sone.template.ParserFilter;
 import net.pterodactylus.sone.template.PostAccessor;
 import net.pterodactylus.sone.template.ProfileAccessor;
@@ -256,7 +258,7 @@ public class WebInterface {
         *            The Sone plugin
         */
        @Inject
-       public WebInterface(SonePlugin sonePlugin, Loaders loaders, ListNotificationFilter listNotificationFilter, PostVisibilityFilter postVisibilityFilter, ReplyVisibilityFilter replyVisibilityFilter) {
+       public WebInterface(SonePlugin sonePlugin, Loaders loaders, ListNotificationFilter listNotificationFilter, PostVisibilityFilter postVisibilityFilter, ReplyVisibilityFilter replyVisibilityFilter, ImageLoader imageLoader) {
                this.sonePlugin = sonePlugin;
                this.loaders = loaders;
                this.listNotificationFilter = listNotificationFilter;
@@ -291,6 +293,7 @@ public class WebInterface {
                templateContextFactory.addFilter("parse", parserFilter = new ParserFilter(getCore(), soneTextParser));
                templateContextFactory.addFilter("shorten", shortenFilter = new ShortenFilter());
                templateContextFactory.addFilter("render", renderFilter = new RenderFilter(getCore(), templateContextFactory));
+               templateContextFactory.addFilter("linked-images", new LinkedImagesFilter(imageLoader));
                templateContextFactory.addFilter("reparse", new ReparseFilter());
                templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate"));
                templateContextFactory.addFilter("format", new FormatFilter());
index 1767090..8e008c7 100644 (file)
@@ -440,6 +440,21 @@ textarea {
        color: green;
 }
 
+#sone .post .linked-images {
+       margin-top: 1ex;
+}
+
+#sone .post .linked-image {
+       display: inline-block;
+       border: solid 1px black;
+       width: 160px;
+       height: 120px;
+       background-size: cover;
+       background-position: center;
+       margin-right: 1ex;
+       margin-bottom: 1ex;
+}
+
 #sone .post .replies {
        clear: both;
        padding-top: 0.2ex;
@@ -496,6 +511,21 @@ textarea {
        font-size: inherit;
 }
 
+#sone .post .reply .linked-images {
+       margin-top: 1ex;
+}
+
+#sone .post .reply .linked-image {
+       display: inline-block;
+       border: solid 1px black;
+       width: 120px;
+       height: 90px;
+       background-size: cover;
+       background-position: center;
+       margin-right: 1ex;
+       margin-bottom: 1ex;
+}
+
 #sone .post .show-reply-form {
        display: inline;
 }
index 7cba220..ac149f8 100644 (file)
                        <div class="post-text short-text<%if raw> hidden<%/if><%if shortText|match key=renderedText> hidden<%/if>"><% shortText></div>
                        <%if !shortText|match value=renderedText><%if !raw><a class="expand-post-text" href="viewPost.html?post=<% post.id|html>&amp;raw=true"><%= View.Post.ShowMore|l10n|html></a><%/if><%/if>
                        <%if !shortText|match value=renderedText><%if !raw><a class="shrink-post-text hidden"><%= View.Post.ShowLess|l10n|html></a><%/if><%/if>
+                       <% parsedText|linked-images|store key==linkedImages>
+                       <% foreach linkedImages linkedImage>
+                               <% first>
+                                       <div class="linked-images">
+                               <%/first>
+                               <a href="/<% linkedImage.link|html>">
+                                       <span class="linked-image" title="<% linkedImage.link|html>" style="background-image: url('/<% linkedImage.link|html>')"/>
+                               </a>
+                               <% last>
+                                       </div>
+                               <%/last>
+                       <%/foreach>
                </div>
                <div class="post-status-line status-line<%if !post.loaded> hidden<%/if>">
                        <div class="bookmarks">
index 1ef8f13..cd56e32 100644 (file)
                        <div class="reply-text short-text<%if raw> hidden<%/if><%if shortText|match key=renderedText> hidden<%/if>"><% shortText></div>
                        <%if !shortText|match value=renderedText><%if !raw><a class="expand-reply-text" href="viewPost.html?post=<% reply.postId|html>&amp;raw=true"><%= View.Post.ShowMore|l10n|html></a><%/if><%/if>
                        <%if !shortText|match value=renderedText><%if !raw><a class="shrink-reply-text hidden"><%= View.Post.ShowLess|l10n|html></a><%/if><%/if>
+                       <% parsedText|linked-images|store key==linkedImages>
+                       <% foreach linkedImages linkedImage>
+                               <% first>
+                                       <div class="linked-images">
+                               <%/first>
+                               <a href="/<% linkedImage.link|html>">
+                                       <span class="linked-image" title="<% linkedImage.link|html>" style="background-image: url('/<% linkedImage.link|html>')"/>
+                               </a>
+                               <% last>
+                                       </div>
+                               <%/last>
+                       <%/foreach>
                </div>
                <div class="reply-status-line status-line">
                        <div class="time"><% reply.time|date format=="MMM d, yyyy, HH:mm:ss"></div>