Force download of images.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 11 Oct 2011 19:16:21 +0000 (21:16 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 11 Oct 2011 19:16:21 +0000 (21:16 +0200)
src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java

index 063a1de..d7b5eea 100644 (file)
@@ -39,7 +39,7 @@ import net.pterodactylus.util.template.TemplateParser;
 public class ImageLinkFilter implements Filter {
 
        /** The template to render for the &lt;img&gt; tag. */
-       private static final Template linkTemplate = TemplateParser.parse(new StringReader("<img<%ifnull !class> class=\"<%class|css>\"<%/if> src=\"<%src|html>\" alt=\"<%alt|html>\" title=\"<%title|html>\" width=\"<%width|html>\" height=\"<%height|html>\" style=\"position: relative;<%ifnull ! top>top: <% top|html>;<%/if><%ifnull ! left>left: <% left|html>;<%/if>\"/>"));
+       private static final Template linkTemplate = TemplateParser.parse(new StringReader("<img<%ifnull !class> class=\"<%class|css>\"<%/if> src=\"<%src|html><%if forceDownload>?forcedownload=true<%/if>\" alt=\"<%alt|html>\" title=\"<%title|html>\" width=\"<%width|html>\" height=\"<%height|html>\" style=\"position: relative;<%ifnull ! top>top: <% top|html>;<%/if><%ifnull ! left>left: <% left|html>;<%/if>\"/>"));
 
        /** The template context factory. */
        private final TemplateContextFactory templateContextFactory;
@@ -73,6 +73,7 @@ public class ImageLinkFilter implements Filter {
                linkTemplateContext.set("class", imageClass);
                if (image.isInserted()) {
                        linkTemplateContext.set("src", "/" + image.getKey());
+                       linkTemplateContext.set("forceDownload", true);
                } else {
                        linkTemplateContext.set("src", "getImage.html?image=" + image.getId());
                }