From 9f8b3c3202fd7b03768c2438c3e5d37faa9dfc5e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 27 Sep 2011 19:30:20 +0200 Subject: [PATCH] Add separate length parameter for the snippet of too-long posts. --- .../java/net/pterodactylus/sone/core/Core.java | 36 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/OptionsPage.java | 7 +++++ src/main/resources/i18n/sone.en.properties | 6 ++-- src/main/resources/templates/include/viewPost.html | 2 +- .../resources/templates/include/viewReply.html | 2 +- src/main/resources/templates/options.html | 9 ++++++ 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 8aac5d7..5361f13 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -2161,6 +2161,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal()); configuration.getIntValue("Option/PostsPerPage").setValue(options.getIntegerOption("PostsPerPage").getReal()); configuration.getIntValue("Option/CharactersPerPost").setValue(options.getIntegerOption("CharactersPerPost").getReal()); + configuration.getIntValue("Option/PostCutOffLength").setValue(options.getIntegerOption("PostCutOffLength").getReal()); configuration.getBooleanValue("Option/RequireFullAccess").setValue(options.getBooleanOption("RequireFullAccess").getReal()); configuration.getIntValue("Option/PositiveTrust").setValue(options.getIntegerOption("PositiveTrust").getReal()); configuration.getIntValue("Option/NegativeTrust").setValue(options.getIntegerOption("NegativeTrust").getReal()); @@ -2235,6 +2236,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis })); options.addIntegerOption("PostsPerPage", new DefaultOption(10, new IntegerRangeValidator(1, Integer.MAX_VALUE))); options.addIntegerOption("CharactersPerPost", new DefaultOption(200, new OrValidator(new IntegerRangeValidator(50, Integer.MAX_VALUE), new EqualityValidator(-1)))); + options.addIntegerOption("PostCutOffLength", new DefaultOption(200, new OrValidator(new IntegerRangeValidator(50, Integer.MAX_VALUE), new EqualityValidator(-1)))); options.addBooleanOption("RequireFullAccess", new DefaultOption(false)); options.addIntegerOption("PositiveTrust", new DefaultOption(75, new IntegerRangeValidator(0, 100))); options.addIntegerOption("NegativeTrust", new DefaultOption(-25, new IntegerRangeValidator(-100, 100))); @@ -2274,6 +2276,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis loadConfigurationValue("InsertionDelay"); loadConfigurationValue("PostsPerPage"); loadConfigurationValue("CharactersPerPost"); + loadConfigurationValue("PostCutOffLength"); options.getBooleanOption("RequireFullAccess").set(configuration.getBooleanValue("Option/RequireFullAccess").getValue(null)); loadConfigurationValue("PositiveTrust"); loadConfigurationValue("NegativeTrust"); @@ -2676,6 +2679,39 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } /** + * Returns the number of characters the shortened post should have. + * + * @return The number of characters of the snippet + */ + public int getPostCutOffLength() { + return options.getIntegerOption("PostCutOffLength").get(); + } + + /** + * Validates the number of characters after which to cut off the post. + * + * @param postCutOffLength + * The number of characters of the snippet + * @return {@code true} if the number of characters of the snippet is + * valid, {@code false} otherwise + */ + public boolean validatePostCutOffLength(Integer postCutOffLength) { + return options.getIntegerOption("PostCutOffLength").validate(postCutOffLength); + } + + /** + * Sets the number of characters the shortened post should have. + * + * @param postCutOffLength + * The number of characters of the snippet + * @return This preferences + */ + public Preferences setPostCutOffLength(Integer postCutOffLength) { + options.getIntegerOption("PostCutOffLength").set(postCutOffLength); + return this; + } + + /** * Returns whether Sone requires full access to be even visible. * * @return {@code true} if Sone requires full access, {@code false} diff --git a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java index 75e73a0..7b4a634 100644 --- a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java +++ b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java @@ -87,6 +87,12 @@ public class OptionsPage extends SoneTemplatePage { } else { preferences.setCharactersPerPost(charactersPerPost); } + Integer postCutOffLength = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("post-cut-off-length", 10), null); + if (!preferences.validatePostCutOffLength(postCutOffLength)) { + fieldErrors.add("post-cut-off-length"); + } else { + preferences.setPostCutOffLength(postCutOffLength); + } boolean requireFullAccess = request.getHttpRequest().isPartSet("require-full-access"); preferences.setRequireFullAccess(requireFullAccess); Integer positiveTrust = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("positive-trust", 3)); @@ -128,6 +134,7 @@ public class OptionsPage extends SoneTemplatePage { templateContext.set("insertion-delay", preferences.getInsertionDelay()); templateContext.set("posts-per-page", preferences.getPostsPerPage()); templateContext.set("characters-per-post", preferences.getCharactersPerPost()); + templateContext.set("post-cut-off-length", preferences.getPostCutOffLength()); templateContext.set("require-full-access", preferences.isRequireFullAccess()); templateContext.set("positive-trust", preferences.getPositiveTrust()); templateContext.set("negative-trust", preferences.getNegativeTrust()); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 4da0855..d6ba9a7 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -43,7 +43,8 @@ Page.Options.Option.EnableSoneInsertNotifications.Description=If enabled, this w Page.Options.Section.RuntimeOptions.Title=Runtime Behaviour Page.Options.Option.InsertionDelay.Description=The number of seconds the Sone inserter waits after a modification of a Sone before it is being inserted. Page.Options.Option.PostsPerPage.Description=The number of posts to display on a page before pagination controls are being shown. -Page.Options.Option.CharactersPerPost.Description=The number of characters to display from a post before cutting it off and showing a link to expand it (-1 to disable). +Page.Options.Option.CharactersPerPost.Description=The number of characters to display from a post before cutting it off and showing a link to expand it (-1 to disable). The actual length of the snippet is determined by the option below. +Page.Options.Option.PostCutOffLength.Description=The number of characters that are displayed if a post is deemed to long (see option above). Page.Options.Option.RequireFullAccess.Description=Whether to deny access to Sone to any host that has not been granted full access. Page.Options.Section.TrustOptions.Title=Trust Settings Page.Options.Option.PositiveTrust.Description=The amount of positive trust you want to assign to other Sones by clicking the checkmark below a post or reply. @@ -373,7 +374,8 @@ WebInterface.DefaultText.UploadImage.Description=Image description WebInterface.DefaultText.EditImage.Title=Image title WebInterface.DefaultText.EditImage.Description=Image description WebInterface.DefaultText.Option.PostsPerPage=Number of posts to show on a page -WebInterface.DefaultText.Option.CharactersPerPost=Number of characters per post after which to cut the post off +WebInterface.DefaultText.Option.CharactersPerPost=Number of characters a post must have to be shortened +WebInterface.DefaultText.Option.PostCutOffLength=Number of characters for the snippet of the shortened post WebInterface.DefaultText.Option.PositiveTrust=The positive trust to assign WebInterface.DefaultText.Option.NegativeTrust=The negative trust to assign WebInterface.DefaultText.Option.TrustComment=The comment to set in the web of trust diff --git a/src/main/resources/templates/include/viewPost.html b/src/main/resources/templates/include/viewPost.html index 931365d..a478bba 100644 --- a/src/main/resources/templates/include/viewPost.html +++ b/src/main/resources/templates/include/viewPost.html @@ -24,7 +24,7 @@ <%/if> <% post.text|html|store key=originalText text=true> <% post.text|parse sone=post.sone|store key=parsedText text=true> - <% post.text|parse sone=post.sone length=core.preferences.charactersPerPost|store key=shortText text=true> + <% post.text|parse sone=post.sone length=core.preferences.charactersPerPost cut-off-length=core.preferences.postCutOffLength|store key=shortText text=true>
<% originalText>
<% parsedText>
<% shortText>
diff --git a/src/main/resources/templates/include/viewReply.html b/src/main/resources/templates/include/viewReply.html index ec62887..f8e3e64 100644 --- a/src/main/resources/templates/include/viewReply.html +++ b/src/main/resources/templates/include/viewReply.html @@ -12,7 +12,7 @@ <% reply.text|html|store key=originalText text=true> <% reply.text|parse sone=reply.sone|store key=parsedText text=true> - <% reply.text|parse sone=reply.sone length=core.preferences.charactersPerPost|store key=shortText text=true> + <% reply.text|parse sone=reply.sone length=core.preferences.charactersPerPost cut-off-length=core.preferences.postCutOffLength|store key=shortText text=true>
<% originalText>
<% parsedText>
<% shortText>
diff --git a/src/main/resources/templates/options.html b/src/main/resources/templates/options.html index 39d579f..2adf57e 100644 --- a/src/main/resources/templates/options.html +++ b/src/main/resources/templates/options.html @@ -11,6 +11,9 @@ getTranslation("WebInterface.DefaultText.Option.CharactersPerPost", function(postsPerPageText) { registerInputTextareaSwap("#sone #options input[name=characters-per-post]", postsPerPageText, "characters-per-post", true, true); }); + getTranslation("WebInterface.DefaultText.Option.PostCutOffLength", function(postCutOffLengthText) { + registerInputTextareaSwap("#sone #options input[name=post-cut-off-length]", postCutOffLengthText, "post-cut-off-length", true, true); + }); getTranslation("WebInterface.DefaultText.Option.PositiveTrust", function(positiveTrustText) { registerInputTextareaSwap("#sone #options input[name=positive-trust]", positiveTrustText, "positive-trust", true, true); }); @@ -68,6 +71,12 @@ <%/if>

+

<%= Page.Options.Option.PostCutOffLength.Description|l10n|html>

+ <%if =post-cut-off-length|in collection=fieldErrors> +

<%= Page.Options.Warnings.ValueNotChanged|l10n|html>

+ <%/if> +

+

checked="checked"<%/if> /> <%= Page.Options.Option.RequireFullAccess.Description|l10n|html>

-- 2.7.4