/*
- * Sone - EditImageAjaxPage.java - Copyright © 2011 David Roden
+ * Sone - EditImageAjaxPage.java - Copyright © 2011–2012 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
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.json.JsonObject;
+import net.pterodactylus.util.template.TemplateContext;
+
+import com.google.common.collect.ImmutableMap;
/**
* Page that stores a user’s image modifications.
*/
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;
}
//
if (image == null) {
return createErrorJsonObject("invalid-image-id");
}
- if (!webInterface.getCore().isLocalSone(image.getSone())) {
+ if (!image.getSone().isLocal()) {
return createErrorJsonObject("not-authorized");
}
if ("true".equals(request.getHttpRequest().getParam("moveLeft"))) {
}
String title = request.getHttpRequest().getParam("title").trim();
String description = request.getHttpRequest().getParam("description").trim();
- image.setTitle(title).setDescription(description);
+ 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(), ImmutableMap.<String, Object> builder().put("sone", image.getSone()).build()));
}
}