From: David ‘Bombe’ Roden Date: Sat, 12 Nov 2011 10:54:34 +0000 (+0100) Subject: Parse descriptions of albums and images. X-Git-Tag: 0.7.3^2~12^2 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=3dc1b526bc547f89a8a9e5d67344e05ae7004d04;p=Sone.git Parse descriptions of albums and images. --- diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 7320ad5..4c41581 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -170,6 +170,9 @@ public class WebInterface implements CoreListener { /** The Sone text parser. */ private final SoneTextParser soneTextParser; + /** The parser filter. */ + private final ParserFilter parserFilter; + /** The “new Sone” notification. */ private final ListNotification newSoneNotification; @@ -242,7 +245,7 @@ public class WebInterface implements CoreListener { templateContextFactory.addFilter("match", new MatchFilter()); templateContextFactory.addFilter("css", new CssClassNameFilter()); templateContextFactory.addFilter("js", new JavascriptFilter()); - templateContextFactory.addFilter("parse", new ParserFilter(getCore(), templateContextFactory, soneTextParser)); + templateContextFactory.addFilter("parse", parserFilter = new ParserFilter(getCore(), templateContextFactory, soneTextParser)); templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate")); templateContextFactory.addFilter("format", new FormatFilter()); templateContextFactory.addFilter("sort", new CollectionSortFilter()); @@ -668,7 +671,7 @@ public class WebInterface implements CoreListener { pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new EditAlbumAjaxPage(this))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImageAjaxPage(this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImageAjaxPage(this, parserFilter))); pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustAjaxPage(this))); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java index 3bef432..3c4de8e 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java @@ -18,10 +18,13 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.data.Image; +import net.pterodactylus.sone.template.ParserFilter; import net.pterodactylus.sone.text.TextFilter; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; +import net.pterodactylus.util.collection.MapBuilder; import net.pterodactylus.util.json.JsonObject; +import net.pterodactylus.util.template.TemplateContext; /** * Page that stores a user’s image modifications. @@ -30,14 +33,20 @@ import net.pterodactylus.util.json.JsonObject; */ public class EditImageAjaxPage extends JsonPage { + /** Parser for image descriptions. */ + private final ParserFilter parserFilter; + /** * Creates a new edit image AJAX page. * * @param webInterface * The Sone web interface + * @param parserFilter + * The parser filter for image descriptions */ - public EditImageAjaxPage(WebInterface webInterface) { + public EditImageAjaxPage(WebInterface webInterface, ParserFilter parserFilter) { super("editImage.ajax", webInterface); + this.parserFilter = parserFilter; } // @@ -71,7 +80,7 @@ public class EditImageAjaxPage extends JsonPage { String description = request.getHttpRequest().getParam("description").trim(); image.setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)); webInterface.getCore().touchConfiguration(); - return createSuccessJsonObject().put("imageId", image.getId()).put("title", image.getTitle()).put("description", image.getDescription()); + return createSuccessJsonObject().put("imageId", image.getId()).put("title", image.getTitle()).put("description", image.getDescription()).put("parsedDescription", (String) parserFilter.format(new TemplateContext(), image.getDescription(), new MapBuilder().put("sone", image.getSone().getId()).get())); } } diff --git a/src/main/resources/templates/imageBrowser.html b/src/main/resources/templates/imageBrowser.html index d97fc25..1da99ff 100644 --- a/src/main/resources/templates/imageBrowser.html +++ b/src/main/resources/templates/imageBrowser.html @@ -118,9 +118,9 @@ ajaxGet("editImage.ajax", { "formPassword": getFormPassword(), "image": imageId, "title": title, "description": description }, function(data) { if (data && data.success) { getImage(data.imageId).find(".image-title").text(data.title); - getImage(data.imageId).find(".image-description").text(data.description); + getImage(data.imageId).find(".image-description").html(data.parsedDescription); getImage(data.imageId).find(":input[name='title']").attr("defaultValue", title); - getImage(data.imageId).find(":input[name='description']").attr("defaultValue", description); + getImage(data.imageId).find(":input[name='description']").attr("defaultValue", data.description); cancelImageEditing(); } }); @@ -322,7 +322,7 @@ <%/foreach> -

<% album.description|html>

+

<% album.description|parse sone=album.sone>

<%if album.sone.local> @@ -378,7 +378,7 @@
<% image.title|html>
-
<% image.description|html>
+
<% image.description|parse sone=image.sone>
<%if album.sone.local>
diff --git a/src/main/resources/templates/include/browseAlbums.html b/src/main/resources/templates/include/browseAlbums.html index d925a3c..1fddebd 100644 --- a/src/main/resources/templates/include/browseAlbums.html +++ b/src/main/resources/templates/include/browseAlbums.html @@ -14,7 +14,7 @@
<% album.title|html> (<%= View.Sone.Stats.Images|l10n 0=album.images.size>)
-
<% album.description|html>
+
<% album.description|parse sone=album.sone>
<%if album.sone.local>