summaryrefslogtreecommitdiff
path: root/lib/VNWeb/Validation.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-02-13 15:28:05 +0100
committerYorhel <git@yorhel.nl>2020-02-13 15:28:07 +0100
commit23fb02e36defa7660ee871dd9e650906b0d2d616 (patch)
treeef96a9aad699df8a42da33930af373d4ea69e177 /lib/VNWeb/Validation.pm
parentf95eab4d6547d402d79e443c5488d12b74650f74 (diff)
v2rw: WIP: Convert character pages
This uses an alternative (non-JS) approach to spoiler hiding, which is both much simpler to implement and properly handles all cases. Downside is that it requires a page reload. It also allows direct linking to a character page with a particular view, but I'm not entirely sure if this is a welcome feature. This is a WIP because it doesn't display instances yet.
Diffstat (limited to 'lib/VNWeb/Validation.pm')
-rw-r--r--lib/VNWeb/Validation.pm28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/VNWeb/Validation.pm b/lib/VNWeb/Validation.pm
index c506903a..b8f1bcdc 100644
--- a/lib/VNWeb/Validation.pm
+++ b/lib/VNWeb/Validation.pm
@@ -16,6 +16,7 @@ our @EXPORT = qw/
form_changed
validate_dbid
can_edit
+ viewget viewset
/;
@@ -174,4 +175,31 @@ sub can_edit {
auth->permDbmod || (auth->permEdit && !($entry->{entry_hidden} || $entry->{entry_locked}));
}
+
+# Returns { spoilers => 0-2, traits_sexual => 0/1 }
+# Based on the view= query parameter or the user's preferences.
+# The query parameter has the following format:
+# view=1 -> spoilers=1, traits_sexual=<default>
+# view=2s -> spoilers=2, traits_sexual=1
+# view=2S -> spoilers=2, traits_sexual=0
+# view=S -> spoilers=<default>, traits_sexual=0
+# i.e. a list of single-character flags:
+# 0-2 -> spoilers
+# s/S -> 1/0 traits_sexual
+# Missing flags will use default.
+sub viewget {
+ (tuwf->reqGet('view')) =~ /^([0-2]?)([sS]?)$/;
+ {
+ spoilers => $1 // auth->pref('spoilers') || 0,
+ traits_sexual => !$2 ? auth->pref('traits_sexual') : $2 eq 's',
+ }
+}
+
+# Modifies the current view settings and serializes that into a view= value.
+# XXX: This may include more flags than the current page will use.
+sub viewset {
+ my %s = (viewget->%*, @_);
+ $s{spoilers}.($s{traits_sexual}?'s':'S')
+}
+
1;