diff options
author | Yorhel <git@yorhel.nl> | 2020-07-13 10:41:33 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-07-13 10:41:40 +0200 |
commit | 078842aba46df0c2b56f1bc6ac53d03d800a7b5d (patch) | |
tree | 8aa0ad4f6a3855e80a1e1aab9631e0e1407f57f9 | |
parent | 7666cac080a282d6278bddddf23f749e4fdc02c9 (diff) |
VN::Page: Display screenshot image flagging status in revision diffs
The flagging status is independent of the change and therefore always
the same for the old and new revisions, but it's still handy info to
have around. The deprecated NSFW flag is now displayed less prominently.
-rw-r--r-- | lib/VNWeb/Images/Lib.pm | 23 | ||||
-rw-r--r-- | lib/VNWeb/VN/Page.pm | 7 |
2 files changed, 21 insertions, 9 deletions
diff --git a/lib/VNWeb/Images/Lib.pm b/lib/VNWeb/Images/Lib.pm index 7a5e2680..bee2086c 100644 --- a/lib/VNWeb/Images/Lib.pm +++ b/lib/VNWeb/Images/Lib.pm @@ -3,9 +3,12 @@ package VNWeb::Images::Lib; use VNWeb::Prelude; use Exporter 'import'; -our @EXPORT = qw/enrich_image validate_token image_ enrich_image_obj/; +our @EXPORT = qw/enrich_image validate_token image_flagging_display image_ enrich_image_obj/; +my @SEX = qw/Safe Suggestive Explicit/; +my @VIO = qw/Tame Violent Brutal /; + # Enrich images so that they match the format expected by the 'ImageResult' Elm # API response. # @@ -63,6 +66,15 @@ sub validate_token { } +# Returns a string like 'Not flagged' or 'Safe / Tame (5)' +sub image_flagging_display { + my($img) = @_; + $img->{votecount} + ? sprintf '%s / %s (%d)', $SEX[$img->{sexual}], $VIO[$img->{violence}], $img->{votecount} + : 'Not flagged' +} + + # Display (or not) an image with preference toggle and hover-information. # Given $img is assumed to be an object generated by enrich_image_obj(). sub image_ { @@ -70,8 +82,6 @@ sub image_ { return p_ 'No image' if !$img; my($sex,$vio) = $img->@{'sexual', 'violence'}; - my $sexd = ['Safe', 'Suggestive', 'Explicit']->[$sex] if $img->{votecount}; - my $viod = ['Tame', 'Violent', 'Brutal' ]->[$vio] if $img->{votecount}; my $sexp = auth->pref('max_sexual')||0; my $viop = auth->pref('max_violence')||0; my $sexh = $sex > $sexp && $sexp >= 0 if $img->{votecount}; @@ -83,16 +93,15 @@ sub image_ { input_ type => 'checkbox', class => 'visuallyhidden', $hidden ? () : (checked => 'checked') if $hide_on_click; div_ class => 'imghover--visible', sub { img_ src => tuwf->imgurl($img->{id}), $opt{alt} ? (alt => $opt{alt}) : (); - a_ class => 'imghover--overlay', href => "/img/$img->{id}?view=".viewset(show_nsfw=>1), - $img->{votecount} ? sprintf '%s / %s (%d)', $sexd, $viod, $img->{votecount} : 'Not flagged'; + a_ class => 'imghover--overlay', href => "/img/$img->{id}?view=".viewset(show_nsfw=>1), image_flagging_display $img; }; div_ class => 'imghover--warning', sub { if($img->{votecount}) { txt_ 'This image has been flagged as:'; br_; br_; - txt_ 'Sexual: '; $sexh ? b_ class => 'standout', $sexd : txt_ $sexd; + txt_ 'Sexual: '; $sexh ? b_ class => 'standout', $SEX[$sex] : txt_ $SEX[$sex]; br_; - txt_ 'Violence '; $vioh ? b_ class => 'standout', $viod : txt_ $viod; + txt_ 'Violence '; $vioh ? b_ class => 'standout', $VIO[$vio] : txt_ $VIO[$vio]; } else { txt_ 'This image has not yet been flagged'; } diff --git a/lib/VNWeb/VN/Page.pm b/lib/VNWeb/VN/Page.pm index 8e6b6540..37b84ab9 100644 --- a/lib/VNWeb/VN/Page.pm +++ b/lib/VNWeb/VN/Page.pm @@ -2,7 +2,7 @@ package VNWeb::VN::Page; use VNWeb::Prelude; use VNWeb::Releases::Lib; -use VNWeb::Images::Lib qw/image_ enrich_image_obj/; +use VNWeb::Images::Lib qw/image_flagging_display image_ enrich_image_obj/; use VNDB::Func 'fmtrating'; use POSIX 'strftime'; @@ -87,7 +87,10 @@ sub rev_ { txt_ 'no release' if !$_->{rid}; txt_ '] '; a_ href => tuwf->imgurl($_->{scr}{id}), 'data-iv' => "$_->{scr}{width}x$_->{scr}{height}::$_->{scr}{sexual}$_->{scr}{violence}$_->{scr}{votecount}", $_->{scr}{id}; - txt_ ' (Not safe)' if $_->{nsfw}; + txt_ ' ['; + a_ href => "/img/$_->{scr}{id}", image_flagging_display $_->{scr}; + txt_ '] '; + b_ class => 'grayedout', sprintf 'old flag: %s', $_->{nsfw} ? 'NSFW' : 'Safe'; }], [ image => 'Image', fmt => sub { image_ $_ } ], [ img_nsfw => 'Image NSFW (unused)', fmt => sub { txt_ $_ ? 'Not safe' : 'Safe' } ], |