<dependency>
<groupId>net.pterodactylus</groupId>
<artifactId>utils</artifactId>
- <version>0.7</version>
+ <version>0.7.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
</dependency>
<dependency>
<groupId>org.freenetproject</groupId>
- <artifactId>fred-ext</artifactId>
+ <artifactId>freenet-ext</artifactId>
<version>26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.pterodactylus</groupId>
<artifactId>utils.json</artifactId>
- <version>0.1-SNAPSHOT</version>
+ <version>0.1</version>
</dependency>
</dependencies>
+ <repositories>
+ <repository>
+ <id>pterodactylus</id>
+ <url>http://maven.pterodactylus.net/</url>
+ </repository>
+ </repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</plugin>
</plugins>
</build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <links>
+ <link>http://download.oracle.com/javase/6/docs/api/</link>
+ <link>http://java.pterodactylus.net/utils/apidocs/</link>
+ <link>http://java.pterodactylus.net/utils.json/apidocs/</link>
+ </links>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
package net.pterodactylus.sone.template;
+import java.io.IOException;
+import java.io.StringReader;
+
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.text.FreenetLinkParser;
import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateFactory;
/**
* Accessor for {@link Post} objects that adds additional properties:
*/
public class PostAccessor extends ReflectionAccessor {
+ /** Parser for Freenet links. */
+ private final FreenetLinkParser linkParser;
+
/** The core to get the replies from. */
private final Core core;
*
* @param core
* The core to get the replies from
+ * @param templateFactory
+ * The template factory for the text parser
*/
- public PostAccessor(Core core) {
+ public PostAccessor(Core core, TemplateFactory templateFactory) {
this.core = core;
+ linkParser = new FreenetLinkParser(templateFactory);
}
/**
return (currentSone != null) && (currentSone.isLikedPostId(post.getId()));
} else if (member.equals("new")) {
return core.isNewPost(post.getId(), false);
+ } else if (member.equals("text")) {
+ String text = post.getText();
+ try {
+ return linkParser.parse(new StringReader(text));
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
}
return super.get(dataProvider, object, member);
}
package net.pterodactylus.sone.template;
+import java.io.IOException;
+import java.io.StringReader;
+
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.text.FreenetLinkParser;
import net.pterodactylus.util.template.Accessor;
import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateFactory;
/**
* {@link Accessor} implementation that adds a couple of properties to
*/
public class ReplyAccessor extends ReflectionAccessor {
+ /** Parser for Freenet links. */
+ private final FreenetLinkParser linkParser;
+
/** The core. */
private final Core core;
*
* @param core
* The core
+ * @param templateFactory
+ * The template factory for the text parser
*/
- public ReplyAccessor(Core core) {
+ public ReplyAccessor(Core core, TemplateFactory templateFactory) {
this.core = core;
+ linkParser = new FreenetLinkParser(templateFactory);
}
/**
return (currentSone != null) && (currentSone.isLikedReplyId(reply.getId()));
} else if (member.equals("new")) {
return core.isNewReply(reply.getId(), false);
+ } else if (member.equals("text")) {
+ String text = reply.getText();
+ try {
+ return linkParser.parse(new StringReader(text));
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
}
return super.get(dataProvider, object, member);
}
--- /dev/null
+/*
+ * Sone - FreenetLinkParser.java - Copyright © 2010 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.template.TemplateFactory;
+
+/**
+ * {@link Parser} implementation that can recognize Freenet URIs.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class FreenetLinkParser implements Parser {
+
+ /** The logger. */
+ private static final Logger logger = Logging.getLogger(FreenetLinkParser.class);
+
+ /** Pattern to detect whitespace. */
+ private static final Pattern whitespacePattern = Pattern.compile("[\\p{javaWhitespace}]");
+
+ /**
+ * Enumeration for all recognized link types.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ private enum LinkType {
+
+ /** Link is a KSK. */
+ KSK,
+
+ /** Link is a CHK. */
+ CHK,
+
+ /** Link is an SSK. */
+ SSK,
+
+ /** Link is a USK. */
+ USK
+
+ }
+
+ /** The template factory. */
+ private final TemplateFactory templateFactory;
+
+ /**
+ * Creates a new freenet link parser.
+ *
+ * @param templateFactory
+ * The template factory
+ */
+ public FreenetLinkParser(TemplateFactory templateFactory) {
+ this.templateFactory = templateFactory;
+ }
+
+ //
+ // PART METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Part parse(Reader source) throws IOException {
+ PartContainer parts = new PartContainer();
+ BufferedReader bufferedReader = (source instanceof BufferedReader) ? (BufferedReader) source : new BufferedReader(source);
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ line = line.trim() + "\n";
+ while (line.length() > 0) {
+ int nextKsk = line.indexOf("KSK@");
+ int nextChk = line.indexOf("CHK@");
+ int nextSsk = line.indexOf("SSK@");
+ int nextUsk = line.indexOf("USK@");
+ if ((nextKsk == -1) && (nextChk == -1) && (nextSsk == -1) && (nextUsk == -1)) {
+ parts.add(createPlainTextPart(line));
+ break;
+ }
+ int next = Integer.MAX_VALUE;
+ LinkType linkType = null;
+ if ((nextKsk > -1) && (nextKsk < next)) {
+ next = nextKsk;
+ linkType = LinkType.KSK;
+ }
+ if ((nextChk > -1) && (nextChk < next)) {
+ next = nextChk;
+ linkType = LinkType.CHK;
+ }
+ if ((nextSsk > -1) && (nextSsk < next)) {
+ next = nextSsk;
+ linkType = LinkType.SSK;
+ }
+ if ((nextUsk > -1) && (nextUsk < next)) {
+ next = nextUsk;
+ linkType = LinkType.USK;
+ }
+ if ((next >= 8) && (line.substring(next - 8, next).equals("freenet:"))) {
+ next -= 8;
+ line = line.substring(0, next) + line.substring(next + 8);
+ }
+ Matcher matcher = whitespacePattern.matcher(line);
+ int nextSpace = matcher.find(next) ? matcher.start() : line.length();
+ if (nextSpace > (next + 4)) {
+ parts.add(createPlainTextPart(line.substring(0, next)));
+ String link = line.substring(next, nextSpace);
+ String name = link;
+ logger.log(Level.FINER, "Found link: " + link);
+ logger.log(Level.FINEST, "Next: %d, CHK: %d, SSK: %d, USK: %d", new Object[] { next, nextChk, nextSsk, nextUsk });
+ if (((linkType == LinkType.CHK) || (linkType == LinkType.SSK) || (linkType == LinkType.USK)) && (link.length() > 98) && (link.charAt(47) == ',') && (link.charAt(91) == ',') && (link.charAt(99) == '/')) {
+ name = link.substring(0, 47) + "…" + link.substring(99);
+ }
+ parts.add(createLinkPart(link, name));
+ line = line.substring(nextSpace);
+ } else {
+ parts.add(createPlainTextPart(line.substring(0, next + 4)));
+ line = line.substring(next + 4);
+ }
+ }
+ }
+ return parts;
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Creates a new plain text part based on a template.
+ *
+ * @param text
+ * The text to display
+ * @return The part that displays the given text
+ */
+ private Part createPlainTextPart(String text) {
+ return new TemplatePart(templateFactory.createTemplate(new StringReader("<% text|html>"))).set("text", text);
+ }
+
+ /**
+ * Creates a new link part based on a template.
+ *
+ * @param link
+ * The target of the link
+ * @param name
+ * The name of the link
+ * @return The part that displays the link
+ */
+ private Part createLinkPart(String link, String name) {
+ return new TemplatePart(templateFactory.createTemplate(new StringReader("<a href=\"/<% link|html>\"><% name|html></a>"))).set("link", link).set("name", name);
+ }
+
+}
--- /dev/null
+/*
+ * Sone - Parser.java - Copyright © 2010 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * Interface for parsers that can create {@link Part}s from a text source
+ * (usually a {@link Reader}).
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface Parser {
+
+ /**
+ * Create a {@link Part} from the given text source.
+ *
+ * @param source
+ * The text source
+ * @return The parsed part
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ public Part parse(Reader source) throws IOException;
+
+}
--- /dev/null
+/*
+ * Sone - Part.java - Copyright © 2010 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import net.pterodactylus.util.io.Renderable;
+
+/**
+ * A part is a single piece of information that can be displayed as a single
+ * element.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface Part extends Renderable {
+
+ /* all required methods are inherited from {@link Renderable}. */
+
+}
--- /dev/null
+/*
+ * Sone - PartContainer.java - Copyright © 2010 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Part implementation that can contain an arbitrary amount of other parts.
+ * Parts are added using the {@link #add(Part)} method and will be rendered in
+ * the order they are added.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class PartContainer implements Part {
+
+ /** The parts to render. */
+ private final List<Part> parts = new ArrayList<Part>();
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Adds a part to render.
+ *
+ * @param part
+ * The part to add
+ */
+ public void add(Part part) {
+ parts.add(part);
+ }
+
+ //
+ // PART METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void render(Writer writer) throws IOException {
+ for (Part part : parts) {
+ part.render(writer);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Sone - TemplatePart.java - Copyright © 2010 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import net.pterodactylus.util.template.Template;
+
+/**
+ * {@link Part} implementation that is rendered using a {@link Template}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class TemplatePart implements Part {
+
+ /** The template to render for this part. */
+ private final Template template;
+
+ /**
+ * Creates a new template part.
+ *
+ * @param template
+ * The template to render
+ */
+ public TemplatePart(Template template) {
+ this.template = template;
+ }
+
+ //
+ // ACTIONS
+ //
+
+ /**
+ * Sets a variable in the template.
+ *
+ * @param key
+ * The key of the variable
+ * @param value
+ * The value of the variable
+ * @return This template part (for method chaining)
+ */
+ public TemplatePart set(String key, String value) {
+ template.set(key, value);
+ return this;
+ }
+
+ //
+ // PART METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void render(Writer writer) throws IOException {
+ template.render(writer);
+ }
+
+}
templateFactory.addAccessor(Object.class, new ReflectionAccessor());
templateFactory.addAccessor(Collection.class, new CollectionAccessor());
templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
- templateFactory.addAccessor(Post.class, new PostAccessor(getCore()));
- templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
+ templateFactory.addAccessor(Post.class, new PostAccessor(getCore(), templateFactory));
+ templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore(), templateFactory));
templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
templateFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
templateFactory.addFilter("date", new DateFilter());
* The Sone web interface
*/
public CreatePostAjaxPage(WebInterface webInterface) {
- super("ajax/createPost.ajax", webInterface);
+ super("createPost.ajax", webInterface);
}
/**
* The Sone web interface
*/
public CreateReplyAjaxPage(WebInterface webInterface) {
- super("ajax/createReply.ajax", webInterface);
+ super("createReply.ajax", webInterface);
}
//
* The Sone web interface
*/
public DeletePostAjaxPage(WebInterface webInterface) {
- super("ajax/deletePost.ajax", webInterface);
+ super("deletePost.ajax", webInterface);
}
//
* The Sone web interface
*/
public DeleteReplyAjaxPage(WebInterface webInterface) {
- super("ajax/deleteReply.ajax", webInterface);
+ super("deleteReply.ajax", webInterface);
}
//
* The Sone web interface
*/
public DismissNotificationAjaxPage(WebInterface webInterface) {
- super("ajax/dismissNotification.ajax", webInterface);
+ super("dismissNotification.ajax", webInterface);
}
/**
* The Sone web interface
*/
public FollowSoneAjaxPage(WebInterface webInterface) {
- super("ajax/followSone.ajax", webInterface);
+ super("followSone.ajax", webInterface);
}
/**
* The Sone web interface
*/
public GetLikesAjaxPage(WebInterface webInterface) {
- super("ajax/getLikes.ajax", webInterface);
+ super("getLikes.ajax", webInterface);
}
//
* The template to render for posts
*/
public GetPostAjaxPage(WebInterface webInterface, Template postTemplate) {
- super("ajax/getPost.ajax", webInterface);
+ super("getPost.ajax", webInterface);
this.postTemplate = postTemplate;
}
* The template to render
*/
public GetReplyAjaxPage(WebInterface webInterface, Template replyTemplate) {
- super("ajax/getReply.ajax", webInterface);
+ super("getReply.ajax", webInterface);
this.replyTemplate = replyTemplate;
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
* The Sone web interface
*/
public GetStatusAjaxPage(WebInterface webInterface) {
- super("ajax/getStatus.ajax", webInterface);
+ super("getStatus.ajax", webInterface);
}
/**
protected JsonObject createJsonObject(Request request) {
/* load Sones. */
boolean loadAllSones = Boolean.parseBoolean(request.getHttpRequest().getParam("loadAllSones", "true"));
- Set<Sone> sones = loadAllSones ? webInterface.getCore().getSones() : Collections.singleton(getCurrentSone(request.getToadletContext()));
+ Set<Sone> sones = new HashSet<Sone>(Collections.singleton(getCurrentSone(request.getToadletContext())));
+ if (loadAllSones) {
+ sones.addAll(webInterface.getCore().getSones());
+ }
JsonArray jsonSones = new JsonArray();
for (Sone sone : sones) {
JsonObject jsonSone = createJsonSone(sone);
* The Sone web interface
*/
public GetTranslationPage(WebInterface webInterface) {
- super("ajax/getTranslation.ajax", webInterface);
+ super("getTranslation.ajax", webInterface);
}
//
* The Sone web interface
*/
public LikeAjaxPage(WebInterface webInterface) {
- super("ajax/like.ajax", webInterface);
+ super("like.ajax", webInterface);
}
/**
* The Sone web interface
*/
public LockSoneAjaxPage(WebInterface webInterface) {
- super("ajax/lockSone.ajax", webInterface);
+ super("lockSone.ajax", webInterface);
}
/**
* The Sone web interface
*/
public MarkPostAsKnownPage(WebInterface webInterface) {
- super("ajax/markPostAsKnown.ajax", webInterface);
+ super("markPostAsKnown.ajax", webInterface);
}
/**
* The Sone web interface
*/
public MarkReplyAsKnownPage(WebInterface webInterface) {
- super("ajax/markReplyAsKnown.ajax", webInterface);
+ super("markReplyAsKnown.ajax", webInterface);
}
/**
* The Sone web interface
*/
public UnfollowSoneAjaxPage(WebInterface webInterface) {
- super("ajax/unfollowSone.ajax", webInterface);
+ super("unfollowSone.ajax", webInterface);
}
/**
* The Sone web interface
*/
public UnlikeAjaxPage(WebInterface webInterface) {
- super("ajax/unlike.ajax", webInterface);
+ super("unlike.ajax", webInterface);
}
/**
* The Sone web interface
*/
public UnlockSoneAjaxPage(WebInterface webInterface) {
- super("ajax/unlockSone.ajax", webInterface);
+ super("unlockSone.ajax", webInterface);
}
/**
callback(translations[key]);
return;
}
- $.getJSON("ajax/getTranslation.ajax", {"key": key}, function(data, textStatus) {
+ $.getJSON("getTranslation.ajax", {"key": key}, function(data, textStatus) {
if ((data != null) && data.success) {
translations[key] = data.value;
callback(data.value);
*/
function enhanceDeletePostButton(button, postId, text) {
enhanceDeleteButton(button, text, function() {
- $.getJSON("ajax/deletePost.ajax", { "post": postId, "formPassword": getFormPassword() }, function(data, textStatus) {
+ $.getJSON("deletePost.ajax", { "post": postId, "formPassword": getFormPassword() }, function(data, textStatus) {
if (data == null) {
return;
}
*/
function enhanceDeleteReplyButton(button, replyId, text) {
enhanceDeleteButton(button, text, function() {
- $.getJSON("ajax/deleteReply.ajax", { "reply": replyId, "formPassword": $("#sone #formPassword").text() }, function(data, textStatus) {
+ $.getJSON("deleteReply.ajax", { "reply": replyId, "formPassword": $("#sone #formPassword").text() }, function(data, textStatus) {
if (data == null) {
return;
}
}
function likePost(postId) {
- $.getJSON("ajax/like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
+ $.getJSON("like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
if ((data == null) || !data.success) {
return;
}
}
function unlikePost(postId) {
- $.getJSON("ajax/unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
+ $.getJSON("unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
if ((data == null) || !data.success) {
return;
}
}
function updatePostLikes(postId) {
- $.getJSON("ajax/getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) {
+ $.getJSON("getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) {
if ((data != null) && data.success) {
$("#sone .post#" + postId + " > .inner-part > .status-line .likes").toggleClass("hidden", data.likes == 0)
$("#sone .post#" + postId + " > .inner-part > .status-line .likes span.like-count").text(data.likes);
}
function likeReply(replyId) {
- $.getJSON("ajax/like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
+ $.getJSON("like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
if ((data == null) || !data.success) {
return;
}
}
function unlikeReply(replyId) {
- $.getJSON("ajax/unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
+ $.getJSON("unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
if ((data == null) || !data.success) {
return;
}
}
function updateReplyLikes(replyId) {
- $.getJSON("ajax/getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) {
+ $.getJSON("getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) {
if ((data != null) && data.success) {
$("#sone .reply#" + replyId + " .status-line .likes").toggleClass("hidden", data.likes == 0)
$("#sone .reply#" + replyId + " .status-line .likes span.like-count").text(data.likes);
* parameters: success, error, replyId)
*/
function postReply(postId, text, callbackFunction) {
- $.getJSON("ajax/createReply.ajax", { "formPassword" : getFormPassword(), "post" : postId, "text": text }, function(data, textStatus) {
+ $.getJSON("createReply.ajax", { "formPassword" : getFormPassword(), "post" : postId, "text": text }, function(data, textStatus) {
if (data == null) {
/* TODO - show error */
return;
* replyDisplayTime, text, html)
*/
function getReply(replyId, callbackFunction) {
- $.getJSON("ajax/getReply.ajax", { "reply" : replyId }, function(data, textStatus) {
+ $.getJSON("getReply.ajax", { "reply" : replyId }, function(data, textStatus) {
if ((data != null) && data.success) {
callbackFunction(data.soneId, data.soneName, data.time, data.displayTime, data.text, data.html);
}
return false;
});
notification.find("form.dismiss button").click(function() {
- $.getJSON("ajax/dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
+ $.getJSON("dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
/* dismiss in case of error, too. */
notification.slideUp();
}, function(xmlHttpRequest, textStatus, error) {
}
function getStatus() {
- $.getJSON("ajax/getStatus.ajax", {}, function(data, textStatus) {
+ $.getJSON("getStatus.ajax", {"loadAllSones": isKnownSonesPage()}, function(data, textStatus) {
if ((data != null) && data.success) {
/* process Sone information. */
$.each(data.sones, function(index, value) {
*
* @returns The ID of the currently shown Sone
*/
-function getSoneId() {
+function getShownSoneId() {
return $("#sone .sone-id").text();
}
+/**
+ * Returns whether the current page is a “view post” page.
+ *
+ * @returns {Boolean} <code>true</code> if the current page is a “view post”
+ * page, <code>false</code> otherwise
+ */
+function isViewPostPage() {
+ return getPageId() == "view-post";
+}
+
+/**
+ * Returns the ID of the currently shown post. This will only return a sensible
+ * value if isViewPostPage() returns <code>true</code>.
+ *
+ * @returns The ID of the currently shown post
+ */
+function getShownPostId() {
+ return $("#sone .post-id").text();
+}
+
+/**
+ * Returns whether the current page is the “known Sones” page.
+ *
+ * @returns {Boolean} <code>true</code> if the current page is the “known
+ * Sones” page, <code>false</code> otherwise
+ */
+function isKnownSonesPage() {
+ return getPageId() == "known-sones";
+}
+
var loadedPosts = {};
var loadedReplies = {};
return;
}
loadedPosts[postId] = true;
- $.getJSON("ajax/getPost.ajax", { "post" : postId }, function(data, textStatus) {
+ $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) {
if ((data != null) && data.success) {
- if (!isIndexPage() && !(isViewSonePage() && (getSoneId() == data.post.sone))) {
+ if (!isIndexPage() && !(isViewSonePage() && (getShownSoneId() == data.post.sone))) {
return;
}
var firstOlderPost = null;
return;
}
loadedReplies[replyId] = true;
- $.getJSON("ajax/getReply.ajax", { "reply": replyId }, function(data, textStatus) {
+ $.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) {
/* find post. */
if ((data != null) && data.success) {
$("#sone .post#" + data.reply.postId).each(function() {
postElement = this;
if ($(postElement).hasClass("new")) {
(function(postElement) {
- $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) {
+ $.getJSON("markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) {
$(postElement).removeClass("new");
});
})(postElement);
replyElement = this;
if ($(replyElement).hasClass("new")) {
(function(replyElement) {
- $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) {
+ $.getJSON("markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) {
$(replyElement).removeClass("new");
});
})(replyElement);
registerInputTextareaSwap("#sone #update-status .status-input", defaultText, "text", false, false);
$("#sone #update-status").submit(function() {
text = $(this).find(":input:enabled").val();
- $.getJSON("ajax/createPost.ajax", { "formPassword": getFormPassword(), "text": text }, function(data, textStatus) {
+ $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "text": text }, function(data, textStatus) {
if ((data != null) && data.success) {
loadNewPost(data.postId);
}
});
/* hides all replies but the latest two. */
- getTranslation("WebInterface.ClickToShow.Replies", function(text) {
- $("#sone .post .replies").each(function() {
- allReplies = $(this).find(".reply");
- if (allReplies.length > 2) {
- newHidden = false;
- for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) {
- $(allReplies[replyIndex]).addClass("hidden");
- newHidden |= $(allReplies[replyIndex]).hasClass("new");
- }
- clickToShowElement = $("<div></div>").addClass("click-to-show");
- if (newHidden) {
- clickToShowElement.addClass("new");
+ if (!isViewPostPage()) {
+ getTranslation("WebInterface.ClickToShow.Replies", function(text) {
+ $("#sone .post .replies").each(function() {
+ allReplies = $(this).find(".reply");
+ if (allReplies.length > 2) {
+ newHidden = false;
+ for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) {
+ $(allReplies[replyIndex]).addClass("hidden");
+ newHidden |= $(allReplies[replyIndex]).hasClass("new");
+ }
+ clickToShowElement = $("<div></div>").addClass("click-to-show");
+ if (newHidden) {
+ clickToShowElement.addClass("new");
+ }
+ (function(clickToShowElement, allReplies, text) {
+ clickToShowElement.text(text);
+ clickToShowElement.click(function() {
+ allReplies.removeClass("hidden");
+ clickToShowElement.addClass("hidden");
+ });
+ })(clickToShowElement, allReplies, text);
+ $(allReplies[0]).before(clickToShowElement);
}
- (function(clickToShowElement, allReplies, text) {
- clickToShowElement.text(text);
- clickToShowElement.click(function() {
- allReplies.removeClass("hidden");
- clickToShowElement.addClass("hidden");
- });
- })(clickToShowElement, allReplies, text);
- $(allReplies[0]).before(clickToShowElement);
- }
+ });
});
- });
+ }
/*
* convert all “follow”, “unfollow”, “lock”, and “unlock” links to something
*/
$("#sone .follow").submit(function() {
var followElement = this;
- $.getJSON("ajax/followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
+ $.getJSON("followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
$(followElement).addClass("hidden");
$(followElement).parent().find(".unfollow").removeClass("hidden");
});
});
$("#sone .unfollow").submit(function() {
var unfollowElement = this;
- $.getJSON("ajax/unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
+ $.getJSON("unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
$(unfollowElement).addClass("hidden");
$(unfollowElement).parent().find(".follow").removeClass("hidden");
});
});
$("#sone .lock").submit(function() {
var lockElement = this;
- $.getJSON("ajax/lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
+ $.getJSON("lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
$(lockElement).addClass("hidden");
$(lockElement).parent().find(".unlock").removeClass("hidden");
});
});
$("#sone .unlock").submit(function() {
var unlockElement = this;
- $.getJSON("ajax/unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
+ $.getJSON("unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
$(unlockElement).addClass("hidden");
$(unlockElement).parent().find(".lock").removeClass("hidden");
});
<div class="recipient profile-link"><a href="viewSone.html?sone=<% post.recipient.id|html>"><% post.recipient.niceName|html></a></div>
<%/if>
<%/if>
- <div class="text"><% post.text|html></div>
+ <div class="text"><% post.text></div>
</div>
<div class="post-status-line status-line">
<div class="time"><a href="viewPost.html?post=<% post.id|html>"><% post.time|date format="MMM d, yyyy, HH:mm:ss"></a></div>
<div class="inner-part">
<div>
<div class="author profile-link"><a href="viewSone.html?sone=<% reply.sone.id|html>"><% reply.sone.niceName|html></a></div>
- <div class="text"><% reply.text|html></div>
+ <div class="text"><% reply.text></div>
</div>
<div class="reply-status-line status-line">
<div class="time"><% reply.time|date format="MMM d, yyyy, HH:mm:ss"></div>
<%include include/head.html>
+ <div class="page-id hidden">known-sones</div>
+
<h1><%= Page.KnownSones.Page.Title|l10n|html></h1>
<div id="known-sones">
<%include include/head.html>
+ <div class="page-id hidden">view-post</div>
+ <div class="post-id hidden"><% post.id|html></div>
+
<h1><%= Page.ViewPost.Page.Title|l10n|insert needle="{sone}" key=post.sone.niceName|html></h1>
<%include include/viewPost.html>