--- /dev/null
+/*
+ * Sone - ReplyAccessor.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.template;
+
+import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.data.Reply;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.util.template.DataProvider;
+import net.pterodactylus.util.template.ReflectionAccessor;
+
+/**
+ * TODO
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ReplyAccessor extends ReflectionAccessor {
+
+ private final Core core;
+
+ public ReplyAccessor(Core core) {
+ this.core = core;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object get(DataProvider dataProvider, Object object, String member) {
+ Reply reply = (Reply) object;
+ if ("likes".equals(member)) {
+ return core.getLikes(reply);
+ } else if (member.equals("liked")) {
+ Sone currentSone = (Sone) dataProvider.getData("currentSone");
+ return (currentSone != null) && (currentSone.isLikedReplyId(reply.getId()));
+ }
+ return super.get(dataProvider, object, member);
+ }
+
+}
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.freenet.L10nFilter;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.sone.template.GetPagePlugin;
import net.pterodactylus.sone.template.PostAccessor;
+import net.pterodactylus.sone.template.ReplyAccessor;
import net.pterodactylus.sone.template.RequestChangeFilter;
import net.pterodactylus.sone.template.SoneAccessor;
import net.pterodactylus.sone.template.SubstringFilter;
templateFactory.addAccessor(Object.class, new ReflectionAccessor());
templateFactory.addAccessor(Sone.class, new SoneAccessor(core()));
templateFactory.addAccessor(Post.class, new PostAccessor(core()));
+ templateFactory.addAccessor(Reply.class, new ReplyAccessor(core()));
templateFactory.addFilter("date", new DateFilter());
templateFactory.addFilter("l10n", new L10nFilter(l10n()));
templateFactory.addFilter("substring", new SubstringFilter());
</div>
<div class="status-line">
<div class="time"><% reply.time|date format="MMM d, yyyy, HH:mm:ss"></div>
+ <div class="likes<%if reply.likes.size|match value=0> hidden<%/if>"><span>⬆<span class="like-count"><% reply.likes.size></span></span></div>
+ <%ifnull ! currentSone>
+ <form class="like<%if reply.liked> hidden<%/if>" action="like.html" method="post">
+ <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+ <input type="hidden" name="returnPage" value="<% request.uri|html>" />
+ <input type="hidden" name="type" value="reply" />
+ <input type="hidden" name="reply" value="<% reply.id|html>" />
+ <button type="submit" value="1"><%= View.Post.LikeLink|l10n|html></button>
+ </form>
+ <form class="unlike<%if ! reply.liked> hidden<%/if>" action="unlike.html" method="post">
+ <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+ <input type="hidden" name="returnPage" value="<% request.uri|html>" />
+ <input type="hidden" name="type" value="reply" />
+ <input type="hidden" name="reply" value="<% reply.id|html>" />
+ <button type="submit" value="1"><%= View.Post.UnlikeLink|l10n|html></button>
+ </form>
+ <%/if>
<%if reply.sone.current>
<form class="delete" action="deleteReply.html" method="post">
<input type="hidden" name="formPassword" value="<% formPassword|html>" />